2018-01-31 05:23:57 +03:00
/ *
2019-01-04 03:22:15 +03:00
Copyright 2018 - 2019 Intel Corporation
2018-01-31 05:23:57 +03:00
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 .
* /
/ * *
* @ description MeshCmd , command line tool for Intel AMT and MeshCentral .
* @ author Ylian Saint - Hilaire
* @ version v0 . 2.0
* /
2018-08-07 04:57:30 +03:00
// Debug Stuff
//console.displayFinalizerMessages = 1; // Display objects that have event listeners that are disposed.
//console.displayStreamPipeMessages = 1; // Display stream pipe and un-pipes
//var __gc = setInterval(function () { console.log('GC'); _debugGC() }, 2000); //
2018-03-07 04:50:44 +03:00
2017-11-01 02:19:58 +03:00
var fs = require ( 'fs' ) ;
var os = require ( 'os' ) ;
var net = require ( 'net' ) ;
var http = require ( 'http' ) ;
var dgram = require ( 'dgram' ) ;
var httpHeaders = require ( 'http-headers' ) ;
var tcpserver = null ;
var broadcastSockets = { } ;
var multicastSockets = { } ;
var discoveryInterval = null ;
var membershipIPv4 = '239.255.255.235' ;
var membershipIPv6 = 'FF02:0:0:0:0:0:0:FE' ;
2017-12-13 03:04:54 +03:00
var settings = null ;
2018-01-31 05:23:57 +03:00
var meshCmdVersion = '***Mesh*Cmd*Version***' ; // Dynamically replaced with MeshCentral version
2017-12-13 03:04:54 +03:00
var amtLms = null , amtMei = null , amtMeiState = null ;
2018-02-08 05:45:14 +03:00
var wsstack = null , amtstack = null ;
var oswsstack = null , osamtstack = null ;
2018-03-07 04:50:44 +03:00
var amtMeiTmpState = null ;
2018-03-13 04:16:06 +03:00
var SMBiosTables = null ;
2018-02-08 05:45:14 +03:00
2019-03-02 04:13:11 +03:00
// MeshCommander for Firmware (GZIP'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6N4uxZF722C5WktfslQgM7y/bNGxye7gzjGZOTuYYXN5f4DlV7p8A6y7A6y3A2wTCAxGPc1IN/V38B7s4m26fwNisA0x3AFh79J8KUwYAI61i1ungpsq1ee21h+o0wUOd2wFZMZpQJqnBmvH0av3hMzMs4aZjRiOsOiEpG94nDIqspTxcXR39KZ4SlO3UYi2yWuRG9w9bAeL2ssFvU2q8i71yIbTaJnE3iX4kp9TdveWXFx/IrcsCFN8z7VKUkGSlLz/ck0WueAk5ETOHs6YwWZlXO+YyDmi2yAiISyGISQUJzVxxum8tnpvkkeWXijp/99oGE1NhwtQYZwIsgJZWSDlN5UXcp4xQvMRBJOrk5IGMflgUYRinFvqGzxPyL+Z3lbLaxVkN+6wrE2WgvRmfMXvqP+
2017-11-01 02:19:58 +03:00
// Check the server certificate fingerprint
function onVerifyServer ( clientName , certs ) {
2018-01-27 04:01:38 +03:00
if ( certs == null ) { certs = clientName ; } // Temporary thing until we fix duktape
2017-11-01 02:19:58 +03:00
try { for ( var i in certs ) { if ( certs [ i ] . fingerprint . replace ( /:/g , '' ) == settings . serverHttpsHash ) { return ; } } } catch ( e ) { }
2017-11-10 04:18:30 +03:00
if ( serverhash != null ) { console . log ( 'Error: Failed to verify server certificate.' ) ; throw 'Invalid server certificate' ; }
2017-11-01 02:19:58 +03:00
}
2018-03-07 04:50:44 +03:00
// Various utility functions
2017-11-01 02:19:58 +03:00
function debug ( level , message ) { if ( ( settings . debugLevel != null ) && ( settings . debugLevel >= level ) ) { console . log ( message ) ; } }
2017-12-13 03:04:54 +03:00
function exit ( status ) { if ( status == null ) { status = 0 ; } try { process . exit ( status ) ; } catch ( e ) { } }
2018-03-07 04:50:44 +03:00
function getInstance ( x , y ) { for ( var i in x ) { if ( x [ i ] [ "InstanceID" ] == y ) return x [ i ] ; } return null ; }
function md5hex ( str ) { return require ( 'MD5Stream' ) . create ( ) . syncHash ( str ) . toString ( 'hex' ) ; }
function guidToStr ( g ) { return g . substring ( 6 , 8 ) + g . substring ( 4 , 6 ) + g . substring ( 2 , 4 ) + g . substring ( 0 , 2 ) + "-" + g . substring ( 10 , 12 ) + g . substring ( 8 , 10 ) + "-" + g . substring ( 14 , 16 ) + g . substring ( 12 , 14 ) + "-" + g . substring ( 16 , 20 ) + "-" + g . substring ( 20 ) ; }
function parceArguments ( argv ) { var r = { } ; for ( var i in argv ) { i = parseInt ( i ) ; if ( argv [ i ] . startsWith ( '--' ) == true ) { var key = argv [ i ] . substring ( 2 ) . toLowerCase ( ) , val = true ; if ( ( ( i + 1 ) < argv . length ) && ( argv [ i + 1 ] . startsWith ( '--' ) == false ) ) { val = argv [ i + 1 ] ; } r [ key ] = val ; } } return r ; }
2017-11-03 04:44:27 +03:00
2018-03-13 04:16:06 +03:00
// Convert an object to string with all functions
function objToString ( x , p , ret ) {
if ( ret == undefined ) ret = '' ;
if ( p == undefined ) p = 0 ;
if ( x == null ) { return '[null]' ; }
if ( p > 8 ) { return '[...]' ; }
if ( x == undefined ) { return '[undefined]' ; }
if ( typeof x == 'string' ) { if ( p == 0 ) return x ; return '"' + ( x . split ( '\0' ) [ 0 ] ) + '"' ; }
if ( typeof x == 'buffer' ) { return '[buffer]' ; }
if ( typeof x != 'object' ) { return x ; }
var r = '{' + ( ret ? '\r\n' : ' ' ) ;
for ( var i in x ) {
if ( i != '_ObjectID' ) { r += ( addPad ( p + 2 , ret ) + i + ': ' + objToString ( x [ i ] , p + 2 , ret ) + ( ret ? '\r\n' : ' ' ) ) ; }
}
return r + addPad ( p , ret ) + '}' ;
}
// Return p number of spaces
function addPad ( p , ret ) { var r = '' ; for ( var i = 0 ; i < p ; i ++ ) { r += ' ' ; } return r ; }
2018-01-31 05:23:57 +03:00
// Parse the incoming arguments
2018-04-04 22:08:28 +03:00
function run ( argv ) {
2017-12-13 03:04:54 +03:00
if ( meshCmdVersion [ 0 ] == '*' ) { meshCmdVersion = '' ; } else { meshCmdVersion = ' v' + meshCmdVersion ; }
2017-11-03 04:44:27 +03:00
var args = parceArguments ( argv ) ;
2018-03-13 04:16:06 +03:00
//console.log(JSON.stringify(argv));
2017-12-13 03:04:54 +03:00
//console.log('addedModules = ' + JSON.stringify(addedModules));
2017-11-01 02:19:58 +03:00
var actionpath = 'meshaction.txt' ;
2017-11-03 04:44:27 +03:00
if ( args . actionfile != null ) { actionpath = args . actionfile ; }
2018-09-20 21:45:12 +03:00
var actions = [ 'HELP' , 'ROUTE' , 'MICROLMS' , 'AMTLOADWEBAPP' , 'AMTLOADSMALLWEBAPP' , 'AMTLOADLARGEWEBAPP' , 'AMTCLEARWEBAPP' , 'AMTSTORAGESTATE' , 'AMTINFO' , 'AMTINFODEBUG' , 'AMTVERSIONS' , 'AMTHASHES' , 'AMTSAVESTATE' , 'AMTSCRIPT' , 'AMTUUID' , 'AMTCCM' , 'AMTDEACTIVATE' , 'SMBIOS' , 'RAWSMBIOS' , 'MESHCOMMANDER' , 'AMTAUDITLOG' , 'AMTPRESENCE' ] ;
2017-12-13 03:04:54 +03:00
2017-11-01 02:19:58 +03:00
// Load the action file
var actionfile = null ;
try { actionfile = fs . readFileSync ( actionpath ) ; } catch ( e ) { }
2017-12-13 03:04:54 +03:00
if ( ( actionpath != 'meshaction.txt' ) && ( actionfile == null ) ) { console . log ( 'Unable to load \"' + actionpath + '\". Create this file or specify the location using --actionfile [filename].' ) ; exit ( 1 ) ; return ; }
if ( actionfile != null ) { try { settings = JSON . parse ( actionfile ) ; } catch ( e ) { console . log ( actionpath , e ) ; exit ( 1 ) ; return ; } } else { if ( argv . length >= 2 ) { settings = { action : argv [ 1 ] } } }
2017-12-16 00:43:04 +03:00
if ( settings == null ) { settings = { } ; }
2017-11-01 02:19:58 +03:00
2017-11-03 04:44:27 +03:00
// Set the arguments
2017-12-16 00:43:04 +03:00
if ( ( typeof args . action ) == 'string' ) { settings . action = args . action ; }
2017-11-03 04:44:27 +03:00
if ( ( typeof args . localport ) == 'string' ) { settings . localport = parseInt ( args . localport ) ; }
if ( ( typeof args . remotenodeid ) == 'string' ) { settings . remoteNodeId = args . remotenodeid ; }
if ( ( typeof args . username ) == 'string' ) { settings . username = args . username ; }
if ( ( typeof args . password ) == 'string' ) { settings . password = args . password ; }
if ( ( typeof args . user ) == 'string' ) { settings . username = args . user ; }
if ( ( typeof args . pass ) == 'string' ) { settings . password = args . pass ; }
2017-12-13 03:04:54 +03:00
if ( ( typeof args . host ) == 'string' ) { settings . hostname = args . host ; }
if ( ( typeof args . hostname ) == 'string' ) { settings . hostname = args . hostname ; }
2017-11-03 04:44:27 +03:00
if ( ( typeof args . serverid ) == 'string' ) { settings . serverId = args . serverid ; }
if ( ( typeof args . serverhttpshash ) == 'string' ) { settings . serverHttpsHash = args . serverhttpshash ; }
if ( ( typeof args . remoteport ) == 'string' ) { settings . remotePort = parseInt ( args . remoteport ) ; }
2018-01-26 03:12:53 +03:00
if ( ( typeof args . out ) == 'string' ) { settings . output = args . out ; }
if ( ( typeof args . output ) == 'string' ) { settings . output = args . output ; }
2017-12-13 03:04:54 +03:00
if ( ( typeof args . debug ) == 'string' ) { settings . debugLevel = parseInt ( args . debug ) ; }
2018-02-02 23:46:09 +03:00
if ( ( typeof args . script ) == 'string' ) { settings . script = args . script ; }
2018-04-29 01:36:10 +03:00
if ( ( typeof args . agent ) == 'string' ) { settings . agent = args . agent ; }
2018-08-07 04:57:30 +03:00
if ( args . debug ) { try { waitForDebugger ( ) ; } catch ( e ) { } }
2018-01-26 03:28:52 +03:00
if ( args . noconsole ) { settings . noconsole = true ; }
if ( args . nocommander ) { settings . noconsole = true ; }
2018-01-26 03:12:53 +03:00
if ( args . lmsdebug ) { settings . lmsdebug = true ; }
if ( args . tls ) { settings . tls = true ; }
2017-12-16 00:43:04 +03:00
if ( ( argv . length > 1 ) && ( actions . indexOf ( argv [ 1 ] . toUpperCase ( ) ) >= 0 ) ) { settings . action = argv [ 1 ] ; }
2017-11-03 04:44:27 +03:00
2017-11-01 02:19:58 +03:00
// Validate meshaction.txt
2018-03-13 04:16:06 +03:00
if ( settings . action == null ) {
console . log ( 'MeshCentral Command (MeshCmd) ' + meshCmdVersion ) ;
console . log ( 'No action specified, use MeshCmd like this:\r\n' ) ;
console . log ( ' meshcmd [action] [arguments...]\r\n' ) ;
console . log ( 'Valid MeshCentral actions:' ) ;
console . log ( ' Route - Map a local TCP port to a remote computer.' ) ;
console . log ( '\r\nValid local actions:' ) ;
console . log ( ' SMBios - Display System Management BIOS tables for this computer.' ) ;
console . log ( ' RawSMBios - Display RAW System Management BIOS tables for this computer.' ) ;
2018-04-04 22:08:28 +03:00
console . log ( ' MicroLMS - Run MicroLMS, allowing local access to Intel AMT.' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' AmtInfo - Show Intel AMT version and activation state.' ) ;
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 ( ' AmtDeactivate - Deactivate Intel AMT if activated in Client Control mode.' ) ;
console . log ( '\r\nValid local or remote actions:' ) ;
2018-03-20 03:31:54 +03:00
console . log ( ' MeshCommander - Launch a local MeshCommander web server.' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' AmtUUID - Show Intel AMT unique identifier.' ) ;
2018-03-21 03:48:03 +03:00
console . log ( ' AmtAuditLog - Show the Intel AMT audit log.' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' AmtLoadWebApp - Load MeshCommander in Intel AMT 11.6+ firmware.' ) ;
console . log ( ' AmtClearWebApp - Clear everything from Intel AMT web storage.' ) ;
console . log ( ' AmtStorageState - Show contents of the Intel AMT web storage.' ) ;
console . log ( ' AmtSaveState - Save all Intel AMT WSMAN object to file.' ) ;
2018-04-29 01:36:10 +03:00
console . log ( ' AmtPresence - Heartbeat a local Intel AMT watchdog agent.' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' AmtScript - Run .mescript on Intel AMT.' ) ;
console . log ( '\r\nHelp on a specific action using:\r\n' ) ;
console . log ( ' meshcmd help [action]' ) ;
exit ( 1 ) ; return ;
}
if ( settings . action == 'help' ) {
if ( argv . length <= 2 ) {
actions . shift ( ) ;
console . log ( 'Help usage:\r\n\r\n MeshCmd help [action]\r\n\r\nValid actions are: ' + actions . join ( ', ' ) + '.' ) ;
exit ( 1 ) ; return ;
}
var action = argv [ 2 ] . toLowerCase ( ) ;
if ( action == 'route' ) {
console . log ( "The route action is used along with a MeshCentral account to map a local TCP port to a remote port on any computer on your MeshCentral account. This action requires many arguments, to avoid specifying them all it's best to download the meshaction.txt file from the web site and place it in the current folder. Example usage:\r\n\r\n (Place meshaction.txt file in current folder)\r\n meshcmd route --pass myAccountPassword" ) ;
} else if ( action == 'smbios' ) {
console . log ( "SMBios action will display this computer's system management BIOS information. Example usage:\r\n\r\n meshcmd smbios --out smbios.txt\r\n" ) ;
console . log ( '\r\Optional arguments:\r\n' ) ;
console . log ( ' --output [filename] Optional filename to write the results to.' ) ;
} else if ( action == 'rawsmbios' ) {
console . log ( "RawSMBios action will display this computer's system management BIOS information in raw hexdecimal form. Example usage:\r\n\r\n meshcmd rawsmbios --out smbios.txt\r\n" ) ;
console . log ( '\r\Optional arguments:\r\n' ) ;
console . log ( ' --output [filename] Optional filename to write the results to.' ) ;
} else if ( action == 'amtinfo' ) {
console . log ( 'AmtInfo action will get the version and activation state of Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Example usage:\r\n\r\n meshcmd amtinfo' ) ;
} else if ( ( action == 'amtversion' ) || ( action == 'amtversions' ) ) {
console . log ( 'AmtVersions will display all version information about Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Example usage:\r\n\r\n meshcmd amtversions' ) ;
} else if ( action == 'amthashes' ) {
console . log ( 'Amthashes will display all trusted activations hashes for Intel AMT on this computer. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. These certificates hashes are used by Intel AMT when performing activation into ACM mode. Example usage:\r\n\r\n meshcmd amthashes' ) ;
2018-04-04 22:08:28 +03:00
} else if ( ( action == 'microlms' ) || ( action == 'lms' ) || ( action == 'amtlms' ) ) {
console . log ( 'Starts MicroLMS on this computer, allowing local access to Intel AMT on TCP ports 16992 and 16993 when applicable. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. These certificates hashes are used by Intel AMT when performing activation into ACM mode. Example usage:\r\n\r\n meshcmd microlms' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --noconsole MeshCommander for LMS will no be available on port 16994.' ) ;
2018-04-04 22:08:28 +03:00
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' microlms install/uninstall/start/stop.' ) ;
2018-03-13 04:16:06 +03:00
} else if ( action == 'amtccm' ) {
console . log ( 'AmtCCM will attempt to activate Intel AMT on this computer into client control mode (CCM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be in "pre-provisioning" state for this command to work and a administrator password must be provided. Example usage:\r\n\r\n meshcmd amtccm --pass mypassword' ) ;
} else if ( action == 'amtdeactivate' ) {
console . log ( 'AmtDeactivate will attempt to deactivate Intel AMT on this computer when in client control mode (CCM). The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. Intel AMT must be activated in client control mode for this command to work. Example usage:\r\n\r\n meshcmd amtdeactivate' ) ;
} else if ( action == 'amtuuid' ) {
console . log ( 'AmtUUID action will get the unique identifier of the local or remote Intel AMT computer. By default, the local UUID is obtained unless a host is specified. Intel AMT must be activated for this command to work. Example usage:\r\n\r\n meshcmd amtuuid --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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 == 'amtloadwebapp' ) || ( action == 'amtloadsmallwebapp' ) || ( action == 'amtloadlargewebapp' ) || ( action == 'amtclearwebapp' ) || ( action == 'amtstoragestate' ) ) {
console . log ( 'AmtLoadWebApp action will load MeshCommander into Intel AMT 11.6 or higher. If the computer is in ACM mode, MeshCommander will replace the default index.htm on HTTP/16992 or HTTPS/16993. If Intel AMT is in CCM mode, MeshCommander will be installed alongside the default web page and will be accessible in the "Web Applications" section. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtloadwebapp --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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 == 'amtclearwebstorage' ) {
console . log ( 'AmtClearWebStorage will clear the web storage of Intel AMT, removing any loaded firmware version of MeshCommander. This command can clear the local or a remote Intel AMT computer. By default, the local computer storage is cleared unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtclearwebstorage --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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 == 'amtstoragestate' ) {
console . log ( 'AmtStorageState will display the content of the web storage of Intel AMT including any loaded firmware version of MeshCommander. This command can read the storage state of a local or remote Intel AMT computer. By default, the local computer storage state is displayed unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtstoragestate --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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 == 'amtsavestate' ) {
console . log ( 'AmtSaveState action will fetch all the entire state of Intel AMT and save it as a JSON file. This action will take multiple minutes to perform. The command will fetch the local computer state unless host is specified. Intel AMT must be ativated for this command to work. Example usage:\r\n\r\n meshcmd amtsavestate --host 1.2.3.4 --user admin --pass mypassword --tls --output state.json' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --output [filename] The output file for the Intel AMT state in JSON format.' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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.' ) ;
2018-04-29 01:36:10 +03:00
} else if ( action == 'amtpresence' ) {
console . log ( 'AmtPresence will heartbeat a local Intel AMT watchdog agent. Example usage:\r\n\r\n meshcmd amtpresence --agent B4B6A24C-255E-A75C-F5E8-B00B4D946AA7' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --agent [uuid] The unique identifier of the watchdog agent.' ) ;
2018-03-13 04:16:06 +03:00
} else if ( action == 'amtscript' ) {
console . log ( 'AmtScript will run a .mescript file on the local or remote Intel AMT. Script files can be built using the MeshCommander script editor and be used to setup or perform actions on Intel AMT. Example usage:\r\n\r\n meshcmd amtscript --script myscript.mescript --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-20 03:31:54 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-13 04:16:06 +03:00
console . log ( ' --script [filename] The script file to run on Intel AMT.' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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.' ) ;
2018-03-20 03:31:54 +03:00
} 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' ) ;
console . log ( ' --localport [port] Local port used for the web server, 3000 is default.' ) ;
2018-04-04 22:08:28 +03:00
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' meshcommander install/uninstall/start/stop.' ) ;
2018-03-21 03:48:03 +03:00
} else if ( action == 'amtauditlog' ) {
console . log ( 'AmtAuditLog action will fetch the local or remote audit log. If used localy, no username/password is required. Example usage:\r\n\r\n meshcmd amtauditlog --host 1.2.3.4 --user admin --pass mypassword --tls --output audit.json' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --output [filename] The output file for the Intel AMT state in JSON format.' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
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.' ) ;
2018-03-13 04:16:06 +03:00
} else {
actions . shift ( ) ;
console . log ( 'Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions . join ( ', ' ) + '.' ) ;
}
exit ( 1 ) ; return ;
}
2017-11-01 02:19:58 +03:00
settings . action = settings . action . toLowerCase ( ) ;
2017-12-13 03:04:54 +03:00
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2018-03-13 04:16:06 +03:00
if ( settings . action == 'smbios' ) {
// Display SM BIOS tables in raw form
SMBiosTables = require ( 'smbios' ) ;
SMBiosTables . get ( function ( data ) {
var r = SMBiosTables . parse ( data ) ;
var out = objToString ( r , 0 , '\r\n' ) ;
2019-01-03 05:34:50 +03:00
if ( settings . output == null ) { console . log ( out ) ; } else { var file = fs . openSync ( settings . output , 'w' ) ; fs . writeSync ( file , Buffer . from ( out , 'utf8' ) ) ; fs . closeSync ( file ) ; }
2018-03-13 04:16:06 +03:00
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'rawsmbios' ) {
// Display SM BIOS tables in raw form
SMBiosTables = require ( 'smbios' ) ;
SMBiosTables . get ( function ( data ) {
var out = '' ;
for ( var i in data ) { var header = false ; for ( var j in data [ i ] ) { if ( data [ i ] [ j ] . length > 0 ) { if ( header == false ) { out += ( 'Table type #' + i + ( ( SMBiosTables . smTableTypes [ i ] == null ) ? '' : ( ', ' + SMBiosTables . smTableTypes [ i ] ) ) ) + '\r\n' ; header = true ; } out += ( ' ' + data [ i ] [ j ] . toString ( 'hex' ) ) + '\r\n' ; } } }
2019-01-03 05:34:50 +03:00
if ( settings . output == null ) { console . log ( out ) ; } else { var file = fs . openSync ( settings . output , 'w' ) ; fs . writeSync ( file , Buffer . from ( out , 'utf8' ) ) ; fs . closeSync ( file ) ; }
2018-03-13 04:16:06 +03:00
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'route' ) {
2018-01-31 05:23:57 +03:00
// MeshCentral Router, port map local TCP port to a remote computer
2017-12-13 03:04:54 +03:00
if ( ( settings . localPort == null ) || ( typeof settings . localPort != 'number' ) || ( settings . localPort < 0 ) || ( settings . localPort > 65535 ) ) { console . log ( 'No or invalid \"localPort\" specified, use --localport [localport].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . remoteNodeId == null ) || ( typeof settings . remoteNodeId != 'string' ) ) { console . log ( 'No or invalid \"remoteNodeId\" specified.' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { console . log ( 'No or invalid \"username\" specified, use --username [username].' ) ; 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 . serverId == null ) || ( typeof settings . serverId != 'string' ) || ( settings . serverId . length != 96 ) ) { console . log ( 'No or invalid \"serverId\" specified.' ) ; exit ( 1 ) ; return ; }
if ( ( settings . serverHttpsHash == null ) || ( typeof settings . serverHttpsHash != 'string' ) || ( settings . serverHttpsHash . length != 96 ) ) { console . log ( 'No or invalid \"serverHttpsHash\" specified.' ) ; exit ( 1 ) ; return ; }
if ( ( settings . remotePort == null ) || ( typeof settings . remotePort != 'number' ) || ( settings . remotePort < 0 ) || ( settings . remotePort > 65535 ) ) { console . log ( 'No or invalid \"remotePort\" specified, use --remoteport [remoteport].' ) ; exit ( 1 ) ; return ; }
if ( settings . serverUrl != null ) { startRouter ( ) ; } else { discoverMeshServer ( ) ; } // Start MeshCentral Router
2018-03-13 04:16:06 +03:00
} else if ( ( settings . action == 'amtloadwebapp' ) || ( settings . action == 'amtloadsmallwebapp' ) || ( settings . action == 'amtloadlargewebapp' ) || ( settings . action == 'amtclearwebapp' ) || ( settings . action == 'amtstoragestate' ) ) { // Intel AMT Web Application Actions
2018-01-31 05:23:57 +03:00
// Intel AMT 11.6+ Load MeshCommander into firmware
2017-12-13 03:04:54 +03:00
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 . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
digest = require ( 'http-digest' ) . create ( settings . username , settings . password ) ;
digest . http = require ( 'http' ) ;
2017-12-16 00:43:04 +03:00
if ( settings . action == 'amtstoragestate' ) {
2017-12-13 03:04:54 +03:00
getAmtStorage ( function ( statusCode , data ) { if ( statusCode == 200 ) { console . log ( "Storage State: " + JSON . stringify ( data , null , 2 ) ) ; exit ( ) ; return ; } else { console . log ( "Unable to read storage state." ) ; exit ( ) ; return ; } } ) ;
} else {
2017-12-16 00:43:04 +03:00
if ( settings . action == 'amtloadwebapp' ) { settings . webapp = Medium _IntelAmtWebApp ; }
else if ( settings . action == 'amtloadsmallwebapp' ) { settings . webapp = Small _IntelAmtWebApp ; }
else if ( settings . action == 'amtloadlargewebapp' ) { settings . webapp = Large _IntelAmtWebApp ; }
else if ( settings . action == 'amtclearwebapp' ) { settings . webapp = null ; }
2017-12-13 03:04:54 +03:00
nextStepStorageUpload ( ) ;
}
2018-03-13 04:16:06 +03:00
} else if ( ( settings . action == 'amtversion' ) || ( settings . action == 'amtversions' ) || ( settings . action == 'amtver' ) ) {
2018-01-31 05:23:57 +03:00
// Display Intel AMT versions
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-26 03:28:52 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-20 03:31:54 +03:00
amtMei . getVersion ( function ( val ) {
console . log ( "MEI Version = " + val . BiosVersion . toString ( ) ) ;
for ( var version in val . Versions ) { console . log ( val . Versions [ version ] . Description + " = " + val . Versions [ version ] . Version ) ; }
exit ( 1 ) ; return ;
2017-12-13 03:04:54 +03:00
} ) ;
2018-03-13 04:16:06 +03:00
} else if ( settings . action == 'amthashes' ) {
2018-01-31 05:23:57 +03:00
// Display Intel AMT list of trusted hashes
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-26 03:28:52 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-20 03:31:54 +03:00
amtMei . getHashHandles ( function ( handles ) {
exitOnCount = handles . length ;
for ( var i = 0 ; i < handles . length ; ++ i ) {
this . getCertHashEntry ( handles [ i ] , function ( result ) {
console . log ( result . name + ', (' + ( result . isDefault ? 'Default' : '' ) + ( result . isActive ? ', Active' : ', Disabled' ) + ')\r\n ' + result . hashAlgorithmStr + ': ' + result . certificateHash ) ;
if ( -- exitOnCount == 0 ) { exit ( 1 ) ; }
} ) ;
}
2017-12-13 03:04:54 +03:00
} ) ;
2018-03-13 04:16:06 +03:00
} else if ( settings . action == 'amtinfo' ) {
2018-01-31 05:23:57 +03:00
// Display Intel AMT version and activation state
2018-03-20 03:31:54 +03:00
mestate = { } ;
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-26 03:28:52 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-10-11 23:29:50 +03:00
amtMei . getVersion ( function ( result ) { if ( result ) { for ( var version in result . Versions ) { if ( result . Versions [ version ] . Description == 'AMT' ) { mestate . ver = result . Versions [ version ] . Version ; } } } } ) ;
amtMei . getProvisioningState ( function ( result ) { if ( result ) { mestate . ProvisioningState = result ; } } ) ;
amtMei . getProvisioningMode ( function ( result ) { if ( result ) { mestate . ProvisioningMode = result ; } } ) ;
2018-04-22 20:47:53 +03:00
amtMei . getEHBCState ( function ( result ) { if ( result ) { mestate . ehbc = result ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result ) { mestate . controlmode = result ; } } ) ;
amtMei . getMACAddresses ( function ( result ) { if ( result ) { mestate . mac = result ; } } ) ;
amtMei . getLanInterfaceSettings ( 0 , function ( result ) { if ( result ) { mestate . net0 = result ; } } ) ;
amtMei . getLanInterfaceSettings ( 1 , function ( result ) { if ( result ) { mestate . net1 = result ; } } ) ;
2018-03-27 03:13:32 +03:00
amtMei . getUuid ( function ( result ) { if ( ( result != null ) && ( result . uuid != null ) ) { mestate . uuid = result . uuid ; } } ) ;
2018-03-20 03:31:54 +03:00
amtMei . getDnsSuffix ( function ( result ) {
2018-10-11 23:29:50 +03:00
if ( result ) { mestate . dns = result ; }
if ( mestate . ver && mestate . ProvisioningState && mestate . ProvisioningMode ) {
var str = 'Intel AMT v' + mestate . ver ;
if ( mestate . ProvisioningState . stateStr == 'PRE' ) { str += ', pre-provisioning state' ; }
else if ( mestate . ProvisioningState . stateStr == 'IN' ) { str += ', in-provisioning state' ; }
else if ( mestate . ProvisioningState . stateStr == 'POST' ) {
if ( mestate . ProvisioningMode ) {
if ( mestate . controlmode ) {
if ( mestate . ProvisioningMode . modeStr == 'ENTERPRISE' ) { str += ', activated in ' + [ "none" , "client control mode" , "admin control mode" , "remote assistance mode" ] [ mestate . controlmode . controlMode ] ; } else { str += ', activated in ' + mestate . ProvisioningMode . modeStr ; }
} else {
str += ', activated in ' + mestate . ProvisioningMode . modeStr ;
}
2018-04-22 20:47:53 +03:00
}
}
2018-10-11 23:29:50 +03:00
if ( ( mestate . ehbc ) && ( mestate . ehbc . EHBC == true ) ) { str += ', EHBC enabled' ; }
str += '.' ;
if ( mestate . net0 != null ) { str += '\r\nWired ' + ( ( mestate . net0 . enabled == 1 ) ? 'Enabled' : 'Disabled' ) + ( ( mestate . net0 . dhcpEnabled == 1 ) ? ', DHCP' : ', Static' ) + ', ' + mestate . net0 . mac + ( mestate . net0 . address == '0.0.0.0' ? '' : ( ', ' + mestate . net0 . address ) ) ; }
if ( mestate . net1 != null ) { str += '\r\nWireless ' + ( ( mestate . net1 . enabled == 1 ) ? 'Enabled' : 'Disabled' ) + ( ( mestate . net1 . dhcpEnabled == 1 ) ? ', DHCP' : ', Static' ) + ', ' + mestate . net1 . mac + ( mestate . net1 . address == '0.0.0.0' ? '' : ( ', ' + mestate . net1 . address ) ) ; }
console . log ( str + '.' ) ;
} else {
console . log ( 'Intel(R) AMT not supported.' ) ;
2018-04-22 20:47:53 +03:00
}
2018-03-20 03:31:54 +03:00
exit ( 1 ) ;
2017-12-13 03:04:54 +03:00
} ) ;
2018-09-20 21:45:12 +03:00
} else if ( settings . action == 'amtinfodebug' ) {
// Display Intel AMT version and activation state
mestate = { } ;
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-09-20 21:45:12 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
amtMei . getVersion ( function ( result ) { console . log ( 'getVersion: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getProvisioningState ( function ( result ) { console . log ( 'getProvisioningState: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getProvisioningMode ( function ( result ) { console . log ( 'getProvisioningMode: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getEHBCState ( function ( result ) { if ( result ) { console . log ( 'getEHBCState: ' + JSON . stringify ( result ) ) ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result ) { console . log ( 'getControlMode: ' + JSON . stringify ( result ) ) ; } } ) ;
amtMei . getMACAddresses ( function ( result ) { if ( result ) { console . log ( 'getMACAddresses: ' + JSON . stringify ( result ) ) ; } } ) ;
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 ) ) ; } ) ;
2018-01-03 03:52:49 +03:00
} else if ( settings . action == 'amtsavestate' ) {
2018-01-31 05:23:57 +03:00
// Save the entire state of Intel AMT info a JSON file
2018-01-26 03:12:53 +03:00
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 . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
if ( ( settings . output == null ) || ( typeof settings . output != 'string' ) || ( settings . output == '' ) ) { console . log ( 'No or invalid \"output\" file specified, use --output [filename].' ) ; exit ( 1 ) ; return ; }
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2018-01-03 03:52:49 +03:00
saveEntireAmtState ( ) ;
2018-04-04 22:08:28 +03:00
} else if ( ( settings . action == 'microlms' ) || ( settings . action == 'amtlms' ) || ( settings . action == 'lms' ) ) {
2018-01-31 05:23:57 +03:00
// Start Intel AMT MicroLMS
2018-03-20 03:31:54 +03:00
startLms ( function ( state ) {
2018-04-04 22:08:28 +03:00
console . log ( [ 'MicroLMS did not start. Must run as administrator or LMS already active.' , 'MicroLMS started.' , 'MicroLMS started, MeshCommander on HTTP/16994.' , 'MEI error' ] [ state ] ) ; console . log ( 'Press ctrl-c to exit.' ) ; if ( state == 0 ) { exit ( 0 ) ; }
2018-03-20 03:31:54 +03:00
} ) ;
2018-04-29 01:36:10 +03:00
} else if ( settings . action == 'amtpresence' ) {
// Heartbeat a Intel AMT watchdog
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' ; }
if ( ( settings . agent == null ) || ( typeof settings . agent != 'string' ) || ( settings . agent == '' ) ) { console . log ( 'No or invalid \"agent\" specified, use --agent [agent].' ) ; exit ( 1 ) ; return ; }
performAmtAgentPresence ( ) ;
2018-03-13 04:16:06 +03:00
} else if ( settings . action == 'amtscript' ) {
2018-02-02 23:46:09 +03:00
// Start running a MEScript
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 . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
2018-03-07 04:50:44 +03:00
if ( ( settings . script == null ) || ( typeof settings . script != 'string' ) || ( settings . script == '' ) ) { if ( mescriptJSON != '' ) { settings . scriptJSON = mescriptJSON ; } else { console . log ( 'No or invalid \"script\" file specified, use --script [filename].' ) ; exit ( 1 ) ; return ; } }
2018-02-02 23:46:09 +03:00
startMeScript ( ) ;
2018-03-07 04:50:44 +03:00
} else if ( settings . action == 'amtuuid' ) {
// Start running
2018-03-27 03:13:32 +03:00
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 ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
}
2018-03-07 04:50:44 +03:00
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
getAmtUuid ( ) ;
} else if ( settings . action == 'amtccm' ) {
// Start activation to CCM
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
activeToCCM ( ) ;
} else if ( settings . action == 'amtdeactivate' ) {
// Deactivate CCM
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
deactivateCCM ( ) ;
2018-03-21 03:48:03 +03:00
} else if ( settings . action == 'meshcommander' ) { // Start MeshCommander
2018-03-20 03:31:54 +03:00
startMeshCommander ( ) ;
2018-03-21 03:48:03 +03:00
} 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 ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
} else { settings . hostname = '127.0.0.1' ; }
readAmtAuditLog ( ) ;
2017-11-01 02:19:58 +03:00
} else {
2017-12-13 03:04:54 +03:00
console . log ( 'Invalid \"action\" specified.' ) ; exit ( 1 ) ; return ;
2017-11-01 02:19:58 +03:00
}
2017-12-13 03:04:54 +03:00
}
2017-11-01 02:19:58 +03:00
2018-04-29 01:36:10 +03:00
//
// Intel AMT Agent Presence
//
function performAmtAgentPresence ( ) { startLms ( function ( ) { tempWatchdogTimer = setTimeout ( performAmtAgentPresenceRegister , 3000 ) ; } ) ; }
function performAmtAgentPresenceRegister ( ) {
// Setup the Intel AMT WSMAN stack
tempWatchdogTimer = null ;
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
wsstack = new wsman ( transport , '127.0.0.1' , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
amtstack = new amt ( wsstack ) ;
// Register the watchdog
watchdog = { DeviceID : Buffer . from ( guidToStr ( settings . agent . split ( '-' ) . join ( '' ) ) . split ( '-' ) . join ( '' ) , 'hex' ) . toString ( 'base64' ) , Retry : 0 } ;
amtstack . AMT _AgentPresenceWatchdog _RegisterAgent ( performAmtAgentPresenceRegisterRetry , watchdog , watchdog . Seq , { 'DeviceID' : watchdog . DeviceID } ) ;
}
// Called after the agent is registered
function performAmtAgentPresenceRegisterRetry ( stack , name , response , status , watchdog ) {
if ( ( status == 200 ) && ( response . Body . SessionSequenceNumber ) && ( response . Body . TimeoutInterval ) ) {
console . log ( 'Asserting presence of the watchdog...' ) ;
watchdog . Seq = response . Body . SessionSequenceNumber ;
watchdog . Interval = response . Body . TimeoutInterval * 800 ;
watchdog . Retry = 0 ;
tempWatchdogTimer = setTimeout ( performAmtAgentPresenceAssert , watchdog . Interval ) ;
} else {
debug ( 1 , 'Failed to register, status = ' + status ) ;
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
tempWatchdogTimer = setTimeout ( function ( ) { amtstack . AMT _AgentPresenceWatchdog _RegisterAgent ( performAmtAgentPresenceRegisterRetry , watchdog , watchdog . Seq , { 'DeviceID' : watchdog . DeviceID } ) ; } , 1000 ) ;
} else {
console . log ( 'Failed to register this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
// Start a new agent assert
function performAmtAgentPresenceAssert ( ) {
watchdog . Seq ++ ;
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceAssertRetry , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
}
// Called after the agent is asserted
function performAmtAgentPresenceAssertRetry ( stack , name , response , status , watchdog ) {
if ( status == 200 ) {
debug ( 1 , 'Succesful assert, sequence = ' + watchdog . Seq ) ;
watchdog . Retry = 0 ;
tempWatchdogTimer = setTimeout ( performAmtAgentPresenceAssert , watchdog . Interval ) ;
} else {
debug ( 1 , 'Failed to assert, status = ' + status ) ;
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceAssertRetry , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
} else {
console . log ( 'Failed to assert presence on this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
function performAmtAgentPresenceEx5 ( stack , name , response , status , watchdog ) {
console . log ( 'b' , status , watchdog ) ;
if ( status == 200 ) {
watchdog . Retry = 0 ;
} else {
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceEx4 , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
} else {
console . log ( 'Failed to assert presence on this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
2018-03-13 04:16:06 +03:00
2018-03-21 03:48:03 +03:00
//
// Intel AMT Audit Log
//
function readAmtAuditLog ( ) {
// See if MicroLMS needs to be started
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( readAmtAuditLogEx ) ;
} else {
readAmtAuditLogEx ( 9999 ) ;
}
}
function readAmtAuditLogEx ( x ) {
if ( x == 9999 ) {
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 . GetAuditLog ( readAmtAuditLogEx2 ) ;
} else {
osamtstack . GetAuditLog ( readAmtAuditLogEx2 ) ;
}
}
function readAmtAuditLogEx2 ( stack , response , status ) {
if ( status != 200 ) {
console . log ( 'Unable to get audit log, status = ' + status + '.' ) ;
} else {
var out = '' ;
for ( var i in response ) {
2018-04-04 22:08:28 +03:00
var name = ( ( response [ i ] . Initiator != '' ) ? ( response [ i ] . Initiator + ': ' ) : '' )
2018-03-21 03:48:03 +03:00
out += ( response [ i ] . Time + ' - ' + name + response [ i ] . Event + '\r\n' ) ;
}
2019-01-03 05:34:50 +03:00
if ( settings . output == null ) { console . log ( out ) ; } else { var file = fs . openSync ( settings . output , 'w' ) ; fs . writeSync ( file , Buffer . from ( out , 'utf8' ) ) ; fs . closeSync ( file ) ; }
2018-03-21 03:48:03 +03:00
}
exit ( 1 ) ;
}
2018-03-20 03:31:54 +03:00
//
// MeshCommander local web server
//
function startMeshCommander ( ) {
2019-03-02 04:13:11 +03:00
// MeshCommander Local v0.7.4
var _IntelAmtLocalWebApp _etag = "LlnBXeX//SEsHV5KjuEC" ;
var _IntelAmtLocalWebApp = " H4sIAAAAAAAEAMQ5h3ajOtOvwu / ckpwNG8DGNd5zcEn3Jk7PPVWADEoEIiCMHZ + 82 P + 1 R / pe4ZMMxBDI7vr6Flc00vTRSCP99x //2f+/wXn/+uFiKNjUwV/2+a8Q0DmGXRsiy6ZtWZJ+ZnAIzC/7DqSADaSeCJ9DNO3eizea2CeOByjSMRQM4lLo0m7leNiFpgUrMcoKTuGM7nEeHcMGfgBpN6QTsVnJEu3Hg8XruQcTfBc4sDshvgOoaEIKDYqIm6WKoWcTF3Zdwlhi5D4JPsTdCmJDKgJlhLrIARbc81xLsH046VZMQEH7DdjRQQDrtV102zu/jKTTQ4t0GaWlIb7oxJwvMt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92RazB1OB09C23u6XJhvcZJS4cr65lheJUrUhyef9Plq79RnNcbD1THn+cdthOkxMLqTw1lKAWOg1QuM/CJ+520Ud73Hm+B+/qTEBPQgb7mJsJvOiOC7FTlV/iGklfC6fTYWfAYEKjxqhchO/XpMwlDKiqehTYFo/hsbFTDh1ZwuaaOXXdp1p4s4zOM1yyjcUwQTDqBYeVXuzNiCdIRb7eIYcqunkCHXkGmbzzGReyBjYNUwitoeYhVu2EnVHhbDWgkxlIQe3MJMarZpv9dS9ycjNv6Q6voPXRQV/DNJo35w8aX+Rs+/59dY7KnjPyFGEaDa0U35/iiaBjgwEgX4R0XWPR2ydhUwdbWrVoJMnK6CuWay80+EU3pYTzRe5LYCkgAywlg1NQsb1UVAxR348ptso4/oxDF/Qof4BEO6WespYanfAN4ykbWIwIF+fJA1jRSbCXgeVgdWTyYN9GEzzeBaiwBAn
2018-03-20 03:31:54 +03:00
if ( settings . localport == null ) { settings . localport = 3000 ; }
// Start the web server
var http = require ( 'http' ) ;
webServer = http . createServer ( ) ;
webServer . listen ( settings . localport ) ;
2018-03-21 03:48:03 +03:00
webServer . wsList = { } ;
webServer . wsListIndex = 0 ;
2018-03-20 03:31:54 +03:00
webServer . on ( 'upgrade' , function ( req , socket , head ) {
//console.log("WebSocket for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/webrelay.ashx' : // MeshCommander relay channel
var ws = socket . upgradeWebSocket ( ) ;
socket . ws = ws ;
2018-03-21 03:48:03 +03:00
ws . wsIndex = ++ webServer . wsListIndex ;
2018-03-22 01:39:16 +03:00
webServer . wsList [ ws . wsIndex ] = ws ; // Keep a reference so the websocket and forwarder don't get disposed.
2018-03-20 03:31:54 +03:00
ws . pause ( ) ;
// We got a new web socket connection, initiate a TCP connection to the target Intel AMT host/port.
var webargs = parseUrlArguments ( req . url ) ;
if ( webargs . p ) { webargs . p = parseInt ( webargs . p ) ; }
if ( webargs . tls ) { webargs . tls = parseInt ( webargs . tls ) ; }
if ( webargs . tls1only ) { webargs . tls1only = parseInt ( webargs . tls1only ) ; }
if ( webargs . port ) { webargs . port = parseInt ( webargs . port ) ; }
//console.log('Opening web socket connection to ' + webargs.host + ':' + webargs.port + '.');
if ( webargs . tls == 0 ) {
// If this is TCP (without TLS) set a normal TCP socket
var net = require ( 'net' ) ;
ws . forwardclient = net . connect ( { host : webargs . host , port : webargs . port } )
2018-03-22 01:39:16 +03:00
ws . forwardclient . on ( 'connect' , function ( ) { this . pipe ( this . ws , { end : false } ) ; this . ws . pipe ( this , { end : false } ) ; } ) ;
2018-03-20 03:31:54 +03:00
ws . forwardclient . ws = ws ;
} else {
// If TLS is going to be used, setup a TLS socket
var tls = require ( 'tls' ) ;
var tlsoptions = { host : webargs . host , port : webargs . port , secureProtocol : ( ( webargs . tls1only == 1 ) ? 'TLSv1_method' : 'SSLv23_method' ) , rejectUnauthorized : false } ;
2018-03-22 01:39:16 +03:00
ws . forwardclient = tls . connect ( tlsoptions , function ( ) { this . pipe ( this . ws , { end : false } ) ; this . ws . pipe ( this , { end : false } ) ; } ) ;
2018-03-20 03:31:54 +03:00
ws . forwardclient . ws = ws ;
}
2018-03-22 01:39:16 +03:00
// Handle pipe closure
ws . on ( 'end' , function ( ) { try { this . forwardclient . end ( ) ; } catch ( e ) { } delete webServer . wsList [ this . wsIndex ] ; } ) ;
ws . forwardclient . on ( 'end' , function ( ) { try { this . ws . end ( ) ; } catch ( e ) { } } ) ;
2018-03-20 03:31:54 +03:00
break ;
default :
socket . end ( ) ;
break ;
}
} ) ;
webServer . on ( 'request' , function ( req , rsp ) {
//console.log("WebRequest for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/' : // Serve MeshCommander Web Application
var meshcommander = null ;
try { meshcommander = fs . readFileSync ( 'meshcommander.htm' ) ; } catch ( e ) { }
if ( meshcommander != null ) {
rsp . writeHead ( 200 , 'OK' , { Server : 'JSLMS' , 'Cache-Control' : 'max-age=0, no-cache' , 'X-Frame-Options' : 'DENY' , 'Content-Type' : 'text/html' , 'Transfer-Encoding' : 'chunked' } ) ;
rsp . end ( meshcommander ) ;
} else {
rsp . writeHead ( 200 , 'OK' , { Server : 'JSLMS' , 'Cache-Control' : 'max-age=0, no-cache' , 'X-Frame-Options' : 'DENY' , 'Content-Type' : 'text/html' , 'Content-Encoding' : 'gzip' , 'Transfer-Encoding' : 'chunked' , ETag : _IntelAmtLocalWebApp _etag } ) ;
rsp . end ( Buffer . from ( _IntelAmtLocalWebApp , 'base64' ) ) ;
}
break ;
default : // Unknown request
rsp . statusCode = 404 ;
rsp . statusMessage = "Not Found" ;
rsp . end ( ) ;
break ;
}
} ) ;
console . log ( 'MeshCommander running on HTTP port ' + settings . localport + '.' ) ;
console . log ( 'Press ctrl-c to exit.' ) ;
}
2018-03-07 04:50:44 +03:00
//
// Deactivate Intel AMT CCM
//
// When called, this will use MEI to deactivate Intel AMT when it's in CCM mode. Simply calls "unprovision" on MEI and checks the return code.
function deactivateCCM ( ) {
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-07 04:50:44 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-20 03:31:54 +03:00
amtMei . unprovision ( 1 , function ( status ) { if ( status == 0 ) { console . log ( 'Success' ) ; } else { console . log ( 'Error ' + status ) ; } exit ( 1 ) ; } ) ;
2018-03-07 04:50:44 +03:00
}
//
// Activate Intel AMT to CCM
//
function activeToCCM ( ) {
// See if MicroLMS needs to be started and setup the $$OsAdmin wsman stack
settings . noconsole = true ;
startLms ( activeToCCMEx ) ; // TODO: Fix this so that it works even if LMS already running.
}
function activeToCCMEx ( state ) {
osamtstack . BatchEnum ( null , [ '*AMT_GeneralSettings' , '*IPS_HostBasedSetupService' ] , activeToCCMEx2 ) ;
}
function activeToCCMEx2 ( stack , name , responses , status ) {
if ( status != 200 ) { console . log ( 'Failed to fetch activation status, status ' + status ) ; exit ( 1 ) ; }
else if ( responses [ 'IPS_HostBasedSetupService' ] . response [ 'AllowedControlModes' ] . length != 2 ) { console . log ( 'Client control mode activation not allowed' ) ; exit ( 1 ) ; }
2018-04-04 22:08:28 +03:00
else { osamtstack . IPS _HostBasedSetupService _Setup ( 2 , md5hex ( 'admin:' + responses [ 'AMT_GeneralSettings' ] . response [ 'DigestRealm' ] + ':' + settings . password ) . substring ( 0 , 32 ) , null , null , null , null , activeToCCMEx3 ) ; }
2018-03-07 04:50:44 +03:00
}
function activeToCCMEx3 ( stack , name , responses , status ) {
if ( status != 200 ) { console . log ( 'Failed to activate, status ' + status ) ; }
else if ( responses . Body . ReturnValue != 0 ) { console . log ( 'Client control mode activation failed: ' + responses . Body . ReturnValueStr ) ; }
else { console . log ( 'Success' ) ; exit ( 0 ) ; }
exit ( 1 ) ;
}
//
// Get AMT UUID
//
// Called to get the UUID of Intel AMT, start by setting up MicroLMS if we are doing the operation on the local computer
function getAmtUuid ( ) {
2018-03-27 03:13:32 +03:00
if ( settings . hostname == null ) {
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-27 03:13:32 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
amtMei . getUuid ( function ( result ) { if ( ( result == null ) || ( result . uuid == null ) ) { console . log ( 'Failed.' ) ; } else { console . log ( result . uuid ) ; } exit ( 1 ) ; } ) ;
} else {
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) { settings . noconsole = true ; startLms ( getAmtUuidEx ) ; return ; } else { getAmtUuidEx ( ) ; }
}
2018-03-07 04:50:44 +03:00
}
// Fetch the computer's UUID by fetching the CIM_ComputerSystemPackage WSMAN object.
function getAmtUuidEx ( ) {
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 . Get ( "CIM_ComputerSystemPackage" , function ( obj , name , response , xstatus , tag ) {
if ( xstatus == 200 ) { console . log ( "GUID: " + guidToStr ( response . Body . PlatformGUID . toLowerCase ( ) ) ) ; } else { console . log ( "Intel AMT is not available or not activated." ) ; } exit ( 1 ) ;
} ) ;
}
2018-02-02 23:46:09 +03:00
//
// Run MESCRIPT
//
2018-03-07 04:50:44 +03:00
// Run a .mescript targeting local or remote Intel AMT.
2018-02-02 23:46:09 +03:00
function startMeScript ( ) {
// See if MicroLMS needs to be started
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) { settings . noconsole = true ; startLms ( startMeScriptEx ) ; return ; } else { startMeScriptEx ( ) ; }
}
function startMeScriptEx ( ) {
2018-03-07 04:50:44 +03:00
//console.log('Running script...');
2018-02-02 23:46:09 +03:00
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 ) ;
2018-02-08 05:45:14 +03:00
//IntelAmtEntireStateProgress = 101;
//amtstack.onProcessChanged = onWsmanProcessChanged;
2018-02-02 23:46:09 +03:00
var scriptData = null ;
2018-03-07 04:50:44 +03:00
if ( settings . script != null ) {
try { scriptData = fs . readFileSync ( settings . script ) ; } catch ( e ) { console . log ( 'Unable to read script file (1): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
} else {
scriptData = settings . scriptJSON ;
2018-04-04 22:08:28 +03:00
}
2018-02-02 23:46:09 +03:00
if ( scriptData == null ) { console . log ( 'Unable to read script file (2): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
try { scriptData = JSON . parse ( scriptData ) ; } catch ( e ) { console . log ( 'Unable to read script file (3): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
if ( scriptData . mescript == null ) { console . log ( 'Unable to read script file (4): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
var scriptData = Buffer . from ( scriptData . mescript , 'base64' ) ;
var scriptModule = require ( 'amt-script' ) ;
var script = scriptModule . setup ( scriptData , { } )
script . amtstack = amtstack ;
script . start ( ) ;
2018-04-04 22:08:28 +03:00
script . onCompleted = function ( ) { exit ( 1 ) ; }
2018-02-02 23:46:09 +03:00
}
2018-01-31 05:23:57 +03:00
2018-03-07 04:50:44 +03:00
2018-01-31 05:23:57 +03:00
//
// FETCH ALL INTEL AMT STATE
//
2018-01-26 03:28:52 +03:00
2019-03-02 04:13:11 +03:00
function saveEntireAmtState2 ( )
{
2018-01-26 03:12:53 +03:00
console . log ( 'Fetching all Intel AMT state, this may take a few minutes...' ) ;
2018-01-31 05:23:57 +03:00
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
2018-04-04 22:08:28 +03:00
wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
2018-01-03 03:52:49 +03:00
amtstack = new amt ( wsstack ) ;
2018-01-26 03:28:52 +03:00
amtstack . onProcessChanged = onWsmanProcessChanged ;
//var AllWsman = "AMT_GeneralSystemDefenseCapabilities".split(',');
2018-01-03 03:52:49 +03:00
var AllWsman = " AMT _8021xCredentialContext , AMT _8021XProfile , AMT _ActiveFilterStatistics , AMT _AgentPresenceCapabilities , AMT _AgentPresenceInterfacePolicy , AMT _AgentPresenceService , AMT _AgentPresenceWatchdog , AMT _AgentPresenceWatchdogAction , AMT _AlarmClockService , IPS _AlarmClockOccurrence , AMT _AssetTable , AMT _AssetTableService , AMT _AuditLog , AMT _AuditPolicyRule , AMT _AuthorizationService , AMT _BootCapabilities , AMT _BootSettingData , AMT _ComplexFilterEntryBase , AMT _CRL , AMT _CryptographicCapabilities , AMT _EACCredentialContext , AMT _EndpointAccessControlService , AMT _EnvironmentDetectionInterfacePolicy , AMT _EnvironmentDetectionSettingData , AMT _EthernetPortSettings , AMT _EventLogEntry , AMT _EventManagerService , AMT _EventSubscriber , AMT _FilterEntryBase , AMT _FilterInSystemDefensePolicy , AMT _GeneralSettings , AMT _GeneralSystemDefenseCapabilities , AMT _Hdr8021Filter , AMT _HeuristicPacketFilterInterfacePolicy , AMT _HeuristicPacketFilterSettings , AMT _HeuristicPacketFilterStatistics , AMT _InterfacePolicy , AMT _IPHeadersFilter , AMT _KerberosSettingData , AMT _ManagementPresenceRemoteSAP , AMT _MessageLog , AMT _MPSUsernamePassword , AMT _NetworkFilter , AMT _NetworkPortDefaultSystemDefensePolicy , AMT _NetworkPortSystemDefenseCapabilities , AMT _NetworkPortSystemDefensePolicy , AMT _PCIDevice , AMT _PETCapabilities , AMT _PETFilterForTarget , AMT _PETFilterSetting , AMT _ProvisioningCertificateHash , AMT _PublicKeyCertificate , AMT _PublicKeyManagementCapabilities , AMT _PublicKeyManagementService , AMT _PublicPrivateKeyPair , AMT _RedirectionService , AMT _RemoteAccessCapabilities , AMT _RemoteAccessCredentialContext , AMT _RemoteAccessPolicyAppliesToMPS , AMT _RemoteAccessPolicyRule , AMT _RemoteAccessService , AMT _SetupAndConfigurationService , AMT _SNMPEventSubscriber , AMT _StateTransitionCondition , AMT _SystemDefensePolicy , AMT _SystemDefensePolicyInService , AMT _SystemDefenseService , AMT _SystemPowerScheme , AMT _ThirdPartyDataStorageAdministrationService , AMT _ThirdPartyDataStorageService , AMT _TimeSynchronizationService , AMT _TLSCredentialContext , AMT _TLSProtocolEndpoint , AMT _TLSProtocolEndpointCollection , AMT _TLSSettingData , AMT _TrapTargetForService , AMT _UserInitiatedConnectionService , AMT _WebUIService , AMT _WiFiPortConfigurationService , CIM _AbstractIndicationSubscription , CIM _Account , CIM _AccountManagementCapabilities , CIM _AccountManagementService , CIM _AccountOnSystem , CIM _AdminDomain , CIM _AlertIndication , CIM _AssignedIdentity , CIM _AssociatedPowerManagementService , CIM _AuthenticationService , CIM _AuthorizationService , CIM _BIOSElement , CIM _BIOSFeature , CIM _BIOSFeatureBIOSElements , CIM _BootConfigSetting , CIM _BootService , CIM _BootSettingData , CIM _BootSourceSetting , CIM _Capabilities , CIM _Card , CIM _Chassis , CIM _Chip , CIM _Collection , CIM _Component , CIM _ComputerSystem , CIM _ComputerSystemPackage , CIM _ConcreteComponent , CIM _ConcreteDependency , CIM _Controller , CIM _CoolingDevice , CIM _Credential , CIM _CredentialContext , CIM _CredentialManagementService , CIM _Dependency , CIM _DeviceSAPImplementation , CIM _ElementCapabilities , CIM _ElementConformsToProfile , CIM _ElementLocation , CIM _ElementSettingData , CIM _ElementSoftwareIdentity , CIM _ElementStatisticalData , CIM _EnabledLogicalElement , CIM _EnabledLogicalElementCapabilities , CIM _EthernetPort , CIM _Fan , CIM _FilterCollection , CIM _FilterCollectionSubscription , CIM _HostedAccessPoint , CIM _HostedDependency , CIM _HostedService , CIM _Identity , CIM _IEEE8021xCapabilities , CIM _IEEE8021xSettings , CIM _Indication , CIM _IndicationService , CIM _InstalledSoftwareIdentity , CIM _KVMRedirectionSAP , CIM _LANEndpoint , CIM _ListenerDestination , CIM _ListenerDestinationWSManagement , CIM _Location , CIM _Log , CIM _LogEntry , CIM _LogicalDevice , CIM _LogicalElement , CIM _LogicalPort , CIM _LogicalPortCapabilities , CIM _LogManagesRecord , CIM _ManagedCredential , CIM _ManagedElement , CIM _ManagedSystemElement , CIM _MediaAccessDevice , CIM _MemberOfCollection , CIM _Memory , CIM _MessageLog , CIM _NetworkPort , CIM _NetworkPortCapabilities , CIM _NetworkPortConfigurationService , CIM _OrderedComponent , CIM _OwningCollectionElement , CIM _OwningJobElement , CIM _PCIController , CIM _PhysicalComponent , CIM _PhysicalElement , CIM _PhysicalElementLocation , CIM _PhysicalFrame , CIM _PhysicalMemory , CIM _PhysicalPackage , CIM _Policy , CIM _PolicyAction , CIM _PolicyCondition , CIM _PolicyInSystem , CIM _PolicyRule , CIM _PolicyR
2018-01-26 03:28:52 +03:00
IntelAmtEntireStateProgress = 101 ;
2018-01-03 03:52:49 +03:00
IntelAmtEntireStateCalls = 3 ;
IntelAmtEntireState = { 'localtime' : Date ( ) , 'utctime' : new Date ( ) . toUTCString ( ) , 'isotime' : new Date ( ) . toISOString ( ) } ;
amtstack . BatchEnum ( null , AllWsman , saveEntireAmtStateOk2 , null , true ) ;
amtstack . GetAuditLog ( saveEntireAmtStateOk3 ) ;
amtstack . GetMessageLog ( saveEntireAmtStateOk4 ) ;
2019-03-02 04:13:11 +03:00
}
// Save the entire Intel AMT state
function saveEntireAmtState ( )
{
// See if MicroLMS needs to be started
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) )
{
settings . noconsole = true ;
startLms ( ) . then ( saveEntireAmtState2 ) ;
}
else
{
saveEntireAmtState2 ( ) ;
}
2018-01-03 03:52:49 +03:00
}
2018-01-26 03:28:52 +03:00
function onWsmanProcessChanged ( a , b ) { var x = Math . floor ( ( a * 100 ) / b ) ; if ( x < IntelAmtEntireStateProgress ) { IntelAmtEntireStateProgress = x ; console . log ( ( 100 - x ) + '%' ) ; } }
function saveEntireAmtStateOk2 ( stack , name , responses , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'wsmanenums' ] = responses ; saveEntireAmtStateDone ( ) ; }
function saveEntireAmtStateOk3 ( stack , messages , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'auditlog' ] = messages ; saveEntireAmtStateDone ( ) ; }
function saveEntireAmtStateOk4 ( stack , messages , tag , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'eventlog' ] = messages ; saveEntireAmtStateDone ( ) ; }
2018-01-03 03:52:49 +03:00
2018-01-31 05:23:57 +03:00
// Called when the entire state of Intel AMT is fetched.
2018-01-03 03:52:49 +03:00
function saveEntireAmtStateDone ( ) {
if ( -- IntelAmtEntireStateCalls != 0 ) return ;
2018-01-26 03:12:53 +03:00
var out = fs . openSync ( settings . output , 'w' ) ;
2019-03-02 04:13:11 +03:00
fs . writeSync ( out , Buffer . from ( JSON . stringify ( IntelAmtEntireState ) ) ) ;
2018-01-26 03:12:53 +03:00
fs . closeSync ( out ) ;
console . log ( 'Done, results written to ' + settings . output + '.' ) ;
2018-01-03 03:52:49 +03:00
exit ( 1 ) ;
}
2018-01-31 05:23:57 +03:00
//
// FETCH ALL INTEL AMT MEI STATE
//
2017-12-13 03:04:54 +03:00
// Get Intel AMT information using MEI
2018-03-07 04:50:44 +03:00
// TODO: If this call is called many time at once, it's going to cause issues.
2018-03-27 03:13:32 +03:00
var getAmtInfoFetching = null ;
var getAmtInfoFetchingTimer = null ;
2017-12-13 03:04:54 +03:00
function getAmtInfo ( func , tag ) {
if ( amtMei == null ) { if ( func != null ) { func ( null , tag ) ; } return ; }
2018-03-27 03:13:32 +03:00
if ( getAmtInfoFetching != null ) { getAmtInfoFetching . push ( { f : func , t : tag } ) ; return ; }
getAmtInfoFetching = [ { f : func , t : tag } ] ;
2018-03-07 04:50:44 +03:00
amtMeiTmpState = { Flags : 0 , TrustedHashes : [ ] } ; // Flags: 1=EHBC, 2=CCM, 4=ACM
2018-03-27 03:13:32 +03:00
getAmtInfoFetchingTimer = setTimeout ( function ( ) {
// MEI failed to respond, break out and reset everthing.
for ( var i in getAmtInfoFetching ) { if ( getAmtInfoFetching [ i ] . f != null ) { getAmtInfoFetching [ i ] . f ( amtMeiTmpState , getAmtInfoFetching [ i ] . t ) ; } }
getAmtInfoFetching = null ;
getAmtInfoFetchingTimer = null ;
2019-03-02 04:13:11 +03:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-27 03:13:32 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
} , 3000 ) ;
2017-12-13 03:04:54 +03:00
amtMei . getProtocolVersion ( function ( result ) { if ( result != null ) { amtMeiTmpState . MeiVersion = result ; } } ) ;
amtMei . getVersion ( function ( val ) {
amtMeiTmpState . Versions = { } ;
if ( val != null ) {
for ( var version in val . Versions ) { amtMeiTmpState . Versions [ val . Versions [ version ] . Description ] = val . Versions [ version ] . Version ; }
amtMei . getProvisioningMode ( function ( result ) { if ( result != null ) { amtMeiTmpState . ProvisioningMode = result . mode ; } } ) ;
amtMei . getProvisioningState ( function ( result ) { if ( result != null ) { amtMeiTmpState . ProvisioningState = result . state ; } } ) ;
amtMei . getEHBCState ( function ( result ) { if ( ( result != null ) && ( result . EHBC == true ) ) { amtMeiTmpState . Flags += 1 ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result != null ) { if ( result . controlMode == 1 ) { amtMeiTmpState . Flags += 2 ; } if ( result . controlMode == 2 ) { amtMeiTmpState . Flags += 4 ; } } } ) ;
//amtMei.getMACAddresses(function (result) { if (result != null) { amtMeiTmpState.mac = result; } });
amtMei . getDnsSuffix ( function ( result ) { if ( result != null ) { amtMeiTmpState . dns = result ; } } ) ;
amtMei . getHashHandles ( function ( handles ) {
exitOnCount = handles . length ;
for ( var i = 0 ; i < handles . length ; ++ i ) {
amtMei . getCertHashEntry ( handles [ i ] , function ( result ) {
amtMeiTmpState . TrustedHashes . push ( { Active : result . isActive , Default : result . isDefault , HashAlgorithm : result . hashAlgorithm , Name : result . name , Hash : result . certificateHash } ) ;
2018-03-07 04:50:44 +03:00
if ( -- exitOnCount == 0 ) {
amtMeiTmpState . Notifications = lmsNotifications ; amtMeiState = amtMeiTmpState ;
2018-03-27 03:13:32 +03:00
for ( var i in getAmtInfoFetching ) { if ( getAmtInfoFetching [ i ] . f != null ) { getAmtInfoFetching [ i ] . f ( amtMeiTmpState , getAmtInfoFetching [ i ] . t ) ; } }
getAmtInfoFetching = null ;
clearTimeout ( getAmtInfoFetchingTimer ) ;
getAmtInfoFetchingTimer = null ;
2018-03-07 04:50:44 +03:00
}
2017-12-13 03:04:54 +03:00
} ) ;
}
} ) ;
} else {
amtMeiState = amtMeiTmpState ;
amtMeiState . ProvisioningMode = - 858993460 ;
amtMeiState . TrustedHashes = { } ;
2018-02-02 23:46:09 +03:00
amtMeiState . Notifications = lmsNotifications ;
2018-03-07 04:50:44 +03:00
//console.log('getAmtInfo3', JSON.stringify(amtMeiState));
2017-12-13 03:04:54 +03:00
if ( func != null ) { func ( amtMeiState , tag ) ; }
}
} ) ;
}
2018-01-31 05:23:57 +03:00
//
// MicroLMS
//
2018-02-02 23:46:09 +03:00
var lmsControlSockets = { } ;
var lmsControlSocketsNextId = 1 ;
var lmsNotifications = [ ] ;
2018-03-07 04:50:44 +03:00
var amtLms = null ;
2019-03-02 04:13:11 +03:00
var promise = require ( 'promise' ) ;
function startLms ( func )
{
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 ; }
2018-03-07 04:50:44 +03:00
//var amtLms = null;
2017-12-13 03:04:54 +03:00
var http = require ( 'http' ) ;
2019-03-02 04:13:11 +03:00
// MeshCommander LMS v0.7.4
var _IntelAmtWebApp _etag = "W7PrsMdzMZVycLmuKL5r" ;
var _IntelAmtWebApp = " H4sIAAAAAAAEAOy9aVvbWLMo + p1foajP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wlq3c0mSqoUIlVWGzyIbK/qo725MUZKOkWVJ2E6lqFEDuQNORNEY4Ky0toiTtaWaXlFOdLJuQDR0b4ELN7L8c1BpHI1Y4OGRp5thySGllsWICnZmPBR5FE9NHkOs7R9BfULZWq0FfQyp0Zcj+7/qTacxWkJnJxvZPHWPPCyIHu9VzrRsDRB/614exfUXL0btRTq9QFpRkVpalF7hBC5QUlArmFdfYNnNa1MTWcfybzyCUgpqFguekzXEQeCjN9FWpa5yfHGq6rAAgdpb9fjRpL//y/t27zbZgccKm2Vw+dwYgSqMEpzeOeBLymdWCNr4rqdqxQNPN2IE+LeGADFGUzIDcKgG575gLA03LZsC+LwF7FEBXPg+RimWANeol0NRD6CVvOXSGbaVzfKEI6Ooz4MEaDdzhNHRSCS7RvkaDg+EepEGKlC3SnF0kW3CNF1SLbrNL/2nLxLaLPo57NxT59+up0JKyC8+2JnmuBq59SJ52gwVW9P9ftug/RQeLuqfKBk74/Bma0Kg3tNS2NNZ3lvug+kLq9/iMpSL4TQ5NYsyCOJoyjo0yHc+g/dLbVXpOPJ3U+q6vdG03DsLSPtlcxFwxdzTDYP2yVcf/SmtuiTeSXda/1LTE9mybcuLcobIJXNOof+07d8ScXVnBijVPJ46frxpAWrEucrLMKPXMWycPIYI0GYLsURHOFm93bi1cBDkrD2KIlNuZkCyOk3psSi6h8b4YPBT9J+tNeRofAa1tJp4z3x3kVMn6bEfTSbG3MJvsEvTSdLKDxikrlsemD+F9
2018-01-31 05:23:57 +03:00
2019-03-02 04:13:11 +03:00
console . log ( 'Setting up MEI...' ) ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-26 03:28:52 +03:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-20 03:31:54 +03:00
//console.log("PTHI Connected.");
2018-04-04 03:07:48 +03:00
2019-03-02 04:13:11 +03:00
console . log ( 'Setting up LME...' ) ;
2018-03-20 03:31:54 +03:00
amtLms = new lme _heci ( { debug : settings . lmsdebug } ) ;
2019-03-02 04:13:11 +03:00
amtLms . promise = ret ;
2018-03-20 03:31:54 +03:00
amtLms . on ( 'error' , function ( e ) {
2018-04-04 03:07:48 +03:00
console . log ( 'LME connection failed' , e ) ;
2018-03-20 03:31:54 +03:00
setupMeiOsAdmin ( func , amtLms . connected == false ? 0 : 3 ) ;
2019-03-02 04:13:11 +03:00
this . promise . _res ( ) ;
2018-03-20 03:31:54 +03:00
} ) ;
amtLms . on ( 'notify' , function ( data , options , str , code ) {
if ( code == 'iAMT0052-3' ) {
2018-07-03 00:34:10 +03:00
kvmGetData ( ) ;
2018-03-20 03:31:54 +03:00
} else if ( str != null ) {
var notify = { date : Date . now ( ) , str : str , code : code } ;
lmsNotifications . push ( notify ) ;
while ( lmsNotifications . length > 100 ) { lmsNotifications . shift ( ) ; }
var notifyBuf = Buffer . concat ( [ Buffer . from ( '0900' , 'hex' ) , Buffer . from ( JSON . stringify ( notify ) ) ] ) // Add a notification
for ( var i in lmsControlSockets ) { lmsControlSockets [ i ] . write ( notifyBuf ) ; }
}
} ) ;
//console.log('LME Connecting...');
2019-03-02 04:13:11 +03:00
amtLms . on ( 'bind' , function ( mapping ) {
if ( mapping [ 16992 ] ) { this . removeAllListeners ( 'bind' ) ; } else { return ; }
//console.log('LMS Bounded');
2018-03-20 03:31:54 +03:00
amtLms . connected = true ;
2019-03-02 04:13:11 +03:00
this . promise . _res ( ) ;
2018-03-20 03:31:54 +03:00
//console.log("LME Connected.");
if ( settings . noconsole !== true ) {
amtLms . meshCommander = http . createServer ( ) ;
amtLms . meshCommander . listen ( 16994 ) ;
amtLms . meshCommander . on ( 'upgrade' , function ( req , socket , head ) {
//console.log("WebSocket for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/lms.ashx' : // MeshCommander control channel (PTHI)
socket . ws = socket . upgradeWebSocket ( ) ;
socket . ws . on ( 'data' , processLmsControlData ) ;
socket . ws . on ( 'end' , function ( ) { if ( lmsControlSockets [ this . id ] ) { delete lmsControlSockets [ this . id ] ; /*console.log('removeControl', JSON.stringify(lmsControlSockets));*/ } } ) ;
var id = lmsControlSocketsNextId ++ ;
lmsControlSockets [ id ] = socket . ws ;
socket . ws . id = id ;
//socket.ws.write(Buffer.concat([Buffer.from('0900', 'hex'), Buffer.from(JSON.stringify(lmsNotifications))])); // Send out full list of notifications
//console.log('addControl', JSON.stringify(lmsControlSockets));
break ;
case '/webrelay.ashx' : // MeshCommander data channel (LME)
socket . ws = socket . upgradeWebSocket ( ) ;
amtLms . bindDuplexStream ( socket . ws , 'IPv4' , 16992 ) ;
break ;
default :
socket . end ( ) ;
break ;
}
} ) ;
amtLms . meshCommander . on ( 'request' , function ( req , rsp ) {
//console.log("WebRequest for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/' : // Serve MeshCommander Web Application for LMS
var lmscommander = null ;
try { lmscommander = fs . readFileSync ( 'lmscommander.htm' ) ; } catch ( e ) { }
if ( lmscommander != null ) {
rsp . writeHead ( 200 , 'OK' , { Server : 'JSLMS' , 'Cache-Control' : 'max-age=0, no-cache' , 'X-Frame-Options' : 'DENY' , 'Content-Type' : 'text/html' , 'Transfer-Encoding' : 'chunked' } ) ;
rsp . end ( lmscommander ) ;
} else {
rsp . writeHead ( 200 , 'OK' , { Server : 'JSLMS' , 'Cache-Control' : 'max-age=0, no-cache' , 'X-Frame-Options' : 'DENY' , 'Content-Type' : 'text/html' , 'Content-Encoding' : 'gzip' , 'Transfer-Encoding' : 'chunked' , ETag : _IntelAmtWebApp _etag } ) ;
rsp . end ( Buffer . from ( _IntelAmtWebApp , 'base64' ) ) ;
}
break ;
default : // Unknown request
rsp . statusCode = 404 ;
rsp . statusMessage = "Not Found" ;
rsp . end ( ) ;
break ;
}
2017-12-13 03:04:54 +03:00
2018-03-20 03:31:54 +03:00
} ) ;
//console.log("LMS started, MeshCommander on HTTP/16994.");
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 2 ) ; } , 100 ) ;
//console.logReferenceCount(tempTimer);
} else {
//console.log("LMS started.");
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 1 ) ; } , 100 ) ;
//console.logReferenceCount(tempTimer);
}
2018-04-04 22:08:28 +03:00
2017-12-13 03:04:54 +03:00
} ) ;
2019-03-02 04:13:11 +03:00
return ( ret ) ;
2017-12-13 03:04:54 +03:00
}
2018-03-07 04:50:44 +03:00
function setupMeiOsAdmin ( func , state ) {
2019-03-02 04:13:11 +03:00
if ( amtMei == null ) {
2018-03-07 04:50:44 +03:00
if ( func ) { func ( state ) ; }
2019-03-02 04:13:11 +03:00
} else {
amtMei . getLocalSystemAccount ( function ( x ) {
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 ) ;
if ( func ) { func ( state ) ; }
//var AllWsman = "CIM_SoftwareIdentity,IPS_SecIOService,IPS_ScreenSettingData,IPS_ProvisioningRecordLog,IPS_HostBasedSetupService,IPS_HostIPSettings,IPS_IPv6PortSettings".split(',');
//osamtstack.BatchEnum(null, AllWsman, startLmsWsmanResponse, null, true);
//*************************************
// Setup KVM data channel if this is Intel AMT 12 or above
amtMei . getVersion ( function ( x ) {
var amtver = null ;
try { for ( var i in x . Versions ) { if ( x . Versions [ i ] . Description == 'AMT' ) amtver = parseInt ( x . Versions [ i ] . Version . split ( '.' ) [ 0 ] ) ; } } catch ( e ) { }
if ( ( amtver != null ) && ( amtver >= 12 ) ) {
kvmGetData ( 'skip' ) ; // Clear any previous data, this is a dummy read to about handling old data.
tempTimer = 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.
}
} ) ;
} ) ;
}
2018-03-07 04:50:44 +03:00
}
2018-03-09 04:58:22 +03:00
function kvmGetData ( tag ) {
osamtstack . IPS _KVMRedirectionSettingData _DataChannelRead ( kvmDataGetResponse , tag ) ;
}
function kvmDataGetResponse ( stack , name , response , status , tag ) {
2018-07-03 00:34:10 +03:00
if ( ( tag != 'skip' ) && ( status == 200 ) && ( response . Body . ReturnValue == 0 ) ) {
2018-03-09 04:58:22 +03:00
var val = null ;
try { val = Buffer . from ( response . Body . DataMessage , 'base64' ) . toString ( ) ; } catch ( e ) { return }
2018-07-03 00:34:10 +03:00
if ( val != null ) { kvmProcessData ( response . Body . RealmsBitmap , response . Body . MessageId , val ) ; }
2018-03-09 04:58:22 +03:00
}
}
var webRtcDesktop = null ;
function kvmProcessData ( realms , messageId , val ) {
var data = null ;
try { data = JSON . parse ( val ) } catch ( e ) { }
if ( ( data != null ) && ( data . action ) ) {
2018-07-03 00:34:10 +03:00
if ( data . action == 'present' ) { kvmSetData ( JSON . stringify ( { action : 'present' , ver : 1 , platform : process . platform } ) ) ; }
2018-03-09 04:58:22 +03:00
if ( data . action == 'offer' ) {
webRtcDesktop = { } ;
var rtc = require ( 'ILibWebRTC' ) ;
webRtcDesktop . webrtc = rtc . createConnection ( ) ;
webRtcDesktop . webrtc . on ( 'connected' , function ( ) { } ) ;
webRtcDesktop . webrtc . on ( 'disconnected' , function ( ) { webRtcCleanUp ( ) ; } ) ;
webRtcDesktop . webrtc . on ( 'dataChannel' , function ( rtcchannel ) {
webRtcDesktop . rtcchannel = rtcchannel ;
var kvmmodule = require ( 'meshDesktop' ) ;
webRtcDesktop . kvm = kvmmodule . getRemoteDesktopStream ( ) ;
2018-07-03 00:34:10 +03:00
webRtcDesktop . kvm . pipe ( webRtcDesktop . rtcchannel , { dataTypeSkip : 1 , end : false } ) ;
2018-03-09 04:58:22 +03:00
webRtcDesktop . rtcchannel . on ( 'end' , function ( ) { webRtcCleanUp ( ) ; } ) ;
2018-07-03 00:34:10 +03:00
webRtcDesktop . rtcchannel . on ( 'data' , function ( x ) { kvmCtrlData ( this , x ) ; } ) ;
webRtcDesktop . rtcchannel . pipe ( webRtcDesktop . kvm , { dataTypeSkip : 1 , end : false } ) ;
2018-03-09 04:58:22 +03:00
//webRtcDesktop.kvm.on('end', function () { console.log('WebRTC DataChannel closed2'); webRtcCleanUp(); });
//webRtcDesktop.rtcchannel.on('data', function (data) { console.log('WebRTC data: ' + data); });
} ) ;
kvmSetData ( JSON . stringify ( { action : 'answer' , ver : 1 , sdp : webRtcDesktop . webrtc . setOffer ( data . sdp ) } ) ) ;
}
}
}
2018-07-03 00:34:10 +03:00
// Polyfill path.join
var path = {
join : function ( ) {
var x = [ ] ;
for ( var i in arguments ) {
var w = arguments [ i ] ;
if ( w != null ) {
while ( w . endsWith ( '/' ) || w . endsWith ( '\\' ) ) { w = w . substring ( 0 , w . length - 1 ) ; }
if ( i != 0 ) {
while ( w . startsWith ( '/' ) || w . startsWith ( '\\' ) ) { w = w . substring ( 1 ) ; }
}
x . push ( w ) ;
}
}
if ( x . length == 0 ) return '/' ;
return x . join ( '/' ) ;
}
} ;
// Get a formated response for a given directory path
function getDirectoryInfo ( reqpath ) {
var response = { path : reqpath , dir : [ ] } ;
if ( ( ( reqpath == undefined ) || ( reqpath == '' ) ) && ( process . platform == 'win32' ) ) {
// List all the drives in the root, or the root itself
var results = null ;
try { results = fs . readDrivesSync ( ) ; } catch ( e ) { } // TODO: Anyway to get drive total size and free space? Could draw a progress bar.
//console.log('a', objToString(results, 0, ' '));
if ( results != null ) {
for ( var i = 0 ; i < results . length ; ++ i ) {
var drive = { n : results [ i ] . name , t : 1 } ;
if ( results [ i ] . type == 'REMOVABLE' ) { drive . dt = 'removable' ; } // TODO: See if this is USB/CDROM or something else, we can draw icons.
response . dir . push ( drive ) ;
}
}
} else {
// List all the files and folders in this path
if ( reqpath == '' ) { reqpath = '/' ; }
var xpath = path . join ( reqpath , '*' ) ;
var results = null ;
try { results = fs . readdirSync ( xpath ) ; } catch ( e ) { }
if ( results != null ) {
for ( var i = 0 ; i < results . length ; ++ i ) {
if ( ( results [ i ] != '.' ) && ( results [ i ] != '..' ) ) {
var stat = null , p = path . join ( reqpath , results [ i ] ) ;
try { stat = fs . statSync ( p ) ; } catch ( e ) { } // TODO: Get file size/date
if ( ( stat != null ) && ( stat != undefined ) ) {
if ( stat . isDirectory ( ) == true ) {
response . dir . push ( { n : results [ i ] , t : 2 , d : stat . mtime } ) ;
} else {
response . dir . push ( { n : results [ i ] , t : 3 , s : stat . size , d : stat . mtime } ) ;
}
}
}
}
}
}
return response ;
}
// Process KVM control channel data
function kvmCtrlData ( channel , cmd ) {
if ( cmd . length > 0 && cmd . charCodeAt ( 0 ) != 123 ) {
// This is upload data
if ( this . fileupload != null ) {
cmd = Buffer . from ( cmd , 'base64' ) ;
var header = cmd . readUInt32BE ( 0 ) ;
if ( ( header == 0x01000000 ) || ( header == 0x01000001 ) ) {
fs . writeSync ( this . fileupload . fp , cmd . slice ( 4 ) ) ;
channel . write ( { action : 'upload' , sub : 'ack' , reqid : this . fileupload . reqid } ) ;
if ( header == 0x01000001 ) { fs . closeSync ( this . fileupload . fp ) ; this . fileupload = null ; } // Close the file
}
}
return ;
}
//console.log('KVM Ctrl Data', cmd);
try { cmd = JSON . parse ( cmd ) ; } catch ( ex ) { console . error ( 'Invalid JSON: ' + cmd ) ; return ; }
if ( ( cmd . path != null ) && ( process . platform != 'win32' ) && ( cmd . path [ 0 ] != '/' ) ) { cmd . path = '/' + cmd . path ; } // Add '/' to paths on non-windows
switch ( cmd . action ) {
2018-07-14 05:18:43 +03:00
case 'ping' : {
// This is a keep alive
channel . write ( { action : 'pong' } ) ;
break ;
}
2018-07-03 00:34:10 +03:00
case 'ls' : {
/ *
// Close the watcher if required
var samepath = ( ( this . httprequest . watcher != undefined ) && ( cmd . path == this . httprequest . watcher . path ) ) ;
if ( ( this . httprequest . watcher != undefined ) && ( samepath == false ) ) {
//console.log('Closing watcher: ' + this.httprequest.watcher.path);
//this.httprequest.watcher.close(); // TODO: This line causes the agent to crash!!!!
delete this . httprequest . watcher ;
}
* /
// Send the folder content to the browser
var response = getDirectoryInfo ( cmd . path ) ;
if ( cmd . reqid != undefined ) { response . reqid = cmd . reqid ; }
channel . write ( response ) ;
/ *
// Start the directory watcher
if ( ( cmd . path != '' ) && ( samepath == false ) ) {
var watcher = fs . watch ( cmd . path , onFileWatcher ) ;
watcher . tunnel = this . httprequest ;
watcher . path = cmd . path ;
this . httprequest . watcher = watcher ;
//console.log('Starting watcher: ' + this.httprequest.watcher.path);
}
* /
break ;
}
case 'mkdir' : {
// Create a new empty folder
fs . mkdirSync ( cmd . path ) ;
break ;
}
case 'rm' : {
// Remove many files or folders
for ( var i in cmd . delfiles ) {
var fullpath = path . join ( cmd . path , cmd . delfiles [ i ] ) ;
try { fs . unlinkSync ( fullpath ) ; } catch ( e ) { console . log ( e ) ; }
}
break ;
}
case 'rename' : {
// Rename a file or folder
var oldfullpath = path . join ( cmd . path , cmd . oldname ) ;
var newfullpath = path . join ( cmd . path , cmd . newname ) ;
try { fs . renameSync ( oldfullpath , newfullpath ) ; } catch ( e ) { console . log ( e ) ; }
break ;
}
case 'download' : {
// Download a file, to browser
var sendNextBlock = 0 ;
if ( cmd . sub == 'start' ) { // Setup the download
if ( this . filedownload != null ) { channel . write ( { action : 'download' , sub : 'cancel' , id : this . filedownload . id } ) ; delete this . filedownload ; }
this . filedownload = { id : cmd . id , path : cmd . path , ptr : 0 }
try { this . filedownload . f = fs . openSync ( this . filedownload . path , 'rbN' ) ; } catch ( e ) { channel . write ( { action : 'download' , sub : 'cancel' , id : this . filedownload . id } ) ; delete this . filedownload ; }
if ( this . filedownload ) { channel . write ( { action : 'download' , sub : 'start' , id : cmd . id } ) ; }
} else if ( ( this . filedownload != null ) && ( cmd . id == this . filedownload . id ) ) { // Download commands
if ( cmd . sub == 'startack' ) { sendNextBlock = 8 ; } else if ( cmd . sub == 'stop' ) { delete this . filedownload ; } else if ( cmd . sub == 'ack' ) { sendNextBlock = 1 ; }
}
// Send the next download block(s)
while ( sendNextBlock > 0 ) {
sendNextBlock -- ;
2019-01-03 05:34:50 +03:00
var buf = Buffer . alloc ( 4096 ) ;
2018-07-03 00:34:10 +03:00
var len = fs . readSync ( this . filedownload . f , buf , 4 , 4092 , null ) ;
this . filedownload . ptr += len ;
if ( len < 4092 ) { buf . writeInt32BE ( 0x01000001 , 0 ) ; fs . closeSync ( this . filedownload . f ) ; delete this . filedownload ; sendNextBlock = 0 ; } else { buf . writeInt32BE ( 0x01000000 , 0 ) ; }
channel . write ( buf . slice ( 0 , len + 4 ) . toString ( 'base64' ) ) ; // Write as Base64
}
break ;
}
case 'upload' : {
// Upload a file, from browser
if ( cmd . sub == 'start' ) { // Start the upload
if ( this . fileupload != null ) { fs . closeSync ( this . fileupload . fp ) ; }
if ( ! cmd . path || ! cmd . name ) break ;
this . fileupload = { reqid : cmd . reqid } ;
var filepath = path . join ( cmd . path , cmd . name ) ;
try { this . fileupload . fp = fs . openSync ( filepath , 'wbN' ) ; } catch ( e ) { }
if ( this . fileupload . fp ) { channel . write ( { action : 'upload' , sub : 'start' , reqid : this . fileupload . reqid } ) ; } else { this . fileupload = null ; channel . write ( { action : 'upload' , sub : 'error' , reqid : this . fileupload . reqid } ) ; }
}
else if ( cmd . sub == 'cancel' ) { // Stop the upload
if ( this . fileupload != null ) { fs . closeSync ( this . fileupload . fp ) ; this . fileupload = null ; }
}
break ;
}
case 'copy' : {
// Copy a bunch of files from scpath to dspath
for ( var i in cmd . names ) {
var sc = path . join ( cmd . scpath , cmd . names [ i ] ) , ds = path . join ( cmd . dspath , cmd . names [ i ] ) ;
if ( sc != ds ) { try { fs . copyFileSync ( sc , ds ) ; } catch ( e ) { } }
}
break ;
}
case 'move' : {
// Move a bunch of files from scpath to dspath
for ( var i in cmd . names ) {
var sc = path . join ( cmd . scpath , cmd . names [ i ] ) , ds = path . join ( cmd . dspath , cmd . names [ i ] ) ;
if ( sc != ds ) { try { fs . copyFileSync ( sc , ds ) ; fs . unlinkSync ( sc ) ; } catch ( e ) { } }
}
break ;
}
2019-01-05 04:59:13 +03:00
default :
// Unknown action, ignore it.
break ;
2018-07-03 00:34:10 +03:00
}
}
2018-03-09 04:58:22 +03:00
function webRtcCleanUp ( ) {
if ( webRtcDesktop == null ) return ;
if ( webRtcDesktop . rtcchannel ) {
try { webRtcDesktop . rtcchannel . close ( ) ; } catch ( e ) { }
try { webRtcDesktop . rtcchannel . removeAllListeners ( 'data' ) ; } catch ( e ) { }
try { webRtcDesktop . rtcchannel . removeAllListeners ( 'end' ) ; } catch ( e ) { }
delete webRtcDesktop . rtcchannel ;
}
if ( webRtcDesktop . webrtc ) {
try { webRtcDesktop . webrtc . close ( ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'connected' ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'disconnected' ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'dataChannel' ) ; } catch ( e ) { }
delete webRtcDesktop . webrtc ;
}
if ( webRtcDesktop . kvm ) {
try { webRtcDesktop . kvm . end ( ) ; } catch ( e ) { }
delete webRtcDesktop . kvm ;
}
webRtcDesktop = null ;
}
function kvmSetData ( x ) {
osamtstack . IPS _KVMRedirectionSettingData _DataChannelWrite ( Buffer . from ( x ) . toString ( 'base64' ) , function ( ) { } ) ;
}
2018-02-08 05:45:14 +03:00
function startLmsWsmanResponse ( stack , name , responses , status ) {
if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; }
else if ( status != 200 ) { console . log ( 'ERROR: Unable to get object from Intel(R) AMT, status = ' + status + '.' ) ; }
2018-03-07 04:50:44 +03:00
else {
//console.log(JSON.stringify(responses), status);
var amtlogicalelements = responses [ "CIM_SoftwareIdentity" ] . responses ;
if ( amtlogicalelements . length > 0 ) {
var v = getInstance ( amtlogicalelements , "AMT" ) [ "VersionString" ] ;
amtversion = parseInt ( v . split ( '.' ) [ 0 ] ) ;
amtversionmin = parseInt ( v . split ( '.' ) [ 1 ] ) ;
//console.log(amtversion, amtversionmin);
}
}
2018-02-08 05:45:14 +03:00
}
2018-01-31 05:23:57 +03:00
// Process commands in the LMS control channel
2018-02-02 23:46:09 +03:00
// Command 9 is add a notification.
2017-12-13 03:04:54 +03:00
function processLmsControlData ( data ) {
if ( data . length < 2 ) return ;
var cmdid = data . readUInt16LE ( 0 ) ;
switch ( cmdid ) {
case 1 : // Request basic Intel AMT information (CMD = 1)
2018-01-31 05:23:57 +03:00
{ getAmtInfo ( function ( meinfo , socket ) { meinfo . LoginMode = 2 ; socket . write ( Buffer . concat ( [ Buffer . from ( '0100' , 'hex' ) , Buffer . from ( JSON . stringify ( meinfo ) ) ] ) ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 2 : // Intel AMT MEI Unprovision (CMD = 2)
2019-01-03 05:34:50 +03:00
{ if ( data . length < 6 ) break ; amtMei . unprovision ( data . readUInt32LE ( 2 ) , function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 2 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 3 : // Intel AMT MEI GetLocalSystemAccount (CMD = 3)
2018-04-04 22:08:28 +03:00
{ amtMei . getLocalSystemAccount ( function ( account , socket ) { socket . write ( Buffer . concat ( [ Buffer . from ( '030000000000' , 'hex' ) , account . raw ] ) ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 4 : // Instruct Intel AMT to start remote configuration (CMD = 4)
2019-01-03 05:34:50 +03:00
{ amtMei . startConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 5 : // Instruct Intel AMT to stop remote configuration (CMD = 5)
2019-01-03 05:34:50 +03:00
{ amtMei . stopConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 6 : // Instruct Intel AMT connect CIRA (CMD = 6)
2019-01-03 05:34:50 +03:00
{ amtMei . openUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 7 : // Instruct Intel AMT disconnect CIRA (CMD = 7)
2019-01-03 05:34:50 +03:00
{ amtMei . closeUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-13 03:04:54 +03:00
case 8 : // Get Intel AMT CIRA State (CMD = 8)
2019-01-03 05:34:50 +03:00
{ amtMei . getRemoteAccessConnectionStatus ( function ( state , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 8 , 0 ) ; data . writeUInt32LE ( state . status , 2 ) ; socket . write ( Buffer . concat ( [ data , state . raw ] ) ) ; } , this ) ; break ; }
2019-01-05 04:59:13 +03:00
default :
// Unknown action, ignore it.
break ;
2017-12-13 03:04:54 +03:00
}
2017-11-01 02:19:58 +03:00
}
2018-01-31 05:23:57 +03:00
//
// MeshCentral TCP port router
//
2017-11-01 02:19:58 +03:00
function startRouter ( ) {
tcpserver = net . createServer ( OnTcpClientConnected ) ;
2018-03-09 04:58:22 +03:00
tcpserver . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + JSON . stringify ( e ) ) ; exit ( 0 ) ; return ; } ) ;
2017-11-01 02:19:58 +03:00
tcpserver . listen ( settings . localPort , function ( ) {
// We started listening.
if ( settings . remoteName == null ) {
console . log ( 'Redirecting local port ' + settings . localPort + ' to remote port ' + settings . remotePort + '.' ) ;
} else {
console . log ( 'Redirecting local port ' + settings . localPort + ' to ' + settings . remoteName + ':' + settings . remotePort + '.' ) ;
}
2018-03-20 03:31:54 +03:00
console . log ( 'Press ctrl-c to exit.' ) ;
2017-11-01 02:19:58 +03:00
// If settings has a "cmd", run it now.
//process.exec("notepad.exe");
} ) ;
}
// Called when a TCP connect is received on the local port. Launch a tunnel.
function OnTcpClientConnected ( c ) {
try {
// 'connection' listener
debug ( 1 , 'Client connected' ) ;
c . on ( 'end' , function ( ) { disconnectTunnel ( this , this . websocket , 'Client closed' ) ; } ) ;
c . pause ( ) ;
try {
options = http . parseUri ( settings . serverUrl + '?user=' + settings . username + '&pass=' + settings . password + '&nodeid=' + settings . remoteNodeId + '&tcpport=' + settings . remotePort ) ;
2017-12-13 03:04:54 +03:00
} catch ( e ) { console . log ( 'Unable to parse \"serverUrl\".' ) ; process . exit ( 1 ) ; return ; }
2017-11-01 02:19:58 +03:00
options . checkServerIdentity = onVerifyServer ;
2018-01-27 04:01:38 +03:00
options . rejectUnauthorized = false ;
2017-11-01 02:19:58 +03:00
c . websocket = http . request ( options ) ;
c . websocket . tcp = c ;
c . websocket . tunneling = false ;
c . websocket . upgrade = OnWebSocket ;
2018-01-27 04:01:38 +03:00
c . websocket . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + JSON . stringify ( e ) ) ; } ) ;
2017-11-01 02:19:58 +03:00
c . websocket . end ( ) ;
} catch ( e ) { debug ( 2 , e ) ; }
}
// Disconnect both TCP & WebSocket connections and display a message.
function disconnectTunnel ( tcp , ws , msg ) {
if ( ws != null ) { try { ws . end ( ) ; } catch ( e ) { debug ( 2 , e ) ; } }
if ( tcp != null ) { try { tcp . end ( ) ; } catch ( e ) { debug ( 2 , e ) ; } }
debug ( 1 , 'Tunnel disconnected: ' + msg ) ;
}
// Called when the web socket gets connected
function OnWebSocket ( msg , s , head ) {
debug ( 1 , 'Websocket connected' ) ;
s . on ( 'data' , function ( msg ) {
if ( this . parent . tunneling == false ) {
msg = msg . toString ( ) ;
if ( msg == 'c' ) {
this . parent . tunneling = true ; this . pipe ( this . parent . tcp ) ; this . parent . tcp . pipe ( this ) ; debug ( 1 , 'Tunnel active' ) ;
} else if ( ( msg . length > 6 ) && ( msg . substring ( 0 , 6 ) == 'error:' ) ) {
console . log ( msg . substring ( 6 ) ) ;
disconnectTunnel ( this . tcp , this , msg . substring ( 6 ) ) ;
}
}
} ) ;
s . on ( 'error' , function ( msg ) { disconnectTunnel ( this . tcp , this , 'Websocket error' ) ; } ) ;
s . on ( 'close' , function ( msg ) { disconnectTunnel ( this . tcp , this , 'Websocket closed' ) ; } ) ;
s . parent = this ;
}
// Try to discover the location of the mesh server
function discoverMeshServer ( ) { console . log ( 'Looking for server...' ) ; discoveryInterval = setInterval ( discoverMeshServerOnce , 5000 ) ; discoverMeshServerOnce ( ) ; }
// Try to discover the location of the mesh server only once
function discoverMeshServerOnce ( ) {
var interfaces = os . networkInterfaces ( ) ;
for ( var adapter in interfaces ) {
if ( interfaces . hasOwnProperty ( adapter ) ) {
2017-12-13 03:04:54 +03:00
for ( var i = 0 ; i < interfaces [ adapter ] . length ; ++ i ) {
2017-11-01 02:19:58 +03:00
var addr = interfaces [ adapter ] [ i ] ;
multicastSockets [ i ] = dgram . createSocket ( { type : ( addr . family == "IPv4" ? "udp4" : "udp6" ) } ) ;
multicastSockets [ i ] . bind ( { address : addr . address , exclusive : false } ) ;
if ( addr . family == "IPv4" ) {
2018-07-24 03:34:24 +03:00
try {
multicastSockets [ i ] . addMembership ( membershipIPv4 ) ;
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets [ i ] . once ( 'message' , OnMulticastMessage ) ;
multicastSockets [ i ] . send ( settings . serverId , 16989 , membershipIPv4 ) ;
} catch ( e ) { }
2017-11-01 02:19:58 +03:00
}
}
}
}
}
// Called when a multicast packet is received
function OnMulticastMessage ( msg , rinfo ) {
var m = msg . toString ( ) . split ( '|' ) ;
if ( ( m . length == 3 ) && ( m [ 0 ] == 'MeshCentral2' ) && ( m [ 1 ] == settings . serverId ) ) {
settings . serverUrl = m [ 2 ] . replace ( '%s' , rinfo . address ) . replace ( '/agent.ashx' , '/meshrelay.ashx' ) ;
console . log ( 'Found server at ' + settings . serverUrl + '.' ) ;
if ( discoveryInterval != null ) { clearInterval ( discoveryInterval ) ; discoveryInterval = null ; }
startRouter ( ) ;
}
}
2018-01-31 05:23:57 +03:00
//
// PUSH MESHCOMMANDER INTO FIRMWARE
//
2017-12-13 03:04:54 +03:00
function nextStepStorageUpload ( ) {
debug ( 3 , "nextStepStorageUpload" ) ;
getAmtStorage ( function ( statusCode , data ) {
if ( statusCode == 200 ) {
debug ( 2 , "getAmtStorage: " + JSON . stringify ( data , null , 2 ) ) ;
if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'index.htm' ] != null ) ) { nextStepStorageUpload3 ( 'index.htm' ) ; }
else if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'logon.htm' ] != null ) ) { nextStepStorageUpload3 ( 'logon.htm' ) ; }
else if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'logon.htm' ] != null ) ) { nextStepStorageUpload3 ( 'logon.htm' ) ; }
else { nextStepStorageUpload2 ( 'index.htm' , null ) ; }
} else {
console . log ( "Unable to read storage state." ) ;
exit ( ) ;
return ;
}
} ) ;
}
function nextStepStorageUpload2 ( uploadName , linkName ) {
debug ( 3 , "nextStepStorageUpload2" ) ;
if ( settings . webapp == null ) { console . log ( "Done." ) ; exit ( ) ; return ; } else {
console . log ( "Uploading MeshCommander..." ) ;
pushToStorage ( uploadName , linkName , Buffer . from ( settings . webapp , 'base64' ) , function ( statusCode ) {
if ( statusCode == 500 ) { console . log ( "Error, check that computer is powered on." ) ; exit ( ) ; return ; }
if ( statusCode != 200 ) {
if ( uploadName == 'index.htm' ) {
nextStepStorageUpload2 ( 'mesh/commander/console' , 'MeshCommander' ) ;
} else {
console . log ( "Unable to upload MeshCommander, status = " + statusCode + "." ) ; exit ( ) ; return ;
}
} else {
console . log ( "Verifying MeshCommander..." ) ;
verifyStorage ( uploadName , Buffer . from ( settings . webapp , 'base64' ) , function ( verified ) {
if ( verified == true ) { console . log ( 'Done.' ) ; } else { console . log ( 'MeshCommander verification failed.' ) ; }
exit ( ) ; return ;
} ) ;
}
} ) ;
}
}
function nextStepStorageUpload3 ( deleteName ) {
console . log ( "Deleting " + deleteName + " from storage..." ) ;
deleteStorage ( deleteName , function ( statusCode ) {
if ( statusCode == 500 ) { console . log ( "Error, check that computer is powered on." ) ; exit ( ) ; return ; }
if ( statusCode == 200 ) { nextStepStorageUpload ( ) ; } else { console . log ( "Unable to delete " + deleteName + "." ) ; exit ( ) ; return ; }
} ) ;
}
// Fetch the Intel AMT storage document
function getAmtStorage ( func , noretry ) {
var req = digest . request ( { protocol : settings . protocol , method : "GET" , host : settings . hostname , path : "/amt-storage/" , port : settings . localport } ,
function ( response ) {
if ( response . statusCode != 200 ) { console . log ( "Unable to connect to Intel(R) AMT." ) ; func ( response . statusCode , null ) ; }
response . on ( 'data' , function ( chunk ) { if ( response . acc == null ) { response . acc = chunk ; } else { response . acc += chunk ; } } ) ;
response . on ( 'end' , function ( ) {
var data = response . acc . toString ( ) , len , data2 , amtstorage = null ;
try {
do { len = data . length ; data2 = data ; data = data2 . replace ( '\x00' , '' ) ; } while ( data != data2 ) ; // Remove all zero's, this is needed because firmware sometimes returns garbage we must fix.
do { len = data . length ; data2 = data ; data = data2 . replace ( '\x22\x01\x22' , '\x22\x22' ) ; } while ( data != data2 ) ; // "\x01", this is needed because firmware sometimes returns garbage we must fix.
amtstorage = JSON . parse ( data ) ;
} catch ( e ) { console . log ( "Error: Unable to parse Intel AMT response." ) ; func ( null ) ; }
if ( func != null ) { func ( response . statusCode , amtstorage ) ; }
} ) ;
} ) ;
req . on ( 'error' , function ( e ) { console . log ( "Error occured: " + JSON . stringify ( e ) ) ; if ( noretry == true ) { if ( func != null ) { func ( null ) ; } } else { getAmtStorage ( func , true ) ; } } ) ;
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function pushToStorage ( name , linkname , data , func , ptr ) {
if ( ptr == null ) { ptr = 0 ; }
2018-04-04 22:08:28 +03:00
var req = digest . request ( { protocol : settings . protocol , method : "PUT" , host : settings . hostname , path : ( "/amt-storage/" + name + ( ( ptr != 0 ) ? '?append=' : '' ) ) , port : settings . localport } ) ;
2017-12-13 03:04:54 +03:00
req . on ( 'error' , function ( e ) { console . log ( "Error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
2018-01-26 03:12:53 +03:00
req . on ( 'response' , function ( response ) {
debug ( 1 , 'Chunk Done' , data . length , ptr ) ;
if ( ( response . statusCode == 200 ) && ( ptr < data . length ) ) { pushToStorage ( name , linkname , data , func , ptr ) ; } else { if ( func != null ) { func ( response . statusCode ) ; } }
} ) ;
2017-12-13 03:04:54 +03:00
var header = ( ptr > 0 ) ? '<metadata></metadata>' : '<metadata><headers><h>Content-Encoding:gzip</h><h>Content-Type:text/html</h></headers>' + ( ( linkname != null ) ? ( '<link>' + linkname + '</link>' ) : '' ) + '</metadata>' ;
var blocklen = ( ( data . length - ptr ) > ( 7000 - header . length ) ) ? ( 7000 - header . length ) : ( data . length - ptr ) ;
req . write ( Buffer . concat ( [ new Buffer ( header ) , data . slice ( ptr , ptr + blocklen ) ] ) ) ;
ptr += blocklen ;
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function verifyStorage ( name , data , func ) {
2018-01-26 03:12:53 +03:00
var req = digest . request ( { protocol : settings . protocol , method : "GET" , host : settings . hostname , path : ( "/amt-storage/" + name ) , port : settings . localport } ) ;
2017-12-13 03:04:54 +03:00
req . on ( 'error' , function ( e ) { console . log ( "Verify error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
2018-01-26 03:12:53 +03:00
req . on ( 'response' , function ( response ) {
response . ptr = 0 ;
response . ok = true ;
2018-01-27 04:01:38 +03:00
response . on ( 'data' , function ( data2 ) { if ( data2 . toString ( 'hex' ) != data . slice ( response . ptr , response . ptr + data2 . length ) . toString ( 'hex' ) ) { response . ok = false ; console . log ( 'Verifiy failed (' + response . ptr + ', ' + data2 . length + ').' ) ; } response . ptr += data2 . length ; } ) ;
2018-01-26 03:12:53 +03:00
response . on ( 'end' , function ( ) { if ( func != null ) { func ( response . ok ) ; } } ) ;
} ) ;
2017-12-13 03:04:54 +03:00
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function deleteStorage ( name , func , noretry ) {
2018-04-04 22:08:28 +03:00
var req = digest . request ( { protocol : settings . protocol , method : "DELETE" , host : settings . hostname , path : "/amt-storage/" + name , port : settings . localport } ) ;
2017-12-13 03:04:54 +03:00
req . on ( 'error' , function ( e ) { if ( ( e == 'Error: Socket was unexpectedly closed' ) && ( noretry != true ) ) { deleteStorage ( name , func , true ) ; } else { if ( func != null ) { if ( e . statusCode ) { func ( e . statusCode ) ; } else { func ( null ) ; } } } } ) ;
2018-01-26 03:12:53 +03:00
req . on ( 'response' , function ( response ) { if ( func != null ) { func ( response . statusCode ) ; } } ) ;
2017-12-13 03:04:54 +03:00
req . end ( ) ;
}
2018-03-20 03:31:54 +03:00
// Parse URL arguments
function parseUrlArguments ( url ) {
var r = { } , x = url . split ( '?' ) ;
if ( x . length < 2 ) return r ;
x = x [ 1 ] . split ( '&' ) ;
for ( var i in x ) { var j = x [ i ] . indexOf ( '=' ) ; if ( j > 0 ) { r [ x [ i ] . substring ( 0 , j ) . toLowerCase ( ) ] = x [ i ] . substring ( j + 1 ) ; } }
return r ;
}
2018-03-21 03:48:03 +03:00
// Remove a element from a array
function removeItemFromArray ( array , element ) {
2018-12-30 02:24:33 +03:00
var index = array . indexOf ( element ) ;
2018-03-21 03:48:03 +03:00
if ( index !== - 1 ) { array . splice ( index , 1 ) ; }
}
2018-04-04 03:07:48 +03:00
// Run MeshCmd, but before we do, we need to see if what type of service we are going to be
var serviceName = null ;
var serviceOpSpecified = 0 ;
2018-06-07 02:52:21 +03:00
var serviceInstall = 0 ;
2018-04-04 03:07:48 +03:00
2018-04-04 22:08:28 +03:00
for ( var i in process . argv ) {
2018-06-07 02:52:21 +03:00
if ( process . argv [ i ] . toLowerCase ( ) == 'install' ) { serviceInstall = 1 } else if ( process . argv [ i ] . toLowerCase ( ) == 'uninstall' ) { serviceInstall = - 1 }
2018-04-04 22:08:28 +03:00
if ( ( process . argv [ i ] . toLowerCase ( ) == 'microlms' ) || ( process . argv [ i ] . toLowerCase ( ) == 'amtlms' ) || ( process . argv [ i ] . toLowerCase ( ) == 'lms' ) ) { serviceName = 'MicroLMS' ; break ; }
if ( ( process . argv [ i ] . toLowerCase ( ) == 'meshcommander' ) || ( process . argv [ i ] . toLowerCase ( ) == 'commander' ) ) { serviceName = 'MeshCommander' ; break ; }
2018-04-04 03:07:48 +03:00
}
2018-04-04 22:08:28 +03:00
if ( serviceName == null ) {
for ( var i in process . argv ) {
if ( ( process . argv [ i ] . toLowerCase ( ) == 'install' ) || ( process . argv [ i ] . toLowerCase ( ) == 'uninstall' ) ) {
console . log ( 'In order to install/uninstall, a service type must be specified.' ) ;
2018-04-04 03:07:48 +03:00
process . exit ( ) ;
}
}
2018-04-04 22:08:28 +03:00
if ( process . execPath . includes ( 'MicroLMS' ) ) { serviceName = 'MicroLMS' ; }
else if ( process . execPath . includes ( 'MeshCommander' ) ) { serviceName = 'MeshCommander' ; }
else { serviceName = 'not_a_service' ; }
2018-04-04 03:07:48 +03:00
}
2018-06-07 02:52:21 +03:00
if ( serviceInstall == 0 ) {
run ( process . argv ) ;
} else {
2018-08-30 04:47:22 +03:00
var serviceHost = require ( 'service-host' ) ;
2018-06-07 02:52:21 +03:00
var meshcmdService = new serviceHost ( { name : serviceName , startType : 'AUTO_START' } ) ;
// Called when the background service is started.
meshcmdService . on ( 'serviceStart' , function onStart ( ) {
console . setDestination ( console . Destinations . DISABLED ) ; // Disable console.log().
if ( process . execPath . includes ( 'MicroLMS' ) ) { run ( [ process . execPath , 'microlms' ] ) ; } //
else if ( process . execPath . includes ( 'MeshCommander' ) ) { run ( [ process . execPath , 'meshcommander' ] ) ; }
else { console . log ( 'Aborting Service Start, because unknown binary: ' + process . execPath ) ; process . exit ( 1 ) ; }
} ) ;
2018-04-04 03:07:48 +03:00
2018-06-07 02:52:21 +03:00
// Called when the background service is stopping
meshcmdService . on ( 'serviceStop' , function onStop ( ) { console . log ( 'Stopping service' ) ; process . exit ( ) ; } ) ; // The console.log() is for debugging, will be ignored unless "console.setDestination()" is set.
2018-04-04 03:07:48 +03:00
2018-06-07 02:52:21 +03:00
// Called when the executable is not running as a service, run normally.
meshcmdService . on ( 'normalStart' , function onNormalStart ( ) { try { run ( process . argv ) ; } catch ( e ) { console . log ( 'ERROR: ' + e ) ; } } ) ;
meshcmdService . run ( ) ;
}