Remove no registered files

This commit is contained in:
Namhyeon Go 2020-12-29 17:11:23 +09:00
parent 7062b08613
commit 4ee77ff7f4
23 changed files with 12 additions and 1406 deletions

1
.gitignore vendored
View File

@ -107,4 +107,3 @@ dist
bin/
packages/
config.xml
staticip.xml

View File

@ -1,352 +1,5 @@
////////////////////////////////////////////////////////////////////////
// index.js
////////////////////////////////////////////////////////////////////////
var CONFIG = require("lib/config");
var FILE = require("lib/file");
var OldBrowser = require("lib/oldbrowser");
var HTTP = require("lib/http");
var SYS = require("lib/system");
var SHELL = require("lib/shell");
var LDPlayer = require("lib/ldplayer");
var NoxPlayer = require("lib/noxplayer");
////////////////////////////////////////////////////////////////////////\
var token, userId;
var apiUrl = CONFIG.getValue("ApiUrl");
var servers = [];
var applications = [];
var localApplications = [];
var assign = function() {
SHELL.runVisibleWindow("cscript app.js shadow");
};
/*
var pingtest = function() {
for (var i = 0; i < servers.length; i++) {
servers[i].entry.find("span.status").text(SYS.ping(servers[i].data.ipaddress) + " ms");
}
};
*/
var getLocalApplications = function() {
// LDPlayer
var LDPList = LDPlayer.getList();
for (var i = 0; i < LDPList.length; i++) {
localApplications.push({
name: "LDPlayer",
uniqueId: LDPList[i].title
});
}
// NoxPlayer
var NoxPList = NoxPlayer.getList();
for (var i = 0; i < NoxPList.length; i++) {
localApplications.push({
name: "NoxPlayer",
uniqueId: NoxPList[i].title
});
}
// Chrome
/*
localApplications.push({
name: "Chrome",
uniqueId: "John"
});
localApplications.push({
name: "Chrome",
uniqueId: "James"
});
localApplications.push({
name: "Chrome",
uniqueId: "Jasmine"
});
*/
var template = $("#listview_applications .template");
for (var i = 0; i < servers.length; i++) {
template.find("select").append($("<option/>").attr({
value: servers[i].data.id
}).text(servers[i].data.ipaddress + (servers[i].data.status !== "published" ? "(점검중)" : "")));
}
for (var i = 0; i < localApplications.length; i++) {
var serverId = "";
var entry = template.clone();
entry.find("a.title").text(localApplications[i].uniqueId + " (" + localApplications[i].name + ")");
entry.find("select").data("application-name", localApplications[i].name);
entry.find("select").data("application-unique-id", localApplications[i].uniqueId);
for (var k = 0; k < applications.length; k++) {
if (applications[k].name == localApplications[i].name
&& applications[k].uniqueId == localApplications[i].uniqueId
&& applications[k].createdBy == userId)
{
entry.find("select").data("application-id", applications[k].id);
serverId = applications[k].server;
break;
}
}
entry.find("select").change(function() {
if ($(this).val() != "") {
var data = {
"status": "published",
"name": $(this).data("application-name"),
"unique_id": $(this).data("application-unique-id"),
"created_by": userId,
"server": $(this).val()
};
var applicationId = $(this).data("application-id");
var req, res;
var onSuccess = function(res) {
if ("error" in res) {
console.error(res.error.message);
} else {
console.log("반영되었습니다.");
}
};
if (applicationId) {
HTTP.create()
.setContentType("application/json-patch+json")
.setBearerAuth(token)
.setRequestBody(JSON.stringify(data))
.patch(apiUrl + "/netsolid/items/applications/" + applicationId, onSuccess)
;
} else {
HTTP.create()
.setContentType("application/json")
.setBearerAuth(token)
.setRequestBody(data)
.post(apiUrl + "/netsolid/items/applications", onSuccess)
;
}
}
}).val(serverId);
entry.appendTo("#listview_applications");
}
template.css("display", "none");
};
var getMyApplications = function() {
var onSuccess = function(res) {
var xmlStrings = [];
xmlStrings.push('<?xml version="1.0" encoding="UTF-8"?>');
xmlStrings.push("<StaticIP>");
for (var i = 0; i < res.data.length; i++) {
if (res.data[i].created_by == userId) {
xmlStrings.push("<Item>");
xmlStrings.push("<Name>" + res.data[i].name + "</Name>");
xmlStrings.push("<UniqueID>" + res.data[i].unique_id + "</UniqueID>");
for (var k = 0; k < servers.length; k++) {
if (servers[k].data.id == res.data[i].server) {
xmlStrings.push("<IPAddress>" + servers[k].data.ipaddress + "</IPAddress>");
applications.push({
id: res.data[i].id,
name: res.data[i].name,
uniqueId: res.data[i].unique_id,
server: res.data[i].server,
ipAddress: servers[k].data.ipaddress,
createdBy: userId
});
}
}
xmlStrings.push("</Item>");
// for Chrome
if (res.data[i].name == "Chrome") {
localApplications.push({
name: "Chrome",
uniqueId: res.data[i].unique_id
});
}
}
}
xmlStrings.push("</StaticIP>");
FILE.writeFile("staticip.xml", xmlStrings.join("\r\n"), "utf-8");
getLocalApplications();
};
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.setUseCache(false)
.setParameters({
"filter[created_by][eq]": userId
})
.get(apiUrl + "/netsolid/items/applications", onSuccess)
;
};
var getMyServers = function(assignedServers) {
var onSuccess = function(res) {
var template = $("#listview_servers .template");
for (var i = 0; i < res.data.length; i++) {
if (assignedServers.indexOf(res.data[i].id) > -1) {
var entry = template.clone();
entry.find("a.title").text(res.data[i].ipaddress);
entry.find("div.description").text(res.data[i].name);
entry.find("span.status").text(res.data[i].status !== "published" ? "점검중" : "사용가능");
entry.appendTo("#listview_servers");
servers.push({
"data": res.data[i],
"entry": entry
});
}
}
template.css("display", "none");
}
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.setUseCache(false)
.setParameters({
//"filter[status][eq]": "published", // get only available items
"filter[id][in]": assignedServers.join(','),
"limit": "-1"
})
.get(apiUrl + "/netsolid/items/servers", onSuccess)
;
//pingtest();
//setInterval(pingtest, 5000);
//document.getElementById("btn_pingtest").onclick = pingtest;
getMyApplications();
};
var getAssignedServers = function() {
var onSuccess = function(res) {
var assignedServers = [];
for (var i = 0; i < res.data.length; i++) {
if (res.data[i].assigned_to == userId) {
assignedServers.push(res.data[i].server);
}
}
getMyServers(assignedServers);
};
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.setUseCache(false)
.setParameters({
//"filter[status][eq]": "published", // get only available items
"filter[assigned_to][eq]": userId
})
.get(apiUrl + "/netsolid/items/assignedservers", onSuccess)
;
};
var getNotices = function() {
var onSuccess = function(res) {
var template = $("#listview_notices .template");
for (var i = 0; i < res.data.length; i++) {
var entry = template.clone();
entry.find("a.title").text(res.data[i].title);
entry.find("div.description").text(res.data[i].content);
entry.find("span.status").text(res.data[i].created_on.substring(0, 10));
entry.appendTo("#listview_notices");
}
template.css("display", "none");
};
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setParameters({
"filter[status][eq]": "published", // get only available items
"sort": "-created_on",
"limit": 3
})
.setBearerAuth(token)
.setUseCache(false)
.get(apiUrl + "/netsolid/items/notices", onSuccess)
;
};
if (FILE.fileExists("token.txt")) {
token = FILE.readFile("token.txt", "utf-8");
}
if (FILE.fileExists("userid.txt")) {
userId = FILE.readFile("userid.txt", "utf-8");
}
if (typeof(token) !== "undefined") {
OldBrowser.setContent(FILE.readFile("app\\servers.html", "utf-8"));
getAssignedServers();
getNotices();
document.getElementById("btn_logout").onclick = function() {
if (FILE.fileExists("token.txt")) {
token = FILE.deleteFile("token.txt")
}
if (FILE.fileExists("userid.txt")) {
userId = FILE.deleteFile("userid.txt");
}
exit(0);
};
document.getElementById("btn_refresh").onclick = function() {
OldBrowser.reload();
};
document.getElementById("btn_close").onclick = function() {
OldBrowser.close();
};
document.getElementById("version").innerHTML = "현재 버전: " + CONFIG.getValue("Version");
assign();
} else {
OldBrowser.setContent(FILE.readFile("app\\login.html", "utf-8"));
document.getElementById("loginform").onsubmit = function(ev) {
ev.preventDefault();
};
if (FILE.fileExists("credential.json")) {
var credential = JSON.parse(FILE.readFile("credential.json", "utf-8"));
document.getElementById("txt_email").value = credential.email;
document.getElementById("txt_password").value = credential.password;
}
document.getElementById("btn_submit").onclick = function() {
var credential = {
"email": document.getElementById("txt_email").value,
"password": document.getElementById("txt_password").value
};
HTTP.create()
.setContentType("application/json")
.setRequestBody(credential)
.post(apiUrl + "/netsolid/auth/authenticate", function(res) {
if ("error" in res) {
console.error(res.error.message);
} else if ("data" in res) {
console.log("ok");
FILE.writeFile("credential.json", JSON.stringify(credential), "utf-8");
FILE.writeFile("token.txt", res.data.token, "utf-8");
FILE.writeFile("userid.txt", res.data.user.id, "utf-8");
OldBrowser.reload();
}
})
;
};
}
// write your code ...

