mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-12 04:31:04 +00:00
fix
This commit is contained in:
parent
2f84b4a732
commit
8491779c6b
|
@ -6,6 +6,7 @@ var SHELL = require("lib/shell");
|
||||||
var binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
|
var binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
|
||||||
|
|
||||||
var Chrome = function() {
|
var Chrome = function() {
|
||||||
|
this.processID = 0;
|
||||||
this.profileName = "Default";
|
this.profileName = "Default";
|
||||||
this.proxyPort = 1080;
|
this.proxyPort = 1080;
|
||||||
|
|
||||||
|
@ -16,14 +17,20 @@ var Chrome = function() {
|
||||||
this.setProxyPort = function(s) {
|
this.setProxyPort = function(s) {
|
||||||
this.proxyPort = s;
|
this.proxyPort = s;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getProcessID = function() {
|
||||||
|
return this.processID;
|
||||||
|
};
|
||||||
|
|
||||||
this.open = function(url) {
|
this.open = function(url) {
|
||||||
SHELL.createProcess([
|
var process = SHELL.createProcess([
|
||||||
binPath,
|
binPath,
|
||||||
"--profile-directory=" + this.profileName,
|
"--profile-directory=" + this.profileName,
|
||||||
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
||||||
url
|
url
|
||||||
]);
|
]);
|
||||||
|
sleep(1000);
|
||||||
|
this.processID = process.ProcessID;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,4 +39,5 @@ exports.start = function(url, proxyPort, profileName) {
|
||||||
instance.setProfileName(profileName);
|
instance.setProfileName(profileName);
|
||||||
instance.setProxyPort(proxyPort);
|
instance.setProxyPort(proxyPort);
|
||||||
instance.open(url);
|
instance.open(url);
|
||||||
|
return instance.getProcessID();
|
||||||
};
|
};
|
||||||
|
|
237
shadow.js
237
shadow.js
|
@ -5,133 +5,132 @@
|
||||||
var SS = require("lib/shadowsocks");
|
var SS = require("lib/shadowsocks");
|
||||||
var SHELL = require("lib/shell");
|
var SHELL = require("lib/shell");
|
||||||
var SYS = require("lib/system");
|
var SYS = require("lib/system");
|
||||||
|
var XML = require("lib/xml");
|
||||||
var LDPlayer = require("lib/ldplayer");
|
var LDPlayer = require("lib/ldplayer");
|
||||||
var NoxPlayer = require("lib/noxplayer");
|
var NoxPlayer = require("lib/noxplayer");
|
||||||
var XML = require("lib/xml");
|
var Chrome = require("lib/chrome");
|
||||||
|
|
||||||
var PIDList = [];
|
var Apps = {
|
||||||
|
LDPlayer: {},
|
||||||
var NumSessions = 0;
|
NoxPlayer: {},
|
||||||
var _NumSessions = 0;
|
Chrome: {},
|
||||||
var NumBridges = 0;
|
ProcessName: {}
|
||||||
var _NumBridges = 0;
|
|
||||||
|
|
||||||
var StaticIP = {
|
|
||||||
LDPlayer: {},
|
|
||||||
NoxPlayer: {}
|
|
||||||
};
|
};
|
||||||
|
var AppsMutex = [];
|
||||||
var items = XML.loadXMLFile("staticip.xml").select("/StaticIP/Item").all();
|
|
||||||
|
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++) {
|
||||||
try {
|
try {
|
||||||
var Name = items[i].selectSingleNode("Name").text;
|
var name = items[i].select("Name").first().getText();
|
||||||
var UniqueID = items[i].selectSingleNode("UniqueID").text;
|
var uniqueId = items[i].select("UniqueID").first().getText();
|
||||||
var IPAddress = items[i].selectSingleNode("IPAddress").text;
|
var ipAddress = items[i].select("IPAddress").first().getText();
|
||||||
StaticIP[Name][UniqueID] = IPAddress;
|
|
||||||
} catch(e) {
|
if (name in Apps) {
|
||||||
console.error(e.message);
|
Apps[name][uniqueId] = ipAddress;
|
||||||
}
|
}
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.main = function() {
|
// App 1. LDPlayer
|
||||||
console.info("Waiting new launched");
|
var check_LDPlayer = function() {
|
||||||
sleep(3000);
|
var listenPort;
|
||||||
|
var items = LDPlayer.getList();
|
||||||
|
|
||||||
while (true) {
|
for (var i = 0; i < items.length; i++) {
|
||||||
sleep(3000);
|
var pid = parseInt(items[i].PIDVBox);
|
||||||
|
var title = items[i].title;
|
||||||
|
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
||||||
|
console.info("New launched LDPlayer: " + title);
|
||||||
|
AppsMutex.push(pid);
|
||||||
|
|
||||||
|
if (title in Apps.LDPlayer) {
|
||||||
|
listenPort = SS.connect(Apps.LDPlayer[title]);
|
||||||
|
} else {
|
||||||
|
console.error("Not assigned static IP: " + title);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
SHELL.run([
|
||||||
// LDPlayer
|
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
||||||
////////////////////////////////////////////////////////////////
|
"-c",
|
||||||
|
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
||||||
|
"-s",
|
||||||
|
"socks://localhost:" + listenPort,
|
||||||
|
"-p",
|
||||||
|
pid
|
||||||
|
]);
|
||||||
|
|
||||||
var LDPList = LDPlayer.getList();
|
console.info("Waiting new launched");
|
||||||
for (var i = 0; i < LDPList.length; i++) {
|
sleep(3000);
|
||||||
var pid = parseInt(LDPList[i].PIDVBox);
|
}
|
||||||
var title = LDPList[i].title;
|
}
|
||||||
if (pid > 0 && PIDList.indexOf(pid) == -1) {
|
|
||||||
console.info("New launched LDPlayer: " + title);
|
|
||||||
|
|
||||||
PIDList.push(pid);
|
|
||||||
|
|
||||||
var listenPort;
|
|
||||||
if (!(title in StaticIP.LDPlayer)) {
|
|
||||||
console.error("Not assigned static IP: " + title);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
listenPort = SS.connect(StaticIP.LDPlayer[title]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SHELL.run([
|
|
||||||
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
|
||||||
"-c",
|
|
||||||
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
|
||||||
"-s",
|
|
||||||
"socks://localhost:" + listenPort,
|
|
||||||
"-p",
|
|
||||||
pid
|
|
||||||
]);
|
|
||||||
|
|
||||||
NumSessions = SS.getCountOfSessions();
|
|
||||||
NumBridges = SS.getCountOfBridges();
|
|
||||||
|
|
||||||
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
|
||||||
console.error("Retrying...");
|
|
||||||
PIDList.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
_NumSessions = NumSessions;
|
|
||||||
_NumBridges = NumBridges;
|
|
||||||
|
|
||||||
console.info("Waiting new launched");
|
|
||||||
sleep(3000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// NoxPlayer
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
var NoxPList = NoxPlayer.getList();
|
|
||||||
for (var i = 0; i < NoxPList.length; i++) {
|
|
||||||
var pid = parseInt(NoxPList[i].PID);
|
|
||||||
var hostname = NoxPList[i].hostname;
|
|
||||||
if (pid > 0 && PIDList.indexOf(pid) == -1) {
|
|
||||||
console.info("New launched NoxPlayer: " + hostname);
|
|
||||||
|
|
||||||
PIDList.push(pid);
|
|
||||||
|
|
||||||
var listenPort;
|
|
||||||
if (!(hostname in StaticIP.NoxPlayer)) {
|
|
||||||
console.error("Not assigned static IP: " + hostname);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
listenPort = SS.connect(StaticIP.NoxPlayer[hostname]);
|
|
||||||
}
|
|
||||||
|
|
||||||
SHELL.run([
|
|
||||||
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
|
||||||
"-c",
|
|
||||||
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
|
||||||
"-s",
|
|
||||||
"socks://localhost:" + listenPort,
|
|
||||||
"-p",
|
|
||||||
pid
|
|
||||||
]);
|
|
||||||
|
|
||||||
NumSessions = SS.getCountOfSessions();
|
|
||||||
NumBridges = SS.getCountOfBridges();
|
|
||||||
|
|
||||||
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
|
||||||
console.error("Retrying...");
|
|
||||||
PIDList.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
_NumSessions = NumSessions;
|
|
||||||
_NumBridges = NumBridges;
|
|
||||||
|
|
||||||
console.info("Waiting new launched");
|
|
||||||
sleep(3000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// App 2. NoxPlayer
|
||||||
|
var check_NoxPlayer = function() {
|
||||||
|
var listenPort;
|
||||||
|
var items = NoxPlayer.getList();
|
||||||
|
|
||||||
|
for (var i = 0; i < items.length; i++) {
|
||||||
|
var pid = parseInt(items[i].PID);
|
||||||
|
var hostname = items[i].hostname;
|
||||||
|
|
||||||
|
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
|
||||||
|
console.info("New launched NoxPlayer: " + title);
|
||||||
|
AppsMutex.push(pid);
|
||||||
|
|
||||||
|
if (title in Apps.NoxPlayer) {
|
||||||
|
listenPort = SS.connect(Apps.NoxPlayer[title]);
|
||||||
|
} else {
|
||||||
|
console.error("Not assigned static IP: " + hostname);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
SHELL.run([
|
||||||
|
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
|
||||||
|
"-c",
|
||||||
|
SYS.getCurrentScriptDirectory() + "/config.template.json",
|
||||||
|
"-s",
|
||||||
|
"socks://localhost:" + listenPort,
|
||||||
|
"-p",
|
||||||
|
pid
|
||||||
|
]);
|
||||||
|
|
||||||
|
console.info("Waiting new launched");
|
||||||
|
sleep(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// App 3. Chrome
|
||||||
|
var check_Chrome = function() {
|
||||||
|
var listenPort, pid;
|
||||||
|
for (var uniqueId in Apps.Chrome) {
|
||||||
|
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
|
||||||
|
console.info("Starting Google Chrome: " + uniqueId);
|
||||||
|
|
||||||
|
listenPort = SS.connect(Apps.Chrome[uniqueId]);
|
||||||
|
Chrome.start("https://naver.com", listenPort, uniqueId);
|
||||||
|
AppsMutex.push("chrome_" + uniqueId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var main = function() {
|
||||||
|
console.info("Waiting new launched");
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
sleep(3000);
|
||||||
|
check_LDPlayer();
|
||||||
|
|
||||||
|
sleep(3000);
|
||||||
|
check_NoxPlayer();
|
||||||
|
|
||||||
|
sleep(3000);
|
||||||
|
check_Chrome();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.main = main;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user