This commit is contained in:
Namhyeon Go 2020-11-09 19:06:34 +09:00
parent 3a2eb32b72
commit 0adba310f2
10 changed files with 201 additions and 271 deletions

View File

@ -10,7 +10,7 @@ var SHELL = require("lib/shell");
var LDPlayer = require("lib/ldplayer");
var NoxPlayer = require("lib/noxplayer");
var apiUrl = CONFIG.readConfig("/Config/ApiUrl").first().text;
var apiUrl = CONFIG.readConfig("/ApiUrl").first().getText();
var token, userId;
var servers = [];

View File

@ -4,49 +4,14 @@
var XML = require("lib/xml");
exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
exports.global = global;
exports.require = require;
var getStream_StringToBinary = function(dText) {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
BinaryStream.Open();
BinaryStream.WriteText(dText);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeBinary;
BinaryStream.Position = 0;
return BinaryStream.Read();
};
var getStream_BinaryToString = function(dBinary) {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.Write(dBinary);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
return BinaryStream.ReadText();
};
exports.encode = function(sText) {
var oXML = XML.createXMLObject();
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
oNode.nodeTypedValue = getStream_StringToBinary(sText);
return oNode.text;
return XML.createElement("base64").encode(sText, "bin.base64");
};
exports.decode = function(vCode) {
var oXML = XML.createXMLObject();
var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64";
oNode.text = vCode;
return getStream_BinaryToString(oNode.nodeTypedValue);
return XML.createElement("base64").decode(vCode, "bin.base64");
};
exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
exports.global = global;
exports.require = require;

13
lib/chrome.js Normal file
View File

@ -0,0 +1,13 @@
//////////////////////////////////////////////////////////////////////////////////
// Google Chrome API
/////////////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var ChromeBrowser = function() {};
ChromeBrowser.prototype.open = function(profile) {
};
exports.open = ChromeBrowser.open;

View File

@ -3,14 +3,9 @@
////////////////////////////////////////////////////////////////////////
var XML = require("lib/xml");
var configObject;
var readConfig = function(path) {
if (typeof(configObject) === "undefined") {
configObject = XML.loadXMLFile("config.xml");
}
return configObject.select(path);
return XML.load("config.xml").select("/Config" + path);
};
exports.readConfig = readConfig;

View File

@ -1,21 +0,0 @@
////////////////////////////////////////////////////////////////////////
// Directus API
///////////////////////////////////////////////////////////////////////
var CONFIG = require("lib/config");
var HTTP = require("lib/http");
exports.authenticate = function() {
var apiUrl = CONFIG.readConfig("/Config/ApiUrl").first().text;
/*
var http = HTTP.post(apiUrl + "/netsolid/auth/authenticate", JSON.stringify({
"email": "admin@example.org",
"password": "1234"
}), {
"Content-Type": "application/json"
});
console.log(http.responseBody);
return http;
*/
};

View File