View File

@ -1,73 +0,0 @@
<div class="cell">
<div class="col width-fill">
<div class="col">
<div class="cell panel">
<div class="header">
로그인
</div>
<div class="body">
<div class="col">
<div class="cell">
<form id="loginform" method="post" action="#">
<div class="col">
<div class="col width-1of5">
<div class="cell">
<label for="login">이메일:</label>
</div>
</div>
<div class="col width-fill">
<div class="cell">
<input type="text" id="txt_email" class="text">
</div>
</div>
</div>
<div class="col">
<div class="col width-1of5">
<div class="cell">
<label for="password">비밀번호:</label>
</div>
</div>
<div class="col width-fill">
<div class="cell">
<input type="password" id="txt_password" class="text password">
</div>
</div>
</div>
<div class="col">
<div class="col width-1of5">
<div class="cell"></div>
</div>
<div class="col width-fill">
<div class="cell">
<button id="btn_submit" class="button" type="submit">로그인</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="cell panel">
<div class="header">
도움말
</div>
<div class="body">
<div class="col">
<div class="cell menu">
<ul class="left nav links">
<li><a href="#">회원가입 안내</a></li>
<li><a href="#">아이디/비밀번호 찾기</a></li>
<li><a href="#">이용약관</a></li>
<li><a href="#">개인정보보호정책</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,99 +0,0 @@
<div class="cell">
<div class="col">
<div id="listview_notices" class="cell panel">
<div class="header">공지사항</div>
<div class="template body">
<div class="cell">
<div class="col">
<div class="col width-fit mobile-width-fit"><span class="icon icon-bell color-blue"></span></div>
<div class="col width-fill mobile-width-fill">
<span class="float-right">
<span class="status text">
N/A
</span>
<span class="icon icon-time"></span>
</span>
<div class="col width-fill mobile-width-fill">
<a class="title fatty" href="#">Repo 1</a>
</div>
<div class="description col">
<span class="text">This is one of my coolest repos.</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="cell">
<div class="col width-1of2">
<div id="listview_servers" class="cell panel">
<div class="header">서버 목록</div>
<div class="template body">
<div class="cell">
<div class="col">
<div class="col width-fit mobile-width-fit"><span class="icon icon-bookmark color-blue"></span></div>
<div class="col width-fill mobile-width-fill">
<span class="float-right">
<span class="status text">
No measure
</span>
<span class="icon icon-bolt color-yellow"></span>
</span>
<div class="col width-fill mobile-width-fill">
<a class="title fatty" href="#">Repo 1</a>
</div>
<div class="description col">
<span class="text">This is one of my coolest repos.</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col width-fill">
<div id="listview_applications" class="cell panel">
<div class="header">활성 어플리케이션 목록</div>
<div class="template body">
<div class="cell">
<div class="col">
<div class="col width-fit mobile-width-fit"><span class="icon icon-bookmark color-blue"></span></div>
<div class="col width-fill mobile-width-fill">
<div class="col width-fill mobile-width-fill">
<a class="title fatty" href="#">Repo 1</a>
</div>
<div class="description col">
<select class="ipaddr">
<option value="">아이피 선택...</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="cell">
<div class="col">
<div class="float-left">
<button id="btn_logout" class="button" type="button">로그아웃</button>
<button id="btn_refresh" class="button" type="button">새로고침</button>
</div>
<div class="float-right">
<button id="btn_close" class="button" type="button">닫기</button>
</div>
</div>
</div>
<div class="cell">
<div class="col">
<div class="float-right">
<span id="version">버전 정보를 확인하고 있습니다.</span>
</div>
</div>
</div>

