mirror of
https://github.com/gnh1201/welsonjs.git
synced 2024-11-26 15:31:42 +00:00
add node-style module.exports compatibility
This commit is contained in:
parent
043650a3e5
commit
61041197fa
2
app.js
2
app.js
|
@ -90,7 +90,7 @@ function require(FN) {
|
|||
|
||||
// make global function
|
||||
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 {
|
||||
cache[FN] = eval(T);
|
||||
} catch (e) {
|
||||
|
|
|
@ -2,13 +2,11 @@
|
|||
// Base64 API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "Base64 Module (base64.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Base64 Module (base64.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = require;
|
||||
|
||||
scope.createMSXMLObject = function() {
|
||||
exports.createMSXMLObject = function() {
|
||||
var progIDs = [
|
||||
"Msxml2.DOMDocument.6.0",
|
||||
"Msxml2.DOMDocument.5.0",
|
||||
|
@ -25,7 +23,7 @@ scope.createMSXMLObject = function() {
|
|||
return null;
|
||||
};
|
||||
|
||||
scope.getStream_StringToBinary = function(dText) {
|
||||
exports.getStream_StringToBinary = function(dText) {
|
||||
var adTypeText = 2;
|
||||
var adTypeBinary = 1;
|
||||
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
||||
|
@ -39,7 +37,7 @@ scope.getStream_StringToBinary = function(dText) {
|
|||
return BinaryStream.Read();
|
||||
};
|
||||
|
||||
scope.getStream_BinaryToString = function(dBinary) {
|
||||
exports.getStream_BinaryToString = function(dBinary) {
|
||||
var adTypeText = 2;
|
||||
var adTypeBinary = 1;
|
||||
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
||||
|
@ -52,20 +50,18 @@ scope.getStream_BinaryToString = function(dBinary) {
|
|||
return BinaryStream.ReadText();
|
||||
};
|
||||
|
||||
scope.encode = function(sText) {
|
||||
var oXML = scope.createMSXMLObject();
|
||||
exports.encode = function(sText) {
|
||||
var oXML = exports.createMSXMLObject();
|
||||
var oNode = oXML.createElement("base64");
|
||||
oNode.dataType = "bin.base64";
|
||||
oNode.nodeTypedValue = scope.getStream_StringToBinary(sText);
|
||||
oNode.nodeTypedValue = exports.getStream_StringToBinary(sText);
|
||||
return oNode.text;
|
||||
};
|
||||
|
||||
scope.decode = function(vCode) {
|
||||
var oXML = scope.createMSXMLObject();
|
||||
exports.decode = function(vCode) {
|
||||
var oXML = exports.createMSXMLObject();
|
||||
var oNode = oXML.createElement("base64");
|
||||
oNode.dataType = "bin.base64";
|
||||
oNode.text = vCode;
|
||||
return scope.getStream_BinaryToString(oNode.nodeTypedValue);
|
||||
return exports.getStream_BinaryToString(oNode.nodeTypedValue);
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
19
lib/db.js
19
lib/db.js
|
@ -1,15 +1,14 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Example Database API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
var scope = {
|
||||
VERSIONINFO: "Database Module (db.js) version 1.0",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
|
||||
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 = {};
|
||||
|
||||
// Create a database connection and open the database, setting isolation level
|
||||
|
@ -82,7 +81,7 @@ scope.open = function(cs) {
|
|||
return instance;
|
||||
}
|
||||
|
||||
scope.blob2Text = function(blobField, charset) {
|
||||
exports.blob2Text = function(blobField, charset) {
|
||||
var stream = LIB.CreateObject("ADODB.Stream");
|
||||
stream.Charset = (charset || "us-ascii").replace(/;$/, "");
|
||||
stream.Type = 1;
|
||||
|
@ -97,7 +96,7 @@ scope.blob2Text = function(blobField, charset) {
|
|||
return text;
|
||||
};
|
||||
|
||||
scope.saveBlob = function(filename, blobField) {
|
||||
exports.saveBlob = function(filename, blobField) {
|
||||
try {
|
||||
var stream = LIB.CreateObject("ADODB.Stream");
|
||||
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 scope;
|
||||
|
|
45
lib/file.js
45
lib/file.js
|
@ -1,28 +1,27 @@
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// file-lib.js
|
||||
// file.js
|
||||
//
|
||||
// Common routines. Defines LIB object which contains the API, as well as
|
||||
// a global console.log function.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var LIB = require('lib/std');
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Private APIs / Utility functions
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "File Lib (file.js) version 0.2",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "File Lib (file.js) version 0.2";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// scope.fileExists
|
||||
// exports.fileExists
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
scope.fileExists = function(FN) {
|
||||
exports.fileExists = function(FN) {
|
||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||
var exists = FSO.FileExists(FN);
|
||||
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 exists = FSO.FolderExists(FN);
|
||||
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 file = FSO.GetFile(FN);
|
||||
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
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
scope.readFile = function(FN, charset) {
|
||||
exports.readFile = function(FN, charset) {
|
||||
if(typeof(charset) === "undefined") {
|
||||
var FSO = CreateObject("Scripting.FileSystemObject");
|
||||
var T = null;
|
||||
|
@ -83,11 +82,11 @@ scope.readFile = function(FN, charset) {
|
|||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// scope.writeFile
|
||||
// exports.writeFile
|
||||
// Write the passed content to named disk file
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
scope.writeFile = function(FN, content, charset) {
|
||||
exports.writeFile = function(FN, content, charset) {
|
||||
var ok;
|
||||
if (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 res = FSO.MoveFile(FROM, TO);
|
||||
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 res = FSO.CreateFolder(FN);
|
||||
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 res = FSO.DeleteFile(FN);
|
||||
FSO = null;
|
||||
|
@ -153,5 +152,3 @@ scope.deleteFile = function(FN) {
|
|||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return scope;
|
||||
|
|
45
lib/http.js
45
lib/http.js
|
@ -1,15 +1,14 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
try {
|
||||
|
@ -22,7 +21,7 @@ scope.create = function() {
|
|||
return http;
|
||||
}
|
||||
|
||||
scope.addHeaders = function(http, headers) {
|
||||
exports.addHeaders = function(http, headers) {
|
||||
var headers = (typeof(headers) !== "undefined") ? headers : {};
|
||||
|
||||
var content = false;
|
||||
|
@ -38,22 +37,22 @@ scope.addHeaders = function(http, headers) {
|
|||
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 http = scope.create();
|
||||
var http = exports.create();
|
||||
|
||||
http.open("POST", url, false);
|
||||
scope.addHeaders(http, headers);
|
||||
exports.addHeaders(http, headers);
|
||||
http.send(data);
|
||||
|
||||
return http;
|
||||
};
|
||||
|
||||
scope.get = function(url, headers) {
|
||||
var http = scope.create();
|
||||
exports.get = function(url, headers) {
|
||||
var http = exports.create();
|
||||
http.open("GET", url, false);
|
||||
scope.addHeaders(http, headers);
|
||||
exports.addHeaders(http, headers);
|
||||
http.send();
|
||||
|
||||
return http;
|
||||
|
@ -69,7 +68,7 @@ scope.get = function(url, headers) {
|
|||
* @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 data = $.file.readBinary(filepath);
|
||||
|
@ -84,20 +83,20 @@ scope.upload = function(filepath, header_uuid, header_key) {
|
|||
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 headers = {};
|
||||
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") {
|
||||
var http = scope.get(url, headers);
|
||||
var http = exports.get(url, headers);
|
||||
} else {
|
||||
var http = scope.post(url, "", headers);
|
||||
var http = exports.post(url, "", headers);
|
||||
}
|
||||
|
||||
var stream = LIB.CreateObject("Adodb.Stream");
|
||||
|
@ -105,11 +104,11 @@ scope.downloadEx = function(verb, url, headers, path) {
|
|||
stream.Open();
|
||||
stream.Write(http.responseBody);
|
||||
|
||||
var data = scope.bin2str(stream);
|
||||
var data = exports.bin2str(stream);
|
||||
$.file.write(path, data);
|
||||
};
|
||||
|
||||
scope.bin2str = function(stream) {
|
||||
exports.bin2str = function(stream) {
|
||||
stream.Flush();
|
||||
stream.Position = 0;
|
||||
|
||||
|
@ -125,5 +124,3 @@ scope.bin2str = function(stream) {
|
|||
rs.Close();
|
||||
return data.substring(0, data.length - 1);
|
||||
};
|
||||
|
||||
return scope;
|
17
lib/json.js
17
lib/json.js
|
@ -1,13 +1,12 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// 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 isArray = (function(_obj) {
|
||||
try {
|
||||
|
@ -19,7 +18,7 @@ scope.stringify = function(obj) {
|
|||
var _toString = function(_obj) {
|
||||
try {
|
||||
if (typeof(_obj) == "object") {
|
||||
return scope.stringify(_obj);
|
||||
return exports.stringify(_obj);
|
||||
} else {
|
||||
var s = String(_obj).replace(/"/g, '\\"');
|
||||
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 scope;
|
|
@ -1,12 +1,14 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Powershell API
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
var SHELL = require("lib/shell");
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "Powershell (powershell.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Powershell (powershell.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
scope.addslashes = function(string) {
|
||||
exports.addslashes = function(string) {
|
||||
return string.replace(/\\/g, '\\\\').
|
||||
replace(/\u0008/g, '\\b').
|
||||
replace(/\t/g, '\\t').
|
||||
|
@ -17,7 +19,7 @@ scope.addslashes = function(string) {
|
|||
replace(/"/g, '\\"');
|
||||
};
|
||||
|
||||
scope.execScript = function(scriptName, args) {
|
||||
exports.execScript = function(scriptName, args) {
|
||||
var arguments = [];
|
||||
|
||||
arguments.push("powershell.exe");
|
||||
|
@ -37,7 +39,7 @@ scope.execScript = function(scriptName, args) {
|
|||
return SHELL.exec(arguments.join(' '));
|
||||
};
|
||||
|
||||
scope.execCommand = function(command) {
|
||||
exports.execCommand = function(command) {
|
||||
var arguments = [];
|
||||
|
||||
arguments.push("powershell.exe");
|
||||
|
@ -47,10 +49,8 @@ scope.execCommand = function(command) {
|
|||
arguments.push("-nologo")
|
||||
arguments.push("-Command");
|
||||
arguments.push("\"& {");
|
||||
arguments.push(scope.addslashes(command));
|
||||
arguments.push(exports.addslashes(command));
|
||||
arguments.push("}\"");
|
||||
|
||||
return SHELL.exec(arguments.join(' '));
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
|
@ -1,54 +1,53 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Registry API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
var scope = {
|
||||
VERSIONINFO: "Registry Module (registry.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
|
||||
exports.VERSIONINFO = "Registry Module (registry.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
// http://apidock.com/ruby/Win32/Registry/Constants
|
||||
scope.HKCR = 0x80000000;
|
||||
scope.HKCU = 0x80000001;
|
||||
scope.HKLM = 0x80000002;
|
||||
exports.HKCR = 0x80000000;
|
||||
exports.HKCU = 0x80000001;
|
||||
exports.HKLM = 0x80000002;
|
||||
|
||||
scope.STRING = 0;
|
||||
scope.BINARY = 1;
|
||||
scope.DWORD = 2;
|
||||
scope.QWORD = 3;
|
||||
exports.STRING = 0;
|
||||
exports.BINARY = 1;
|
||||
exports.DWORD = 2;
|
||||
exports.QWORD = 3;
|
||||
|
||||
scope.provider = function(computer) {
|
||||
exports.provider = function(computer) {
|
||||
var computer = (typeof(computer) !== "undefined") ? computer : ".";
|
||||
var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv");
|
||||
return reg;
|
||||
}
|
||||
|
||||
scope.write = function(hKey, path, key, value, valType, computer) {
|
||||
var reg = scope.provider(computer);
|
||||
exports.write = function(hKey, path, key, value, valType, computer) {
|
||||
var reg = exports.provider(computer);
|
||||
|
||||
reg.CreateKey(hKey, path);
|
||||
|
||||
if (valType == scope.STRING)
|
||||
if (valType == exports.STRING)
|
||||
reg.SetStringValue(hKey, path, key, value);
|
||||
else if (valType == scope.DWORD)
|
||||
else if (valType == exports.DWORD)
|
||||
reg.SetDWORDValue(hKey, path, key, value);
|
||||
else if (valType == scope.QWORD)
|
||||
else if (valType == exports.QWORD)
|
||||
reg.SetQWORDValue(hKey, path, key, value);
|
||||
else if (valType == scope.BINARY)
|
||||
else if (valType == exports.BINARY)
|
||||
reg.SetBinaryValue(hKey, path, key, value);
|
||||
}
|
||||
|
||||
scope.read = function(hKey, path, key, valType, computer) {
|
||||
var reg = scope.provider(computer);
|
||||
exports.read = function(hKey, path, key, valType, computer) {
|
||||
var reg = exports.provider(computer);
|
||||
|
||||
var methodName = "";
|
||||
if (valType == scope.STRING)
|
||||
if (valType == exports.STRING)
|
||||
methodName = "GetStringValue";
|
||||
else if (valType == scope.DWORD)
|
||||
else if (valType == exports.DWORD)
|
||||
methodName = "GetDWORDValue";
|
||||
else if (valType == scope.QWORD)
|
||||
else if (valType == exports.QWORD)
|
||||
methodName = "GetQWORDValue";
|
||||
else if (valType == scope.BINARY)
|
||||
else if (valType == exports.BINARY)
|
||||
methodName = "GetBinaryValue";
|
||||
|
||||
if (methodName == "")
|
||||
|
@ -66,14 +65,14 @@ scope.read = function(hKey, path, key, valType, computer) {
|
|||
return outparams;
|
||||
}
|
||||
|
||||
scope.destroy = function(hKey, path, key, computer) {
|
||||
var reg = scope.provider(computer);
|
||||
exports.destroy = function(hKey, path, key, computer) {
|
||||
var reg = exports.provider(computer);
|
||||
var loc = (key == "") ? path : path + "\\" + key;
|
||||
return reg.DeleteKey(hKey, loc);
|
||||
}
|
||||
|
||||
// DEPRECATED
|
||||
scope.create = function(hiveKey, path, key, computer) {
|
||||
exports.create = function(hiveKey, path, key, computer) {
|
||||
console.log("Warning! Registry.create method is DEPRECATED.");
|
||||
|
||||
var computer = (typeof(computer) !== "undefined") ? computer : ".";
|
||||
|
@ -112,7 +111,7 @@ scope.create = function(hiveKey, path, key, computer) {
|
|||
return createRet.returnValue == 0;
|
||||
}
|
||||
|
||||
scope.import = function(scriptName) {
|
||||
exports.import = function(scriptName) {
|
||||
var arguments = [];
|
||||
|
||||
arguments.push("reg");
|
||||
|
@ -121,5 +120,3 @@ scope.import = function(scriptName) {
|
|||
|
||||
return SHELL.exec(arguments.join(' '));
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Security API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
var scope = {
|
||||
VERSIONINFO: "Security Module (security.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
|
||||
var REG = require("lib/registry");
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
|
||||
scope.DISABLED = 0x00000001;
|
||||
scope.ENABLED = 0x00000000;
|
||||
exports.VERSIONINFO = "Security Module (security.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
exports.DISABLED = 0x00000001;
|
||||
exports.ENABLED = 0x00000000;
|
||||
|
||||
// check 'run as administrator'
|
||||
scope.isElevated = function() {
|
||||
exports.isElevated = function() {
|
||||
try {
|
||||
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
||||
return true;
|
||||
|
@ -23,28 +23,28 @@ scope.isElevated = function() {
|
|||
};
|
||||
|
||||
// turn on/off Windows Defender
|
||||
scope.setAntiSpyware = function(buffer) {
|
||||
exports.setAntiSpyware = function(buffer) {
|
||||
var path = "SOFTWARE\\Policies\\Microsoft\\Windows Defender";
|
||||
var key = "DisableAntiSpyware";
|
||||
REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
|
||||
};
|
||||
|
||||
// trun on/off Registry Editor (regedit)
|
||||
scope.setRegedit = function(buffer) {
|
||||
exports.setRegedit = function(buffer) {
|
||||
var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
|
||||
var key = "DisableRegistryTools";
|
||||
REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
|
||||
};
|
||||
|
||||
// turn on/off Task Manager (taskmgr)
|
||||
scope.setTaskmgr = function(buffer) {
|
||||
exports.setTaskmgr = function(buffer) {
|
||||
var path = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System";
|
||||
var key = "DisableTaskMgr";
|
||||
REG.write(registry.HKLM, path, key, buffer, registry.DWORD);
|
||||
};
|
||||
|
||||
// detect antivirus from security center
|
||||
scope.detectAntivirus = function() {
|
||||
exports.detectAntivirus = function() {
|
||||
var displayNames = [];
|
||||
|
||||
var objWMIService = GetObject("winmgmts:\\.\root\SecurityCenter2");
|
||||
|
@ -57,5 +57,3 @@ scope.detectAntivirus = function() {
|
|||
|
||||
return displayNames;
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
|
@ -5,44 +5,43 @@
|
|||
// Sendmail using either CDO or Persits.MailSender
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
var LIB = require('lib/std');
|
||||
|
||||
var LIB = require("lib/std");
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Private APIs / Utility functions
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "sendmail Lib (sendmail.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Sendmail Lib (sendmail.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Send Mail Message
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
scope.sendmail = function(msg) {
|
||||
exports.sendmail = function(msg) {
|
||||
var ok, MAIL;
|
||||
|
||||
DBG("SENDMAIL: " + msg.To);
|
||||
console.log("SENDMAIL: " + msg.To);
|
||||
|
||||
// Which method we use depends on the system. On some versions of
|
||||
// Persits.MailSender it does not support adding of Message-ID
|
||||
// so we have to use CDO (which is the preferred option anyway).
|
||||
if (scope.usePersitsMailSender) {
|
||||
if (exports.usePersitsMailSender) {
|
||||
|
||||
// Use Persits AspEmail to send mail
|
||||
try {
|
||||
MAIL = scope.CreateObject("Persits.MailSender");
|
||||
MAIL = CreateObject("Persits.MailSender");
|
||||
} catch (e) {
|
||||
DBG("ERROR " + e.number + ", " + e.description);
|
||||
console.log("ERROR " + e.number + ", " + e.description);
|
||||
throw e;
|
||||
}
|
||||
|
||||
DBG("USING PERSITS MAIL SENDER");
|
||||
DBG("MAIL FROM " + msg.From);
|
||||
DBG("MAIL TO " + msg.To);
|
||||
DBG("SUBJECT " + msg.Subject);
|
||||
console.log("USING PERSITS MAIL SENDER");
|
||||
console.log("MAIL FROM " + msg.From);
|
||||
console.log("MAIL TO " + msg.To);
|
||||
console.log("SUBJECT " + msg.Subject);
|
||||
|
||||
MAIL.Host = msg.MAILHOST;
|
||||
MAIL.From = msg.From;
|
||||
|
@ -53,9 +52,9 @@ scope.sendmail = function(msg) {
|
|||
MAIL.IsHTML = msg.IsHTML;
|
||||
MAIL.Body = msg.Body;
|
||||
MAIL.addCustomHeader("Reply-To: <" + msg.ReplyTo + ">");
|
||||
DBG("Reply-To: <" + msg.ReplyTo + ">");
|
||||
console.log("Reply-To: <" + msg.ReplyTo + ">");
|
||||
if (msg.id) {
|
||||
DBG("Message-ID: <" + msg.id + ">");
|
||||
console.log("Message-ID: <" + msg.id + ">");
|
||||
MAIL.addCustomHeader("Message-ID: <" + msg.id + ">");
|
||||
}
|
||||
|
||||
|
@ -93,13 +92,13 @@ scope.sendmail = function(msg) {
|
|||
}
|
||||
|
||||
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();
|
||||
ok = true;
|
||||
} catch (e) {
|
||||
DBG(e.number + "," + e.description);
|
||||
console.log(e.number + "," + e.description);
|
||||
ok = false;
|
||||
DBG("failed");
|
||||
console.log("failed");
|
||||
}
|
||||
|
||||
MAIL = null;
|
||||
|
@ -108,4 +107,4 @@ scope.sendmail = function(msg) {
|
|||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return scope;
|
||||
return scope;
|
||||
|
|
15
lib/shell.js
15
lib/shell.js
|
@ -1,15 +1,14 @@
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
// Shell API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var FILE = require('lib/file');
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "Shell Module (shell.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Shell Module (shell.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
scope.exec = function(cmd, stdOutPath) {
|
||||
exports.exec = function(cmd, stdOutPath) {
|
||||
var WSH = CreateObject("WScript.Shell"),
|
||||
data;
|
||||
|
||||
|
@ -28,11 +27,9 @@ scope.exec = function(cmd, stdOutPath) {
|
|||
return data;
|
||||
}
|
||||
|
||||
scope.run = function(cmd, fork) {
|
||||
exports.run = function(cmd, fork) {
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var fork = (typeof(fork) !== "undefined") ? fork : true;
|
||||
var c = "%comspec% /q /c " + cmd;
|
||||
WSH.Run(cmd, 0, !fork);
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
12
lib/std.js
12
lib/std.js
|
@ -76,20 +76,16 @@ global.exit = function() {
|
|||
// Private APIs / Utility functions
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "Standard Lib (std.js) version 0.2",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Standard Lib (std.js) version 0.2";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Emulate Server.CreateObject
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
scope.CreateObject = function(n) {
|
||||
exports.CreateObject = function(n) {
|
||||
return new ActiveXObject(n);
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
return scope;
|
||||
|
|
|
@ -2,18 +2,16 @@
|
|||
// System API
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "System Module (system.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
|
||||
var SHELL = require("lib/shell");
|
||||
var WSH = CreateObject("WScript.Shell");
|
||||
var WMI = GetObject("winmgmts:\\\\.\\root\\CIMV2");
|
||||
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 {
|
||||
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
||||
return true;
|
||||
|
@ -22,7 +20,7 @@ scope.isElevated = function() {
|
|||
}
|
||||
};
|
||||
|
||||
scope.getOS = function() {
|
||||
exports.getOS = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
|
@ -31,7 +29,7 @@ scope.getOS = function() {
|
|||
} catch (e) {}
|
||||
};
|
||||
|
||||
scope.getDCName = function() {
|
||||
exports.getDCName = function() {
|
||||
try {
|
||||
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
|
||||
if (DC.length > 0)
|
||||
|
@ -39,7 +37,7 @@ scope.getDCName = function() {
|
|||
} catch (e) {}
|
||||
};
|
||||
|
||||
scope.getArch = function() {
|
||||
exports.getArch = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
|
@ -48,7 +46,7 @@ scope.getArch = function() {
|
|||
} catch (e) {}
|
||||
};
|
||||
|
||||
scope.getUUID = function() {
|
||||
exports.getUUID = function() {
|
||||
try {
|
||||
var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct");
|
||||
var enumItems = new Enumerator(colItems);
|
||||
|
@ -57,7 +55,7 @@ scope.getUUID = function() {
|
|||
} catch (e) {}
|
||||
};
|
||||
|
||||
scope.getCurrentWorkingDirectory = function() {
|
||||
exports.getCurrentWorkingDirectory = function() {
|
||||
try {
|
||||
cwd = SHELL.exec("cd", "cwd.txt").rtrim();
|
||||
return cwd;
|
||||
|
@ -65,13 +63,13 @@ scope.getCurrentWorkingDirectory = function() {
|
|||
};
|
||||
|
||||
// "console only";
|
||||
scope.getCurrentScriptDirectory = function() {
|
||||
exports.getCurrentScriptDirectory = function() {
|
||||
var path = WScript.ScriptFullName;
|
||||
var pos = path.lastIndexOf("\\");
|
||||
return path.substring(0, pos);
|
||||
};
|
||||
|
||||
scope.getNetworkInterfaces = function() {
|
||||
exports.getNetworkInterfaces = function() {
|
||||
var wbemFlagReturnImmediately = 0x10;
|
||||
var wbemFlagForwardOnly = 0x20;
|
||||
var rows = [];
|
||||
|
@ -99,7 +97,7 @@ scope.getNetworkInterfaces = function() {
|
|||
return rows;
|
||||
};
|
||||
|
||||
scope.getCurrentProcesses = function() {
|
||||
exports.getCurrentProcesses = function() {
|
||||
var processes = [];
|
||||
var response = SHELL.exec("tasklist.exe");
|
||||
|
||||
|
@ -113,8 +111,8 @@ scope.getCurrentProcesses = function() {
|
|||
return processes;
|
||||
};
|
||||
|
||||
scope.createShortcut = function(shoutcutName, fileName) {
|
||||
var workingDirectory = scope.getCurrentWorkingDirectory();
|
||||
exports.createShortcut = function(shoutcutName, fileName) {
|
||||
var workingDirectory = exports.getCurrentWorkingDirectory();
|
||||
var desktopPath = WSH.SpecialFolders("Desktop");
|
||||
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
|
||||
link.IconLocation = fileName + ",1";
|
||||
|
@ -123,5 +121,3 @@ scope.createShortcut = function(shoutcutName, fileName) {
|
|||
link.WorkingDirectory = workingDirectory;
|
||||
link.Save();
|
||||
};
|
||||
|
||||
return scope;
|
||||
|
|
38
lib/timer.js
38
lib/timer.js
|
@ -16,32 +16,30 @@
|
|||
functions in the queue, call the run method again.
|
||||
*/
|
||||
|
||||
var scope = {
|
||||
VERSIONINFO: "Timer Module (timer.js) version 0.1",
|
||||
global: global,
|
||||
require: global.require
|
||||
};
|
||||
exports.VERSIONINFO = "Timer Module (timer.js) version 0.1";
|
||||
exports.global = global;
|
||||
exports.require = global.require;
|
||||
|
||||
scope.sleep = function(ms, callback) {
|
||||
exports.sleep = function(ms, callback) {
|
||||
WScript.Sleep(ms);
|
||||
if(typeof(callback) == "function") {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
scope.setTimeout = function(func, delay) {
|
||||
exports.setTimeout = function(func, 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) {
|
||||
scope.setTimeout.queue.del(timer);
|
||||
exports.clearTimeout = function(timer) {
|
||||
exports.setTimeout.queue.del(timer);
|
||||
};
|
||||
|
||||
// A queue object, with methods add, del, run.
|
||||
// Tied to setTimeout to keep it out of the global namespace.
|
||||
|
||||
scope.setTimeout.queue = (function() {
|
||||
exports.setTimeout.queue = (function() {
|
||||
var store = [];
|
||||
var nextid = 0;
|
||||
|
||||
|
@ -70,7 +68,7 @@ scope.setTimeout.queue = (function() {
|
|||
var item = store[i];
|
||||
|
||||
if (now > item.when) {
|
||||
scope.setTimeout.queue.del(item.id);
|
||||
exports.setTimeout.queue.del(item.id);
|
||||
item.func(); // <---- actually invoke the function 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.
|
||||
// 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');
|
||||
|
||||
scope.setTimeout(console.log('A'), 500);
|
||||
exports.setTimeout(console.log('A'), 500);
|
||||
var b = setTimeout(console.log('B'), 1220);
|
||||
scope.setTimeout(console.log('C'), 300);
|
||||
scope.setTimeout(console.log('D'), 1000);
|
||||
exports.setTimeout(console.log('C'), 300);
|
||||
exports.setTimeout(console.log('D'), 1000);
|
||||
clearTimeout(b);
|
||||
|
||||
scope.setTimeout(function() {
|
||||
exports.setTimeout(function() {
|
||||
console.log('N');
|
||||
scope.setTimeout(function() {
|
||||
exports.setTimeout(function() {
|
||||
console.log('M');
|
||||
}, 100)
|
||||
}, 1300);
|
||||
|
||||
scope.setTimeout.queue.run();
|
||||
exports.setTimeout.queue.run();
|
||||
console.log('done');
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user