@ -1,157 +0,0 @@
// https://stackoverflow.com/a/58677712/3702603
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Elements = {};
Elements.DOMPath = {};
/**
* @param {!Node} node
* @param {boolean=} optimized
* @return {string}
*/
Elements.DOMPath.xPath = function (node, optimized) {
if (node.nodeType === Node.DOCUMENT_NODE) {
return '/';
}
const steps = [];
let contextNode = node;
while (contextNode) {
const step = Elements.DOMPath._xPathValue(contextNode, optimized);
if (!step) {
break;
} // Error - bail out early.
steps.push(step);
if (step.optimized) {
break;
}
contextNode = contextNode.parentNode;
}
steps.reverse();
return (steps.length && steps[0].optimized ? '' : '/') + steps.join('/');
};
/**
* @param {!Node} node
* @param {boolean=} optimized
* @return {?Elements.DOMPath.Step}
*/
Elements.DOMPath._xPathValue = function (node, optimized) {
let ownValue;
const ownIndex = Elements.DOMPath._xPathIndex(node);
if (ownIndex === -1) {
return null;
} // Error.
switch (node.nodeType) {
case Node.ELEMENT_NODE:
if (optimized && node.getAttribute('id')) {
return new Elements.DOMPath.Step('//*[@id="' + node.getAttribute('id') + '"]', true);
}
ownValue = node.localName;
break;
case Node.ATTRIBUTE_NODE:
ownValue = '@' + node.nodeName;
break;
case Node.TEXT_NODE:
case Node.CDATA_SECTION_NODE:
ownValue = 'text()';
break;
case Node.PROCESSING_INSTRUCTION_NODE:
ownValue = 'processing-instruction()';
break;
case Node.COMMENT_NODE:
ownValue = 'comment()';
break;
case Node.DOCUMENT_NODE:
ownValue = '';
break;
default:
ownValue = '';
break;
}
if (ownIndex > 0) {
ownValue += '[' + ownIndex + ']';
}
return new Elements.DOMPath.Step(ownValue, node.nodeType === Node.DOCUMENT_NODE);
};
/**
* @param {!Node} node
* @return {number}
*/
Elements.DOMPath._xPathIndex = function (node) {
// Returns -1 in case of error, 0 if no siblings matching the same expression,
// <XPath index among the same expression-matching sibling nodes> otherwise.
function areNodesSimilar(left, right) {
if (left === right) {
return true;
}
if (left.nodeType === Node.ELEMENT_NODE && right.nodeType === Node.ELEMENT_NODE) {
return left.localName === right.localName;
}
if (left.nodeType === right.nodeType) {
return true;
}
// XPath treats CDATA as text nodes.
const leftType = left.nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : left.nodeType;
const rightType = right.nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : right.nodeType;
return leftType === rightType;
}
const siblings = node.parentNode ? node.parentNode.children : null;
if (!siblings) {
return 0;
} // Root node - no siblings.
let hasSameNamedElements;
for (let i = 0; i < siblings.length; ++i) {
if (areNodesSimilar(node, siblings[i]) && siblings[i] !== node) {
hasSameNamedElements = true;
break;
}
}
if (!hasSameNamedElements) {
return 0;
}
let ownIndex = 1; // XPath indices start with 1.
for (let i = 0; i < siblings.length; ++i) {
if (areNodesSimilar(node, siblings[i])) {
if (siblings[i] === node) {
return ownIndex;
}
++ownIndex;
}
}
return -1; // An error occurred: |node| not found in parent's children.
};
/**
* @unrestricted
*/
Elements.DOMPath.Step = class {
/**
* @param {string} value
* @param {boolean} optimized
*/
constructor(value, optimized) {
this.value = value;
this.optimized = optimized || false;
}
/**
* @override
* @return {string}
*/
toString() {
return this.value;
}
};

View File

@ -1,7 +1,5 @@
//////////////////////////////////////////////////////////////////////////////////
//
// excel.js
//
// Microsoft Excel API
/////////////////////////////////////////////////////////////////////////////////
var FILE = require("lib/file");

View File

