mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
Update shell.js and relative files
This commit is contained in:
parent
e204d0d467
commit
a2c475a89a
11
bootstrap.js
vendored
11
bootstrap.js
vendored
|
@ -10,7 +10,7 @@ var SYS = require("lib/system");
|
||||||
var SHELL = require("lib/shell");
|
var SHELL = require("lib/shell");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
main: function() {
|
main: function(args) {
|
||||||
// unlock file
|
// unlock file
|
||||||
console.log("Starting unlock files...");
|
console.log("Starting unlock files...");
|
||||||
PS.execCommand("dir | Unblock-File");
|
PS.execCommand("dir | Unblock-File");
|
||||||
|
@ -29,8 +29,13 @@ return {
|
||||||
|
|
||||||
// open HTA file
|
// open HTA file
|
||||||
console.log("Trying open GUI...");
|
console.log("Trying open GUI...");
|
||||||
SHELL.run("app.hta");
|
if (typeof(args) !== "undefined") {
|
||||||
|
SHELL.run(["app.hta"].concat(args));
|
||||||
|
} else {
|
||||||
|
SHELL.run("app.hta");
|
||||||
|
}
|
||||||
|
|
||||||
console.log("done");
|
// echo welcome
|
||||||
|
console.log("welcome");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,16 +9,14 @@ exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.execScript = function(scriptName, args) {
|
exports.execScript = function(scriptName, args) {
|
||||||
var commandOptions = [];
|
var cmd = [
|
||||||
|
"%PROGRAMFILES%\\AutoHotkey\\AutoHotkey.exe",
|
||||||
|
scriptName + ".ahk"
|
||||||
|
];
|
||||||
|
|
||||||
commandOptions.push("\"%PROGRAMFILES%\\AutoHotkey\\AutoHotkey.exe\"");
|
if (typeof(args) !== "undefined") {
|
||||||
commandOptions.push(scriptName + ".ahk");
|
cmd = cmd.concat(args);
|
||||||
|
|
||||||
if(typeof(args) !== "undefined") {
|
|
||||||
for(var i in args) {
|
|
||||||
commandOptions.push(args[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,16 +9,14 @@ exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.execScript = function(scriptName, args) {
|
exports.execScript = function(scriptName, args) {
|
||||||
var commandOptions = [];
|
var cmd = [
|
||||||
|
"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe",
|
||||||
|
scriptName + ".au3"
|
||||||
|
];
|
||||||
|
|
||||||
commandOptions.push("\"%PROGRAMFILES(X86)%\\AutoIt3\\AutoIt3.exe\"");
|
if (typeof(args) !== "undefined") {
|
||||||
commandOptions.push(scriptName + ".au3");
|
cmd = cmd.concat(args);
|
||||||
|
|
||||||
if(typeof(args) !== "undefined") {
|
|
||||||
for(var i in args) {
|
|
||||||
commandOptions.push(args[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,10 +19,9 @@ if(arch.indexOf("64") > -1) {
|
||||||
// TODO: https://developers.cloudflare.com/access/rdp/rdp-guide/
|
// TODO: https://developers.cloudflare.com/access/rdp/rdp-guide/
|
||||||
|
|
||||||
exports.installService = function() {
|
exports.installService = function() {
|
||||||
var commandOptions = [];
|
return SHELL.exec([
|
||||||
commandOptions.push(exports.binPath);
|
exports.binPath,
|
||||||
commandOptions.push("service");
|
"service",
|
||||||
commandOptions.push("install");
|
"install"
|
||||||
|
]);
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,49 +8,32 @@ exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
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) {
|
exports.execScript = function(scriptName, args) {
|
||||||
var commandOptions = [];
|
var cmd = [
|
||||||
|
"powershell.exe",
|
||||||
|
"-NoProfile",
|
||||||
|
"-ExecutionPolicy",
|
||||||
|
"ByPass",
|
||||||
|
"-nologo",
|
||||||
|
"-file",
|
||||||
|
scriptName + ".ps1"
|
||||||
|
];
|
||||||
|
|
||||||
commandOptions.push("powershell.exe");
|
if (typeof(cmd) !== "undefined") {
|
||||||
commandOptions.push("-NoProfile");
|
cmd = cmd.concat(args);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.execCommand = function(command) {
|
exports.execCommand = function(cmd) {
|
||||||
var commandOptions = [];
|
return SHELL.exec([
|
||||||
|
"powershell.exe",
|
||||||
commandOptions.push("powershell.exe");
|
"-NoProfile",
|
||||||
commandOptions.push("-NoProfile");
|
"-ExecutionPolicy",
|
||||||
commandOptions.push("-ExecutionPolicy");
|
"ByPass",
|
||||||
commandOptions.push("ByPass");
|
"-nologo",
|
||||||
commandOptions.push("-nologo")
|
"-Command",
|
||||||
commandOptions.push("-Command");
|
"& {" + cmd + "}"
|
||||||
commandOptions.push("\"& {");
|
]);
|
||||||
commandOptions.push(exports.addslashes(command));
|
|
||||||
commandOptions.push("}\"");
|
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -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)
|
// 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) {
|
exports.queryService = function(name, options) {
|
||||||
var commandOptons = [],
|
var cmd = [
|
||||||
|
"sc",
|
||||||
|
"query",
|
||||||
|
name
|
||||||
|
],
|
||||||
_options = {
|
_options = {
|
||||||
type: [
|
type: [
|
||||||
"service", // type= {driver | service | all}
|
"service", // type= {driver | service | all}
|
||||||
|
@ -26,22 +30,26 @@ exports.queryService = function(name, options) {
|
||||||
if(_options[k] !== false) {
|
if(_options[k] !== false) {
|
||||||
if(_options[k].constructor == Array) {
|
if(_options[k].constructor == Array) {
|
||||||
for(var i in options[k]) {
|
for(var i in options[k]) {
|
||||||
commandOptions.push(k + "=");
|
cmd.push(k + '=');
|
||||||
commandOptions.push("\"" + _options[k][i] + "\"");
|
cmd.push(_options[k][i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commandOptions.push(k + '=');
|
cmd.push(k + '=');
|
||||||
commandOptions.push("\"" + _options[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
|
// https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/sc-create
|
||||||
exports.createService = function(name, options) {
|
exports.createService = function(name, options) {
|
||||||
var commandOptions = [],
|
var cmd = [
|
||||||
|
"sc",
|
||||||
|
"create",
|
||||||
|
name
|
||||||
|
],
|
||||||
_options = {
|
_options = {
|
||||||
type: "share", // type= {own | share | kernel | filesys | rec | interact type= {own | share}}
|
type: "share", // type= {own | share | kernel | filesys | rec | interact type= {own | share}}
|
||||||
start: "demand", // start= {boot | system | auto | demand | disabled | delayed-auto }
|
start: "demand", // start= {boot | system | auto | demand | disabled | delayed-auto }
|
||||||
|
@ -55,10 +63,6 @@ exports.createService = function(name, options) {
|
||||||
password: false // password= <Password>
|
password: false // password= <Password>
|
||||||
};
|
};
|
||||||
|
|
||||||
commandOptions.push("sc");
|
|
||||||
commandOptions.push("create");
|
|
||||||
commandOptions.push(name);
|
|
||||||
|
|
||||||
for(var k in _options) {
|
for(var k in _options) {
|
||||||
if(k in options) {
|
if(k in options) {
|
||||||
_options[k] = options[k];
|
_options[k] = options[k];
|
||||||
|
@ -67,51 +71,45 @@ exports.createService = function(name, options) {
|
||||||
if(_options[k] !== false) {
|
if(_options[k] !== false) {
|
||||||
if(_options[k].constructor == Array) {
|
if(_options[k].constructor == Array) {
|
||||||
for(var i in options[k]) {
|
for(var i in options[k]) {
|
||||||
commandOptions.push(k + "=");
|
cmd.push(k + '=');
|
||||||
commandOptions.push("\"" + _options[k][i] + "\"");
|
cmd.push(_options[k][i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
commandOptions.push(k + '=');
|
cmd.push(k + '=');
|
||||||
commandOptions.push("\"" + _options[k] + "\"");
|
cmd.push(_options[k]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.startService = function(name, args) {
|
exports.startService = function(name, args) {
|
||||||
var commandOptions = [];
|
var cmd = [
|
||||||
|
"sc",
|
||||||
commandOptions.push("sc");
|
"start",
|
||||||
commandOptions.push("start");
|
name
|
||||||
commandOptions.push(name);
|
];
|
||||||
|
|
||||||
if(typeof(args) !== "undefined") {
|
if(typeof(args) !== "undefined") {
|
||||||
for(var i in args) {
|
cmd = cmd.concat(args);
|
||||||
commandOptions.push(args[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.stopService = function(name, args) {
|
exports.stopService = function(name) {
|
||||||
var commandOptions = [];
|
return SHELL.exec([
|
||||||
|
"sc",
|
||||||
commandOptions.push("sc");
|
"stop",
|
||||||
commandOptions.push("stop");
|
name
|
||||||
commandOptions.push(name);
|
]);
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteService = function(name) {
|
exports.deleteService = function(name) {
|
||||||
var commandOptions = [];
|
return SHELL.exec([
|
||||||
|
"sc",
|
||||||
commandOptions.push("sc");
|
"delete",
|
||||||
commandOptions.push("delete");
|
name
|
||||||
commandOptions.push(name);
|
]);
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,18 +16,27 @@ if(arch.indexOf("64") > -1) {
|
||||||
exports.binPath = "bin/shadowsocks-lib-mingw-x86/ss-local";
|
exports.binPath = "bin/shadowsocks-lib-mingw-x86/ss-local";
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.connect = function(host, remotePort, localPort, password, algorithm) {
|
exports.getRandomInt = function(min, max) {
|
||||||
var commandOptions = [];
|
var x = Math.random();
|
||||||
commandOptions.push(exports.binPath);
|
return min + Math.floor((max - min) * x);
|
||||||
commandOptions.push("-s");
|
};
|
||||||
commandOptions.push(host);
|
|
||||||
commandOptions.push("-p");
|
exports.connect = function() {
|
||||||
commandOptions.push(remotePort);
|
var port = exports.getRandomInt(49152, 65535);
|
||||||
commandOptions.push("-l");
|
|
||||||
commandOptions.push(localPorts);
|
SHELL.run([
|
||||||
commandOptions.push("-k");
|
exports.binPath,
|
||||||
commandOptions.push(password);
|
"-s",
|
||||||
commandOptions.push("-m");
|
__config.shadowsocks.host,
|
||||||
commandOptions.push(algoritm);
|
"-p",
|
||||||
SHELL.run(commandOptions.join(' '), true);
|
__config.shadowsocks.port,
|
||||||
|
"-l",
|
||||||
|
port,
|
||||||
|
"-k",
|
||||||
|
__config.shadowsocks.password,
|
||||||
|
"-m",
|
||||||
|
__config.shadowsocks.cipher
|
||||||
|
], true);
|
||||||
|
|
||||||
|
return port;
|
||||||
};
|
};
|
||||||
|
|
33
lib/shell.js
33
lib/shell.js
|
@ -8,14 +8,35 @@ exports.VERSIONINFO = "Shell Module (shell.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.exec = function(cmd, stdOutPath) {
|
exports.addslashes = function(string) {
|
||||||
var WSH = CreateObject("WScript.Shell"),
|
return string.replace(/\\/g, '\\\\').
|
||||||
data;
|
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";
|
stdOutPath = "stdout.txt";
|
||||||
}
|
}
|
||||||
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
|
var c = "%comspec% /c (" + exports.makeCmdLine(cmd) + ") 1> " + stdOutPath;
|
||||||
c += " 2>&1";
|
c += " 2>&1";
|
||||||
WSH.Run(c, 0, true);
|
WSH.Run(c, 0, true);
|
||||||
data = FILE.readFile(stdOutPath, "utf-8");
|
data = FILE.readFile(stdOutPath, "utf-8");
|
||||||
|
@ -30,6 +51,6 @@ exports.exec = function(cmd, stdOutPath) {
|
||||||
exports.run = function(cmd, fork) {
|
exports.run = function(cmd, fork) {
|
||||||
var WSH = CreateObject("WScript.Shell");
|
var WSH = CreateObject("WScript.Shell");
|
||||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
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);
|
WSH.Run(c, 0, !fork);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,18 +9,16 @@ exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
||||||
exports.execScript = function(scriptName, args) {
|
exports.execScript = function(scriptName, args) {
|
||||||
var commandOptions = [];
|
var cmd = [
|
||||||
|
"cscript",
|
||||||
|
scriptName + ".vbs"
|
||||||
|
];
|
||||||
|
|
||||||
commandOptions.push("cscript");
|
if (typeof(args) !== "undefined") {
|
||||||
commandOptions.push(scriptName + ".vbs");
|
cmd = cmd.concat(args);
|
||||||
|
|
||||||
if(typeof(args) !== "undefined") {
|
|
||||||
for(var i in args) {
|
|
||||||
commandOptions.push(args[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHELL.exec(commandOptions.join(' '));
|
return SHELL.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.execCommand = function(command) {
|
exports.execCommand = function(command) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user