mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-02-06 15:04:58 +00:00
add system.js and relatives
This commit is contained in:
parent
ca1d5c4ec9
commit
e776d22dd8
6
app.js
6
app.js
|
@ -52,7 +52,7 @@ var console = {
|
||||||
},
|
},
|
||||||
error: function(msg, status) {
|
error: function(msg, status) {
|
||||||
this.log(msg);
|
this.log(msg);
|
||||||
if(typeof(WScript) !== 'undefined') {
|
if (typeof(WScript) !== 'undefined') {
|
||||||
WScript.quit(status);
|
WScript.quit(status);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -64,8 +64,8 @@ var console = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function CreateObject(n) {
|
function CreateObject(name) {
|
||||||
return new ActiveXObject(n);
|
return new ActiveXObject(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function require(FN) {
|
function require(FN) {
|
||||||
|
|
71
lib/base64.js
Normal file
71
lib/base64.js
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Base64 API
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var scope = {
|
||||||
|
VERSIONINFO: "Base64 Module (base64.js) version 0.1",
|
||||||
|
global: global,
|
||||||
|
require: global.require
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.createMSXMLObject = function() {
|
||||||
|
var progIDs = [
|
||||||
|
"Msxml2.DOMDocument.6.0",
|
||||||
|
"Msxml2.DOMDocument.5.0",
|
||||||
|
"Msxml2.DOMDocument.4.0",
|
||||||
|
"Msxml2.DOMDocument.3.0",
|
||||||
|
"MSXML2.DOMDocument",
|
||||||
|
"MSXML.DOMDocument"
|
||||||
|
];
|
||||||
|
for (var i = 0; i < progIDs.length; i++) {
|
||||||
|
try {
|
||||||
|
return new ActiveXObject(progIDs[i]);
|
||||||
|
} catch(e) {};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getStream_StringToBinary = function(dText) {
|
||||||
|
var adTypeText = 2;
|
||||||
|
var adTypeBinary = 1;
|
||||||
|
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
||||||
|
BinaryStream.Type = adTypeText;
|
||||||
|
BinaryStream.CharSet = "utf-8";
|
||||||
|
BinaryStream.Open();
|
||||||
|
BinaryStream.WriteText(dText);
|
||||||
|
BinaryStream.Position = 0;
|
||||||
|
BinaryStream.Type = adTypeBinary;
|
||||||
|
BinaryStream.Position = 0;
|
||||||
|
return BinaryStream.Read();
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getStream_BinaryToString = function(dBinary) {
|
||||||
|
var adTypeText = 2;
|
||||||
|
var adTypeBinary = 1;
|
||||||
|
var BinaryStream = new ActiveXObject("ADODB.Stream");
|
||||||
|
BinaryStream.Type = adTypeBinary;
|
||||||
|
BinaryStream.Open();
|
||||||
|
BinaryStream.Write(dBinary);
|
||||||
|
BinaryStream.Position = 0;
|
||||||
|
BinaryStream.Type = adTypeText;
|
||||||
|
BinaryStream.CharSet = "utf-8";
|
||||||
|
return BinaryStream.ReadText();
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.encode = function(sText) {
|
||||||
|
var oXML = scope.createMSXMLObject();
|
||||||
|
var oNode = oXML.createElement("base64");
|
||||||
|
oNode.dataType = "bin.base64";
|
||||||
|
oNode.nodeTypedValue = scope.getStream_StringToBinary(sText);
|
||||||
|
return oNode.text;
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.decode = function(vCode) {
|
||||||
|
var oXML = scope.createMSXMLObject();
|
||||||
|
var oNode = oXML.createElement("base64");
|
||||||
|
oNode.dataType = "bin.base64";
|
||||||
|
oNode.text = vCode;
|
||||||
|
return scope.getStream_BinaryToString(oNode.nodeTypedValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
return scope;
|
|
@ -10,7 +10,7 @@ var scope = {
|
||||||
};
|
};
|
||||||
|
|
||||||
scope.exec = function(cmd, stdOutPath) {
|
scope.exec = function(cmd, stdOutPath) {
|
||||||
var WSS = CreateObject("WScript.Shell"),
|
var WSH = CreateObject("WScript.Shell"),
|
||||||
data;
|
data;
|
||||||
|
|
||||||
if (typeof(stdOutPath) == "undefined") {
|
if (typeof(stdOutPath) == "undefined") {
|
||||||
|
@ -18,7 +18,7 @@ scope.exec = function(cmd, stdOutPath) {
|
||||||
}
|
}
|
||||||
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
|
var c = "%comspec% /c (" + cmd + ") 1> " + stdOutPath;
|
||||||
c += " 2>&1";
|
c += " 2>&1";
|
||||||
WSS.Run(c, 0, true);
|
WSH.Run(c, 0, true);
|
||||||
data = FILE.readFile(stdOutPath, "utf-8");
|
data = FILE.readFile(stdOutPath, "utf-8");
|
||||||
|
|
||||||
if (FILE.fileExists(stdOutPath)) {
|
if (FILE.fileExists(stdOutPath)) {
|
||||||
|
@ -29,10 +29,10 @@ scope.exec = function(cmd, stdOutPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.run = function(cmd, fork) {
|
scope.run = function(cmd, fork) {
|
||||||
var WSS = 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;
|
||||||
WSS.Run(cmd, 0, !fork);
|
WSH.Run(cmd, 0, !fork);
|
||||||
};
|
};
|
||||||
|
|
||||||
return scope;
|
return scope;
|
102
lib/system.js
Normal file
102
lib/system.js
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 = new ActiveXObject("Scripting.FileSystemObject");
|
||||||
|
|
||||||
|
scope.isElevated = function() {
|
||||||
|
try {
|
||||||
|
WSH.RegRead("HKEY_USERS\\s-1-5-19\\");
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getOS = function() {
|
||||||
|
try {
|
||||||
|
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||||
|
var enumItems = new Enumerator(colItems);
|
||||||
|
var objItem = enumItems.item();
|
||||||
|
return objItem.Caption.rtrim();
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getDCName = function() {
|
||||||
|
try {
|
||||||
|
var DC = WSH.RegRead("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Group Policy\\History\\DCName");
|
||||||
|
if (DC.length > 0)
|
||||||
|
return DC;
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getArch = function() {
|
||||||
|
try {
|
||||||
|
var colItems = WMI.ExecQuery("SELECT * FROM Win32_OperatingSystem");
|
||||||
|
var enumItems = new Enumerator(colItems);
|
||||||
|
var objItem = enumItems.item();
|
||||||
|
return objItem.OSArchitecture;
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getUUID = function() {
|
||||||
|
try {
|
||||||
|
var colItems = WMI.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct");
|
||||||
|
var enumItems = new Enumerator(colItems);
|
||||||
|
var objItem = enumItems.item();
|
||||||
|
return objItem.UUID.toLowerCase();
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getCurrentWorkingDirectory = function() {
|
||||||
|
try {
|
||||||
|
cwd = SHELL.exec("cd", "cwd.txt").rtrim();
|
||||||
|
return cwd;
|
||||||
|
} catch (e) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
// "console only";
|
||||||
|
scope.getCurrentScriptDirectory = function() {
|
||||||
|
var path = WScript.ScriptFullName;
|
||||||
|
var pos = path.lastIndexOf("\\");
|
||||||
|
return path.substring(0, pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
scope.getNetworkInterfaces = function() {
|
||||||
|
var wbemFlagReturnImmediately = 0x10;
|
||||||
|
var wbemFlagForwardOnly = 0x20;
|
||||||
|
var rows = [];
|
||||||
|
|
||||||
|
try {
|
||||||
|
var colItems = WMI.ExecQuery(
|
||||||
|
"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",
|
||||||
|
"WQL",
|
||||||
|
wbemFlagReturnImmediately | wbemFlagForwardOnly
|
||||||
|
);
|
||||||
|
|
||||||
|
var enumItems = new Enumerator(colItems);
|
||||||
|
for (; !enumItems.atEnd(); enumItems.moveNext()) {
|
||||||
|
var objItem = enumItems.item();
|
||||||
|
try {
|
||||||
|
rows.push({
|
||||||
|
Caption: objItem.Caption,
|
||||||
|
IPAddresses: objItem.IPAddress.toArray(),
|
||||||
|
MACAddress: objItem.MACAddress
|
||||||
|
});
|
||||||
|
} catch(e) {}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
};
|
||||||
|
|
||||||
|
return scope;
|
Loading…
Reference in New Issue
Block a user