@ -6,11 +6,6 @@ var CONFIG = require("lib/config");
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = "bin\\ss-local.exe";
exports.getRandomInt = function(min, max) {
var x = Math.random();
return min + Math.floor((max - min) * x);
@ -24,13 +19,13 @@ exports.connect = function(host) {
"-s",
host,
"-p",
CONFIG.readConfig("/Config/SSPort").first().text,
CONFIG.readConfig("/SSPort").first().getText(),
"-l",
listenPort,
"-k",
CONFIG.readConfig("/Config/SSPassword").first().text,
CONFIG.readConfig("/SSPassword").first().getText(),
"-m",
CONFIG.readConfig("/Config/SSCipher").first().text
CONFIG.readConfig("/SSCipher").first().getText()
], true);
return listenPort;
@ -72,3 +67,8 @@ exports.getCountOfSessions = function() {
exports.getCountOfBridges = function() {
return exports.getCountByProcessName("shadow.exe");
};
exports.VERSIONINFO = "Shadowsocks Lib (shadowsocks.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = "bin\\ss-local.exe";

View File

@ -1,3 +1,6 @@
//////////////////////////////////////////////////////////////////////////////////
// Windows Service API
/////////////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
exports.VERSIONINFO = "Windows Service Lib (service.js) version 0.1";

View File

@ -1,7 +1,6 @@
////////////////////////////////////////////////////////////////////////
// XML API
////////////////////////////////////////////////////////////////////////
var FILE = require("lib/file");
var createXMLObject = function() {
@ -15,52 +14,187 @@ var createXMLObject = function() {
]);
};
var loadXMLFile = function(filename) {
var doc;
var StreamBuilder = function(data) {
this.data = data;
try {
doc = createXMLObject();
this.toBinary = function() {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
BinaryStream.Open();
BinaryStream.WriteText(this.data);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeBinary;
BinaryStream.Position = 0;
return BinaryStream.Read();
};
this.toString = function() {
var adTypeText = 2;
var adTypeBinary = 1;
var BinaryStream = CreateObject("ADODB.Stream");
BinaryStream.Type = adTypeBinary;
BinaryStream.Open();
BinaryStream.Write(this.data);
BinaryStream.Position = 0;
BinaryStream.Type = adTypeText;
BinaryStream.CharSet = "utf-8";
return BinaryStream.ReadText();
};
};
var XMLObject = function(node) {
this.filename = null;
this.dom = null;
this.nodes = [];
if (typeof(node) !== "undefined" && node instanceof this) {
this.dom = node;
} else {
this.dom = createXMLObject();
}
this.load = function(filename) {
this.filename = filename;
if (FILE.fileExists(filename)) {
doc.loadXML(FILE.readFile(filename, "utf-8"));
this.dom.loadXML(FILE.readFile(this.filename, "utf-8"));
} else {
console.error("The file does not exists");
return;
}
} catch(e) {
console.error(e.message);
return this;
}
this.setObject = function(dom) {
this.dom = dom;
};
this.getObject = function() {
return this.dom;
};
this.getAttribute = function(name) {
return this.getObject().getAttribute(name);
};
this.getText = function() {
return this.getObject().text;
};
this.select = function(path) {
var nodes = this.getObject().selectNodes(path);
for (var i = 0; i < nodes.length; i++) {
this.nodes.push(new XMLObject(node[i]));
}
};
this.toArray = function() {
return this.nodes;
};
this.first = function() {
if(this.nodes.length > 0) {
return this.nodes[0];
}
};
this.last = function() {
if(this.nodes.length > 0) {
return this.nodes[this.nodes.length - 1];
}
};
this.eq = function(i) {
if(nodes.length > i) {
return nodes[i];
}
}
return {
select: function(path) {
var nodes = doc.selectNodes(path);
this.retrieve = function(mode, callback) {
var nodes = [];
return {
getObject: function() {
return doc;
},
all: function() {
return nodes;
},
first: function() {
if(nodes.length > 0) {
return nodes[0];
}
},
last: function() {
if(nodes.length > 0) {
return nodes[nodes.length - 1];
}
},
eq: function(i) {
if(nodes.length > i) {
return nodes[i];
}
if (typeof(callback) === "function") {
var i = 0, s = 0;
while (s == 0 && i < this.nodes.length) {
if (callback(this.nodes[i])) {
if (mode === "find")
s++;
nodes.push(this.nodes[i]);
}
i++;
}
}
switch (mode) {
case "find":
if (nodes.length > 0)
return nodes.pop();
break;
case "filter":
this.nodes = nodes;
break;
case "forEach":
break;
}
return this;
}
this.find = function(callback) {
return this.retrieve("find", callback);
};
this.filter = function(callback) {
return this.retrieve("filter", callback);
};
this.forEach = function(callback) {
return this.retrieve("forEach", callback);
};
this.createElement = function(elementname) {
this.setObject(this.getObject().createElement(name));
}
this.encode = function(value, type) {
this.getObject().dataType = type;
if (type.indexOf("bin.") == 0) {
this.getObject().nodeTypedValue = (new StreamBuilder(value)).toBinary();
} else {
this.getObject().nodeTypedValue = value;
}
return this.getObject().text;
};
this.decode = function(value, type) {
this.getObject().dataType = type;
if (type.indexOf("bin.") == 0) {
this.getObject().text = (new StreamBuilder(value)).toString();
} else {
this.getObject().text = value;
}
return this.getObject().nodeTypedValue;
};
};
exports.createXMLObject = createXMLObject;
exports.loadXMLFile = loadXMLFile;
exports.create = createXMLObject;
exports.load = function(filename) {
return (new XMLObject()).load(filename);
};
exports.createElement = function(elementname) {
return (new XMLObject()).createElement(elementname);
};