4
bootstrap.js vendored
View File

@ -29,10 +29,6 @@ exports.main = function(args) {
REG.write(REG.HKCR, appName + "\\DefaultIcon", "", SYS.getCurrentScriptDirectory() + "\\app\\favicon.ico,0", REG.STRING);
REG.write(REG.HKCR, appName + "\\shell\\open\\command", "", "cmd.exe /c cscript " + SYS.getCurrentScriptDirectory() + "\\app.js uriloader \"%1\"", REG.STRING);
// check updates
console.log("Checking updates...");
UPDATER.checkUpdates();
// open web application
console.log("Trying open GUI...");

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Config>
<AppName>WelsonJS</AppName>
<ApiUrl>http://127.0.0.1</ApiUrl>
</Config>

View File

@ -1,16 +0,0 @@
{
"server": "",
"name_server": "https://1.1.1.1/dns-query",
"windivert_filter_string": "outbound and (ip ? ip.DstAddr != 1.2.3.4 and ip.DstAddr != 1.1.1.1 : true)",
"ip_cidr_rules": {
"proxy": []
},
"app_rules": {
"proxy": []
},
"domain_rules": {
"proxy": [],
"direct": [],
"blocked": []
}
}

View File

@ -1,80 +0,0 @@
////////////////////////////////////////////////////////////////////////
// HTTPServer API
///////////////////////////////////////////////////////////////////////
var HTTPServer = {
_this: this, // Avoid conflicts between HTTPServer and Winsock variables
StatusCodes: {
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"
},
Listener: null,
Connections: {},
CreateWinsockObject: function() {
return CreateObject([
"MSWinsock.Winsock.1",
"MSWinsock.Winsock"
], "listener_");
},
Bind: function(port) {
try {
_this.Listener = _this.CreateWinsockObject();
_this.Listener.localPort = port;
_this.Listener.bind();
_this.Listener.listen();
console.info("Listening port: " + port);
} catch (e) {
console.error("port ", port, " could not bind: ", e.message);
}
},
OnRequest: function(request, response) {
console.log("HTTPServer.OnRequest() dose not implemented");
},
CreateServer: function(OnRequest) {
if (typeof OnRequest !== "function") {
throw new TypeError("OnRequest() must be a function.");
}
_this.OnRequest = OnRequest;
return HTTPServer;
},
ConnectionRequest: function(requestID) {
console.info("Connection request " + requestID);
_this.Connections[requestID] = {
Listener: _this.CreateWinsockObject()
};
_this.Connections[requestID].Listener.accept(requestID);
},
DataArrival: function(length) {
// TODO: DataArrival
},
SendComplete: function() {
// TODO: SendComplete
}
};
global.listener_ConnectionRequest = HTTPServer.ConnectionRequest;
global.listener_DataArrival = HTTPServer.DataArrival;
global.listener_SendComplete = HTTPServer.SendComplete;
exports = HTTPServer;

View File

@ -1,54 +0,0 @@
////////////////////////////////////////////////////////////////////////
// JSON API
////////////////////////////////////////////////////////////////////////
exports.VERSIONINFO = "JSON Lib (json.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.stringify = function(obj) {
var items = [];
var isArray = (function(_obj) {
try {
return (_obj instanceof Array);
} catch (e) {
return false;
}
})(obj);
var _toString = function(_obj) {
try {
if (typeof(_obj) == "object") {
return exports.stringify(_obj);
} else {
var s = String(_obj).replace(/"/g, '\\"');
if (typeof(_obj) == "number" || typeof(_obj) == "boolean") {
return s;
} else {
return '"' + s + '"';
}
}
} catch (e) {
return "null";
}
};
for (var k in obj) {
var v = obj[k];
if (!isArray) {
items.push('"' + k + '":' + _toString(v));
} else {
items.push(_toString(v));
}
}
if (!isArray) {
return "{" + items.join(",") + "}";
} else {
return "[" + items.join(",") + "]";
}
};
exports.parse = function(jsonString) {
return (new Function("return " + jsonString)());
};

View File

@ -1,43 +0,0 @@
////////////////////////////////////////////////////////////////////////
// LDPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "LDPlayer (ldplayer.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.getList = function() {
var data = [];
var commands = [
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer4.0/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/LDPlayer/LDPlayer3.0/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/NOXGAMES/MOMO/ldconsole.exe", "list2"],
[SYS.getEnvString("SYSTEMDRIVE") + "/XuanZhi/LDPlayer/ldconsole.exe", "list2"]
];
for (var i = 0; i < commands.length; i++) {
var result = SHELL.exec(commands[i]);
var lines = result.split(/\r?\n/);
for(var k = 0; k < lines.length; k++) {
var row = lines[k].split(',');
if(row.length == 7) {
data.push({
index: row[0],
title: row[1],
topWindowHandle: row[2],
binddWindowHandle: row[3],
androidStarted: row[4],
PID: parseInt(row[5]),
PIDVBox: parseInt(row[6])
});
}
}
}
return data;
};

