mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 07:21:43 +00:00
fix
This commit is contained in:
parent
0014384539
commit
a634f54400
BIN
Default_HTA.reg
Normal file
BIN
Default_HTA.reg
Normal file
Binary file not shown.
26
app.js
26
app.js
|
@ -32,6 +32,7 @@
|
|||
// The appname argument causes <appname>.js to be loaded. The interface returned
|
||||
// must define main = function(args) {}, which is called once the module is
|
||||
// loaded.
|
||||
|
||||
var exit = function(status) {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
WScript.quit(status);
|
||||
|
@ -41,28 +42,27 @@ var exit = function(status) {
|
|||
|
||||
var console = {
|
||||
_messages: [],
|
||||
_echo: function(msg, type) {
|
||||
msg = (typeof(type) !== "undefined" ? type + ": " : "") + msg;
|
||||
_echo: function(args, type) {
|
||||
msg = (typeof(type) !== "undefined" ? type + ": " : "") + args[0];
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
WScript.echo(" * " + msg);
|
||||
}
|
||||
|
||||
this._messages.push(msg);
|
||||
},
|
||||
log: function(msg) {
|
||||
this._echo(msg);
|
||||
log: function() {
|
||||
this._echo(arguments);
|
||||
},
|
||||
error: function(msg) {
|
||||
this._echo(msg, "error");
|
||||
error: function() {
|
||||
this._echo(arguments, "error");
|
||||
},
|
||||
info: function(msg) {
|
||||
this._echo(msg, "info");
|
||||
info: function() {
|
||||
this._echo(arguments, "info");
|
||||
},
|
||||
warn: function(msg) {
|
||||
this._echo(msg, "warn");
|
||||
warn: function() {
|
||||
this._echo(arguments, "warn");
|
||||
},
|
||||
debug: function(msg) {
|
||||
this._echo(msg, "debug");
|
||||
debug: function() {
|
||||
this._echo(arguments, "debug");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ var getLocalApplications = function() {
|
|||
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++) {
|
||||
|
@ -258,6 +258,12 @@ if (typeof(token) !== "undefined") {
|
|||
ev.preventDefault();
|
||||
};
|
||||
|
||||
if (FILE.fileExists("credential.json")) {
|
||||
var credential = JSON.parse(FILE.readFile("token.txt", "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,
|
||||
|
@ -272,6 +278,7 @@ if (typeof(token) !== "undefined") {
|
|||
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();
|
||||
|
|
13
bootstrap.js
vendored
13
bootstrap.js
vendored
|
@ -28,8 +28,19 @@ 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);
|
||||
|
||||
// open HTA file
|
||||
// open web application
|
||||
console.log("Trying open GUI...");
|
||||
|
||||
// detect old process
|
||||
var processList = SYS.getProcessList();
|
||||
for (var i = 0; i < processList.length; i++) {
|
||||
var process = processList[i];
|
||||
if (process.Caption == "mshta.exe") {
|
||||
SYS.killProcess(process.ProcessID);
|
||||
}
|
||||
}
|
||||
|
||||
// open web application
|
||||
if (typeof(args) !== "undefined") {
|
||||
SHELL.run(["app.hta"].concat(args));
|
||||
} else {
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
/////////////////////////////////////////////////////////////////////////////////
|
||||
var SHELL = require("lib/shell");
|
||||
var SYS = require("lib/system");
|
||||
var SB = require("lib/sandboxie");
|
||||
|
||||
var ChromeObject = function() {
|
||||
this.binPath = "%PROGRAMFILES%\\Google\\Chrome\\Application\\chrome.exe";
|
||||
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:profileName\\Application";
|
||||
this.binPath = this.workingDirectory + "\\chrome.exe";
|
||||
this.processID = 0;
|
||||
this.profileName = "Default";
|
||||
this.proxyPort = 1080;
|
||||
|
@ -17,8 +17,10 @@ var ChromeObject = function() {
|
|||
return this;
|
||||
};
|
||||
|
||||
this.setProfileName = function(s) {
|
||||
this.profileName = s;
|
||||
this.setProfileName = function(profileName) {
|
||||
this.profileName = (profileName == "Default" ? "Chrome" : profileName);
|
||||
this.workingDirectory = this.workingDirectory.replace(":profileName", this.profileName);
|
||||
this.binPath = this.binPath.replace(":profileName", this.profileName);
|
||||
return this;
|
||||
};
|
||||
|
||||
|
@ -32,18 +34,40 @@ var ChromeObject = function() {
|
|||
};
|
||||
|
||||
this.open = function(url) {
|
||||
this.setProfileName(this.profileName);
|
||||
|
||||
var process;
|
||||
while (this.processID == 0) {
|
||||
try {
|
||||
/*
|
||||
process = SB.start(this.profileName, [
|
||||
this.binPath,
|
||||
"--profile-directory=" + this.profileName,
|
||||
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
||||
url
|
||||
]);
|
||||
*/
|
||||
/*
|
||||
process = SHELL.createProcess([
|
||||
this.binPath,
|
||||
"--profile-directory=" + this.profileName,
|
||||
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
|
||||
url
|
||||
], this.workingDirectory);
|
||||
*/
|
||||
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory);
|
||||
var process = shell.createProcess([
|
||||
"\"" + this.binPath + "\"",
|
||||
"--profile-directory=\"" + this.profileName + "\"",
|
||||
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
|
||||
"--user-data-dir=\"" + this.workingDirectory + "\"",
|
||||
"\"" + url + "\""
|
||||
].join(" "));
|
||||
sleep(1000);
|
||||
this.processID = process.ProcessID;
|
||||
shell.release();
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
console.error("ChromeObject.open() -> " + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -168,3 +168,7 @@ exports.deleteFile = function(FN) {
|
|||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
exports.copyFolder = function(FN) {
|
||||
|
||||
};
|
|
@ -17,7 +17,7 @@ var SandboxieObject = function() {
|
|||
process = SHELL.createProcess([
|
||||
this.binPath,
|
||||
"/box:" + this.sandboxName,
|
||||
SHELL.buildCommand(cmd)
|
||||
SHELL.build(cmd)
|
||||
].join(' '));
|
||||
this.processID = process.ProcessID;
|
||||
} catch (e) {
|
||||
|
|
180
lib/shell.js
180
lib/shell.js
|
@ -1,13 +1,8 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Shell API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var FILE = require("lib/file");
|
||||
|
||||
exports.VERSIONINFO = "Shell Lib (shell.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
var addslashes = function(s) {
|
||||
return s.toString().replace(/\\/g, '\\\\').
|
||||
replace(/\u0008/g, '\\b').
|
||||
|
@ -19,67 +14,140 @@ var addslashes = function(s) {
|
|||
replace(/"/g, '\\"');
|
||||
};
|
||||
|
||||
exports.buildCommand = function(cmd) {
|
||||
if (typeof(cmd) === "string") {
|
||||
return cmd;
|
||||
} else if (typeof(cmd) === "object") {
|
||||
return cmd.map(function(s) {
|
||||
var regex = /[ "]/g;
|
||||
if (!regex.test(s)) {
|
||||
return s;
|
||||
} else {
|
||||
return "\"" + addslashes(s) + "\"";
|
||||
}
|
||||
}).join(' ');
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
var ShellObject = function() {
|
||||
this.interface = null;
|
||||
this.currentDirectory = null;
|
||||
this.workingDirectory = null;
|
||||
this.isElevated = false;
|
||||
this.isFork = false;
|
||||
|
||||
this.create = function() {
|
||||
try {
|
||||
this.interface = CreateObject("WScript.Shell");
|
||||
this.currentDirectory = this.interface.CurrentDirectory;
|
||||
} catch (e) {
|
||||
console.error("ShellObject.create() -> " + e.message);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setWorkingDirectory = function(dirname) {
|
||||
if (typeof(dirname) === "string") {
|
||||
this.workingDirectory = dirname;
|
||||
this.interface.CurrentDirectory = this.workingDirectory;
|
||||
console.info("ShellObject.workingDirectory -> " + this.workingDirectory);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
this.build = function(cmd) {
|
||||
if (typeof(cmd) === "string") {
|
||||
return cmd;
|
||||
} else if (typeof(cmd) === "object") {
|
||||
return cmd.map(function(s) {
|
||||
var regex = /[ "]/g;
|
||||
if (!regex.test(s)) {
|
||||
return s;
|
||||
} else {
|
||||
return "\"" + addslashes(s) + "\"";
|
||||
}
|
||||
}).join(' ');
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
this.createProcess = function(cmd) {
|
||||
try {
|
||||
var c = this.build(cmd);
|
||||
console.info("ShellObject.createProcess() -> " + c);
|
||||
return this.interface.Exec(c);
|
||||
} catch (e) {
|
||||
console.error("ShellObject.createProcess() -> " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
this.exec = function(cmd, stdOutPath) {
|
||||
var data;
|
||||
|
||||
if (typeof(stdOutPath) === "undefined") {
|
||||
stdOutPath = "stdout.txt";
|
||||
}
|
||||
var c = "%comspec% /c (" + this.build(cmd) + ") 1> " + stdOutPath;
|
||||
c += " 2>&1";
|
||||
this.interface.Run(c, 0, true);
|
||||
console.info("ShellObject.exec() -> " + c);
|
||||
data = FILE.readFile(stdOutPath, "utf-8");
|
||||
|
||||
if (FILE.fileExists(stdOutPath)) {
|
||||
FILE.deleteFile(stdOutPath);
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
this.run = function(cmd, fork) {
|
||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
||||
var c = "%comspec% /q /c (" + this.build(cmd) + ")";
|
||||
console.info("ShellObject.run() -> " + c);
|
||||
this.interface.Run(c, 0, !fork);
|
||||
};
|
||||
|
||||
this.runWindow = function(cmd, fork) {
|
||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
||||
var c = "%comspec% /q /c (" + this.build(cmd) + ")";
|
||||
console.info("ShellObject.runWindow() -> " + c);
|
||||
this.interface.Run(c, 1, !fork);
|
||||
};
|
||||
|
||||
this.runAs = function(FN, args) {
|
||||
var c = FN + " " + args.join(' ');
|
||||
var oShell = CreateObject("Shell.Application");
|
||||
console.info("ShellObject.runAs() -> " + c);
|
||||
oShell.shellExecute(FN, args, null, "runas", 0);
|
||||
return oShell;
|
||||
};
|
||||
|
||||
this.release = function() {
|
||||
console.info("ShellObject.release() -> " + this.currentDirectory);
|
||||
this.interface.CurrentDirectory = this.currentDirectory;
|
||||
this.interface = null;
|
||||
};
|
||||
|
||||
this.create();
|
||||
};
|
||||
|
||||
exports.create = function() {
|
||||
return new ShellObject();
|
||||
};
|
||||
|
||||
exports.build = function(cmd) {
|
||||
return (new ShellObject()).build(cmd);
|
||||
};
|
||||
|
||||
exports.exec = function(cmd, stdOutPath) {
|
||||
var WSH = CreateObject("WScript.Shell"), data;
|
||||
if (typeof(stdOutPath) === "undefined") {
|
||||
stdOutPath = "stdout.txt";
|
||||
}
|
||||
var c = "%comspec% /c (" + exports.buildCommand(cmd) + ") 1> " + stdOutPath;
|
||||
c += " 2>&1";
|
||||
WSH.Run(c, 0, true);
|
||||
console.info("exec() -> " + c);
|
||||
data = FILE.readFile(stdOutPath, "utf-8");
|
||||
|
||||
if (FILE.fileExists(stdOutPath)) {
|
||||
FILE.deleteFile(stdOutPath);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
return (new ShellObject()).exec(cmd, stdOutPath);
|
||||
};
|
||||
|
||||
exports.run = function(cmd, fork) {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
||||
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
|
||||
console.info("run() -> " + c);
|
||||
WSH.Run(c, 0, !fork);
|
||||
return (new ShellObject()).run(cmd, fork);
|
||||
};
|
||||
|
||||
exports.runWindow = function(cmd, fork) {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
||||
var c = "%comspec% /q /c (" + exports.buildCommand(cmd) + ")";
|
||||
console.info("run() -> " + c);
|
||||
WSH.Run(c, 1, !fork);
|
||||
return (new ShellObject()).runWindow(cmd, fork);
|
||||
}
|
||||
|
||||
exports.createProcess = function(cmd) {
|
||||
var c = exports.buildCommand(cmd);
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
console.info("createProcess() -> " + c);
|
||||
return WSH.Exec(c);
|
||||
exports.createProcess = function(cmd, workingDirectory) {
|
||||
if (typeof(workingDirectory) !== "undefined") {
|
||||
console.info("Working directory: " + workingDirectory);
|
||||
}
|
||||
return (new ShellObject()).setWorkingDirectory(workingDirectory).createProcess(cmd);
|
||||
};
|
||||
|
||||
exports.elevatedRun = function(FN, args) {
|
||||
console.info("elevatedRun() -> " + FN + " " + args.join(' '));
|
||||
var oShell = CreateObject("Shell.Application");
|
||||
oShell.shellExecute(FN, args, null, "runas", 0);
|
||||
return oShell;
|
||||
exports.runAs = function(FN, args) {
|
||||
return (new ShellObject()).runAs(FN, args);
|
||||
};
|
||||
|
||||
exports.VERSIONINFO = "Shell Lib (shell.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
|
18
lib/xml.js
18
lib/xml.js
|
@ -57,14 +57,18 @@ var XMLObject = function(dom) {
|
|||
return this.dom;
|
||||
};
|
||||
|
||||
this.load = function(s) {
|
||||
this.filename = s;
|
||||
this.load = function(filename) {
|
||||
this.filename = filename;
|
||||
console.info("XMLObject.load() -> Opening XML file: " + filename)
|
||||
|
||||
if (FILE.fileExists(s)) {
|
||||
this.getDOM().loadXML(FILE.readFile(this.filename, "utf-8"));
|
||||
} else {
|
||||
console.error("The file does not exists");
|
||||
return;
|
||||
try {
|
||||
if (FILE.fileExists(filename)) {
|
||||
this.getDOM().loadXML(FILE.readFile(this.filename, "utf-8"));
|
||||
} else {
|
||||
console.error("XMLObject.load() -> The file does not exists or access denied");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("XMLObject.load() -> " + e.message);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Reference in New Issue
Block a user