mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-22 13:21:31 +03:00
Make MeshAgent and MeshCore update.
This commit is contained in:
parent
9c2da0696f
commit
a546cf852a
@ -139,6 +139,8 @@
|
||||
<Content Include="agents\MeshAgentOSXPackager.zip" />
|
||||
<Content Include="agents\meshagent_arm" />
|
||||
<Content Include="agents\meshagent_arm-linaro" />
|
||||
<Content Include="agents\meshagent_arm64" />
|
||||
<Content Include="agents\meshagent_armhf" />
|
||||
<Content Include="agents\meshagent_osx-x86-64" />
|
||||
<Content Include="agents\meshagent_pogo" />
|
||||
<Content Include="agents\meshagent_poky" />
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -155,7 +155,7 @@ function run(argv) {
|
||||
console.log(' AmtVersions - Show all Intel ME version information.');
|
||||
console.log(' AmtHashes - Show all Intel AMT trusted activation hashes.');
|
||||
console.log(' AmtCCM - Activate Intel AMT into Client Control Mode.');
|
||||
//console.log(' AmtACM - Activate Intel AMT into Admin Control Mode.'); // Not correcly implemented so not making this visible yet.
|
||||
console.log(' AmtACM - Activate Intel AMT into Admin Control Mode.');
|
||||
console.log(' AmtDeactivate - Deactivate Intel AMT if activated in Client Control mode.');
|
||||
console.log(' AmtAcmDeactivate - Deactivate Intel AMT if activated in Admin Control mode.');
|
||||
console.log('\r\nValid local or remote actions:');
|
||||
@ -449,7 +449,7 @@ function run(argv) {
|
||||
amtMei.getLanInterfaceSettings(0, function (result) { console.log('getLanInterfaceSettings0: ' + JSON.stringify(result)); });
|
||||
amtMei.getLanInterfaceSettings(1, function (result) { console.log('getLanInterfaceSettings1: ' + JSON.stringify(result)); });
|
||||
amtMei.getUuid(function (result) { console.log('getUuid: ' + JSON.stringify(result)); });
|
||||
amtMei.getDnsSuffix(function (result) { console.log('getDnsSuffix: ' + JSON.stringify(result)); exit(1);});
|
||||
amtMei.getDnsSuffix(function (result) { console.log('getDnsSuffix: ' + JSON.stringify(result)); exit(1); });
|
||||
} else if (settings.action == 'amtsavestate') {
|
||||
// Save the entire state of Intel AMT info a JSON file
|
||||
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
|
||||
@ -519,6 +519,8 @@ function run(argv) {
|
||||
deactivateACM();
|
||||
} else if (settings.action == 'meshcommander') { // Start MeshCommander
|
||||
startMeshCommander();
|
||||
//} else if (settings.action == 'amtdisable') { // Disable AMT Network Interface
|
||||
// amtDisable();
|
||||
} else if (settings.action == 'amtauditlog') { // Read the Intel AMT audit log
|
||||
if (settings.hostname != null) {
|
||||
if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; }
|
||||
@ -657,6 +659,21 @@ function readAmtAuditLogEx2(stack, response, status) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Disable AMT Network
|
||||
//
|
||||
|
||||
//function amtDisable() {
|
||||
// settings.noconsole = true;
|
||||
// startLms(amtDisableEx);
|
||||
//}
|
||||
|
||||
//function amtDisableEx(stack, response, status) {
|
||||
// //console.log(osamtstack);
|
||||
// osamtstack.Get('AMT_EthernetPortSettings', function (stack, name, response, status) {
|
||||
// console.log(response.Body);
|
||||
// });
|
||||
//}
|
||||
|
||||
//
|
||||
// MeshCommander local web server
|
||||
@ -831,11 +848,11 @@ function deactivateACMEx() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Activate Intel AMT to ACM
|
||||
//
|
||||
|
||||
|
||||
function activeToACM() {
|
||||
// See if MicroLMS needs to be started and setup the $$OsAdmin wsman stack
|
||||
console.log('Starting AMT Provisioning to Admin Control Mode.');
|
||||
@ -855,12 +872,30 @@ function activeToACM() {
|
||||
|
||||
// Gets the FWNonce from AMT and saves it to a file.
|
||||
function getFwNonce() {
|
||||
osamtstack.Get("IPS_HostBasedSetupService", function (obj, name, responses, status) {
|
||||
var fwNonce = Buffer.from(responses["Body"]['ConfigurationNonce'], 'base64');
|
||||
var amtMeiModule, amtMei;
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], function (stack, name, responses, status) {
|
||||
var fwNonce = responses['IPS_HostBasedSetupService'].response['ConfigurationNonce'];
|
||||
var digestRealm = responses['AMT_GeneralSettings'].response['DigestRealm'];
|
||||
var amtMeiModule, amtMei, str;
|
||||
try { amtMeiModule = require('amt-mei'); amtMei = new amtMeiModule(); } catch (ex) { console.log(ex); exit(1); return; }
|
||||
amtMei.getLanInterfaceSettings(0, function (result) { if (result) { mestate.net0 = result; } });
|
||||
amtMei.getDnsSuffix(function (result) {
|
||||
activeToACMEx(fwNonce, result);
|
||||
var fqdn = null;
|
||||
if ((mestate.net0 == null) && (meinfo.net0.enabled != 0)) { console.log("No Intel AMT wired interface, can't perform ACM activation."); exit(100); return; }
|
||||
if (result) { fqdn = result; } // If Intel AMT has a trusted DNS suffix set, use that one.
|
||||
else {
|
||||
// Look for the DNS suffix for the Intel AMT Ethernet interface
|
||||
var interfaces = require('os').networkInterfaces();
|
||||
for (var i in interfaces) {
|
||||
for (var j in interfaces[i]) {
|
||||
if ((interfaces[i][j].mac == mestate.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { fqdn = interfaces[i][j].fqdn; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fqdn != null) {
|
||||
activeToACMEx(fwNonce, fqdn, digestRealm);
|
||||
} else {
|
||||
console.log("Trusted DNS suffix not set, can't perform ACM activation."); exit(100); return;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -868,10 +903,10 @@ function getFwNonce() {
|
||||
// Sends a message to RCS server using RCS Message Protocol
|
||||
function sendRCSMessage(socket, status, event, message) {
|
||||
//console.log('Status: ' + status + '. Event: ' + event + '. Message: ' + message);
|
||||
if (socket !== null) { socket.write({"status": status, "event": event, "data": message}); }
|
||||
if (socket !== null) { socket.write({ "status": status, "event": event, "data": message }); }
|
||||
}
|
||||
|
||||
function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
function activeToACMEx(fwNonce, dnsSuffix, digestRealm) {
|
||||
// open connection to RCS
|
||||
console.log('Initializing WebSocket...');
|
||||
// Establish WebSocket connection to RCS server
|
||||
@ -890,8 +925,7 @@ function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
if (status == 2) {
|
||||
console.log('AMT already provisioned.Exiting ' + status);
|
||||
sendRCSMessage(socket, "error", "finish", "failed with status: " + status);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log('Failed to fetch activation status, status ' + status);
|
||||
sendRCSMessage(socket, "error", "finish", "failed with status: " + status);
|
||||
}
|
||||
@ -903,7 +937,7 @@ function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
socket.end();
|
||||
exit(status);
|
||||
} else {
|
||||
activeToACMEx2(message, responses, function (stack, name, responses, status, message) {
|
||||
activeToACMEx2(message, function (stack, name, responses, status, message) {
|
||||
if (status != 200) {
|
||||
console.log('Failed to activate, status ' + status);
|
||||
sendRCSMessage(socket, "error", "finish", "failed to activate. Status: " + status);
|
||||
@ -911,7 +945,7 @@ function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
console.log('Admin control mode activation failed: ' + responses.Body.ReturnValueStr);
|
||||
sendRCSMessage(socket, "error", "finish", "failed to activate: " + responses.Body.ReturnValueStr);
|
||||
} else {
|
||||
if (message.profileScript !== '') {
|
||||
if (message.profileScript !== null) {
|
||||
console.log("Running MEScript...");
|
||||
settings.scriptjson = message.profileScript;
|
||||
settings.password = message.amtPassword
|
||||
@ -928,7 +962,6 @@ function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
exit(0);
|
||||
}
|
||||
console.log('AMT Provisioning Success');
|
||||
|
||||
}
|
||||
//socket.end();
|
||||
//exit(status);
|
||||
@ -940,10 +973,8 @@ function activeToACMEx(fwNonce, dnsSuffix) {
|
||||
sendRCSMessage(socket, "ok", "message", JSON.stringify(fwNonce));
|
||||
}
|
||||
});
|
||||
socket.on('end', function () {
|
||||
console.log('WebSocket closed');
|
||||
});
|
||||
sendRCSMessage(socket, "ok", "cmd", { "cmd": "acm", "dnssuffix": dnsSuffix, "profile": settings.profile });
|
||||
socket.on('end', function () { console.log('WebSocket closed'); });
|
||||
sendRCSMessage(socket, "ok", "cmd", { "cmd": "acm", "dnssuffix": dnsSuffix, "profile": settings.profile, 'digestrealm': digestRealm, 'fwnonce': fwNonce });
|
||||
});
|
||||
}
|
||||
|
||||
@ -980,8 +1011,8 @@ function injectCert(index, cert, callback, stack, name, responses, status) {
|
||||
var root = false;
|
||||
if (index == 0) { leaf = true; }
|
||||
if (index == cert.provCertObj.certChain.length - 1) { root = true; }
|
||||
if (index < cert.provCertObj.certChain.length){
|
||||
if (cert.provCertObj.certChain[index] !== undefined){
|
||||
if (index < cert.provCertObj.certChain.length) {
|
||||
if (cert.provCertObj.certChain[index] !== undefined) {
|
||||
osamtstack.IPS_HostBasedSetupService_AddNextCertInChain(cert.provCertObj.certChain[index], leaf, root, function (stack, name, responses, status) {
|
||||
if (status !== 200) { exit(status); return; }
|
||||
else if (responses['Body']['ReturnValue'] !== 0) { exit(responses['Body']['ReturnValueStr']); return; }
|
||||
@ -995,11 +1026,11 @@ function injectCert(index, cert, callback, stack, name, responses, status) {
|
||||
}
|
||||
|
||||
// Sends the password hash, mcnonce, and digital signature to complete the admin control mode provisioning
|
||||
function activeToACMEx2(data, responses, callback) {
|
||||
var passwordhash = md5hex('admin:' + responses['AMT_GeneralSettings'].response['DigestRealm'] + ':' + data.amtPassword).substring(0, 32);
|
||||
function activeToACMEx2(data, callback) {
|
||||
//var passwordhash = md5hex('admin:' + responses['AMT_GeneralSettings'].response['DigestRealm'] + ':' + data.passwordHash).substring(0, 32);
|
||||
//var debugreturn = {"Body": {"ReturnValue": 0}};
|
||||
//console.log("DEBUG: Everything up to activation works"); callback(null, null, debugreturn, 200, data);
|
||||
osamtstack.IPS_HostBasedSetupService_AdminSetup(2, passwordhash, data.mcNonce, 2, data.digitalSignature, function (stack, name, responses, status) { callback(stack, name, responses, status, data); });
|
||||
osamtstack.IPS_HostBasedSetupService_AdminSetup(2, data.passwordHash, data.mcNonce, 2, data.digitalSignature, function (stack, name, responses, status) { callback(stack, name, responses, status, data); });
|
||||
}
|
||||
|
||||
//
|
||||
@ -1075,8 +1106,7 @@ function startMeScriptEx(callback, amtstack) {
|
||||
//
|
||||
|
||||
|
||||
function saveEntireAmtState2()
|
||||
{
|
||||
function saveEntireAmtState2() {
|
||||
console.log('Fetching all Intel AMT state, this may take a few minutes...');
|
||||
var transport = require('amt-wsman-duk');
|
||||
var wsman = require('amt-wsman');
|
||||
@ -1096,16 +1126,13 @@ function saveEntireAmtState2()
|
||||
}
|
||||
|
||||
// Save the entire Intel AMT state
|
||||
function saveEntireAmtState()
|
||||
{
|
||||
function saveEntireAmtState() {
|
||||
// See if MicroLMS needs to be started
|
||||
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost'))
|
||||
{
|
||||
if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) {
|
||||
settings.noconsole = true;
|
||||
startLms().then(saveEntireAmtState2);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
saveEntireAmtState2();
|
||||
}
|
||||
}
|
||||
@ -1196,8 +1223,7 @@ var lmsNotifications = [];
|
||||
var amtLms = null;
|
||||
var promise = require('promise');
|
||||
|
||||
function startLms(func, lmscommander)
|
||||
{
|
||||
function startLms(func, lmscommander) {
|
||||
var ret = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
var lme_heci = null
|
||||
try { lme_heci = require('amt-lme'); } catch (ex) { }
|
||||
@ -1893,7 +1919,7 @@ function performIder() {
|
||||
var sfloppy = null, scdrom = null;
|
||||
if (settings.floppy) { try { if (sfloppy = fs.statSync(settings.floppy)) { sfloppy.file = fs.openSync(settings.floppy, 'rbN'); } } catch (ex) { console.log(ex); process.exit(1); return; } }
|
||||
if (settings.cdrom) { try { scdrom = fs.statSync(settings.cdrom); if (scdrom) { scdrom.file = fs.openSync(settings.cdrom, 'rbN'); } } catch (ex) { console.log(ex); process.exit(1); return; } }
|
||||
|
||||
|
||||
ider = require('amt-redir-duk')(require('amt-ider')());
|
||||
ider.onStateChanged = onIderStateChange;
|
||||
ider.m.floppy = sfloppy;
|
||||
@ -1903,11 +1929,11 @@ function performIder() {
|
||||
if (settings.timeout > 0) { ider.m.sectorStats = iderSectorStats; }
|
||||
//ider.digestRealmMatch = wsstack.comm.digestRealm;
|
||||
//ider.tlsv1only = amtstack.wsman.comm.tlsv1only;
|
||||
ider.Start(settings.hostname, (settings.tls == true)?16995:16994, settings.username ? 'admin' : settings.username, settings.password, settings.tls);
|
||||
ider.Start(settings.hostname, (settings.tls == true) ? 16995 : 16994, settings.username ? 'admin' : settings.username, settings.password, settings.tls);
|
||||
} catch (ex) { console.log(ex); }
|
||||
}
|
||||
|
||||
function onIderStateChange(stack, state) { console.log(['Disconnected', 'Connecting...', 'Connected...', 'Started IDER...'][state]);}
|
||||
function onIderStateChange(stack, state) { console.log(['Disconnected', 'Connecting...', 'Connected...', 'Started IDER...'][state]); }
|
||||
|
||||
function iderSectorStats(mode, dev, mediaBlocks, lba, len) {
|
||||
if (iderIdleTimer != null) { clearTimeout(iderIdleTimer); }
|
||||
|
1979
agents/meshcmd.min.js
vendored
1979
agents/meshcmd.min.js
vendored
File diff suppressed because one or more lines are too long
1950
agents/meshcore-old.js
Normal file
1950
agents/meshcore-old.js
Normal file
File diff suppressed because it is too large
Load Diff
@ -22,6 +22,7 @@ process.on('uncaughtException', function (ex) {
|
||||
//attachDebugger({ webport: 9999, wait: 1 }).then(function (prt) { console.log('Point Browser for Debug to port: ' + prt); });
|
||||
|
||||
// Mesh Rights
|
||||
var MNG_ERROR = 65;
|
||||
var MESHRIGHT_EDITMESH = 1;
|
||||
var MESHRIGHT_MANAGEUSERS = 2;
|
||||
var MESHRIGHT_MANAGECOMPUTERS = 4;
|
||||
@ -36,10 +37,12 @@ var MESHRIGHT_NOFILES = 1024;
|
||||
var MESHRIGHT_NOAMT = 2048;
|
||||
var MESHRIGHT_LIMITEDINPUT = 4096;
|
||||
|
||||
function createMeshCore(agent) {
|
||||
function createMeshCore(agent)
|
||||
{
|
||||
var obj = {};
|
||||
|
||||
if (process.platform == 'darwin' && !process.versions) {
|
||||
if (process.platform == 'darwin' && !process.versions)
|
||||
{
|
||||
// This is an older MacOS Agent, so we'll need to check the service definition so that Auto-Update will function correctly
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
@ -48,18 +51,21 @@ function createMeshCore(agent) {
|
||||
child.stdin.write(" if(c[1]==\"dict\"){ split(a[2], d, \"</dict>\"); if(split(d[1], truval, \"<true/>\")>1) { split(truval[1], kn1, \"<key>\"); split(kn1[2], kn2, \"</key>\"); print kn2[1]; } }");
|
||||
child.stdin.write(" else { split(c[1], ka, \"/\"); if(ka[1]==\"true\") {print \"ALWAYS\";} } }'\nexit\n");
|
||||
child.waitExit();
|
||||
if (child.stdout.str.trim() == 'Crashed') {
|
||||
if (child.stdout.str.trim() == 'Crashed')
|
||||
{
|
||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdin.write("launchctl list | grep 'meshagent' | awk '{ if($3==\"meshagent\"){print $1;}}'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
if (parseInt(child.stdout.str.trim()) == process.pid) {
|
||||
if (parseInt(child.stdout.str.trim()) == process.pid)
|
||||
{
|
||||
// The currently running MeshAgent is us, so we can continue with the update
|
||||
var plist = require('fs').readFileSync('/Library/LaunchDaemons/meshagent_osx64_LaunchDaemon.plist').toString();
|
||||
var tokens = plist.split('<key>KeepAlive</key>');
|
||||
if (tokens[1].split('>')[0].split('<')[1] == 'dict') {
|
||||
if (tokens[1].split('>')[0].split('<')[1] == 'dict')
|
||||
{
|
||||
var tmp = tokens[1].split('</dict>');
|
||||
tmp.shift();
|
||||
tokens[1] = '\n <true/>' + tmp.join('</dict>');
|
||||
@ -114,6 +120,133 @@ function createMeshCore(agent) {
|
||||
}
|
||||
}
|
||||
|
||||
// Create Secure IPC for Diagnostic Agent Communications
|
||||
obj.DAIPC = require('net').createServer();
|
||||
if (process.platform != 'win32') { try { require('fs').unlinkSync(process.cwd() + '/DAIPC'); } catch (ee) { } }
|
||||
obj.DAIPC.IPCPATH = process.platform == 'win32' ? ('\\\\.\\pipe\\' + require('_agentNodeId')() + '-DAIPC') : (process.cwd() + '/DAIPC');
|
||||
try { obj.DAIPC.listen({ path: obj.DAIPC.IPCPATH }); } catch (e) { }
|
||||
obj.DAIPC.on('connection', function (c)
|
||||
{
|
||||
c._send = function (j)
|
||||
{
|
||||
var data = JSON.stringify(j);
|
||||
var packet = Buffer.alloc(data.length + 4);
|
||||
packet.writeUInt32LE(data.length + 4, 0);
|
||||
Buffer.from(data).copy(packet, 4);
|
||||
this.end(packet);
|
||||
};
|
||||
this._daipc = c;
|
||||
c.parent = this;
|
||||
c.on('end', function () { console.log('Connection Closed'); this.parent._daipc = null; });
|
||||
c.on('data', function (chunk)
|
||||
{
|
||||
if (chunk.length < 4) { this.unshift(chunk); return; }
|
||||
var len = chunk.readUInt32LE(0);
|
||||
if (len > 8192) { this.parent._daipc = null; this.end(); return; }
|
||||
if (chunk.length < len) { this.unshift(chunk); return; }
|
||||
|
||||
var data = chunk.slice(4, len);
|
||||
try
|
||||
{
|
||||
data = JSON.parse(data.toString());
|
||||
}
|
||||
catch(de)
|
||||
{
|
||||
this.parent._daipc = null; this.end(); return;
|
||||
}
|
||||
|
||||
if (!data.cmd) { this.parent._daipc = null; this.end(); return; }
|
||||
|
||||
try
|
||||
{
|
||||
switch(data.cmd)
|
||||
{
|
||||
case 'query':
|
||||
switch(data.value)
|
||||
{
|
||||
case 'connection':
|
||||
data.result = require('MeshAgent').ConnectedServer;
|
||||
this._send(data);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.parent._daipc = null; this.end(); return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(xe)
|
||||
{
|
||||
this.parent._daipc = null; this.end(); return;
|
||||
}
|
||||
});
|
||||
});
|
||||
function diagnosticAgent_uninstall()
|
||||
{
|
||||
require('service-manager').manager.uninstallService('meshagentDiagnostic');
|
||||
require('task-scheduler').delete('meshagentDiagnostic/periodicStart');
|
||||
};
|
||||
function diagnosticAgent_installCheck(install)
|
||||
{
|
||||
try
|
||||
{
|
||||
var diag = require('service-manager').manager.getService('meshagentDiagnostic');
|
||||
return (diag);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
}
|
||||
if (!install) { return (null); }
|
||||
|
||||
var svc = null;
|
||||
try
|
||||
{
|
||||
require('service-manager').manager.installService(
|
||||
{
|
||||
name: 'meshagentDiagnostic',
|
||||
displayName: 'Mesh Agent Diagnostic Service',
|
||||
description: 'Mesh Agent Diagnostic Service',
|
||||
servicePath: process.execPath,
|
||||
parameters: ['-recovery']
|
||||
//files: [{ newName: 'diagnostic.js', _buffer: Buffer.from('LyoNCkNvcHlyaWdodCAyMDE5IEludGVsIENvcnBvcmF0aW9uDQoNCkxpY2Vuc2VkIHVuZGVyIHRoZSBBcGFjaGUgTGljZW5zZSwgVmVyc2lvbiAyLjAgKHRoZSAiTGljZW5zZSIpOw0KeW91IG1heSBub3QgdXNlIHRoaXMgZmlsZSBleGNlcHQgaW4gY29tcGxpYW5jZSB3aXRoIHRoZSBMaWNlbnNlLg0KWW91IG1heSBvYnRhaW4gYSBjb3B5IG9mIHRoZSBMaWNlbnNlIGF0DQoNCiAgICBodHRwOi8vd3d3LmFwYWNoZS5vcmcvbGljZW5zZXMvTElDRU5TRS0yLjANCg0KVW5sZXNzIHJlcXVpcmVkIGJ5IGFwcGxpY2FibGUgbGF3IG9yIGFncmVlZCB0byBpbiB3cml0aW5nLCBzb2Z0d2FyZQ0KZGlzdHJpYnV0ZWQgdW5kZXIgdGhlIExpY2Vuc2UgaXMgZGlzdHJpYnV0ZWQgb24gYW4gIkFTIElTIiBCQVNJUywNCldJVEhPVVQgV0FSUkFOVElFUyBPUiBDT05ESVRJT05TIE9GIEFOWSBLSU5ELCBlaXRoZXIgZXhwcmVzcyBvciBpbXBsaWVkLg0KU2VlIHRoZSBMaWNlbnNlIGZvciB0aGUgc3BlY2lmaWMgbGFuZ3VhZ2UgZ292ZXJuaW5nIHBlcm1pc3Npb25zIGFuZA0KbGltaXRhdGlvbnMgdW5kZXIgdGhlIExpY2Vuc2UuDQoqLw0KDQp2YXIgaG9zdCA9IHJlcXVpcmUoJ3NlcnZpY2UtaG9zdCcpLmNyZWF0ZSgnbWVzaGFnZW50RGlhZ25vc3RpYycpOw0KdmFyIFJlY292ZXJ5QWdlbnQgPSByZXF1aXJlKCdNZXNoQWdlbnQnKTsNCg0KaG9zdC5vbignc2VydmljZVN0YXJ0JywgZnVuY3Rpb24gKCkNCnsNCiAgICBjb25zb2xlLnNldERlc3RpbmF0aW9uKGNvbnNvbGUuRGVzdGluYXRpb25zLkxPR0ZJTEUpOw0KICAgIGhvc3Quc3RvcCA9IGZ1bmN0aW9uKCkNCiAgICB7DQogICAgICAgIHJlcXVpcmUoJ3NlcnZpY2UtbWFuYWdlcicpLm1hbmFnZXIuZ2V0U2VydmljZSgnbWVzaGFnZW50RGlhZ25vc3RpYycpLnN0b3AoKTsNCiAgICB9DQogICAgUmVjb3ZlcnlBZ2VudC5vbignQ29ubmVjdGVkJywgZnVuY3Rpb24gKHN0YXR1cykNCiAgICB7DQogICAgICAgIGlmIChzdGF0dXMgPT0gMCkNCiAgICAgICAgew0KICAgICAgICAgICAgY29uc29sZS5sb2coJ0RpYWdub3N0aWMgQWdlbnQ6IFNlcnZlciBjb25uZWN0aW9uIGxvc3QuLi4nKTsNCiAgICAgICAgICAgIHJldHVybjsNCiAgICAgICAgfQ0KICAgICAgICBjb25zb2xlLmxvZygnRGlhZ25vc3RpYyBBZ2VudDogQ29ubmVjdGlvbiBFc3RhYmxpc2hlZCB3aXRoIFNlcnZlcicpOw0KICAgICAgICBzdGFydCgpOw0KICAgIH0pOw0KfSk7DQpob3N0Lm9uKCdub3JtYWxTdGFydCcsIGZ1bmN0aW9uICgpDQp7DQogICAgaG9zdC5zdG9wID0gZnVuY3Rpb24gKCkNCiAgICB7DQogICAgICAgIHByb2Nlc3MuZXhpdCgpOw0KICAgIH0NCiAgICBjb25zb2xlLmxvZygnTm9uIFNlcnZpY2UgTW9kZScpOw0KICAgIFJlY292ZXJ5QWdlbnQub24oJ0Nvbm5lY3RlZCcsIGZ1bmN0aW9uIChzdGF0dXMpDQogICAgew0KICAgICAgICBpZiAoc3RhdHVzID09IDApDQogICAgICAgIHsNCiAgICAgICAgICAgIGNvbnNvbGUubG9nKCdEaWFnbm9zdGljIEFnZW50OiBTZXJ2ZXIgY29ubmVjdGlvbiBsb3N0Li4uJyk7DQogICAgICAgICAgICByZXR1cm47DQogICAgICAgIH0NCiAgICAgICAgY29uc29sZS5sb2coJ0RpYWdub3N0aWMgQWdlbnQ6IENvbm5lY3Rpb24gRXN0YWJsaXNoZWQgd2l0aCBTZXJ2ZXInKTsNCiAgICAgICAgc3RhcnQoKTsNCiAgICB9KTsNCn0pOw0KaG9zdC5vbignc2VydmljZVN0b3AnLCBmdW5jdGlvbiAoKSB7IHByb2Nlc3MuZXhpdCgpOyB9KTsNCmhvc3QucnVuKCk7DQoNCg0KZnVuY3Rpb24gc3RhcnQoKQ0Kew0KDQp9Ow0K', 'base64') }]
|
||||
});
|
||||
svc = require('service-manager').manager.getService('meshagentDiagnostic');
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
return (null);
|
||||
}
|
||||
var proxyConfig = require('global-tunnel').proxyConfig;
|
||||
var cert = require('MeshAgent').GenerateAgentCertificate('CN=MeshNodeDiagnosticCertificate');
|
||||
var nodeid = require('tls').loadCertificate(cert.root).getKeyHash().toString('base64');
|
||||
ddb = require('SimpleDataStore').Create(svc.appWorkingDirectory().replace('\\', '/') + '/meshagentDiagnostic.db');
|
||||
ddb.Put('disableUpdate', '1');
|
||||
ddb.Put('MeshID', Buffer.from(require('MeshAgent').ServerInfo.MeshID, 'hex'));
|
||||
ddb.Put('ServerID', require('MeshAgent').ServerInfo.ServerID);
|
||||
ddb.Put('MeshServer', require('MeshAgent').ServerInfo.ServerUri);
|
||||
if (cert.root.pfx) { ddb.Put('SelfNodeCert', cert.root.pfx); }
|
||||
if (cert.tls) { ddb.Put('SelfNodeTlsCert', cert.tls.pfx); }
|
||||
if (proxyConfig)
|
||||
{
|
||||
ddb.Put('WebProxy', proxyConfig.host + ':' + proxyConfig.port);
|
||||
}
|
||||
else
|
||||
{
|
||||
ddb.Put('ignoreProxyFile', '1');
|
||||
}
|
||||
|
||||
require('MeshAgent').SendCommand({ action: 'diagnostic', value: { command: 'register', value: nodeid } });
|
||||
require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: 'Diagnostic Agent Registered [' + nodeid.length + '/' + nodeid + ']' });
|
||||
|
||||
delete ddb;
|
||||
|
||||
// Set a recurrent task, to run the Diagnostic Agent every 2 days
|
||||
require('task-scheduler').create({name: 'meshagentDiagnostic/periodicStart', daily: 2, time: require('tls').generateRandomInteger('0', '23') + ':' + require('tls').generateRandomInteger('0', '59').padStart(2, '0'), service: 'meshagentDiagnostic'});
|
||||
//require('task-scheduler').create({ name: 'meshagentDiagnostic/periodicStart', daily: '1', time: '17:16', service: 'meshagentDiagnostic' });
|
||||
|
||||
return (svc);
|
||||
}
|
||||
|
||||
/*
|
||||
function borderController() {
|
||||
this.container = null;
|
||||
@ -191,6 +324,8 @@ function createMeshCore(agent) {
|
||||
mesh = agent.getMeshApi();
|
||||
}
|
||||
|
||||
mesh.DAIPC = obj.DAIPC;
|
||||
|
||||
/*
|
||||
var AMTScanner = require("AMTScanner");
|
||||
var scan = new AMTScanner();
|
||||
@ -815,39 +950,7 @@ function createMeshCore(agent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Test the console messaging system
|
||||
//this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'This is a sample test for remote terminal...' })); // Send a console message back using the console channel, "\n" is supported.
|
||||
|
||||
// Perform notification if needed. Toast messages may not be supported on all platforms.
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 2)) {
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote terminal session.'); } catch (ex) { }
|
||||
}
|
||||
|
||||
// Remote terminal using native pipes
|
||||
if (process.platform == "win32")
|
||||
{
|
||||
this.httprequest._term = require('win-terminal').Start(80, 25);
|
||||
this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
|
||||
this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
|
||||
this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); });
|
||||
//this.httprequest.process = childProcess.execFile("%windir%\\system32\\cmd.exe");
|
||||
} else {
|
||||
if (fs.existsSync("/bin/bash")) {
|
||||
this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM });
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); }
|
||||
} else {
|
||||
this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
|
||||
}
|
||||
//if (this.httprequest.process == null) { }
|
||||
this.httprequest.process.tunnel = this;
|
||||
this.httprequest.process.on('exit', function (ecode, sig) { this.tunnel.end(); });
|
||||
this.httprequest.process.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
|
||||
this.httprequest.process.stdout.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
|
||||
this.pipe(this.httprequest.process.stdin, { dataTypeSkip: 1, end: false }); // 0 = Binary, 1 = Text.
|
||||
this.prependListener('end', function () { this.httprequest.process.kill(); });
|
||||
}
|
||||
|
||||
|
||||
this.end = function () {
|
||||
if (process.platform == "win32") {
|
||||
// Unpipe the web socket
|
||||
@ -868,11 +971,75 @@ function createMeshCore(agent) {
|
||||
}
|
||||
};
|
||||
|
||||
// Remote terminal using native pipes
|
||||
if (process.platform == "win32") {
|
||||
this.httprequest._term = require('win-terminal').Start(80, 25);
|
||||
this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
|
||||
this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
|
||||
this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); });
|
||||
} else {
|
||||
if (fs.existsSync("/bin/bash")) {
|
||||
this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM });
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); }
|
||||
} else {
|
||||
this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
|
||||
if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
|
||||
}
|
||||
this.httprequest.process.tunnel = this;
|
||||
this.httprequest.process.on('exit', function (ecode, sig) { this.tunnel.end(); });
|
||||
this.httprequest.process.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
|
||||
this.httprequest.process.stdout.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
|
||||
this.pipe(this.httprequest.process.stdin, { dataTypeSkip: 1, end: false }); // 0 = Binary, 1 = Text.
|
||||
this.prependListener('end', function () { this.httprequest.process.kill(); });
|
||||
this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nclear\n");
|
||||
}
|
||||
|
||||
// Perform notification if needed. Toast messages may not be supported on all platforms.
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 16)) {
|
||||
// User Consent Prompt is required
|
||||
|
||||
// Send a console message back using the console channel, "\n" is supported.
|
||||
this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
|
||||
|
||||
var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting Terminal Access. Grant access?', 10);
|
||||
pr.ws = this;
|
||||
this.pause();
|
||||
|
||||
pr.then(
|
||||
function () {
|
||||
// Success!
|
||||
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
|
||||
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 2)) {
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote terminal session.'); } catch (ex) { }
|
||||
}
|
||||
|
||||
this.ws.resume();
|
||||
},
|
||||
function (e) {
|
||||
// User Consent Denied/Failed!
|
||||
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
|
||||
this.ws.end();
|
||||
});
|
||||
}
|
||||
else {
|
||||
// User Consent Prompt is not required
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 2)) {
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote terminal session.'); } catch (ex) { }
|
||||
}
|
||||
this.resume();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
this.removeAllListeners('data');
|
||||
this.on('data', onTunnelControlData);
|
||||
//this.write('MeshCore Terminal Hello');
|
||||
} else if (this.httprequest.protocol == 2) {
|
||||
|
||||
} else if (this.httprequest.protocol == 2)
|
||||
{
|
||||
// Check user access rights for desktop
|
||||
if (((this.httprequest.rights & MESHRIGHT_REMOTECONTROL) == 0) && ((this.httprequest.rights & MESHRIGHT_REMOTEVIEW) == 0)) {
|
||||
// Disengage this tunnel, user does not have the rights to do this!!
|
||||
@ -882,13 +1049,6 @@ function createMeshCore(agent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Test the console messaging system
|
||||
//this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'This is a sample test for remote desktop...' })); // Send a console message back using the console channel, "\n" is supported.
|
||||
|
||||
// Perform notification if needed. Toast messages may not be supported on all platforms.
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 1)) {
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
|
||||
}
|
||||
|
||||
// Remote desktop using native pipes
|
||||
this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(), tunnel: this };
|
||||
@ -926,7 +1086,56 @@ function createMeshCore(agent) {
|
||||
// TODO!!!
|
||||
}
|
||||
|
||||
this.httprequest.desktop.kvm.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text. Pipe the KVM --> Browser images.
|
||||
// Perform notification if needed. Toast messages may not be supported on all platforms.
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 8))
|
||||
{
|
||||
// User Consent Prompt is required
|
||||
|
||||
// Send a console message back using the console channel, "\n" is supported.
|
||||
this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
|
||||
|
||||
var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting KVM Access. Grant access?', 10);
|
||||
pr.ws = this;
|
||||
this.pause();
|
||||
|
||||
pr.then(
|
||||
function ()
|
||||
{
|
||||
// Success!
|
||||
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
|
||||
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 1))
|
||||
{
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
|
||||
}
|
||||
|
||||
this.ws.httprequest.desktop.kvm.pipe(this.ws, { dataTypeSkip: 1 });
|
||||
this.ws.resume();
|
||||
},
|
||||
function (e)
|
||||
{
|
||||
// User Consent Denied/Failed!
|
||||
this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
|
||||
|
||||
//var err = 'User consent: ' + e.toString();
|
||||
//var b = Buffer.alloc(5 + err.length);
|
||||
//b.writeUInt16BE(MNG_ERROR, 0);
|
||||
//b.writeUInt16BE(err.length + 4, 2);
|
||||
//Buffer.from(err).copy(b, 4);
|
||||
//this.ws.end(b);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// User Consent Prompt is not required
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 1))
|
||||
{
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote desktop session.'); } catch (ex) { }
|
||||
}
|
||||
this.httprequest.desktop.kvm.pipe(this, { dataTypeSkip: 1 });
|
||||
}
|
||||
|
||||
this.removeAllListeners('data');
|
||||
this.on('data', onTunnelControlData);
|
||||
//this.write('MeshCore KVM Hello!1');
|
||||
@ -938,16 +1147,45 @@ function createMeshCore(agent) {
|
||||
// Disengage this tunnel, user does not have the rights to do this!!
|
||||
this.httprequest.protocol = 999999;
|
||||
this.httprequest.s.end();
|
||||
sendConsoleText('Error: No Files Control Rights.');
|
||||
sendConsoleText('Error: No files control rights.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Test the console messaging system
|
||||
//this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'This is a sample test for remote files...' })); // Send a console message back using the console channel, "\n" is supported.
|
||||
// Perform notification if needed. Toast messages may not be supported on all platforms.
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 32))
|
||||
{
|
||||
// User Consent Prompt is required
|
||||
|
||||
// Perform notification if needed
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 4)) {
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote file access.'); } catch (ex) { }
|
||||
// Send a console message back using the console channel, "\n" is supported.
|
||||
this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: 'Waiting for user to grant access...' }));
|
||||
|
||||
var pr = require('message-box').create('MeshCentral', this.httprequest.username + ' requesting remote file access. Grant access?', 10);
|
||||
pr.ws = this;
|
||||
this.pause();
|
||||
|
||||
pr.then(
|
||||
function () {
|
||||
// Success!
|
||||
this.ws.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: null }));
|
||||
if (this.ws.httprequest.consent && (this.ws.httprequest.consent & 4))
|
||||
{
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.ws.httprequest.username + ' started a remote file session.'); } catch (ex) { }
|
||||
}
|
||||
this.ws.resume();
|
||||
},
|
||||
function (e) {
|
||||
// User Consent Denied/Failed!
|
||||
this.ws.end(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
|
||||
});
|
||||
}
|
||||
else {
|
||||
// User Consent Prompt is not required
|
||||
if (this.httprequest.consent && (this.httprequest.consent & 4)) {
|
||||
// User Notifications is required
|
||||
try { require('toaster').Toast('MeshCentral', this.httprequest.username + ' started a remote file session.'); } catch (ex) { }
|
||||
}
|
||||
this.resume();
|
||||
}
|
||||
|
||||
// Setup files
|
||||
@ -1291,7 +1529,7 @@ function createMeshCore(agent) {
|
||||
var response = null;
|
||||
switch (cmd) {
|
||||
case 'help': { // Displays available commands
|
||||
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtdeactivate,\r\namtpolicy, getscript, getclip, setclip.';
|
||||
response = 'Available commands: help, info, osinfo,args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm, amtdeactivate,\r\namtpolicy, getscript, getclip, setclip.';
|
||||
break;
|
||||
}
|
||||
/*
|
||||
@ -1349,6 +1587,13 @@ function createMeshCore(agent) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'amtacm': {
|
||||
if (amt == null) { response = 'Intel AMT not supported.'; } else {
|
||||
amt.setPolicy({ type: 0 });
|
||||
amt.getAmtInfo(function (meinfo) { amt.activeToACM(meinfo); });
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'amtdeactivate': {
|
||||
if (amt == null) { response = 'Intel AMT not supported.'; } else { amt.setPolicy({ type: 0 }); amt.deactivateCCM(); }
|
||||
break;
|
||||
@ -1372,12 +1617,9 @@ function createMeshCore(agent) {
|
||||
break;
|
||||
}
|
||||
case 'toast': {
|
||||
if (process.platform == 'win32') {
|
||||
if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else {
|
||||
try { require('toaster').Toast('MeshCentral', args['_'][0]); response = 'ok'; } catch (ex) { response = ex; }
|
||||
}
|
||||
} else {
|
||||
response = 'Only supported on Windows.';
|
||||
if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else
|
||||
{
|
||||
require('toaster').Toast('MeshCentral', args['_'][0]).then(sendConsoleText, sendConsoleText);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1669,6 +1911,8 @@ function createMeshCore(agent) {
|
||||
if (state != null) { resp = objToString(state, 0, ' ', true); }
|
||||
sendConsoleText(resp, sessionid);
|
||||
});
|
||||
} else {
|
||||
response = 'Intel AMT not detected.';
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1763,6 +2007,48 @@ function createMeshCore(agent) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'diagnostic':
|
||||
{
|
||||
if (!mesh.DAIPC.listening)
|
||||
{
|
||||
response = 'Unable to bind to Diagnostic IPC, most likely because the path (' + process.cwd() + ') is not on a local file system';
|
||||
break;
|
||||
}
|
||||
var diag = diagnosticAgent_installCheck();
|
||||
if (diag)
|
||||
{
|
||||
if (args['_'].length == 1 && args['_'][0] == 'uninstall')
|
||||
{
|
||||
diagnosticAgent_uninstall();
|
||||
response = 'Diagnostic Agent uninstalled';
|
||||
}
|
||||
else
|
||||
{
|
||||
response = 'Diagnostic Agent installed at: ' + diag.appLocation();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args['_'].length == 1 && args['_'][0] == 'install')
|
||||
{
|
||||
diag = diagnosticAgent_installCheck(true);
|
||||
if (diag)
|
||||
{
|
||||
response = 'Diagnostic agent was installed at: ' + diag.appLocation();
|
||||
}
|
||||
else
|
||||
{
|
||||
response = 'Diagnostic agent installation failed';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
response = 'Diagnostic Agent Not installed. To install: diagnostic install';
|
||||
}
|
||||
}
|
||||
if (diag) { diag.close(); diag = null; }
|
||||
break;
|
||||
}
|
||||
default: { // This is an unknown command, return an error message
|
||||
response = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
|
||||
break;
|
||||
@ -1839,7 +2125,7 @@ function createMeshCore(agent) {
|
||||
if (meinfo.UUID != null) { intelamt.uuid = meinfo.UUID; p = true; }
|
||||
if ((meinfo.ProvisioningState == 0) && (meinfo.net0 != null) && (meinfo.net0.enabled == 1)) { // If not activated, look to see if we have wired net working.
|
||||
// Not activated and we have wired ethernet, look for the trusted DNS
|
||||
var dns = meinfo.dns;
|
||||
var dns = meinfo.DNS;
|
||||
if (dns == null) {
|
||||
// Trusted DNS not set, let's look for the OS network DNS suffix
|
||||
var interfaces = require('os').networkInterfaces();
|
||||
|
1
agents/meshcore.min.js
vendored
1
agents/meshcore.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/amt-ider.min.js
vendored
1
agents/modules_meshcmd_min/amt-ider.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/amt-lme.min.js
vendored
1
agents/modules_meshcmd_min/amt-lme.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/amt-mei.min.js
vendored
1
agents/modules_meshcmd_min/amt-mei.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b<e;b++){d=(d<<1);d++}return{min:c&(4294967295-d),max:(c&(4294967295-d))+d}}g=this.parseIpv4Addr(f);if(g==null){return null}return{min:g,max:g}};this.parseIpv4Addr=function(b){var c=b.split(".");if(c.length==4){return(parseInt(c[0])<<24)+(parseInt(c[1])<<16)+(parseInt(c[2])<<8)+(parseInt(c[3])<<0)}return null};this.IPv4NumToStr=function(b){return((b>>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner;
|
1
agents/modules_meshcmd_min/amt-script.min.js
vendored
1
agents/modules_meshcmd_min/amt-script.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
function CreateWsmanComm(){var a={};a.PendingAjax=[];a.ActiveAjaxCount=0;a.MaxActiveAjaxCount=1;a.FailAllError=0;a.digest=null;a.RequestCount=0;if(arguments.length==1&&typeof(arguments[0]=="object")){a.host=arguments[0].host;a.port=arguments[0].port;a.authToken=arguments[0].authToken;a.tls=arguments[0].tls}else{a.host=arguments[0];a.port=arguments[1];a.user=arguments[2];a.pass=arguments[3];a.tls=arguments[4]}a.PerformAjax=function(d,c,f,e,g,b){if((a.ActiveAjaxCount==0||((a.ActiveAjaxCount<a.MaxActiveAjaxCount)&&(a.challengeParams!=null)))&&a.PendingAjax.length==0){a.PerformAjaxEx(d,c,f,g,b)}else{if(e==1){a.PendingAjax.unshift([d,c,f,g,b])}else{a.PendingAjax.push([d,c,f,g,b])}}};a.PerformNextAjax=function(){if(a.ActiveAjaxCount>=a.MaxActiveAjaxCount||a.PendingAjax.length==0){return}var b=a.PendingAjax.shift();a.PerformAjaxEx(b[0],b[1],b[2],b[3],b[4]);a.PerformNextAjax()};a.PerformAjaxEx=function(d,c,g,h,b){if(a.FailAllError!=0){if(a.FailAllError!=999){a.gotNextMessagesError({status:a.FailAllError},"error",null,[d,c,g])}return}if(!d){d=""}if(globalDebugFlags&1){console.log("SEND: "+d+"\r\n\r\n")}if(a.digest==null){if(a.authToken){a.digest=require("http-digest").create({authToken:a.authToken})}else{a.digest=require("http-digest").create(a.user,a.pass)}a.digest.http=require("http")}var f={protocol:(a.tls==1?"https:":"http:"),method:"POST",host:a.host,path:"/wsman",port:a.port,rejectUnauthorized:false,checkServerIdentity:function(i){console.log("checkServerIdentity",JSON.stringify(i))}};var e=a.digest.request(f);e.on("error",function(i){a.gotNextMessagesError({status:600},"error",null,[d,c,g])});e.on("response",function(i){if(globalDebugFlags&1){console.log("Response: "+i.statusCode)}if(i.statusCode!=200){if(globalDebugFlags&1){console.log("ERR:"+JSON.stringify(i))}a.gotNextMessagesError({status:i.statusCode},"error",null,[d,c,g])}else{i.acc="";i.on("data",function(j){this.acc+=j});i.on("end",function(){a.gotNextMessages(i.acc,"success",{status:i.statusCode},[d,c,g])})}});e.end(d);a.ActiveAjaxCount++;return e};a.pendingAjaxCall=[];a.gotNextMessages=function(c,e,d,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(globalDebugFlags&1){console.log("RECV: "+c+"\r\n\r\n")}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(d.status!=200){b[1](null,d.status,b[2]);return}b[1](c,200,b[2]);a.PerformNextAjax()};a.gotNextMessagesError=function(d,e,c,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(a.FailAllError!=999){b[1]({Header:{HttpError:d.status}},d.status,b[2])}a.PerformNextAjax()};a.CancelAllQueries=function(b){while(a.PendingAjax.length>0){var c=a.PendingAjax.shift();c[1](null,b,c[2])}};return a}module.exports=CreateWsmanComm;
|
1
agents/modules_meshcmd_min/amt-wsman.min.js
vendored
1
agents/modules_meshcmd_min/amt-wsman.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/amt-xml.min.js
vendored
1
agents/modules_meshcmd_min/amt-xml.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/amt.min.js
vendored
1
agents/modules_meshcmd_min/amt.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
agents/modules_meshcmd_min/smbios.min.js
vendored
1
agents/modules_meshcmd_min/smbios.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -34,6 +34,7 @@ function AmtManager(agent, db, isdebug) {
|
||||
var osamtstack = null;
|
||||
var amtpolicy = null;
|
||||
var obj = this;
|
||||
var mestate;
|
||||
obj.state = 0;
|
||||
obj.lmsstate = 0;
|
||||
obj.onStateChange = null;
|
||||
@ -92,7 +93,7 @@ function AmtManager(agent, db, isdebug) {
|
||||
amtMei.getLanInterfaceSettings(0, function (result) { if (result) { amtMeiTmpState.net0 = result; } });
|
||||
amtMei.getLanInterfaceSettings(1, function (result) { if (result) { amtMeiTmpState.net1 = result; } });
|
||||
amtMei.getUuid(function (result) { if ((result != null) && (result.uuid != null)) { amtMeiTmpState.UUID = result.uuid; } });
|
||||
amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.dns = result; } if (func != null) { func(amtMeiTmpState); } });
|
||||
amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.DNS = result; } if (func != null) { func(amtMeiTmpState); } });
|
||||
} catch (e) { if (func != null) { func(null); } return; }
|
||||
}
|
||||
|
||||
@ -167,7 +168,7 @@ function AmtManager(agent, db, isdebug) {
|
||||
var amtver = null;
|
||||
try { for (var i in amtGetVersionResult.Versions) { if (amtGetVersionResult.Versions[i].Description == 'AMT') amtver = parseInt(amtGetVersionResult.Versions[i].Version.split('.')[0]); } } catch (e) { }
|
||||
if ((amtver != null) && (amtver >= 12)) {
|
||||
debug('KVM data channel setup');
|
||||
//debug('KVM data channel setup');
|
||||
kvmGetData('skip'); // Clear any previous data, this is a dummy read to about handling old data.
|
||||
obj.kvmTempTimer = setInterval(function () { kvmGetData(); }, 2000); // Start polling for KVM data.
|
||||
kvmSetData(JSON.stringify({ action: 'restart', ver: 1 })); // Send a restart command to advise the console if present that MicroLMS just started.
|
||||
@ -431,6 +432,60 @@ function AmtManager(agent, db, isdebug) {
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Activate Intel AMT to ACM
|
||||
//
|
||||
|
||||
obj.activeToACM = function (mestate) {
|
||||
//debug('ProvisioningState: ' + JSON.stringify(mestate.ProvisioningState));
|
||||
if (mestate.ProvisioningState != 0) return; // Can't activate unless in "PRE" activation mode.
|
||||
var trustedFqdn = null;
|
||||
//debug('Wired Interface: ' + JSON.stringify(mestate.net0));
|
||||
if ((mestate.net0 == null) && (mestate.net0.enabled != 0)) return; // Can't activate unless wired interface is active
|
||||
if (mestate.DNS) { trustedFqdn = mestate.DNS; } // If Intel AMT has a trusted DNS suffix set, use that one.
|
||||
else {
|
||||
// Look for the DNS suffix for the Intel AMT Ethernet interface
|
||||
var interfaces = require('os').networkInterfaces();
|
||||
for (var i in interfaces) {
|
||||
for (var j in interfaces[i]) {
|
||||
if ((interfaces[i][j].mac == mestate.net0.mac) && (interfaces[i][j].fqdn != null) && (interfaces[i][j].fqdn != '')) { trustedFqdn = interfaces[i][j].fqdn; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (trustedFqdn == null) return; // No trusted DNS suffix.
|
||||
//debug('TrustedFqdn: ' + trustedFqdn);
|
||||
|
||||
// Fetch Intel AMT realm and activation nonce and get ready to ACM activation...
|
||||
if (osamtstack != null) {
|
||||
//debug('Trying to get Intel AMT activation information...');
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToACM2, trustedFqdn);
|
||||
} else {
|
||||
//debug('ACM Activation: Trying to get local account info...');
|
||||
amtMei.getLocalSystemAccount(function (x) {
|
||||
if ((x != null) && x.user && x.pass) {
|
||||
//debug('Intel AMT local account info: User=' + x.user + ', Pass=' + x.pass + '.');
|
||||
var transport = require('amt-wsman-duk');
|
||||
var wsman = require('amt-wsman');
|
||||
var amt = require('amt');
|
||||
oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false);
|
||||
osamtstack = new amt(oswsstack);
|
||||
//debug('Trying to get Intel AMT activation information...');
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToACM2, trustedFqdn);
|
||||
} else {
|
||||
//debug('Unable to get $$OsAdmin password.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function activeToACM2(stack, name, responses, status, trustedFqdn) {
|
||||
debug('activeToACM2: ' + trustedFqdn);
|
||||
if (status != 200) return;
|
||||
var fwNonce = responses['IPS_HostBasedSetupService'].response['ConfigurationNonce'];
|
||||
var digestRealm = responses['AMT_GeneralSettings'].response['DigestRealm'];
|
||||
agent.SendCommand({ "action": "acmactivate", "nonce": fwNonce, "realm": digestRealm, "fqdn": trustedFqdn });
|
||||
}
|
||||
|
||||
//
|
||||
// Activate Intel AMT to CCM
|
||||
//
|
||||
@ -444,21 +499,25 @@ function AmtManager(agent, db, isdebug) {
|
||||
obj.activeToCCM = function (adminpass) {
|
||||
if ((adminpass == null) || (adminpass == '')) { adminpass = 'P@0s' + makePass(23); }
|
||||
intelAmtAdminPass = adminpass;
|
||||
//debug('Trying to get local account info...');
|
||||
amtMei.getLocalSystemAccount(function (x) {
|
||||
if ((x != null) && x.user && x.pass) {
|
||||
//debug('Intel AMT local account info: User=' + x.user + ', Pass=' + x.pass + '.');
|
||||
var transport = require('amt-wsman-duk');
|
||||
var wsman = require('amt-wsman');
|
||||
var amt = require('amt');
|
||||
oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false);
|
||||
osamtstack = new amt(oswsstack);
|
||||
//debug('Trying to get Intel AMT activation information...');
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToCCMEx2, adminpass);
|
||||
} else {
|
||||
debug('Unable to get $$OsAdmin password.');
|
||||
}
|
||||
});
|
||||
if (osamtstack != null) {
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToCCMEx2, adminpass);
|
||||
} else {
|
||||
//debug('Trying to get local account info...');
|
||||
amtMei.getLocalSystemAccount(function (x) {
|
||||
if ((x != null) && x.user && x.pass) {
|
||||
//debug('Intel AMT local account info: User=' + x.user + ', Pass=' + x.pass + '.');
|
||||
var transport = require('amt-wsman-duk');
|
||||
var wsman = require('amt-wsman');
|
||||
var amt = require('amt');
|
||||
oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false);
|
||||
osamtstack = new amt(oswsstack);
|
||||
//debug('Trying to get Intel AMT activation information...');
|
||||
osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToCCMEx2, adminpass);
|
||||
} else {
|
||||
//debug('Unable to get $$OsAdmin password.');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var activeToCCMEx2 = function(stack, name, responses, status, adminpass) {
|
||||
@ -518,13 +577,7 @@ function AmtManager(agent, db, isdebug) {
|
||||
try { amtstack.BatchEnum(null, wsmanQuery, wsmanPassTestResponse); } catch (ex) { debug(ex); }
|
||||
} else if ((amtpolicy.type == 3) && (meinfo.ProvisioningState == 0)) {
|
||||
// ACM Activation Policy
|
||||
// TODO: Check that we have wired ethernet enabled and that the DNS domain suffix matches a server certificate...
|
||||
|
||||
// TODO: Check that a trusted hash matches the server cert root hash...
|
||||
|
||||
// TODO: Fetch Intel AMT Realm and Nonce and get ready to ACM activation...
|
||||
|
||||
//console.log(meinfo);
|
||||
obj.activeToACM(meinfo);
|
||||
} else {
|
||||
// Other possible cases...
|
||||
}
|
||||
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
Copyright 2018-2019 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
var toasters = {};
|
||||
|
||||
function Toaster()
|
||||
{
|
||||
this._ObjectID = 'toaster';
|
||||
this.Toast = function Toast(title, caption)
|
||||
{
|
||||
var retVal = {};
|
||||
var emitter = require('events').inherits(retVal);
|
||||
emitter.createEvent('Dismissed');
|
||||
|
||||
retVal.title = title;
|
||||
retVal.caption = caption;
|
||||
|
||||
if (process.platform == 'win32')
|
||||
{
|
||||
emitter.createEvent('Clicked');
|
||||
|
||||
var session = require('user-sessions').Current();
|
||||
for (var i in session) {
|
||||
console.log(session[i]);
|
||||
}
|
||||
try {
|
||||
console.log('Attempting Toast Mechanism 1');
|
||||
retVal._child = require('ScriptContainer').Create({ processIsolation: true, sessionId: session.Active[0].SessionId });
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
console.log('Attempting Toast Mechanism 2');
|
||||
retVal._child = require('ScriptContainer').Create({ processIsolation: true });
|
||||
}
|
||||
retVal._child.parent = retVal;
|
||||
|
||||
retVal._child.on('exit', function (code) { this.parent.emit('Dismissed'); delete this.parent._child; });
|
||||
retVal._child.addModule('win-console', getJSModule('win-console'));
|
||||
retVal._child.addModule('win-message-pump', getJSModule('win-message-pump'));
|
||||
|
||||
var str = "\
|
||||
try{\
|
||||
var toast = require('win-console');\
|
||||
var balloon = toast.SetTrayIcon({ szInfo: '" + caption + "', szInfoTitle: '" + title + "', balloonOnly: true });\
|
||||
balloon.on('ToastDismissed', function(){process.exit();});\
|
||||
}\
|
||||
catch(e)\
|
||||
{\
|
||||
require('ScriptContainer').send(e);\
|
||||
}\
|
||||
require('ScriptContainer').send('done');\
|
||||
";
|
||||
retVal._child.ExecuteString(str);
|
||||
toasters[retVal._hashCode()] = retVal;
|
||||
retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; });
|
||||
console.log('Returning');
|
||||
return (retVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!require('fs').existsSync('/usr/bin/notify-send'))
|
||||
{
|
||||
throw ('Toast not supported on this platform');
|
||||
}
|
||||
Object.defineProperty(retVal, '_sessions', {
|
||||
value: require('user-sessions').Current(function onCurrentSession(sessions)
|
||||
{
|
||||
this._cchild = require('child_process').execFile('/usr/bin/whoami', ['whoami'], { type: require('child_process').SpawnTypes.TERM });
|
||||
this._cchild.stdout.on('data', function (chunk)
|
||||
{
|
||||
if (chunk.toString().split('\r\n')[0] == 'root')
|
||||
{
|
||||
if (sessions[':0'].State != 'Connected' && sessions[':0'].State != 'Active')
|
||||
{
|
||||
// No logged in user owns the display
|
||||
this.parent.parent.Parent.emit('Dismissed');
|
||||
return;
|
||||
}
|
||||
|
||||
// We root, so we need to direct to DISPLAY=:0
|
||||
this.parent.parent._notify = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
|
||||
this.parent.parent._notify.stdin.write('su - ' + sessions[':0'].Username + ' -c "DISPLAY=:0 notify-send \'' + this.parent.parent.Parent.title + '\' \'' + this.parent.parent.Parent.caption + '\'"\n');
|
||||
this.parent.parent._notify.stdin.write('exit\n');
|
||||
this.parent.parent._notify.stdout.on('data', function (chunk) { });
|
||||
}
|
||||
else
|
||||
{
|
||||
// We ain't root, so that means we can just call send-notify directly
|
||||
this.parent.parent._notify = require('child_process').execFile('/usr/bin/notify-send', ['notify-send', this.parent.parent.Parent.title, this.parent.parent.Parent.caption], { type: require('child_process').SpawnTypes.TERM });
|
||||
this.parent.parent._notify.stdout.on('data', function (chunk) { });
|
||||
}
|
||||
|
||||
// NOTIFY-SEND has a bug where timeouts don't work, so the default is 10 seconds
|
||||
this.parent.parent.Parent._timeout = setTimeout(function onFakeDismissed(obj)
|
||||
{
|
||||
obj.emit('Dismissed');
|
||||
}, 10000, this.parent.parent.Parent);
|
||||
});
|
||||
this._cchild.parent = this;
|
||||
})
|
||||
});
|
||||
retVal._sessions.Parent = retVal;
|
||||
|
||||
toasters[retVal._hashCode()] = retVal;
|
||||
retVal.on('Dismissed', function () { delete toasters[this._hashCode()]; });
|
||||
|
||||
return (retVal);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = new Toaster();
|
1
agents/modules_meshcore_min/amt-lme.min.js
vendored
1
agents/modules_meshcore_min/amt-lme.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
agents/modules_meshcore_min/amt-mei.min.js
vendored
1
agents/modules_meshcore_min/amt-mei.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
function AMTScanner(){var a=require("events").inherits(this);a.createEvent("found");this.dgram=require("dgram");this.buildRmcpPing=function(c){var b=Buffer.from("06000006000011BE80000000","hex");b[9]=c;return b};this.parseRmcpPacket=function(h,b,g,d){if(b==null||b.length<20){return}var f={};if(((b[12]==0)||(b[13]!=0)||(b[14]!=1)||(b[15]!=87))&&(b[21]&32)){f.servertag=b[9];f.minorVersion=b[18]&15;f.majorVersion=(b[18]>>4)&15;f.provisioningState=b[19]&3;var e=(b[16]*256)+b[17];var c=((b[19]&4)!=0)?true:false;f.openPorts=[e];f.address=g.address;if(c==true){f.openPorts=[16992,16993]}if(d!==undefined){d(h,f)}}};this.parseIPv4Range=function(f){if(f==undefined||f==null){return null}var g=f.split("-");if(g.length==2){return{min:this.parseIpv4Addr(g[0]),max:this.parseIpv4Addr(g[1])}}g=f.split("/");if(g.length==2){var c=this.parseIpv4Addr(g[0]),e=parseInt(g[1]),d=0;if(e<=16||e>32){return null}e=32-e;for(var b=0;b<e;b++){d=(d<<1);d++}return{min:c&(4294967295-d),max:(c&(4294967295-d))+d}}g=this.parseIpv4Addr(f);if(g==null){return null}return{min:g,max:g}};this.parseIpv4Addr=function(b){var c=b.split(".");if(c.length==4){return(parseInt(c[0])<<24)+(parseInt(c[1])<<16)+(parseInt(c[2])<<8)+(parseInt(c[3])<<0)}return null};this.IPv4NumToStr=function(b){return((b>>24)&255)+"."+((b>>16)&255)+"."+((b>>8)&255)+"."+(b&255)};this.scan=function(d,g){var c=this.parseIPv4Range(d);var e=this.buildRmcpPing(0);var f=this.dgram.createSocket({type:"udp4"});f.parent=this;f.scanResults=[];f.on("error",function(i){console.log("Error:"+i)});f.on("message",function(i,j){if(j.size>4){this.parent.parseRmcpPacket(this,i,j,function(l,k){l.scanResults.push(k)})}});f.on("listening",function(){for(var j=c.min;j<=c.max;j++){f.send(e,623,f.parent.IPv4NumToStr(j))}});f.bind({address:"0.0.0.0",port:0,exclusive:true});var h=setTimeout(function b(){f.close();f.parent.emit("found",f.scanResults);delete f},g)}}module.exports=AMTScanner;
|
@ -1 +0,0 @@
|
||||
function CreateWsmanComm(){var a={};a.PendingAjax=[];a.ActiveAjaxCount=0;a.MaxActiveAjaxCount=1;a.FailAllError=0;a.digest=null;a.RequestCount=0;if(arguments.length==1&&typeof(arguments[0]=="object")){a.host=arguments[0].host;a.port=arguments[0].port;a.authToken=arguments[0].authToken;a.tls=arguments[0].tls}else{a.host=arguments[0];a.port=arguments[1];a.user=arguments[2];a.pass=arguments[3];a.tls=arguments[4]}a.PerformAjax=function(d,c,f,e,g,b){if((a.ActiveAjaxCount==0||((a.ActiveAjaxCount<a.MaxActiveAjaxCount)&&(a.challengeParams!=null)))&&a.PendingAjax.length==0){a.PerformAjaxEx(d,c,f,g,b)}else{if(e==1){a.PendingAjax.unshift([d,c,f,g,b])}else{a.PendingAjax.push([d,c,f,g,b])}}};a.PerformNextAjax=function(){if(a.ActiveAjaxCount>=a.MaxActiveAjaxCount||a.PendingAjax.length==0){return}var b=a.PendingAjax.shift();a.PerformAjaxEx(b[0],b[1],b[2],b[3],b[4]);a.PerformNextAjax()};a.PerformAjaxEx=function(d,c,g,h,b){if(a.FailAllError!=0){if(a.FailAllError!=999){a.gotNextMessagesError({status:a.FailAllError},"error",null,[d,c,g])}return}if(!d){d=""}if(a.digest==null){if(a.authToken){a.digest=require("http-digest").create({authToken:a.authToken})}else{a.digest=require("http-digest").create(a.user,a.pass)}a.digest.http=require("http")}var f={protocol:(a.tls==1?"https:":"http:"),method:"POST",host:a.host,path:"/wsman",port:a.port,rejectUnauthorized:false,checkServerIdentity:function(i){console.log("checkServerIdentity",JSON.stringify(i))}};var e=a.digest.request(f);e.on("error",function(i){a.gotNextMessagesError({status:600},"error",null,[d,c,g])});e.on("response",function(i){if(i.statusCode!=200){a.gotNextMessagesError({status:i.statusCode},"error",null,[d,c,g])}else{i.acc="";i.on("data",function(j){this.acc+=j});i.on("end",function(){a.gotNextMessages(i.acc,"success",{status:i.statusCode},[d,c,g])})}});e.end(d);a.ActiveAjaxCount++;return e};a.pendingAjaxCall=[];a.gotNextMessages=function(c,e,d,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(d.status!=200){b[1](null,d.status,b[2]);return}b[1](c,200,b[2]);a.PerformNextAjax()};a.gotNextMessagesError=function(d,e,c,b){a.ActiveAjaxCount--;if(a.FailAllError==999){return}if(a.FailAllError!=0){b[1](null,a.FailAllError,b[2]);return}if(a.FailAllError!=999){b[1]({Header:{HttpError:d.status}},d.status,b[2])}a.PerformNextAjax()};a.CancelAllQueries=function(b){while(a.PendingAjax.length>0){var c=a.PendingAjax.shift();c[1](null,b,c[2])}};return a}module.exports=CreateWsmanComm;
|
1
agents/modules_meshcore_min/amt-wsman.min.js
vendored
1
agents/modules_meshcore_min/amt-wsman.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcore_min/amt-xml.min.js
vendored
1
agents/modules_meshcore_min/amt-xml.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcore_min/amt.min.js
vendored
1
agents/modules_meshcore_min/amt.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
try{Object.defineProperty(Array.prototype,"peek",{value:function(){return(this.length>0?this[this.length-1]:undefined)}})}catch(e){}function dbus(a,b){this._ObjectID="linux-dbus";require("events").EventEmitter.call(this,true).createEvent("signal");Object.defineProperty(this,"uid",{value:b});this._child=require("child_process").execFile("/bin/sh",["sh"],{type:require("child_process").SpawnTypes.TERM,uid:b==null?-1:b});this._child.stdin.write("dbus-monitor --session \"type='signal', interface='"+a+'\'" | ( while read X; do echo "$X"; done )\n');this._child.stdout.dbus=this;this._child.stdout.on("data",function(c){if(!this.ready){this.ready=true;return}var f=[];var g=c.toString().split("\r\n");for(var d in g){if(g[d]==""){this.dbus.preParseRecords(f);f=[]}else{f.push(g[d])}}});this.preParseRecords=function(d){var f=[];for(var c in d){if(d[c].startsWith("signal ")){if(f.length>0){this.parseRecords(f)}f=[]}f.push(d[c])}if(f.length>0){this.parseRecords(f)}};this.parseRecords=function(d){if(d[0].startsWith("signal ")){var g={};var h=d[0].split(" ");h.shift();for(var c in h){var f=h[c].split("=");if(f.length==2){g[f[0]]=f[1]}}d.shift();g.data=d;this.parseSignal(g)}};this.parseSignal=function(f){var c=f.data;f.data=[];for(var d=0;d<c.length;++d){if(c[d].startsWith("array ")){f.data.push([]);for(d=d+1;d<c.length;++d){this.parseSignal2(c[d],f.data.peek())}}else{this.parseSignal2(c[d],f.data)}}this.emit("signal",f)};this.parseSignal2=function(c,d){if(c.startsWith("string ")){d.push(JSON.parse(c.slice(7)))}else{if(c.startsWith("boolean ")){d.push(JSON.parse(c.slice(8)))}}}}module.exports=dbus;
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
function powerMonitor(){this._ObjectID="power-monitor";require("events").EventEmitter.call(this,true).createEvent("changed").createEvent("sx").createEvent("batteryLevel").createEvent("acdc").createEvent("display");this._i=setImmediate(function(a){require("user-sessions");delete a._i},this)}module.exports=new powerMonitor();
|
1
agents/modules_meshcore_min/smbios.min.js
vendored
1
agents/modules_meshcore_min/smbios.min.js
vendored
File diff suppressed because one or more lines are too long
1
agents/modules_meshcore_min/toaster.min.js
vendored
1
agents/modules_meshcore_min/toaster.min.js
vendored
@ -1 +0,0 @@
|
||||
var toasters={};function Toaster(){this._ObjectID="toaster";this.Toast=function a(l,b){var h={};var d=require("events").inherits(h);d.createEvent("Dismissed");h.title=l;h.caption=b;if(process.platform=="win32"){d.createEvent("Clicked");var j=require("user-sessions").Current();for(var f in j){console.log(j[f])}try{console.log("Attempting Toast Mechanism 1");h._child=require("ScriptContainer").Create({processIsolation:true,sessionId:j.Active[0].SessionId})}catch(c){console.log(c);console.log("Attempting Toast Mechanism 2");h._child=require("ScriptContainer").Create({processIsolation:true})}h._child.parent=h;h._child.on("exit",function(e){this.parent.emit("Dismissed");delete this.parent._child});h._child.addModule("win-console",getJSModule("win-console"));h._child.addModule("win-message-pump",getJSModule("win-message-pump"));var k=" try{ var toast = require('win-console'); var balloon = toast.SetTrayIcon({ szInfo: '"+b+"', szInfoTitle: '"+l+"', balloonOnly: true }); balloon.on('ToastDismissed', function(){process.exit();}); } catch(e) { require('ScriptContainer').send(e); } require('ScriptContainer').send('done'); ";h._child.ExecuteString(k);toasters[h._hashCode()]=h;h.on("Dismissed",function(){delete toasters[this._hashCode()]});console.log("Returning");return(h)}else{if(!require("fs").existsSync("/usr/bin/notify-send")){throw ("Toast not supported on this platform")}Object.defineProperty(h,"_sessions",{value:require("user-sessions").Current(function g(e){this._cchild=require("child_process").execFile("/usr/bin/whoami",["whoami"],{type:require("child_process").SpawnTypes.TERM});this._cchild.stdout.on("data",function(i){if(i.toString().split("\r\n")[0]=="root"){if(e[":0"].State!="Connected"&&e[":0"].State!="Active"){this.parent.parent.Parent.emit("Dismissed");return}this.parent.parent._notify=require("child_process").execFile("/bin/sh",["sh"],{type:require("child_process").SpawnTypes.TERM});this.parent.parent._notify.stdin.write("su - "+e[":0"].Username+" -c \"DISPLAY=:0 notify-send '"+this.parent.parent.Parent.title+"' '"+this.parent.parent.Parent.caption+"'\"\n");this.parent.parent._notify.stdin.write("exit\n");this.parent.parent._notify.stdout.on("data",function(n){})}else{this.parent.parent._notify=require("child_process").execFile("/usr/bin/notify-send",["notify-send",this.parent.parent.Parent.title,this.parent.parent.Parent.caption],{type:require("child_process").SpawnTypes.TERM});this.parent.parent._notify.stdout.on("data",function(n){})}this.parent.parent.Parent._timeout=setTimeout(function m(n){n.emit("Dismissed")},10000,this.parent.parent.Parent)});this._cchild.parent=this})});h._sessions.Parent=h;toasters[h._hashCode()]=h;h.on("Dismissed",function(){delete toasters[this._hashCode()]});return(h)}}}module.exports=new Toaster();
|
@ -1 +0,0 @@
|
||||
function _Scan(){var f=this.Marshal.CreatePointer();this.Native.WlanEnumInterfaces(this.Handle,0,f);var a=f.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var d=f.Deref().Deref(8,532);var c=d.Deref(16,512).AnsiString;var e;switch(d.Deref(528,4).toBuffer().readUInt32LE(0)){case 0:e="NOT READY";break;case 1:e="CONNECTED";break;case 2:e="AD-HOC";break;case 3:e="DISCONNECTING";break;case 4:e="DISCONNECTED";break;case 5:e="ASSOCIATING";break;case 6:e="DISCOVERING";break;case 7:e="AUTHENTICATING";break;default:e="UNKNOWN";break}var b=d.Deref(0,16);if(this.Native.WlanScan(this.Handle,b,0,0,0).Val==0){return(true)}else{return(false)}}function AccessPoint(d,a,c,b){this.ssid=d;this.bssid=a;this.rssi=c;this.lq=b}AccessPoint.prototype.toString=function(){return(this.ssid+" ["+this.bssid+"]: "+this.lq)};function OnNotify(g){var h=g.Deref(0,4).toBuffer().readUInt32LE(0);var f=g.Deref(4,4).toBuffer().readUInt32LE(0);var c=g.Deref(8,16);if((h&8)&&(f==7)){var a=this.Parent.Marshal.CreatePointer();var k=this.Parent.Native.GetBSSList(this.Parent.Handle,c,0,3,0,0,a).Val;if(k==0){var n=a.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var j=a.Deref().Deref(4,4).toBuffer().readUInt32LE(0);for(i=0;i<j;++i){var d=a.Deref().Deref(8+(360*i),360);var m=d.Deref(4,32).String.trim();var b=d.Deref(40,6).HexString2;var l=d.Deref(56,4).toBuffer().readUInt32LE(0);var e=d.Deref(60,4).toBuffer().readUInt32LE(0);this.Parent.emit("Scan",new AccessPoint(m,b,l,e))}}}}function Wireless(){var a=require("events").inherits(this);this.Marshal=require("_GenericMarshal");this.Native=this.Marshal.CreateNativeProxy("wlanapi.dll");this.Native.CreateMethod("WlanOpenHandle");this.Native.CreateMethod("WlanGetNetworkBssList","GetBSSList");this.Native.CreateMethod("WlanRegisterNotification");this.Native.CreateMethod("WlanEnumInterfaces");this.Native.CreateMethod("WlanScan");this.Native.CreateMethod("WlanQueryInterface");var c=this.Marshal.CreatePointer();var b=this.Marshal.CreatePointer();this.Native.WlanOpenHandle(2,0,c,b);this.Handle=b.Deref();this._NOTIFY_PROXY_OBJECT=this.Marshal.CreateCallbackProxy(OnNotify,2);this._NOTIFY_PROXY_OBJECT.Parent=this;var d=this.Marshal.CreatePointer();var e=this.Native.WlanRegisterNotification(this.Handle,65535,0,this._NOTIFY_PROXY_OBJECT.Callback,this._NOTIFY_PROXY_OBJECT.State,0,d);a.createEvent("Scan");a.addMethod("Scan",_Scan);this.GetConnectedNetwork=function(){var n=this.Marshal.CreatePointer();console.log("Success = "+this.Native.WlanEnumInterfaces(this.Handle,0,n).Val);var h=n.Deref().Deref(0,4).toBuffer().readUInt32LE(0);var m=n.Deref().Deref(8,532);var l=m.Deref(16,512).AnsiString;var o=m.Deref(528,4).toBuffer().readUInt32LE(0);if(m.Deref(528,4).toBuffer().readUInt32LE(0)==1){var j=this.Marshal.CreatePointer();var q=this.Marshal.CreatePointer();var s=this.Marshal.CreatePointer();var k=m.Deref(0,16);var r=this.Native.WlanQueryInterface(this.Handle,k,7,0,j,q,s).Val;if(r==0){var f=q.Deref().Deref(524,32).String;var g=q.Deref().Deref(560,6).HexString;var p=q.Deref().Deref(576,4).toBuffer().readUInt32LE(0);return(new AccessPoint(f,g,0,p))}}throw ("GetConnectedNetworks: FAILED (not associated to a network)")};return(this)}module.exports=new Wireless();
|
@ -1 +0,0 @@
|
||||
var MemoryStream=require("MemoryStream");var WindowsChildScript='var parent = require("ScriptContainer");var Wireless = require("wifi-scanner-windows");Wireless.on("Scan", function (ap) { parent.send(ap); });Wireless.Scan();';function AccessPoint(c,a,b){this.ssid=c;this.bssid=a;this.lq=b}AccessPoint.prototype.toString=function(){return("["+this.bssid+"]: "+this.ssid+" ("+this.lq+")")};function WiFiScanner(){var a=require("events").inherits(this);a.createEvent("accessPoint");this.hasWireless=function(){var d=false;var b=require("os").networkInterfaces();for(var c in b){if(b[c][0].type=="wireless"){d=true;break}}return(d)};this.Scan=function(){if(process.platform=="win32"){this.master=require("ScriptContainer").Create(15,ContainerPermissions.DEFAULT);this.master.parent=this;this.master.on("data",function(e){this.parent.emit("accessPoint",new AccessPoint(e.ssid,e.bssid,e.lq))});this.master.addModule("wifi-scanner-windows",getJSModule("wifi-scanner-windows"));this.master.ExecuteString(WindowsChildScript)}else{if(process.platform=="linux"){var c=require("os").networkInterfaces();var d=null;for(var b in c){if(c[b][0].type=="wireless"){d=b;break}}if(d!=null){this.child=require("child_process").execFile("/sbin/iwlist",["iwlist",d,"scan"]);this.child.parent=this;this.child.ms=new MemoryStream();this.child.ms.parent=this.child;this.child.stdout.on("data",function(e){this.parent.ms.write(e)});this.child.on("exit",function(){this.ms.end()});this.child.ms.on("end",function(){var l=this.buffer.toString();tokens=l.split(" - Address: ");for(var h in tokens){if(h==0){continue}var i=tokens[h].split("\n");var e=i[0];var f;var g;for(var j in i){j=i[j].trim();j=j.trim();if(j.startsWith("ESSID:")){g=j.slice(7,j.length-1);if(g=="<hidden>"){g=""}}if(j.startsWith("Signal level=")){f=j.slice(13,j.length-4)}else{if(j.startsWith("Quality=")){f=j.slice(8,10);var k=j.slice(11,13)}}}this.parent.parent.emit("accessPoint",new AccessPoint(g,e,f))}})}}}}}module.exports=WiFiScanner;
|
@ -1 +0,0 @@
|
||||
var TrayIconFlags={NIF_MESSAGE:1,NIF_ICON:2,NIF_TIP:4,NIF_STATE:8,NIF_INFO:16,NIF_GUID:32,NIF_REALTIME:64,NIF_SHOWTIP:128,NIM_ADD:0,NIM_MODIFY:1,NIM_DELETE:2,NIM_SETFOCUS:3,NIM_SETVERSION:4};var NOTIFYICON_VERSION_4=4;var MessageTypes={WM_APP:32768,WM_USER:1024};function WindowsConsole(){if(process.platform=="win32"){this._ObjectID="win-console";this._Marshal=require("_GenericMarshal");this._kernel32=this._Marshal.CreateNativeProxy("kernel32.dll");this._user32=this._Marshal.CreateNativeProxy("user32.dll");this._kernel32.CreateMethod("GetConsoleWindow");this._kernel32.CreateMethod("GetCurrentThread");this._user32.CreateMethod("ShowWindow");this._user32.CreateMethod("LoadImageA");this._user32.CreateMethod({method:"GetMessageA",threadDispatch:1});this._shell32=this._Marshal.CreateNativeProxy("Shell32.dll");this._shell32.CreateMethod("Shell_NotifyIconA");this._handle=this._kernel32.GetConsoleWindow();this.minimize=function(){this._user32.ShowWindow(this._handle,6)};this.restore=function(){this._user32.ShowWindow(this._handle,9)};this.hide=function(){this._user32.ShowWindow(this._handle,0)};this.show=function(){this._user32.ShowWindow(this._handle,5)};this._loadicon=function(c){var b=this._user32.LoadImageA(0,this._Marshal.CreateVariable(c),1,0,0,16|32768|64);return(b)};this.SetTrayIcon=function a(h){var b=this._Marshal.CreateVariable(this._Marshal.PointerSize==4?508:528);b.toBuffer().writeUInt32LE(b._size,0);var n=TrayIconFlags.NIF_TIP|TrayIconFlags.NIF_MESSAGE;h.filter=MessageTypes.WM_APP+1;b.Deref(this._Marshal.PointerSize==4?16:24,4).toBuffer().writeUInt32LE(h.filter);if(!h.noBalloon){n|=TrayIconFlags.NIF_INFO}if(h.icon){n|=TrayIconFlags.NIF_ICON;var c=b.Deref(this._Marshal.PointerSize==4?20:32,this._Marshal.PointerSize);h.icon.pointerBuffer().copy(c.toBuffer())}b.Deref(this._Marshal.PointerSize*2,4).toBuffer().writeUInt32LE(1);b.Deref(this._Marshal.PointerSize==4?12:20,4).toBuffer().writeUInt32LE(n);b.Deref(this._Marshal.PointerSize==4?416:432,4).toBuffer().writeUInt32LE(NOTIFYICON_VERSION_4);var m=b.Deref(this._Marshal.PointerSize==4?24:40,128);var k=b.Deref(this._Marshal.PointerSize==4?160:176,256);var l=b.Deref(this._Marshal.PointerSize==4?420:436,64);if(h.szTip){Buffer.from(h.szTip).copy(m.toBuffer())}if(h.szInfo){Buffer.from(h.szInfo).copy(k.toBuffer())}if(h.szInfoTitle){Buffer.from(h.szInfoTitle).copy(l.toBuffer())}var d=require("win-message-pump");retVal={_ObjectID:"WindowsConsole.TrayIcon",MessagePump:new d(h)};var j=require("events").inherits(retVal);j.createEvent("ToastClicked");j.createEvent("IconHover");j.createEvent("ToastDismissed");retVal.Options=h;retVal.MessagePump.TrayIcon=retVal;retVal.MessagePump.NotifyData=b;retVal.MessagePump.WindowsConsole=this;retVal.MessagePump.on("exit",function e(o){console.log("Pump Exited");if(this.TrayIcon){this.TrayIcon.remove()}});retVal.MessagePump.on("hwnd",function f(o){h.hwnd=o;o.pointerBuffer().copy(this.NotifyData.Deref(this.WindowsConsole._Marshal.PointerSize,this.WindowsConsole._Marshal.PointerSize).toBuffer());if(this.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_ADD,this.NotifyData).Val==0){}});retVal.MessagePump.on("message",function g(p){if(p.message==this.TrayIcon.Options.filter){var o=false;if(p.wparam==1&&p.lparam==1029){this.TrayIcon.emit("ToastClicked");o=true}if(p.wparam==1&&p.lparam==512){this.TrayIcon.emit("IconHover");o=true}if(this.TrayIcon.Options.balloonOnly&&p.wparam==1&&(p.lparam==1028||p.lparam==1029)){this.TrayIcon.emit("ToastDismissed");this.TrayIcon.remove();o=true}}});retVal.remove=function i(){this.MessagePump.WindowsConsole._shell32.Shell_NotifyIconA(TrayIconFlags.NIM_DELETE,this.MessagePump.NotifyData);this.MessagePump.stop();delete this.MessagePump.TrayIcon;delete this.MessagePump};return(retVal)}}}module.exports=new WindowsConsole();
|
File diff suppressed because one or more lines are too long
@ -1200,6 +1200,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'acmactivate':
|
||||
{
|
||||
// Agent is asking the server to sign an Intel AMT ACM activation request
|
||||
//console.log(command);
|
||||
// TODO
|
||||
break;
|
||||
}
|
||||
case 'diagnostic':
|
||||
{
|
||||
if (typeof command.value == 'object') {
|
||||
|
@ -1600,7 +1600,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (common.validateString(command.amtpolicy.password, 0, 32) == false) break; // Check the amtpolicy.password
|
||||
if (common.validateInt(command.amtpolicy.cirasetup, 0, 2) == false) break; // Check the amtpolicy.cirasetup
|
||||
}
|
||||
console.log('meshamtpolicy', command);
|
||||
mesh = parent.meshes[command.meshid];
|
||||
change = '';
|
||||
if (mesh) {
|
||||
|
@ -1,834 +0,0 @@
|
||||
/**
|
||||
* @description Remote Desktop
|
||||
* @author Ylian Saint-Hilaire
|
||||
* @version v0.0.2g
|
||||
*/
|
||||
|
||||
// Construct a MeshServer object
|
||||
var CreateAmtRemoteDesktop = function (divid, scrolldiv) {
|
||||
var obj = {};
|
||||
obj.canvasid = divid;
|
||||
obj.CanvasId = Q(divid);
|
||||
obj.scrolldiv = scrolldiv;
|
||||
obj.canvas = Q(divid).getContext("2d");
|
||||
obj.protocol = 2; // KVM
|
||||
obj.state = 0;
|
||||
obj.acc = "";
|
||||
obj.ScreenWidth = 960;
|
||||
obj.ScreenHeight = 700;
|
||||
obj.width = 0;
|
||||
obj.height = 0;
|
||||
obj.rwidth = 0;
|
||||
obj.rheight = 0;
|
||||
obj.bpp = 2; // Bytes per pixel (1 or 2 supported)
|
||||
obj.useZRLE = true;
|
||||
obj.showmouse = true;
|
||||
obj.buttonmask = 0;
|
||||
obj.localKeyMap = true;
|
||||
//obj.inbytes = 0;
|
||||
//obj.outbytes = 0;
|
||||
obj.spare = null;
|
||||
obj.sparew = 0;
|
||||
obj.spareh = 0;
|
||||
obj.sparew2 = 0;
|
||||
obj.spareh2 = 0;
|
||||
obj.sparecache = {};
|
||||
obj.ZRLEfirst = 1;
|
||||
obj.onScreenSizeChange = null;
|
||||
obj.frameRateDelay = 0;
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
obj.noMouseRotate = false;
|
||||
obj.rotation = 0;
|
||||
// ###END###{DesktopRotation}
|
||||
// ###BEGIN###{DesktopInband}
|
||||
obj.kvmDataSupported = false;
|
||||
obj.onKvmData = null;
|
||||
obj.onKvmDataPending = [];
|
||||
obj.onKvmDataAck = -1;
|
||||
obj.holding = false;
|
||||
obj.lastKeepAlive = Date.now();
|
||||
// ###END###{DesktopInband}
|
||||
|
||||
// ###BEGIN###{DesktopFocus}
|
||||
obj.mx = 0; // Last mouse x position
|
||||
obj.my = 0; // Last mouse y position
|
||||
obj.ox = -1; // Old mouse x position
|
||||
obj.oy = -1; // Old mouse y position
|
||||
obj.focusmode = 0;
|
||||
// ###END###{DesktopFocus}
|
||||
// ###BEGIN###{Inflate}
|
||||
obj.inflate = ZLIB.inflateInit(-15);
|
||||
// ###END###{Inflate}
|
||||
|
||||
// Private method
|
||||
obj.Debug = function (msg) { console.log(msg); }
|
||||
|
||||
obj.xxStateChange = function (newstate) {
|
||||
if (newstate == 0) {
|
||||
obj.canvas.fillStyle = '#000000';
|
||||
obj.canvas.fillRect(0, 0, obj.width, obj.height);
|
||||
obj.canvas.canvas.width = obj.rwidth = obj.width = 640;
|
||||
obj.canvas.canvas.height = obj.rheight = obj.height = 400;
|
||||
QS(obj.canvasid).cursor = 'default';
|
||||
} else {
|
||||
QS(obj.canvasid).cursor = obj.showmouse ?'default':'none';
|
||||
}
|
||||
}
|
||||
|
||||
obj.ProcessData = function (data) {
|
||||
if (!data) return;
|
||||
// obj.Debug("KRecv(" + data.length + "): " + rstr2hex(data));
|
||||
//obj.inbytes += data.length;
|
||||
//obj.Debug("KRecv(" + obj.inbytes + ")");
|
||||
obj.acc += data;
|
||||
while (obj.acc.length > 0) {
|
||||
//obj.Debug("KAcc(" + obj.acc.length + "): " + rstr2hex(obj.acc));
|
||||
var cmdsize = 0;
|
||||
if (obj.state == 0 && obj.acc.length >= 12) {
|
||||
// Getting handshake & version
|
||||
cmdsize = 12;
|
||||
//if (obj.acc.substring(0, 4) != "RFB ") { return obj.Stop(); }
|
||||
//var version = parseFloat(obj.acc.substring(4, 11));
|
||||
//obj.Debug("KVersion: " + version);
|
||||
obj.state = 1;
|
||||
obj.send("RFB 003.008\n");
|
||||
}
|
||||
else if (obj.state == 1 && obj.acc.length >= 1) {
|
||||
// Getting security options
|
||||
cmdsize = obj.acc.charCodeAt(0) + 1;
|
||||
obj.send(String.fromCharCode(1)); // Send the "None" security type. Since we already authenticated using redirection digest auth, we don't need to do this again.
|
||||
obj.state = 2;
|
||||
}
|
||||
else if (obj.state == 2 && obj.acc.length >= 4) {
|
||||
// Getting security response
|
||||
cmdsize = 4;
|
||||
if (ReadInt(obj.acc, 0) != 0) { return obj.Stop(); }
|
||||
obj.send(String.fromCharCode(1)); // Send share desktop flag
|
||||
obj.state = 3;
|
||||
}
|
||||
else if (obj.state == 3 && obj.acc.length >= 24) {
|
||||
// Getting server init
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
obj.rotation = 0; // We don't currently support screen init while rotated.
|
||||
// ###END###{DesktopRotation}
|
||||
var namelen = ReadInt(obj.acc, 20);
|
||||
if (obj.acc.length < 24 + namelen) return;
|
||||
cmdsize = 24 + namelen;
|
||||
obj.canvas.canvas.width = obj.rwidth = obj.width = obj.ScreenWidth = ReadShort(obj.acc, 0);
|
||||
obj.canvas.canvas.height = obj.rheight = obj.height = obj.ScreenHeight = ReadShort(obj.acc, 2);
|
||||
|
||||
// These are all values we don't really need, we are going to only run in RGB565 or RGB332 and not use the flexibility provided by these settings.
|
||||
// Makes the javascript code smaller and maybe a bit faster.
|
||||
/*
|
||||
obj.xbpp = obj.acc.charCodeAt(4);
|
||||
obj.depth = obj.acc.charCodeAt(5);
|
||||
obj.bigend = obj.acc.charCodeAt(6);
|
||||
obj.truecolor = obj.acc.charCodeAt(7);
|
||||
obj.rmax = ReadShort(obj.acc, 8);
|
||||
obj.gmax = ReadShort(obj.acc, 10);
|
||||
obj.bmax = ReadShort(obj.acc, 12);
|
||||
obj.rsh = obj.acc.charCodeAt(14);
|
||||
obj.gsh = obj.acc.charCodeAt(15);
|
||||
obj.bsh = obj.acc.charCodeAt(16);
|
||||
var name = obj.acc.substring(24, 24 + namelen);
|
||||
obj.Debug("name: " + name);
|
||||
obj.Debug("width: " + obj.width + ", height: " + obj.height);
|
||||
obj.Debug("bits-per-pixel: " + obj.xbpp);
|
||||
obj.Debug("depth: " + obj.depth);
|
||||
obj.Debug("big-endian-flag: " + obj.bigend);
|
||||
obj.Debug("true-colour-flag: " + obj.truecolor);
|
||||
obj.Debug("rgb max: " + obj.rmax + "," + obj.gmax + "," + obj.bmax);
|
||||
obj.Debug("rgb shift: " + obj.rsh + "," + obj.gsh + "," + obj.bsh);
|
||||
*/
|
||||
|
||||
// SetEncodings, with AMT we can't omit RAW, must be specified.
|
||||
// Intel AMT supports encodings: RAW (0), ZRLE (16), Desktop Size (0xFFFFFF21, -223)
|
||||
|
||||
var supportedEncodings = '';
|
||||
if (obj.useZRLE) supportedEncodings += IntToStr(16);
|
||||
supportedEncodings += IntToStr(0);
|
||||
// ###BEGIN###{DesktopInband}
|
||||
supportedEncodings += IntToStr(1092);
|
||||
// ###END###{DesktopInband}
|
||||
|
||||
obj.send(String.fromCharCode(2, 0) + ShortToStr((supportedEncodings.length / 4) + 1) + supportedEncodings + IntToStr(-223)); // Supported Encodings + Desktop Size
|
||||
|
||||
// Set the pixel encoding to something much smaller
|
||||
// obj.send(String.fromCharCode(0, 0, 0, 0, 16, 16, 0, 1) + ShortToStr(31) + ShortToStr(63) + ShortToStr(31) + String.fromCharCode(11, 5, 0, 0, 0, 0)); // Setup 16 bit color RGB565 (This is the default, so we don't need to set it)
|
||||
if (obj.bpp == 1) obj.send(String.fromCharCode(0, 0, 0, 0, 8, 8, 0, 1) + ShortToStr(7) + ShortToStr(7) + ShortToStr(3) + String.fromCharCode(5, 2, 0, 0, 0, 0)); // Setup 8 bit color RGB332
|
||||
|
||||
obj.state = 4;
|
||||
obj.parent.xxStateChange(3);
|
||||
_SendRefresh();
|
||||
//obj.timer = setInterval(obj.xxOnTimer, 50);
|
||||
|
||||
// ###BEGIN###{DesktopFocus}
|
||||
obj.ox = -1; // Old mouse x position
|
||||
// ###END###{DesktopFocus}
|
||||
|
||||
if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
|
||||
}
|
||||
else if (obj.state == 4) {
|
||||
switch (obj.acc.charCodeAt(0)) {
|
||||
case 0: // FramebufferUpdate
|
||||
if (obj.acc.length < 4) return;
|
||||
obj.state = 100 + ReadShort(obj.acc, 2); // Read the number of tiles that are going to be sent, add 100 and use that as our protocol state.
|
||||
cmdsize = 4;
|
||||
break;
|
||||
case 2: // This is the bell, do nothing.
|
||||
cmdsize = 1;
|
||||
break;
|
||||
case 3: // This is ServerCutText
|
||||
if (obj.acc.length < 8) return;
|
||||
var len = ReadInt(obj.acc, 4) + 8;
|
||||
if (obj.acc.length < len) return;
|
||||
cmdsize = handleServerCutText(obj.acc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (obj.state > 100 && obj.acc.length >= 12) {
|
||||
var x = ReadShort(obj.acc, 0),
|
||||
y = ReadShort(obj.acc, 2),
|
||||
width = ReadShort(obj.acc, 4),
|
||||
height = ReadShort(obj.acc, 6),
|
||||
s = width * height,
|
||||
encoding = ReadInt(obj.acc, 8);
|
||||
|
||||
if (encoding < 17) {
|
||||
if (width < 1 || width > 64 || height < 1 || height > 64) { console.log("Invalid tile size (" + width + "," + height + "), disconnecting."); return obj.Stop(); }
|
||||
|
||||
// Set the spare bitmap to the rigth size if it's not already. This allows us to recycle the spare most if not all the time.
|
||||
if (obj.sparew != width || obj.spareh != height) {
|
||||
obj.sparew = obj.sparew2 = width;
|
||||
obj.spareh = obj.spareh2 = height;
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
if (obj.rotation == 1 || obj.rotation == 3) { obj.sparew2 = height, obj.spareh2 = width; }
|
||||
// ###END###{DesktopRotation}
|
||||
var xspacecachename = obj.sparew2 + 'x' + obj.spareh2;
|
||||
obj.spare = obj.sparecache[xspacecachename];
|
||||
if (!obj.spare) { obj.sparecache[xspacecachename] = obj.spare = obj.canvas.createImageData(obj.sparew2, obj.spareh2); }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (encoding == 0xFFFFFF21) {
|
||||
// Desktop Size (0xFFFFFF21, -223)
|
||||
obj.canvas.canvas.width = obj.rwidth = obj.width = width;
|
||||
obj.canvas.canvas.height = obj.rheight = obj.height = height;
|
||||
obj.send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest
|
||||
cmdsize = 12;
|
||||
if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); }
|
||||
// obj.Debug("New desktop width: " + obj.width + ", height: " + obj.height);
|
||||
}
|
||||
else if (encoding == 0) {
|
||||
// RAW encoding
|
||||
var ptr = 12, cs = 12 + (s * obj.bpp);
|
||||
if (obj.acc.length < cs) return; // Check we have all the data needed and we can only draw 64x64 tiles.
|
||||
cmdsize = cs;
|
||||
|
||||
// CRITICAL LOOP, optimize this as much as possible
|
||||
for (var i = 0; i < s; i++) { _setPixel(obj.acc.charCodeAt(ptr++) + ((obj.bpp == 2) ? (obj.acc.charCodeAt(ptr++) << 8) : 0), i); }
|
||||
_putImage(obj.spare, x, y);
|
||||
}
|
||||
else if (encoding == 16) {
|
||||
// ZRLE encoding
|
||||
if (obj.acc.length < 16) return;
|
||||
var datalen = ReadInt(obj.acc, 12);
|
||||
if (obj.acc.length < (16 + datalen)) return;
|
||||
//obj.Debug("RECT ZRLE (" + x + "," + y + "," + width + "," + height + ") LEN = " + datalen);
|
||||
//obj.Debug("RECT ZRLE LEN: " + ReadShortX(obj.acc, 17) + ", DATA: " + rstr2hex(obj.acc.substring(16)));
|
||||
|
||||
// Process the ZLib header if this is the first block
|
||||
var ptr = 16, delta = 5, dx = 0;
|
||||
|
||||
if (datalen > 5 && obj.acc.charCodeAt(ptr) == 0 && ReadShortX(obj.acc, ptr + 1) == (datalen - delta)) {
|
||||
// This is an uncompressed ZLib data block
|
||||
_decodeLRE(obj.acc, ptr + 5, x, y, width, height, s, datalen);
|
||||
}
|
||||
// ###BEGIN###{Inflate}
|
||||
else {
|
||||
// This is compressed ZLib data, decompress and process it.
|
||||
var arr = obj.inflate.inflate(obj.acc.substring(ptr, ptr + datalen - dx));
|
||||
if (arr.length > 0) { _decodeLRE(arr, 0, x, y, width, height, s, arr.length); } else { obj.Debug("Invalid deflate data"); }
|
||||
}
|
||||
// ###END###{Inflate}
|
||||
|
||||
cmdsize = 16 + datalen;
|
||||
}
|
||||
else {
|
||||
obj.Debug("Unknown Encoding: " + encoding);
|
||||
return obj.Stop();
|
||||
}
|
||||
if (--obj.state == 100) {
|
||||
obj.state = 4;
|
||||
if (obj.frameRateDelay == 0) {
|
||||
_SendRefresh(); // Ask for new frame
|
||||
} else {
|
||||
setTimeout(_SendRefresh, obj.frameRateDelay); // Hold x miliseconds before asking for a new frame
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cmdsize == 0) return;
|
||||
obj.acc = obj.acc.substring(cmdsize);
|
||||
}
|
||||
}
|
||||
|
||||
function _decodeLRE(data, ptr, x, y, width, height, s, datalen) {
|
||||
var subencoding = data.charCodeAt(ptr++), index, v, runlengthdecode, palette = {}, rlecount = 0, runlength = 0, i;
|
||||
// obj.Debug("RECT RLE (" + (datalen - 5) + ", " + subencoding + "):" + rstr2hex(data.substring(21, 21 + (datalen - 5))));
|
||||
if (subencoding == 0) {
|
||||
// RAW encoding
|
||||
for (i = 0; i < s; i++) { _setPixel(data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0), i); }
|
||||
_putImage(obj.spare, x, y);
|
||||
}
|
||||
else if (subencoding == 1) {
|
||||
// Solid color tile
|
||||
v = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0);
|
||||
obj.canvas.fillStyle = 'rgb(' + ((obj.bpp == 1) ? ((v & 224) + ',' + ((v & 28) << 3) + ',' + _fixColor((v & 3) << 6)) : (((v >> 8) & 248) + ',' + ((v >> 3) & 252) + ',' + ((v & 31) << 3))) + ')';
|
||||
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
var xx = _rotX(x, y);
|
||||
y = _rotY(x, y);
|
||||
x = xx;
|
||||
// ###END###{DesktopRotation}
|
||||
|
||||
obj.canvas.fillRect(x, y, width, height);
|
||||
}
|
||||
else if (subencoding > 1 && subencoding < 17) { // Packed palette encoded tile
|
||||
// Read the palette
|
||||
var br = 4, bm = 15; // br is BitRead and bm is BitMask. By adjusting these two we can support all the variations in this encoding.
|
||||
for (i = 0; i < subencoding; i++) { palette[i] = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0); }
|
||||
|
||||
// Compute bits to read & bit mark
|
||||
if (subencoding == 2) { br = 1; bm = 1; } else if (subencoding <= 4) { br = 2; bm = 3; }
|
||||
|
||||
// Display all the bits
|
||||
while (rlecount < s && ptr < data.length) { v = data.charCodeAt(ptr++); for (i = (8 - br) ; i >= 0; i -= br) { _setPixel(palette[(v >> i) & bm], rlecount++); } }
|
||||
_putImage(obj.spare, x, y);
|
||||
}
|
||||
else if (subencoding == 128) { // RLE encoded tile
|
||||
while (rlecount < s && ptr < data.length) {
|
||||
// Get the run color
|
||||
v = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0);
|
||||
|
||||
// Decode the run length. This is the fastest and most compact way I found to do this.
|
||||
runlength = 1; do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255);
|
||||
|
||||
// Draw a run
|
||||
while (--runlength >= 0) { _setPixel(v, rlecount++); }
|
||||
}
|
||||
_putImage(obj.spare, x, y);
|
||||
}
|
||||
else if (subencoding > 129) { // Palette RLE encoded tile
|
||||
// Read the palette
|
||||
for (i = 0; i < (subencoding - 128) ; i++) { palette[i] = data.charCodeAt(ptr++) + ((obj.bpp == 2) ? (data.charCodeAt(ptr++) << 8) : 0); }
|
||||
|
||||
// Decode RLE on palette
|
||||
while (rlecount < s && ptr < data.length) {
|
||||
// Setup the run, get the color index and get the color from the palette.
|
||||
runlength = 1; index = data.charCodeAt(ptr++); v = palette[index % 128];
|
||||
|
||||
// If the index starts with high order bit 1, this is a run and decode the run length.
|
||||
if (index > 127) { do { runlength += (runlengthdecode = data.charCodeAt(ptr++)); } while (runlengthdecode == 255); }
|
||||
|
||||
// Draw a run
|
||||
while (--runlength >= 0) { _setPixel(v, rlecount++); }
|
||||
}
|
||||
_putImage(obj.spare, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
// ###BEGIN###{DesktopInband}
|
||||
obj.hold = function (holding) {
|
||||
if (obj.holding == holding) return;
|
||||
obj.holding = holding;
|
||||
obj.canvas.fillStyle = '#000000';
|
||||
obj.canvas.fillRect(0, 0, obj.width, obj.height); // Paint black
|
||||
if (obj.holding == false) {
|
||||
// Go back to normal operations
|
||||
// Set canvas size and ask for full screen refresh
|
||||
if ((obj.canvas.canvas.width != obj.width) || (obj.canvas.canvas.height != obj.height)) {
|
||||
obj.canvas.canvas.width = obj.width; obj.canvas.canvas.height = obj.height;
|
||||
if (obj.onScreenSizeChange != null) { obj.onScreenSizeChange(obj, obj.ScreenWidth, obj.ScreenHeight); } // ???
|
||||
}
|
||||
obj.Send(String.fromCharCode(3, 0, 0, 0, 0, 0) + ShortToStr(obj.width) + ShortToStr(obj.height)); // FramebufferUpdateRequest
|
||||
} else {
|
||||
obj.UnGrabMouseInput();
|
||||
obj.UnGrabKeyInput();
|
||||
}
|
||||
}
|
||||
// ###END###{DesktopInband}
|
||||
|
||||
function _putImage(i, x, y) {
|
||||
// ###BEGIN###{DesktopInband}
|
||||
if (obj.holding == true) return;
|
||||
// ###END###{DesktopInband}
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
var xx = _arotX(x, y);
|
||||
y = _arotY(x, y);
|
||||
x = xx;
|
||||
// ###END###{DesktopRotation}
|
||||
obj.canvas.putImageData(i, x, y);
|
||||
}
|
||||
|
||||
function _setPixel(v, p) {
|
||||
var pp = p * 4;
|
||||
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
if (obj.rotation > 0) {
|
||||
if (obj.rotation == 1) {
|
||||
var x = p % obj.sparew;
|
||||
var y = Math.floor(p / obj.sparew);
|
||||
p = (x * obj.sparew2) + (obj.sparew2 - 1 - y);
|
||||
pp = p * 4;
|
||||
}
|
||||
else if (obj.rotation == 2) { pp = (obj.sparew * obj.spareh * 4) - 4 - pp; }
|
||||
else if (obj.rotation == 3) {
|
||||
var x = p % obj.sparew;
|
||||
var y = Math.floor(p / obj.sparew);
|
||||
p = ((obj.sparew2 - 1 - x) * obj.sparew2) + (y);
|
||||
pp = p * 4;
|
||||
}
|
||||
}
|
||||
// ###END###{DesktopRotation}
|
||||
|
||||
if (obj.bpp == 1) {
|
||||
// Set 8bit color RGB332
|
||||
obj.spare.data[pp++] = v & 224;
|
||||
obj.spare.data[pp++] = (v & 28) << 3;
|
||||
obj.spare.data[pp++] = _fixColor((v & 3) << 6);
|
||||
} else {
|
||||
// Set 16bit color RGB565
|
||||
obj.spare.data[pp++] = (v >> 8) & 248;
|
||||
obj.spare.data[pp++] = (v >> 3) & 252;
|
||||
obj.spare.data[pp++] = (v & 31) << 3;
|
||||
}
|
||||
obj.spare.data[pp] = 0xFF; // Set alpha channel to opaque.
|
||||
}
|
||||
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
function _arotX(x, y) {
|
||||
if (obj.rotation == 0) return x;
|
||||
if (obj.rotation == 1) return obj.canvas.canvas.width - obj.sparew2 - y;
|
||||
if (obj.rotation == 2) return obj.canvas.canvas.width - obj.sparew2 - x;
|
||||
if (obj.rotation == 3) return y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _arotY(x, y) {
|
||||
if (obj.rotation == 0) return y;
|
||||
if (obj.rotation == 1) return x;
|
||||
if (obj.rotation == 2) return obj.canvas.canvas.height - obj.spareh2 - y;
|
||||
if (obj.rotation == 3) return obj.canvas.canvas.height - obj.spareh - x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _crotX(x, y) {
|
||||
if (obj.rotation == 0) return x;
|
||||
if (obj.rotation == 1) return y;
|
||||
if (obj.rotation == 2) return obj.canvas.canvas.width - x;
|
||||
if (obj.rotation == 3) return obj.canvas.canvas.height - y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _crotY(x, y) {
|
||||
if (obj.rotation == 0) return y;
|
||||
if (obj.rotation == 1) return obj.canvas.canvas.width - x;
|
||||
if (obj.rotation == 2) return obj.canvas.canvas.height - y;
|
||||
if (obj.rotation == 3) return x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _rotX(x, y) {
|
||||
if (obj.rotation == 0) return x;
|
||||
if (obj.rotation == 1) return x;
|
||||
if (obj.rotation == 2) return x - obj.canvas.canvas.width;
|
||||
if (obj.rotation == 3) return x - obj.canvas.canvas.height;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function _rotY(x, y) {
|
||||
if (obj.rotation == 0) return y;
|
||||
if (obj.rotation == 1) return y - obj.canvas.canvas.width;
|
||||
if (obj.rotation == 2) return y - obj.canvas.canvas.height;
|
||||
if (obj.rotation == 3) return y;
|
||||
return 0;
|
||||
}
|
||||
|
||||
obj.tcanvas = null;
|
||||
obj.setRotation = function (x) {
|
||||
while (x < 0) { x += 4; }
|
||||
var newrotation = x % 4;
|
||||
//console.log('hard-rot: ' + newrotation);
|
||||
// ###BEGIN###{DesktopInband}
|
||||
if (obj.holding == true) { obj.rotation = newrotation; return; }
|
||||
// ###END###{DesktopInband}
|
||||
|
||||
if (newrotation == obj.rotation) return true;
|
||||
var rw = obj.canvas.canvas.width;
|
||||
var rh = obj.canvas.canvas.height;
|
||||
if (obj.rotation == 1 || obj.rotation == 3) { rw = obj.canvas.canvas.height; rh = obj.canvas.canvas.width; }
|
||||
|
||||
// Copy the canvas, put it back in the correct direction
|
||||
if (obj.tcanvas == null) obj.tcanvas = document.createElement('canvas');
|
||||
var tcanvasctx = obj.tcanvas.getContext('2d');
|
||||
tcanvasctx.setTransform(1, 0, 0, 1, 0, 0);
|
||||
tcanvasctx.canvas.width = rw;
|
||||
tcanvasctx.canvas.height = rh;
|
||||
tcanvasctx.rotate((obj.rotation * -90) * Math.PI / 180);
|
||||
if (obj.rotation == 0) tcanvasctx.drawImage(obj.canvas.canvas, 0, 0);
|
||||
if (obj.rotation == 1) tcanvasctx.drawImage(obj.canvas.canvas, -obj.canvas.canvas.width, 0);
|
||||
if (obj.rotation == 2) tcanvasctx.drawImage(obj.canvas.canvas, -obj.canvas.canvas.width, -obj.canvas.canvas.height);
|
||||
if (obj.rotation == 3) tcanvasctx.drawImage(obj.canvas.canvas, 0, -obj.canvas.canvas.height);
|
||||
|
||||
// Change the size and orientation and copy the canvas back into the rotation
|
||||
if (obj.rotation == 0 || obj.rotation == 2) { obj.canvas.canvas.height = rw; obj.canvas.canvas.width = rh; }
|
||||
if (obj.rotation == 1 || obj.rotation == 3) { obj.canvas.canvas.height = rh; obj.canvas.canvas.width = rw; }
|
||||
obj.canvas.setTransform(1, 0, 0, 1, 0, 0);
|
||||
obj.canvas.rotate((newrotation * 90) * Math.PI / 180);
|
||||
obj.rotation = newrotation;
|
||||
obj.canvas.drawImage(obj.tcanvas, _rotX(0, 0), _rotY(0, 0));
|
||||
|
||||
obj.width = obj.canvas.canvas.width;
|
||||
obj.height = obj.canvas.canvas.height;
|
||||
if (obj.onScreenResize != null) obj.onScreenResize(obj, obj.width, obj.height, obj.CanvasId);
|
||||
return true;
|
||||
}
|
||||
// ###END###{DesktopRotation}
|
||||
|
||||
function _fixColor(c) { return (c > 127) ? (c + 32) : c; }
|
||||
|
||||
function _SendRefresh() {
|
||||
// ###BEGIN###{DesktopInband}
|
||||
if (obj.holding == true) return;
|
||||
// ###END###{DesktopInband}
|
||||
// ###BEGIN###{DesktopFocus}
|
||||
if (obj.focusmode > 0) {
|
||||
// Request only pixels around the last mouse position
|
||||
var df = obj.focusmode * 2;
|
||||
obj.send(String.fromCharCode(3, 1) + ShortToStr(Math.max(Math.min(obj.ox, obj.mx) - obj.focusmode, 0)) + ShortToStr(Math.max(Math.min(obj.oy, obj.my) - obj.focusmode, 0)) + ShortToStr(df + Math.abs(obj.ox - obj.mx)) + ShortToStr(df + Math.abs(obj.oy - obj.my))); // FramebufferUpdateRequest
|
||||
obj.ox = obj.mx;
|
||||
obj.oy = obj.my;
|
||||
} else {
|
||||
// ###END###{DesktopFocus}
|
||||
// Request the entire screen
|
||||
obj.send(String.fromCharCode(3, 1, 0, 0, 0, 0) + ShortToStr(obj.rwidth) + ShortToStr(obj.rheight)); // FramebufferUpdateRequest
|
||||
// ###BEGIN###{DesktopFocus}
|
||||
}
|
||||
// ###END###{DesktopFocus}
|
||||
}
|
||||
|
||||
obj.Start = function () {
|
||||
//obj.Debug("KVM-Start");
|
||||
obj.state = 0;
|
||||
obj.acc = "";
|
||||
obj.ZRLEfirst = 1;
|
||||
//obj.inbytes = 0;
|
||||
//obj.outbytes = 0;
|
||||
// ###BEGIN###{Inflate}
|
||||
obj.inflate.inflateReset();
|
||||
// ###END###{Inflate}
|
||||
// ###BEGIN###{DesktopInband}
|
||||
obj.onKvmDataPending = [];
|
||||
obj.onKvmDataAck = -1;
|
||||
obj.kvmDataSupported = false;
|
||||
// ###END###{DesktopInband}
|
||||
for (var i in obj.sparecache) { delete obj.sparecache[i]; }
|
||||
}
|
||||
|
||||
obj.Stop = function () {
|
||||
obj.UnGrabMouseInput();
|
||||
obj.UnGrabKeyInput();
|
||||
obj.parent.Stop();
|
||||
}
|
||||
|
||||
obj.send = function (x) {
|
||||
//obj.Debug("KSend(" + x.length + "): " + rstr2hex(x));
|
||||
//obj.outbytes += x.length;
|
||||
obj.parent.send(x);
|
||||
}
|
||||
|
||||
var convertAmtKeyCodeTable = {
|
||||
"Pause": 19,
|
||||
"CapsLock": 20,
|
||||
"Space": 32,
|
||||
"Quote": 39,
|
||||
"Minus": 45,
|
||||
"NumpadMultiply": 42,
|
||||
"NumpadAdd": 43,
|
||||
"PrintScreen": 44,
|
||||
"Comma": 44,
|
||||
"NumpadSubtract": 45,
|
||||
"NumpadDecimal": 46,
|
||||
"Period": 46,
|
||||
"Slash": 47,
|
||||
"NumpadDivide": 47,
|
||||
"Semicolon": 59,
|
||||
"Equal": 61,
|
||||
"OSLeft": 91,
|
||||
"BracketLeft": 91,
|
||||
"OSRight": 91,
|
||||
"Backslash": 92,
|
||||
"BracketRight": 93,
|
||||
"ContextMenu": 93,
|
||||
"Backquote": 96,
|
||||
"NumLock": 144,
|
||||
"ScrollLock": 145,
|
||||
"Backspace": 0xff08,
|
||||
"Tab": 0xff09,
|
||||
"Enter": 0xff0d,
|
||||
"NumpadEnter": 0xff0d,
|
||||
"Escape": 0xff1b,
|
||||
"Delete": 0xffff,
|
||||
"Home": 0xff50,
|
||||
"PageUp": 0xff55,
|
||||
"PageDown": 0xff56,
|
||||
"ArrowLeft": 0xff51,
|
||||
"ArrowUp": 0xff52,
|
||||
"ArrowRight": 0xff53,
|
||||
"ArrowDown": 0xff54,
|
||||
"End": 0xff57,
|
||||
"Insert": 0xff63,
|
||||
"F1": 0xffbe,
|
||||
"F2": 0xffbf,
|
||||
"F3": 0xffc0,
|
||||
"F4": 0xffc1,
|
||||
"F5": 0xffc2,
|
||||
"F6": 0xffc3,
|
||||
"F7": 0xffc4,
|
||||
"F8": 0xffc5,
|
||||
"F9": 0xffc6,
|
||||
"F10": 0xffc7,
|
||||
"F11": 0xffc8,
|
||||
"F12": 0xffc9,
|
||||
"ShiftLeft": 0xffe1,
|
||||
"ShiftRight": 0xffe2,
|
||||
"ControlLeft": 0xffe3,
|
||||
"ControlRight": 0xffe4,
|
||||
"AltLeft": 0xffe9,
|
||||
"AltRight": 0xffea,
|
||||
"MetaLeft": 0xffe7,
|
||||
"MetaRight": 0xffe8
|
||||
}
|
||||
function convertAmtKeyCode(e) {
|
||||
if (e.code.startsWith('Key') && e.code.length == 4) { return e.code.charCodeAt(3) + ((e.shiftKey == false) ? 32 : 0); }
|
||||
if (e.code.startsWith('Digit') && e.code.length == 6) { return e.code.charCodeAt(5); }
|
||||
if (e.code.startsWith('Numpad') && e.code.length == 7) { return e.code.charCodeAt(6); }
|
||||
return convertAmtKeyCodeTable[e.code];
|
||||
}
|
||||
|
||||
/*
|
||||
Intel AMT only recognizes a small subset of keysym characters defined in the keysymdef.h so you don’t need to
|
||||
implement all the languages (this is taken care by the USB Scancode Extension in RFB4.0 protocol).
|
||||
The only subset recognized by the FW is the defined by the following sets : XK_LATIN1 , XK_MISCELLANY, XK_3270, XK_XKB_KEYS, XK_KATAKANA.
|
||||
In addition to keysymdef.h symbols there are 6 japanese extra keys that we do support:
|
||||
|
||||
#define XK_Intel_EU_102kbd_backslash_pipe_45 0x17170056 // European 102-key: 45 (backslash/pipe), usb Usage: 0x64
|
||||
#define XK_Intel_JP_106kbd_yen_pipe 0x1717007d // Japanese 106-key: 14 (Yen/pipe), usb Usage: 0x89
|
||||
#define XK_Intel_JP_106kbd_backslash_underbar 0x17170073 // Japanese 106-key: 56 (backslash/underbar), usb Usage: 0x87
|
||||
#define XK_Intel_JP_106kbd_NoConvert 0x1717007b // Japanese 106-key: 131 (NoConvert), usb Usage: 0x8b
|
||||
#define XK_Intel_JP_106kbd_Convert 0x17170079 // Japanese 106-key: 132 (Convert), usb Usage: 0x8a
|
||||
#define XK_Intel_JP_106kbd_Hirigana_Katakana 0x17170070 // Japanese 106-key: 133 (Hirigana/Katakana), usb Usage: 0x88
|
||||
*/
|
||||
|
||||
function _keyevent(d, e) {
|
||||
if (!e) { e = window.event; }
|
||||
|
||||
if (e.code && (obj.localKeyMap == false)) {
|
||||
// For new browsers, this mapping is keyboard language independent
|
||||
var k = convertAmtKeyCode(e);
|
||||
if (k != null) { obj.sendkey(k, d); }
|
||||
} else {
|
||||
// For older browsers, this mapping works best for EN-US keyboard
|
||||
var k = e.keyCode, kk = k;
|
||||
if (e.shiftKey == false && k >= 65 && k <= 90) kk = k + 32;
|
||||
if (k >= 112 && k <= 124) kk = k + 0xFF4E;
|
||||
if (k == 8) kk = 0xff08; // Backspace
|
||||
if (k == 9) kk = 0xff09; // Tab
|
||||
if (k == 13) kk = 0xff0d; // Return
|
||||
if (k == 16) kk = 0xffe1; // Shift (Left)
|
||||
if (k == 17) kk = 0xffe3; // Ctrl (Left)
|
||||
if (k == 18) kk = 0xffe9; // Alt (Left)
|
||||
if (k == 27) kk = 0xff1b; // ESC
|
||||
if (k == 33) kk = 0xff55; // PageUp
|
||||
if (k == 34) kk = 0xff56; // PageDown
|
||||
if (k == 35) kk = 0xff57; // End
|
||||
if (k == 36) kk = 0xff50; // Home
|
||||
if (k == 37) kk = 0xff51; // Left
|
||||
if (k == 38) kk = 0xff52; // Up
|
||||
if (k == 39) kk = 0xff53; // Right
|
||||
if (k == 40) kk = 0xff54; // Down
|
||||
if (k == 45) kk = 0xff63; // Insert
|
||||
if (k == 46) kk = 0xffff; // Delete
|
||||
if (k >= 96 && k <= 105) kk = k - 48; // Key pad numbers
|
||||
if (k == 106) kk = 42; // Pad *
|
||||
if (k == 107) kk = 43; // Pad +
|
||||
if (k == 109) kk = 45; // Pad -
|
||||
if (k == 110) kk = 46; // Pad .
|
||||
if (k == 111) kk = 47; // Pad /
|
||||
if (k == 186) kk = 59; // ;
|
||||
if (k == 187) kk = 61; // =
|
||||
if (k == 188) kk = 44; // ,
|
||||
if (k == 189) kk = 45; // -
|
||||
if (k == 190) kk = 46; // .
|
||||
if (k == 191) kk = 47; // /
|
||||
if (k == 192) kk = 96; // `
|
||||
if (k == 219) kk = 91; // [
|
||||
if (k == 220) kk = 92; // \
|
||||
if (k == 221) kk = 93; // ]t
|
||||
if (k == 222) kk = 39; // '
|
||||
//console.log('Key' + d + ": " + k + " = " + kk);
|
||||
obj.sendkey(kk, d);
|
||||
}
|
||||
return obj.haltEvent(e);
|
||||
}
|
||||
|
||||
obj.sendkey = function (k, d) {
|
||||
if (typeof k == 'object') { for (var i in k) { obj.sendkey(k[i][0], k[i][1]); } }
|
||||
else { obj.send(String.fromCharCode(4, d, 0, 0) + IntToStr(k)); }
|
||||
}
|
||||
|
||||
function handleServerCutText(acc) {
|
||||
if (acc.length < 8) return 0;
|
||||
var len = ReadInt(obj.acc, 4) + 8;
|
||||
if (acc.length < len) return 0;
|
||||
// ###BEGIN###{DesktopInband}
|
||||
if (obj.onKvmData != null) {
|
||||
var d = acc.substring(8, len);
|
||||
if ((d.length >= 16) && (d.substring(0, 15) == '\0KvmDataChannel')) {
|
||||
if (obj.kvmDataSupported == false) { obj.kvmDataSupported = true; console.log('KVM Data Channel Supported.'); }
|
||||
if (((obj.onKvmDataAck == -1) && (d.length == 16)) || (d.charCodeAt(15) != 0)) { obj.onKvmDataAck = true; }
|
||||
//if (urlvars && urlvars['kvmdatatrace']) { console.log('KVM-Recv(' + (d.length - 16) + '): ' + d.substring(16)); }
|
||||
if (d.length >= 16) { obj.onKvmData(d.substring(16)); } // Event the data and ack
|
||||
if ((obj.onKvmDataAck == true) && (obj.onKvmDataPending.length > 0)) { obj.sendKvmData(obj.onKvmDataPending.shift()); } // Send pending data
|
||||
}
|
||||
}
|
||||
// ###END###{DesktopInband}
|
||||
return len;
|
||||
}
|
||||
|
||||
// ###BEGIN###{DesktopInband}
|
||||
obj.sendKvmData = function (x) {
|
||||
if (obj.onKvmDataAck !== true) {
|
||||
obj.onKvmDataPending.push(x);
|
||||
} else {
|
||||
//if (urlvars && urlvars['kvmdatatrace']) { console.log('KVM-Send(' + x.length + '): ' + x); }
|
||||
x = '\0KvmDataChannel\0' + x;
|
||||
obj.send(String.fromCharCode(6, 0, 0, 0) + IntToStr(x.length) + x);
|
||||
obj.onKvmDataAck = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Send a HWKVM keep alive if it's not been sent in the last 5 seconds.
|
||||
obj.sendKeepAlive = function () {
|
||||
if (obj.lastKeepAlive < Date.now() - 5000) { obj.lastKeepAlive = Date.now(); obj.send(String.fromCharCode(6, 0, 0, 0) + IntToStr(16) + '\0KvmDataChannel\0'); }
|
||||
}
|
||||
// ###END###{DesktopInband}
|
||||
|
||||
obj.SendCtrlAltDelMsg = function () { obj.sendcad(); }
|
||||
obj.sendcad = function () { obj.sendkey([[0xFFE3, 1], [0xFFE9, 1], [0xFFFF, 1], [0xFFFF, 0], [0xFFE9, 0], [0xFFE3, 0]]); } // Control down, Alt down, Delete down, Delete up , Alt up , Control up
|
||||
|
||||
var _MouseInputGrab = false;
|
||||
var _KeyInputGrab = false;
|
||||
|
||||
obj.GrabMouseInput = function () {
|
||||
if (_MouseInputGrab == true) return;
|
||||
var c = obj.canvas.canvas;
|
||||
c.onmouseup = obj.mouseup;
|
||||
c.onmousedown = obj.mousedown;
|
||||
c.onmousemove = obj.mousemove;
|
||||
//if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = obj.xxDOMMouseScroll; else c.onmousewheel = obj.xxMouseWheel;
|
||||
_MouseInputGrab = true;
|
||||
}
|
||||
|
||||
obj.UnGrabMouseInput = function () {
|
||||
if (_MouseInputGrab == false) return;
|
||||
var c = obj.canvas.canvas;
|
||||
c.onmousemove = null;
|
||||
c.onmouseup = null;
|
||||
c.onmousedown = null;
|
||||
//if (navigator.userAgent.match(/mozilla/i)) c.DOMMouseScroll = null; else c.onmousewheel = null;
|
||||
_MouseInputGrab = false;
|
||||
}
|
||||
|
||||
obj.GrabKeyInput = function () {
|
||||
if (_KeyInputGrab == true) return;
|
||||
document.onkeyup = obj.handleKeyUp;
|
||||
document.onkeydown = obj.handleKeyDown;
|
||||
document.onkeypress = obj.handleKeys;
|
||||
_KeyInputGrab = true;
|
||||
}
|
||||
|
||||
obj.UnGrabKeyInput = function () {
|
||||
if (_KeyInputGrab == false) return;
|
||||
document.onkeyup = null;
|
||||
document.onkeydown = null;
|
||||
document.onkeypress = null;
|
||||
_KeyInputGrab = false;
|
||||
}
|
||||
|
||||
obj.handleKeys = function (e) { return obj.haltEvent(e); }
|
||||
obj.handleKeyUp = function (e) { return _keyevent(0, e); }
|
||||
obj.handleKeyDown = function (e) { return _keyevent(1, e); }
|
||||
obj.haltEvent = function (e) { if (e.preventDefault) e.preventDefault(); if (e.stopPropagation) e.stopPropagation(); return false; }
|
||||
|
||||
// RFB "PointerEvent" and mouse handlers
|
||||
obj.mousedblclick = function (e) { }
|
||||
obj.mousedown = function (e) { obj.buttonmask |= (1 << e.button); return obj.mousemove(e); }
|
||||
obj.mouseup = function (e) { obj.buttonmask &= (0xFFFF - (1 << e.button)); return obj.mousemove(e); }
|
||||
obj.mousemove = function (e) {
|
||||
if (obj.state != 4) return true;
|
||||
var ScaleFactorHeight = (obj.canvas.canvas.height / Q(obj.canvasid).offsetHeight);
|
||||
var ScaleFactorWidth = (obj.canvas.canvas.width / Q(obj.canvasid).offsetWidth);
|
||||
var Offsets = obj.getPositionOfControl(Q(obj.canvasid));
|
||||
obj.mx = ((event.pageX - Offsets[0]) * ScaleFactorWidth);
|
||||
obj.my = ((event.pageY - Offsets[1]) * ScaleFactorHeight);
|
||||
if (event.addx) { obj.mx += event.addx; }
|
||||
if (event.addy) { obj.my += event.addy; }
|
||||
|
||||
// ###BEGIN###{DesktopRotation}
|
||||
if (obj.noMouseRotate != true) {
|
||||
obj.mx2 = _crotX(obj.mx, obj.my);
|
||||
obj.my = _crotY(obj.mx, obj.my);
|
||||
obj.mx = obj.mx2;
|
||||
}
|
||||
// ###END###{DesktopRotation}
|
||||
|
||||
obj.send(String.fromCharCode(5, obj.buttonmask) + ShortToStr(obj.mx) + ShortToStr(obj.my));
|
||||
|
||||
// ###BEGIN###{DesktopFocus}
|
||||
// Update focus area if we are in focus mode
|
||||
QV('DeskFocus', obj.focusmode);
|
||||
if (obj.focusmode != 0) {
|
||||
var x = Math.min(obj.mx, obj.canvas.canvas.width - obj.focusmode),
|
||||
y = Math.min(obj.my, obj.canvas.canvas.height - obj.focusmode),
|
||||
df = obj.focusmode * 2,
|
||||
c = Q(obj.canvasid),
|
||||
qx = c.offsetHeight / obj.canvas.canvas.height,
|
||||
qy = c.offsetWidth / obj.canvas.canvas.width,
|
||||
q = QS('DeskFocus'),
|
||||
ppos = obj.getPositionOfControl(Q(obj.canvasid).parentElement);
|
||||
q.left = (Math.max(((x - obj.focusmode) * qx), 0) + (pos[0] - ppos[0])) + 'px';
|
||||
q.top = (Math.max(((y - obj.focusmode) * qy), 0) + (pos[1] - ppos[1])) + 'px';
|
||||
q.width = ((df * qx) - 6) + 'px';
|
||||
q.height = ((df * qx) - 6) + 'px';
|
||||
}
|
||||
// ###END###{DesktopFocus}
|
||||
|
||||
return obj.haltEvent(e);
|
||||
}
|
||||
|
||||
obj.getPositionOfControl = function (Control) {
|
||||
var Position = Array(2);
|
||||
Position[0] = Position[1] = 0;
|
||||
while (Control) {
|
||||
Position[0] += Control.offsetLeft;
|
||||
Position[1] += Control.offsetTop;
|
||||
Control = Control.offsetParent;
|
||||
}
|
||||
return Position;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
Loading…
Reference in New Issue
Block a user