View File

@ -1,71 +0,0 @@
////////////////////////////////////////////////////////////////////////
// LDPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/nox_adb.exe";
exports.getDevices = function() {
var data = [];
var cmd = [
exports.binPath,
"devices"
]
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.length == 2) {
data.push({
host: row[0],
type: row[1]
});
}
}
return data;
};
exports.getHostname = function(host) {
return SHELL.exec([
exports.binPath,
"-s",
host,
"shell",
"getprop",
"net.hostname"
]).trim();
};
exports.getPID = function(host) {
var row = host.split(':');
var addr = row[0];
var port = row[1];
var cmd = "netstat -ano | findstr :" + port + " | findstr :0";
var result = SHELL.exec(cmd);
return result.substring(result.lastIndexOf(' '));
};
exports.getList = function() {
var data = [];
var devices = exports.getDevices();
for(var i = 0; i < devices.length; i++) {
var hostname = exports.getHostname(devices[i].host);
var pid = exports.getPID(devices[i].host);
data.push({
hostname: hostname,
PID: parseInt(pid)
});
}
return data;
};

View File

@ -1,52 +0,0 @@
////////////////////////////////////////////////////////////////////////
// NoxPlayer API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "NoxPlayer (noxplayer.js) version 0.2";
exports.global = global;
exports.require = global.require;
exports.getList = function() {
var data = [];
var commands = [
[SYS.getEnvString("PROGRAMFILES(X86)") + "/Nox/bin/NoxConsole", "list"]
];
for (var i = 0; i < commands.length; i++) {
var result = SHELL.exec(commands[i]);
var lines = result.split(/\r?\n/);
for(var k = 0; k < lines.length; k++) {
var row = lines[k].split(',');
if(row.length == 7) {
data.push({
index: row[0],
name: row[1],
title: row[2],
handle1: row[3],
handle2: row[4],
handle3: row[5],
PID: parseInt(row[6]),
handle4: -1
});
} else if(row.length == 8) {
data.push({
index: row[0],
name: row[1],
title: row[2],
handle1: row[3],
handle2: row[4],
handle3: row[5],
PID: parseInt(row[6]),
handle4: row[7]
});
}
}
}
return data;
};

