mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-14 13:41:05 +00:00
enhance feature of CreateObject
This commit is contained in:
parent
eda780811c
commit
c38f6a8858
|
@ -6,27 +6,21 @@ exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = require;
|
exports.require = require;
|
||||||
|
|
||||||
exports.createMSXMLObject = function() {
|
var createMSXMLObject = function() {
|
||||||
var progIDs = [
|
return CreateObject([
|
||||||
"Msxml2.DOMDocument.6.0",
|
"Msxml2.DOMDocument.6.0",
|
||||||
"Msxml2.DOMDocument.5.0",
|
"Msxml2.DOMDocument.5.0",
|
||||||
"Msxml2.DOMDocument.4.0",
|
"Msxml2.DOMDocument.4.0",
|
||||||
"Msxml2.DOMDocument.3.0",
|
"Msxml2.DOMDocument.3.0",
|
||||||
"MSXML2.DOMDocument",
|
"MSXML2.DOMDocument",
|
||||||
"MSXML.DOMDocument"
|
"MSXML.DOMDocument"
|
||||||
];
|
]);
|
||||||
for (var i = 0; i < progIDs.length; i++) {
|
|
||||||
try {
|
|
||||||
return new ActiveXObject(progIDs[i]);
|
|
||||||
} catch(e) {};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getStream_StringToBinary = function(dText) {
|
var getStream_StringToBinary = function(dText) {
|
||||||
var adTypeText = 2;
|
var adTypeText = 2;
|
||||||
var adTypeBinary = 1;
|
var adTypeBinary = 1;
|
||||||
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
var BinaryStream = CreateObject("ADODB.Stream");
|
||||||
BinaryStream.Type = adTypeText;
|
BinaryStream.Type = adTypeText;
|
||||||
BinaryStream.CharSet = "utf-8";
|
BinaryStream.CharSet = "utf-8";
|
||||||
BinaryStream.Open();
|
BinaryStream.Open();
|
||||||
|
@ -37,10 +31,10 @@ exports.getStream_StringToBinary = function(dText) {
|
||||||
return BinaryStream.Read();
|
return BinaryStream.Read();
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getStream_BinaryToString = function(dBinary) {
|
var getStream_BinaryToString = function(dBinary) {
|
||||||
var adTypeText = 2;
|
var adTypeText = 2;
|
||||||
var adTypeBinary = 1;
|
var adTypeBinary = 1;
|
||||||
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
var BinaryStream = CreateObject("ADODB.Stream");
|
||||||
BinaryStream.Type = adTypeBinary;
|
BinaryStream.Type = adTypeBinary;
|
||||||
BinaryStream.Open();
|
BinaryStream.Open();
|
||||||
BinaryStream.Write(dBinary);
|
BinaryStream.Write(dBinary);
|
||||||
|
@ -51,17 +45,17 @@ exports.getStream_BinaryToString = function(dBinary) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.encode = function(sText) {
|
exports.encode = function(sText) {
|
||||||
var oXML = exports.createMSXMLObject();
|
var oXML = createMSXMLObject();
|
||||||
var oNode = oXML.createElement("base64");
|
var oNode = oXML.createElement("base64");
|
||||||
oNode.dataType = "bin.base64";
|
oNode.dataType = "bin.base64";
|
||||||
oNode.nodeTypedValue = exports.getStream_StringToBinary(sText);
|
oNode.nodeTypedValue = getStream_StringToBinary(sText);
|
||||||
return oNode.text;
|
return oNode.text;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.decode = function(vCode) {
|
exports.decode = function(vCode) {
|
||||||
var oXML = exports.createMSXMLObject();
|
var oXML = createMSXMLObject();
|
||||||
var oNode = oXML.createElement("base64");
|
var oNode = oXML.createElement("base64");
|
||||||
oNode.dataType = "bin.base64";
|
oNode.dataType = "bin.base64";
|
||||||
oNode.text = vCode;
|
oNode.text = vCode;
|
||||||
return exports.getStream_BinaryToString(oNode.nodeTypedValue);
|
return getStream_BinaryToString(oNode.nodeTypedValue);
|
||||||
};
|
};
|
||||||
|
|
40
lib/httpserver.js
Normal file
40
lib/httpserver.js
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// HTTPServer API
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var SHELL = require("lib/shell");
|
||||||
|
|
||||||
|
var ResponseCodes = {
|
||||||
|
100: "Continue",
|
||||||
|
200: "OK",
|
||||||
|
206: "Partial Content",
|
||||||
|
301: "Moved Permanently",
|
||||||
|
302: "Found",
|
||||||
|
304: "Not Modified",
|
||||||
|
400: "Bad Request",
|
||||||
|
401: "Unauthorized",
|
||||||
|
403: "Forbidden",
|
||||||
|
404: "Not Found",
|
||||||
|
500: "Internal Server Error",
|
||||||
|
503: "Service Unavailable"
|
||||||
|
};
|
||||||
|
|
||||||
|
var listener, http = {};
|
||||||
|
|
||||||
|
var listen = function(port) {
|
||||||
|
try {
|
||||||
|
listener = CreateObject("MSWinsock.Winsock.1", "listener_");
|
||||||
|
listener.localPort = port;
|
||||||
|
listener.bind();
|
||||||
|
listener.listen();
|
||||||
|
console.info("Listening port: " + port);
|
||||||
|
} catch(e) {
|
||||||
|
console.error("port " + port " could not bind: " + e.message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var arrival = function() {
|
||||||
|
// todo
|
||||||
|
};
|
||||||
|
|
||||||
|
// todo
|
|
@ -8,21 +8,20 @@ var SYS = require("lib/system");
|
||||||
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
|
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
|
||||||
exports.global = global;
|
exports.global = global;
|
||||||
exports.require = global.require;
|
exports.require = global.require;
|
||||||
exports.binPath = "bin/ss-local.exe";
|
exports.binPath = "bin\\ss-local.exe";
|
||||||
|
|
||||||
exports.getRandomInt = function(min, max) {
|
exports.getRandomInt = function(min, max) {
|
||||||
var x = Math.random();
|
var x = Math.random();
|
||||||
return min + Math.floor((max - min) * x);
|
return min + Math.floor((max - min) * x);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.connect = function() {
|
exports.connect = function(host) {
|
||||||
var listenPort = 1080;
|
var listenPort = exports.getRandomInt(49152, 65535);
|
||||||
//var listenPort = exports.getRandomInt(49152, 65535);
|
|
||||||
|
|
||||||
SHELL.run([
|
SHELL.run([
|
||||||
exports.binPath,
|
exports.binPath,
|
||||||
"-s",
|
"-s",
|
||||||
__config.shadowsocks.host,
|
host,
|
||||||
"-p",
|
"-p",
|
||||||
__config.shadowsocks.port,
|
__config.shadowsocks.port,
|
||||||
"-l",
|
"-l",
|
||||||
|
@ -35,3 +34,25 @@ exports.connect = function() {
|
||||||
|
|
||||||
return listenPort;
|
return listenPort;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.getCountByProcessName = function(processName) {
|
||||||
|
var num = 0;
|
||||||
|
var cmd = "tasklist | findstr " + processName;
|
||||||
|
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+/);
|
||||||
|
if(row[0] == processName) {
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getCountOfSessions = function() {
|
||||||
|
return exports.getCountByProcessName("ss-local.exe");
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getCountOfBridges = function() {
|
||||||
|
return exports.getCountByProcessName("shadow.exe");
|
||||||
|
};
|
||||||
|
|
|
@ -63,6 +63,7 @@ exports.run = function(cmd, fork) {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.elevatedRun = function(FN, args) {
|
exports.elevatedRun = function(FN, args) {
|
||||||
|
console.info("elevatedRun() -> " + FN + " " + args.join(' '));
|
||||||
var oShell = CreateObject("Shell.Application");
|
var oShell = CreateObject("Shell.Application");
|
||||||
oShell.shellExecute(FN, args, null, "runas", 0);
|
oShell.shellExecute(FN, args, null, "runas", 0);
|
||||||
return oShell;
|
return oShell;
|
||||||
|
|
16
lib/std.js
16
lib/std.js
|
@ -76,8 +76,20 @@ exports.require = global.require;
|
||||||
// Emulate Server.CreateObject
|
// Emulate Server.CreateObject
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
exports.CreateObject = function(n) {
|
exports.CreateObject = function(objectName) {
|
||||||
return new ActiveXObject(n);
|
var objectNames = [];
|
||||||
|
|
||||||
|
if(typeof(objectName) == "object") {
|
||||||
|
objectNames = objectName;
|
||||||
|
} else {
|
||||||
|
objectNames.push(objectName);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < objectNames.length; i++) {
|
||||||
|
try {
|
||||||
|
return new ActiveXObject(objectNames[i]);
|
||||||
|
} catch(e) {};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// SSloader
|
// ShadowLoader
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var SS = require("lib/shadowsocks");
|
var SS = require("lib/shadowsocks");
|
||||||
|
@ -21,23 +21,24 @@ exports.main = function() {
|
||||||
console.info("Waiting new launched");
|
console.info("Waiting new launched");
|
||||||
sleep(10000);
|
sleep(10000);
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
sleep(10000);
|
sleep(10000);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
// LDPlayer
|
// LDPlayer
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var LDPList = LDPlayer.getList();
|
var LDPList = LDPlayer.getList();
|
||||||
for(var i = 0; i < LDPList.length; i++) {
|
for (var i = 0; i < LDPList.length; i++) {
|
||||||
var pid = parseInt(LDPList[i].PIDVBox);
|
var pid = parseInt(LDPList[i].PIDVBox);
|
||||||
var title = LDPList[i].title;
|
var title = LDPList[i].title;
|
||||||
if(pid > 0 && PIDList.indexOf(pid) == -1) {
|
if (pid > 0 && PIDList.indexOf(pid) == -1) {
|
||||||
console.info("New launched LDPlayer: " + title);
|
console.info("New launched LDPlayer: " + title);
|
||||||
|
|
||||||
PIDList.push(pid);
|
PIDList.push(pid);
|
||||||
|
|
||||||
var listenPort;
|
var listenPort;
|
||||||
if(!(title in __config.StaticIP.LDPlayer)) {
|
if (!(title in __config.StaticIP.LDPlayer)) {
|
||||||
console.error("Not assigned static IP: " + title);
|
console.error("Not assigned static IP: " + title);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,7 +58,7 @@ exports.main = function() {
|
||||||
NumSessions = SS.getCountOfSessions();
|
NumSessions = SS.getCountOfSessions();
|
||||||
NumBridges = SS.getCountOfBridges();
|
NumBridges = SS.getCountOfBridges();
|
||||||
|
|
||||||
if(!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
||||||
console.error("Retrying...");
|
console.error("Retrying...");
|
||||||
PIDList.pop();
|
PIDList.pop();
|
||||||
}
|
}
|
||||||
|
@ -75,16 +76,16 @@ exports.main = function() {
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var NoxPList = NoxPlayer.getList();
|
var NoxPList = NoxPlayer.getList();
|
||||||
for(var i = 0; i < NoxPList.length; i++) {
|
for (var i = 0; i < NoxPList.length; i++) {
|
||||||
var pid = parseInt(NoxPList[i].PID);
|
var pid = parseInt(NoxPList[i].PID);
|
||||||
var hostname = NoxPList[i].hostname;
|
var hostname = NoxPList[i].hostname;
|
||||||
if(pid > 0 && PIDList.indexOf(pid) == -1) {
|
if (pid > 0 && PIDList.indexOf(pid) == -1) {
|
||||||
console.info("New launched NoxPlayer: " + hostname);
|
console.info("New launched NoxPlayer: " + hostname);
|
||||||
|
|
||||||
PIDList.push(pid);
|
PIDList.push(pid);
|
||||||
|
|
||||||
var listenPort;
|
var listenPort;
|
||||||
if(!(hostname in __config.StaticIP.NoxPlayer)) {
|
if (!(hostname in __config.StaticIP.NoxPlayer)) {
|
||||||
console.error("Not assigned static IP: " + hostname);
|
console.error("Not assigned static IP: " + hostname);
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +105,7 @@ exports.main = function() {
|
||||||
NumSessions = SS.getCountOfSessions();
|
NumSessions = SS.getCountOfSessions();
|
||||||
NumBridges = SS.getCountOfBridges();
|
NumBridges = SS.getCountOfBridges();
|
||||||
|
|
||||||
if(!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
if (!(NumSessions > _NumSessions && NumBridges > _NumBridges)) {
|
||||||
console.error("Retrying...");
|
console.error("Retrying...");
|
||||||
PIDList.pop();
|
PIDList.pop();
|
||||||
}
|
}
|
||||||
|
@ -118,4 +119,3 @@ exports.main = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user