diff --git a/agents/MeshCmd-signed.exe b/agents/MeshCmd-signed.exe index bb5c6aff..1e726025 100644 Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ diff --git a/agents/MeshCmd64-signed.exe b/agents/MeshCmd64-signed.exe index cf3893d0..f99c19f7 100644 Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ diff --git a/agents/meshcmd.js b/agents/meshcmd.js index 618e9ff0..bdbe7f7c 100644 --- a/agents/meshcmd.js +++ b/agents/meshcmd.js @@ -113,7 +113,7 @@ function run(argv) { //console.log('addedModules = ' + JSON.stringify(addedModules)); var actionpath = 'meshaction.txt'; if (args.actionfile != null) { actionpath = args.actionfile; } - var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTPRESENCE']; + var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTPOWER', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTPRESENCE']; // Load the action file var actionfile = null; @@ -186,6 +186,7 @@ function run(argv) { console.log(' AmtStorageState - Show contents of the Intel AMT web storage.'); console.log(' AmtSaveState - Save all Intel AMT WSMAN object to file.'); console.log(' AmtPresence - Heartbeat a local Intel AMT watchdog agent.'); + console.log(' AmtPower - Perform remote Intel AMT power operation.'); console.log(' AmtScript - Run .mescript on Intel AMT.'); console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log('\r\nHelp on a specific action using:\r\n'); @@ -295,6 +296,15 @@ function run(argv) { console.log(' --user [username] The Intel AMT login username, admin is default.'); console.log(' --pass [password] The Intel AMT login password.'); console.log(' --tls Specifies that TLS must be used.'); + } else if (action == 'amtpower') { + console.log('AmtPower will get current pwoer state or send a reboot command to a remote Intel AMT device. Example usage:\r\n\r\n meshcmd amtpower --reset --host 1.2.3.4 --user admin --pass mypassword --tls'); + console.log('\r\nRequired arguments:\r\n'); + console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.'); + console.log(' --pass [password] The Intel AMT login password.'); + console.log('\r\nOptional arguments:\r\n'); + console.log(' --reset, --poweron, --poweroff, --powercycle, --sleep, --hibernate'); + console.log(' --user [username] The Intel AMT login username, admin is default.'); + console.log(' --tls Specifies that TLS must be used.'); } else if (action == 'meshcommander') { console.log('This action launched a local web server that hosts MeshCommander, a Intel AMT management console.'); console.log('\r\nPossible arguments:\r\n'); @@ -572,6 +582,38 @@ function run(argv) { if ((settings.cdrom == null) || (typeof settings.cdrom != 'string') || (settings.cdrom == '')) { settings.cdrom = null; } if ((settings.floppy == null) && (settings.cdrom == null)) { console.log('No or invalid \"floppy\" or \"cdrom\" specified, use --floppy [file] or --cdrom [file].'); exit(1); return; } performIder(); + } else if (settings.action == 'amtpower') { // Perform remote Intel AMT power operation + if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { console.log('No or invalid \"hostname\" specified, use --hostname [host].'); exit(1); return; } + if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; } + if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; } + + /* + 2 = Power On + 3 = Sleep - Light + 4 = Sleep - Deep + 5 = Power Cycle (Off Soft) + 6 = Power Off - Hard + 7 = Hibernate + 8 = Power Off - Soft + 9 = Power Cycle (Off Hard) + 10 = Master Bus Reset + 11 = Diagnostic Interrupt (NMI) + 12 = Power Off - Soft Graceful + 13 = Power Off - Hard Graceful + 14 = Master Bus Reset Graceful + 15 = Power Cycle (Off - Soft Graceful) + 16 = Power Cycle (Off - Hard Graceful) + */ + + settings.poweraction = 0; + if (args.poweron) { settings.poweraction = 2; } + if (args.sleep) { settings.poweraction = 3; } + if (args.powercycle) { settings.poweraction = 5; } + if (args.poweroff) { settings.poweraction = 6; } + if (args.hibernate) { settings.poweraction = 7; } + if (args.reset) { settings.poweraction = 10; } + //if (settings.poweraction == 0) { console.log('No power action, specify --poweron, --sleep, --powercycle, --poweroff, --hibernate, --reset.'); exit(1); return; } + performAmtPowerAction(); } else { console.log('Invalid \"action\" specified.'); exit(1); return; } @@ -2027,6 +2069,53 @@ function iderSectorStats(mode, dev, mediaBlocks, lba, len) { iderIdleTimer = setTimeout(function () { console.log('Idle timeout'); process.exit(1); }, 1000 * settings.timeout); } + +// +// Intel AMT Remote Power Action +// + +function performAmtPowerAction() { + var transport = require('amt-wsman-duk'); + var wsman = require('amt-wsman'); + var amt = require('amt'); + wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls); + amtstack = new amt(wsstack); + if (settings.poweraction != 0) { + // Set the power state + amtstack.RequestPowerStateChange(settings.poweraction, performAmtPowerActionEx); + } else { + // Get the power state + amtstack.Get("CIM_AssociatedPowerManagementService", performAmtPowerActionEx2, 0, 1); + } +} + +function performAmtPowerActionEx(stack, name, response, status) { + if (status == 200) { + console.log(response.Body.ReturnValueStr.split('_').join(' ')); + process.exit(0); + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + +var DMTFPowerStates = ["", "", "Power on", "Light sleep", "Deep sleep", "Power cycle (Soft off)", "Off - Hard", "Hibernate (Off soft)", "Soft off", "Power cycle (Off-hard)", "Master bus reset", "Diagnostic interrupt (NMI)", "Not applicable", "Off - Soft graceful", "Off - Hard graceful", "Master bus reset graceful", "Power cycle (Off - Soft graceful)", "Power cycle (Off - Hard graceful)", "Diagnostic interrupt (INIT)"]; +function performAmtPowerActionEx2(stack, name, response, status) { + if (status == 200) { + var powerNumber = parseInt(response.Body.PowerState); + if ((powerNumber >= DMTFPowerStates.length) && (powerNumber > 1)) { + console.log('Unknown power state: ' + response.Body.PowerState); + } else { + console.log('Current power state: ' + DMTFPowerStates[powerNumber]); + } + process.exit(0); + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + + // // Startup // diff --git a/agents/meshcmd.min.js b/agents/meshcmd.min.js index 618e9ff0..bdbe7f7c 100644 --- a/agents/meshcmd.min.js +++ b/agents/meshcmd.min.js @@ -113,7 +113,7 @@ function run(argv) { //console.log('addedModules = ' + JSON.stringify(addedModules)); var actionpath = 'meshaction.txt'; if (args.actionfile != null) { actionpath = args.actionfile; } - var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTPRESENCE']; + var actions = ['HELP', 'ROUTE', 'MICROLMS', 'AMTPOWER', 'AMTLOADWEBAPP', 'AMTLOADSMALLWEBAPP', 'AMTLOADLARGEWEBAPP', 'AMTCLEARWEBAPP', 'AMTSTORAGESTATE', 'AMTINFO', 'AMTINFODEBUG', 'AMTVERSIONS', 'AMTHASHES', 'AMTSAVESTATE', 'AMTSCRIPT', 'AMTUUID', 'AMTCCM', 'AMTACM', 'AMTDEACTIVATE', 'AMTACMDEACTIVATE', 'SMBIOS', 'RAWSMBIOS', 'MESHCOMMANDER', 'AMTAUDITLOG', 'AMTPRESENCE']; // Load the action file var actionfile = null; @@ -186,6 +186,7 @@ function run(argv) { console.log(' AmtStorageState - Show contents of the Intel AMT web storage.'); console.log(' AmtSaveState - Save all Intel AMT WSMAN object to file.'); console.log(' AmtPresence - Heartbeat a local Intel AMT watchdog agent.'); + console.log(' AmtPower - Perform remote Intel AMT power operation.'); console.log(' AmtScript - Run .mescript on Intel AMT.'); console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log('\r\nHelp on a specific action using:\r\n'); @@ -295,6 +296,15 @@ function run(argv) { console.log(' --user [username] The Intel AMT login username, admin is default.'); console.log(' --pass [password] The Intel AMT login password.'); console.log(' --tls Specifies that TLS must be used.'); + } else if (action == 'amtpower') { + console.log('AmtPower will get current pwoer state or send a reboot command to a remote Intel AMT device. Example usage:\r\n\r\n meshcmd amtpower --reset --host 1.2.3.4 --user admin --pass mypassword --tls'); + console.log('\r\nRequired arguments:\r\n'); + console.log(' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.'); + console.log(' --pass [password] The Intel AMT login password.'); + console.log('\r\nOptional arguments:\r\n'); + console.log(' --reset, --poweron, --poweroff, --powercycle, --sleep, --hibernate'); + console.log(' --user [username] The Intel AMT login username, admin is default.'); + console.log(' --tls Specifies that TLS must be used.'); } else if (action == 'meshcommander') { console.log('This action launched a local web server that hosts MeshCommander, a Intel AMT management console.'); console.log('\r\nPossible arguments:\r\n'); @@ -572,6 +582,38 @@ function run(argv) { if ((settings.cdrom == null) || (typeof settings.cdrom != 'string') || (settings.cdrom == '')) { settings.cdrom = null; } if ((settings.floppy == null) && (settings.cdrom == null)) { console.log('No or invalid \"floppy\" or \"cdrom\" specified, use --floppy [file] or --cdrom [file].'); exit(1); return; } performIder(); + } else if (settings.action == 'amtpower') { // Perform remote Intel AMT power operation + if ((settings.hostname == null) || (typeof settings.hostname != 'string') || (settings.hostname == '')) { console.log('No or invalid \"hostname\" specified, use --hostname [host].'); exit(1); return; } + if ((settings.password == null) || (typeof settings.password != 'string') || (settings.password == '')) { console.log('No or invalid \"password\" specified, use --password [password].'); exit(1); return; } + if ((settings.username == null) || (typeof settings.username != 'string') || (settings.username == '')) { settings.username = 'admin'; } + + /* + 2 = Power On + 3 = Sleep - Light + 4 = Sleep - Deep + 5 = Power Cycle (Off Soft) + 6 = Power Off - Hard + 7 = Hibernate + 8 = Power Off - Soft + 9 = Power Cycle (Off Hard) + 10 = Master Bus Reset + 11 = Diagnostic Interrupt (NMI) + 12 = Power Off - Soft Graceful + 13 = Power Off - Hard Graceful + 14 = Master Bus Reset Graceful + 15 = Power Cycle (Off - Soft Graceful) + 16 = Power Cycle (Off - Hard Graceful) + */ + + settings.poweraction = 0; + if (args.poweron) { settings.poweraction = 2; } + if (args.sleep) { settings.poweraction = 3; } + if (args.powercycle) { settings.poweraction = 5; } + if (args.poweroff) { settings.poweraction = 6; } + if (args.hibernate) { settings.poweraction = 7; } + if (args.reset) { settings.poweraction = 10; } + //if (settings.poweraction == 0) { console.log('No power action, specify --poweron, --sleep, --powercycle, --poweroff, --hibernate, --reset.'); exit(1); return; } + performAmtPowerAction(); } else { console.log('Invalid \"action\" specified.'); exit(1); return; } @@ -2027,6 +2069,53 @@ function iderSectorStats(mode, dev, mediaBlocks, lba, len) { iderIdleTimer = setTimeout(function () { console.log('Idle timeout'); process.exit(1); }, 1000 * settings.timeout); } + +// +// Intel AMT Remote Power Action +// + +function performAmtPowerAction() { + var transport = require('amt-wsman-duk'); + var wsman = require('amt-wsman'); + var amt = require('amt'); + wsstack = new wsman(transport, settings.hostname, settings.tls ? 16993 : 16992, settings.username, settings.password, settings.tls); + amtstack = new amt(wsstack); + if (settings.poweraction != 0) { + // Set the power state + amtstack.RequestPowerStateChange(settings.poweraction, performAmtPowerActionEx); + } else { + // Get the power state + amtstack.Get("CIM_AssociatedPowerManagementService", performAmtPowerActionEx2, 0, 1); + } +} + +function performAmtPowerActionEx(stack, name, response, status) { + if (status == 200) { + console.log(response.Body.ReturnValueStr.split('_').join(' ')); + process.exit(0); + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + +var DMTFPowerStates = ["", "", "Power on", "Light sleep", "Deep sleep", "Power cycle (Soft off)", "Off - Hard", "Hibernate (Off soft)", "Soft off", "Power cycle (Off-hard)", "Master bus reset", "Diagnostic interrupt (NMI)", "Not applicable", "Off - Soft graceful", "Off - Hard graceful", "Master bus reset graceful", "Power cycle (Off - Soft graceful)", "Power cycle (Off - Hard graceful)", "Diagnostic interrupt (INIT)"]; +function performAmtPowerActionEx2(stack, name, response, status) { + if (status == 200) { + var powerNumber = parseInt(response.Body.PowerState); + if ((powerNumber >= DMTFPowerStates.length) && (powerNumber > 1)) { + console.log('Unknown power state: ' + response.Body.PowerState); + } else { + console.log('Current power state: ' + DMTFPowerStates[powerNumber]); + } + process.exit(0); + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + + // // Startup // diff --git a/package.json b/package.json index 6fe9c9ec..f27b5ffc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.7-o", + "version": "0.3.7-p", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default-min.handlebars b/views/default-min.handlebars index cdcda4f1..c33107c1 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index 8925c107..a9f0f240 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -3842,7 +3842,7 @@ // Add node name var nname = EscapeHtml(node.name); if (nname.length == 0) { nname = 'None'; } - if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '' + nname + ' '; } + if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '' + nname + ' '; } QH('p10deviceName', nname); QH('p11deviceName', nname); QH('p12deviceName', nname); diff --git a/webserver.js b/webserver.js index eccd4597..397dff49 100644 --- a/webserver.js +++ b/webserver.js @@ -2584,7 +2584,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { res.set({ 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Content-Type': 'text/plain', 'Content-Disposition': 'attachment; filename="' + scriptInfo.rname + '"' }); var data = scriptInfo.data; var cmdoptions = { wgetoptionshttp: '', wgetoptionshttps: '', curloptionshttp: '-L ', curloptionshttps: '-L ' } - if (isTrustedCert() == false) { + if (isTrustedCert() != true) { cmdoptions.wgetoptionshttps += '--no-check-certificate '; cmdoptions.curloptionshttps += '-k '; }