View File

@ -1,61 +0,0 @@
////////////////////////////////////////////////////////////////////////
// Shadowsocks API
////////////////////////////////////////////////////////////////////////
var CONFIG = require("lib/config");
var SHELL = require("lib/shell");
var binPath = "bin\\ss-local.exe";
var getRandomInt = function(min, max) {
var x = Math.random();
return min + Math.floor((max - min) * x);
};
var ShadowsocksObject = function() {
this.binPath
this.processID = 0;
this.listenPort = 0;
this.connect = function(host) {
this.listenPort = getRandomInt(49152, 65535);
var process = SHELL.createProcess([
binPath,
"-s",
host,
"-p",
CONFIG.getValue("SSPort"),
"-l",
this.listenPort,
"-k",
CONFIG.getValue("SSPassword"),
"-m",
CONFIG.getValue("SSCipher")
]);
sleep(1000);
try {
this.processID = process.ProcessID;
if (this.processID > 0) {
return this;
} else {
console.info("Retrying connect to shadowsocks...");
return this.connect();
}
} catch(e) {
console.info("Retrying connect to shadowsocks...");
return this.connect();
}
};
};
exports.connect = function(host) {
return (new ShadowsocksObject()).connect(host);
};
exports.VERSIONINFO = "Shadowsocks interface (shadowsocks.js) version 0.2";
exports.global = global;
exports.require = global.require;

View File

