Update shell.js and relative files

This commit is contained in:
Namhyeon Go 2020-07-26 20:40:25 +09:00
parent e204d0d467
commit a2c475a89a
9 changed files with 145 additions and 136 deletions

9
bootstrap.js vendored
View File

@ -10,7 +10,7 @@ var SYS = require("lib/system");
var SHELL = require("lib/shell");
return {
main: function() {
main: function(args) {
// unlock file
console.log("Starting unlock files...");
PS.execCommand("dir | Unblock-File");
@ -29,8 +29,13 @@ return {
// open HTA file
console.log("Trying open GUI...");
if (typeof(args) !== "undefined") {
SHELL.run(["app.hta"].concat(args));
} else {
SHELL.run("app.hta");
}
console.log("done");
// echo welcome
console.log("welcome");
}
};

View File

@ -9,16 +9,14 @@ exports.global = global;
exports.require = global.require;
exports.execScript = function(scriptName, args) {
var commandOptions = [];
commandOptions.push("\"%PROGRAMFILES%\\AutoHotkey\\AutoHotkey.exe\"");
commandOptions.push(scriptName + ".ahk");
var cmd = [
"%PROGRAMFILES%\\AutoHotkey\\AutoHotkey.exe",
scriptName + ".ahk"
];
if (typeof(args) !== "undefined") {
for(var i in args) {
commandOptions.push(args[i]);
}
cmd = cmd.concat(args);
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};

View File

@ -9,16 +9,14 @@ exports.global = global;
exports.require = global.require;
exports.execScript = function(scriptName, args) {
var commandOptions = [];
commandOptions.push("\"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe\"");
commandOptions.push(scriptName + ".au3");
var cmd = [
"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe",
scriptName + ".au3"
];
if (typeof(args) !== "undefined") {
for(var i in args) {
commandOptions.push(args[i]);
}
cmd = cmd.concat(args);
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};

View File

@ -19,10 +19,9 @@ if(arch.indexOf("64") > -1) {
// TODO: https://developers.cloudflare.com/access/rdp/rdp-guide/
exports.installService = function() {
var commandOptions = [];
commandOptions.push(exports.binPath);
commandOptions.push("service");
commandOptions.push("install");
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec([
exports.binPath,
"service",
"install"
]);
};

View File

@ -8,49 +8,32 @@ exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.addslashes = function(string) {
return string.replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"');
};
exports.execScript = function(scriptName, args) {
var commandOptions = [];
var cmd = [
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-file",
scriptName + ".ps1"
];
commandOptions.push("powershell.exe");
commandOptions.push("-NoProfile");
commandOptions.push("-ExecutionPolicy");
commandOptions.push("ByPass");
commandOptions.push("-nologo")
commandOptions.push("-file");
commandOptions.push(scriptName + ".ps1");
if(typeof(args) !== "undefined") {
for(var i in args) {
commandOptions.push(args[i]);
}
if (typeof(cmd) !== "undefined") {
cmd = cmd.concat(args);
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};
exports.execCommand = function(command) {
var commandOptions = [];
commandOptions.push("powershell.exe");
commandOptions.push("-NoProfile");
commandOptions.push("-ExecutionPolicy");
commandOptions.push("ByPass");
commandOptions.push("-nologo")
commandOptions.push("-Command");
commandOptions.push("\"& {");
commandOptions.push(exports.addslashes(command));
commandOptions.push("}\"");
return SHELL.exec(commandOptions.join(' '));
exports.execCommand = function(cmd) {
return SHELL.exec([
"powershell.exe",
"-NoProfile",
"-ExecutionPolicy",
"ByPass",
"-nologo",
"-Command",
"& {" + cmd + "}"
]);
};

View File

@ -6,7 +6,11 @@ exports.require = global.require;
// https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dd228922(v=ws.11)
exports.queryService = function(name, options) {
var commandOptons = [],
var cmd = [
"sc",
"query",
name
],
_options = {
type: [
"service", // type= {driver | service | all}
@ -26,22 +30,26 @@ exports.queryService = function(name, options) {
if(_options[k] !== false) {
if(_options[k].constructor == Array) {
for(var i in options[k]) {
commandOptions.push(k + "=");
commandOptions.push("\"" + _options[k][i] + "\"");
cmd.push(k + '=');
cmd.push(_options[k][i]);
}
} else {
commandOptions.push(k + '=');
commandOptions.push("\"" + _options[k] + "\"");
cmd.push(k + '=');
cmd.push(_options[k]);
}
}
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};
// https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create
exports.createService = function(name, options) {
var commandOptions = [],
var cmd = [
"sc",
"create",
name
],
_options = {
type: "share", // type= {own | share | kernel | filesys | rec | interact type= {own | share}}
start: "demand", // start= {boot | system | auto | demand | disabled | delayed-auto }
@ -55,10 +63,6 @@ exports.createService = function(name, options) {
password: false // password= <Password>
};
commandOptions.push("sc");
commandOptions.push("create");
commandOptions.push(name);
for(var k in _options) {
if(k in options) {
_options[k] = options[k];
@ -67,51 +71,45 @@ exports.createService = function(name, options) {
if(_options[k] !== false) {
if(_options[k].constructor == Array) {
for(var i in options[k]) {
commandOptions.push(k + "=");
commandOptions.push("\"" + _options[k][i] + "\"");
cmd.push(k + '=');
cmd.push(_options[k][i]);
}
} else {
commandOptions.push(k + '=');
commandOptions.push("\"" + _options[k] + "\"");
cmd.push(k + '=');
cmd.push(_options[k]);
}
}
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};
exports.startService = function(name, args) {
var commandOptions = [];
commandOptions.push("sc");
commandOptions.push("start");
commandOptions.push(name);
var cmd = [
"sc",
"start",
name
];
if(typeof(args) !== "undefined") {
for(var i in args) {
commandOptions.push(args[i]);
}
cmd = cmd.concat(args);
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};
exports.stopService = function(name, args) {
var commandOptions = [];
commandOptions.push("sc");
commandOptions.push("stop");
commandOptions.push(name);
return SHELL.exec(commandOptions.join(' '));
exports.stopService = function(name) {
return SHELL.exec([
"sc",
"stop",
name
]);
};
exports.deleteService = function(name) {
var commandOptions = [];
commandOptions.push("sc");
commandOptions.push("delete");
commandOptions.push(name);
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec([
"sc",
"delete",
name
]);
};

View File

@ -16,18 +16,27 @@ if(arch.indexOf("64") > -1) {
exports.binPath = "bin/shadowsocks-lib-mingw-x86/ss-local";
}
exports.connect = function(host, remotePort, localPort, password, algorithm) {
var commandOptions = [];
commandOptions.push(exports.binPath);
commandOptions.push("-s");
commandOptions.push(host);
commandOptions.push("-p");
commandOptions.push(remotePort);
commandOptions.push("-l");
commandOptions.push(localPorts);
commandOptions.push("-k");
commandOptions.push(password);
commandOptions.push("-m");
commandOptions.push(algoritm);
SHELL.run(commandOptions.join(' '), true);
exports.getRandomInt = function(min, max) {
var x = Math.random();
return min + Math.floor((max - min) * x);
};
exports.connect = function() {
var port = exports.getRandomInt(49152, 65535);
SHELL.run([
exports.binPath,
"-s",
__config.shadowsocks.host,
"-p",
__config.shadowsocks.port,
"-l",
port,
"-k",
__config.shadowsocks.password,
"-m",
__config.shadowsocks.cipher
], true);
return port;
};

View File

@ -8,14 +8,35 @@ exports.VERSIONINFO = "Shell Module (shell.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.exec = function(cmd, stdOutPath) {
var WSH = CreateObject("WScript.Shell"),
data;
exports.addslashes = function(string) {
return string.replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t').
replace(/\n/g, '\\n').
replace(/\f/g, '\\f').
replace(/\r/g, '\\r').
replace(/'/g, '\\\'').
replace(/"/g, '\\"');
};
if (typeof(stdOutPath) == "undefined") {
exports.makeCmdLine = function(cmd) {
if (typeof(cmd) === "string") {
return cmd;
} else if (typeof(cmd) === "object") {
return cmd.map(function(s) {
return "\"" + exports.addslashes(s) + "\"";
}).join(' ');
} else {
return "";
}
};
exports.exec = function(cmd, stdOutPath) {
var WSH = CreateObject("WScript.Shell"), data;
if (typeof(stdOutPath) === "undefined") {
stdOutPath = "stdout.txt";
}
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
var c = "%comspec% /c (" + exports.makeCmdLine(cmd) + ") 1> " + stdOutPath;
c += " 2>&1";
WSH.Run(c, 0, true);
data = FILE.readFile(stdOutPath, "utf-8");
@ -30,6 +51,6 @@ exports.exec = function(cmd, stdOutPath) {
exports.run = function(cmd, fork) {
var WSH = CreateObject("WScript.Shell");
var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c " + cmd;
var c = "%comspec% /q /c " + exports.makeCmdLine(cmd);
WSH.Run(c, 0, !fork);
};

View File

@ -9,18 +9,16 @@ exports.global = global;
exports.require = global.require;
exports.execScript = function(scriptName, args) {
var commandOptions = [];
commandOptions.push("cscript");
commandOptions.push(scriptName + ".vbs");
var cmd = [
"cscript",
scriptName + ".vbs"
];
if (typeof(args) !== "undefined") {
for(var i in args) {
commandOptions.push(args[i]);
}
cmd = cmd.concat(args);
}
return SHELL.exec(commandOptions.join(' '));
return SHELL.exec(cmd);
};
exports.execCommand = function(command) {