2019-06-20 03:59:03 +03:00
/ *
Copyright 2018 - 2019 Intel Corporation
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
/ * *
* @ description MeshCmd , command line tool for Intel AMT and MeshCentral .
* @ author Ylian Saint - Hilaire
* @ version v0 . 2.0
* /
// 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); //
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' ;
var settings = null ;
var meshCmdVersion = '***Mesh*Cmd*Version***' ; // Dynamically replaced with MeshCentral version
var amtLms = null , amtMei = null , amtMeiState = null ;
var wsstack = null , amtstack = null ;
var oswsstack = null , osamtstack = null ;
var amtMeiTmpState = null ;
var SMBiosTables = null ;
var globalDebugFlags = 0 ; // 1 = IDER Debug
2019-07-16 00:45:36 +03:00
var pendingAmtConfigActions = 0 ;
2019-09-16 20:49:35 +03:00
var RCSMessageProtocolVersion = 1 ; // RCS Message Protocol Version. Needs to be less than or equal to RCS server Message Protocol Version
2019-06-20 03:59:03 +03:00
2019-07-05 23:28:41 +03:00
// MeshCommander for Firmware (GZIP'ed, Base64) v0.7.8
var Large _IntelAmtWebApp _etag = "zVObfGF4CXPIxvxSUu+3" ;
var Large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vhudlQ7G0RD1+pRLeZv6CC1KklLQO7xRGKQTqUi+NLoxso+6H9iKYtyZec0b1diSP3tsZyWUqvWioM070/b5Gxye7gztGZOVuYYbO2P7jlG12+BtbdAtbbArYOBBqjHjJSmvpbeA+28dbdvwYx2IQYboGwt2peDRMagGNt49YxcBOl+sLW+gNxukByxwYgPU4LpHmmsXYcuXqPyEw/a+jZiOYIVSfEfcO3KeUmlVE2ju/29tVTmriNQrR1Xovc4O5hM1jUXi7IbWLKu8QjG+bHizTxzsCX/JzRuzfk9OIDuaFhlOF7rmWa5STNyPtPF+S2EJxEjPDZwxkzXK+M6x0QPkd0GyRPCU2AhET5YU2ccTqvrd7r9BvNToX0/280jKYmwwWoMElzsgRZacjl15UXMbaixC8oCCZXhxUNYvJB4xjFOLHEX/A8ofhL97ZSXkuRXbvDstZZCo7X4yv+Xep
// MeshCommander LMS (GZIP'ed, Base64) v0.7.8
var _IntelAmtWebApp _etag = "N8Wf/McOVX3T6idS+oh9" ;
var _IntelAmtWebApp = " H4sIAAAAAAAEANQ8iXravLKvokPu35OcPyTegSTwXQI0TRraLF3 + sx9hC3DjrbYcQvP1xe76SPcVrsaWjRXbIZSzhgSwpFk1M5qR1P7ff / 7 vya + G7wcffns1QnPqOr0TeEcRXTqkOyf2bE6PZEn6ibUTbPVOXEIxG0iDJvka2 / fdX5of + 82 B7waY2hOHINP3KPFot3E + 6 hJrRhocJG + n5IEeAo1jc47DiNBuTKfNdqOIdJAObn5YBoTDe9gl3akfupg2LUKJSW3fK2J1SDD3PdL1fEbSsb07FBKn27DZkAaiDFHXdvGMHAbeDM1DMu02LEzxUd54PMERMbR9 + 9 Pp + 5 uF9PZs5ncZpkQRvYlvLR8L2jh28UOz + Ozfk3Dq + IujuW1ZxDue + oz9KXZtZ3mEQxs7 + 2 hOnHtCbRPvowh7UTMioT1NB0b2N3LUCeix6Tt + eDRxsHl3PGFvs9CPPetoMbcpYTTDme01qR8cSdmDQ6Z09RQCQ + yxuSCTO5uyobE5b5rYcfyYHnlMPXlXzMgzFhxiZh13MCkV7a7 / rao1KjeWGr479mPKGmMqwJZle7MjiTXjCXEeLTsKHLxk4vrmHRd9YXuWvwAbKcjfLPYdVyBc2BadJxPBcR / NYUIeSyjmTEEOKOn4yXNC8Ts + urcjmxLrEZ6ZnZl + iMHQEnE4zI6kTWEo2NgLxnFWeJuu68ff5 / LjatplOaCpFSxSe5r4jiUYQnGq9eChaAeytHqe + JT67pERPDAKSoFCZxMChkjAKOFn0xc8PgOhlSFE81SAQWqJDLKWebkl010cRozZwLc9SsKiY + xgjI + / H 0 B o Y u M C P 7 K T W Z j a D 8 Q 6 T h 2 F e 0 j m G t x p j V b w I C C S V O M Y f T 8 I Q n 8 W k i i a 4 E p 0 A F a D U S k j Z J z Z n q A r T Q L h D x x / 9 l g c O 5 l M 8 E R P O + T a H k Q h D C E a H n m U e f X c d q x d 3 7 L 2 B A D S J m R K G M A 0 d h y T O E 6 l G J 3 g I e c / m y U u F + t 5 E s w Y M h f b 3 g 8 g k 3 W j j C 7 z 2 1 Q j o D b W D 3 H R a W L m i 9 4 R Q 8 p I e v i + b h I 6 6 S Q I 9 H g I A I K s M b R I u D I 3 F P m O b a G d U 2 l g v B 5 U k C t N 3 O o Z 3 J z g s D k L s W U T j + 5 S H 6 V E 9 9 H O Z G r J U x N J P + 1 z v S O I Q X s p 9 / J j F q B k x o L E / u C z n b s H q P p 5 v 0 z C f j M K s E l Y Y F m E O D g W X S E l p A g m p i q i P 0 o C y h J 8 + C Q U Q Z P 0 W F p 7 W K v 8 y P X K d S 7 n i m W 6 W R 5 D J O Q a B T 4 A Q n m s a F Q 3 R q P W R f O d t t p W W p O y U F E Q E m w J C 3 Z h i S j h y U S k t k t C z l 6 B r x 0 8 M T G R y 3 C 8 A y D d g h p b i R a Z 7 o t h X p H q o / D O o A 2 v m r g L a k g D f Y J U e a w A E k c t c O g 9 1 t E y J f h h o y A z k h + 5 X i B q Z + r S h U j W D E l A M C z o / F u x L 8 m e j u L Q 2 S 1 m U z N 7 m m V T N 5 J z 9 n 7 o z E f 9 / n X / c n z V v x w o y 4 f O M J S c p f I 5 v m m / t u J 4 f r 1 0 / P e f v 3 2 z Z k v X O F v + L v 4 q H 9 6 3 f v 4 6 m A f m l w v p g v z i t o h + f 3 9 4 e L h 8 o 5 / 2 G b Z + u 3 / Z Z z + A 9 x Q + b p b t s X P x V V b e j y c k m o z 6 y y + j 8 e D d 6 S f / y 7 m / H I z n F / 3 f / n Y 2 f C 8 v F u O B d H G J Z 9 q o 3 z 4 b + l e n y 7 e / x a e j w c f z i + F i P n s / W i x e + 7 P + u / H b L 8 P r x S A c v x n M 1 e X N 4 G q s x 3 7 n 6 s 2 C 9 p 1 R u / V m Q P q 6 5 Z 1 f X N 2 M Z x + + v W 6 d X l 9 f v D 2 9 / j r t X 5 + N 5 9 p v z + Y L 4 t z 8 9 q Y / j L q N P a 5 x 5 e + q 8 Y v R s H 8 1 / D T G 7 n i 4 Y E q 6 K m p w / E S D 5 0 v v / O f g N O z j z 5 7 t v / v 8 1 f Y m 1 x f m B x V f f J M + n 9 3 + F s / 6 F y b F 0 v t z J 5 p M z y + V j x P i D K 8 f 3 v a j W z v 6 8 G V 4 3 v f 7 7 x f d l b T q 3 1 X a t + d v + p c j 8 w 3 5 h b Z w h e 0 c F q U 3 n 0 j / D p P L 0 L x 0 P 4 / P g 4 U d / O 7 0 3 f m Z 8 9 t T 7 V s / + P I a / / a 0 / + W 3 1 x 9 + q 8 1 / O b v 9 O h 9 8 v l H x 7 e X P p 9 6 o / X D e H 4 1 m + P T h e n h t 9 7 X P j j 8 j s 9 v r y 9 f a x z f 9 y N f O 5 u 6 F N 7 r 9 d H f T 6 n + 9 V q 7 v z I 9 v P s r R 3 e D u U z 8 i I 3 O w s g 9 K 3 F M c 5 u t G C 4 I A 8 + 0 s w 5 D q M i 2 + 1 M H a k u o b x 9 T P l 0 F s 2 X G U d F Z E U L M 9 a c v l C G r 6 b h C z r 8 C S a Y f Z N C q F a Y T v I g l N T I E g n o s M w g A R 9 6 N I u c g + y s Q u L J m A I N O O U k K 2 Z p 1 g o + P o s b o 2 s j 2 b 2 t i p L I + A m 6 r y C J a q c n n E W 6 N y Y 6 n h O 4 K A P o C 8 q t L m f 5 1 8 j Z g U r o s 9 p u h D Z l s + D D 0 I v N m v 9 5 7 z I j A n I Z U E h C V 8 4 K O R L g G 6 v S R F k V Y T r E u Z O a V f x Z n i U 8 / r v A N b 2 Y x W U 9 + K m r o h N V n a i p y 2 K b n t p N M 3 J K d s J 5 2 x K b m t p P v y Q q t U j E q r V I y c l m K s p a V s R q u p G N t Q U z e k p i v b U N M 2 p N Z q b 0 N N 3 5 C a L G n b k D M 2 J a d u Y y e w U j 0 i N L U d 1 p e u W y h b C Q q N k Y k d s p u U e M g P s G n T 5 a 7 B H m D j Q K j b m 3 n V K v 2 E o P g o J 0 F Q i E w d H 9 O 0 z E E I l Z a A i s o z B G B W e E 6 T H 4 a a f T c 7 8 O K V Z 2 n t 4 9 0 V S 0 U 5 2 8 K U Y n P u M l p H k R n 6 j g O q U X 5 U L u B 1 U 8 E 4 t w x 3 L u T f T D A 5 + k f N G J b g V S c Y 7 9 5 i x q K / 5 5 R x d t d P 2 f a S O Z N J T K n v 8 W x U K w i h a a V s V C w z h F J f 2 J I r J 9 W 5 y k L i Y G r f k 6 f R g z v / k X S g F 9 j i 6 W f W K R e 6 I u I 8 r o A 6 Y k 9 W E r a V K h m Q x P 9 A H h H 3 + p U U J J y w e V M V H i e f R E l V y a O k q q y L k s 5 E 2 Z y g q m x F U d 2 c o q F t Q d E l X l y u S 8 R R v A C B y V l B 1 B c f x q R j m a 2 k V P E g 7 R 8 z A G H L 9 n U H X o z E Q z O a Y 4 t t l D J v Q j I o L p x N 8 C 6 S 9 v n v g Y r 2 j s v 7 U 6 Z p H q P c a P G E N c e U i P v f j h 3 R Z n K Y l Q p R O k X R e b G Z b 5 T B M 3 7 I n n V 4 / t a 0 m c 4 f W J Y n g T w u i J N t R 2 m a d p y d 6 N g e x I t m e r A j b P e 2 V w V c W h M K L c C x X n j m W 4 T Q V H n Q w v 1 G / y m b V I t M c e z Q 0 p Z z y a N z 9 s X j m W k H X s J 2 c K f D 3 P X k M D 0 H P K E 2 Z R + X 4 1 s 0 J t F 8 k F n h y W H a c Z L s 0 P t e 7 D k + t r o N 0 y H Y i 4 P d v Q Z r 5 P M P B t O d M z C H D F Y W s U v u i U f 3 e i e W f Y 9 s q y s h 0 8 F R 1 E 2 P N h h h P H E I b + N F I z + k X e 1 s 5 v k 4 U x i D A C g L 3 S e b q d 0 G A 2 q g d B e 5 2 0 g / 2 f F m s E I p l 8 U q d i v A l V x C 2 W O i A 2 s J 4 3 x 0 4 R A l l 0 c R j 5 R X P l m 1 I R s S i + F l k O I 7 R 6 V y M t k J B 8 d c 2 D k 2 C T i t Y F a p Q Q v 7 s U x H U Y A 9 Q K n 1 L n 0 M Y w 8 O D k 4 O o Z V N Z Z j + 2 V 4 Q 0 / Q E O Q 3 Z I H 9 M u g P H j w h M q 2 O b d 1 1 m + m x + P W L S 3 b 0 n / O r V / G b O A p a c j O X t J W 0 4 o L E k K c 2 U V z 5 j M 0 Q v A v 3 m 9 I 0 1 B F d J z c u S 5 1 x m 6 v s O W H P y t C v t c X 1 y r K t j B Y a i 9 8 q b R M H x q 5 1 O q 2 U c c x W v 1 F S v 5 R s y D U k 0 z 2 k 6 b s S b d v c 4 F M j Y q g D t m 8 z T M S V s T i s 0 U M S Y j R R Q t i t Q D g l + M d J 8 r I i 2 U 4 H 2 0 m d T u R 5 j M k x A J k s V 2 B r n H i X O q 5 D M j l F / / A F l 2 B t r 0 L N o N L V n c Q j 8 1 n u f L H M 0 f A W B M 4 e n Q 5 T 6 I e J A l Q 9 s l J f N U f J z X G T 2 u L z G 8 d U N T L 6 j r Y x W k g o b h e p q 5 Y I w I B V X W k i w s r + d d v J T X m D B 9 x r F A J e t + T W e I E t y 5 g s g p N Z 7 N W G u n 1 n 9 g O 9 Y I q 7 v d E H j i t m A h l K k o V f M r U j 2 4 + 0 p u i U 0 D g 4 m t o d G l k 3 9 s H J O j P X h i i 9 H d Q F r p y 3 B q 3 D m l q 1 G H O L v E F q o V R 9 T 3 p E F O F t G K 4 4 m f / b I I l H O K T h Y P e T 7 g H h P Q X 3 W V o Y F T V Y F p V t 8 T 5 5 i i F j b C o O 4 o g K e N p d b P A v P k 5 z m k p d I 3 B t K h / G p e 4 C q c p S d c v J Q X j + T 2 R S 2 8 Q G R C o i E 6 R A X 1 S T 6 n E R x U J 4 t 6 I a 4 B L M U B z 0 I T q J Z j r G H Z y T k k 1 h Y o 1 b 7 / 7 0 z Q l k j D i m x 0 G R 5 g u v n k c O K J t Y 7 i X t m S D B l o e H k M G b a x j 2 M G B x s / 5 B 9 E Z 8 4 u f U I Y V g R n 4 f I g x 0 B C Y a N Q B r h h 8 g K 8 Q y 9 Y h 9 + E E A P R l E u O N B G 7 J P O 7 Q i l F 5 0 O q r x T k d a F V n G 4 X L 7 J J 4 T U 1 U i F u 3 1 6 7 6 K o e x 5 H I V O v 8 g z b K i Q /
// MeshCommander Local (GZIP'ed, Base64) v0.7.8
var FullSite _IntelAmtLocalWebApp _etag = "PR80FHg+cPmsp2l3pigx" ;
var FullSite _IntelAmtLocalWebApp = " H4sIAAAAAAAEAMQ5h3ajOtOvwu / ckpwNG8DGNd5zcEn3pm8291QBApQIREAYOz55sf9rj / S9wicZiCGQ3fX1La5opOmjkUb67z / + s / 9 / o / Phzf3FWHCoiz / t818hpHMM + w5EtkO7siT9zOAQmJ / 2 XUgBG0h9ET5FaNr / Kt5q4pC4PqBIx1AwiEehR / u143EfmjasJSgrOIUzusd59AwHBCGk / YhaYruWJzpMBos3cx + m + B5wYd8igQuoaEIKDYqIl6eKoe8QD / Y9wlhi5D0KAcT9GmJDagJlhPrIBTbc8z1bcAJo9WsmoKD7CuzpIITNxi76Mji / iqXTQ5v0GaWlIT7pxJwvctbouWAm5ttkCgMLk7jrINOEXs8iTHwLuAjPuyBAAO8KDsRT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GmGfETHJkhzLqy+FiFMnvsxACUzNEpF+c4VpOwbGWiwI1Is4LbUizyPDuCNp4JJ3uyLWYGpwOvqW293SZMP7jBIXjlfXskJxqlYkubz/B0vXfqM5LraeKY8/Tjtsp8mJhVSeGkpQC50GKNxn4RN3u+ijPe4834N3dSagJyGDfczNBF50x4XYqcovcY2kr4XT6bAzYDChUWNULsL3a1LmEgZUVT0KbIvH8NjYKYeOLGFzzZy67lMtvFlG5xku2cZimCAY9YLDSi/2ZsQTpCJf75BDFd08gY48g0ze+YwLWQObhimE1lDzEKt2ws6ocLYa0MkMpKB2ZhLjVbPN/roXObmZt3SHV9D66KCvYRrNm/MHjS9ytn3/vjpHZc8ZeYowjYZWiu9P8UTQscEAkC9Cuq6x6O2TsKmDLa1aNJJkZfQVy7UXGvyim1LC+SL3JbAUkAGWksEpqNheKiqGqO/HFFtlHH/GoQt6lD9Aop1ST1lLjU74hvGUDSxGhIvz5AGs6CTYy8B
2019-06-20 03:59:03 +03:00
// Check the server certificate fingerprint
function onVerifyServer ( clientName , certs ) {
if ( certs == null ) { certs = clientName ; } // Temporary thing until we fix duktape
try { for ( var i in certs ) { if ( certs [ i ] . fingerprint . replace ( /:/g , '' ) == settings . serverhttpshash ) { return ; } } } catch ( e ) { }
2019-06-23 08:06:50 +03:00
if ( settings . serverhttpshash != null ) {
console . log ( 'Error: Failed to verify server certificate.' ) ;
console . log ( 'Server TLS hash: ' + certs [ i ] . fingerprint . replace ( /:/g , '' ) ) ;
exit ( 255 ) ;
throw 'Invalid server certificate' ;
}
2019-06-20 03:59:03 +03:00
}
// Various utility functions
function debug ( level , message ) { if ( ( settings . debuglevel != null ) && ( settings . debuglevel >= level ) ) { console . log ( message ) ; } }
function exit ( status ) { if ( status == null ) { status = 0 ; } try { process . exit ( status ) ; } catch ( e ) { } }
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 ; }
// 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 ; }
// Parse the incoming arguments
function run ( argv ) {
if ( meshCmdVersion [ 0 ] == '*' ) { meshCmdVersion = '' ; } else { meshCmdVersion = ' v' + meshCmdVersion ; }
var args = parceArguments ( argv ) ;
//console.log(JSON.stringify(argv));
//console.log('addedModules = ' + JSON.stringify(addedModules));
var actionpath = 'meshaction.txt' ;
if ( args . actionfile != null ) { actionpath = args . actionfile ; }
2019-07-16 01:44:18 +03:00
var actions = [ 'HELP' , 'ROUTE' , 'MICROLMS' , 'AMTPOWER' , 'AMTFEATURES' , 'AMTNETWORK' , 'AMTLOADWEBAPP' , 'AMTLOADSMALLWEBAPP' , 'AMTLOADLARGEWEBAPP' , 'AMTCLEARWEBAPP' , 'AMTSTORAGESTATE' , 'AMTINFO' , 'AMTINFODEBUG' , 'AMTVERSIONS' , 'AMTHASHES' , 'AMTSAVESTATE' , 'AMTSCRIPT' , 'AMTUUID' , 'AMTCCM' , 'AMTACM' , 'AMTDEACTIVATE' , 'AMTACMDEACTIVATE' , 'SMBIOS' , 'RAWSMBIOS' , 'MESHCOMMANDER' , 'AMTAUDITLOG' , 'AMTEVENTLOG' , 'AMTPRESENCE' ] ;
2019-06-20 03:59:03 +03:00
// Load the action file
var actionfile = null ;
try { actionfile = fs . readFileSync ( actionpath ) ; } catch ( e ) { }
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 ] } } }
if ( settings == null ) { settings = { } ; }
var settings2 = { } ; for ( var i in settings ) { settings2 [ i . toLowerCase ( ) ] = settings [ i ] ; } settings = settings2 ;
// Set the arguments
if ( ( typeof args . action ) == 'string' ) { settings . action = args . action ; }
if ( ( typeof args . localport ) == 'string' ) { settings . localport = parseInt ( args . localport ) ; }
if ( ( typeof args . remotenodeid ) == 'string' ) { settings . remotenodeid = args . remotenodeid ; }
2019-06-25 04:56:14 +03:00
if ( ( typeof args . name ) == 'string' ) { settings . name = args . name ; }
2019-06-20 03:59:03 +03:00
if ( ( typeof args . username ) == 'string' ) { settings . username = args . username ; }
if ( ( typeof args . password ) == 'string' ) { settings . password = args . password ; }
2019-06-22 03:42:43 +03:00
if ( ( typeof args . url ) == 'string' ) { settings . url = args . url ; }
2019-06-20 03:59:03 +03:00
if ( ( typeof args . profile ) == 'string' ) { settings . profile = args . profile ; }
if ( ( typeof args . type ) == 'string' ) { settings . type = args . type ; }
if ( ( typeof args . user ) == 'string' ) { settings . username = args . user ; }
if ( ( typeof args . pass ) == 'string' ) { settings . password = args . pass ; }
if ( ( typeof args . host ) == 'string' ) { settings . hostname = args . host ; }
if ( ( typeof args . hostname ) == 'string' ) { settings . hostname = args . hostname ; }
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 ) ; }
if ( ( typeof args . out ) == 'string' ) { settings . output = args . out ; }
if ( ( typeof args . output ) == 'string' ) { settings . output = args . output ; }
if ( ( typeof args . debug ) == 'string' ) { settings . debuglevel = parseInt ( args . debug ) ; }
if ( ( typeof args . debugflags ) == 'string' ) { globalDebugFlags = parseInt ( args . debugflags ) ; }
if ( ( typeof args . script ) == 'string' ) { settings . script = args . script ; }
if ( ( typeof args . agent ) == 'string' ) { settings . agent = args . agent ; }
if ( ( typeof args . proxy ) == 'string' ) { settings . proxy = args . proxy ; }
if ( ( typeof args . floppy ) == 'string' ) { settings . floppy = args . floppy ; }
if ( ( typeof args . cdrom ) == 'string' ) { settings . cdrom = args . cdrom ; }
2019-06-25 04:56:14 +03:00
if ( ( typeof args . tag ) == 'string' ) { settings . tag = args . tag ; }
2019-06-20 03:59:03 +03:00
if ( ( typeof args . timeout ) == 'string' ) { settings . timeout = parseInt ( args . timeout ) ; }
if ( args . debug === true ) { settings . debuglevel = 1 ; }
if ( args . debug ) { try { waitForDebugger ( ) ; } catch ( e ) { } }
if ( args . noconsole ) { settings . noconsole = true ; }
if ( args . nocommander ) { settings . noconsole = true ; }
if ( args . lmsdebug ) { settings . lmsdebug = true ; }
2019-07-16 01:44:18 +03:00
if ( args . json ) { settings . json = true ; }
2019-06-20 03:59:03 +03:00
if ( args . tls ) { settings . tls = true ; }
if ( ( argv . length > 1 ) && ( actions . indexOf ( argv [ 1 ] . toUpperCase ( ) ) >= 0 ) ) { settings . action = argv [ 1 ] ; }
// Validate meshaction.txt
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:' ) ;
2019-07-15 22:55:52 +03:00
console . log ( ' Route - Map a local TCP port to a remote computer.' ) ;
2019-06-20 03:59:03 +03:00
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.' ) ;
console . log ( ' MicroLMS - Run MicroLMS, allowing local access to Intel AMT.' ) ;
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 ( ' AmtACM - Activate Intel AMT into Admin Control Mode.' ) ;
console . log ( ' AmtDeactivate - Deactivate Intel AMT if activated in Client Control mode.' ) ;
console . log ( ' AmtAcmDeactivate - Deactivate Intel AMT if activated in Admin Control mode.' ) ;
console . log ( '\r\nValid local or remote actions:' ) ;
console . log ( ' MeshCommander - Launch a local MeshCommander web server.' ) ;
console . log ( ' AmtUUID - Show Intel AMT unique identifier.' ) ;
2019-07-16 01:44:18 +03:00
console . log ( ' AmtEventLog - Show the Intel AMT event log.' ) ;
2019-06-20 03:59:03 +03:00
console . log ( ' AmtAuditLog - Show the Intel AMT audit log.' ) ;
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.' ) ;
console . log ( ' AmtPresence - Heartbeat a local Intel AMT watchdog agent.' ) ;
2019-07-12 02:54:27 +03:00
console . log ( ' AmtPower - Perform remote Intel AMT power operation.' ) ;
2019-06-20 03:59:03 +03:00
console . log ( ' AmtScript - Run .mescript on Intel AMT.' ) ;
console . log ( ' AmtIDER - Mount local disk image to remote computer.' ) ;
2019-07-15 22:55:52 +03:00
console . log ( ' AmtFeatures - Intel AMT features & user consent.' ) ;
2019-07-16 00:45:36 +03:00
console . log ( ' AmtNetwork - Intel AMT network interface settings.' ) ;
2019-06-20 03:59:03 +03:00
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' ) ;
} 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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --noconsole MeshCommander for LMS will no be available on port 16994.' ) ;
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' microlms install/uninstall/start/stop.' ) ;
} else if ( action == 'amtccm' ) {
2019-06-25 04:56:14 +03:00
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.' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --password [password] Admin password used to activate Intel AMT.' ) ;
console . log ( '\r\nor:\r\n' ) ;
console . log ( ' --url [wss://server] Url to the activation server.' ) ;
console . log ( ' --tag [string] Optional string sent to the server during activation.' ) ;
console . log ( ' --serverhttpshash [hash] Optional TLS server certificate hash.' ) ;
console . log ( ' --profile [string] Optional profile used for server activation.' ) ;
2019-06-20 03:59:03 +03:00
} else if ( action == 'amtacm' ) {
2019-06-22 03:42:43 +03:00
console . log ( 'AmtACM will attempt to activate Intel AMT on this computer into admin control mode (ACM). 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. Example usage:\r\n\r\n meshcmd amtacm --url [url]' ) ;
2019-06-20 03:59:03 +03:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2019-06-25 04:56:14 +03:00
console . log ( ' --url [wss://server] The address of the Intel AMT activation server.' ) ;
console . log ( ' --tag [string] Optional string sent to the server during activation.' ) ;
console . log ( ' --serverhttpshash [hash] Optional TLS server certificate hash.' ) ;
console . log ( ' --profile [string] Optional profile used for server activation.' ) ;
2019-06-20 03:59:03 +03:00
} 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 == 'amtacmdeactivate' ) {
console . log ( 'AmtACMDeactivate will attempt to deactivate Intel AMT on this computer when in admin control mode (ACM). 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 admin control mode for this command to work. Example usage:\r\n\r\n meshcmd amtacmdeactivate' ) ;
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 ( ' --type [partial/full] Specifies to perform partial or full unprovision.' ) ;
} 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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
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' ) ;
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.' ) ;
} 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.' ) ;
} 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' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
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.' ) ;
2019-07-12 02:54:27 +03:00
} else if ( action == 'amtpower' ) {
console . log ( 'AmtPower will get current pwoer state or send a reboot command to a remote Intel AMT device. Example usage:\r\n\r\n meshcmd amtpower --reset --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
console . log ( '\r\nRequired arguments:\r\n' ) ;
2019-07-16 00:45:36 +03:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT.' ) ;
2019-07-12 02:54:27 +03:00
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( '\r\nOptional arguments:\r\n' ) ;
console . log ( ' --reset, --poweron, --poweroff, --powercycle, --sleep, --hibernate' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
2019-07-16 00:45:36 +03:00
} else if ( action == 'amtnetwork' ) {
console . log ( 'AmtNetwork is used to get/set Intel AMT network interface configuration. Example usage:\r\n\r\n meshcmd amtnetwork --host 1.2.3.4 --user admin --pass mypassword --dhcp' ) ;
console . log ( '\r\nRequired arguments:\r\n' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( '\r\nOptional arguments:\r\n' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
2019-07-16 22:25:21 +03:00
console . log ( ' --ipsync [0 or 1] Change the wired IPSync setting on Intel AMT 7+' ) ;
2019-07-16 00:45:36 +03:00
console . log ( ' --dhcp Change IPv4 wired interface to DHCP mode' ) ;
console . log ( ' --static Change IPv4 wired interface to static IP mode' ) ;
console . log ( ' --ip [1.2.3.4] Static IPv4 address (required)' ) ;
console . log ( ' --subnet [1.2.3.4] Static IPv4 subnet mask' ) ;
console . log ( ' --gateway [1.2.3.4] Static IPv4 default gateway' ) ;
console . log ( ' --dns [1.2.3.4] Primary DNS IPv4 address' ) ;
console . log ( ' --dns2 [1.2.3.4] Secondary DNS IPv4 address' ) ;
2019-07-15 22:55:52 +03:00
} else if ( action == 'amtfeatures' ) {
console . log ( 'AmtFeatures is used to get/set Intel AMT feature configuration. Example usage:\r\n\r\n meshcmd amtfeatures --host 1.2.3.4 --user admin --pass mypassword --tls --redir 1' ) ;
console . log ( '\r\nRequired arguments:\r\n' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( '\r\nOptional arguments:\r\n' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
console . log ( ' --consent [none/kvm/all] Set Intel AMT user consent feature.' ) ;
console . log ( ' --redir [0/1] Set Intel AMT redirection port feature.' ) ;
console . log ( ' --kvm [0/1] Set Intel AMT KVM feature.' ) ;
console . log ( ' --sol [0/1] Set Intel AMT Serial-over-LAN feature.' ) ;
console . log ( ' --ider [0/1] Set Intel AMT IDE redirection feature.' ) ;
2019-06-20 03:59:03 +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.' ) ;
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' meshcommander install/uninstall/start/stop.' ) ;
2019-07-16 01:44:18 +03:00
} else if ( action == 'amteventlog' ) {
console . log ( 'AmtEventLog action will fetch the local or remote event log. Example usage:\r\n\r\n meshcmd amteventlog --host 1.2.3.4 --user admin --pass mypassword --tls --output events.txt' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --output [filename] The output file for the Intel AMT event log.' ) ;
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.' ) ;
console . log ( ' --json Output as a JSON format.' ) ;
2019-06-20 03:59: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' ) ;
2019-07-16 01:44:18 +03:00
console . log ( ' --output [filename] The output file for the Intel AMT audit log.' ) ;
2019-06-20 03:59:03 +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.' ) ;
2019-07-16 01:44:18 +03:00
console . log ( ' --json Output as a JSON format.' ) ;
2019-06-20 03:59:03 +03:00
} else if ( action == 'amtider' ) {
console . log ( 'AmtIDER will mount a local disk images to a remote Intel AMT computer. Example usage:\r\n\r\n meshcmd amtider --host 1.2.3.4 --user admin --pass mypassword --tls --floppy disk.img --cdrom disk.iso' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT.' ) ;
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.' ) ;
console . log ( ' --floppy [file] Specifies .img file to be mounted as a flppy disk.' ) ;
console . log ( ' --cdrom [file] Specifies .img file to be mounted as a CDROM disk.' ) ;
console . log ( ' --timeout [seconds] Optional, disconnect after number of seconds without disk read.' ) ;
} 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 ;
}
settings . action = settings . action . toLowerCase ( ) ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
// Setup the proxy if needed
if ( ( typeof settings . proxy ) == 'string' ) {
var proxy = settings . proxy . split ( ':' ) , proxyport = ( proxy . length == 2 ) ? parseInt ( proxy [ 1 ] ) : 0 ;
if ( ( proxy . length != 2 ) || ( proxy [ 0 ] . length < 1 ) || ( proxyport < 1 ) || ( proxyport > 65535 ) ) { console . log ( 'Invalid \"proxy\" specified, use --proxy [hostname]:[port].' ) ; exit ( 1 ) ; return ; }
try { require ( 'global-tunnel' ) . initialize ( { host : proxy [ 0 ] , port : proxyport } ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
console . log ( 'Proxy set to ' + proxy [ 0 ] + ':' + proxyport ) ;
}
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' ) ;
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 ) ; }
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' ; } } }
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 ) ; }
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'route' ) {
// MeshCentral Router, port map local TCP port to a remote computer
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
} else if ( ( settings . action == 'amtloadwebapp' ) || ( settings . action == 'amtloadsmallwebapp' ) || ( settings . action == 'amtloadlargewebapp' ) || ( settings . action == 'amtclearwebapp' ) || ( settings . action == 'amtstoragestate' ) ) { // Intel AMT Web Application Actions
// Intel AMT 11.6+ Load MeshCommander into firmware
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' ) ;
if ( settings . action == 'amtstoragestate' ) {
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 {
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 ; }
nextStepStorageUpload ( ) ;
}
} else if ( ( settings . action == 'amtversion' ) || ( settings . action == 'amtversions' ) || ( settings . action == 'amtver' ) ) {
// Display Intel AMT versions
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
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 ;
} ) ;
} else if ( settings . action == 'amthashes' ) {
// Display Intel AMT list of trusted hashes
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
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 ) ; }
} ) ;
}
} ) ;
2019-06-27 08:13:56 +03:00
} else if ( settings . action == 'netinfo' ) {
// Display network information
var interfaces = require ( 'os' ) . networkInterfaces ( ) ;
console . log ( JSON . stringify ( interfaces , 2 , ' ' ) ) ;
exit ( 0 ) ; return ;
2019-06-20 03:59:03 +03:00
} else if ( settings . action == 'amtinfo' ) {
// Display Intel AMT version and activation state
mestate = { } ;
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
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 ; } } ) ;
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 ; } } ) ;
amtMei . getUuid ( function ( result ) { if ( ( result != null ) && ( result . uuid != null ) ) { mestate . uuid = result . uuid ; } } ) ;
amtMei . getDnsSuffix ( function ( result ) {
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 ;
}
}
}
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 ) ) ; }
if ( ( mestate . ProvisioningState . stateStr != 'POST' ) && ( mestate . net0 != null ) && ( mestate . net0 . enabled == 1 ) ) {
if ( mestate . dns != null ) {
// Intel AMT has a trusted DNS suffix set, use that one.
str += '\r\nTrusted DNS suffix: ' + mestate . dns ;
} else {
// Look for the DNS suffix for the Intel AMT Ethernet interface
var fqdn = null , interfaces = require ( 'os' ) . networkInterfaces ( ) ;
for ( var i in interfaces ) {
for ( var j in interfaces [ i ] ) {
if ( ( interfaces [ i ] [ j ] . mac == mestate . net0 . mac ) && ( interfaces [ i ] [ j ] . fqdn != null ) && ( interfaces [ i ] [ j ] . fqdn != '' ) ) { fqdn = interfaces [ i ] [ j ] . fqdn ; }
}
}
if ( fqdn != null ) { str += '\r\nDNS suffix: ' + fqdn ; }
}
}
console . log ( str + '.' ) ;
} else {
console . log ( 'Intel(R) AMT not supported.' ) ;
}
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'amtinfodebug' ) {
// Display Intel AMT version and activation state
mestate = { } ;
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
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 ) ) ; exit ( 1 ) ; } ) ;
} else if ( settings . action == 'amtsavestate' ) {
// Save the entire state of Intel AMT info a JSON file
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
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 ) ) ;
saveEntireAmtState ( ) ;
} else if ( ( settings . action == 'microlms' ) || ( settings . action == 'amtlms' ) || ( settings . action == 'lms' ) ) {
// Start Intel AMT MicroLMS
startLms ( function ( state ) {
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 ] ) ;
if ( ( ( state == 0 ) || ( state == 3 ) ) && ( settings . noconsole === true ) ) { exit ( 0 ) ; } else { console . log ( 'Press ctrl-c to exit.' ) ; }
} , settings . noconsole !== true ) ;
} 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 ( ) ;
} else if ( settings . action == 'amtscript' ) {
// 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' ; }
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 ; } }
startMeScript ( ) ;
} else if ( settings . action == 'amtuuid' ) {
// Start running
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' ; }
}
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
getAmtUuid ( ) ;
} else if ( settings . action == 'amtccm' ) {
// Start activation to CCM
2019-06-25 04:56:14 +03:00
if ( ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) && ( ( settings . url == null ) || ( typeof settings . url != 'string' ) || ( settings . url == '' ) ) ) { console . log ( 'No or invalid parameters specified, use --password [password] or --url [url].' ) ; exit ( 1 ) ; return ; }
if ( ( typeof settings . profile != 'string' ) || ( settings . profile == '' ) ) { settings . profile = null ; }
2019-06-20 03:59:03 +03:00
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2019-06-28 02:04:52 +03:00
if ( settings . password != null ) { activeToCCM ( ) ; } else { activeToACM ( ) ; }
2019-06-20 03:59:03 +03:00
} else if ( settings . action == 'amtacm' ) {
// Start activation to ACM
2019-06-22 03:42:43 +03:00
if ( ( settings . url == null ) || ( typeof settings . url != 'string' ) || ( settings . url == '' ) ) { console . log ( 'No activation server URL specified, use --url [url].' ) ; exit ( 1 ) ; return ; }
2019-06-22 03:18:48 +03:00
if ( ( typeof settings . profile != 'string' ) || ( settings . profile == '' ) ) { settings . profile = null ; }
2019-06-20 03:59:03 +03:00
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
activeToACM ( ) ;
2019-06-28 02:04:52 +03:00
} else if ( settings . action == 'amtdiscover' ) {
// Intel AMT server discovery, tell the server the state of Intel AMT.
if ( ( settings . url == null ) || ( typeof settings . url != 'string' ) || ( settings . url == '' ) ) { console . log ( 'No activation server URL specified, use --url [url].' ) ; exit ( 1 ) ; return ; }
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
activeToACM ( ) ;
2019-06-20 03:59:03 +03:00
} else if ( settings . action == 'amtdeactivate' ) {
// Deactivate CCM
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
deactivateCCM ( ) ;
} else if ( settings . action == 'amtacmdeactivate' ) {
// Deactivate ACM
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 . type == null ) || ( typeof settings . type != 'string' ) || ( settings . type == '' ) ) { console . log ( 'Unprovisioning \"type\" must be specified, use --type [partial/full].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
if ( settings . hostname == null ) { settings . hostname = '127.0.0.1' ; }
if ( settings . tls == null ) { settings . tls = false ; }
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
deactivateACM ( ) ;
} else if ( settings . action == 'meshcommander' ) { // Start MeshCommander
startMeshCommander ( ) ;
//} else if (settings.action == 'amtdisable') { // Disable AMT Network Interface
// amtDisable();
} else if ( settings . action == 'amtauditlog' ) { // Read the Intel AMT audit log
if ( settings . hostname != null ) {
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
} else { settings . hostname = '127.0.0.1' ; }
readAmtAuditLog ( ) ;
2019-07-16 01:44:18 +03:00
} else if ( settings . action == 'amteventlog' ) { // Read the Intel AMT audit log
if ( settings . hostname == null ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
readAmtEventLog ( ) ;
2019-06-20 03:59:03 +03:00
} else if ( settings . action == 'amtider' ) { // Remote mount IDER image
if ( ( settings . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { console . log ( 'No or invalid \"hostname\" specified, use --hostname [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
if ( ( settings . floppy == null ) || ( typeof settings . floppy != 'string' ) || ( settings . floppy == '' ) ) { settings . floppy = null ; }
if ( ( settings . cdrom == null ) || ( typeof settings . cdrom != 'string' ) || ( settings . cdrom == '' ) ) { settings . cdrom = null ; }
if ( ( settings . floppy == null ) && ( settings . cdrom == null ) ) { console . log ( 'No or invalid \"floppy\" or \"cdrom\" specified, use --floppy [file] or --cdrom [file].' ) ; exit ( 1 ) ; return ; }
performIder ( ) ;
2019-07-16 00:45:36 +03:00
} else if ( settings . action == 'amtnetwork' ) { // Perform remote Intel AMT wired IPv4 configuration operation
if ( settings . hostname == null ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
performAmtNetConfig ( args ) ;
2019-07-15 22:55:52 +03:00
} else if ( settings . action == 'amtfeatures' ) { // Perform remote Intel AMT feature configuration operation
2019-07-16 00:45:36 +03:00
if ( settings . hostname == null ) { settings . hostname = '127.0.0.1' ; }
2019-07-15 22:55:52 +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 . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
performAmtFeatureConfig ( args ) ;
2019-07-12 02:54:27 +03:00
} else if ( settings . action == 'amtpower' ) { // Perform remote Intel AMT power operation
if ( ( settings . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { console . log ( 'No or invalid \"hostname\" specified, use --hostname [host].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
/ *
2 = Power On
3 = Sleep - Light
4 = Sleep - Deep
5 = Power Cycle ( Off Soft )
6 = Power Off - Hard
7 = Hibernate
8 = Power Off - Soft
9 = Power Cycle ( Off Hard )
10 = Master Bus Reset
11 = Diagnostic Interrupt ( NMI )
12 = Power Off - Soft Graceful
13 = Power Off - Hard Graceful
14 = Master Bus Reset Graceful
15 = Power Cycle ( Off - Soft Graceful )
16 = Power Cycle ( Off - Hard Graceful )
* /
settings . poweraction = 0 ;
if ( args . poweron ) { settings . poweraction = 2 ; }
if ( args . sleep ) { settings . poweraction = 3 ; }
if ( args . powercycle ) { settings . poweraction = 5 ; }
if ( args . poweroff ) { settings . poweraction = 6 ; }
if ( args . hibernate ) { settings . poweraction = 7 ; }
if ( args . reset ) { settings . poweraction = 10 ; }
//if (settings.poweraction == 0) { console.log('No power action, specify --poweron, --sleep, --powercycle, --poweroff, --hibernate, --reset.'); exit(1); return; }
performAmtPowerAction ( ) ;
2019-06-20 03:59:03 +03:00
} else {
console . log ( 'Invalid \"action\" specified.' ) ; exit ( 1 ) ; return ;
}
}
//
// 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 ) ;
}
}
}
2019-07-16 01:44:18 +03:00
//
// Intel AMT Event Log
//
function readAmtEventLog ( ) {
// See if MicroLMS needs to be started
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( readAmtEventLogEx ) ;
} else {
readAmtEventLogEx ( 9999 ) ;
}
}
function readAmtEventLogEx ( 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 . GetMessageLog ( readAmtEventLogEx2 ) ;
} else {
osamtstack . GetMessageLog ( readAmtEventLogEx2 ) ;
}
}
function readAmtEventLogEx2 ( stack , messages ) {
if ( messages == null ) {
console . log ( 'Unable to get event log.' ) ;
} else {
var out = '' ;
if ( settings . json ) {
out = JSON . stringify ( messages , 4 , ' ' ) ;
} else {
for ( var i in messages ) { out += messages [ i ] . Time + ', ' + messages [ i ] . EntityStr + ', ' + messages [ i ] . Desc + '\r\n' ; }
}
if ( settings . output == null ) { console . log ( out ) ; } else {
var file = fs . openSync ( settings . output , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
}
}
exit ( 1 ) ;
}
2019-06-20 03:59: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 = '' ;
2019-07-16 01:44:18 +03:00
if ( settings . json ) {
out = JSON . stringify ( response , 4 , ' ' ) ;
} else {
for ( var i in response ) {
var name = ( ( response [ i ] . Initiator != '' ) ? ( response [ i ] . Initiator + ': ' ) : '' )
out += ( response [ i ] . Time + ' - ' + name + response [ i ] . Event + '\r\n' ) ;
}
}
if ( settings . output == null ) { console . log ( out ) ; } else {
var file = fs . openSync ( settings . output , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
2019-06-20 03:59:03 +03:00
}
}
exit ( 1 ) ;
}
//
// Disable AMT Network
//
//function amtDisable() {
// settings.noconsole = true;
// startLms(amtDisableEx);
//}
//function amtDisableEx(stack, response, status) {
// //console.log(osamtstack);
// osamtstack.Get('AMT_EthernetPortSettings', function (stack, name, response, status) {
// console.log(response.Body);
// });
//}
//
// MeshCommander local web server
//
function startMeshCommander ( ) {
if ( settings . localport == null ) { settings . localport = 3000 ; }
// Start the web server
var http = require ( 'http' ) ;
webServer = http . createServer ( ) ;
webServer . listen ( settings . localport ) ;
webServer . wsList = { } ;
webServer . wsListIndex = 0 ;
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 ;
ws . wsIndex = ++ webServer . wsListIndex ;
webServer . wsList [ ws . wsIndex ] = ws ; // Keep a reference so the websocket and forwarder don't get disposed.
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 ) ; }
debug ( 1 , 'Opening web socket connection to ' + webargs . host + ':' + 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 } )
ws . forwardclient . on ( 'connect' , function ( ) { debug ( 1 , 'Connected TCP to ' + webargs . host + ':' + webargs . port + '.' ) ; this . pipe ( this . ws , { end : false } ) ; this . ws . pipe ( this , { end : false } ) ; } ) ;
ws . forwardclient . on ( 'error' , function ( ) { debug ( 1 , 'TCP connection error to ' + webargs . host + ':' + webargs . port + '.' ) ; try { this . ws . end ( ) ; } catch ( e ) { } } ) ;
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 } ;
ws . forwardclient = tls . connect ( tlsoptions , function ( ) { debug ( 1 , 'Connected TLS to ' + webargs . host + ':' + webargs . port + '.' ) ; this . pipe ( this . ws , { end : false } ) ; this . ws . pipe ( this , { end : false } ) ; } ) ;
ws . forwardclient . on ( 'error' , function ( ) { debug ( 1 , 'TLS connection error to ' + webargs . host + ':' + webargs . port + '.' ) ; try { this . ws . end ( ) ; } catch ( e ) { } } ) ;
ws . forwardclient . ws = ws ;
}
// Handle pipe closure
ws . on ( 'end' , function ( ) { debug ( 1 , 'Disconnected from ' + webargs . host + ':' + webargs . port + '.' ) ; try { this . forwardclient . end ( ) ; } catch ( e ) { } delete webServer . wsList [ this . wsIndex ] ; } ) ;
ws . forwardclient . on ( 'end' , function ( ) { try { this . ws . end ( ) ; } catch ( e ) { } } ) ;
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 {
2019-07-05 23:28:41 +03:00
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 : FullSite _IntelAmtLocalWebApp _etag } ) ;
rsp . end ( Buffer . from ( FullSite _IntelAmtLocalWebApp , 'base64' ) ) ;
2019-06-20 03:59:03 +03:00
}
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.' ) ;
}
//
// 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 ( ) {
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
amtMei . unprovision ( 1 , function ( status ) { if ( status == 0 ) { console . log ( 'Success' ) ; } else { console . log ( 'Error ' + status ) ; } exit ( 1 ) ; } ) ;
}
//
// 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 ) ; }
else { osamtstack . IPS _HostBasedSetupService _Setup ( 2 , md5hex ( 'admin:' + responses [ 'AMT_GeneralSettings' ] . response [ 'DigestRealm' ] + ':' + settings . password ) . substring ( 0 , 32 ) , null , null , null , null , activeToCCMEx3 ) ; }
}
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 ) ;
}
2019-06-25 04:56:14 +03:00
2019-06-20 03:59:03 +03:00
//
// Deactivate Intel AMT ACM
//
// When called, this will use MEI to deactivate Intel AMT when it's in ACM mode. Calls "unprovision" on MEI and checks the return code.
function deactivateACM ( ) {
settings . noconsole = true ;
startLms ( deactivateACMEx ) ;
}
function deactivateACMEx ( ) {
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 ( "AMT_SetupAndConfigurationService" , function ( stack , name , responses , status ) {
if ( status !== 200 ) {
console . log ( 'Command not allowed. Status: ' + status ) ;
exit ( 1 ) ;
} else {
var sacs = responses . Body ;
if ( sacs . ZeroTouchConfigurationEnabled == true ) { sacs . ZeroTouchConfigurationEnabled = true ; }
amtstack . Put ( "AMT_SetupAndConfigurationService" , sacs , function ( stack , name , responses , status ) {
if ( settings . type == 'full' ) {
amtstack . AMT _SetupAndConfigurationService _Unprovision ( 2 , function ( stack , name , responses , status ) {
if ( status != 200 ) { console . log ( 'Failed to fully unconfigure AMT, status ' + status ) ; exit ( 1 ) ; }
else if ( responses . Body . ReturnValue != 0 ) { console . log ( 'Unprovision failed: ' + responses . Body . ReturnValueStr ) ; exit ( 1 ) ; }
else { console . log ( 'AMT fully unprovisioned.' ) ; exit ( 0 ) ; }
} ) ;
} else {
console . log ( 'Only full unprovision is currently supported.' ) ;
exit ( 0 ) ;
}
//} else if (settings.type == 'partial') {
// amtstack.AMT_SetupAndConfigurationService_PartialUnprovision(null, function (stack, name, responses, status) {
// if (status != 200) { console.log('Failed to partially unconfigure AMT, status ' + status); exit(1); }
// else if (responses.Body.ReturnValue != 0) { console.log('Unprovision failed: ' + responses.Body.ReturnValueStr); exit(1); }
// else { console.log('AMT partially unprovisioned.'); exit(0); }
// });
//}
} ) ;
}
} ) ;
}
2019-06-22 03:18:48 +03:00
//
// Get Intel AMT activation hashes
//
var trustedHashes = null ;
function getTrustedHashes ( amtMei , func , tag ) {
if ( trustedHashes != null ) { func ( tag ) ; }
trustedHashes = [ ] ;
amtMei . getHashHandles ( function ( handles ) {
var exitOnCount = handles . length ;
for ( var i = 0 ; i < handles . length ; ++ i ) {
this . getCertHashEntry ( handles [ i ] , function ( result ) {
if ( result . isActive == 1 ) { trustedHashes . push ( result . certificateHash . toLowerCase ( ) ) ; }
if ( -- exitOnCount == 0 ) { func ( tag ) ; }
} ) ;
}
} ) ;
}
2019-06-20 03:59:03 +03:00
//
2019-06-28 02:04:52 +03:00
// Activate Intel AMT to with server (ACM or CCM)
2019-06-20 03:59:03 +03:00
//
function activeToACM ( ) {
2019-06-28 02:04:52 +03:00
console . log ( 'Starting Intel AMT activation attempt...' ) ;
2019-06-20 03:59:03 +03:00
settings . noconsole = true ;
2019-06-22 03:18:48 +03:00
2019-06-20 03:59:03 +03:00
// Display Intel AMT version and activation state
mestate = { } ;
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2019-06-22 03:18:48 +03:00
amtMei . getProvisioningState ( function ( result ) { if ( result ) { mestate . ProvisioningState = result ; } } ) ;
2019-06-25 04:56:14 +03:00
amtMei . getVersion ( function ( val ) { mestate . vers = { } ; if ( val != null ) { for ( var version in val . Versions ) { mestate . vers [ val . Versions [ version ] . Description ] = val . Versions [ version ] . Version ; } } } ) ;
2019-06-22 03:18:48 +03:00
amtMei . getLanInterfaceSettings ( 0 , function ( result ) { if ( result ) { mestate . net0 = result ; } } ) ;
amtMei . getUuid ( function ( result ) { if ( ( result != null ) && ( result . uuid != null ) ) { mestate . uuid = result . uuid ; } } ) ;
2019-06-28 02:04:52 +03:00
amtMei . getControlMode ( function ( result ) { if ( result != null ) { mestate . controlMode = result . controlMode ; } } ) ; // controlMode: 0 = NoActivated, 1 = CCM, 2 = ACM
2019-06-22 03:18:48 +03:00
amtMei . getDnsSuffix ( function ( result ) {
2019-06-25 04:56:14 +03:00
if ( ( mestate . vers == null ) || ( mestate . vers [ 'AMT' ] == null ) ) { console . log ( "Unable to get Intel AMT version." ) ; exit ( 100 ) ; return ; }
if ( mestate . ProvisioningState == null ) { console . log ( "Unable to read Intel AMT activation state." ) ; exit ( 100 ) ; return ; }
2019-06-28 02:04:52 +03:00
if ( ( settings . action != 'amtdiscover' ) && ( mestate . controlMode == 2 ) ) { console . log ( "Intel AMT already activation in admin control mode." ) ; exit ( 100 ) ; return ; }
2019-06-22 03:18:48 +03:00
if ( mestate . uuid == null ) { console . log ( "Unable to get Intel AMT UUID." ) ; exit ( 100 ) ; return ; }
var fqdn = null ;
if ( ( mestate . net0 == null ) && ( meinfo . net0 . enabled != 0 ) ) { console . log ( "No Intel AMT wired interface, can't perform ACM activation." ) ; exit ( 100 ) ; return ; }
if ( result ) { fqdn = result ; } // If Intel AMT has a trusted DNS suffix set, use that one.
else {
// Look for the DNS suffix for the Intel AMT Ethernet interface
var interfaces = require ( 'os' ) . networkInterfaces ( ) ;
for ( var i in interfaces ) {
for ( var j in interfaces [ i ] ) {
if ( ( interfaces [ i ] [ j ] . mac == mestate . net0 . mac ) && ( interfaces [ i ] [ j ] . fqdn != null ) && ( interfaces [ i ] [ j ] . fqdn != '' ) ) { fqdn = interfaces [ i ] [ j ] . fqdn ; }
}
}
}
if ( fqdn != null ) {
settings . fqdn = fqdn ;
settings . uuid = mestate . uuid ;
getTrustedHashes ( amtMei , function ( ) { startLms ( getFwNonce , amtMei ) ; } ) ;
} else {
console . log ( "Trusted DNS suffix not set, can't perform ACM activation." ) ; exit ( 100 ) ; return ;
2019-06-20 03:59:03 +03:00
}
} ) ;
}
// Gets the FWNonce from AMT and saves it to a file.
function getFwNonce ( ) {
osamtstack . BatchEnum ( null , [ '*AMT_GeneralSettings' , '*IPS_HostBasedSetupService' ] , function ( stack , name , responses , status ) {
2019-06-22 03:18:48 +03:00
if ( status != 200 ) { console . log ( "Unable to get firmware activation nonce, status=" + status ) ; exit ( 100 ) ; return ; }
2019-06-20 03:59:03 +03:00
var fwNonce = responses [ 'IPS_HostBasedSetupService' ] . response [ 'ConfigurationNonce' ] ;
var digestRealm = responses [ 'AMT_GeneralSettings' ] . response [ 'DigestRealm' ] ;
2019-06-28 02:04:52 +03:00
var allowedModes = responses [ 'IPS_HostBasedSetupService' ] . response [ 'AllowedControlModes' ] ; // 1 = CCM, 2 = ACM
activeToACMEx ( fwNonce , settings . fqdn , digestRealm , settings . uuid , allowedModes ) ;
2019-06-20 03:59:03 +03:00
} ) ;
}
2019-06-22 03:18:48 +03:00
// Connect to the activation server and perform ACM activation
2019-06-28 02:04:52 +03:00
function activeToACMEx ( fwNonce , dnsSuffix , digestRealm , uuid , allowedModes ) {
2019-06-22 03:18:48 +03:00
console . log ( 'FQDN: ' + dnsSuffix ) ;
console . log ( 'UUID: ' + uuid ) ;
console . log ( 'Realm: ' + digestRealm ) ;
console . log ( 'Nonce: ' + fwNonce ) ;
2019-06-22 03:42:43 +03:00
console . log ( 'Connecting to ' + settings . url ) ;
2019-06-22 03:18:48 +03:00
// Establish WebSocket connection to activation server
2019-06-22 03:42:43 +03:00
var options = http . parseUri ( settings . url ) ;
2019-06-23 08:06:50 +03:00
options . checkServerIdentity = onVerifyServer ;
2019-06-22 03:18:48 +03:00
options . rejectUnauthorized = false ;
var connection = http . request ( options ) ;
2019-06-20 03:59:03 +03:00
connection . on ( 'upgrade' , function ( response , socket ) {
2019-06-28 02:04:52 +03:00
settings . xxsocket = socket ;
2019-06-22 03:18:48 +03:00
console . log ( 'Connected, requesting activation...' ) ;
socket . on ( 'end' , function ( ) { console . log ( 'Connection closed' ) ; exit ( 0 ) ; } ) ;
socket . on ( 'error' , function ( ) { console . log ( 'Connection error' ) ; exit ( 100 ) ; } ) ;
2019-06-20 03:59:03 +03:00
socket . on ( 'data' , function ( data ) {
2019-06-22 03:18:48 +03:00
// Parse and check the response
var cmd = null ;
try { cmd = JSON . parse ( data ) ; } catch ( ex ) { console . log ( 'Unable to parse server response: ' + data ) ; exit ( 100 ) ; return ; }
if ( typeof cmd != 'object' ) { console . log ( 'Invalid server response: ' + cmd ) ; exit ( 100 ) ; return ; }
if ( typeof cmd . errorText == 'string' ) { console . log ( 'Server error: ' + cmd . errorText ) ; exit ( 100 ) ; return ; }
2019-06-28 02:04:52 +03:00
switch ( cmd . action ) {
case 'acmactivate' : {
// Server responded with ACM activation response
if ( typeof cmd . signature != 'string' ) { console . log ( 'Invalid server signature' ) ; exit ( 100 ) ; return ; }
if ( typeof cmd . password != 'string' ) { console . log ( 'Invalid server password' ) ; exit ( 100 ) ; return ; }
if ( typeof cmd . nonce != 'string' ) { console . log ( 'Invalid server nonce' ) ; exit ( 100 ) ; return ; }
if ( typeof cmd . certs != 'object' ) { console . log ( 'Invalid server certificates' ) ; exit ( 100 ) ; return ; }
2019-06-28 02:14:14 +03:00
settings . xxprofileScript = cmd . profileScript ;
settings . xxrawpassword = cmd . rawpassword ;
2019-06-28 02:04:52 +03:00
cmd . index = 0 ;
// If we are in CCM mode, deactivate.
if ( mestate . controlMode == 1 ) {
amtMei . unprovision ( 1 , function ( status ) {
if ( status == 0 ) {
console . log ( 'Intel AMT CCM deactivated, holding 10 seconds...' ) ;
// We are ready to go, perform ACM activation.
settings . xxTimer = setTimeout ( function ( ) { performAcmActivation ( cmd , AcmActivationCompleted ) ; } , 10000 ) ;
} else {
console . log ( 'Intel AMT CCM deactivation error ' + status ) ; exit ( 1 ) ; return ;
}
} ) ;
2019-06-20 03:59:03 +03:00
} else {
2019-06-28 02:04:52 +03:00
// We are ready to go, perform ACM activation.
performAcmActivation ( cmd , AcmActivationCompleted ) ;
2019-06-20 03:59:03 +03:00
}
2019-06-28 02:04:52 +03:00
break ;
2019-06-22 03:18:48 +03:00
}
2019-06-28 02:04:52 +03:00
case 'ccmactivate' : {
// Server responded with CCM activation response
if ( typeof cmd . password != 'string' ) { console . log ( 'Invalid server password' ) ; exit ( 100 ) ; return ; }
settings . xxprofileScript = cmd . profileScript ;
settings . xxrawpassword = cmd . rawpassword ;
// If we are already in CCM mode, deactivate.
if ( mestate . controlMode == 1 ) {
amtMei . unprovision ( 1 , function ( status ) {
if ( status == 0 ) {
console . log ( 'Intel AMT CCM deactivated, holding 10 seconds...' ) ;
// We are ready to go, perform CCM activation.
settings . xxTimer = setTimeout ( function ( ) { osamtstack . IPS _HostBasedSetupService _Setup ( 2 , cmd . password , null , null , null , null , performCcmActivation ) ; } , 10000 ) ;
} else {
console . log ( 'Intel AMT CCM deactivation error ' + status ) ; exit ( 1 ) ; return ;
}
} ) ;
} else {
// We are ready to go, perform CCM activation.
osamtstack . IPS _HostBasedSetupService _Setup ( 2 , cmd . password , null , null , null , null , performCcmActivation ) ;
}
break ;
}
case 'amtdiscover' : {
console . log ( 'Done.' ) ;
exit ( 0 ) ;
break ;
}
default : {
console . log ( 'Invalid server response, command: ' + cmd . action ) ; exit ( 100 ) ;
break ;
}
}
2019-06-20 03:59:03 +03:00
} ) ;
2019-06-28 02:04:52 +03:00
var action = 'acmactivate' ;
if ( settings . action == 'amtccm' ) { action = 'ccmactivate' ; }
if ( settings . action == 'amtdiscover' ) { action = 'amtdiscover' ; }
2019-09-13 00:03:18 +03:00
socket . write ( { client : 'meshcmd' , version : 1 , action : action , fqdn : dnsSuffix , realm : digestRealm , nonce : fwNonce , uuid : uuid , profile : settings . profile , hashes : trustedHashes , tag : settings . tag , name : settings . name , ver : mestate . vers [ 'AMT' ] , build : mestate . vers [ 'Build Number' ] , modes : allowedModes , currentMode : mestate . controlMode } ) ;
2019-06-20 03:59:03 +03:00
} ) ;
2019-06-22 03:18:48 +03:00
connection . end ( ) ;
2019-06-20 03:59:03 +03:00
}
2019-06-28 02:04:52 +03:00
function performCcmActivation ( stack , name , responses , status ) {
if ( status != 200 ) {
settings . xxsocket . write ( { client : 'meshcmd' , version : 1 , action : 'ccmactivate-failed' , uuid : mestate . uuid } ) ;
console . log ( 'Failed to activate, status ' + status ) ;
} else if ( responses . Body . ReturnValue != 0 ) {
settings . xxsocket . write ( { client : 'meshcmd' , version : 1 , action : 'ccmactivate-failed' , uuid : mestate . uuid } ) ;
console . log ( 'Intel AMT CCM activation failed: ' + responses . Body . ReturnValueStr ) ;
} else {
settings . xxsocket . write ( { client : 'meshcmd' , version : 1 , action : 'ccmactivate-success' , uuid : mestate . uuid } ) ;
if ( ( settings . xxprofileScript !== null ) && ( settings . xxrawpassword != null ) ) {
console . log ( "Intel AMT CCM activation success, applying profile..." ) ;
settings . scriptjson = settings . xxprofileScript ;
settings . password = settings . xxrawpassword ; // This is only going to work if the server sends the raw password
settings . username = 'admin' ;
startMeScriptEx ( function ( ) { console . log ( 'Intel AMT profile applied.' ) ; socket . end ( ) ; exit ( 0 ) ; } , stack ) ;
return ;
} else {
console . log ( 'Intel AMT CCM activation success.' ) ;
settings . xxsocket . end ( ) ;
exit ( 0 ) ;
return ;
}
}
settings . xxsocket . end ( ) ;
exit ( 1 ) ;
}
function AcmActivationCompleted ( result ) {
if ( result == false ) {
console . log ( 'Intel AMT ACM activation failed.' ) ;
settings . xxsocket . write ( { client : 'meshcmd' , version : 1 , action : 'acmactivate-failed' , uuid : mestate . uuid } ) ;
settings . xxsocket . end ( ) ;
exit ( 1 ) ;
} else {
2019-06-28 02:14:14 +03:00
if ( ( settings . xxprofileScript !== null ) && ( settings . xxrawpassword != null ) ) {
2019-06-28 02:04:52 +03:00
console . log ( 'Intel AMT ACM activation success, applying profile...' ) ;
2019-06-28 02:14:14 +03:00
settings . scriptjson = settings . xxprofileScript ;
settings . password = settings . xxrawpassword ; // This is only going to work if the server sends the raw password
2019-06-28 02:04:52 +03:00
settings . username = 'admin' ;
startMeScriptEx ( function ( ) { console . log ( 'Intel AMT profile applied.' ) ; settings . xxsocket . end ( ) ; exit ( 0 ) ; } , stack ) ;
} else {
console . log ( 'Intel AMT ACM activation success.' ) ;
settings . xxsocket . write ( { client : 'meshcmd' , version : 1 , action : 'acmactivate-success' , uuid : mestate . uuid } ) ;
settings . xxsocket . end ( ) ;
exit ( 0 ) ;
}
}
}
2019-06-22 03:18:48 +03:00
// Recursive function to inject the provisioning certificates into AMT in the proper order and completes ACM activation
function performAcmActivation ( acmdata , func ) {
var leaf = ( acmdata . index == 0 ) , root = ( acmdata . index == ( acmdata . certs . length - 1 ) ) ;
if ( ( acmdata . index < acmdata . certs . length ) && ( acmdata . certs [ acmdata . index ] != null ) ) {
osamtstack . IPS _HostBasedSetupService _AddNextCertInChain ( acmdata . certs [ acmdata . index ] , leaf , root , function ( stack , name , responses , status ) {
2019-06-28 02:04:52 +03:00
if ( status !== 200 ) { console . log ( 'AddNextCertInChain error, status=' + status ) ; exit ( 1 ) ; return ; }
else if ( responses [ 'Body' ] [ 'ReturnValue' ] !== 0 ) { console . log ( 'AddNextCertInChain error: ' + responses [ 'Body' ] [ 'ReturnValue' ] ) ; exit ( 1 ) ; return ; }
2019-06-22 03:18:48 +03:00
else { acmdata . index ++ ; performAcmActivation ( acmdata , func ) ; }
2019-06-20 03:59:03 +03:00
} ) ;
} else {
2019-06-28 02:04:52 +03:00
//console.log(acmdata.password, acmdata.nonce, acmdata.signature);
2019-06-22 03:18:48 +03:00
osamtstack . IPS _HostBasedSetupService _AdminSetup ( 2 , acmdata . password , acmdata . nonce , 2 , acmdata . signature ,
2019-06-25 04:56:14 +03:00
function ( stack , name , responses , status ) {
if ( status !== 200 ) { console . log ( 'Error, AdminSetup status: ' + status ) ; }
else if ( responses [ 'Body' ] [ 'ReturnValue' ] != 0 ) { console . log ( 'Error, AdminSetup return value: ' + responses [ 'Body' ] [ 'ReturnValue' ] ) ; }
func ( ( status == 200 ) && ( responses [ 'Body' ] [ 'ReturnValue' ] == 0 ) ) ;
}
2019-06-22 03:18:48 +03:00
) ;
2019-06-20 03:59:03 +03:00
}
}
//
// 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 ( ) {
if ( settings . hostname == null ) {
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
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 ( ) ; }
}
}
// 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 ) ;
} ) ;
}
//
// Run MESCRIPT
//
// Run a .mescript targeting local or remote Intel AMT.
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 ( callback , amtstack ) {
//console.log('Running script...');
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
if ( ! wsstack ) { wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ; }
if ( ! amtstack ) { amtstack = new amt ( wsstack ) ; }
//IntelAmtEntireStateProgress = 101;
//amtstack.onProcessChanged = onWsmanProcessChanged;
var scriptData = null ;
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 ;
}
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 ( ) ;
script . onCompleted = function ( ) { if ( callback ) { callback ( ) ; } exit ( 1 ) ; }
}
//
// FETCH ALL INTEL AMT STATE
//
function saveEntireAmtState2 ( ) {
console . log ( 'Fetching all Intel AMT state, this may take a few minutes...' ) ;
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
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 . onProcessChanged = onWsmanProcessChanged ;
//var AllWsman = "AMT_GeneralSystemDefenseCapabilities".split(',');
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
IntelAmtEntireStateProgress = 101 ;
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 ) ;
}
// 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 ( ) ;
}
}
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 ( ) ; }
// Called when the entire state of Intel AMT is fetched.
function saveEntireAmtStateDone ( ) {
if ( -- IntelAmtEntireStateCalls != 0 ) return ;
var out = fs . openSync ( settings . output , 'w' ) ;
fs . writeSync ( out , Buffer . from ( JSON . stringify ( IntelAmtEntireState ) ) ) ;
fs . closeSync ( out ) ;
console . log ( 'Done, results written to ' + settings . output + '.' ) ;
exit ( 1 ) ;
}
//
// FETCH ALL INTEL AMT MEI STATE
//
// Get Intel AMT information using MEI
// TODO: If this call is called many time at once, it's going to cause issues.
var getAmtInfoFetching = null ;
var getAmtInfoFetchingTimer = null ;
function getAmtInfo ( func , tag ) {
if ( amtMei == null ) { if ( func != null ) { func ( null , tag ) ; } return ; }
if ( getAmtInfoFetching != null ) { getAmtInfoFetching . push ( { f : func , t : tag } ) ; return ; }
getAmtInfoFetching = [ { f : func , t : tag } ] ;
amtMeiTmpState = { Flags : 0 , TrustedHashes : [ ] } ; // Flags: 1=EHBC, 2=CCM, 4=ACM
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 ;
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
} , 3000 ) ;
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 } ) ;
if ( -- exitOnCount == 0 ) {
amtMeiTmpState . Notifications = lmsNotifications ; amtMeiState = amtMeiTmpState ;
for ( var i in getAmtInfoFetching ) { if ( getAmtInfoFetching [ i ] . f != null ) { getAmtInfoFetching [ i ] . f ( amtMeiTmpState , getAmtInfoFetching [ i ] . t ) ; } }
getAmtInfoFetching = null ;
clearTimeout ( getAmtInfoFetchingTimer ) ;
getAmtInfoFetchingTimer = null ;
}
} ) ;
}
} ) ;
} else {
amtMeiState = amtMeiTmpState ;
amtMeiState . ProvisioningMode = - 858993460 ;
amtMeiState . TrustedHashes = { } ;
amtMeiState . Notifications = lmsNotifications ;
//console.log('getAmtInfo3', JSON.stringify(amtMeiState));
if ( func != null ) { func ( amtMeiState , tag ) ; }
}
} ) ;
}
//
// MicroLMS
//
var lmsControlSockets = { } ;
var lmsControlSocketsNextId = 1 ;
var lmsNotifications = [ ] ;
var amtLms = null ;
var promise = require ( 'promise' ) ;
2019-07-16 00:45:36 +03:00
function startLms ( func , lmscommander , tag ) {
2019-06-20 03:59:03 +03:00
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 ) { }
2019-07-16 00:45:36 +03:00
if ( lme _heci == null ) { if ( func != null ) { func ( 0 , tag ) ; } this . promise . _res ( ) ; return ; }
2019-06-20 03:59:03 +03:00
//var amtLms = null;
var http = require ( 'http' ) ;
console . log ( 'Setting up MEI...' ) ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
//console.log("PTHI Connected.");
console . log ( 'Setting up LME...' ) ;
amtLms = new lme _heci ( { debug : settings . lmsdebug } ) ;
amtLms . promise = ret ;
amtLms . on ( 'error' , function ( e ) {
//console.log('LME connection failed', e);
if ( lmscommander === true ) { //settings.noconsole !== true) {
startMeshCommanderLms ( ) ;
//console.log("LMS started, MeshCommander on HTTP/16994.");
2019-07-16 00:45:36 +03:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 2 , tag ) ; } , 100 ) ;
2019-06-20 03:59:03 +03:00
} else {
//console.log('LME connection failed: ' + JSON.stringify(e));
2019-07-16 00:45:36 +03:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 0 , tag ) ; } , 100 ) ;
2019-06-20 03:59:03 +03:00
}
this . promise . _res ( ) ;
} ) ;
amtLms . on ( 'notify' , function ( data , options , str , code ) {
if ( code == 'iAMT0052-3' ) {
kvmGetData ( ) ;
} 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...');
amtLms . on ( 'bind' , function ( mapping ) {
if ( mapping [ 16992 ] ) { this . removeAllListeners ( 'bind' ) ; } else { return ; }
//console.log('LMS Bounded');
amtLms . connected = true ;
this . promise . _res ( ) ;
//console.log("LME Connected.");
if ( settings . noconsole !== true ) {
startMeshCommanderLms ( ) ;
//console.log("LMS started, MeshCommander on HTTP/16994.");
2019-07-16 00:45:36 +03:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 2 , tag ) ; } , 100 ) ;
2019-06-20 03:59:03 +03:00
//console.logReferenceCount(tempTimer);
} else {
//console.log("LMS started.");
2019-07-16 00:45:36 +03:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 1 , tag ) ; } , 100 ) ;
2019-06-20 03:59:03 +03:00
//console.logReferenceCount(tempTimer);
}
} ) ;
return ( ret ) ;
}
function startMeshCommanderLms ( ) {
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 ( ) ;
if ( amtLms . connected == true ) {
// Route traffic directly into MicroLMS
amtLms . bindDuplexStream ( socket . ws , 'IPv4' , 16992 ) ;
} else {
// Route traffic to real LMS service
var net = require ( 'net' ) ;
socket . relay = net . connect ( { host : '127.0.0.1' , port : 16992 } )
socket . relay . on ( 'connect' , function ( ) {
socket . ws . on ( 'data' , function ( data ) { socket . relay . write ( data ) ; } ) ;
socket . ws . on ( 'end' , function ( ) { socket . relay . end ( ) ; } ) ;
} ) ;
socket . relay . on ( 'data' , function ( data ) { socket . ws . write ( data ) ; } ) ;
socket . relay . on ( 'close' , function ( ) { socket . ws . end ( ) ; } ) ;
}
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 } ) ;
2019-07-05 23:28:41 +03:00
rsp . end ( Buffer . from ( _IntelAmtWebApp , "base64" ) ) ;
2019-06-20 03:59:03 +03:00
}
break ;
default : // Unknown request
rsp . statusCode = 404 ;
rsp . statusMessage = "Not Found" ;
rsp . end ( ) ;
break ;
}
} ) ;
}
2019-07-16 00:45:36 +03:00
function setupMeiOsAdmin ( func , state , tag ) {
2019-06-20 03:59:03 +03:00
if ( amtMei == null ) {
2019-07-16 00:45:36 +03:00
if ( func ) { func ( state , tag ) ; }
2019-06-20 03:59:03 +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 ) ;
2019-07-16 00:45:36 +03:00
if ( func ) { func ( state , tag ) ; }
2019-06-20 03:59:03 +03:00
//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.
}
} ) ;
} ) ;
}
}
function kvmGetData ( tag ) {
osamtstack . IPS _KVMRedirectionSettingData _DataChannelRead ( kvmDataGetResponse , tag ) ;
}
function kvmDataGetResponse ( stack , name , response , status , tag ) {
if ( ( tag != 'skip' ) && ( status == 200 ) && ( response . Body . ReturnValue == 0 ) ) {
var val = null ;
try { val = Buffer . from ( response . Body . DataMessage , 'base64' ) . toString ( ) ; } catch ( e ) { return }
if ( val != null ) { kvmProcessData ( response . Body . RealmsBitmap , response . Body . MessageId , val ) ; }
}
}
var webRtcDesktop = null ;
function kvmProcessData ( realms , messageId , val ) {
var data = null ;
try { data = JSON . parse ( val ) } catch ( e ) { }
if ( ( data != null ) && ( data . action ) ) {
if ( data . action == 'present' ) { kvmSetData ( JSON . stringify ( { action : 'present' , ver : 1 , platform : process . platform } ) ) ; }
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 ( ) ;
webRtcDesktop . kvm . pipe ( webRtcDesktop . rtcchannel , { dataTypeSkip : 1 , end : false } ) ;
webRtcDesktop . rtcchannel . on ( 'end' , function ( ) { webRtcCleanUp ( ) ; } ) ;
webRtcDesktop . rtcchannel . on ( 'data' , function ( x ) { kvmCtrlData ( this , x ) ; } ) ;
webRtcDesktop . rtcchannel . pipe ( webRtcDesktop . kvm , { dataTypeSkip : 1 , end : false } ) ;
//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 ) } ) ) ;
}
}
}
// 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 ) {
case 'ping' : {
// This is a keep alive
channel . write ( { action : 'pong' } ) ;
break ;
}
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 -- ;
var buf = Buffer . alloc ( 4096 ) ;
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 ;
}
default :
// Unknown action, ignore it.
break ;
}
}
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 ( ) { } ) ;
}
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 + '.' ) ; }
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);
}
}
}
// Process commands in the LMS control channel
// Command 9 is add a notification.
function processLmsControlData ( data ) {
if ( data . length < 2 ) return ;
var cmdid = data . readUInt16LE ( 0 ) ;
switch ( cmdid ) {
case 1 : // Request basic Intel AMT information (CMD = 1)
{ getAmtInfo ( function ( meinfo , socket ) { meinfo . LoginMode = 2 ; socket . write ( Buffer . concat ( [ Buffer . from ( '0100' , 'hex' ) , Buffer . from ( JSON . stringify ( meinfo ) ) ] ) ) ; } , this ) ; break ; }
case 2 : // Intel AMT MEI Unprovision (CMD = 2)
{ 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 ; }
case 3 : // Intel AMT MEI GetLocalSystemAccount (CMD = 3)
{ amtMei . getLocalSystemAccount ( function ( account , socket ) { socket . write ( Buffer . concat ( [ Buffer . from ( '030000000000' , 'hex' ) , account . raw ] ) ) ; } , this ) ; break ; }
case 4 : // Instruct Intel AMT to start remote configuration (CMD = 4)
{ amtMei . startConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
case 5 : // Instruct Intel AMT to stop remote configuration (CMD = 5)
{ amtMei . stopConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
case 6 : // Instruct Intel AMT connect CIRA (CMD = 6)
{ amtMei . openUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
case 7 : // Instruct Intel AMT disconnect CIRA (CMD = 7)
{ amtMei . closeUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
case 8 : // Get Intel AMT CIRA State (CMD = 8)
{ 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 ; }
default :
// Unknown action, ignore it.
break ;
}
}
//
// MeshCentral TCP port router
//
function startRouter ( ) {
tcpserver = net . createServer ( OnTcpClientConnected ) ;
tcpserver . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + JSON . stringify ( e ) ) ; exit ( 0 ) ; return ; } ) ;
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 + '.' ) ;
}
console . log ( 'Press ctrl-c to exit.' ) ;
// 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 ) ;
} catch ( e ) { console . log ( 'Unable to parse \"serverUrl\".' ) ; process . exit ( 1 ) ; return ; }
options . checkServerIdentity = onVerifyServer ;
options . rejectUnauthorized = false ;
c . websocket = http . request ( options ) ;
c . websocket . tcp = c ;
c . websocket . tunneling = false ;
c . websocket . upgrade = OnWebSocket ;
c . websocket . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + JSON . stringify ( e ) ) ; } ) ;
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 ( ) ;
2019-08-15 01:08:11 +03:00
if ( ( msg == 'c' ) || ( msg == 'cr' ) ) {
2019-06-20 03:59:03 +03:00
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 ) ) {
for ( var i = 0 ; i < interfaces [ adapter ] . length ; ++ i ) {
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" ) {
try {
multicastSockets [ i ] . addMembership ( membershipIPv4 ) ;
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets [ i ] . once ( 'message' , OnMulticastMessage ) ;
multicastSockets [ i ] . send ( settings . serverid , 16989 , membershipIPv4 ) ;
} catch ( e ) { }
}
}
}
}
}
// 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 ( ) ;
}
}
//
// PUSH MESHCOMMANDER INTO FIRMWARE
//
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 ;
data = data . split ( '\t' ) . join ( '' ) . split ( '\r' ) . join ( '' ) . split ( '\n' ) . join ( '' ) ;
try {
do { len = data . length ; data2 = data ; data = data2 . replace ( '": ' , '":' ) ; } 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 ( '\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.
var xopen = data . split ( "{" ) . length , xclose = data . split ( "}" ) . length , xadd = '' ;
while ( xopen > xclose ) { data += '}' ; xclose ++ ; } // Close any missing close brackets
amtstorage = JSON . parse ( data ) ;
} catch ( e ) { console . log ( "Error: Unable to parse Intel AMT response: " + data , e ) ; 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 ; }
var req = digest . request ( { protocol : settings . protocol , method : "PUT" , host : settings . hostname , path : ( "/amt-storage/" + name + ( ( ptr != 0 ) ? '?append=' : '' ) ) , port : settings . localport } ) ;
req . on ( 'error' , function ( e ) { console . log ( "Error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
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 ) ; } }
} ) ;
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 ) {
var req = digest . request ( { protocol : settings . protocol , method : "GET" , host : settings . hostname , path : ( "/amt-storage/" + name ) , port : settings . localport } ) ;
req . on ( 'error' , function ( e ) { console . log ( "Verify error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
req . on ( 'response' , function ( response ) {
response . ptr = 0 ;
response . ok = true ;
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 ; } ) ;
response . on ( 'end' , function ( ) { if ( func != null ) { func ( response . ok ) ; } } ) ;
} ) ;
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function deleteStorage ( name , func , noretry ) {
var req = digest . request ( { protocol : settings . protocol , method : "DELETE" , host : settings . hostname , path : "/amt-storage/" + name , port : settings . localport } ) ;
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 ) ; } } } } ) ;
req . on ( 'response' , function ( response ) { if ( func != null ) { func ( response . statusCode ) ; } } ) ;
req . end ( ) ;
}
//
// IDER
//
ider = null ;
iderIdleTimer = null ;
// Perform IDER
function performIder ( ) {
if ( ( settings . floppy != null ) && fs . existsSync ( settings . floppy ) == false ) { console . log ( "Unable to floppy image file: " + settings . floppy ) ; process . exit ( ) ; return ; }
if ( ( settings . cdrom != null ) && fs . existsSync ( settings . cdrom ) == false ) { console . log ( "Unable to CDROM image file: " + settings . cdrom ) ; process . exit ( ) ; return ; }
try {
var sfloppy = null , scdrom = null ;
if ( settings . floppy ) { try { if ( sfloppy = fs . statSync ( settings . floppy ) ) { sfloppy . file = fs . openSync ( settings . floppy , 'rbN' ) ; } } catch ( ex ) { console . log ( ex ) ; process . exit ( 1 ) ; return ; } }
if ( settings . cdrom ) { try { scdrom = fs . statSync ( settings . cdrom ) ; if ( scdrom ) { scdrom . file = fs . openSync ( settings . cdrom , 'rbN' ) ; } } catch ( ex ) { console . log ( ex ) ; process . exit ( 1 ) ; return ; } }
ider = require ( 'amt-redir-duk' ) ( require ( 'amt-ider' ) ( ) ) ;
ider . onStateChanged = onIderStateChange ;
ider . m . floppy = sfloppy ;
ider . m . cdrom = scdrom ;
ider . m . iderStart = 1 ; // OnReboot = 0, Graceful = 1, Now = 2
ider . m . debug = ( settings . debuglevel > 0 ) ;
if ( settings . timeout > 0 ) { ider . m . sectorStats = iderSectorStats ; }
//ider.digestRealmMatch = wsstack.comm.digestRealm;
//ider.tlsv1only = amtstack.wsman.comm.tlsv1only;
ider . Start ( settings . hostname , ( settings . tls == true ) ? 16995 : 16994 , settings . username ? 'admin' : settings . username , settings . password , settings . tls ) ;
} catch ( ex ) { console . log ( ex ) ; }
}
function onIderStateChange ( stack , state ) { console . log ( [ 'Disconnected' , 'Connecting...' , 'Connected...' , 'Started IDER...' ] [ state ] ) ; }
function iderSectorStats ( mode , dev , mediaBlocks , lba , len ) {
if ( iderIdleTimer != null ) { clearTimeout ( iderIdleTimer ) ; }
iderIdleTimer = setTimeout ( function ( ) { console . log ( 'Idle timeout' ) ; process . exit ( 1 ) ; } , 1000 * settings . timeout ) ;
}
2019-07-16 00:45:36 +03:00
//
// Intel AMT IPv4 wired configuration
//
function performAmtNetConfig ( args ) {
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( performAmtNetConfig0 , false , args ) ;
} else {
performAmtNetConfig0 ( 1 , args ) ;
}
}
function performAmtNetConfig0 ( state , args ) {
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
amtstack = new amt ( wsstack ) ;
amtstack . BatchEnum ( null , [ 'AMT_EthernetPortSettings' ] , performAmtNetConfig1 , args ) ;
}
function performAmtNetConfig1 ( stack , name , response , status , args ) {
if ( status == 200 ) {
// Set wired and wireless interfaces
var amtwirelessif = - 1 ;
var amtwiredif = - 1 ;
for ( var y in response [ 'AMT_EthernetPortSettings' ] . responses ) {
var z = response [ 'AMT_EthernetPortSettings' ] . responses [ y ] ;
if ( z [ 'WLANLinkProtectionLevel' ] || ( y == 1 ) ) { amtwirelessif = y ; } // Set the wireless interface, this seems to cover new wireless only computers and older computers with dual interfaces.
if ( y == 0 ) { if ( ( amtwirelessif != y ) && ( z [ "MACAddress" ] != "00-00-00-00-00-00" ) ) { amtwiredif = y ; } } // On computers with only wireless, the wired interface will have a null MAC
}
// Check if configuration change is required
if ( args ) {
2019-07-16 22:25:21 +03:00
var docall = false ;
var x = JSON . parse ( JSON . stringify ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ) ) ;
var y = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ;
delete x [ "IpSyncEnabled" ] ;
delete x [ "LinkIsUp" ] ;
delete x [ "LinkPolicy" ] ;
delete x [ "MACAddress" ] ;
delete x [ "SharedDynamicIP" ] ;
delete x [ "SharedMAC" ] ;
delete x [ "SharedStaticIp" ] ;
if ( ( y [ 'IpSyncEnabled' ] == false ) && ( args . ipsync === '1' ) ) { x [ 'IpSyncEnabled' ] = true ; docall = true ; }
if ( ( y [ 'IpSyncEnabled' ] == true ) && ( args . ipsync === '0' ) ) { x [ 'IpSyncEnabled' ] = false ; docall = true ; }
2019-07-16 00:45:36 +03:00
if ( args . dhcp && ( amtwiredif != - 1 ) && ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] . DHCPEnabled == false ) ) {
// Change to DHCP
x [ 'DHCPEnabled' ] = true ;
2019-07-16 22:25:21 +03:00
docall = true ;
2019-07-16 00:45:36 +03:00
}
else if ( args . static && ( amtwiredif != - 1 ) && ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] . DHCPEnabled == true ) ) {
// Change to STATIC
x [ 'DHCPEnabled' ] = false ;
if ( args . ip ) { x [ "IPAddress" ] = args . ip ; } else { console . log ( 'Missing IPv4 address, use --ip 1.2.3.4' ) ; process . exit ( 1 ) ; }
if ( args . subnet ) { x [ "SubnetMask" ] = args . subnet ; } else { console . log ( 'Missing IPv4 subnet, use --subnet 255.255.255.0' ) ; process . exit ( 1 ) ; }
if ( args . gateway ) { x [ "DefaultGateway" ] = args . gateway ; }
if ( args . dns ) { x [ "PrimaryDNS" ] = args . dns ; }
if ( args . dns2 ) { x [ "SecondaryDNS" ] = args . dns2 ; }
2019-07-16 22:25:21 +03:00
docall = true ;
}
if ( docall ) {
if ( x [ "DHCPEnabled" ] == true ) {
delete x [ "IPAddress" ] ;
delete x [ "DefaultGateway" ] ;
delete x [ "PrimaryDNS" ] ;
delete x [ "SecondaryDNS" ] ;
delete x [ "SubnetMask" ] ;
}
pendingAmtConfigActions ++ ;
//console.log(JSON.stringify(x, 4, ' '));
amtstack . Put ( "AMT_EthernetPortSettings" , x , function ( stack , name , response , status ) { if ( status != 200 ) { console . log ( 'Error, status ' + status + '.' ) ; } if ( -- pendingAmtConfigActions == 0 ) { performAmtNetConfig0 ( ) ; } } , null , 0 , x ) ;
2019-07-16 00:45:36 +03:00
}
}
if ( pendingAmtConfigActions == 0 ) {
2019-07-16 22:25:21 +03:00
var maxlen = 0 ;
if ( amtwiredif != - 1 ) { for ( var i in response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ) { if ( i . length > maxlen ) { maxlen = i . length ; } } }
if ( amtwirelessif != - 1 ) { for ( var i in response [ 'AMT_EthernetPortSettings' ] . responses [ amtwirelessif ] ) { if ( i . length > maxlen ) { maxlen = i . length ; } } }
2019-07-16 00:45:36 +03:00
if ( amtwiredif != - 1 ) { // Wired
var z = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ;
console . log ( '--WIRED---' ) ;
for ( var i in z ) {
if ( [ 'ElementName' , 'InstanceID' ] . indexOf ( i ) == - 1 ) {
var name = i ;
2019-07-16 22:25:21 +03:00
while ( name . length < maxlen ) { name += ' ' ; }
console . log ( name + ' : ' + z [ i ] ) ;
2019-07-16 00:45:36 +03:00
}
}
}
if ( amtwirelessif != - 1 ) { // Wireless
var z = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwirelessif ] ;
console . log ( '--WIRELESS---' ) ;
for ( var i in z ) {
if ( [ 'ElementName' , 'InstanceID' ] . indexOf ( i ) == - 1 ) {
var name = i ;
2019-07-16 22:25:21 +03:00
while ( name . length < maxlen ) { name += ' ' ; }
console . log ( name + ' : ' + z [ i ] ) ;
2019-07-16 00:45:36 +03:00
}
}
}
process . exit ( 0 ) ;
}
} else {
console . log ( 'Error, status ' + status + '.' ) ;
process . exit ( 1 ) ;
}
}
2019-07-15 22:55:52 +03:00
//
// Intel AMT feature configuration action
//
function performAmtFeatureConfig ( args ) {
2019-07-16 00:45:36 +03:00
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( performAmtFeatureConfig0 , false , args ) ;
} else {
performAmtFeatureConfig0 ( 1 , args ) ;
}
}
function performAmtFeatureConfig0 ( state , args ) {
2019-07-15 22:55:52 +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 ) ;
amtstack . BatchEnum ( null , [ '*IPS_OptInService' , '*AMT_RedirectionService' , '*CIM_KVMRedirectionSAP' ] , performAmtFeatureConfig1 , args ) ;
}
function performAmtFeatureConfig1 ( stack , name , response , status , args ) {
if ( status == 200 ) {
// User consent
var optinrequired = response [ 'IPS_OptInService' ] . response [ "OptInRequired" ] ;
if ( args ) {
if ( ( args . userconsent == 'none' ) && ( optinrequired != 0 ) ) {
pendingAmtConfigActions ++ ;
response [ 'IPS_OptInService' ] . response [ "OptInRequired" ] = 0 ;
2019-07-16 00:45:36 +03:00
amtstack . Put ( "IPS_OptInService" , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 22:55:52 +03:00
}
else if ( ( args . userconsent == 'kvm' ) && ( optinrequired != 1 ) ) {
pendingAmtConfigActions ++ ;
response [ 'IPS_OptInService' ] . response [ "OptInRequired" ] = 1 ;
2019-07-16 00:45:36 +03:00
amtstack . Put ( "IPS_OptInService" , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 22:55:52 +03:00
}
else if ( ( args . userconsent == 'all' ) && ( optinrequired != 0xFFFFFFFF ) ) {
pendingAmtConfigActions ++ ;
response [ 'IPS_OptInService' ] . response [ "OptInRequired" ] = 0xFFFFFFFF ;
2019-07-16 00:45:36 +03:00
amtstack . Put ( "IPS_OptInService" , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 22:55:52 +03:00
}
}
// Redirection ports
var redirportchange = false ;
var redirchange = false ;
var redir = ( response [ 'AMT_RedirectionService' ] . response [ "ListenerEnabled" ] == true ) ;
var sol = ( ( response [ 'AMT_RedirectionService' ] . response [ "EnabledState" ] & 2 ) != 0 ) ;
var ider = ( ( response [ 'AMT_RedirectionService' ] . response [ "EnabledState" ] & 1 ) != 0 ) ;
if ( args ) {
if ( ( redir == false ) && ( ( args . redir == 'enabled' ) || ( args . redir == 1 ) ) ) { response [ 'AMT_RedirectionService' ] . response [ "ListenerEnabled" ] = true ; redirportchange = true ; }
if ( ( redir == true ) && ( ( args . redir == 'disabled' ) || ( args . redir == 0 ) ) ) { response [ 'AMT_RedirectionService' ] . response [ "ListenerEnabled" ] = false ; redirportchange = true ; }
if ( ( sol == false ) && ( ( args . sol == 'enabled' ) || ( args . sol == 1 ) ) ) { sol = true ; redirchange = true ; }
if ( ( sol == true ) && ( ( args . sol == 'disabled' ) || ( args . sol == 0 ) ) ) { sol = false ; redirchange = true ; }
if ( ( ider == false ) && ( ( args . ider == 'enabled' ) || ( args . ider == 1 ) ) ) { ider = true ; redirchange = true ; }
if ( ( ider == true ) && ( ( args . ider == 'disabled' ) || ( args . ider == 0 ) ) ) { ider = false ; redirchange = true ; }
2019-07-16 00:45:36 +03:00
if ( redirportchange ) { pendingAmtConfigActions ++ ; amtstack . Put ( "AMT_RedirectionService" , response [ 'AMT_RedirectionService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ; }
if ( redirchange ) { pendingAmtConfigActions ++ ; amtstack . AMT _RedirectionService _RequestStateChange ( ( 32768 + ( ( ider ? 1 : 0 ) + ( sol ? 2 : 0 ) ) ) , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ; }
2019-07-15 22:55:52 +03:00
}
// KVM
var kvm = false ;
var kvmchange = false ;
if ( response [ 'CIM_KVMRedirectionSAP' ] != null ) {
kvm = ( ( response [ 'CIM_KVMRedirectionSAP' ] . response [ "EnabledState" ] == 6 && response [ 'CIM_KVMRedirectionSAP' ] . response [ "RequestedState" ] == 2 ) || response [ 'CIM_KVMRedirectionSAP' ] . response [ "EnabledState" ] == 2 || response [ 'CIM_KVMRedirectionSAP' ] . response [ "EnabledState" ] == 6 ) ;
if ( args ) {
if ( ( kvm == false ) && ( ( args . kvm == 'enabled' ) || ( args . kvm == 1 ) ) ) { kvm = true ; kvmchange = true ; }
if ( ( kvm == true ) && ( ( args . kvm == 'disabled' ) || ( args . kvm == 0 ) ) ) { kvm = false ; kvmchange = true ; }
2019-07-16 00:45:36 +03:00
if ( kvmchange ) { pendingAmtConfigActions ++ ; amtstack . CIM _KVMRedirectionSAP _RequestStateChange ( kvm ? 2 : 3 , 0 , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ; }
2019-07-15 22:55:52 +03:00
}
}
if ( pendingAmtConfigActions == 0 ) {
2019-07-16 00:45:36 +03:00
if ( optinrequired == 0 ) { console . log ( 'User Consent : None' ) ; }
else if ( optinrequired == 1 ) { console . log ( 'User Consent : KVM' ) ; }
else if ( optinrequired == 0xFFFFFFFF ) { console . log ( 'User Consent : All' ) ; }
else { console . log ( 'User Consent : ' + optinrequired ) ; }
console . log ( 'Redirection Port : ' + ( redir ? 'Enabled' : 'Disabled' ) ) ;
console . log ( 'Serial-over-LAN : ' + ( sol ? 'Enabled' : 'Disabled' ) ) ;
console . log ( 'IDE Redirection : ' + ( ider ? 'Enabled' : 'Disabled' ) ) ;
if ( response [ 'CIM_KVMRedirectionSAP' ] != null ) { console . log ( 'Remote desktop (KVM) : ' + ( kvm ? 'Enabled' : 'Disabled' ) ) ; }
2019-07-15 22:55:52 +03:00
process . exit ( 0 ) ;
}
} else {
console . log ( 'Error, status ' + status + '.' ) ;
process . exit ( 1 ) ;
}
}
2019-07-12 02:54:27 +03:00
//
// Intel AMT Remote Power Action
//
function performAmtPowerAction ( ) {
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
amtstack = new amt ( wsstack ) ;
if ( settings . poweraction != 0 ) {
// Set the power state
amtstack . RequestPowerStateChange ( settings . poweraction , performAmtPowerActionEx ) ;
} else {
// Get the power state
amtstack . Get ( "CIM_AssociatedPowerManagementService" , performAmtPowerActionEx2 , 0 , 1 ) ;
}
}
function performAmtPowerActionEx ( stack , name , response , status ) {
if ( status == 200 ) {
console . log ( response . Body . ReturnValueStr . split ( '_' ) . join ( ' ' ) ) ;
process . exit ( 0 ) ;
} else {
console . log ( 'Error, status ' + status + '.' ) ;
process . exit ( 1 ) ;
}
}
var DMTFPowerStates = [ "" , "" , "Power on" , "Light sleep" , "Deep sleep" , "Power cycle (Soft off)" , "Off - Hard" , "Hibernate (Off soft)" , "Soft off" , "Power cycle (Off-hard)" , "Master bus reset" , "Diagnostic interrupt (NMI)" , "Not applicable" , "Off - Soft graceful" , "Off - Hard graceful" , "Master bus reset graceful" , "Power cycle (Off - Soft graceful)" , "Power cycle (Off - Hard graceful)" , "Diagnostic interrupt (INIT)" ] ;
function performAmtPowerActionEx2 ( stack , name , response , status ) {
if ( status == 200 ) {
var powerNumber = parseInt ( response . Body . PowerState ) ;
if ( ( powerNumber >= DMTFPowerStates . length ) && ( powerNumber > 1 ) ) {
console . log ( 'Unknown power state: ' + response . Body . PowerState ) ;
} else {
console . log ( 'Current power state: ' + DMTFPowerStates [ powerNumber ] ) ;
}
process . exit ( 0 ) ;
} else {
console . log ( 'Error, status ' + status + '.' ) ;
process . exit ( 1 ) ;
}
}
2019-06-20 03:59:03 +03:00
//
// Startup
//
// 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 ;
}
// Remove a element from a array
function removeItemFromArray ( array , element ) {
var index = array . indexOf ( element ) ;
if ( index !== - 1 ) { array . splice ( index , 1 ) ; }
}
// 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 ;
var serviceInstall = 0 ;
for ( var i in process . argv ) {
if ( process . argv [ i ] . toLowerCase ( ) == 'install' ) { serviceInstall = 1 } else if ( process . argv [ i ] . toLowerCase ( ) == 'uninstall' ) { serviceInstall = - 1 }
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 ; }
}
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.' ) ;
process . exit ( ) ;
}
}
if ( process . execPath . includes ( 'MicroLMS' ) ) { serviceName = 'MicroLMS' ; }
else if ( process . execPath . includes ( 'MeshCommander' ) ) { serviceName = 'MeshCommander' ; }
else { serviceName = 'not_a_service' ; }
}
if ( serviceInstall == 0 ) {
run ( process . argv ) ;
} else {
var serviceHost = require ( 'service-host' ) ;
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 ) ; }
} ) ;
// 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.
// 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 ( ) ;
}