@ -1,43 +0,0 @@
////////////////////////////////////////////////////////////////////////
// TUN2SOCKS API
////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
exports.VERSIONINFO = "TUN2SOCKS Lib (tun2socks.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.binPath = "bin/tun2socks.exe";
/**
* @param {string} name
* @param {Object} options
*/
exports.assign = function(name, options) {
var defaultOptions = {
tunAddr: "10.0.0.2",
tunGw: "10.0.0.1",
proxyType: "socks",
proxyServer: "127.0.0.1:1080",
tunDns: "8.8.8.8,8.8.4.4", // Cloudflare DNS
tunName: name
}, _options = options, cmd = [];
// fill with default options
for (var k in defaultOptions) {
if (!(k in _options)) {
_options[k] = defaultOptions[k];
}
}
// make command
cmd.push("tun2socks");
for (var k in _options) {
cmd.push('-' + k);
cmd.push(_options[k]);
}
// return
SHELL.run(cmd);
};

View File

@ -1,76 +0,0 @@
var FILE = require("lib/file");
var HTTP = require("lib/http");
var CONFIG = require("lib/config");
var SHELL = require("lib/shell");
var apiUrl = CONFIG.getValue("ApiUrl");
var token = null;
var versionId = 0;
if (FILE.fileExists("token.txt")) {
token = FILE.readFile("token.txt", "utf-8");
}
if (FILE.fileExists("versionid.txt")) {
versionId = parseInt(FILE.readFile("versionid.txt", "utf-8"));
}
var downloadFile = function(url) {
// download a file
console.log(SHELL.exec(["bin\\curl", url, "-o", "update.zip"]));
// extract a file
console.log(SHELL.exec(["bin\\unzip", "-o", "update.zip"]));
// run installer
SHELL.run(["start", "mysetup.exe"]);
// close application
exit();
};
var requestFile = function(id) {
var onSuccess = function(res) {
var data = res.data;
var full_url = data.data.full_url;
console.log("Downloading a file...");
downloadFile(full_url);
};
console.log("Requesting a file...");
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.get(apiUrl + "/netsolid/files/" + id, onSuccess)
;
};
var checkUpdates = function() {
if (!token) {
console.warn("Could not find authorization token. 로그인이 필요합니다.");
} else {
var onSuccess = function(res) {
var data = res.data;
for (var i = 0; i < data.length; i++) {
if (data[i].id > versionId) {
console.info("업데이트가 있습니다. 다운로드를 진행합니다.");
requestFile(data[i].file);
}
}
};
HTTP.create()
.setContentType("application/x-www-form-urlencoded")
.setBearerAuth(token)
.setParameters({
"status": "published",
"sort": "-created_on",
"limit": 1
})
.get(apiUrl + "/netsolid/items/updates", onSuccess)
;
}
};
exports.checkUpdates = checkUpdates;

View File

@ -1,55 +0,0 @@
////////////////////////////////////////////////////////////////////////
// WindowsTAP API
////////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var FILE = require("lib/file");
exports.VERSIONINFO = "WindowsTAP Lib (wintap.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.infPath = SYS.getEnvString("PROGRAMFILES") + "/TAP-Windows/driver/OemVista.inf";
exports.binPath = SYS.getEnvString("PROGRAMFILES") + "/TAP-Windows/bin/tapinstall.exe";
exports.before = function() {
if(!FILE.fileExists(exports.binPath)) {
console.log("WindowsTAP dose not installed. Trying to install...");
return SHELL.exec(["bin/tap-windows-9.24.2-I601-Win7.exe"]);
} else {
return true;
}
};
/**
* @param {string} id
*/
exports.install = function(id) {
exports.before();
return SHELL.exec([exports.binPath, "install", exports.infPath, id]);
};
/**
* @param {string} id
*/
exports.update = function(id) {
exports.before();
return SHELL.exec([exports.binPath, "update", exports.infPath, id]);
};
/**
* @param {string} id
*/
exports.query = function(id) {
exports.before();
return SHELL.exec([exports.binPath, "hwids", id]);
};
/**
* @param {string} id
*/
exports.remove = function(id) {
exports.before();
return SHELL.exec([exports.binPath, "remove", id]);
};

View File

