This commit is contained in:
Namhyeon Go 2024-07-10 19:26:58 +09:00
parent 97f68c39bb
commit 1309e2ab8f
6 changed files with 53 additions and 49 deletions

View File

@ -69,7 +69,7 @@ Router.add('/test', function(render) {
alert("모든 메시지가 정상적으로 보였다면 테스트에 성공한 것입니다."); alert("모든 메시지가 정상적으로 보였다면 테스트에 성공한 것입니다.");
}; };
var content = FILE.readFile("data/test-oss-20231030.json", FILE.CdoCharset.CdoUTF_8); var content = FILE.readFile("data/test-oss-korea-2023.json", FILE.CdoCharset.CdoUTF_8);
var data = JSON.parse(content); var data = JSON.parse(content);
render("app/test.html", { render("app/test.html", {
"data": data "data": data

View File

@ -6,17 +6,17 @@ var SYS = require("lib/system");
// A common Android devices // A common Android devices
function ADBObject() { function ADBObject() {
var _interface = SHELL.create(); this._interface = SHELL.create();
this.setBinPath = function(binPath) { this.setBinPath = function(binPath) {
this.binPath = binPath; this.binPath = binPath;
_interface.setPrefix(this.binPath); this._interface.setPrefix(this.binPath);
return this; return this;
}; };
this.getDevices = function() { this.getDevices = function() {
var devices = []; var devices = [];
var result = _interface.exec(["devices"]); var result = this._interface.exec(["devices"]);
splitLn(result).forEach(function(line) { splitLn(result).forEach(function(line) {
var row = line.split(/\s+/); var row = line.split(/\s+/);
@ -63,32 +63,32 @@ function ADBObject() {
// download a file from target device // download a file from target device
this.pull = function(id, path) { this.pull = function(id, path) {
return _interface.exec(["-s", id, "pull", path, "data\\"]); return this._interface.exec(["-s", id, "pull", path, "data\\"]);
}; };
// upload a file to target device // upload a file to target device
this.push = function(id, filename, path) { this.push = function(id, filename, path) {
return _interface.exec(["-s", id, "push", "data\\" + filename, path]); return this._interface.exec(["-s", id, "push", "data\\" + filename, path]);
}; };
// install APK file // install APK file
this.install = function(id, filename) { this.install = function(id, filename) {
return _interface.exec(["-s", id, "install", "data\\" + filename]); return this._interface.exec(["-s", id, "install", "data\\" + filename]);
}; };
// Uninstall the App // Uninstall the App
this.uninstall = function(id, appname) { this.uninstall = function(id, appname) {
return _interface.exec(["-s", id, "uninstall", appname]); return this._interface.exec(["-s", id, "uninstall", appname]);
}; };
// reboot device // reboot device
this.reboot = function(id) { this.reboot = function(id) {
return _interface.exec(["-s", id, "reboot"]); return this._interface.exec(["-s", id, "reboot"]);
}; };
// set the binary path // set the binary path
this.binPath = "bin\\platform-tools_r33.0.0-windows\\platform-tools\\adb.exe"; this.binPath = "bin\\platform-tools_r33.0.0-windows\\platform-tools\\adb.exe";
_interface.setPrefix(this.binPath); this._interface.setPrefix(this.binPath);
} }
// An Android Emulator // An Android Emulator

View File

@ -17,7 +17,7 @@ var PROCESS_VERSION = SYS.getProcessVersion();
var DEFAULT_USER_AGENT = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + PROCESS_VERSION + "; " + DEVICE_UUID + "; abuse@catswords.net)"; var DEFAULT_USER_AGENT = "WelsonJS/0.2.7 (" + OS_NAME + "; " + OS_ARCH + "; " + PROCESS_VERSION + "; " + DEVICE_UUID + "; abuse@catswords.net)";
var HTTPObject = function(engine) { var HTTPObject = function(engine) {
var _interface = null; this._interface = null;
this.contentType = "application/x-www-form-urlencoded"; this.contentType = "application/x-www-form-urlencoded";
this.requestBody = ""; this.requestBody = "";
@ -82,9 +82,11 @@ var HTTPObject = function(engine) {
switch (this.engine) { switch (this.engine) {
case "MSXML": case "MSXML":
if (typeof XMLHttpRequest !== "undefined") { if (typeof XMLHttpRequest !== "undefined") {
_interface = new XMLHttpRequest(); console.log("A");
this._interface = new XMLHttpRequest();
} else { } else {
_interface = CreateObject([ console.log("B");
this._interface = CreateObject([
"Microsoft.XMLHTTP", "Microsoft.XMLHTTP",
"WinHttp.WinHttpRequest.5.1", "WinHttp.WinHttpRequest.5.1",
"Msxml3.XMLHTTP", "Msxml3.XMLHTTP",
@ -105,13 +107,15 @@ var HTTPObject = function(engine) {
break; break;
case "CURL": case "CURL":
_interface = SHELL.create(); console.log("C");
_interface.setPrefix("bin\\curl.exe"); // the location of cURL binary this._interface = SHELL.create();
this._interface.setPrefix("bin\\curl.exe"); // the location of cURL binary
break; break;
case "BITS": case "BITS":
_interface = SHELL.create(); console.log("D");
_interface.setPrefix("bitsadmin.exe"); // the location of BITS binary this._interface = SHELL.create();
this._interface.setPrefix("bitsadmin.exe"); // the location of BITS binary
break; break;
} }
@ -246,7 +250,7 @@ var HTTPObject = function(engine) {
this.getHeader = function(key) { this.getHeader = function(key) {
try { try {
return _interface.getResponseHeader(key); return this._interface.getResponseHeader(key);
} catch (e) { } catch (e) {
console.error("HTTPObject.getHeader() -> ", e.message); console.error("HTTPObject.getHeader() -> ", e.message);
} }
@ -254,7 +258,7 @@ var HTTPObject = function(engine) {
this.getHeaders = function() { this.getHeaders = function() {
try { try {
var raw = _interface.getAllResponseHeaders(); var raw = this._interface.getAllResponseHeaders();
return raw.split(/[\r\n]+/).filter(function(s) { return raw.split(/[\r\n]+/).filter(function(s) {
return s.trim().length > 0; return s.trim().length > 0;
@ -385,11 +389,11 @@ var HTTPObject = function(engine) {
// Open // Open
switch (this.method) { switch (this.method) {
case "POST": case "POST":
_interface.open(method, url, this.isAsynchronous); this._interface.open(method, url, this.isAsynchronous);
break; break;
case "GET": case "GET":
_interface.open(method, url, this.isAsynchronous); this._interface.open(method, url, this.isAsynchronous);
break; break;
default: default:
@ -439,27 +443,30 @@ var HTTPObject = function(engine) {
this.setHeader("Content-Type", this.contentType); this.setHeader("Content-Type", this.contentType);
} }
console.log("engine: ", this.engine);
console.log("interface: ", typeof this._interface);
try { try {
// MSXML (XHR) // MSXML (XHR)
if (this.engine == "MSXML") { if (this.engine == "MSXML") {
for (var key in this.headers) { for (var key in this.headers) {
_interface.setRequestHeader(key, this.evaluate(this.headers[key])); this._interface.setRequestHeader(key, this.evaluate(this.headers[key]));
} }
switch (this.method) { switch (this.method) {
case "GET": case "GET":
_interface.send(); this._interface.send();
break; break;
default: default:
_interface.send(this.serialize()); this._interface.send(this.serialize());
} }
// Waiting a response // Waiting a response
while (_interface.readyState < 4) sleep(100); while (this._interface.readyState < 4) sleep(100);
// Get response text // Get response text
responseText = _interface.responseText; responseText = this._interface.responseText;
} }
// cURL // cURL
@ -584,7 +591,7 @@ var HTTPObject = function(engine) {
cmd.push(state.url); cmd.push(state.url);
// Get response text // Get response text
responseText = _interface.setCharset(this.charset).exec(cmd); responseText = this._interface.setCharset(this.charset).exec(cmd);
// Reload a cookie in the pipe // Reload a cookie in the pipe
if (this.isLoggingCookie) { if (this.isLoggingCookie) {
@ -597,14 +604,14 @@ var HTTPObject = function(engine) {
console.log("Detected charset:", detectedCharset); console.log("Detected charset:", detectedCharset);
if (detectedCharset != null && this.charset != detectedCharset) { if (detectedCharset != null && this.charset != detectedCharset) {
var _interface = SHELL.create(); var this._interface = SHELL.create();
responseText = _interface.setCharset(detectedCharset).exec(cmd); responseText = this._interface.setCharset(detectedCharset).exec(cmd);
debuggingText = _interface.stderr.read(); debuggingText = this._interface.stderr.read();
} }
} }
// Get debuging text // Get debuging text
debuggingText = _interface.stderr.read(); debuggingText = this._interface.stderr.read();
} }
} }
@ -619,11 +626,11 @@ var HTTPObject = function(engine) {
if (this.method == "GET") { if (this.method == "GET") {
cmd = cmd.concat(["/download", "/priority", job_priority, url, out.path]); // build a BITS command cmd = cmd.concat(["/download", "/priority", job_priority, url, out.path]); // build a BITS command
_interface.exec(cmd); // launch the download job this._interface.exec(cmd); // launch the download job
out.reload(); // read the downloaded data out.reload(); // read the downloaded data
responseText = out.read() // set the downloaded data to response text responseText = out.read() // set the downloaded data to response text
var err = _interface.exec(["/geterror", job_name]); // get error information var err = this._interface.exec(["/geterror", job_name]); // get error information
debuggingText = err.stdout.read(); // set the error information to debugging text debuggingText = err.stdout.read(); // set the error information to debugging text
out.destroy(); // destroy the downloaded data out.destroy(); // destroy the downloaded data

View File

@ -5,7 +5,7 @@ var FILE = require("lib/file");
var PipeIPC = require("lib/pipe-ipc"); var PipeIPC = require("lib/pipe-ipc");
var ShellObject = function() { var ShellObject = function() {
this.interface = null; this._interface = null;
this.currentDirectory = null; this.currentDirectory = null;
this.workingDirectory = null; this.workingDirectory = null;
@ -20,8 +20,8 @@ var ShellObject = function() {
this.create = function() { this.create = function() {
try { try {
this.interface = CreateObject("WScript.Shell"); this._interface = CreateObject("WScript.Shell");
this.currentDirectory = this.interface.CurrentDirectory; this.currentDirectory = this._interface.CurrentDirectory;
this.workingDirectory = this.currentDirectory; this.workingDirectory = this.currentDirectory;
} catch (e) { } catch (e) {
console.error("ShellObject.create() ->", e.message); console.error("ShellObject.create() ->", e.message);
@ -42,7 +42,7 @@ var ShellObject = function() {
this.setWorkingDirectory = function(dirname) { this.setWorkingDirectory = function(dirname) {
if (typeof(dirname) === "string") { if (typeof(dirname) === "string") {
this.workingDirectory = dirname; this.workingDirectory = dirname;
this.interface.CurrentDirectory = this.workingDirectory; this._interface.CurrentDirectory = this.workingDirectory;
console.log("ShellObject.workingDirectory ->", this.workingDirectory); console.log("ShellObject.workingDirectory ->", this.workingDirectory);
} }
return this; return this;
@ -79,7 +79,7 @@ var ShellObject = function() {
try { try {
var c = this.build(cmd); var c = this.build(cmd);
console.log("ShellObject.createProcess() ->", c); console.log("ShellObject.createProcess() ->", c);
return this.interface.Exec(c); return this._interface.Exec(c);
} catch (e) { } catch (e) {
console.error("ShellObject.createProcess() ->", e.message); console.error("ShellObject.createProcess() ->", e.message);
} }
@ -102,7 +102,7 @@ var ShellObject = function() {
var c = "%comspec% /c (" + this.build(cmd) + ") 1> " + this.stdout.path; var c = "%comspec% /c (" + this.build(cmd) + ") 1> " + this.stdout.path;
//c += " 2>&1"; //c += " 2>&1";
c += " 2> " + this.stderr.path; c += " 2> " + this.stderr.path;
this.interface.Run(c, 0, true); this._interface.Run(c, 0, true);
console.log("ShellObject.exec() ->", c); console.log("ShellObject.exec() ->", c);
sleep(1); sleep(1);
@ -127,7 +127,7 @@ var ShellObject = function() {
var fork = (typeof(fork) !== "undefined") ? fork : true; var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c (" + this.build(cmd) + ")"; var c = "%comspec% /q /c (" + this.build(cmd) + ")";
console.log("ShellObject.run() ->", c); console.log("ShellObject.run() ->", c);
this.interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork); this._interface.Run(c, (!this.isVisibleWindow ? 0 : 1), !fork);
}; };
this.runAs = function(FN, args) { this.runAs = function(FN, args) {
@ -142,11 +142,11 @@ var ShellObject = function() {
}; };
this.createShoutcut = function(shoutcutName, cmd) { this.createShoutcut = function(shoutcutName, cmd) {
var desktopPath = this.interface.SpecialFolders("Desktop"); var desktopPath = this._interface.SpecialFolders("Desktop");
var path = desktopPath + "\\" + shoutcutName + ".lnk"; var path = desktopPath + "\\" + shoutcutName + ".lnk";
if (!FILE.fileExists(path)) { if (!FILE.fileExists(path)) {
var link = this.interface.CreateShortcut(path); var link = this._interface.CreateShortcut(path);
//link.TargetPath = "cmd"; //link.TargetPath = "cmd";
//link.Arguments = "/q /c " + this.build(cmd); //link.Arguments = "/q /c " + this.build(cmd);
link.TargetPath = "wscript"; link.TargetPath = "wscript";
@ -161,13 +161,13 @@ var ShellObject = function() {
}; };
this.getPathOfMyDocuments = function() { this.getPathOfMyDocuments = function() {
return this.interface.SpecialFolders("MyDocuments"); return this._interface.SpecialFolders("MyDocuments");
}; };
this.release = function() { this.release = function() {
console.log("ShellObject.release() ->", this.currentDirectory); console.log("ShellObject.release() ->", this.currentDirectory);
this.interface.CurrentDirectory = this.currentDirectory; this._interface.CurrentDirectory = this.currentDirectory;
this.interface = null; this._interface = null;
}; };
this.create(); this.create();
@ -221,7 +221,7 @@ exports.getPathOfMyDocuments = function() {
exports.CdoCharset = PipeIPC.CdoCharset; exports.CdoCharset = PipeIPC.CdoCharset;
exports.VERSIONINFO = "Windows Shell Interface with WelsonJS Pipe-IPC module (shell.js) version 0.3.11"; exports.VERSIONINFO = "Windows Shell Interface (shell.js) version 0.3.11";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -1,3 +0,0 @@
@echo off
pushd "%~dp0"
cscript app.js bootstrap