mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-09 05:06:04 +00:00
fix
This commit is contained in:
parent
02c68cd034
commit
0014384539
|
@ -2,56 +2,59 @@
|
||||||
// Google Chrome API
|
// Google Chrome API
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
var SHELL = require("lib/shell");
|
var SHELL = require("lib/shell");
|
||||||
|
var SYS = require("lib/system");
|
||||||
|
var SB = require("lib/sandboxie");
|
||||||
|
|
||||||
var binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
|
var ChromeObject = function() {
|
||||||
|
this.binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
|
||||||
var Chrome = function() {
|
this.processID = 0;
|
||||||
this.PID = 0;
|
|
||||||
this.profileName = "Default";
|
this.profileName = "Default";
|
||||||
this.proxyPort = 1080;
|
this.proxyPort = 1080;
|
||||||
|
this.processList = [];
|
||||||
|
|
||||||
|
this.setBinPath = function(path) {
|
||||||
|
this.binPath = path;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
this.setProfileName = function(s) {
|
this.setProfileName = function(s) {
|
||||||
this.profileName = s;
|
this.profileName = s;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setProxyPort = function(s) {
|
this.setProxyPort = function(s) {
|
||||||
this.proxyPort = s;
|
this.proxyPort = s;
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getPID = function() {
|
this.getProcessList = function() {
|
||||||
return this.PID;
|
return this.processList;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.open = function(url) {
|
this.open = function(url) {
|
||||||
var process = SHELL.createProcess([
|
var process;
|
||||||
binPath,
|
while (this.processID == 0) {
|
||||||
"--profile-directory=" + this.profileName,
|
try {
|
||||||
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
process = SB.start(this.profileName, [
|
||||||
url
|
this.binPath,
|
||||||
]);
|
"--profile-directory=" + this.profileName,
|
||||||
|
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
||||||
|
url
|
||||||
|
]);
|
||||||
|
this.processID = process.ProcessID;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sleep(1000);
|
return this;
|
||||||
|
|
||||||
try {
|
|
||||||
this.PID = process.ProcessID;
|
|
||||||
|
|
||||||
if (this.PID > 0) {
|
|
||||||
return this;
|
|
||||||
} else {
|
|
||||||
console.info("Retrying call to open Chrome...");
|
|
||||||
return this.connect();
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
console.info("Retrying call to open Chrome...");
|
|
||||||
return this.connect();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.start = function(url, proxyPort, profileName) {
|
exports.getProcessIDs = function() {
|
||||||
var instance = new Chrome();
|
return (new ChromeObject()).getProcessIDs();
|
||||||
instance.setProfileName(profileName);
|
};
|
||||||
instance.setProxyPort(proxyPort);
|
|
||||||
instance.open(url);
|
exports.start = function(url, proxyPort, profileName) {
|
||||||
return instance.getPID();
|
return (new ChromeObject()).setProxyPort(proxyPort).setProfileName(profileName).open(url).processID;
|
||||||
};
|
};
|
||||||
|
|
37
lib/sandboxie.js
Normal file
37
lib/sandboxie.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
var SHELL = require("lib/shell");
|
||||||
|
|
||||||
|
var SandboxieObject = function() {
|
||||||
|
this.binPath = "%PROGRAMFILES%\\Sandboxie-Plus\\Start.exe";
|
||||||
|
this.processID = 0;
|
||||||
|
this.sandboxName = "";
|
||||||
|
|
||||||
|
this.setSandboxName = function(name) {
|
||||||
|
this.sandboxName = name;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.start = function(cmd) {
|
||||||
|
var process;
|
||||||
|
while (this.processID == 0) {
|
||||||
|
try {
|
||||||
|
process = SHELL.createProcess([
|
||||||
|
this.binPath,
|
||||||
|
"/box:" + this.sandboxName,
|
||||||
|
SHELL.buildCommand(cmd)
|
||||||
|
].join(' '));
|
||||||
|
this.processID = process.ProcessID;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.start = function(sandboxName, cmd) {
|
||||||
|
return (new SandboxieObject()).setSandboxName(sandboxName).start(cmd).processID;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.VERSIONINFO = "Sandboxie interface (sandboxie.js) version 0.1";
|
||||||
|
exports.global = global;
|
||||||
|
exports.require = global.require;
|
|
@ -52,10 +52,10 @@ var ShadowsocksObject = function() {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.create = function() {
|
exports.connect = function(host) {
|
||||||
return (new ShadowsocksObject());
|
return (new ShadowsocksObject()).connect(host);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.2";
|
exports.VERSIONINFO = "Shadowsocks interface (shadowsocks.js) version 0.2";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
|
|
10
lib/shell.js
10
lib/shell.js
|
@ -19,7 +19,7 @@ var addslashes = function(s) {
|
||||||
replace(/"/g, '\\"');
|
replace(/"/g, '\\"');
|
||||||
};
|
};
|
||||||
|
|
||||||
var makeCommand = function(cmd) {
|
exports.buildCommand = function(cmd) {
|
||||||
if (typeof(cmd) === "string") {
|
if (typeof(cmd) === "string") {
|
||||||
return cmd;
|
return cmd;
|
||||||
} else if (typeof(cmd) === "object") {
|
} else if (typeof(cmd) === "object") {
|
||||||
|
@ -41,7 +41,7 @@ exports.exec = function(cmd, stdOutPath) {
|
||||||
if (typeof(stdOutPath) === "undefined") {
|
if (typeof(stdOutPath) === "undefined") {
|
||||||
stdOutPath = "stdout.txt";
|
stdOutPath = "stdout.txt";
|
||||||
}
|
}
|
||||||
var c = "%comspec% /c (" + makeCommand(cmd) + ") 1> " + stdOutPath;
|
var c = "%comspec% /c (" + exports.buildCommand(cmd) + ") 1> " + stdOutPath;
|
||||||
c += " 2>&1";
|
c += " 2>&1";
|
||||||
WSH.Run(c, 0, true);
|
WSH.Run(c, 0, true);
|
||||||
console.info("exec() -> " + c);
|
console.info("exec() -> " + c);
|
||||||
|
@ -57,7 +57,7 @@ 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 (" + makeCommand(cmd) + ")";
|
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
|
||||||
console.info("run() -> " + c);
|
console.info("run() -> " + c);
|
||||||
WSH.Run(c, 0, !fork);
|
WSH.Run(c, 0, !fork);
|
||||||
};
|
};
|
||||||
|
@ -65,13 +65,13 @@ exports.run = function(cmd, fork) {
|
||||||
exports.runWindow = function(cmd, fork) {
|
exports.runWindow = 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 (" + makeCommand(cmd) + ")";
|
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
|
||||||
console.info("run() -> " + c);
|
console.info("run() -> " + c);
|
||||||
WSH.Run(c, 1, !fork);
|
WSH.Run(c, 1, !fork);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.createProcess = function(cmd) {
|
exports.createProcess = function(cmd) {
|
||||||
var c = makeCommand(cmd);
|
var c = exports.buildCommand(cmd);
|
||||||
var WSH = CreateObject("WScript.Shell");
|
var WSH = CreateObject("WScript.Shell");
|
||||||
console.info("createProcess() -> " + c);
|
console.info("createProcess() -> " + c);
|
||||||
return WSH.Exec(c);
|
return WSH.Exec(c);
|
||||||
|
|
|
@ -112,10 +112,16 @@ exports.getNetworkInterfaces = function() {
|
||||||
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
return WMI.execQuery("SELECT * FROM Win32_NetworkAdapterConfiguration").fetchAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getProcesses = function() {
|
exports.getProcessList = function() {
|
||||||
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
return WMI.execQuery("Select * From Win32_Process").fetchAll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getProcessListByName = function(name) {
|
||||||
|
return exports.getProcessList().filter(function(s) {
|
||||||
|
return (s.Caption === name);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
exports.killProcess = function(pid) {
|
exports.killProcess = function(pid) {
|
||||||
var processes = exports.getProcesses();
|
var processes = exports.getProcesses();
|
||||||
|
|
||||||
|
|
130
lib/wmi.js
130
lib/wmi.js
|
@ -2,71 +2,6 @@
|
||||||
// WMI(Windows Management Instrumentation) API
|
// WMI(Windows Management Instrumentation) API
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var WMIClassObject = function() {
|
|
||||||
this.interface = (new WMIQueryObject()).interface;
|
|
||||||
this.class = null;
|
|
||||||
this.className = "";
|
|
||||||
this.instance = null;
|
|
||||||
this.method = null;
|
|
||||||
this.methodName = "";
|
|
||||||
this.inParams = {};
|
|
||||||
this.outParams = {};
|
|
||||||
|
|
||||||
// Instance
|
|
||||||
this.setClass = function(className) {
|
|
||||||
this.className = className;
|
|
||||||
this.class = this.interface.Get(className);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.create = function() {
|
|
||||||
this.instance = this.class.SpawnInstance_();
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.getAttribute = function(key) {
|
|
||||||
return this.instance[key];
|
|
||||||
};
|
|
||||||
this.setAttribute = function(key, value) {
|
|
||||||
this.instance[key] = value;
|
|
||||||
};
|
|
||||||
this.getInstance = function() {
|
|
||||||
return this.instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Method
|
|
||||||
this.setMethod = function(methodName) {
|
|
||||||
this.methodName = methodName;
|
|
||||||
this.method = this.class.Methods_.Item(methodName);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.setParameter = function(key, value) {
|
|
||||||
this.inParams[key] = value;
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.setParameters = function(params) {
|
|
||||||
if (typeof(params) !== "undefined") {
|
|
||||||
for (k in params) {
|
|
||||||
this.setParameter(k, params[k]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.execute = function() {
|
|
||||||
var params = this.method.InParameters.SpawnInstance_();
|
|
||||||
for (k in this.parameters) {
|
|
||||||
params[k] = this.inParams[k];
|
|
||||||
}
|
|
||||||
this.outParams = this.class.ExecMethod_(this.methodName, params);
|
|
||||||
return this;
|
|
||||||
};
|
|
||||||
this.get = function(key) {
|
|
||||||
if (key in this.outParams) {
|
|
||||||
return this.outParams[key];
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
var WMIQueryObject = function() {
|
var WMIQueryObject = function() {
|
||||||
var wbemFlagReturnImmediately = 0x10;
|
var wbemFlagReturnImmediately = 0x10;
|
||||||
var wbemFlagForwardOnly = 0x20;
|
var wbemFlagForwardOnly = 0x20;
|
||||||
|
@ -128,6 +63,71 @@ var WMIQueryObject = function() {
|
||||||
this.create();
|
this.create();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var WMIClassObject = function() {
|
||||||
|
this.interface = (new WMIQueryObject()).interface;
|
||||||
|
this.classObject = null;
|
||||||
|
this.className = "";
|
||||||
|
this.instance = null;
|
||||||
|
this.methodObject = null;
|
||||||
|
this.methodName = "";
|
||||||
|
this.inParams = {};
|
||||||
|
this.outParams = {};
|
||||||
|
|
||||||
|
// Instance
|
||||||
|
this.setClass = function(className) {
|
||||||
|
this.className = className;
|
||||||
|
this.classObject = this.interface.Get(className);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.create = function() {
|
||||||
|
this.instance = this.classObject.SpawnInstance_();
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.getAttribute = function(key) {
|
||||||
|
return this.instance[key];
|
||||||
|
};
|
||||||
|
this.setAttribute = function(key, value) {
|
||||||
|
this.instance[key] = value;
|
||||||
|
};
|
||||||
|
this.getInstance = function() {
|
||||||
|
return this.instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Method
|
||||||
|
this.setMethod = function(methodName) {
|
||||||
|
this.methodName = methodName;
|
||||||
|
this.methodObject = this.classObject.Methods_.Item(methodName);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.setParameter = function(key, value) {
|
||||||
|
this.inParams[key] = value;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.setParameters = function(params) {
|
||||||
|
if (typeof(params) !== "undefined") {
|
||||||
|
for (k in params) {
|
||||||
|
this.setParameter(k, params[k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.execute = function() {
|
||||||
|
var params = this.methodObject.InParameters.SpawnInstance_();
|
||||||
|
for (k in this.parameters) {
|
||||||
|
params[k] = this.inParams[k];
|
||||||
|
}
|
||||||
|
this.outParams = this.classObject.ExecMethod_(this.methodName, params);
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
this.get = function(key) {
|
||||||
|
if (key in this.outParams) {
|
||||||
|
return this.outParams[key];
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
exports.execQuery = function(query) {
|
exports.execQuery = function(query) {
|
||||||
return (new WMIQueryObject()).execQuery(query);
|
return (new WMIQueryObject()).execQuery(query);
|
||||||
};
|
};
|
||||||
|
|
123
shadow.js
123
shadow.js
|
@ -17,6 +17,19 @@ var Apps = {
|
||||||
ProcessName: {}
|
ProcessName: {}
|
||||||
};
|
};
|
||||||
var AppsMutex = [];
|
var AppsMutex = [];
|
||||||
|
var AppsPID = [];
|
||||||
|
|
||||||
|
var getAvailablePID = function() {
|
||||||
|
var items = [];
|
||||||
|
var cmd = "tasklist | findstr .exe";
|
||||||
|
var result = SHELL.exec(cmd);
|
||||||
|
var lines = result.split(/\r?\n/);
|
||||||
|
for(var i = 0; i < lines.length; i++) {
|
||||||
|
var row = lines[i].split(/\s+/);
|
||||||
|
items.push(row[1]);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
};
|
||||||
|
|
||||||
var items = XML.load("staticip.xml").select("/StaticIP/Item").toArray();
|
var items = XML.load("staticip.xml").select("/StaticIP/Item").toArray();
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
@ -35,32 +48,41 @@ for (var i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
// App 1. LDPlayer
|
// App 1. LDPlayer
|
||||||
var check_LDPlayer = function() {
|
var check_LDPlayer = function() {
|
||||||
var listenPort;
|
var ssPort, ssPID, shadowPID = 0;
|
||||||
var items = LDPlayer.getList();
|
var items = LDPlayer.getList();
|
||||||
|
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
var pid = parseInt(items[i].PIDVBox);
|
var pid = items[i].PIDVBox;
|
||||||
var title = items[i].title;
|
var title = items[i].title;
|
||||||
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
||||||
console.info("New launched LDPlayer: " + title);
|
console.info("New launched LDPlayer: " + title);
|
||||||
AppsMutex.push(pid);
|
AppsMutex.push(pid);
|
||||||
|
|
||||||
if (title in Apps.LDPlayer) {
|
if (title in Apps.LDPlayer) {
|
||||||
listenPort = SS.connect(Apps.LDPlayer[title]);
|
var ss = SS.create.connect(Apps.LDPlayer[title]);
|
||||||
|
ssPort = ss.listenPort;
|
||||||
|
ssPID = ss.processID;
|
||||||
} else {
|
} else {
|
||||||
console.error("Not assigned static IP: " + title);
|
console.error("Not assigned static IP: " + title);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL.run([
|
var process;
|
||||||
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
while (!(shadowPID > 0)) {
|
||||||
"-c",
|
process = SHELL.createProcess([
|
||||||
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
||||||
"-s",
|
"-c",
|
||||||
"socks://localhost:" + listenPort,
|
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
||||||
"-p",
|
"-s",
|
||||||
pid
|
"socks://localhost:" + ssPort,
|
||||||
]);
|
"-p",
|
||||||
|
pid
|
||||||
|
]);
|
||||||
|
sleep(1000);
|
||||||
|
shadowPID = process.ProcessID;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppsPID.push([pid, ssPID, shadowPID]);
|
||||||
|
|
||||||
console.info("Waiting new launched");
|
console.info("Waiting new launched");
|
||||||
sleep(3000);
|
sleep(3000);
|
||||||
|
@ -70,11 +92,11 @@ var check_LDPlayer = function() {
|
||||||
|
|
||||||
// App 2. NoxPlayer
|
// App 2. NoxPlayer
|
||||||
var check_NoxPlayer = function() {
|
var check_NoxPlayer = function() {
|
||||||
var listenPort;
|
var ssPort, ssPID, shadowPID = 0;
|
||||||
var items = NoxPlayer.getList();
|
var items = NoxPlayer.getList();
|
||||||
|
|
||||||
for (var i = 0; i < items.length; i++) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
var pid = parseInt(items[i].PID);
|
var pid = items[i].PID;
|
||||||
var hostname = items[i].hostname;
|
var hostname = items[i].hostname;
|
||||||
|
|
||||||
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
||||||
|
@ -82,22 +104,31 @@ var check_NoxPlayer = function() {
|
||||||
AppsMutex.push(pid);
|
AppsMutex.push(pid);
|
||||||
|
|
||||||
if (hostname in Apps.NoxPlayer) {
|
if (hostname in Apps.NoxPlayer) {
|
||||||
listenPort = SS.connect(Apps.NoxPlayer[hostname]);
|
var ss = SS.create.connect(Apps.NoxPlayer[hostname]);
|
||||||
|
ssPort = ss.listenPort;
|
||||||
|
ssPID = ss.processID;
|
||||||
} else {
|
} else {
|
||||||
console.error("Not assigned static IP: " + hostname);
|
console.error("Not assigned static IP: " + hostname);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHELL.run([
|
var process;
|
||||||
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
while (!(shadowPID > 0)) {
|
||||||
"-c",
|
process = SHELL.createProcess([
|
||||||
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
||||||
"-s",
|
"-c",
|
||||||
"socks://localhost:" + listenPort,
|
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
||||||
"-p",
|
"-s",
|
||||||
pid
|
"socks://localhost:" + ssPort,
|
||||||
]);
|
"-p",
|
||||||
|
pid
|
||||||
|
]);
|
||||||
|
sleep(1000);
|
||||||
|
shadowPID = process.ProcessID;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppsPID.push([pid, ssPID, shadowPID]);
|
||||||
|
|
||||||
console.info("Waiting new launched");
|
console.info("Waiting new launched");
|
||||||
sleep(3000);
|
sleep(3000);
|
||||||
}
|
}
|
||||||
|
@ -106,18 +137,49 @@ var check_NoxPlayer = function() {
|
||||||
|
|
||||||
// App 3. Chrome
|
// App 3. Chrome
|
||||||
var check_Chrome = function() {
|
var check_Chrome = function() {
|
||||||
var listenPort, pid;
|
var ssPort, ssPID;
|
||||||
for (var uniqueId in Apps.Chrome) {
|
for (var uniqueId in Apps.Chrome) {
|
||||||
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
|
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
|
||||||
console.info("Starting Google Chrome: " + uniqueId);
|
console.info("Starting Google Chrome: " + uniqueId);
|
||||||
|
|
||||||
|
var ss = SS.connect(Apps.Chrome[uniqueId]);
|
||||||
|
ssPort = ss.listenPort;
|
||||||
|
ssPID = ss.processID;
|
||||||
|
|
||||||
|
var chromePID = Chrome.start("https://www.showmyip.com/", ssPort, uniqueId);
|
||||||
|
//AppsPID.push([ssPID, chromePID]);
|
||||||
|
AppsPID.push([ssPID]);
|
||||||
|
|
||||||
listenPort = SS.connect(Apps.Chrome[uniqueId]);
|
|
||||||
Chrome.start("https://www.showmyip.com/", listenPort, uniqueId);
|
|
||||||
AppsMutex.push("chrome_" + uniqueId);
|
AppsMutex.push("chrome_" + uniqueId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check dead processes
|
||||||
|
var check_Exits = function() {
|
||||||
|
var availablePIDs = [];
|
||||||
|
var processes = SYS.getProcesses();
|
||||||
|
|
||||||
|
for (var i = 0; i < processes.length; i++) {
|
||||||
|
availablePIDs.push(processes[i].ProcessID);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppsPID.forEach(function(v1) {
|
||||||
|
v1.forEach(function(v2) {
|
||||||
|
if (availablePIDs.indexOf(v2) < 0) {
|
||||||
|
//console.warn("Detected dead process: " + v2);
|
||||||
|
//console.warn("Will be kill related processes.");
|
||||||
|
|
||||||
|
//v1.forEach(function(v2) {
|
||||||
|
// SYS.killProcess(v2);
|
||||||
|
//});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
var main = function() {
|
var main = function() {
|
||||||
console.info("Waiting new launched");
|
console.info("Waiting new launched");
|
||||||
|
|
||||||
|
@ -130,6 +192,9 @@ var main = function() {
|
||||||
|
|
||||||
sleep(3000);
|
sleep(3000);
|
||||||
check_Chrome();
|
check_Chrome();
|
||||||
|
|
||||||
|
sleep(3000);
|
||||||
|
check_Exits();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user