@ -1,6 +1,6 @@
{
"name": "welsonjs",
"version": "0.1.2",
"version": "0.1.4",
"description": "Build a Windows desktop apps with JavaScript, HTML, and CSS based on WSH/HTA",
"main": "app.js",
"directories": {

View File

@ -26,8 +26,16 @@ Source: "app.hta"; DestDir: "{app}";
Source: "start.bat"; DestDir: "{app}";
Source: "uriloader.js"; DestDir: "{app}";
Source: "webloader.js"; DestDir: "{app}";
Source: "testloader.js"; DestDir: "{app}";
Source: "shadow.js"; DestDir: "{app}";
Source: "bootstrap.js"; DestDir: "{app}";
Source: "shadow.js"; DestDir: "{app}";
Source: "shoutcut.js"; DestDir: "{app}";
Source: "bgloader.js"; DestDir: "{app}";
Source: "config.template.json"; DestDir: "{app}";
Source: "config.xml"; DestDir: "{app}";
Source: "versionid.txt"; DestDir: "{app}";
Source: "manual.pptx"; DestDir: "{app}";
Source: "app\*"; DestDir: "{app}/app"; Flags: ignoreversion recursesubdirs;
Source: "lib\*"; DestDir: "{app}/lib"; Flags: ignoreversion recursesubdirs;
Source: "bin\*"; DestDir: "{app}/bin"; Flags: ignoreversion recursesubdirs;

260
shadow.js
View File

@ -1,260 +0,0 @@
////////////////////////////////////////////////////////////////////////
// ShadowLoader
////////////////////////////////////////////////////////////////////////
var SS = require("lib/shadowsocks");
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var XML = require("lib/xml");
var LDPlayer = require("lib/ldplayer");
var NoxPlayer = require("lib/noxplayer");
var Chrome = require("lib/chrome");
var Apps = {
LDPlayer: {},
NoxPlayer: {},
Chrome: {},
ProcessName: {}
};
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();
for (var i = 0; i < items.length; i++) {
try {
var name = items[i].getDOM().selectSingleNode("Name").text;
var uniqueId = items[i].getDOM().selectSingleNode("UniqueID").text;
var ipAddress = items[i].getDOM().selectSingleNode("IPAddress").text;
if (name in Apps) {
Apps[name][uniqueId] = ipAddress;
}
} catch (e) {}
}
// App 1. LDPlayer
var check_LDPlayer = function() {
var ssPort, ssPID, shadowPID = 0;
var items = LDPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = 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) {
while (!SYS.isAlivePID(ssPID)) {
var ss = SS.connect(Apps.LDPlayer[title]);
ssPort = ss.listenPort;
ssPID = ss.processID;
}
} else {
console.error("Not assigned static IP: " + title);
continue;
}
var process;
while (!SYS.isAlivePID(shadowPID)) {
process = SHELL.createProcess([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + ssPort,
"-p",
pid
]);
sleep(1500);
shadowPID = process.ProcessID;
}
AppsPID.push([pid, ssPID, shadowPID]);
console.info("Waiting new launched");
sleep(1500);
}
}
};
// App 2. NoxPlayer
var check_NoxPlayer = function() {
var ssPort, ssPID, shadowPID = 0;
var items = NoxPlayer.getList();
for (var i = 0; i < items.length; i++) {
var pid = items[i].PID;
var title = items[i].title;
if (pid > 0 && AppsMutex.indexOf(pid) < 0) {
console.info("New launched NoxPlayer: " + title);
AppsMutex.push(pid);
if (title in Apps.NoxPlayer) {
while (!SYS.isAlivePID(ssPID)) {
var ss = SS.connect(Apps.NoxPlayer[title]);
ssPort = ss.listenPort;
ssPID = ss.processID;
}
} else {
console.error("Not assigned static IP: " + title);
continue;
}
var process;
while (!SYS.isAlivePID(shadowPID)) {
process = SHELL.createProcess([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + ssPort,
"-p",
pid
]);
sleep(1500);
shadowPID = process.ProcessID;
}
AppsPID.push([pid, ssPID, shadowPID]);
console.info("Waiting new launched");
sleep(1500);
}
}
};
// App 3. Chrome
var check_Chrome = function() {
for (var uniqueId in Apps.Chrome) {
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Creating Chrome Shoutcut: " + uniqueId);
// 바탕화면에 바로가기만 생성
var number = uniqueId.replace(/[^0-9]/g,'');
Chrome.create()
.setProfile(uniqueId, uniqueId)
.setInPrivate(true)
.createShoutcut("https://google.com")
;
AppsMutex.push("chrome_" + uniqueId);
}
}
};
// App 4. ProcessName
var check_ProcessName = function() {
for (var uniqueId in Apps.ProcessName) {
if (AppsMutex.indexOf("processName_" + uniqueId) < 0) {
var ssPort, ssPID, shadowPID = 0;
console.info("Running listener with process name: " + uniqueId);
AppsMutex.push("processName_" + uniqueId);
// 소켓 연결
while (!SYS.isAlivePID(ssPID)) {
var ss = SS.connect(Apps.ProcessName[uniqueId]);
ssPort = ss.listenPort;
ssPID = ss.processID;
}
// 프로세스 이름으로 실행
var process;
while (!SYS.isAlivePID(shadowPID)) {
process = SHELL.createProcess([
SYS.getCurrentScriptDirectory() + "/bin/shadow.exe",
"-c",
SYS.getCurrentScriptDirectory() + "/config.template.json",
"-s",
"socks://localhost:" + ssPort,
"-n",
uniqueId
]);
sleep(1500);
shadowPID = process.ProcessID;
}
AppsPID.push([ssPID, shadowPID]);
sleep(1500);
}
}
};
var check_Zombie = function() {
var alives = SYS.getPIDList();
var zombies = [];
// find dead processes
var _AppsPID = [];
for (var i = 0; i < AppsPID.length; i++) {
var v1 = AppsPID[i];
var isDead = false;
for (var k = 0; k < v1.length; k++) {
var v2 = v1[k];
if (alives.indexOf(v2) < 0) {
console.warn("Detected zombie: " + v2);
console.warn("Will be kill all related processes.");
zombies = zombies.concat(v1);
isDead = true;
break;
}
}
if (!isDead) {
_AppsPID.push(v1);
}
}
AppsPID = _AppsPID;
// kill zombie processes
var _zombies = [];
for (var i = 0; i < zombies.length; i++) {
var pid = zombies[i];
if (pid > 0) {
try {
SYS.killProcess(pid);
} catch (e) {
_zombies.push(pid);
console.error("shadow -> check_Zombie() -> ", e.message);
}
}
}
zombies = _zombies;
};
var main = function() {
console.info("Waiting new launched");
while (true) {
sleep(1500);
check_LDPlayer();
sleep(1500);
check_NoxPlayer();
sleep(1500);
check_Chrome();
sleep(1500);
check_ProcessName();
sleep(1500);
check_Zombie();
}
};
exports.main = main;

