diff --git a/agents/MeshCmd-signed.exe b/agents/MeshCmd-signed.exe index 403cad3d..92cbde26 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 2950fff1..16b14ebc 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 2b60f643..0315eb24 100644 --- a/agents/meshcmd.js +++ b/agents/meshcmd.js @@ -46,6 +46,7 @@ var oswsstack = null, osamtstack = null; var amtMeiTmpState = null; var SMBiosTables = null; var globalDebugFlags = 0; // 1 = IDER Debug +var pendingAmtConfigActions = 0; const RCSMessageProtocolVersion = 1; // RCS Message Protocol Version. Needs to be less than or equal to RCS server Message Protocol Version // MeshCommander for Firmware (GZIP'ed, Base64) v0.7.8 @@ -113,7 +114,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', 'AMTPOWER', 'AMTFEATURES', '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', 'AMTFEATURES', 'AMTNETWORK', '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; @@ -190,6 +191,7 @@ function run(argv) { console.log(' AmtScript - Run .mescript on Intel AMT.'); console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log(' AmtFeatures - Intel AMT features & user consent.'); + console.log(' AmtNetwork - Intel AMT network interface settings.'); console.log('\r\nHelp on a specific action using:\r\n'); console.log(' meshcmd help [action]'); exit(1); return; @@ -300,12 +302,27 @@ function run(argv) { } 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(' --host [hostname] The IP address or DNS name of Intel AMT.'); 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 == 'amtnetwork') { + console.log('AmtNetwork is used to get/set Intel AMT network interface configuration. Example usage:\r\n\r\n meshcmd amtnetwork --host 1.2.3.4 --user admin --pass mypassword --dhcp'); + 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(' --user [username] The Intel AMT login username, admin is default.'); + console.log(' --tls Specifies that TLS must be used.'); + console.log(' --dhcp Change IPv4 wired interface to DHCP mode'); + console.log(' --static Change IPv4 wired interface to static IP mode'); + console.log(' --ip [1.2.3.4] Static IPv4 address (required)'); + console.log(' --subnet [1.2.3.4] Static IPv4 subnet mask'); + console.log(' --gateway [1.2.3.4] Static IPv4 default gateway'); + console.log(' --dns [1.2.3.4] Primary DNS IPv4 address'); + console.log(' --dns2 [1.2.3.4] Secondary DNS IPv4 address'); } else if (action == 'amtfeatures') { console.log('AmtFeatures is used to get/set Intel AMT feature configuration. Example usage:\r\n\r\n meshcmd amtfeatures --host 1.2.3.4 --user admin --pass mypassword --tls --redir 1'); console.log('\r\nRequired arguments:\r\n'); @@ -596,8 +613,13 @@ 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 == 'amtnetwork') { // Perform remote Intel AMT wired IPv4 configuration operation + if (settings.hostname == null) { settings.hostname = '127.0.0.1'; } + 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'; } + performAmtNetConfig(args); } else if (settings.action == 'amtfeatures') { // Perform remote Intel AMT feature configuration 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.hostname == null) { settings.hostname = '127.0.0.1'; } 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'; } performAmtFeatureConfig(args); @@ -1374,11 +1396,11 @@ var lmsNotifications = []; var amtLms = null; var promise = require('promise'); -function startLms(func, lmscommander) { +function startLms(func, lmscommander, tag) { 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) { } - if (lme_heci == null) { if (func != null) { func(func, 0); } this.promise._res(); return; } + if (lme_heci == null) { if (func != null) { func(0, tag); } this.promise._res(); return; } //var amtLms = null; var http = require('http'); @@ -1396,10 +1418,10 @@ function startLms(func, lmscommander) { if (lmscommander === true) { //settings.noconsole !== true) { startMeshCommanderLms(); //console.log("LMS started, MeshCommander on HTTP/16994."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2, tag); }, 100); } else { //console.log('LME connection failed: ' + JSON.stringify(e)); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 0); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 0, tag); }, 100); } this.promise._res(); }); @@ -1425,11 +1447,11 @@ function startLms(func, lmscommander) { if (settings.noconsole !== true) { startMeshCommanderLms(); //console.log("LMS started, MeshCommander on HTTP/16994."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2, tag); }, 100); //console.logReferenceCount(tempTimer); } else { //console.log("LMS started."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 1); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 1, tag); }, 100); //console.logReferenceCount(tempTimer); } @@ -1500,9 +1522,9 @@ function startMeshCommanderLms() { }); } -function setupMeiOsAdmin(func, state) { +function setupMeiOsAdmin(func, state, tag) { if (amtMei == null) { - if (func) { func(state); } + if (func) { func(state, tag); } } else { amtMei.getLocalSystemAccount(function (x) { var transport = require('amt-wsman-duk'); @@ -1510,7 +1532,7 @@ function setupMeiOsAdmin(func, state) { var amt = require('amt'); oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false); osamtstack = new amt(oswsstack); - if (func) { func(state); } + if (func) { func(state, tag); } //var AllWsman = "CIM_SoftwareIdentity,IPS_SecIOService,IPS_ScreenSettingData,IPS_ProvisioningRecordLog,IPS_HostBasedSetupService,IPS_HostIPSettings,IPS_IPv6PortSettings".split(','); //osamtstack.BatchEnum(null, AllWsman, startLmsWsmanResponse, null, true); @@ -2088,11 +2110,116 @@ function iderSectorStats(mode, dev, mediaBlocks, lba, len) { iderIdleTimer = setTimeout(function () { console.log('Idle timeout'); process.exit(1); }, 1000 * settings.timeout); } +// +// Intel AMT IPv4 wired configuration +// + +function performAmtNetConfig(args) { + if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { + settings.noconsole = true; startLms(performAmtNetConfig0, false, args); + } else { + performAmtNetConfig0(1, args); + } +} + +function performAmtNetConfig0(state, args) { + 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); + amtstack.BatchEnum(null, ['AMT_EthernetPortSettings'], performAmtNetConfig1, args); +} + +function performAmtNetConfig1(stack, name, response, status, args) { + if (status == 200) { + // Set wired and wireless interfaces + var amtwirelessif = -1; + var amtwiredif = -1; + for (var y in response['AMT_EthernetPortSettings'].responses) { + var z = response['AMT_EthernetPortSettings'].responses[y]; + if (z['WLANLinkProtectionLevel'] || (y == 1)) { amtwirelessif = y; } // Set the wireless interface, this seems to cover new wireless only computers and older computers with dual interfaces. + if (y == 0) { if ((amtwirelessif != y) && (z["MACAddress"] != "00-00-00-00-00-00")) { amtwiredif = y; } } // On computers with only wireless, the wired interface will have a null MAC + } + + // Check if configuration change is required + if (args) { + if (args.dhcp && (amtwiredif != -1) && (response['AMT_EthernetPortSettings'].responses[amtwiredif].DHCPEnabled == false)) { + // Change to DHCP + pendingAmtConfigActions++; + var x = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + x['DHCPEnabled'] = true; + delete x["IPAddress"]; + delete x["SubnetMask"]; + delete x["DefaultGateway"]; + delete x["PrimaryDNS"]; + delete x["SecondaryDNS"]; + amtstack.Put("AMT_EthernetPortSettings", x, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtNetConfig0(); } }); + } + else if (args.static && (amtwiredif != -1) && (response['AMT_EthernetPortSettings'].responses[amtwiredif].DHCPEnabled == true)) { + // Change to STATIC + pendingAmtConfigActions++; + var x = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + x['DHCPEnabled'] = false; + delete x["IPAddress"]; + delete x["SubnetMask"]; + delete x["DefaultGateway"]; + delete x["PrimaryDNS"]; + delete x["SecondaryDNS"]; + if (args.ip) { x["IPAddress"] = args.ip; } else { console.log('Missing IPv4 address, use --ip 1.2.3.4'); process.exit(1); } + if (args.subnet) { x["SubnetMask"] = args.subnet; } else { console.log('Missing IPv4 subnet, use --subnet 255.255.255.0'); process.exit(1); } + if (args.gateway) { x["DefaultGateway"] = args.gateway; } + if (args.dns) { x["PrimaryDNS"] = args.dns; } + if (args.dns2) { x["SecondaryDNS"] = args.dns2; } + amtstack.Put("AMT_EthernetPortSettings", x, function (stack, name, response, status) { console.log(status); if (--pendingAmtConfigActions == 0) { performAmtNetConfig0(); } }); + } + } + + if (pendingAmtConfigActions == 0) { + if (amtwiredif != -1) { // Wired + var z = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + console.log('--WIRED---'); + for (var i in z) { + if (['ElementName', 'InstanceID'].indexOf(i) == -1) { + var name = i; + while (name.length < 16) { name += ' '; } + console.log(name + ': ' + z[i]); + } + } + } + if (amtwirelessif != -1) { // Wireless + var z = response['AMT_EthernetPortSettings'].responses[amtwirelessif]; + console.log('--WIRELESS---'); + for (var i in z) { + if (['ElementName', 'InstanceID'].indexOf(i) == -1) { + var name = i; + while (name.length < 16) { name += ' '; } + console.log(name + ': ' + z[i]); + } + } + } + process.exit(0); + } + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + + // // Intel AMT feature configuration action // function performAmtFeatureConfig(args) { + if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { + settings.noconsole = true; startLms(performAmtFeatureConfig0, false, args); + } else { + performAmtFeatureConfig0(1, args); + } +} + +function performAmtFeatureConfig0(state, args) { var transport = require('amt-wsman-duk'); var wsman = require('amt-wsman'); var amt = require('amt'); @@ -2101,7 +2228,6 @@ function performAmtFeatureConfig(args) { amtstack.BatchEnum(null, ['*IPS_OptInService', '*AMT_RedirectionService', '*CIM_KVMRedirectionSAP'], performAmtFeatureConfig1, args); } -var pendingAmtConfigActions = 0; function performAmtFeatureConfig1(stack, name, response, status, args) { if (status == 200) { // User consent @@ -2110,17 +2236,17 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if ((args.userconsent == 'none') && (optinrequired != 0)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 0; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } else if ((args.userconsent == 'kvm') && (optinrequired != 1)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 1; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } else if ((args.userconsent == 'all') && (optinrequired != 0xFFFFFFFF)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 0xFFFFFFFF; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } @@ -2138,8 +2264,8 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if ((sol == true) && ((args.sol == 'disabled') || (args.sol == 0))) { sol = false; redirchange = true; } if ((ider == false) && ((args.ider == 'enabled') || (args.ider == 1))) { ider = true; redirchange = true; } if ((ider == true) && ((args.ider == 'disabled') || (args.ider == 0))) { ider = false; redirchange = true; } - if (redirportchange) { pendingAmtConfigActions++; amtstack.Put("AMT_RedirectionService", response['AMT_RedirectionService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } - if (redirchange) { pendingAmtConfigActions++; amtstack.AMT_RedirectionService_RequestStateChange((32768 + ((ider ? 1 : 0) + (sol ? 2 : 0))), function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } + if (redirportchange) { pendingAmtConfigActions++; amtstack.Put("AMT_RedirectionService", response['AMT_RedirectionService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } + if (redirchange) { pendingAmtConfigActions++; amtstack.AMT_RedirectionService_RequestStateChange((32768 + ((ider ? 1 : 0) + (sol ? 2 : 0))), function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } // KVM @@ -2150,19 +2276,19 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if (args) { if ((kvm == false) && ((args.kvm == 'enabled') || (args.kvm == 1))) { kvm = true; kvmchange = true; } if ((kvm == true) && ((args.kvm == 'disabled') || (args.kvm == 0))) { kvm = false; kvmchange = true; } - if (kvmchange) { pendingAmtConfigActions++; amtstack.CIM_KVMRedirectionSAP_RequestStateChange(kvm ? 2 : 3, 0, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } + if (kvmchange) { pendingAmtConfigActions++; amtstack.CIM_KVMRedirectionSAP_RequestStateChange(kvm ? 2 : 3, 0, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } } if (pendingAmtConfigActions == 0) { - if (optinrequired == 0) { console.log('User Consent: None'); } - else if (optinrequired == 1) { console.log('User Consent: KVM'); } - else if (optinrequired == 0xFFFFFFFF) { console.log('User Consent: All'); } - else { console.log('User Consent: ' + optinrequired); } - console.log('Redirection Port: ' + (redir ? 'Enabled' : 'Disabled')); - console.log('Serial-over-LAN: ' + (sol ? 'Enabled' : 'Disabled')); - console.log('IDE Redirection: ' + (ider ? 'Enabled' : 'Disabled')); - if (response['CIM_KVMRedirectionSAP'] != null) { console.log('Remote desktop (KVM): ' + (kvm ? 'Enabled' : 'Disabled')); } + if (optinrequired == 0) { console.log('User Consent : None'); } + else if (optinrequired == 1) { console.log('User Consent : KVM'); } + else if (optinrequired == 0xFFFFFFFF) { console.log('User Consent : All'); } + else { console.log('User Consent : ' + optinrequired); } + console.log('Redirection Port : ' + (redir ? 'Enabled' : 'Disabled')); + console.log('Serial-over-LAN : ' + (sol ? 'Enabled' : 'Disabled')); + console.log('IDE Redirection : ' + (ider ? 'Enabled' : 'Disabled')); + if (response['CIM_KVMRedirectionSAP'] != null) { console.log('Remote desktop (KVM) : ' + (kvm ? 'Enabled' : 'Disabled')); } process.exit(0); } } else { diff --git a/agents/meshcmd.min.js b/agents/meshcmd.min.js index 2b60f643..0315eb24 100644 --- a/agents/meshcmd.min.js +++ b/agents/meshcmd.min.js @@ -46,6 +46,7 @@ var oswsstack = null, osamtstack = null; var amtMeiTmpState = null; var SMBiosTables = null; var globalDebugFlags = 0; // 1 = IDER Debug +var pendingAmtConfigActions = 0; const RCSMessageProtocolVersion = 1; // RCS Message Protocol Version. Needs to be less than or equal to RCS server Message Protocol Version // MeshCommander for Firmware (GZIP'ed, Base64) v0.7.8 @@ -113,7 +114,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', 'AMTPOWER', 'AMTFEATURES', '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', 'AMTFEATURES', 'AMTNETWORK', '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; @@ -190,6 +191,7 @@ function run(argv) { console.log(' AmtScript - Run .mescript on Intel AMT.'); console.log(' AmtIDER - Mount local disk image to remote computer.'); console.log(' AmtFeatures - Intel AMT features & user consent.'); + console.log(' AmtNetwork - Intel AMT network interface settings.'); console.log('\r\nHelp on a specific action using:\r\n'); console.log(' meshcmd help [action]'); exit(1); return; @@ -300,12 +302,27 @@ function run(argv) { } 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(' --host [hostname] The IP address or DNS name of Intel AMT.'); 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 == 'amtnetwork') { + console.log('AmtNetwork is used to get/set Intel AMT network interface configuration. Example usage:\r\n\r\n meshcmd amtnetwork --host 1.2.3.4 --user admin --pass mypassword --dhcp'); + 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(' --user [username] The Intel AMT login username, admin is default.'); + console.log(' --tls Specifies that TLS must be used.'); + console.log(' --dhcp Change IPv4 wired interface to DHCP mode'); + console.log(' --static Change IPv4 wired interface to static IP mode'); + console.log(' --ip [1.2.3.4] Static IPv4 address (required)'); + console.log(' --subnet [1.2.3.4] Static IPv4 subnet mask'); + console.log(' --gateway [1.2.3.4] Static IPv4 default gateway'); + console.log(' --dns [1.2.3.4] Primary DNS IPv4 address'); + console.log(' --dns2 [1.2.3.4] Secondary DNS IPv4 address'); } else if (action == 'amtfeatures') { console.log('AmtFeatures is used to get/set Intel AMT feature configuration. Example usage:\r\n\r\n meshcmd amtfeatures --host 1.2.3.4 --user admin --pass mypassword --tls --redir 1'); console.log('\r\nRequired arguments:\r\n'); @@ -596,8 +613,13 @@ 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 == 'amtnetwork') { // Perform remote Intel AMT wired IPv4 configuration operation + if (settings.hostname == null) { settings.hostname = '127.0.0.1'; } + 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'; } + performAmtNetConfig(args); } else if (settings.action == 'amtfeatures') { // Perform remote Intel AMT feature configuration 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.hostname == null) { settings.hostname = '127.0.0.1'; } 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'; } performAmtFeatureConfig(args); @@ -1374,11 +1396,11 @@ var lmsNotifications = []; var amtLms = null; var promise = require('promise'); -function startLms(func, lmscommander) { +function startLms(func, lmscommander, tag) { 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) { } - if (lme_heci == null) { if (func != null) { func(func, 0); } this.promise._res(); return; } + if (lme_heci == null) { if (func != null) { func(0, tag); } this.promise._res(); return; } //var amtLms = null; var http = require('http'); @@ -1396,10 +1418,10 @@ function startLms(func, lmscommander) { if (lmscommander === true) { //settings.noconsole !== true) { startMeshCommanderLms(); //console.log("LMS started, MeshCommander on HTTP/16994."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2, tag); }, 100); } else { //console.log('LME connection failed: ' + JSON.stringify(e)); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 0); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 0, tag); }, 100); } this.promise._res(); }); @@ -1425,11 +1447,11 @@ function startLms(func, lmscommander) { if (settings.noconsole !== true) { startMeshCommanderLms(); //console.log("LMS started, MeshCommander on HTTP/16994."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 2, tag); }, 100); //console.logReferenceCount(tempTimer); } else { //console.log("LMS started."); - tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 1); }, 100); + tempTimer = setTimeout(function () { delete tempTimer; setupMeiOsAdmin(func, 1, tag); }, 100); //console.logReferenceCount(tempTimer); } @@ -1500,9 +1522,9 @@ function startMeshCommanderLms() { }); } -function setupMeiOsAdmin(func, state) { +function setupMeiOsAdmin(func, state, tag) { if (amtMei == null) { - if (func) { func(state); } + if (func) { func(state, tag); } } else { amtMei.getLocalSystemAccount(function (x) { var transport = require('amt-wsman-duk'); @@ -1510,7 +1532,7 @@ function setupMeiOsAdmin(func, state) { var amt = require('amt'); oswsstack = new wsman(transport, '127.0.0.1', 16992, x.user, x.pass, false); osamtstack = new amt(oswsstack); - if (func) { func(state); } + if (func) { func(state, tag); } //var AllWsman = "CIM_SoftwareIdentity,IPS_SecIOService,IPS_ScreenSettingData,IPS_ProvisioningRecordLog,IPS_HostBasedSetupService,IPS_HostIPSettings,IPS_IPv6PortSettings".split(','); //osamtstack.BatchEnum(null, AllWsman, startLmsWsmanResponse, null, true); @@ -2088,11 +2110,116 @@ function iderSectorStats(mode, dev, mediaBlocks, lba, len) { iderIdleTimer = setTimeout(function () { console.log('Idle timeout'); process.exit(1); }, 1000 * settings.timeout); } +// +// Intel AMT IPv4 wired configuration +// + +function performAmtNetConfig(args) { + if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { + settings.noconsole = true; startLms(performAmtNetConfig0, false, args); + } else { + performAmtNetConfig0(1, args); + } +} + +function performAmtNetConfig0(state, args) { + 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); + amtstack.BatchEnum(null, ['AMT_EthernetPortSettings'], performAmtNetConfig1, args); +} + +function performAmtNetConfig1(stack, name, response, status, args) { + if (status == 200) { + // Set wired and wireless interfaces + var amtwirelessif = -1; + var amtwiredif = -1; + for (var y in response['AMT_EthernetPortSettings'].responses) { + var z = response['AMT_EthernetPortSettings'].responses[y]; + if (z['WLANLinkProtectionLevel'] || (y == 1)) { amtwirelessif = y; } // Set the wireless interface, this seems to cover new wireless only computers and older computers with dual interfaces. + if (y == 0) { if ((amtwirelessif != y) && (z["MACAddress"] != "00-00-00-00-00-00")) { amtwiredif = y; } } // On computers with only wireless, the wired interface will have a null MAC + } + + // Check if configuration change is required + if (args) { + if (args.dhcp && (amtwiredif != -1) && (response['AMT_EthernetPortSettings'].responses[amtwiredif].DHCPEnabled == false)) { + // Change to DHCP + pendingAmtConfigActions++; + var x = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + x['DHCPEnabled'] = true; + delete x["IPAddress"]; + delete x["SubnetMask"]; + delete x["DefaultGateway"]; + delete x["PrimaryDNS"]; + delete x["SecondaryDNS"]; + amtstack.Put("AMT_EthernetPortSettings", x, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtNetConfig0(); } }); + } + else if (args.static && (amtwiredif != -1) && (response['AMT_EthernetPortSettings'].responses[amtwiredif].DHCPEnabled == true)) { + // Change to STATIC + pendingAmtConfigActions++; + var x = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + x['DHCPEnabled'] = false; + delete x["IPAddress"]; + delete x["SubnetMask"]; + delete x["DefaultGateway"]; + delete x["PrimaryDNS"]; + delete x["SecondaryDNS"]; + if (args.ip) { x["IPAddress"] = args.ip; } else { console.log('Missing IPv4 address, use --ip 1.2.3.4'); process.exit(1); } + if (args.subnet) { x["SubnetMask"] = args.subnet; } else { console.log('Missing IPv4 subnet, use --subnet 255.255.255.0'); process.exit(1); } + if (args.gateway) { x["DefaultGateway"] = args.gateway; } + if (args.dns) { x["PrimaryDNS"] = args.dns; } + if (args.dns2) { x["SecondaryDNS"] = args.dns2; } + amtstack.Put("AMT_EthernetPortSettings", x, function (stack, name, response, status) { console.log(status); if (--pendingAmtConfigActions == 0) { performAmtNetConfig0(); } }); + } + } + + if (pendingAmtConfigActions == 0) { + if (amtwiredif != -1) { // Wired + var z = response['AMT_EthernetPortSettings'].responses[amtwiredif]; + console.log('--WIRED---'); + for (var i in z) { + if (['ElementName', 'InstanceID'].indexOf(i) == -1) { + var name = i; + while (name.length < 16) { name += ' '; } + console.log(name + ': ' + z[i]); + } + } + } + if (amtwirelessif != -1) { // Wireless + var z = response['AMT_EthernetPortSettings'].responses[amtwirelessif]; + console.log('--WIRELESS---'); + for (var i in z) { + if (['ElementName', 'InstanceID'].indexOf(i) == -1) { + var name = i; + while (name.length < 16) { name += ' '; } + console.log(name + ': ' + z[i]); + } + } + } + process.exit(0); + } + } else { + console.log('Error, status ' + status + '.'); + process.exit(1); + } +} + + // // Intel AMT feature configuration action // function performAmtFeatureConfig(args) { + if ((settings.hostname == '127.0.0.1') || (settings.hostname.toLowerCase() == 'localhost')) { + settings.noconsole = true; startLms(performAmtFeatureConfig0, false, args); + } else { + performAmtFeatureConfig0(1, args); + } +} + +function performAmtFeatureConfig0(state, args) { var transport = require('amt-wsman-duk'); var wsman = require('amt-wsman'); var amt = require('amt'); @@ -2101,7 +2228,6 @@ function performAmtFeatureConfig(args) { amtstack.BatchEnum(null, ['*IPS_OptInService', '*AMT_RedirectionService', '*CIM_KVMRedirectionSAP'], performAmtFeatureConfig1, args); } -var pendingAmtConfigActions = 0; function performAmtFeatureConfig1(stack, name, response, status, args) { if (status == 200) { // User consent @@ -2110,17 +2236,17 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if ((args.userconsent == 'none') && (optinrequired != 0)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 0; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } else if ((args.userconsent == 'kvm') && (optinrequired != 1)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 1; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } else if ((args.userconsent == 'all') && (optinrequired != 0xFFFFFFFF)) { pendingAmtConfigActions++; response['IPS_OptInService'].response["OptInRequired"] = 0xFFFFFFFF; - amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); + amtstack.Put("IPS_OptInService", response['IPS_OptInService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } @@ -2138,8 +2264,8 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if ((sol == true) && ((args.sol == 'disabled') || (args.sol == 0))) { sol = false; redirchange = true; } if ((ider == false) && ((args.ider == 'enabled') || (args.ider == 1))) { ider = true; redirchange = true; } if ((ider == true) && ((args.ider == 'disabled') || (args.ider == 0))) { ider = false; redirchange = true; } - if (redirportchange) { pendingAmtConfigActions++; amtstack.Put("AMT_RedirectionService", response['AMT_RedirectionService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } - if (redirchange) { pendingAmtConfigActions++; amtstack.AMT_RedirectionService_RequestStateChange((32768 + ((ider ? 1 : 0) + (sol ? 2 : 0))), function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } + if (redirportchange) { pendingAmtConfigActions++; amtstack.Put("AMT_RedirectionService", response['AMT_RedirectionService'].response, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } + if (redirchange) { pendingAmtConfigActions++; amtstack.AMT_RedirectionService_RequestStateChange((32768 + ((ider ? 1 : 0) + (sol ? 2 : 0))), function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } // KVM @@ -2150,19 +2276,19 @@ function performAmtFeatureConfig1(stack, name, response, status, args) { if (args) { if ((kvm == false) && ((args.kvm == 'enabled') || (args.kvm == 1))) { kvm = true; kvmchange = true; } if ((kvm == true) && ((args.kvm == 'disabled') || (args.kvm == 0))) { kvm = false; kvmchange = true; } - if (kvmchange) { pendingAmtConfigActions++; amtstack.CIM_KVMRedirectionSAP_RequestStateChange(kvm ? 2 : 3, 0, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig(); } }); } + if (kvmchange) { pendingAmtConfigActions++; amtstack.CIM_KVMRedirectionSAP_RequestStateChange(kvm ? 2 : 3, 0, function (stack, name, response, status) { if (--pendingAmtConfigActions == 0) { performAmtFeatureConfig0(); } }); } } } if (pendingAmtConfigActions == 0) { - if (optinrequired == 0) { console.log('User Consent: None'); } - else if (optinrequired == 1) { console.log('User Consent: KVM'); } - else if (optinrequired == 0xFFFFFFFF) { console.log('User Consent: All'); } - else { console.log('User Consent: ' + optinrequired); } - console.log('Redirection Port: ' + (redir ? 'Enabled' : 'Disabled')); - console.log('Serial-over-LAN: ' + (sol ? 'Enabled' : 'Disabled')); - console.log('IDE Redirection: ' + (ider ? 'Enabled' : 'Disabled')); - if (response['CIM_KVMRedirectionSAP'] != null) { console.log('Remote desktop (KVM): ' + (kvm ? 'Enabled' : 'Disabled')); } + if (optinrequired == 0) { console.log('User Consent : None'); } + else if (optinrequired == 1) { console.log('User Consent : KVM'); } + else if (optinrequired == 0xFFFFFFFF) { console.log('User Consent : All'); } + else { console.log('User Consent : ' + optinrequired); } + console.log('Redirection Port : ' + (redir ? 'Enabled' : 'Disabled')); + console.log('Serial-over-LAN : ' + (sol ? 'Enabled' : 'Disabled')); + console.log('IDE Redirection : ' + (ider ? 'Enabled' : 'Disabled')); + if (response['CIM_KVMRedirectionSAP'] != null) { console.log('Remote desktop (KVM) : ' + (kvm ? 'Enabled' : 'Disabled')); } process.exit(0); } } else { diff --git a/package.json b/package.json index ba9d5210..168187f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.7-t", + "version": "0.3.7-u", "keywords": [ "Remote Management", "Intel AMT",