add node-style module.exports compatibility

This commit is contained in:
Namhyeon Go 2020-07-21 03:57:53 +09:00
parent 043650a3e5
commit 61041197fa
14 changed files with 184 additions and 219 deletions

2
app.js
View File

@ -90,7 +90,7 @@ function require(FN) {
// make global function // make global function
FSO = null; FSO = null;
T = "(function(global){\n" + '"use strict";' + "\n" + T + "})(this);\n\n////@ sourceURL=" + FN; T = "(function(global){\n" + '"use strict";' + "var module={exports:{}};var exports={};\n" + T + "\nmodule.exports=exports;return module.exports;})(this);\n\n////@ sourceURL=" + FN;
try { try {
cache[FN] = eval(T); cache[FN] = eval(T);
} catch (e) { } catch (e) {

View File

@ -2,13 +2,11 @@
// Base64 API // Base64 API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = { exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
VERSIONINFO: "Base64 Module (base64.js) version 0.1", exports.global = global;
global: global, exports.require = require;
require: global.require
};
scope.createMSXMLObject = function() { exports.createMSXMLObject = function() {
var progIDs = [ var progIDs = [
"Msxml2.DOMDocument.6.0", "Msxml2.DOMDocument.6.0",
"Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.5.0",
@ -25,7 +23,7 @@ scope.createMSXMLObject = function() {
return null; return null;
}; };
scope.getStream_StringToBinary = function(dText) { exports.getStream_StringToBinary = function(dText) {
var adTypeText = 2; var adTypeText = 2;
var adTypeBinary = 1; var adTypeBinary = 1;
var BinaryStream = new ActiveXObject("ADODB.Stream"); var BinaryStream = new ActiveXObject("ADODB.Stream");
@ -39,7 +37,7 @@ scope.getStream_StringToBinary = function(dText) {
return BinaryStream.Read(); return BinaryStream.Read();
}; };
scope.getStream_BinaryToString = function(dBinary) { exports.getStream_BinaryToString = function(dBinary) {
var adTypeText = 2; var adTypeText = 2;
var adTypeBinary = 1; var adTypeBinary = 1;
var BinaryStream = new ActiveXObject("ADODB.Stream"); var BinaryStream = new ActiveXObject("ADODB.Stream");
@ -52,20 +50,18 @@ scope.getStream_BinaryToString = function(dBinary) {
return BinaryStream.ReadText(); return BinaryStream.ReadText();
}; };
scope.encode = function(sText) { exports.encode = function(sText) {
var oXML = scope.createMSXMLObject(); var oXML = exports.createMSXMLObject();
var oNode = oXML.createElement("base64"); var oNode = oXML.createElement("base64");
oNode.dataType = "bin.base64"; oNode.dataType = "bin.base64";
oNode.nodeTypedValue = scope.getStream_StringToBinary(sText); oNode.nodeTypedValue = exports.getStream_StringToBinary(sText);
return oNode.text; return oNode.text;
}; };
scope.decode = function(vCode) { exports.decode = function(vCode) {
var oXML = scope.createMSXMLObject(); var oXML = exports.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 scope.getStream_BinaryToString(oNode.nodeTypedValue); return exports.getStream_BinaryToString(oNode.nodeTypedValue);
}; };
return scope;

View File

@ -1,15 +1,14 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Example Database API // Example Database API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "Database Module (db.js) version 1.0",
global: global,
require: global.require
};
var LIB = require("lib/std"); var LIB = require("lib/std");
scope.open = function(cs) { exports.VERSIONINFO = "Database Module (db.js) version 1.0";
exports.global = global;
exports.require = global.require;
exports.open = function(cs) {
var instance = {}; var instance = {};
// Create a database connection and open the database, setting isolation level // Create a database connection and open the database, setting isolation level
@ -82,7 +81,7 @@ scope.open = function(cs) {
return instance; return instance;
} }
scope.blob2Text = function(blobField, charset) { exports.blob2Text = function(blobField, charset) {
var stream = LIB.CreateObject("ADODB.Stream"); var stream = LIB.CreateObject("ADODB.Stream");
stream.Charset = (charset || "us-ascii").replace(/;$/, ""); stream.Charset = (charset || "us-ascii").replace(/;$/, "");
stream.Type = 1; stream.Type = 1;
@ -97,7 +96,7 @@ scope.blob2Text = function(blobField, charset) {
return text; return text;
}; };
scope.saveBlob = function(filename, blobField) { exports.saveBlob = function(filename, blobField) {
try { try {
var stream = LIB.CreateObject("ADODB.Stream"); var stream = LIB.CreateObject("ADODB.Stream");
stream.Type = 1; stream.Type = 1;
@ -112,8 +111,6 @@ scope.saveBlob = function(filename, blobField) {
} }
}; };
scope.quoteString = function(s) { exports.quoteString = function(s) {
return "'" + s.replace(/\'/g, "''") + "'"; return "'" + s.replace(/\'/g, "''") + "'";
}; };
return scope;

View File

@ -1,28 +1,27 @@
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
// //
// file-lib.js // file.js
// //
// Common routines. Defines LIB object which contains the API, as well as // Common routines. Defines LIB object which contains the API, as well as
// a global console.log function. // a global console.log function.
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var LIB = require('lib/std'); var LIB = require('lib/std');
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Private APIs / Utility functions // Private APIs / Utility functions
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var scope = { exports.VERSIONINFO = "File Lib (file.js) version 0.2";
VERSIONINFO: "File Lib (file.js) version 0.2", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.fileExists // exports.fileExists
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.fileExists = function(FN) { exports.fileExists = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var exists = FSO.FileExists(FN); var exists = FSO.FileExists(FN);
FSO = null; FSO = null;
@ -30,10 +29,10 @@ scope.fileExists = function(FN) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.folderExists // exports.folderExists
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.folderExists = function(FN) { exports.folderExists = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var exists = FSO.FolderExists(FN); var exists = FSO.FolderExists(FN);
FSO = null; FSO = null;
@ -41,10 +40,10 @@ scope.folderExists = function(FN) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.fileGet // exports.fileGet
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.fileGet = function(FN) { exports.fileGet = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var file = FSO.GetFile(FN); var file = FSO.GetFile(FN);
FSO = null; FSO = null;
@ -52,11 +51,11 @@ scope.fileGet = function(FN) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.readFile // exports.readFile
// Read the conents of the pass filename and return as a string // Read the conents of the pass filename and return as a string
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.readFile = function(FN, charset) { exports.readFile = function(FN, charset) {
if(typeof(charset) === "undefined") { if(typeof(charset) === "undefined") {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var T = null; var T = null;
@ -83,11 +82,11 @@ scope.readFile = function(FN, charset) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.writeFile // exports.writeFile
// Write the passed content to named disk file // Write the passed content to named disk file
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.writeFile = function(FN, content, charset) { exports.writeFile = function(FN, content, charset) {
var ok; var ok;
if (charset) { if (charset) {
console.log("WRITE TO DISK USING ADODB.Stream CHARSET " + charset); console.log("WRITE TO DISK USING ADODB.Stream CHARSET " + charset);
@ -120,10 +119,10 @@ scope.writeFile = function(FN, content, charset) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.moveFile // exports.moveFile
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.moveFile = function(FROM, TO) { exports.moveFile = function(FROM, TO) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.MoveFile(FROM, TO); var res = FSO.MoveFile(FROM, TO);
FSO = null; FSO = null;
@ -131,10 +130,10 @@ scope.moveFile = function(FROM, TO) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.createFolder // exports.createFolder
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.createFolder = function(FN) { exports.createFolder = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.CreateFolder(FN); var res = FSO.CreateFolder(FN);
FSO = null; FSO = null;
@ -142,10 +141,10 @@ scope.createFolder = function(FN) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// scope.deleteFile // exports.deleteFile
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.deleteFile = function(FN) { exports.deleteFile = function(FN) {
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
var res = FSO.DeleteFile(FN); var res = FSO.DeleteFile(FN);
FSO = null; FSO = null;
@ -153,5 +152,3 @@ scope.deleteFile = function(FN) {
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
return scope;

View File

@ -1,15 +1,14 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// HTTP API // HTTP API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "HTTP Module (http.js) version 0.1",
global: global,
require: global.require
};
var LIB = require('lib/std'); var LIB = require("lib/std");
scope.create = function() { exports.VERSIONINFO = "HTTP Module (http.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.create = function() {
var http = null; var http = null;
try { try {
@ -22,7 +21,7 @@ scope.create = function() {
return http; return http;
} }
scope.addHeaders = function(http, headers) { exports.addHeaders = function(http, headers) {
var headers = (typeof(headers) !== "undefined") ? headers : {}; var headers = (typeof(headers) !== "undefined") ? headers : {};
var content = false; var content = false;
@ -38,22 +37,22 @@ scope.addHeaders = function(http, headers) {
http.setRequestHeader("Content-Type", "application/octet-stream"); http.setRequestHeader("Content-Type", "application/octet-stream");
}; };
scope.post = function(url, data, headers) { exports.post = function(url, data, headers) {
var data = (typeof(data) !== "undefined") ? data : ""; var data = (typeof(data) !== "undefined") ? data : "";
var http = scope.create(); var http = exports.create();
http.open("POST", url, false); http.open("POST", url, false);
scope.addHeaders(http, headers); exports.addHeaders(http, headers);
http.send(data); http.send(data);
return http; return http;
}; };
scope.get = function(url, headers) { exports.get = function(url, headers) {
var http = scope.create(); var http = exports.create();
http.open("GET", url, false); http.open("GET", url, false);
scope.addHeaders(http, headers); exports.addHeaders(http, headers);
http.send(); http.send();
return http; return http;
@ -69,7 +68,7 @@ scope.get = function(url, headers) {
* @return object - the HTTP object * @return object - the HTTP object
* *
**/ **/
scope.upload = function(filepath, header_uuid, header_key) { exports.upload = function(filepath, header_uuid, header_key) {
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag"; var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
var data = $.file.readBinary(filepath); var data = $.file.readBinary(filepath);
@ -84,20 +83,20 @@ scope.upload = function(filepath, header_uuid, header_key) {
return $.work.report(data, headers); return $.work.report(data, headers);
}; };
scope.download = function(filepath, header_uuid, header_key) { exports.download = function(filepath, header_uuid, header_key) {
var key = (typeof(header_key) !== "undefined") ? header_key : "ETag"; var key = (typeof(header_key) !== "undefined") ? header_key : "ETag";
var headers = {}; var headers = {};
headers[key] = header_uuid; headers[key] = header_uuid;
return scope.downloadEx("POST", $.work.make_url(), headers, filepath); return exports.downloadEx("POST", $.work.make_url(), headers, filepath);
}; };
scope.downloadEx = function(verb, url, headers, path) { exports.downloadEx = function(verb, url, headers, path) {
if (verb == "GET") { if (verb == "GET") {
var http = scope.get(url, headers); var http = exports.get(url, headers);
} else { } else {
var http = scope.post(url, "", headers); var http = exports.post(url, "", headers);
} }
var stream = LIB.CreateObject("Adodb.Stream"); var stream = LIB.CreateObject("Adodb.Stream");
@ -105,11 +104,11 @@ scope.downloadEx = function(verb, url, headers, path) {
stream.Open(); stream.Open();
stream.Write(http.responseBody); stream.Write(http.responseBody);
var data = scope.bin2str(stream); var data = exports.bin2str(stream);
$.file.write(path, data); $.file.write(path, data);
}; };
scope.bin2str = function(stream) { exports.bin2str = function(stream) {
stream.Flush(); stream.Flush();
stream.Position = 0; stream.Position = 0;
@ -125,5 +124,3 @@ scope.bin2str = function(stream) {
rs.Close(); rs.Close();
return data.substring(0, data.length - 1); return data.substring(0, data.length - 1);
}; };
return scope;

View File

@ -1,13 +1,12 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// JSON API // JSON API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "JSON Module (json.js) version 0.1",
global: global,
require: global.require
};
scope.stringify = function(obj) { exports.VERSIONINFO = "JSON Module (json.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.stringify = function(obj) {
var items = []; var items = [];
var isArray = (function(_obj) { var isArray = (function(_obj) {
try { try {
@ -19,7 +18,7 @@ scope.stringify = function(obj) {
var _toString = function(_obj) { var _toString = function(_obj) {
try { try {
if (typeof(_obj) == "object") { if (typeof(_obj) == "object") {
return scope.stringify(_obj); return exports.stringify(_obj);
} else { } else {
var s = String(_obj).replace(/"/g, '\\"'); var s = String(_obj).replace(/"/g, '\\"');
if (typeof(_obj) == "number" || typeof(_obj) == "boolean") { if (typeof(_obj) == "number" || typeof(_obj) == "boolean") {
@ -50,8 +49,6 @@ scope.stringify = function(obj) {
} }
}; };
scope.parse = function(jsonString) { exports.parse = function(jsonString) {
return (new Function("return " + jsonString)()); return (new Function("return " + jsonString)());
}; };
return scope;

View File

@ -1,12 +1,14 @@
////////////////////////////////////////////////////////////////////////
// Powershell API
///////////////////////////////////////////////////////////////////////
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var scope = { exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
VERSIONINFO: "Powershell (powershell.js) version 0.1", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
scope.addslashes = function(string) { exports.addslashes = function(string) {
return string.replace(/\\/g, '\\\\'). return string.replace(/\\/g, '\\\\').
replace(/\u0008/g, '\\b'). replace(/\u0008/g, '\\b').
replace(/\t/g, '\\t'). replace(/\t/g, '\\t').
@ -17,7 +19,7 @@ scope.addslashes = function(string) {
replace(/"/g, '\\"'); replace(/"/g, '\\"');
}; };
scope.execScript = function(scriptName, args) { exports.execScript = function(scriptName, args) {
var arguments = []; var arguments = [];
arguments.push("powershell.exe"); arguments.push("powershell.exe");
@ -37,7 +39,7 @@ scope.execScript = function(scriptName, args) {
return SHELL.exec(arguments.join(' ')); return SHELL.exec(arguments.join(' '));
}; };
scope.execCommand = function(command) { exports.execCommand = function(command) {
var arguments = []; var arguments = [];
arguments.push("powershell.exe"); arguments.push("powershell.exe");
@ -47,10 +49,8 @@ scope.execCommand = function(command) {
arguments.push("-nologo") arguments.push("-nologo")
arguments.push("-Command"); arguments.push("-Command");
arguments.push("\"& {"); arguments.push("\"& {");
arguments.push(scope.addslashes(command)); arguments.push(exports.addslashes(command));
arguments.push("}\""); arguments.push("}\"");
return SHELL.exec(arguments.join(' ')); return SHELL.exec(arguments.join(' '));
}; };
return scope;

View File

@ -1,54 +1,53 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Registry API // Registry API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "Registry Module (registry.js) version 0.1", exports.VERSIONINFO = "Registry Module (registry.js) version 0.1";
global: global, exports.global = global;
require: global.require exports.require = global.require;
};
// http://apidock.com/ruby/Win32/Registry/Constants // http://apidock.com/ruby/Win32/Registry/Constants
scope.HKCR = 0x80000000; exports.HKCR = 0x80000000;
scope.HKCU = 0x80000001; exports.HKCU = 0x80000001;
scope.HKLM = 0x80000002; exports.HKLM = 0x80000002;
scope.STRING = 0; exports.STRING = 0;
scope.BINARY = 1; exports.BINARY = 1;
scope.DWORD = 2; exports.DWORD = 2;
scope.QWORD = 3; exports.QWORD = 3;
scope.provider = function(computer) { exports.provider = function(computer) {
var computer = (typeof(computer) !== "undefined") ? computer : "."; var computer = (typeof(computer) !== "undefined") ? computer : ".";
var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv"); var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv");
return reg; return reg;
} }
scope.write = function(hKey, path, key, value, valType, computer) { exports.write = function(hKey, path, key, value, valType, computer) {
var reg = scope.provider(computer); var reg = exports.provider(computer);
reg.CreateKey(hKey, path); reg.CreateKey(hKey, path);
if (valType == scope.STRING) if (valType == exports.STRING)
reg.SetStringValue(hKey, path, key, value); reg.SetStringValue(hKey, path, key, value);
else if (valType == scope.DWORD) else if (valType == exports.DWORD)
reg.SetDWORDValue(hKey, path, key, value); reg.SetDWORDValue(hKey, path, key, value);
else if (valType == scope.QWORD) else if (valType == exports.QWORD)
reg.SetQWORDValue(hKey, path, key, value); reg.SetQWORDValue(hKey, path, key, value);
else if (valType == scope.BINARY) else if (valType == exports.BINARY)
reg.SetBinaryValue(hKey, path, key, value); reg.SetBinaryValue(hKey, path, key, value);
} }
scope.read = function(hKey, path, key, valType, computer) { exports.read = function(hKey, path, key, valType, computer) {
var reg = scope.provider(computer); var reg = exports.provider(computer);
var methodName = ""; var methodName = "";
if (valType == scope.STRING) if (valType == exports.STRING)
methodName = "GetStringValue"; methodName = "GetStringValue";
else if (valType == scope.DWORD) else if (valType == exports.DWORD)
methodName = "GetDWORDValue"; methodName = "GetDWORDValue";
else if (valType == scope.QWORD) else if (valType == exports.QWORD)
methodName = "GetQWORDValue"; methodName = "GetQWORDValue";
else if (valType == scope.BINARY) else if (valType == exports.BINARY)
methodName = "GetBinaryValue"; methodName = "GetBinaryValue";
if (methodName == "") if (methodName == "")
@ -66,14 +65,14 @@ scope.read = function(hKey, path, key, valType, computer) {
return outparams; return outparams;
} }
scope.destroy = function(hKey, path, key, computer) { exports.destroy = function(hKey, path, key, computer) {
var reg = scope.provider(computer); var reg = exports.provider(computer);
var loc = (key == "") ? path : path + "\\" + key; var loc = (key == "") ? path : path + "\\" + key;
return reg.DeleteKey(hKey, loc); return reg.DeleteKey(hKey, loc);
} }
// DEPRECATED // DEPRECATED
scope.create = function(hiveKey, path, key, computer) { exports.create = function(hiveKey, path, key, computer) {
console.log("Warning! Registry.create method is DEPRECATED."); console.log("Warning! Registry.create method is DEPRECATED.");
var computer = (typeof(computer) !== "undefined") ? computer : "."; var computer = (typeof(computer) !== "undefined") ? computer : ".";
@ -112,7 +111,7 @@ scope.create = function(hiveKey, path, key, computer) {
return createRet.returnValue == 0; return createRet.returnValue == 0;
} }
scope.import = function(scriptName) { exports.import = function(scriptName) {
var arguments = []; var arguments = [];
arguments.push("reg"); arguments.push("reg");
@ -121,5 +120,3 @@ scope.import = function(scriptName) {
return SHELL.exec(arguments.join(' ')); return SHELL.exec(arguments.join(' '));
}; };
return scope;

View File

@ -1,19 +1,19 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Security API // Security API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "Security Module (security.js) version 0.1",
global: global,
require: global.require
};
var REG = require("lib/registry"); var REG = require("lib/registry");
var WSH = CreateObject("WScript.Shell"); var WSH = CreateObject("WScript.Shell");
scope.DISABLED = 0x00000001; exports.VERSIONINFO = "Security Module (security.js) version 0.1";
scope.ENABLED = 0x00000000; exports.global = global;
exports.require = global.require;
exports.DISABLED = 0x00000001;
exports.ENABLED = 0x00000000;
// check 'run as administrator' // check 'run as administrator'
scope.isElevated = function() { exports.isElevated = function() {
try { try {
WSH.RegRead("HKEY_USERS\\s-1-5-19\\"); WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
return true; return true;
@ -23,28 +23,28 @@ scope.isElevated = function() {
}; };
// turn on/off Windows Defender // turn on/off Windows Defender
scope.setAntiSpyware = function(buffer) { exports.setAntiSpyware = function(buffer) {
var path = "SOFTWARE\\Policies\\Microsoft\\Windows Defender"; var path = "SOFTWARE\\Policies\\Microsoft\\Windows Defender";
var key = "DisableAntiSpyware"; var key = "DisableAntiSpyware";
REG.write(registry.HKLM, path, key, buffer, registry.DWORD); REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
}; };
// trun on/off Registry Editor (regedit) // trun on/off Registry Editor (regedit)
scope.setRegedit = function(buffer) { exports.setRegedit = function(buffer) {
var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
var key = "DisableRegistryTools"; var key = "DisableRegistryTools";
REG.write(registry.HKLM, path, key, buffer, registry.DWORD); REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
}; };
// turn on/off Task Manager (taskmgr) // turn on/off Task Manager (taskmgr)
scope.setTaskmgr = function(buffer) { exports.setTaskmgr = function(buffer) {
var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System"; var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
var key = "DisableTaskMgr"; var key = "DisableTaskMgr";
REG.write(registry.HKLM, path, key, buffer, registry.DWORD); REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
}; };
// detect antivirus from security center // detect antivirus from security center
scope.detectAntivirus = function() { exports.detectAntivirus = function() {
var displayNames = []; var displayNames = [];
var objWMIService = GetObject("winmgmts:\\.\root\SecurityCenter2"); var objWMIService = GetObject("winmgmts:\\.\root\SecurityCenter2");
@ -57,5 +57,3 @@ scope.detectAntivirus = function() {
return displayNames; return displayNames;
}; };
return scope;

View File

@ -5,44 +5,43 @@
// Sendmail using either CDO or Persits.MailSender // Sendmail using either CDO or Persits.MailSender
// //
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var LIB = require('lib/std');
var LIB = require("lib/std");
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Private APIs / Utility functions // Private APIs / Utility functions
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var scope = { exports.VERSIONINFO = "Sendmail Lib (sendmail.js) version 0.1";
VERSIONINFO: "sendmail Lib (sendmail.js) version 0.1", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Send Mail Message // Send Mail Message
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.sendmail = function(msg) { exports.sendmail = function(msg) {
var ok, MAIL; var ok, MAIL;
DBG("SENDMAIL: " + msg.To); console.log("SENDMAIL: " + msg.To);
// Which method we use depends on the system. On some versions of // Which method we use depends on the system. On some versions of
// Persits.MailSender it does not support adding of Message-ID // Persits.MailSender it does not support adding of Message-ID
// so we have to use CDO (which is the preferred option anyway). // so we have to use CDO (which is the preferred option anyway).
if (scope.usePersitsMailSender) { if (exports.usePersitsMailSender) {
// Use Persits AspEmail to send mail // Use Persits AspEmail to send mail
try { try {
MAIL = scope.CreateObject("Persits.MailSender"); MAIL = CreateObject("Persits.MailSender");
} catch (e) { } catch (e) {
DBG("ERROR " + e.number + ", " + e.description); console.log("ERROR " + e.number + ", " + e.description);
throw e; throw e;
} }
DBG("USING PERSITS MAIL SENDER"); console.log("USING PERSITS MAIL SENDER");
DBG("MAIL FROM " + msg.From); console.log("MAIL FROM " + msg.From);
DBG("MAIL TO " + msg.To); console.log("MAIL TO " + msg.To);
DBG("SUBJECT " + msg.Subject); console.log("SUBJECT " + msg.Subject);
MAIL.Host = msg.MAILHOST; MAIL.Host = msg.MAILHOST;
MAIL.From = msg.From; MAIL.From = msg.From;
@ -53,9 +52,9 @@ scope.sendmail = function(msg) {
MAIL.IsHTML = msg.IsHTML; MAIL.IsHTML = msg.IsHTML;
MAIL.Body = msg.Body; MAIL.Body = msg.Body;
MAIL.addCustomHeader("Reply-To: <" + msg.ReplyTo + ">"); MAIL.addCustomHeader("Reply-To: <" + msg.ReplyTo + ">");
DBG("Reply-To: <" + msg.ReplyTo + ">"); console.log("Reply-To: <" + msg.ReplyTo + ">");
if (msg.id) { if (msg.id) {
DBG("Message-ID: <" + msg.id + ">"); console.log("Message-ID: <" + msg.id + ">");
MAIL.addCustomHeader("Message-ID: <" + msg.id + ">"); MAIL.addCustomHeader("Message-ID: <" + msg.id + ">");
} }
@ -93,13 +92,13 @@ scope.sendmail = function(msg) {
} }
try { try {
DBG("Sending email To " + msg.To + (msg.Cc ? " (Cc " + msg.Cc + ")" : "")); console.log("Sending email To " + msg.To + (msg.Cc ? " (Cc " + msg.Cc + ")" : ""));
MAIL.Send(); MAIL.Send();
ok = true; ok = true;
} catch (e) { } catch (e) {
DBG(e.number + "," + e.description); console.log(e.number + "," + e.description);
ok = false; ok = false;
DBG("failed"); console.log("failed");
} }
MAIL = null; MAIL = null;
@ -108,4 +107,4 @@ scope.sendmail = function(msg) {
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
return scope; return scope;

View File

@ -1,15 +1,14 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Shell API // Shell API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var FILE = require('lib/file'); var FILE = require('lib/file');
var scope = { exports.VERSIONINFO = "Shell Module (shell.js) version 0.1";
VERSIONINFO: "Shell Module (shell.js) version 0.1", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
scope.exec = function(cmd, stdOutPath) { exports.exec = function(cmd, stdOutPath) {
var WSH = CreateObject("WScript.Shell"), var WSH = CreateObject("WScript.Shell"),
data; data;
@ -28,11 +27,9 @@ scope.exec = function(cmd, stdOutPath) {
return data; return data;
} }
scope.run = function(cmd, fork) { exports.run = function(cmd, fork) {
var WSH = CreateObject("WScript.Shell"); var WSH = CreateObject("WScript.Shell");
var fork = (typeof(fork) !== "undefined") ? fork : true; var fork = (typeof(fork) !== "undefined") ? fork : true;
var c = "%comspec% /q /c " + cmd; var c = "%comspec% /q /c " + cmd;
WSH.Run(cmd, 0, !fork); WSH.Run(cmd, 0, !fork);
}; };
return scope;

View File

@ -76,20 +76,16 @@ global.exit = function() {
// Private APIs / Utility functions // Private APIs / Utility functions
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
var scope = { exports.VERSIONINFO = "Standard Lib (std.js) version 0.2";
VERSIONINFO: "Standard Lib (std.js) version 0.2", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
// Emulate Server.CreateObject // Emulate Server.CreateObject
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
scope.CreateObject = function(n) { exports.CreateObject = function(n) {
return new ActiveXObject(n); return new ActiveXObject(n);
}; };
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
return scope;

View File

@ -2,18 +2,16 @@
// System API // System API
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
var scope = {
VERSIONINFO: "System Module (system.js) version 0.1",
global: global,
require: global.require
};
var SHELL = require("lib/shell"); var SHELL = require("lib/shell");
var WSH = CreateObject("WScript.Shell"); var WSH = CreateObject("WScript.Shell");
var WMI = GetObject("winmgmts:\\\\.\\root\\CIMV2"); var WMI = GetObject("winmgmts:\\\\.\\root\\CIMV2");
var FSO = CreateObject("Scripting.FileSystemObject"); var FSO = CreateObject("Scripting.FileSystemObject");
scope.isElevated = function() { exports.VERSIONINFO = "System Module (system.js) version 0.1";
exports.global = global;
exports.require = global.require;
exports.isElevated = function() {
try { try {
WSH.RegRead("HKEY_USERS\\s-1-5-19\\"); WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
return true; return true;
@ -22,7 +20,7 @@ scope.isElevated = function() {
} }
}; };
scope.getOS = function() { exports.getOS = function() {
try { try {
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem"); var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
var enumItems = new Enumerator(colItems); var enumItems = new Enumerator(colItems);
@ -31,7 +29,7 @@ scope.getOS = function() {
} catch (e) {} } catch (e) {}
}; };
scope.getDCName = function() { exports.getDCName = function() {
try { try {
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName"); var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
if (DC.length > 0) if (DC.length > 0)
@ -39,7 +37,7 @@ scope.getDCName = function() {
} catch (e) {} } catch (e) {}
}; };
scope.getArch = function() { exports.getArch = function() {
try { try {
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem"); var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
var enumItems = new Enumerator(colItems); var enumItems = new Enumerator(colItems);
@ -48,7 +46,7 @@ scope.getArch = function() {
} catch (e) {} } catch (e) {}
}; };
scope.getUUID = function() { exports.getUUID = function() {
try { try {
var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct"); var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct");
var enumItems = new Enumerator(colItems); var enumItems = new Enumerator(colItems);
@ -57,7 +55,7 @@ scope.getUUID = function() {
} catch (e) {} } catch (e) {}
}; };
scope.getCurrentWorkingDirectory = function() { exports.getCurrentWorkingDirectory = function() {
try { try {
cwd = SHELL.exec("cd", "cwd.txt").rtrim(); cwd = SHELL.exec("cd", "cwd.txt").rtrim();
return cwd; return cwd;
@ -65,13 +63,13 @@ scope.getCurrentWorkingDirectory = function() {
}; };
// "console only"; // "console only";
scope.getCurrentScriptDirectory = function() { exports.getCurrentScriptDirectory = function() {
var path = WScript.ScriptFullName; var path = WScript.ScriptFullName;
var pos = path.lastIndexOf("\\"); var pos = path.lastIndexOf("\\");
return path.substring(0, pos); return path.substring(0, pos);
}; };
scope.getNetworkInterfaces = function() { exports.getNetworkInterfaces = function() {
var wbemFlagReturnImmediately = 0x10; var wbemFlagReturnImmediately = 0x10;
var wbemFlagForwardOnly = 0x20; var wbemFlagForwardOnly = 0x20;
var rows = []; var rows = [];
@ -99,7 +97,7 @@ scope.getNetworkInterfaces = function() {
return rows; return rows;
}; };
scope.getCurrentProcesses = function() { exports.getCurrentProcesses = function() {
var processes = []; var processes = [];
var response = SHELL.exec("tasklist.exe"); var response = SHELL.exec("tasklist.exe");
@ -113,8 +111,8 @@ scope.getCurrentProcesses = function() {
return processes; return processes;
}; };
scope.createShortcut = function(shoutcutName, fileName) { exports.createShortcut = function(shoutcutName, fileName) {
var workingDirectory = scope.getCurrentWorkingDirectory(); var workingDirectory = exports.getCurrentWorkingDirectory();
var desktopPath = WSH.SpecialFolders("Desktop"); var desktopPath = WSH.SpecialFolders("Desktop");
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk"); var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
link.IconLocation = fileName + ",1"; link.IconLocation = fileName + ",1";
@ -123,5 +121,3 @@ scope.createShortcut = function(shoutcutName, fileName) {
link.WorkingDirectory = workingDirectory; link.WorkingDirectory = workingDirectory;
link.Save(); link.Save();
}; };
return scope;

View File

@ -16,32 +16,30 @@
functions in the queue, call the run method again. functions in the queue, call the run method again.
*/ */
var scope = { exports.VERSIONINFO = "Timer Module (timer.js) version 0.1";
VERSIONINFO: "Timer Module (timer.js) version 0.1", exports.global = global;
global: global, exports.require = global.require;
require: global.require
};
scope.sleep = function(ms, callback) { exports.sleep = function(ms, callback) {
WScript.Sleep(ms); WScript.Sleep(ms);
if(typeof(callback) == "function") { if(typeof(callback) == "function") {
callback(); callback();
} }
}; };
scope.setTimeout = function(func, delay) { exports.setTimeout = function(func, delay) {
var when = new Date().getTime() + delay; var when = new Date().getTime() + delay;
return scope.setTimeout.queue.add(func, when); return exports.setTimeout.queue.add(func, when);
}; };
scope.clearTimeout = function(timer) { exports.clearTimeout = function(timer) {
scope.setTimeout.queue.del(timer); exports.setTimeout.queue.del(timer);
}; };
// A queue object, with methods add, del, run. // A queue object, with methods add, del, run.
// Tied to setTimeout to keep it out of the global namespace. // Tied to setTimeout to keep it out of the global namespace.
scope.setTimeout.queue = (function() { exports.setTimeout.queue = (function() {
var store = []; var store = [];
var nextid = 0; var nextid = 0;
@ -70,7 +68,7 @@ scope.setTimeout.queue = (function() {
var item = store[i]; var item = store[i];
if (now > item.when) { if (now > item.when) {
scope.setTimeout.queue.del(item.id); exports.setTimeout.queue.del(item.id);
item.func(); // <---- actually invoke the function here item.func(); // <---- actually invoke the function here
// Note: we can't continue looping through the queue here, // Note: we can't continue looping through the queue here,
@ -83,30 +81,30 @@ scope.setTimeout.queue = (function() {
// We burn a millisecond here to throttle the looping. // We burn a millisecond here to throttle the looping.
// Otherwise it will loop on the order of 200,000 times per sec. // Otherwise it will loop on the order of 200,000 times per sec.
scope.sleep(1); exports.sleep(1);
} }
} }
} }
} }
})(); })();
scope.setTimeout.test = function() { exports.setTimeout.test = function() {
console.log('You should see: C,A,D,N,M'); console.log('You should see: C,A,D,N,M');
scope.setTimeout(console.log('A'), 500); exports.setTimeout(console.log('A'), 500);
var b = setTimeout(console.log('B'), 1220); var b = setTimeout(console.log('B'), 1220);
scope.setTimeout(console.log('C'), 300); exports.setTimeout(console.log('C'), 300);
scope.setTimeout(console.log('D'), 1000); exports.setTimeout(console.log('D'), 1000);
clearTimeout(b); clearTimeout(b);
scope.setTimeout(function() { exports.setTimeout(function() {
console.log('N'); console.log('N');
scope.setTimeout(function() { exports.setTimeout(function() {
console.log('M'); console.log('M');
}, 100) }, 100)
}, 1300); }, 1300);
scope.setTimeout.queue.run(); exports.setTimeout.queue.run();
console.log('done'); console.log('done');
}; };