View File

@ -1,66 +1,7 @@
var SS = require("lib/shadowsocks");
var XML = require("lib/xml");
var Chrome = require("lib/chrome");
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var Apps = {
LDPlayer: {},
NoxPlayer: {},
Chrome: {},
ProcessName: {}
};
var AppsMutex = [];
var AppsPID = [];
var items = XML.load("staticip.xml").select("/StaticIP/Item").toArray();
for (var i = 0; i < items.length; i++) {
try {
var name = items[i].getDOM().selectSingleNode("Name").text;
var uniqueId = items[i].getDOM().selectSingleNode("UniqueID").text;
var ipAddress = items[i].getDOM().selectSingleNode("IPAddress").text;
if (name in Apps) {
Apps[name][uniqueId] = ipAddress;
}
} catch (e) {}
}
var do_Chrome = function(args) {
var _uniqueId = args[1];
var _args = {};
var _url = "https://google.com";
for (var i = 0; i < args.length; i++) {
var pos = args[i].indexOf('=');
if (pos > -1) {
if (args[i].indexOf("--") == 0) {
_args[args[i].substring(2, pos)] = args[i].substring(pos + 1);
} else {
_args[args[i].substring(0, pos)] = args[i].substring(pos + 1);
}
} else if (args[i] != "chrome") {
_url = args[i];
}
}
var ssPort, ssPID;
for (var uniqueId in Apps.Chrome) {
if (_uniqueId == uniqueId && AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Starting Google Chrome: " + uniqueId);
var ss = SS.connect(Apps.Chrome[uniqueId]);
ssPort = ss.listenPort;
ssPID = ss.processID;
console.info("Wait 3 seconds...")
sleep(3000);
Chrome.start(_url, ssPort, _args['profile-directory'], _args['user-data-dir'], _uniqueId);
AppsPID.push([ssPID]);
AppsMutex.push("chrome_" + uniqueId);
}
}
Chrome.create().open("https://google.com");
};
exports.main = function(args) {

View File

@ -1 +0,0 @@
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwiZXhwIjoxNjA1MTU4NjA2LCJ0dGwiOjIwLCJ0eXBlIjoiYXV0aCIsImtleSI6Ijg1N2NlZDg1LTMzOWEtNDViNS04YTQ5LTJjOGM0YmE4ZDVmNCIsInByb2plY3QiOiJuZXRzb2xpZCJ9.4g7ChYBd7fnGivaLif50R1uVaHp08wDXacn-cOXPLKA

View File

@ -1 +0,0 @@
1

View File

@ -1 +0,0 @@
100