updated library 'lib/shell'

This commit is contained in:
Namhyeon Go 2020-07-07 18:02:51 +09:00
parent 3902523e9d
commit da0d03cc1d
4 changed files with 123 additions and 76 deletions

10
app.js
View File

@ -38,11 +38,11 @@ var console = {
log: function(msg, status) { log: function(msg, status) {
if (typeof(window) !== 'undefined') { if (typeof(window) !== 'undefined') {
if (typeof(window.jQuery) !== 'undefined') { if (typeof(window.jQuery) !== 'undefined') {
window.jQuery.toast({ //window.jQuery.toast({
heading: "Information", // heading: "Information",
text: msg, // text: msg,
icon: "info" // icon: "info"
}); //});
} else { } else {
messages.push(msg); messages.push(msg);
} }

View File

@ -1,12 +1,13 @@
var FILE = require("lib/file"); var FILE = require("lib/file");
var SHELL = require("lib/shell");
var serverUrl = "http://96.30.198.29/"; var serverUrl = "http://96.30.198.29/";
$(document).ready(function() { $(".show-logged").css("display", "none");
$(".show-logged").css("display", "none");
$("#loginform").ajaxForm({ $("#loginform").ajaxForm({
success: function(res) { success: function(res) {
if(res.success === false) { if (res.success === false) {
console.log("로그인에 실패하였습니다. 다시 시도하여 주세요"); console.log("로그인에 실패하였습니다. 다시 시도하여 주세요");
} else { } else {
// 로그인 사용자의 토큰을 저장 // 로그인 사용자의 토큰을 저장
@ -14,7 +15,7 @@ $(document).ready(function() {
// 저장 여부 확인 // 저장 여부 확인
var isTokenExists = FILE.fileExists("token.txt"); var isTokenExists = FILE.fileExists("token.txt");
if(isTokenExists) { if (isTokenExists) {
// 성공하면 아이디 표시 // 성공하면 아이디 표시
$("#logged_username").text(res.data.username); $("#logged_username").text(res.data.username);
@ -30,11 +31,11 @@ $(document).ready(function() {
var errorMessage = xhr.status + ': ' + xhr.statusText; var errorMessage = xhr.status + ': ' + xhr.statusText;
alert('Error - ' + errorMessage); alert('Error - ' + errorMessage);
} }
}); });
// 기존 토큰 정보가 있는 경우 // 기존 토큰 정보가 있는 경우
var isTokenExists = FILE.fileExists("token.txt"); var isTokenExists = FILE.fileExists("token.txt");
if(isTokenExists) { if (isTokenExists) {
var token = FILE.readFile("token.txt", "utf-8"); var token = FILE.readFile("token.txt", "utf-8");
$.get(serverUrl, { $.get(serverUrl, {
route: "api.authenticate", route: "api.authenticate",
@ -48,15 +49,15 @@ $(document).ready(function() {
$(".show-no-logged").css("display", "none"); $(".show-no-logged").css("display", "none");
$(".show-logged").css("display", ""); $(".show-logged").css("display", "");
}); });
} }
// 닫기 // 닫기
$("a[href='#exit']").click(function() { $("a[href='#exit']").click(function() {
exit(); exit();
}); });
// 로그아웃 // 로그아웃
$("#btn_logout").click(function() { $("#btn_logout").click(function() {
// 토큰 파일 삭제 // 토큰 파일 삭제
FILE.deleteFile("token.txt"); FILE.deleteFile("token.txt");
@ -67,5 +68,8 @@ $(document).ready(function() {
$(".logoutbox").css("display", "none"); $(".logoutbox").css("display", "none");
console.log("로그아웃 되었습니다."); console.log("로그아웃 되었습니다.");
});
}); });
// 계산기 실행
var text = SHELL.exec("calc && echo hello");
alert(text);

38
lib/shell.js Normal file
View File

@ -0,0 +1,38 @@
////////////////////////////////////////////////////////////////////////
// Shell API
////////////////////////////////////////////////////////////////////////
var FILE = require('lib/file');
var scope = {
VERSIONINFO: "Shell Module (shell.js) version 0.1",
global: global,
require: global.require
};
scope.exec = function(cmd, stdOutPath) {
var WSS = CreateObject("WScript.Shell"),
data;
if (typeof(stdOutPath) == "undefined") {
stdOutPath = "stdout.txt";
}
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
c += " 2>&1";
WSS.Run(c, 0, true);
data = FILE.readFile(stdOutPath, "utf-8");
if (FILE.fileExists(stdOutPath)) {
FILE.deleteFile(stdOutPath);
}
return data;
}
scope.run = function(cmd, fork) {
var WSS = CreateObject("WScript.Shell");
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c " + cmd;
WSS.Run(cmd, 0, !fork);
};
return scope;

View File

@ -217,6 +217,11 @@ return {
self.addStylesheet("app/assets/css/jquery.toast-1.3.2.min.css"); self.addStylesheet("app/assets/css/jquery.toast-1.3.2.min.css");
self.addStylesheet("app/assets/css/style.css"); self.addStylesheet("app/assets/css/style.css");
// "go to entrypoint";
var start = function() {
self.addScript("app/assets/js/index.js");
};
// "when loaded jquery (strictly)"; // "when loaded jquery (strictly)";
var jqLoaded = function(el) { var jqLoaded = function(el) {
jQuery.support.cors = true; jQuery.support.cors = true;
@ -226,13 +231,16 @@ return {
for (var i in messages) { for (var i in messages) {
console.log(messages[i]); console.log(messages[i]);
} }
// "start this app"
start();
} }
}, function(el) { }, function(el) {
return window.jQuery.toast; return window.jQuery.toast;
}); });
}; };
if(self.getIEVersion() == 8) { if (self.getIEVersion() == 8) {
self.addScript("app/assets/css/jquery/webreflection-ie8-0.8.1.min.js"); self.addScript("app/assets/css/jquery/webreflection-ie8-0.8.1.min.js");
} }
@ -279,9 +287,6 @@ return {
// "set movable window"; // "set movable window";
self.enableMovableWindow(); self.enableMovableWindow();
// "go to entrypoint";
self.addScript("app/assets/js/index.js");
return 0; return 0;
} }
} }