2018-01-30 21:23:57 -05:00
/ *
2020-01-02 21:30:12 -05:00
Copyright 2018 - 2020 Intel Corporation
2018-01-30 21:23:57 -05:00
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
/ * *
* @ description MeshCmd , command line tool for Intel AMT and MeshCentral .
* @ author Ylian Saint - Hilaire
* @ version v0 . 2.0
* /
2018-08-06 21:57:30 -04:00
// Debug Stuff
//console.displayFinalizerMessages = 1; // Display objects that have event listeners that are disposed.
//console.displayStreamPipeMessages = 1; // Display stream pipe and un-pipes
//var __gc = setInterval(function () { console.log('GC'); _debugGC() }, 2000); //
2018-03-06 20:50:44 -05:00
2017-10-31 19:19:58 -04:00
var fs = require ( 'fs' ) ;
var os = require ( 'os' ) ;
var net = require ( 'net' ) ;
var http = require ( 'http' ) ;
var dgram = require ( 'dgram' ) ;
var httpHeaders = require ( 'http-headers' ) ;
var tcpserver = null ;
var broadcastSockets = { } ;
var multicastSockets = { } ;
var discoveryInterval = null ;
var membershipIPv4 = '239.255.255.235' ;
var membershipIPv6 = 'FF02:0:0:0:0:0:0:FE' ;
2017-12-12 19:04:54 -05:00
var settings = null ;
2018-01-30 21:23:57 -05:00
var meshCmdVersion = '***Mesh*Cmd*Version***' ; // Dynamically replaced with MeshCentral version
2017-12-12 19:04:54 -05:00
var amtLms = null , amtMei = null , amtMeiState = null ;
2018-02-07 21:45:14 -05:00
var wsstack = null , amtstack = null ;
var oswsstack = null , osamtstack = null ;
2018-03-06 20:50:44 -05:00
var amtMeiTmpState = null ;
2018-03-12 21:16:06 -04:00
var SMBiosTables = null ;
2019-06-06 12:59:13 -04:00
var globalDebugFlags = 0 ; // 1 = IDER Debug
2019-07-15 17:45:36 -04:00
var pendingAmtConfigActions = 0 ;
2019-09-16 13:49:35 -04:00
var RCSMessageProtocolVersion = 1 ; // RCS Message Protocol Version. Needs to be less than or equal to RCS server Message Protocol Version
2018-02-07 21:45:14 -05:00
2019-07-05 16:28:41 -04:00
// MeshCommander for Firmware (GZIP'ed, Base64) v0.7.8
var Large _IntelAmtWebApp _etag = "zVObfGF4CXPIxvxSUu+3" ;
var Large _IntelAmtWebApp = " H4sIAAAAAAAEAHq / e7 + Noou / c0hkgCuA0 + pcchQHwq9CeXNgFzwZlrmcc76 / DWpANULihJyW8rtfy4KxPHjjRKvD1586QVCbRly / sn + DzmwEZjXyqjZJHEUPSI7Arl81aIAMTRvifwu + zP4N //os/EI1LRieCwwKJQ1Kk82++ypDVuHMuezlBtfmpY2RFjXoDk22MGV4OfNBv3DG4Z+bFgd/CQ1mpdINmJChwcJwJX1UgW2tJGZSUUjB5U2gUWQzTiazwBBQxhuo8GUrq6DWWGYzBgaSW2GaQ4fnp8/535//8vsq+uGbSmWEtEvEda7YpveykTawDv2zWqIuhVolNWcMZVoqol9Cw8UmAc1BPA9qFEs0vIDnQQeyCzvUvHSGHX+NyVVr0kIJpZNcQHGT5vSn0mohWbKquUGKqSsuQ6PaJBoPAkuzP2kiZI/hCvMbbsh0UdRhAUKohUmkknirWlB4oiCwGBU3tihH5I16fUzaTYUTwVbw3lEjUi0wxmWVRCSGHEXPeNcK2NB1VXEzXH3FJVMr2yPe/UNflx4BXHFmalcIh53UtiD9BKKmBAn6Nemd8y7iFpIl77hB1ttzyLBQGmyjues4n3vRaWlNbY+9j52jMsjOzs7SbR33+7LHcWtcF6xcP+VKML8RDkp91q79Poij/TlXxqgmOSfJtp57Ea4+JMD5YYDzCT6Vr+3f4nE69Thsz7klaNghQZLUU8mYu4XuiGyruDSo/cG4BwDp9oVdTWTXqo7vqlDyNbLUDcowIeNoDEN7fkEsfKDo5DwNti9arSqNXZfDMTjndhxxPgUkZlwe5OqU6kVSoaret83zHPIzp4jf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ff3h0+nbvTZ3+O5vc1/r+cB8xUha7fmE8V8kWYvey+3QVh2ROyWoZ+jkND3CMjwjVKeLbB3hswX4/OmKUd/MTRbtwmYdAE0NR7cgPv0Z83NOhz5aPfy3a+UKdXX6YnLdnp23Lsvrdn2M/uVvxvcR7aNK+zVrFo4sk5SA0yzhckqZLmlDek/P1ovlJ61/mfNQDDxwrbxlTn1ES3NPggdzTjHuGlQdblTvhudlQ7G0RD1+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 / Kt5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evwvO3+U67hnGGvU/lcIdhpGK57OVEP13FysaeAdmnUyioRw15xxlGi8weUVm3xxJl1wKGEb4yVOaoqHox+Jc21dcEnMB3cygSeh2/aFWyR7GxSRt0oRreP5nQLsndUwriq46d57IC40pOqqYCrvLBKHOyCrTzIbbiiH3XO6R6dv6UjSovwBg7TmAfDQ5kaSO2lFbMP1aXANeSN4tOW9r3833FoQruUHs74zCsPLIMZrDGmGfETHJkhzLqy+FiFMnvsxACUzNEpF+c4VpOwbGWiwI1Is4LbUizyPDuCNp4JJ3uyLWYGpwOvqW293SZMP7jBIXjlfXskJxqlYkubz/B0vXfqM5LraeKY8/Tjtsp8mJhVSeGkpQC50GKNxn4RN3u+ijPe4834N3dSagJyGDfczNBF50x4XYqcovcY2kr4XT6bAzYDChUWNULsL3a1LmEgZUVT0KbIvH8NjYKYeOLGFzzZy67lMtvFlG5xku2cZimCAY9YLDSi/2ZsQTpCJf75BDFd08gY48g0ze+YwLWQObhimE1lDzEKt2ws6ocLYa0MkMpKB2ZhLjVbPN/roXObmZt3SHV9D66KCvYRrNm/MHjS9ytn3/vjpHZc8ZeYowjYZWiu9P8UTQscEAkC9Cuq6x6O2TsKmDLa1aNJJkZfQVy7UXGvyim1LC+SL3JbAUkAGWksEpqNheKiqGqO/HFFtlHH/GoQt6lD9Aop1ST1lLjU74hvGUDSxGhIvz5AGs6CTYy8B
2017-10-31 19:19:58 -04:00
// Check the server certificate fingerprint
function onVerifyServer ( clientName , certs ) {
2018-01-26 20:01:38 -05:00
if ( certs == null ) { certs = clientName ; } // Temporary thing until we fix duktape
2019-03-26 18:18:07 -04:00
try { for ( var i in certs ) { if ( certs [ i ] . fingerprint . replace ( /:/g , '' ) == settings . serverhttpshash ) { return ; } } } catch ( e ) { }
2019-06-23 01:06:50 -04: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' ;
}
2017-10-31 19:19:58 -04:00
}
2018-03-06 20:50:44 -05:00
// Various utility functions
2019-03-26 18:18:07 -04:00
function debug ( level , message ) { if ( ( settings . debuglevel != null ) && ( settings . debuglevel >= level ) ) { console . log ( message ) ; } }
2017-12-12 19:04:54 -05:00
function exit ( status ) { if ( status == null ) { status = 0 ; } try { process . exit ( status ) ; } catch ( e ) { } }
2018-03-06 20:50:44 -05:00
function getInstance ( x , y ) { for ( var i in x ) { if ( x [ i ] [ "InstanceID" ] == y ) return x [ i ] ; } return null ; }
function md5hex ( str ) { return require ( 'MD5Stream' ) . create ( ) . syncHash ( str ) . toString ( 'hex' ) ; }
function guidToStr ( g ) { return g . substring ( 6 , 8 ) + g . substring ( 4 , 6 ) + g . substring ( 2 , 4 ) + g . substring ( 0 , 2 ) + "-" + g . substring ( 10 , 12 ) + g . substring ( 8 , 10 ) + "-" + g . substring ( 14 , 16 ) + g . substring ( 12 , 14 ) + "-" + g . substring ( 16 , 20 ) + "-" + g . substring ( 20 ) ; }
function parceArguments ( argv ) { var r = { } ; for ( var i in argv ) { i = parseInt ( i ) ; if ( argv [ i ] . startsWith ( '--' ) == true ) { var key = argv [ i ] . substring ( 2 ) . toLowerCase ( ) , val = true ; if ( ( ( i + 1 ) < argv . length ) && ( argv [ i + 1 ] . startsWith ( '--' ) == false ) ) { val = argv [ i + 1 ] ; } r [ key ] = val ; } } return r ; }
2017-11-02 21:44:27 -04:00
2018-03-12 21:16:06 -04:00
// Convert an object to string with all functions
function objToString ( x , p , ret ) {
if ( ret == undefined ) ret = '' ;
if ( p == undefined ) p = 0 ;
if ( x == null ) { return '[null]' ; }
if ( p > 8 ) { return '[...]' ; }
if ( x == undefined ) { return '[undefined]' ; }
if ( typeof x == 'string' ) { if ( p == 0 ) return x ; return '"' + ( x . split ( '\0' ) [ 0 ] ) + '"' ; }
if ( typeof x == 'buffer' ) { return '[buffer]' ; }
if ( typeof x != 'object' ) { return x ; }
var r = '{' + ( ret ? '\r\n' : ' ' ) ;
for ( var i in x ) {
if ( i != '_ObjectID' ) { r += ( addPad ( p + 2 , ret ) + i + ': ' + objToString ( x [ i ] , p + 2 , ret ) + ( ret ? '\r\n' : ' ' ) ) ; }
}
return r + addPad ( p , ret ) + '}' ;
}
// Return p number of spaces
function addPad ( p , ret ) { var r = '' ; for ( var i = 0 ; i < p ; i ++ ) { r += ' ' ; } return r ; }
2018-01-30 21:23:57 -05:00
// Parse the incoming arguments
2018-04-04 15:08:28 -04:00
function run ( argv ) {
2017-12-12 19:04:54 -05:00
if ( meshCmdVersion [ 0 ] == '*' ) { meshCmdVersion = '' ; } else { meshCmdVersion = ' v' + meshCmdVersion ; }
2017-11-02 21:44:27 -04:00
var args = parceArguments ( argv ) ;
2018-03-12 21:16:06 -04:00
//console.log(JSON.stringify(argv));
2017-12-12 19:04:54 -05:00
//console.log('addedModules = ' + JSON.stringify(addedModules));
2017-10-31 19:19:58 -04:00
var actionpath = 'meshaction.txt' ;
2017-11-02 21:44:27 -04:00
if ( args . actionfile != null ) { actionpath = args . actionfile ; }
2020-05-13 03:27:31 -04:00
var actions = [ 'HELP' , 'ROUTE' , 'MICROLMS' , 'AMTSCAN' , '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' , 'AMTWIFI' , 'AMTWAKE' ] ;
2017-12-12 19:04:54 -05:00
2017-10-31 19:19:58 -04:00
// Load the action file
var actionfile = null ;
try { actionfile = fs . readFileSync ( actionpath ) ; } catch ( e ) { }
2017-12-12 19:04:54 -05:00
if ( ( actionpath != 'meshaction.txt' ) && ( actionfile == null ) ) { console . log ( 'Unable to load \"' + actionpath + '\". Create this file or specify the location using --actionfile [filename].' ) ; exit ( 1 ) ; return ; }
if ( actionfile != null ) { try { settings = JSON . parse ( actionfile ) ; } catch ( e ) { console . log ( actionpath , e ) ; exit ( 1 ) ; return ; } } else { if ( argv . length >= 2 ) { settings = { action : argv [ 1 ] } } }
2017-12-15 16:43:04 -05:00
if ( settings == null ) { settings = { } ; }
2019-03-26 18:18:07 -04:00
var settings2 = { } ; for ( var i in settings ) { settings2 [ i . toLowerCase ( ) ] = settings [ i ] ; } settings = settings2 ;
2017-10-31 19:19:58 -04:00
2017-11-02 21:44:27 -04:00
// Set the arguments
2017-12-15 16:43:04 -05:00
if ( ( typeof args . action ) == 'string' ) { settings . action = args . action ; }
2017-11-02 21:44:27 -04:00
if ( ( typeof args . localport ) == 'string' ) { settings . localport = parseInt ( args . localport ) ; }
2019-03-26 18:18:07 -04:00
if ( ( typeof args . remotenodeid ) == 'string' ) { settings . remotenodeid = args . remotenodeid ; }
2019-06-24 21:56:14 -04:00
if ( ( typeof args . name ) == 'string' ) { settings . name = args . name ; }
2017-11-02 21:44:27 -04:00
if ( ( typeof args . username ) == 'string' ) { settings . username = args . username ; }
if ( ( typeof args . password ) == 'string' ) { settings . password = args . password ; }
2019-06-21 20:42:43 -04:00
if ( ( typeof args . url ) == 'string' ) { settings . url = args . url ; }
2019-06-13 12:12:11 -04:00
if ( ( typeof args . profile ) == 'string' ) { settings . profile = args . profile ; }
2019-05-24 14:33:59 -04:00
if ( ( typeof args . type ) == 'string' ) { settings . type = args . type ; }
2017-11-02 21:44:27 -04:00
if ( ( typeof args . user ) == 'string' ) { settings . username = args . user ; }
if ( ( typeof args . pass ) == 'string' ) { settings . password = args . pass ; }
2017-12-12 19:04:54 -05:00
if ( ( typeof args . host ) == 'string' ) { settings . hostname = args . host ; }
if ( ( typeof args . hostname ) == 'string' ) { settings . hostname = args . hostname ; }
2019-03-26 18:18:07 -04:00
if ( ( typeof args . serverid ) == 'string' ) { settings . serverid = args . serverid ; }
if ( ( typeof args . serverhttpshash ) == 'string' ) { settings . serverhttpshash = args . serverhttpshash ; }
2020-05-22 13:17:53 -04:00
if ( ( typeof args . serverurl ) == 'string' ) { settings . serverurl = args . serverurl ; }
2019-03-26 18:18:07 -04:00
if ( ( typeof args . remoteport ) == 'string' ) { settings . remoteport = parseInt ( args . remoteport ) ; }
2019-10-25 04:16:00 -04:00
if ( ( typeof args . remotetarget ) == 'string' ) { settings . remotetarget = args . remotetarget ; }
2018-01-25 19:12:53 -05:00
if ( ( typeof args . out ) == 'string' ) { settings . output = args . out ; }
if ( ( typeof args . output ) == 'string' ) { settings . output = args . output ; }
2019-03-26 18:18:07 -04:00
if ( ( typeof args . debug ) == 'string' ) { settings . debuglevel = parseInt ( args . debug ) ; }
2019-04-29 18:31:11 -04:00
if ( ( typeof args . debugflags ) == 'string' ) { globalDebugFlags = parseInt ( args . debugflags ) ; }
2018-02-02 15:46:09 -05:00
if ( ( typeof args . script ) == 'string' ) { settings . script = args . script ; }
2018-04-28 18:36:10 -04:00
if ( ( typeof args . agent ) == 'string' ) { settings . agent = args . agent ; }
2019-03-27 15:55:31 -04:00
if ( ( typeof args . proxy ) == 'string' ) { settings . proxy = args . proxy ; }
2019-06-06 12:59:13 -04:00
if ( ( typeof args . floppy ) == 'string' ) { settings . floppy = args . floppy ; }
if ( ( typeof args . cdrom ) == 'string' ) { settings . cdrom = args . cdrom ; }
2019-06-24 21:56:14 -04:00
if ( ( typeof args . tag ) == 'string' ) { settings . tag = args . tag ; }
2019-10-01 19:53:10 -04:00
if ( ( typeof args . scan ) == 'string' ) { settings . scan = args . scan ; }
2020-04-03 19:06:38 -04:00
if ( ( typeof args . token ) == 'string' ) { settings . token = args . token ; }
2019-06-06 12:59:13 -04:00
if ( ( typeof args . timeout ) == 'string' ) { settings . timeout = parseInt ( args . timeout ) ; }
2019-10-22 19:29:02 -04:00
if ( ( typeof args . uuidoutput ) == 'string' || args . uuidoutput ) { settings . uuidoutput = args . uuidoutput ; }
2020-04-03 19:06:38 -04:00
if ( args . emailtoken ) { settings . emailtoken = true ; }
2019-06-06 12:59:13 -04:00
if ( args . debug === true ) { settings . debuglevel = 1 ; }
2018-08-06 21:57:30 -04:00
if ( args . debug ) { try { waitForDebugger ( ) ; } catch ( e ) { } }
2018-01-25 19:28:52 -05:00
if ( args . noconsole ) { settings . noconsole = true ; }
if ( args . nocommander ) { settings . noconsole = true ; }
2018-01-25 19:12:53 -05:00
if ( args . lmsdebug ) { settings . lmsdebug = true ; }
2019-07-15 18:44:18 -04:00
if ( args . json ) { settings . json = true ; }
2018-01-25 19:12:53 -05:00
if ( args . tls ) { settings . tls = true ; }
2017-12-15 16:43:04 -05:00
if ( ( argv . length > 1 ) && ( actions . indexOf ( argv [ 1 ] . toUpperCase ( ) ) >= 0 ) ) { settings . action = argv [ 1 ] ; }
2017-11-02 21:44:27 -04:00
2017-10-31 19:19:58 -04:00
// Validate meshaction.txt
2018-03-12 21:16:06 -04:00
if ( settings . action == null ) {
console . log ( 'MeshCentral Command (MeshCmd) ' + meshCmdVersion ) ;
console . log ( 'No action specified, use MeshCmd like this:\r\n' ) ;
console . log ( ' meshcmd [action] [arguments...]\r\n' ) ;
console . log ( 'Valid MeshCentral actions:' ) ;
2019-07-15 15:55:52 -04:00
console . log ( ' Route - Map a local TCP port to a remote computer.' ) ;
2018-03-12 21:16:06 -04:00
console . log ( '\r\nValid local actions:' ) ;
2019-05-24 14:33:59 -04:00
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.' ) ;
2019-06-14 19:33:53 -04:00
console . log ( ' AmtACM - Activate Intel AMT into Admin Control Mode.' ) ;
2019-05-24 14:33:59 -04:00
console . log ( ' AmtDeactivate - Deactivate Intel AMT if activated in Client Control mode.' ) ;
console . log ( ' AmtAcmDeactivate - Deactivate Intel AMT if activated in Admin Control mode.' ) ;
2018-03-12 21:16:06 -04:00
console . log ( '\r\nValid local or remote actions:' ) ;
2019-05-24 14:33:59 -04:00
console . log ( ' MeshCommander - Launch a local MeshCommander web server.' ) ;
console . log ( ' AmtUUID - Show Intel AMT unique identifier.' ) ;
2019-07-15 18:44:18 -04:00
console . log ( ' AmtEventLog - Show the Intel AMT event log.' ) ;
2019-05-24 14:33:59 -04: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-11 19:54:27 -04:00
console . log ( ' AmtPower - Perform remote Intel AMT power operation.' ) ;
2019-05-24 14:33:59 -04:00
console . log ( ' AmtScript - Run .mescript on Intel AMT.' ) ;
2019-06-06 12:59:13 -04:00
console . log ( ' AmtIDER - Mount local disk image to remote computer.' ) ;
2019-07-15 15:55:52 -04:00
console . log ( ' AmtFeatures - Intel AMT features & user consent.' ) ;
2019-07-15 17:45:36 -04:00
console . log ( ' AmtNetwork - Intel AMT network interface settings.' ) ;
2019-10-01 19:53:10 -04:00
console . log ( ' AmtScan - Search local network for Intel AMT devices.' ) ;
2020-04-09 15:14:09 -04:00
console . log ( ' AmtWifi - Intel AMT Wifi interface settings.' ) ;
2020-05-13 03:27:31 -04:00
console . log ( ' AmtWake - Intel AMT Wake Alarms.' ) ;
2018-03-12 21:16:06 -04: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' ) ;
2018-04-04 15:08:28 -04:00
} else if ( ( action == 'microlms' ) || ( action == 'lms' ) || ( action == 'amtlms' ) ) {
console . log ( 'Starts MicroLMS on this computer, allowing local access to Intel AMT on TCP ports 16992 and 16993 when applicable. The command must be run on a computer with Intel AMT, must run as administrator and the Intel management driver must be installed. These certificates hashes are used by Intel AMT when performing activation into ACM mode. Example usage:\r\n\r\n meshcmd microlms' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --noconsole MeshCommander for LMS will no be available on port 16994.' ) ;
2018-04-04 15:08:28 -04:00
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' microlms install/uninstall/start/stop.' ) ;
2018-03-12 21:16:06 -04:00
} else if ( action == 'amtccm' ) {
2019-06-24 21:56:14 -04: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-05-24 14:33:59 -04:00
} else if ( action == 'amtacm' ) {
2019-06-21 20:42:43 -04: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-05-24 14:33:59 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2019-06-24 21:56:14 -04: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.' ) ;
2018-03-12 21:16:06 -04: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' ) ;
2019-05-24 14:33:59 -04:00
} else if ( action == 'amtacmdeactivate' ) {
2019-05-29 15:45:21 -04:00
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' ) ;
2019-05-24 14:33:59 -04:00
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.' ) ;
2018-03-12 21:16:06 -04:00
} else if ( action == 'amtuuid' ) {
console . log ( 'AmtUUID action will get the unique identifier of the local or remote Intel AMT computer. By default, the local UUID is obtained unless a host is specified. Intel AMT must be activated for this command to work. Example usage:\r\n\r\n meshcmd amtuuid --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
} else if ( ( action == 'amtloadwebapp' ) || ( action == 'amtloadsmallwebapp' ) || ( action == 'amtloadlargewebapp' ) || ( action == 'amtclearwebapp' ) || ( action == 'amtstoragestate' ) ) {
console . log ( 'AmtLoadWebApp action will load MeshCommander into Intel AMT 11.6 or higher. If the computer is in ACM mode, MeshCommander will replace the default index.htm on HTTP/16992 or HTTPS/16993. If Intel AMT is in CCM mode, MeshCommander will be installed alongside the default web page and will be accessible in the "Web Applications" section. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtloadwebapp --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
} else if ( action == 'amtclearwebstorage' ) {
console . log ( 'AmtClearWebStorage will clear the web storage of Intel AMT, removing any loaded firmware version of MeshCommander. This command can clear the local or a remote Intel AMT computer. By default, the local computer storage is cleared unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtclearwebstorage --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
} else if ( action == 'amtstoragestate' ) {
console . log ( 'AmtStorageState will display the content of the web storage of Intel AMT including any loaded firmware version of MeshCommander. This command can read the storage state of a local or remote Intel AMT computer. By default, the local computer storage state is displayed unless a host is specified. Intel AMT must be activated for this command to work. This action works on Intel AMT 11.6 and higher only. Example usage:\r\n\r\n meshcmd amtstoragestate --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
} else if ( action == 'amtsavestate' ) {
console . log ( 'AmtSaveState action will fetch all the entire state of Intel AMT and save it as a JSON file. This action will take multiple minutes to perform. The command will fetch the local computer state unless host is specified. Intel AMT must be ativated for this command to work. Example usage:\r\n\r\n meshcmd amtsavestate --host 1.2.3.4 --user admin --pass mypassword --tls --output state.json' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --output [filename] The output file for the Intel AMT state in JSON format.' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
2018-04-28 18:36:10 -04:00
} else if ( action == 'amtpresence' ) {
console . log ( 'AmtPresence will heartbeat a local Intel AMT watchdog agent. Example usage:\r\n\r\n meshcmd amtpresence --agent B4B6A24C-255E-A75C-F5E8-B00B4D946AA7' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --agent [uuid] The unique identifier of the watchdog agent.' ) ;
2018-03-12 21:16:06 -04:00
} else if ( action == 'amtscript' ) {
console . log ( 'AmtScript will run a .mescript file on the local or remote Intel AMT. Script files can be built using the MeshCommander script editor and be used to setup or perform actions on Intel AMT. Example usage:\r\n\r\n meshcmd amtscript --script myscript.mescript --host 1.2.3.4 --user admin --pass mypassword --tls' ) ;
2018-03-19 20:31:54 -04:00
console . log ( '\r\nPossible arguments:\r\n' ) ;
2018-03-12 21:16:06 -04:00
console . log ( ' --script [filename] The script file to run on Intel AMT.' ) ;
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT, 127.0.0.1 is default.' ) ;
console . log ( ' --user [username] The Intel AMT login username, admin is default.' ) ;
console . log ( ' --pass [password] The Intel AMT login password.' ) ;
console . log ( ' --tls Specifies that TLS must be used.' ) ;
2019-07-11 19:54:27 -04: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-15 17:45:36 -04:00
console . log ( ' --host [hostname] The IP address or DNS name of Intel AMT.' ) ;
2019-07-11 19:54:27 -04: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-15 17:45:36 -04: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 15:25:21 -04:00
console . log ( ' --ipsync [0 or 1] Change the wired IPSync setting on Intel AMT 7+' ) ;
2019-07-15 17:45:36 -04: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 15:55:52 -04: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.' ) ;
2018-03-19 20:31:54 -04:00
} else if ( action == 'meshcommander' ) {
console . log ( 'This action launched a local web server that hosts MeshCommander, a Intel AMT management console.' ) ;
console . log ( '\r\nPossible arguments:\r\n' ) ;
console . log ( ' --localport [port] Local port used for the web server, 3000 is default.' ) ;
2018-04-04 15:08:28 -04:00
console . log ( '\r\nRun as a background service:\r\n' ) ;
console . log ( ' meshcommander install/uninstall/start/stop.' ) ;
2019-07-15 18:44:18 -04: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.' ) ;
2019-10-22 19:29:02 -04:00
console . log ( ' --uuidoutput Output with unique identifier as the filename.' ) ;
2019-07-15 18:44:18 -04:00
console . log ( ' --json Output as a JSON format.' ) ;
2018-03-20 20:48:03 -04: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-15 18:44:18 -04:00
console . log ( ' --output [filename] The output file for the Intel AMT audit log.' ) ;
2018-03-20 20:48:03 -04: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-10-22 19:29:02 -04:00
console . log ( ' --uuidoutput Output with unique identifier as the filename.' ) ;
2019-07-15 18:44:18 -04:00
console . log ( ' --json Output as a JSON format.' ) ;
2019-06-06 12:59:13 -04: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.' ) ;
2019-10-01 19:53:10 -04:00
} else if ( action == 'amtscan' ) {
console . log ( 'AmtSCAN will look for Intel AMT device on the network. Example usage:\r\n\r\n meshcmd amtscan --scan 192.168.1.0/24' ) ;
console . log ( '\r\Required arguments:\r\n' ) ;
console . log ( ' --scan [ip range] The IP address range to perform the scan on.' ) ;
2020-04-09 15:14:09 -04:00
} else if ( action == 'amtwifi' ) {
console . log ( 'AmtWifi is used to get/set Intel AMT Wifi configuration. Example usage:\r\n\r\n meshcmd amtwifi --host 1.2.3.4 --user admin --pass mypassword --list' ) ;
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 ( ' --[action] Action options are list, add, del.' ) ;
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.' ) ;
2020-05-13 03:27:31 -04:00
console . log ( ' --list List Wifi profiles' ) ;
2020-04-09 15:14:09 -04:00
console . log ( ' --add Add new Wifi profile' ) ;
console . log ( ' --name New Wifi profile name' ) ;
2020-04-09 15:22:15 -04:00
console . log ( ' --priority Priority of this profile - default 0' ) ;
2020-04-09 15:14:09 -04:00
console . log ( ' --ssid Wifi SSID' ) ;
console . log ( ' --auth Wifi Authentication method (4 - WPA, 6 - WPA2/RSN) - default 6' ) ;
console . log ( ' --enc Wifi Encryption type (3 - TKIP, 4 - CCMP) - default 3' ) ;
console . log ( ' --psk Wifi password/pre-shared key' ) ;
console . log ( ' --del [profile-name] Delete new Wifi profile' ) ;
2020-05-13 03:27:31 -04:00
} else if ( action == 'amtwake' ) {
console . log ( 'AmtWake is used to view/set/remote Intel AMT Wake Alarms. Example usage:\r\n\r\n meshcmd amtwake --host 1.2.3.4 --user admin --pass mypassword --list' ) ;
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 ( ' --[action] Action options are list, add, del.' ) ;
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 ( ' --list List wake alarms profile' ) ;
console . log ( ' --add [alarm-name] Add new wake alarm' ) ;
console . log ( ' --date [yyyy-mm-dd] Alarm date in year-month-day format' ) ;
console . log ( ' --time (hh:mm:ss) Optional alarm time in hours:minutes:seconds format, default is 00:00:00.' ) ;
console . log ( ' --interval (dd-hh-mm) Optional alarm interval in days-hours-minutes format, default is alarm once.' ) ;
console . log ( ' --deletewhendone Indicates alarm is removed once triggered, default is to no remove.' ) ;
console . log ( ' --del [alarm-name] Remove a wake alarm' ) ;
2018-03-12 21:16:06 -04:00
} else {
actions . shift ( ) ;
console . log ( 'Invalid action, usage:\r\n\r\n meshcmd help [action]\r\n\r\nValid actions are: ' + actions . join ( ', ' ) + '.' ) ;
}
exit ( 1 ) ; return ;
}
2017-10-31 19:19:58 -04:00
settings . action = settings . action . toLowerCase ( ) ;
2017-12-12 19:04:54 -05:00
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2019-03-27 15:55:31 -04:00
// 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 ) ;
}
2018-03-12 21:16:06 -04:00
if ( settings . action == 'smbios' ) {
// Display SM BIOS tables in raw form
SMBiosTables = require ( 'smbios' ) ;
SMBiosTables . get ( function ( data ) {
var r = SMBiosTables . parse ( data ) ;
var out = objToString ( r , 0 , '\r\n' ) ;
2019-01-02 21:34:50 -05:00
if ( settings . output == null ) { console . log ( out ) ; } else { var file = fs . openSync ( settings . output , 'w' ) ; fs . writeSync ( file , Buffer . from ( out , 'utf8' ) ) ; fs . closeSync ( file ) ; }
2018-03-12 21:16:06 -04:00
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'rawsmbios' ) {
// Display SM BIOS tables in raw form
SMBiosTables = require ( 'smbios' ) ;
SMBiosTables . get ( function ( data ) {
var out = '' ;
for ( var i in data ) { var header = false ; for ( var j in data [ i ] ) { if ( data [ i ] [ j ] . length > 0 ) { if ( header == false ) { out += ( 'Table type #' + i + ( ( SMBiosTables . smTableTypes [ i ] == null ) ? '' : ( ', ' + SMBiosTables . smTableTypes [ i ] ) ) ) + '\r\n' ; header = true ; } out += ( ' ' + data [ i ] [ j ] . toString ( 'hex' ) ) + '\r\n' ; } } }
2019-01-02 21:34:50 -05:00
if ( settings . output == null ) { console . log ( out ) ; } else { var file = fs . openSync ( settings . output , 'w' ) ; fs . writeSync ( file , Buffer . from ( out , 'utf8' ) ) ; fs . closeSync ( file ) ; }
2018-03-12 21:16:06 -04:00
exit ( 1 ) ;
} ) ;
} else if ( settings . action == 'route' ) {
2018-01-30 21:23:57 -05:00
// MeshCentral Router, port map local TCP port to a remote computer
2019-03-26 18:18:07 -04:00
if ( ( settings . localport == null ) || ( typeof settings . localport != 'number' ) || ( settings . localport < 0 ) || ( settings . localport > 65535 ) ) { console . log ( 'No or invalid \"localPort\" specified, use --localport [localport].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . remotenodeid == null ) || ( typeof settings . remotenodeid != 'string' ) ) { console . log ( 'No or invalid \"remoteNodeId\" specified.' ) ; exit ( 1 ) ; return ; }
2017-12-12 19:04:54 -05:00
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 ; }
2019-03-26 18:18:07 -04:00
if ( ( settings . serverid == null ) || ( typeof settings . serverid != 'string' ) || ( settings . serverid . length != 96 ) ) { console . log ( 'No or invalid \"serverId\" specified.' ) ; exit ( 1 ) ; return ; }
if ( ( settings . serverhttpshash == null ) || ( typeof settings . serverhttpshash != 'string' ) || ( settings . serverhttpshash . length != 96 ) ) { console . log ( 'No or invalid \"serverHttpsHash\" specified.' ) ; exit ( 1 ) ; return ; }
if ( ( settings . remoteport == null ) || ( typeof settings . remoteport != 'number' ) || ( settings . remoteport < 0 ) || ( settings . remoteport > 65535 ) ) { console . log ( 'No or invalid \"remotePort\" specified, use --remoteport [remoteport].' ) ; exit ( 1 ) ; return ; }
if ( settings . serverurl != null ) { startRouter ( ) ; } else { discoverMeshServer ( ) ; } // Start MeshCentral Router
2018-03-12 21:16:06 -04:00
} else if ( ( settings . action == 'amtloadwebapp' ) || ( settings . action == 'amtloadsmallwebapp' ) || ( settings . action == 'amtloadlargewebapp' ) || ( settings . action == 'amtclearwebapp' ) || ( settings . action == 'amtstoragestate' ) ) { // Intel AMT Web Application Actions
2018-01-30 21:23:57 -05:00
// Intel AMT 11.6+ Load MeshCommander into firmware
2017-12-12 19:04:54 -05:00
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
digest = require ( 'http-digest' ) . create ( settings . username , settings . password ) ;
digest . http = require ( 'http' ) ;
2017-12-15 16:43:04 -05:00
if ( settings . action == 'amtstoragestate' ) {
2017-12-12 19:04:54 -05:00
getAmtStorage ( function ( statusCode , data ) { if ( statusCode == 200 ) { console . log ( "Storage State: " + JSON . stringify ( data , null , 2 ) ) ; exit ( ) ; return ; } else { console . log ( "Unable to read storage state." ) ; exit ( ) ; return ; } } ) ;
} else {
2017-12-15 16:43:04 -05:00
if ( settings . action == 'amtloadwebapp' ) { settings . webapp = Medium _IntelAmtWebApp ; }
else if ( settings . action == 'amtloadsmallwebapp' ) { settings . webapp = Small _IntelAmtWebApp ; }
else if ( settings . action == 'amtloadlargewebapp' ) { settings . webapp = Large _IntelAmtWebApp ; }
else if ( settings . action == 'amtclearwebapp' ) { settings . webapp = null ; }
2017-12-12 19:04:54 -05:00
nextStepStorageUpload ( ) ;
}
2018-03-12 21:16:06 -04:00
} else if ( ( settings . action == 'amtversion' ) || ( settings . action == 'amtversions' ) || ( settings . action == 'amtver' ) ) {
2019-10-01 17:54:38 -04:00
// Display Intel ME versions
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-25 19:28:52 -05:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-19 20:31:54 -04:00
amtMei . getVersion ( function ( val ) {
2019-10-01 17:54:38 -04:00
console . log ( "BIOS Version = " + val . BiosVersion . toString ( ) ) ;
for ( var version in val . Versions ) {
var extras = '' , skuBits = [ '' , 'iQST' , 'ASF' , 'AMT' , 'ISM' , 'TPM' , '' , '' , 'HomeIT' , '' , 'WOX' , '' , '' , 'AT-p' , 'Corporate' , 'L3 Mgt Upgrade' ] ;
if ( val . Versions [ version ] . Description == 'Sku' ) {
var n = parseInt ( val . Versions [ version ] . Version ) , x = [ ] , xx = 1 ;
for ( var i = 0 ; i < skuBits . length ; i ++ ) { if ( ( n & xx ) != 0 ) { x . push ( skuBits [ i ] ) ; } xx = xx << 1 ; }
if ( x . length > 0 ) { extras = ' (' + x . join ( ', ' ) + ')' }
}
console . log ( val . Versions [ version ] . Description + " = " + val . Versions [ version ] . Version + extras ) ;
}
2018-03-19 20:31:54 -04:00
exit ( 1 ) ; return ;
2017-12-12 19:04:54 -05:00
} ) ;
2018-03-12 21:16:06 -04:00
} else if ( settings . action == 'amthashes' ) {
2018-01-30 21:23:57 -05:00
// Display Intel AMT list of trusted hashes
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-25 19:28:52 -05:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-19 20:31:54 -04:00
amtMei . getHashHandles ( function ( handles ) {
exitOnCount = handles . length ;
for ( var i = 0 ; i < handles . length ; ++ i ) {
this . getCertHashEntry ( handles [ i ] , function ( result ) {
console . log ( result . name + ', (' + ( result . isDefault ? 'Default' : '' ) + ( result . isActive ? ', Active' : ', Disabled' ) + ')\r\n ' + result . hashAlgorithmStr + ': ' + result . certificateHash ) ;
if ( -- exitOnCount == 0 ) { exit ( 1 ) ; }
} ) ;
}
2017-12-12 19:04:54 -05:00
} ) ;
2019-06-27 01:13:56 -04:00
} else if ( settings . action == 'netinfo' ) {
// Display network information
var interfaces = require ( 'os' ) . networkInterfaces ( ) ;
console . log ( JSON . stringify ( interfaces , 2 , ' ' ) ) ;
exit ( 0 ) ; return ;
2018-03-12 21:16:06 -04:00
} else if ( settings . action == 'amtinfo' ) {
2018-01-30 21:23:57 -05:00
// Display Intel AMT version and activation state
2018-03-19 20:31:54 -04:00
mestate = { } ;
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-25 19:28:52 -05:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2019-10-01 17:54:38 -04:00
amtMei . getVersion ( function ( result ) {
if ( result ) {
for ( var version in result . Versions ) {
if ( result . Versions [ version ] . Description == 'AMT' ) { mestate . ver = result . Versions [ version ] . Version ; }
if ( result . Versions [ version ] . Description == 'Sku' ) { mestate . sku = parseInt ( result . Versions [ version ] . Version ) ; }
}
}
} ) ;
2018-10-11 16:29:50 -04:00
amtMei . getProvisioningState ( function ( result ) { if ( result ) { mestate . ProvisioningState = result ; } } ) ;
amtMei . getProvisioningMode ( function ( result ) { if ( result ) { mestate . ProvisioningMode = result ; } } ) ;
2018-04-22 13:47:53 -04:00
amtMei . getEHBCState ( function ( result ) { if ( result ) { mestate . ehbc = result ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result ) { mestate . controlmode = result ; } } ) ;
amtMei . getMACAddresses ( function ( result ) { if ( result ) { mestate . mac = result ; } } ) ;
amtMei . getLanInterfaceSettings ( 0 , function ( result ) { if ( result ) { mestate . net0 = result ; } } ) ;
amtMei . getLanInterfaceSettings ( 1 , function ( result ) { if ( result ) { mestate . net1 = result ; } } ) ;
2018-03-26 20:13:32 -04:00
amtMei . getUuid ( function ( result ) { if ( ( result != null ) && ( result . uuid != null ) ) { mestate . uuid = result . uuid ; } } ) ;
2018-03-19 20:31:54 -04:00
amtMei . getDnsSuffix ( function ( result ) {
2018-10-11 16:29:50 -04:00
if ( result ) { mestate . dns = result ; }
if ( mestate . ver && mestate . ProvisioningState && mestate . ProvisioningMode ) {
2019-10-01 17:54:38 -04:00
var str = 'Intel ME v' + mestate . ver ;
if ( mestate . sku & 8 ) { str = 'Intel AMT v' + mestate . ver }
else if ( mestate . sku & 16 ) { str = 'Intel SM v' + mestate . ver }
2018-10-11 16:29:50 -04:00
if ( mestate . ProvisioningState . stateStr == 'PRE' ) { str += ', pre-provisioning state' ; }
else if ( mestate . ProvisioningState . stateStr == 'IN' ) { str += ', in-provisioning state' ; }
else if ( mestate . ProvisioningState . stateStr == 'POST' ) {
if ( mestate . ProvisioningMode ) {
if ( mestate . controlmode ) {
if ( mestate . ProvisioningMode . modeStr == 'ENTERPRISE' ) { str += ', activated in ' + [ "none" , "client control mode" , "admin control mode" , "remote assistance mode" ] [ mestate . controlmode . controlMode ] ; } else { str += ', activated in ' + mestate . ProvisioningMode . modeStr ; }
} else {
str += ', activated in ' + mestate . ProvisioningMode . modeStr ;
}
2018-04-22 13:47:53 -04:00
}
}
2018-10-11 16:29:50 -04:00
if ( ( mestate . ehbc ) && ( mestate . ehbc . EHBC == true ) ) { str += ', EHBC enabled' ; }
str += '.' ;
if ( mestate . net0 != null ) { str += '\r\nWired ' + ( ( mestate . net0 . enabled == 1 ) ? 'Enabled' : 'Disabled' ) + ( ( mestate . net0 . dhcpEnabled == 1 ) ? ', DHCP' : ', Static' ) + ', ' + mestate . net0 . mac + ( mestate . net0 . address == '0.0.0.0' ? '' : ( ', ' + mestate . net0 . address ) ) ; }
if ( mestate . net1 != null ) { str += '\r\nWireless ' + ( ( mestate . net1 . enabled == 1 ) ? 'Enabled' : 'Disabled' ) + ( ( mestate . net1 . dhcpEnabled == 1 ) ? ', DHCP' : ', Static' ) + ', ' + mestate . net1 . mac + ( mestate . net1 . address == '0.0.0.0' ? '' : ( ', ' + mestate . net1 . address ) ) ; }
2019-06-12 22:40:27 -04:00
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 ; }
}
}
2018-10-11 16:29:50 -04:00
console . log ( str + '.' ) ;
} else {
console . log ( 'Intel(R) AMT not supported.' ) ;
2018-04-22 13:47:53 -04:00
}
2018-03-19 20:31:54 -04:00
exit ( 1 ) ;
2017-12-12 19:04:54 -05:00
} ) ;
2018-09-20 14:45:12 -04:00
} else if ( settings . action == 'amtinfodebug' ) {
// Display Intel AMT version and activation state
mestate = { } ;
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-09-20 14:45:12 -04:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
amtMei . getVersion ( function ( result ) { console . log ( 'getVersion: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getProvisioningState ( function ( result ) { console . log ( 'getProvisioningState: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getProvisioningMode ( function ( result ) { console . log ( 'getProvisioningMode: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getEHBCState ( function ( result ) { if ( result ) { console . log ( 'getEHBCState: ' + JSON . stringify ( result ) ) ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result ) { console . log ( 'getControlMode: ' + JSON . stringify ( result ) ) ; } } ) ;
amtMei . getMACAddresses ( function ( result ) { if ( result ) { console . log ( 'getMACAddresses: ' + JSON . stringify ( result ) ) ; } } ) ;
amtMei . getLanInterfaceSettings ( 0 , function ( result ) { console . log ( 'getLanInterfaceSettings0: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getLanInterfaceSettings ( 1 , function ( result ) { console . log ( 'getLanInterfaceSettings1: ' + JSON . stringify ( result ) ) ; } ) ;
amtMei . getUuid ( function ( result ) { console . log ( 'getUuid: ' + JSON . stringify ( result ) ) ; } ) ;
2019-06-14 19:33:53 -04:00
amtMei . getDnsSuffix ( function ( result ) { console . log ( 'getDnsSuffix: ' + JSON . stringify ( result ) ) ; exit ( 1 ) ; } ) ;
2018-01-02 19:52:49 -05:00
} else if ( settings . action == 'amtsavestate' ) {
2018-01-30 21:23:57 -05:00
// Save the entire state of Intel AMT info a JSON file
2018-01-25 19:12:53 -05:00
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
if ( ( settings . output == null ) || ( typeof settings . output != 'string' ) || ( settings . output == '' ) ) { console . log ( 'No or invalid \"output\" file specified, use --output [filename].' ) ; exit ( 1 ) ; return ; }
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2018-01-02 19:52:49 -05:00
saveEntireAmtState ( ) ;
2018-04-04 15:08:28 -04:00
} else if ( ( settings . action == 'microlms' ) || ( settings . action == 'amtlms' ) || ( settings . action == 'lms' ) ) {
2018-01-30 21:23:57 -05:00
// Start Intel AMT MicroLMS
2018-03-19 20:31:54 -04:00
startLms ( function ( state ) {
2019-03-19 19:36:30 -04:00
console . log ( [ 'MicroLMS did not start. Must run as administrator or LMS already active.' , 'MicroLMS started.' , 'MicroLMS started, MeshCommander on HTTP/16994.' , 'MEI error' ] [ state ] ) ;
if ( ( ( state == 0 ) || ( state == 3 ) ) && ( settings . noconsole === true ) ) { exit ( 0 ) ; } else { console . log ( 'Press ctrl-c to exit.' ) ; }
} , settings . noconsole !== true ) ;
2018-04-28 18:36:10 -04:00
} else if ( settings . action == 'amtpresence' ) {
// Heartbeat a Intel AMT watchdog
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
if ( ( settings . agent == null ) || ( typeof settings . agent != 'string' ) || ( settings . agent == '' ) ) { console . log ( 'No or invalid \"agent\" specified, use --agent [agent].' ) ; exit ( 1 ) ; return ; }
performAmtAgentPresence ( ) ;
2018-03-12 21:16:06 -04:00
} else if ( settings . action == 'amtscript' ) {
2018-02-02 15:46:09 -05:00
// Start running a MEScript
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . hostname == null ) || ( typeof settings . hostname != 'string' ) || ( settings . hostname == '' ) ) { settings . hostname = '127.0.0.1' ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
2020-02-10 15:22:01 -05:00
//if ((settings.script == null) || (typeof settings.script != 'string') || (settings.script == '')) { if (mescriptJSON != '') { settings.scriptjson = mescriptJSON; } else { console.log('No or invalid \"script\" file specified, use --script [filename].'); exit(1); return; } }
if ( ( settings . script == null ) || ( typeof settings . script != 'string' ) || ( settings . script == '' ) ) { console . log ( 'No or invalid \"script\" file specified, use --script [filename].' ) ; exit ( 1 ) ; return ; }
2018-02-02 15:46:09 -05:00
startMeScript ( ) ;
2018-03-06 20:50:44 -05:00
} else if ( settings . action == 'amtuuid' ) {
2020-02-10 15:22:01 -05:00
// Start running
2018-03-26 20:13:32 -04:00
if ( settings . hostname != null ) {
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
}
2018-03-06 20:50:44 -05:00
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
getAmtUuid ( ) ;
} else if ( settings . action == 'amtccm' ) {
// Start activation to CCM
2019-06-24 21:56:14 -04: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 ; }
2018-03-06 20:50:44 -05:00
settings . protocol = 'http:' ;
settings . localport = 16992 ;
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
2019-06-27 19:04:52 -04:00
if ( settings . password != null ) { activeToCCM ( ) ; } else { activeToACM ( ) ; }
2019-05-24 14:33:59 -04:00
} else if ( settings . action == 'amtacm' ) {
// Start activation to ACM
2019-06-21 20:42:43 -04: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-21 20:18:48 -04:00
if ( ( typeof settings . profile != 'string' ) || ( settings . profile == '' ) ) { settings . profile = null ; }
2019-05-24 14:33:59 -04:00
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
activeToACM ( ) ;
2019-06-27 19:04:52 -04: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 ( ) ;
2018-03-06 20:50:44 -05:00
} else if ( settings . action == 'amtdeactivate' ) {
// Deactivate CCM
debug ( 1 , "Settings: " + JSON . stringify ( settings ) ) ;
deactivateCCM ( ) ;
2019-05-24 14:33:59 -04:00
} 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 ( ) ;
2018-03-20 20:48:03 -04:00
} else if ( settings . action == 'meshcommander' ) { // Start MeshCommander
2018-03-19 20:31:54 -04:00
startMeshCommander ( ) ;
2019-06-14 19:33:53 -04:00
//} else if (settings.action == 'amtdisable') { // Disable AMT Network Interface
// amtDisable();
2019-10-01 19:53:10 -04:00
} else if ( settings . action == 'amtscan' ) {
// Scan the network for Intel AMT devices
if ( ( settings . scan == null ) || ( typeof settings . scan != 'string' ) || ( settings . scan == '' ) ) { console . log ( 'No or invalid \"scan\" specified, use --scan [ip range].' ) ; exit ( 1 ) ; return ; }
console . log ( 'Scanning: ' + settings . scan + '...' ) ;
var AMTScannerModule = require ( 'amt-scanner' ) ;
var amtscanner = new AMTScannerModule ( ) , r = '' ;
amtscanner . scan ( settings . scan , 2000 , function ( data ) {
if ( data . length > 0 ) {
r = '' , pstates = [ 'NotActivated' , 'InActivation' , 'Activated' ] ;
for ( var i in data ) {
var x = data [ i ] ;
if ( r != '' ) { r += '\r\n' ; }
r += x . address + ' - Intel AMT v' + x . majorVersion + '.' + x . minorVersion ;
if ( x . provisioningState < 3 ) { r += ( ', ' + pstates [ x . provisioningState ] ) ; }
if ( x . provisioningState == 2 ) { r += ( ', ' + x . openPorts . join ( ', ' ) ) ; }
r += '.' ;
}
} else {
r = 'No Intel AMT found.' ;
}
console . log ( r ) ;
exit ( 1 ) ;
} ) ;
2018-03-20 20:48:03 -04:00
} else if ( settings . action == 'amtauditlog' ) { // Read the Intel AMT audit log
if ( settings . hostname != null ) {
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
} else { settings . hostname = '127.0.0.1' ; }
readAmtAuditLog ( ) ;
2019-07-15 18:44:18 -04:00
} else if ( settings . action == 'amteventlog' ) { // Read the Intel AMT audit log
2019-10-22 19:29:02 -04:00
if ( settings . hostname != null ) {
if ( ( settings . password == null ) || ( typeof settings . password != 'string' ) || ( settings . password == '' ) ) { console . log ( 'No or invalid \"password\" specified, use --password [password].' ) ; exit ( 1 ) ; return ; }
if ( ( settings . username == null ) || ( typeof settings . username != 'string' ) || ( settings . username == '' ) ) { settings . username = 'admin' ; }
} else { settings . hostname = '127.0.0.1' ; }
2019-07-15 18:44:18 -04:00
readAmtEventLog ( ) ;
2019-06-06 12:59:13 -04: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-15 17:45:36 -04: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 ) ;
2020-04-09 15:14:09 -04:00
} else if ( settings . action == 'amtwifi' ) { // Perform remote Intel AMT Wifi 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' ; }
if ( args . add != null ) {
2020-05-13 03:27:31 -04:00
if ( ( args . name == null ) || ( typeof args . name != 'string' ) || args . name == '' ) { console . log ( "Wifi profile name is required." ) ; exit ( 1 ) ; return ; }
if ( ( args . ssid == null ) || ( typeof args . ssid != 'string' ) || args . ssid == '' ) { console . log ( "Wifi SSID is required." ) ; exit ( 1 ) ; return ; }
if ( ( args . psk == null ) || ( typeof args . psk != 'string' ) || args . psk == '' ) { console . log ( "Wifi password is required." ) ; exit ( 1 ) ; return ; }
2020-04-09 15:14:09 -04:00
}
if ( args . del != null ) {
2020-05-13 03:27:31 -04:00
if ( ( settings . name == null ) || ( typeof settings . name != 'string' ) || settings . name == '' ) { console . log ( "Wifi profile name is required." ) ; exit ( 1 ) ; return ; }
2020-04-09 15:14:09 -04:00
}
performAmtWifiConfig ( args ) ;
2020-05-13 03:27:31 -04:00
} else if ( settings . action == 'amtwake' ) { // Perform remote Intel AMT wake alarm operations
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' ; }
if ( ( args . del != null ) && ( ( typeof args . del != 'string' ) || args . del == '' ) ) { console . log ( "Alarm name is required (--del [name])." ) ; exit ( 1 ) ; return ; }
if ( args . add != null ) {
if ( ( ( typeof args . add != 'string' ) || args . add == '' ) ) { console . log ( "Wake alarm name is required (--add [name])." ) ; exit ( 1 ) ; return ; }
if ( ( ( typeof args . date != 'string' ) || args . data == '' ) ) { console . log ( "Wake alarm date is required (--date [yyyy-mm-dd])." ) ; exit ( 1 ) ; return ; }
}
performAmtWakeConfig ( args ) ;
2019-07-15 15:55:52 -04:00
} else if ( settings . action == 'amtfeatures' ) { // Perform remote Intel AMT feature configuration operation
2019-07-15 17:45:36 -04:00
if ( settings . hostname == null ) { settings . hostname = '127.0.0.1' ; }
2019-07-15 15:55:52 -04: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-11 19:54:27 -04: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 ( ) ;
2017-10-31 19:19:58 -04:00
} else {
2017-12-12 19:04:54 -05:00
console . log ( 'Invalid \"action\" specified.' ) ; exit ( 1 ) ; return ;
2017-10-31 19:19:58 -04:00
}
2017-12-12 19:04:54 -05:00
}
2017-10-31 19:19:58 -04:00
2018-04-28 18:36:10 -04:00
//
// Intel AMT Agent Presence
//
function performAmtAgentPresence ( ) { startLms ( function ( ) { tempWatchdogTimer = setTimeout ( performAmtAgentPresenceRegister , 3000 ) ; } ) ; }
function performAmtAgentPresenceRegister ( ) {
// Setup the Intel AMT WSMAN stack
tempWatchdogTimer = null ;
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
wsstack = new wsman ( transport , '127.0.0.1' , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
amtstack = new amt ( wsstack ) ;
// Register the watchdog
watchdog = { DeviceID : Buffer . from ( guidToStr ( settings . agent . split ( '-' ) . join ( '' ) ) . split ( '-' ) . join ( '' ) , 'hex' ) . toString ( 'base64' ) , Retry : 0 } ;
amtstack . AMT _AgentPresenceWatchdog _RegisterAgent ( performAmtAgentPresenceRegisterRetry , watchdog , watchdog . Seq , { 'DeviceID' : watchdog . DeviceID } ) ;
}
// Called after the agent is registered
function performAmtAgentPresenceRegisterRetry ( stack , name , response , status , watchdog ) {
if ( ( status == 200 ) && ( response . Body . SessionSequenceNumber ) && ( response . Body . TimeoutInterval ) ) {
console . log ( 'Asserting presence of the watchdog...' ) ;
watchdog . Seq = response . Body . SessionSequenceNumber ;
watchdog . Interval = response . Body . TimeoutInterval * 800 ;
watchdog . Retry = 0 ;
tempWatchdogTimer = setTimeout ( performAmtAgentPresenceAssert , watchdog . Interval ) ;
} else {
debug ( 1 , 'Failed to register, status = ' + status ) ;
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
tempWatchdogTimer = setTimeout ( function ( ) { amtstack . AMT _AgentPresenceWatchdog _RegisterAgent ( performAmtAgentPresenceRegisterRetry , watchdog , watchdog . Seq , { 'DeviceID' : watchdog . DeviceID } ) ; } , 1000 ) ;
} else {
console . log ( 'Failed to register this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
// Start a new agent assert
function performAmtAgentPresenceAssert ( ) {
watchdog . Seq ++ ;
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceAssertRetry , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
}
// Called after the agent is asserted
function performAmtAgentPresenceAssertRetry ( stack , name , response , status , watchdog ) {
if ( status == 200 ) {
2019-11-29 01:29:22 -05:00
debug ( 1 , 'Successful assert, sequence = ' + watchdog . Seq ) ;
2018-04-28 18:36:10 -04:00
watchdog . Retry = 0 ;
tempWatchdogTimer = setTimeout ( performAmtAgentPresenceAssert , watchdog . Interval ) ;
} else {
debug ( 1 , 'Failed to assert, status = ' + status ) ;
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceAssertRetry , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
} else {
console . log ( 'Failed to assert presence on this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
function performAmtAgentPresenceEx5 ( stack , name , response , status , watchdog ) {
console . log ( 'b' , status , watchdog ) ;
if ( status == 200 ) {
watchdog . Retry = 0 ;
} else {
watchdog . Retry ++ ;
if ( watchdog . Retry < 5 ) {
amtstack . AMT _AgentPresenceWatchdog _AssertPresence ( watchdog . Seq , performAmtAgentPresenceEx4 , watchdog , 0 , { 'DeviceID' : watchdog . DeviceID } ) ;
} else {
console . log ( 'Failed to assert presence on this watchdog.' ) ;
process . exit ( 0 ) ;
}
}
}
2018-03-12 21:16:06 -04:00
2019-07-15 18:44:18 -04: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 {
2019-10-22 19:29:02 -04:00
for ( var i in messages ) { out += messages [ i ] . Time + ', ' + messages [ i ] . EntityStr + ', ' + messages [ i ] . Desc + ', ' + messages [ i ] . EventSeverity + '\r\n' ; }
2019-07-15 18:44:18 -04:00
}
2019-10-22 19:29:02 -04:00
if ( ( settings . output == null || settings . output == "" ) && ! settings . uuidoutput ) { console . log ( out ) ; exit ( 1 ) ; }
else {
try {
if ( settings . output ) {
var file = fs . openSync ( settings . output , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
exit ( 1 ) ;
}
else if ( settings . uuidoutput ) {
var destpath = null ; //Dest path where messagelog file will be saved
if ( ( typeof settings . uuidoutput ) == 'string' ) {
fs . statSync ( settings . uuidoutput ) . isDirectory ( ) ; //Validate directory path
destpath = settings . uuidoutput ;
}
//Generate uuid and append it to dest path
stack . Get ( 'CIM_ComputerSystemPackage' , function ( obj , name , response , xstatus , tag ) {
if ( xstatus == 200 ) {
var eventlogsfile = path . join ( destpath , guidToStr ( response . Body . PlatformGUID . toLowerCase ( ) + '_Event' + ( settings . json ? '.json' : '.csv' ) ) ) ;
var file = fs . openSync ( eventlogsfile , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
} else {
console . log ( 'Intel AMT is not available or not activated, status = ' + status + '.' ) ;
} exit ( 1 ) ;
} ) ;
}
else {
console . log ( 'Invalid action, usage:\r\n\r\n meshcmd help amtauditlog' ) ;
exit ( 1 ) ;
}
}
catch ( e ) {
console . log ( e ) ;
exit ( 1 ) ;
}
2019-07-15 18:44:18 -04:00
}
}
}
2018-03-20 20:48:03 -04: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-15 18:44:18 -04: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' ) ;
}
}
2019-10-22 19:29:02 -04:00
if ( ( settings . output == null || settings . output == "" ) && ! settings . uuidoutput ) { console . log ( out ) ; exit ( 1 ) ; }
else {
try {
if ( settings . output ) {
var file = fs . openSync ( settings . output , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
exit ( 1 ) ;
}
else if ( settings . uuidoutput ) {
var destpath = null ; //Dest path where auditlog file will be saved
if ( ( typeof settings . uuidoutput ) == 'string' ) {
fs . statSync ( settings . uuidoutput ) . isDirectory ( ) ; //Validate directory path
destpath = settings . uuidoutput ;
}
//Generate uuid and append it to dest path
stack . Get ( 'CIM_ComputerSystemPackage' , function ( obj , name , response , xstatus , tag ) {
if ( xstatus == 200 ) {
var auditlogsfile = path . join ( destpath , guidToStr ( response . Body . PlatformGUID . toLowerCase ( ) + '_Audit' + ( settings . json ? '.json' : '.csv' ) ) ) ;
var file = fs . openSync ( auditlogsfile , 'w' ) ;
fs . writeSync ( file , Buffer . from ( out ) ) ;
fs . closeSync ( file ) ;
} else {
console . log ( 'Intel AMT is not available or not activated, status = ' + status + '.' ) ;
} exit ( 1 ) ;
} ) ;
}
else {
console . log ( 'Invalid action, usage:\r\n\r\n meshcmd help amtauditlog' ) ;
exit ( 1 ) ;
}
}
catch ( e ) {
console . log ( e ) ;
exit ( 1 ) ;
}
2018-03-20 20:48:03 -04:00
}
}
}
2019-06-14 19:33:53 -04:00
//
// 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);
// });
//}
2018-03-20 20:48:03 -04:00
2018-03-19 20:31:54 -04:00
//
// 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 ) ;
2018-03-20 20:48:03 -04:00
webServer . wsList = { } ;
webServer . wsListIndex = 0 ;
2018-03-19 20:31:54 -04:00
webServer . on ( 'upgrade' , function ( req , socket , head ) {
//console.log("WebSocket for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/webrelay.ashx' : // MeshCommander relay channel
var ws = socket . upgradeWebSocket ( ) ;
socket . ws = ws ;
2018-03-20 20:48:03 -04:00
ws . wsIndex = ++ webServer . wsListIndex ;
2018-03-21 18:39:16 -04:00
webServer . wsList [ ws . wsIndex ] = ws ; // Keep a reference so the websocket and forwarder don't get disposed.
2018-03-19 20:31:54 -04:00
ws . pause ( ) ;
// We got a new web socket connection, initiate a TCP connection to the target Intel AMT host/port.
var webargs = parseUrlArguments ( req . url ) ;
if ( webargs . p ) { webargs . p = parseInt ( webargs . p ) ; }
if ( webargs . tls ) { webargs . tls = parseInt ( webargs . tls ) ; }
if ( webargs . tls1only ) { webargs . tls1only = parseInt ( webargs . tls1only ) ; }
if ( webargs . port ) { webargs . port = parseInt ( webargs . port ) ; }
2019-04-29 00:23:49 -04:00
debug ( 1 , 'Opening web socket connection to ' + webargs . host + ':' + webargs . port + '.' ) ;
2018-03-19 20:31:54 -04:00
//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 } )
2019-04-29 00:23:49 -04:00
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 ) { } } ) ;
2018-03-19 20:31:54 -04:00
ws . forwardclient . ws = ws ;
} else {
// If TLS is going to be used, setup a TLS socket
var tls = require ( 'tls' ) ;
2020-03-30 22:29:46 -04:00
var tlsoptions = { host : webargs . host , port : webargs . port , rejectUnauthorized : false } ;
if ( webargs . tls1only == 1 ) { tlsoptions . secureProtocol = 'TLSv1_method' ; }
2019-04-29 00:23:49 -04:00
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 ) { } } ) ;
2018-03-19 20:31:54 -04:00
ws . forwardclient . ws = ws ;
}
2018-03-21 18:39:16 -04:00
// Handle pipe closure
2019-04-29 00:23:49 -04:00
ws . on ( 'end' , function ( ) { debug ( 1 , 'Disconnected from ' + webargs . host + ':' + webargs . port + '.' ) ; try { this . forwardclient . end ( ) ; } catch ( e ) { } delete webServer . wsList [ this . wsIndex ] ; } ) ;
2018-03-21 18:39:16 -04:00
ws . forwardclient . on ( 'end' , function ( ) { try { this . ws . end ( ) ; } catch ( e ) { } } ) ;
2018-03-19 20:31:54 -04:00
break ;
default :
socket . end ( ) ;
break ;
}
} ) ;
webServer . on ( 'request' , function ( req , rsp ) {
//console.log("WebRequest for " + req.url.split('?')[0]);
switch ( req . url . split ( '?' ) [ 0 ] ) {
case '/' : // Serve MeshCommander Web Application
var meshcommander = null ;
try { meshcommander = fs . readFileSync ( 'meshcommander.htm' ) ; } catch ( e ) { }
if ( meshcommander != null ) {
rsp . writeHead ( 200 , 'OK' , { Server : 'JSLMS' , 'Cache-Control' : 'max-age=0, no-cache' , 'X-Frame-Options' : 'DENY' , 'Content-Type' : 'text/html' , 'Transfer-Encoding' : 'chunked' } ) ;
rsp . end ( meshcommander ) ;
} else {
2019-07-05 16:28:41 -04: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' ) ) ;
2018-03-19 20:31:54 -04: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.' ) ;
}
2018-03-06 20:50:44 -05:00
//
// Deactivate Intel AMT CCM
//
// When called, this will use MEI to deactivate Intel AMT when it's in CCM mode. Simply calls "unprovision" on MEI and checks the return code.
function deactivateCCM ( ) {
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-06 20:50:44 -05:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-19 20:31:54 -04:00
amtMei . unprovision ( 1 , function ( status ) { if ( status == 0 ) { console . log ( 'Success' ) ; } else { console . log ( 'Error ' + status ) ; } exit ( 1 ) ; } ) ;
2018-03-06 20:50:44 -05:00
}
//
// Activate Intel AMT to CCM
//
function activeToCCM ( ) {
// See if MicroLMS needs to be started and setup the $$OsAdmin wsman stack
settings . noconsole = true ;
startLms ( activeToCCMEx ) ; // TODO: Fix this so that it works even if LMS already running.
}
function activeToCCMEx ( state ) {
osamtstack . BatchEnum ( null , [ '*AMT_GeneralSettings' , '*IPS_HostBasedSetupService' ] , activeToCCMEx2 ) ;
}
function activeToCCMEx2 ( stack , name , responses , status ) {
if ( status != 200 ) { console . log ( 'Failed to fetch activation status, status ' + status ) ; exit ( 1 ) ; }
else if ( responses [ 'IPS_HostBasedSetupService' ] . response [ 'AllowedControlModes' ] . length != 2 ) { console . log ( 'Client control mode activation not allowed' ) ; exit ( 1 ) ; }
2018-04-04 15:08:28 -04:00
else { osamtstack . IPS _HostBasedSetupService _Setup ( 2 , md5hex ( 'admin:' + responses [ 'AMT_GeneralSettings' ] . response [ 'DigestRealm' ] + ':' + settings . password ) . substring ( 0 , 32 ) , null , null , null , null , activeToCCMEx3 ) ; }
2018-03-06 20:50:44 -05:00
}
function activeToCCMEx3 ( stack , name , responses , status ) {
if ( status != 200 ) { console . log ( 'Failed to activate, status ' + status ) ; }
else if ( responses . Body . ReturnValue != 0 ) { console . log ( 'Client control mode activation failed: ' + responses . Body . ReturnValueStr ) ; }
else { console . log ( 'Success' ) ; exit ( 0 ) ; }
exit ( 1 ) ;
}
2019-06-24 21:56:14 -04:00
2019-05-24 14:33:59 -04: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-21 20:18:48 -04: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-14 19:33:53 -04:00
2019-05-24 14:33:59 -04:00
//
2019-06-27 19:04:52 -04:00
// Activate Intel AMT to with server (ACM or CCM)
2019-05-24 14:33:59 -04:00
//
function activeToACM ( ) {
2019-06-27 19:04:52 -04:00
console . log ( 'Starting Intel AMT activation attempt...' ) ;
2019-05-24 14:33:59 -04:00
settings . noconsole = true ;
2019-06-21 20:18:48 -04:00
2019-05-24 14:33:59 -04: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-21 20:18:48 -04:00
amtMei . getProvisioningState ( function ( result ) { if ( result ) { mestate . ProvisioningState = result ; } } ) ;
2019-06-24 21:56:14 -04: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-21 20:18:48 -04: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-27 19:04:52 -04:00
amtMei . getControlMode ( function ( result ) { if ( result != null ) { mestate . controlMode = result . controlMode ; } } ) ; // controlMode: 0 = NoActivated, 1 = CCM, 2 = ACM
2019-06-21 20:18:48 -04:00
amtMei . getDnsSuffix ( function ( result ) {
2019-06-24 21:56:14 -04: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-27 19:04:52 -04:00
if ( ( settings . action != 'amtdiscover' ) && ( mestate . controlMode == 2 ) ) { console . log ( "Intel AMT already activation in admin control mode." ) ; exit ( 100 ) ; return ; }
2019-06-21 20:18:48 -04: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-05-24 14:33:59 -04:00
}
} ) ;
}
// Gets the FWNonce from AMT and saves it to a file.
function getFwNonce ( ) {
2019-06-14 19:33:53 -04:00
osamtstack . BatchEnum ( null , [ '*AMT_GeneralSettings' , '*IPS_HostBasedSetupService' ] , function ( stack , name , responses , status ) {
2019-06-21 20:18:48 -04:00
if ( status != 200 ) { console . log ( "Unable to get firmware activation nonce, status=" + status ) ; exit ( 100 ) ; return ; }
2019-06-14 19:33:53 -04:00
var fwNonce = responses [ 'IPS_HostBasedSetupService' ] . response [ 'ConfigurationNonce' ] ;
var digestRealm = responses [ 'AMT_GeneralSettings' ] . response [ 'DigestRealm' ] ;
2019-06-27 19:04:52 -04:00
var allowedModes = responses [ 'IPS_HostBasedSetupService' ] . response [ 'AllowedControlModes' ] ; // 1 = CCM, 2 = ACM
activeToACMEx ( fwNonce , settings . fqdn , digestRealm , settings . uuid , allowedModes ) ;
2019-05-24 14:33:59 -04:00
} ) ;
}
2019-06-21 20:18:48 -04:00
// Connect to the activation server and perform ACM activation
2019-06-27 19:04:52 -04:00
function activeToACMEx ( fwNonce , dnsSuffix , digestRealm , uuid , allowedModes ) {
2019-06-21 20:18:48 -04:00
console . log ( 'FQDN: ' + dnsSuffix ) ;
console . log ( 'UUID: ' + uuid ) ;
console . log ( 'Realm: ' + digestRealm ) ;
console . log ( 'Nonce: ' + fwNonce ) ;
2019-06-21 20:42:43 -04:00
console . log ( 'Connecting to ' + settings . url ) ;
2019-06-21 20:18:48 -04:00
// Establish WebSocket connection to activation server
2019-06-21 20:42:43 -04:00
var options = http . parseUri ( settings . url ) ;
2019-06-23 01:06:50 -04:00
options . checkServerIdentity = onVerifyServer ;
2019-06-21 20:18:48 -04:00
options . rejectUnauthorized = false ;
var connection = http . request ( options ) ;
2019-05-24 14:33:59 -04:00
connection . on ( 'upgrade' , function ( response , socket ) {
2019-06-27 19:04:52 -04:00
settings . xxsocket = socket ;
2019-10-01 19:53:10 -04:00
if ( settings . action == 'amtdiscover' ) { console . log ( 'Connected, performing discovery...' ) ; } else { console . log ( 'Connected, requesting activation...' ) ; }
2019-06-21 20:18:48 -04:00
socket . on ( 'end' , function ( ) { console . log ( 'Connection closed' ) ; exit ( 0 ) ; } ) ;
socket . on ( 'error' , function ( ) { console . log ( 'Connection error' ) ; exit ( 100 ) ; } ) ;
2019-05-24 14:33:59 -04:00
socket . on ( 'data' , function ( data ) {
2019-06-21 20:18:48 -04: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-10-01 17:54:38 -04:00
if ( typeof cmd . messageText == 'string' ) { console . log ( 'Server: ' + cmd . messageText ) ; return ; }
2019-06-27 19:04:52 -04: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-27 19:14:14 -04:00
settings . xxprofileScript = cmd . profileScript ;
settings . xxrawpassword = cmd . rawpassword ;
2019-06-27 19:04:52 -04: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-13 12:12:11 -04:00
} else {
2019-06-27 19:04:52 -04:00
// We are ready to go, perform ACM activation.
performAcmActivation ( cmd , AcmActivationCompleted ) ;
2019-05-24 14:33:59 -04:00
}
2019-06-27 19:04:52 -04:00
break ;
2019-06-21 20:18:48 -04:00
}
2019-06-27 19:04:52 -04: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-05-24 14:33:59 -04:00
} ) ;
2019-06-27 19:04:52 -04:00
var action = 'acmactivate' ;
if ( settings . action == 'amtccm' ) { action = 'ccmactivate' ; }
if ( settings . action == 'amtdiscover' ) { action = 'amtdiscover' ; }
2019-10-01 17:54:38 -04: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' ] , sku : parseInt ( mestate . vers [ 'Sku' ] ) , modes : allowedModes , currentMode : mestate . controlMode , hostname : require ( 'os' ) . hostname ( ) } ) ;
2019-05-24 14:33:59 -04:00
} ) ;
2019-06-21 20:18:48 -04:00
connection . end ( ) ;
2019-05-24 14:33:59 -04:00
}
2019-06-27 19:04:52 -04: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-27 19:14:14 -04:00
if ( ( settings . xxprofileScript !== null ) && ( settings . xxrawpassword != null ) ) {
2019-06-27 19:04:52 -04:00
console . log ( 'Intel AMT ACM activation success, applying profile...' ) ;
2019-06-27 19:14:14 -04:00
settings . scriptjson = settings . xxprofileScript ;
settings . password = settings . xxrawpassword ; // This is only going to work if the server sends the raw password
2019-06-27 19:04:52 -04: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-21 20:18:48 -04: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-27 19:04:52 -04: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-21 20:18:48 -04:00
else { acmdata . index ++ ; performAcmActivation ( acmdata , func ) ; }
2019-05-24 14:33:59 -04:00
} ) ;
} else {
2019-06-27 19:04:52 -04:00
//console.log(acmdata.password, acmdata.nonce, acmdata.signature);
2019-06-21 20:18:48 -04:00
osamtstack . IPS _HostBasedSetupService _AdminSetup ( 2 , acmdata . password , acmdata . nonce , 2 , acmdata . signature ,
2019-06-24 21:56:14 -04: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-21 20:18:48 -04:00
) ;
2019-05-24 14:33:59 -04:00
}
}
2018-03-06 20:50:44 -05: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 ( ) {
2018-03-26 20:13:32 -04:00
if ( settings . hostname == null ) {
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-26 20:13:32 -04:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
amtMei . getUuid ( function ( result ) { if ( ( result == null ) || ( result . uuid == null ) ) { console . log ( 'Failed.' ) ; } else { console . log ( result . uuid ) ; } exit ( 1 ) ; } ) ;
} else {
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) { settings . noconsole = true ; startLms ( getAmtUuidEx ) ; return ; } else { getAmtUuidEx ( ) ; }
}
2018-03-06 20:50:44 -05:00
}
// Fetch the computer's UUID by fetching the CIM_ComputerSystemPackage WSMAN object.
function getAmtUuidEx ( ) {
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
amtstack = new amt ( wsstack ) ;
amtstack . Get ( "CIM_ComputerSystemPackage" , function ( obj , name , response , xstatus , tag ) {
if ( xstatus == 200 ) { console . log ( "GUID: " + guidToStr ( response . Body . PlatformGUID . toLowerCase ( ) ) ) ; } else { console . log ( "Intel AMT is not available or not activated." ) ; } exit ( 1 ) ;
} ) ;
}
2018-02-02 15:46:09 -05:00
//
// Run MESCRIPT
//
2018-03-06 20:50:44 -05:00
// Run a .mescript targeting local or remote Intel AMT.
2018-02-02 15:46:09 -05:00
function startMeScript ( ) {
// See if MicroLMS needs to be started
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) { settings . noconsole = true ; startLms ( startMeScriptEx ) ; return ; } else { startMeScriptEx ( ) ; }
}
2019-06-13 12:12:11 -04:00
function startMeScriptEx ( callback , amtstack ) {
2018-03-06 20:50:44 -05:00
//console.log('Running script...');
2018-02-02 15:46:09 -05:00
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
2019-06-13 12:12:11 -04:00
if ( ! wsstack ) { wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ; }
if ( ! amtstack ) { amtstack = new amt ( wsstack ) ; }
2018-02-07 21:45:14 -05:00
//IntelAmtEntireStateProgress = 101;
//amtstack.onProcessChanged = onWsmanProcessChanged;
2018-02-02 15:46:09 -05:00
var scriptData = null ;
2018-03-06 20:50:44 -05:00
if ( settings . script != null ) {
try { scriptData = fs . readFileSync ( settings . script ) ; } catch ( e ) { console . log ( 'Unable to read script file (1): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
} else {
2019-03-26 18:18:07 -04:00
scriptData = settings . scriptjson ;
2018-04-04 15:08:28 -04:00
}
2018-02-02 15:46:09 -05:00
if ( scriptData == null ) { console . log ( 'Unable to read script file (2): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
try { scriptData = JSON . parse ( scriptData ) ; } catch ( e ) { console . log ( 'Unable to read script file (3): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
if ( scriptData . mescript == null ) { console . log ( 'Unable to read script file (4): ' + settings . script + '.' ) ; exit ( 1 ) ; return ; }
var scriptData = Buffer . from ( scriptData . mescript , 'base64' ) ;
var scriptModule = require ( 'amt-script' ) ;
var script = scriptModule . setup ( scriptData , { } )
script . amtstack = amtstack ;
script . start ( ) ;
2019-06-13 12:12:11 -04:00
script . onCompleted = function ( ) { if ( callback ) { callback ( ) ; } exit ( 1 ) ; }
2018-02-02 15:46:09 -05:00
}
2018-01-30 21:23:57 -05:00
2018-03-06 20:50:44 -05:00
2018-01-30 21:23:57 -05:00
//
// FETCH ALL INTEL AMT STATE
//
2019-06-14 19:33:53 -04:00
function saveEntireAmtState2 ( ) {
2018-01-25 19:12:53 -05:00
console . log ( 'Fetching all Intel AMT state, this may take a few minutes...' ) ;
2018-01-30 21:23:57 -05:00
var transport = require ( 'amt-wsman-duk' ) ;
var wsman = require ( 'amt-wsman' ) ;
var amt = require ( 'amt' ) ;
2018-04-04 15:08:28 -04:00
wsstack = new wsman ( transport , settings . hostname , settings . tls ? 16993 : 16992 , settings . username , settings . password , settings . tls ) ;
2018-01-02 19:52:49 -05:00
amtstack = new amt ( wsstack ) ;
2018-01-25 19:28:52 -05:00
amtstack . onProcessChanged = onWsmanProcessChanged ;
//var AllWsman = "AMT_GeneralSystemDefenseCapabilities".split(',');
2018-01-02 19:52:49 -05:00
var AllWsman = " AMT _8021xCredentialContext , AMT _8021XProfile , AMT _ActiveFilterStatistics , AMT _AgentPresenceCapabilities , AMT _AgentPresenceInterfacePolicy , AMT _AgentPresenceService , AMT _AgentPresenceWatchdog , AMT _AgentPresenceWatchdogAction , AMT _AlarmClockService , IPS _AlarmClockOccurrence , AMT _AssetTable , AMT _AssetTableService , AMT _AuditLog , AMT _AuditPolicyRule , AMT _AuthorizationService , AMT _BootCapabilities , AMT _BootSettingData , AMT _ComplexFilterEntryBase , AMT _CRL , AMT _CryptographicCapabilities , AMT _EACCredentialContext , AMT _EndpointAccessControlService , AMT _EnvironmentDetectionInterfacePolicy , AMT _EnvironmentDetectionSettingData , AMT _EthernetPortSettings , AMT _EventLogEntry , AMT _EventManagerService , AMT _EventSubscriber , AMT _FilterEntryBase , AMT _FilterInSystemDefensePolicy , AMT _GeneralSettings , AMT _GeneralSystemDefenseCapabilities , AMT _Hdr8021Filter , AMT _HeuristicPacketFilterInterfacePolicy , AMT _HeuristicPacketFilterSettings , AMT _HeuristicPacketFilterStatistics , AMT _InterfacePolicy , AMT _IPHeadersFilter , AMT _KerberosSettingData , AMT _ManagementPresenceRemoteSAP , AMT _MessageLog , AMT _MPSUsernamePassword , AMT _NetworkFilter , AMT _NetworkPortDefaultSystemDefensePolicy , AMT _NetworkPortSystemDefenseCapabilities , AMT _NetworkPortSystemDefensePolicy , AMT _PCIDevice , AMT _PETCapabilities , AMT _PETFilterForTarget , AMT _PETFilterSetting , AMT _ProvisioningCertificateHash , AMT _PublicKeyCertificate , AMT _PublicKeyManagementCapabilities , AMT _PublicKeyManagementService , AMT _PublicPrivateKeyPair , AMT _RedirectionService , AMT _RemoteAccessCapabilities , AMT _RemoteAccessCredentialContext , AMT _RemoteAccessPolicyAppliesToMPS , AMT _RemoteAccessPolicyRule , AMT _RemoteAccessService , AMT _SetupAndConfigurationService , AMT _SNMPEventSubscriber , AMT _StateTransitionCondition , AMT _SystemDefensePolicy , AMT _SystemDefensePolicyInService , AMT _SystemDefenseService , AMT _SystemPowerScheme , AMT _ThirdPartyDataStorageAdministrationService , AMT _ThirdPartyDataStorageService , AMT _TimeSynchronizationService , AMT _TLSCredentialContext , AMT _TLSProtocolEndpoint , AMT _TLSProtocolEndpointCollection , AMT _TLSSettingData , AMT _TrapTargetForService , AMT _UserInitiatedConnectionService , AMT _WebUIService , AMT _WiFiPortConfigurationService , CIM _AbstractIndicationSubscription , CIM _Account , CIM _AccountManagementCapabilities , CIM _AccountManagementService , CIM _AccountOnSystem , CIM _AdminDomain , CIM _AlertIndication , CIM _AssignedIdentity , CIM _AssociatedPowerManagementService , CIM _AuthenticationService , CIM _AuthorizationService , CIM _BIOSElement , CIM _BIOSFeature , CIM _BIOSFeatureBIOSElements , CIM _BootConfigSetting , CIM _BootService , CIM _BootSettingData , CIM _BootSourceSetting , CIM _Capabilities , CIM _Card , CIM _Chassis , CIM _Chip , CIM _Collection , CIM _Component , CIM _ComputerSystem , CIM _ComputerSystemPackage , CIM _ConcreteComponent , CIM _ConcreteDependency , CIM _Controller , CIM _CoolingDevice , CIM _Credential , CIM _CredentialContext , CIM _CredentialManagementService , CIM _Dependency , CIM _DeviceSAPImplementation , CIM _ElementCapabilities , CIM _ElementConformsToProfile , CIM _ElementLocation , CIM _ElementSettingData , CIM _ElementSoftwareIdentity , CIM _ElementStatisticalData , CIM _EnabledLogicalElement , CIM _EnabledLogicalElementCapabilities , CIM _EthernetPort , CIM _Fan , CIM _FilterCollection , CIM _FilterCollectionSubscription , CIM _HostedAccessPoint , CIM _HostedDependency , CIM _HostedService , CIM _Identity , CIM _IEEE8021xCapabilities , CIM _IEEE8021xSettings , CIM _Indication , CIM _IndicationService , CIM _InstalledSoftwareIdentity , CIM _KVMRedirectionSAP , CIM _LANEndpoint , CIM _ListenerDestination , CIM _ListenerDestinationWSManagement , CIM _Location , CIM _Log , CIM _LogEntry , CIM _LogicalDevice , CIM _LogicalElement , CIM _LogicalPort , CIM _LogicalPortCapabilities , CIM _LogManagesRecord , CIM _ManagedCredential , CIM _ManagedElement , CIM _ManagedSystemElement , CIM _MediaAccessDevice , CIM _MemberOfCollection , CIM _Memory , CIM _MessageLog , CIM _NetworkPort , CIM _NetworkPortCapabilities , CIM _NetworkPortConfigurationService , CIM _OrderedComponent , CIM _OwningCollectionElement , CIM _OwningJobElement , CIM _PCIController , CIM _PhysicalComponent , CIM _PhysicalElement , CIM _PhysicalElementLocation , CIM _PhysicalFrame , CIM _PhysicalMemory , CIM _PhysicalPackage , CIM _Policy , CIM _PolicyAction , CIM _PolicyCondition , CIM _PolicyInSystem , CIM _PolicyRule , CIM _PolicyR
2018-01-25 19:28:52 -05:00
IntelAmtEntireStateProgress = 101 ;
2018-01-02 19:52:49 -05:00
IntelAmtEntireStateCalls = 3 ;
IntelAmtEntireState = { 'localtime' : Date ( ) , 'utctime' : new Date ( ) . toUTCString ( ) , 'isotime' : new Date ( ) . toISOString ( ) } ;
amtstack . BatchEnum ( null , AllWsman , saveEntireAmtStateOk2 , null , true ) ;
amtstack . GetAuditLog ( saveEntireAmtStateOk3 ) ;
amtstack . GetMessageLog ( saveEntireAmtStateOk4 ) ;
2019-03-01 20:13:11 -05:00
}
// Save the entire Intel AMT state
2019-06-14 19:33:53 -04:00
function saveEntireAmtState ( ) {
2019-03-01 20:13:11 -05:00
// See if MicroLMS needs to be started
2019-06-14 19:33:53 -04:00
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
2019-03-01 20:13:11 -05:00
settings . noconsole = true ;
startLms ( ) . then ( saveEntireAmtState2 ) ;
}
2019-06-14 19:33:53 -04:00
else {
2019-03-01 20:13:11 -05:00
saveEntireAmtState2 ( ) ;
}
2018-01-02 19:52:49 -05:00
}
2018-01-25 19:28:52 -05:00
function onWsmanProcessChanged ( a , b ) { var x = Math . floor ( ( a * 100 ) / b ) ; if ( x < IntelAmtEntireStateProgress ) { IntelAmtEntireStateProgress = x ; console . log ( ( 100 - x ) + '%' ) ; } }
function saveEntireAmtStateOk2 ( stack , name , responses , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'wsmanenums' ] = responses ; saveEntireAmtStateDone ( ) ; }
function saveEntireAmtStateOk3 ( stack , messages , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'auditlog' ] = messages ; saveEntireAmtStateDone ( ) ; }
function saveEntireAmtStateOk4 ( stack , messages , tag , status ) { if ( status == 600 ) { console . log ( 'ERROR: Unable to connect to Intel(R) AMT.' ) ; exit ( 2 ) ; } IntelAmtEntireState [ 'eventlog' ] = messages ; saveEntireAmtStateDone ( ) ; }
2018-01-02 19:52:49 -05:00
2018-01-30 21:23:57 -05:00
// Called when the entire state of Intel AMT is fetched.
2018-01-02 19:52:49 -05:00
function saveEntireAmtStateDone ( ) {
if ( -- IntelAmtEntireStateCalls != 0 ) return ;
2018-01-25 19:12:53 -05:00
var out = fs . openSync ( settings . output , 'w' ) ;
2019-03-01 20:13:11 -05:00
fs . writeSync ( out , Buffer . from ( JSON . stringify ( IntelAmtEntireState ) ) ) ;
2018-01-25 19:12:53 -05:00
fs . closeSync ( out ) ;
console . log ( 'Done, results written to ' + settings . output + '.' ) ;
2018-01-02 19:52:49 -05:00
exit ( 1 ) ;
}
2018-01-30 21:23:57 -05:00
//
// FETCH ALL INTEL AMT MEI STATE
//
2017-12-12 19:04:54 -05:00
// Get Intel AMT information using MEI
2018-03-06 20:50:44 -05:00
// TODO: If this call is called many time at once, it's going to cause issues.
2018-03-26 20:13:32 -04:00
var getAmtInfoFetching = null ;
var getAmtInfoFetchingTimer = null ;
2017-12-12 19:04:54 -05:00
function getAmtInfo ( func , tag ) {
if ( amtMei == null ) { if ( func != null ) { func ( null , tag ) ; } return ; }
2018-03-26 20:13:32 -04:00
if ( getAmtInfoFetching != null ) { getAmtInfoFetching . push ( { f : func , t : tag } ) ; return ; }
getAmtInfoFetching = [ { f : func , t : tag } ] ;
2018-03-06 20:50:44 -05:00
amtMeiTmpState = { Flags : 0 , TrustedHashes : [ ] } ; // Flags: 1=EHBC, 2=CCM, 4=ACM
2018-03-26 20:13:32 -04:00
getAmtInfoFetchingTimer = setTimeout ( function ( ) {
// MEI failed to respond, break out and reset everthing.
for ( var i in getAmtInfoFetching ) { if ( getAmtInfoFetching [ i ] . f != null ) { getAmtInfoFetching [ i ] . f ( amtMeiTmpState , getAmtInfoFetching [ i ] . t ) ; } }
getAmtInfoFetching = null ;
getAmtInfoFetchingTimer = null ;
2019-03-01 20:13:11 -05:00
var amtMeiModule , amtMei ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-03-26 20:13:32 -04:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
} , 3000 ) ;
2017-12-12 19:04:54 -05:00
amtMei . getProtocolVersion ( function ( result ) { if ( result != null ) { amtMeiTmpState . MeiVersion = result ; } } ) ;
amtMei . getVersion ( function ( val ) {
amtMeiTmpState . Versions = { } ;
if ( val != null ) {
for ( var version in val . Versions ) { amtMeiTmpState . Versions [ val . Versions [ version ] . Description ] = val . Versions [ version ] . Version ; }
amtMei . getProvisioningMode ( function ( result ) { if ( result != null ) { amtMeiTmpState . ProvisioningMode = result . mode ; } } ) ;
amtMei . getProvisioningState ( function ( result ) { if ( result != null ) { amtMeiTmpState . ProvisioningState = result . state ; } } ) ;
amtMei . getEHBCState ( function ( result ) { if ( ( result != null ) && ( result . EHBC == true ) ) { amtMeiTmpState . Flags += 1 ; } } ) ;
amtMei . getControlMode ( function ( result ) { if ( result != null ) { if ( result . controlMode == 1 ) { amtMeiTmpState . Flags += 2 ; } if ( result . controlMode == 2 ) { amtMeiTmpState . Flags += 4 ; } } } ) ;
//amtMei.getMACAddresses(function (result) { if (result != null) { amtMeiTmpState.mac = result; } });
amtMei . getDnsSuffix ( function ( result ) { if ( result != null ) { amtMeiTmpState . dns = result ; } } ) ;
amtMei . getHashHandles ( function ( handles ) {
exitOnCount = handles . length ;
for ( var i = 0 ; i < handles . length ; ++ i ) {
amtMei . getCertHashEntry ( handles [ i ] , function ( result ) {
amtMeiTmpState . TrustedHashes . push ( { Active : result . isActive , Default : result . isDefault , HashAlgorithm : result . hashAlgorithm , Name : result . name , Hash : result . certificateHash } ) ;
2018-03-06 20:50:44 -05:00
if ( -- exitOnCount == 0 ) {
amtMeiTmpState . Notifications = lmsNotifications ; amtMeiState = amtMeiTmpState ;
2018-03-26 20:13:32 -04:00
for ( var i in getAmtInfoFetching ) { if ( getAmtInfoFetching [ i ] . f != null ) { getAmtInfoFetching [ i ] . f ( amtMeiTmpState , getAmtInfoFetching [ i ] . t ) ; } }
getAmtInfoFetching = null ;
clearTimeout ( getAmtInfoFetchingTimer ) ;
getAmtInfoFetchingTimer = null ;
2018-03-06 20:50:44 -05:00
}
2017-12-12 19:04:54 -05:00
} ) ;
}
} ) ;
} else {
amtMeiState = amtMeiTmpState ;
amtMeiState . ProvisioningMode = - 858993460 ;
amtMeiState . TrustedHashes = { } ;
2018-02-02 15:46:09 -05:00
amtMeiState . Notifications = lmsNotifications ;
2018-03-06 20:50:44 -05:00
//console.log('getAmtInfo3', JSON.stringify(amtMeiState));
2017-12-12 19:04:54 -05:00
if ( func != null ) { func ( amtMeiState , tag ) ; }
}
} ) ;
}
2018-01-30 21:23:57 -05:00
//
// MicroLMS
//
2018-02-02 15:46:09 -05:00
var lmsControlSockets = { } ;
var lmsControlSocketsNextId = 1 ;
var lmsNotifications = [ ] ;
2018-03-06 20:50:44 -05:00
var amtLms = null ;
2019-03-01 20:13:11 -05:00
var promise = require ( 'promise' ) ;
2019-07-15 17:45:36 -04:00
function startLms ( func , lmscommander , tag ) {
2019-03-01 20:13:11 -05: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-15 17:45:36 -04:00
if ( lme _heci == null ) { if ( func != null ) { func ( 0 , tag ) ; } this . promise . _res ( ) ; return ; }
2019-03-01 20:13:11 -05:00
2018-03-06 20:50:44 -05:00
//var amtLms = null;
2017-12-12 19:04:54 -05:00
var http = require ( 'http' ) ;
2019-03-01 20:13:11 -05:00
console . log ( 'Setting up MEI...' ) ;
try { amtMeiModule = require ( 'amt-mei' ) ; amtMei = new amtMeiModule ( ) ; } catch ( ex ) { console . log ( ex ) ; exit ( 1 ) ; return ; }
2018-01-25 19:28:52 -05:00
amtMei . on ( 'error' , function ( e ) { console . log ( 'ERROR: ' + e ) ; exit ( 1 ) ; return ; } ) ;
2018-03-19 20:31:54 -04:00
//console.log("PTHI Connected.");
2018-04-03 20:07:48 -04:00
2019-03-01 20:13:11 -05:00
console . log ( 'Setting up LME...' ) ;
2018-03-19 20:31:54 -04:00
amtLms = new lme _heci ( { debug : settings . lmsdebug } ) ;
2019-03-01 20:13:11 -05:00
amtLms . promise = ret ;
2018-03-19 20:31:54 -04:00
amtLms . on ( 'error' , function ( e ) {
2019-03-19 19:36:30 -04:00
//console.log('LME connection failed', e);
if ( lmscommander === true ) { //settings.noconsole !== true) {
startMeshCommanderLms ( ) ;
//console.log("LMS started, MeshCommander on HTTP/16994.");
2019-07-15 17:45:36 -04:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 2 , tag ) ; } , 100 ) ;
2019-03-19 19:36:30 -04:00
} else {
//console.log('LME connection failed: ' + JSON.stringify(e));
2019-07-15 17:45:36 -04:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 0 , tag ) ; } , 100 ) ;
2019-03-19 19:36:30 -04:00
}
2019-03-01 20:13:11 -05:00
this . promise . _res ( ) ;
2018-03-19 20:31:54 -04:00
} ) ;
amtLms . on ( 'notify' , function ( data , options , str , code ) {
if ( code == 'iAMT0052-3' ) {
2018-07-02 17:34:10 -04:00
kvmGetData ( ) ;
2018-03-19 20:31:54 -04:00
} else if ( str != null ) {
var notify = { date : Date . now ( ) , str : str , code : code } ;
lmsNotifications . push ( notify ) ;
while ( lmsNotifications . length > 100 ) { lmsNotifications . shift ( ) ; }
var notifyBuf = Buffer . concat ( [ Buffer . from ( '0900' , 'hex' ) , Buffer . from ( JSON . stringify ( notify ) ) ] ) // Add a notification
for ( var i in lmsControlSockets ) { lmsControlSockets [ i ] . write ( notifyBuf ) ; }
}
} ) ;
//console.log('LME Connecting...');
2019-03-01 20:13:11 -05:00
amtLms . on ( 'bind' , function ( mapping ) {
if ( mapping [ 16992 ] ) { this . removeAllListeners ( 'bind' ) ; } else { return ; }
//console.log('LMS Bounded');
2018-03-19 20:31:54 -04:00
amtLms . connected = true ;
2019-03-01 20:13:11 -05:00
this . promise . _res ( ) ;
2018-03-19 20:31:54 -04:00
//console.log("LME Connected.");
if ( settings . noconsole !== true ) {
2019-03-19 19:36:30 -04:00
startMeshCommanderLms ( ) ;
2018-03-19 20:31:54 -04:00
//console.log("LMS started, MeshCommander on HTTP/16994.");
2019-07-15 17:45:36 -04:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 2 , tag ) ; } , 100 ) ;
2018-03-19 20:31:54 -04:00
//console.logReferenceCount(tempTimer);
} else {
//console.log("LMS started.");
2019-07-15 17:45:36 -04:00
tempTimer = setTimeout ( function ( ) { delete tempTimer ; setupMeiOsAdmin ( func , 1 , tag ) ; } , 100 ) ;
2018-03-19 20:31:54 -04:00
//console.logReferenceCount(tempTimer);
}
2018-04-04 15:08:28 -04:00
2017-12-12 19:04:54 -05:00
} ) ;
2019-03-01 20:13:11 -05:00
return ( ret ) ;
2017-12-12 19:04:54 -05:00
}
2019-03-19 19:36:30 -04:00
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 16:28:41 -04:00
rsp . end ( Buffer . from ( _IntelAmtWebApp , "base64" ) ) ;
2019-03-19 19:36:30 -04:00
}
break ;
default : // Unknown request
rsp . statusCode = 404 ;
rsp . statusMessage = "Not Found" ;
rsp . end ( ) ;
break ;
}
} ) ;
}
2019-07-15 17:45:36 -04:00
function setupMeiOsAdmin ( func , state , tag ) {
2019-03-01 20:13:11 -05:00
if ( amtMei == null ) {
2019-07-15 17:45:36 -04:00
if ( func ) { func ( state , tag ) ; }
2019-03-01 20:13:11 -05: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-15 17:45:36 -04:00
if ( func ) { func ( state , tag ) ; }
2019-03-19 19:36:30 -04:00
2019-03-01 20:13:11 -05: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.
}
} ) ;
} ) ;
}
2018-03-06 20:50:44 -05:00
}
2018-03-08 20:58:22 -05:00
function kvmGetData ( tag ) {
osamtstack . IPS _KVMRedirectionSettingData _DataChannelRead ( kvmDataGetResponse , tag ) ;
}
function kvmDataGetResponse ( stack , name , response , status , tag ) {
2018-07-02 17:34:10 -04:00
if ( ( tag != 'skip' ) && ( status == 200 ) && ( response . Body . ReturnValue == 0 ) ) {
2018-03-08 20:58:22 -05:00
var val = null ;
try { val = Buffer . from ( response . Body . DataMessage , 'base64' ) . toString ( ) ; } catch ( e ) { return }
2018-07-02 17:34:10 -04:00
if ( val != null ) { kvmProcessData ( response . Body . RealmsBitmap , response . Body . MessageId , val ) ; }
2018-03-08 20:58:22 -05:00
}
}
var webRtcDesktop = null ;
function kvmProcessData ( realms , messageId , val ) {
var data = null ;
try { data = JSON . parse ( val ) } catch ( e ) { }
if ( ( data != null ) && ( data . action ) ) {
2018-07-02 17:34:10 -04:00
if ( data . action == 'present' ) { kvmSetData ( JSON . stringify ( { action : 'present' , ver : 1 , platform : process . platform } ) ) ; }
2018-03-08 20:58:22 -05:00
if ( data . action == 'offer' ) {
webRtcDesktop = { } ;
var rtc = require ( 'ILibWebRTC' ) ;
webRtcDesktop . webrtc = rtc . createConnection ( ) ;
webRtcDesktop . webrtc . on ( 'connected' , function ( ) { } ) ;
webRtcDesktop . webrtc . on ( 'disconnected' , function ( ) { webRtcCleanUp ( ) ; } ) ;
webRtcDesktop . webrtc . on ( 'dataChannel' , function ( rtcchannel ) {
webRtcDesktop . rtcchannel = rtcchannel ;
var kvmmodule = require ( 'meshDesktop' ) ;
webRtcDesktop . kvm = kvmmodule . getRemoteDesktopStream ( ) ;
2018-07-02 17:34:10 -04:00
webRtcDesktop . kvm . pipe ( webRtcDesktop . rtcchannel , { dataTypeSkip : 1 , end : false } ) ;
2018-03-08 20:58:22 -05:00
webRtcDesktop . rtcchannel . on ( 'end' , function ( ) { webRtcCleanUp ( ) ; } ) ;
2018-07-02 17:34:10 -04:00
webRtcDesktop . rtcchannel . on ( 'data' , function ( x ) { kvmCtrlData ( this , x ) ; } ) ;
webRtcDesktop . rtcchannel . pipe ( webRtcDesktop . kvm , { dataTypeSkip : 1 , end : false } ) ;
2018-03-08 20:58:22 -05:00
//webRtcDesktop.kvm.on('end', function () { console.log('WebRTC DataChannel closed2'); webRtcCleanUp(); });
//webRtcDesktop.rtcchannel.on('data', function (data) { console.log('WebRTC data: ' + data); });
} ) ;
kvmSetData ( JSON . stringify ( { action : 'answer' , ver : 1 , sdp : webRtcDesktop . webrtc . setOffer ( data . sdp ) } ) ) ;
}
}
}
2018-07-02 17:34:10 -04:00
// Polyfill path.join
var path = {
join : function ( ) {
var x = [ ] ;
for ( var i in arguments ) {
var w = arguments [ i ] ;
if ( w != null ) {
while ( w . endsWith ( '/' ) || w . endsWith ( '\\' ) ) { w = w . substring ( 0 , w . length - 1 ) ; }
if ( i != 0 ) {
while ( w . startsWith ( '/' ) || w . startsWith ( '\\' ) ) { w = w . substring ( 1 ) ; }
}
x . push ( w ) ;
}
}
if ( x . length == 0 ) return '/' ;
return x . join ( '/' ) ;
}
} ;
// Get a formated response for a given directory path
function getDirectoryInfo ( reqpath ) {
var response = { path : reqpath , dir : [ ] } ;
if ( ( ( reqpath == undefined ) || ( reqpath == '' ) ) && ( process . platform == 'win32' ) ) {
// List all the drives in the root, or the root itself
var results = null ;
try { results = fs . readDrivesSync ( ) ; } catch ( e ) { } // TODO: Anyway to get drive total size and free space? Could draw a progress bar.
//console.log('a', objToString(results, 0, ' '));
if ( results != null ) {
for ( var i = 0 ; i < results . length ; ++ i ) {
var drive = { n : results [ i ] . name , t : 1 } ;
if ( results [ i ] . type == 'REMOVABLE' ) { drive . dt = 'removable' ; } // TODO: See if this is USB/CDROM or something else, we can draw icons.
response . dir . push ( drive ) ;
}
}
} else {
// List all the files and folders in this path
if ( reqpath == '' ) { reqpath = '/' ; }
var xpath = path . join ( reqpath , '*' ) ;
var results = null ;
try { results = fs . readdirSync ( xpath ) ; } catch ( e ) { }
if ( results != null ) {
for ( var i = 0 ; i < results . length ; ++ i ) {
if ( ( results [ i ] != '.' ) && ( results [ i ] != '..' ) ) {
var stat = null , p = path . join ( reqpath , results [ i ] ) ;
try { stat = fs . statSync ( p ) ; } catch ( e ) { } // TODO: Get file size/date
if ( ( stat != null ) && ( stat != undefined ) ) {
if ( stat . isDirectory ( ) == true ) {
response . dir . push ( { n : results [ i ] , t : 2 , d : stat . mtime } ) ;
} else {
response . dir . push ( { n : results [ i ] , t : 3 , s : stat . size , d : stat . mtime } ) ;
}
}
}
}
}
}
return response ;
}
// Process KVM control channel data
function kvmCtrlData ( channel , cmd ) {
if ( cmd . length > 0 && cmd . charCodeAt ( 0 ) != 123 ) {
// This is upload data
if ( this . fileupload != null ) {
cmd = Buffer . from ( cmd , 'base64' ) ;
var header = cmd . readUInt32BE ( 0 ) ;
if ( ( header == 0x01000000 ) || ( header == 0x01000001 ) ) {
fs . writeSync ( this . fileupload . fp , cmd . slice ( 4 ) ) ;
channel . write ( { action : 'upload' , sub : 'ack' , reqid : this . fileupload . reqid } ) ;
if ( header == 0x01000001 ) { fs . closeSync ( this . fileupload . fp ) ; this . fileupload = null ; } // Close the file
}
}
return ;
}
//console.log('KVM Ctrl Data', cmd);
try { cmd = JSON . parse ( cmd ) ; } catch ( ex ) { console . error ( 'Invalid JSON: ' + cmd ) ; return ; }
if ( ( cmd . path != null ) && ( process . platform != 'win32' ) && ( cmd . path [ 0 ] != '/' ) ) { cmd . path = '/' + cmd . path ; } // Add '/' to paths on non-windows
switch ( cmd . action ) {
2018-07-13 22:18:43 -04:00
case 'ping' : {
// This is a keep alive
channel . write ( { action : 'pong' } ) ;
break ;
}
2018-07-02 17:34:10 -04:00
case 'ls' : {
/ *
// Close the watcher if required
var samepath = ( ( this . httprequest . watcher != undefined ) && ( cmd . path == this . httprequest . watcher . path ) ) ;
if ( ( this . httprequest . watcher != undefined ) && ( samepath == false ) ) {
//console.log('Closing watcher: ' + this.httprequest.watcher.path);
//this.httprequest.watcher.close(); // TODO: This line causes the agent to crash!!!!
delete this . httprequest . watcher ;
}
* /
// Send the folder content to the browser
var response = getDirectoryInfo ( cmd . path ) ;
if ( cmd . reqid != undefined ) { response . reqid = cmd . reqid ; }
channel . write ( response ) ;
/ *
// Start the directory watcher
if ( ( cmd . path != '' ) && ( samepath == false ) ) {
var watcher = fs . watch ( cmd . path , onFileWatcher ) ;
watcher . tunnel = this . httprequest ;
watcher . path = cmd . path ;
this . httprequest . watcher = watcher ;
//console.log('Starting watcher: ' + this.httprequest.watcher.path);
}
* /
break ;
}
case 'mkdir' : {
// Create a new empty folder
fs . mkdirSync ( cmd . path ) ;
break ;
}
case 'rm' : {
// Remove many files or folders
for ( var i in cmd . delfiles ) {
var fullpath = path . join ( cmd . path , cmd . delfiles [ i ] ) ;
try { fs . unlinkSync ( fullpath ) ; } catch ( e ) { console . log ( e ) ; }
}
break ;
}
case 'rename' : {
// Rename a file or folder
var oldfullpath = path . join ( cmd . path , cmd . oldname ) ;
var newfullpath = path . join ( cmd . path , cmd . newname ) ;
try { fs . renameSync ( oldfullpath , newfullpath ) ; } catch ( e ) { console . log ( e ) ; }
break ;
}
case 'download' : {
// Download a file, to browser
var sendNextBlock = 0 ;
if ( cmd . sub == 'start' ) { // Setup the download
if ( this . filedownload != null ) { channel . write ( { action : 'download' , sub : 'cancel' , id : this . filedownload . id } ) ; delete this . filedownload ; }
this . filedownload = { id : cmd . id , path : cmd . path , ptr : 0 }
try { this . filedownload . f = fs . openSync ( this . filedownload . path , 'rbN' ) ; } catch ( e ) { channel . write ( { action : 'download' , sub : 'cancel' , id : this . filedownload . id } ) ; delete this . filedownload ; }
if ( this . filedownload ) { channel . write ( { action : 'download' , sub : 'start' , id : cmd . id } ) ; }
} else if ( ( this . filedownload != null ) && ( cmd . id == this . filedownload . id ) ) { // Download commands
if ( cmd . sub == 'startack' ) { sendNextBlock = 8 ; } else if ( cmd . sub == 'stop' ) { delete this . filedownload ; } else if ( cmd . sub == 'ack' ) { sendNextBlock = 1 ; }
}
// Send the next download block(s)
while ( sendNextBlock > 0 ) {
sendNextBlock -- ;
2019-01-02 21:34:50 -05:00
var buf = Buffer . alloc ( 4096 ) ;
2018-07-02 17:34:10 -04:00
var len = fs . readSync ( this . filedownload . f , buf , 4 , 4092 , null ) ;
this . filedownload . ptr += len ;
if ( len < 4092 ) { buf . writeInt32BE ( 0x01000001 , 0 ) ; fs . closeSync ( this . filedownload . f ) ; delete this . filedownload ; sendNextBlock = 0 ; } else { buf . writeInt32BE ( 0x01000000 , 0 ) ; }
channel . write ( buf . slice ( 0 , len + 4 ) . toString ( 'base64' ) ) ; // Write as Base64
}
break ;
}
case 'upload' : {
// Upload a file, from browser
if ( cmd . sub == 'start' ) { // Start the upload
if ( this . fileupload != null ) { fs . closeSync ( this . fileupload . fp ) ; }
if ( ! cmd . path || ! cmd . name ) break ;
this . fileupload = { reqid : cmd . reqid } ;
var filepath = path . join ( cmd . path , cmd . name ) ;
try { this . fileupload . fp = fs . openSync ( filepath , 'wbN' ) ; } catch ( e ) { }
if ( this . fileupload . fp ) { channel . write ( { action : 'upload' , sub : 'start' , reqid : this . fileupload . reqid } ) ; } else { this . fileupload = null ; channel . write ( { action : 'upload' , sub : 'error' , reqid : this . fileupload . reqid } ) ; }
}
else if ( cmd . sub == 'cancel' ) { // Stop the upload
if ( this . fileupload != null ) { fs . closeSync ( this . fileupload . fp ) ; this . fileupload = null ; }
}
break ;
}
case 'copy' : {
// Copy a bunch of files from scpath to dspath
for ( var i in cmd . names ) {
var sc = path . join ( cmd . scpath , cmd . names [ i ] ) , ds = path . join ( cmd . dspath , cmd . names [ i ] ) ;
if ( sc != ds ) { try { fs . copyFileSync ( sc , ds ) ; } catch ( e ) { } }
}
break ;
}
case 'move' : {
// Move a bunch of files from scpath to dspath
for ( var i in cmd . names ) {
var sc = path . join ( cmd . scpath , cmd . names [ i ] ) , ds = path . join ( cmd . dspath , cmd . names [ i ] ) ;
if ( sc != ds ) { try { fs . copyFileSync ( sc , ds ) ; fs . unlinkSync ( sc ) ; } catch ( e ) { } }
}
break ;
}
2019-01-04 20:59:13 -05:00
default :
// Unknown action, ignore it.
break ;
2018-07-02 17:34:10 -04:00
}
}
2018-03-08 20:58:22 -05:00
function webRtcCleanUp ( ) {
if ( webRtcDesktop == null ) return ;
if ( webRtcDesktop . rtcchannel ) {
try { webRtcDesktop . rtcchannel . close ( ) ; } catch ( e ) { }
try { webRtcDesktop . rtcchannel . removeAllListeners ( 'data' ) ; } catch ( e ) { }
try { webRtcDesktop . rtcchannel . removeAllListeners ( 'end' ) ; } catch ( e ) { }
delete webRtcDesktop . rtcchannel ;
}
if ( webRtcDesktop . webrtc ) {
try { webRtcDesktop . webrtc . close ( ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'connected' ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'disconnected' ) ; } catch ( e ) { }
try { webRtcDesktop . webrtc . removeAllListeners ( 'dataChannel' ) ; } catch ( e ) { }
delete webRtcDesktop . webrtc ;
}
if ( webRtcDesktop . kvm ) {
try { webRtcDesktop . kvm . end ( ) ; } catch ( e ) { }
delete webRtcDesktop . kvm ;
}
webRtcDesktop = null ;
}
function kvmSetData ( x ) {
osamtstack . IPS _KVMRedirectionSettingData _DataChannelWrite ( Buffer . from ( x ) . toString ( 'base64' ) , function ( ) { } ) ;
}
2018-02-07 21:45:14 -05:00
function startLmsWsmanResponse ( stack , name , responses , status ) {
2019-10-28 21:25:35 -04:00
if ( status == 600 ) { console . log ( "ERROR: Unable to connect to Intel(R) AMT." ) ; }
else if ( status != 200 ) { console . log ( "ERROR: Unable to get object from Intel(R) AMT, status = " + status + "." ) ; }
2018-03-06 20:50:44 -05:00
else {
//console.log(JSON.stringify(responses), status);
2019-10-28 21:25:35 -04:00
var amtlogicalelements = responses [ 'CIM_SoftwareIdentity' ] . responses ;
2018-03-06 20:50:44 -05:00
if ( amtlogicalelements . length > 0 ) {
2019-10-28 21:25:35 -04:00
var v = getInstance ( amtlogicalelements , 'AMT' ) [ 'VersionString' ] ;
2018-03-06 20:50:44 -05:00
amtversion = parseInt ( v . split ( '.' ) [ 0 ] ) ;
amtversionmin = parseInt ( v . split ( '.' ) [ 1 ] ) ;
//console.log(amtversion, amtversionmin);
}
}
2018-02-07 21:45:14 -05:00
}
2018-01-30 21:23:57 -05:00
// Process commands in the LMS control channel
2018-02-02 15:46:09 -05:00
// Command 9 is add a notification.
2017-12-12 19:04:54 -05:00
function processLmsControlData ( data ) {
if ( data . length < 2 ) return ;
var cmdid = data . readUInt16LE ( 0 ) ;
switch ( cmdid ) {
case 1 : // Request basic Intel AMT information (CMD = 1)
2018-01-30 21:23:57 -05:00
{ getAmtInfo ( function ( meinfo , socket ) { meinfo . LoginMode = 2 ; socket . write ( Buffer . concat ( [ Buffer . from ( '0100' , 'hex' ) , Buffer . from ( JSON . stringify ( meinfo ) ) ] ) ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 2 : // Intel AMT MEI Unprovision (CMD = 2)
2019-01-02 21:34:50 -05:00
{ if ( data . length < 6 ) break ; amtMei . unprovision ( data . readUInt32LE ( 2 ) , function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 2 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 3 : // Intel AMT MEI GetLocalSystemAccount (CMD = 3)
2018-04-04 15:08:28 -04:00
{ amtMei . getLocalSystemAccount ( function ( account , socket ) { socket . write ( Buffer . concat ( [ Buffer . from ( '030000000000' , 'hex' ) , account . raw ] ) ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 4 : // Instruct Intel AMT to start remote configuration (CMD = 4)
2019-01-02 21:34:50 -05:00
{ amtMei . startConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 5 : // Instruct Intel AMT to stop remote configuration (CMD = 5)
2019-01-02 21:34:50 -05:00
{ amtMei . stopConfiguration ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 6 : // Instruct Intel AMT connect CIRA (CMD = 6)
2019-01-02 21:34:50 -05:00
{ amtMei . openUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 7 : // Instruct Intel AMT disconnect CIRA (CMD = 7)
2019-01-02 21:34:50 -05:00
{ amtMei . closeUserInitiatedConnection ( function ( status , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 7 , 0 ) ; data . writeUInt32LE ( status , 2 ) ; socket . write ( data ) ; } , this ) ; break ; }
2017-12-12 19:04:54 -05:00
case 8 : // Get Intel AMT CIRA State (CMD = 8)
2019-01-02 21:34:50 -05:00
{ amtMei . getRemoteAccessConnectionStatus ( function ( state , socket ) { var data = Buffer . alloc ( 6 ) ; data . writeUInt16LE ( 8 , 0 ) ; data . writeUInt32LE ( state . status , 2 ) ; socket . write ( Buffer . concat ( [ data , state . raw ] ) ) ; } , this ) ; break ; }
2019-01-04 20:59:13 -05:00
default :
// Unknown action, ignore it.
break ;
2017-12-12 19:04:54 -05:00
}
2017-10-31 19:19:58 -04:00
}
2018-01-30 21:23:57 -05:00
//
// MeshCentral TCP port router
//
2017-10-31 19:19:58 -04:00
function startRouter ( ) {
2020-04-03 19:06:38 -04:00
// Start by requesting a login token, this is needed because of 2FA and check that we have correct credentials from the start
var options ;
try {
var url = settings . serverurl . split ( 'meshrelay.ashx' ) . join ( 'control.ashx' ) + '?user=' + settings . username + '&pass=' + settings . password ;
if ( settings . emailtoken ) { url += '&token=**email**' ; } else if ( settings . token != null ) { url += '&token=' + settings . token ; }
options = http . parseUri ( url ) ;
} catch ( e ) { console . log ( "Unable to parse \"serverUrl\"." ) ; process . exit ( 1 ) ; return ; }
options . checkServerIdentity = onVerifyServer ;
options . rejectUnauthorized = false ;
settings . websocket = http . request ( options ) ;
settings . websocket . upgrade = OnServerWebSocket ;
settings . websocket . on ( 'error' , function ( e ) { console . log ( "ERROR: " + JSON . stringify ( e ) ) ; } ) ;
settings . websocket . end ( ) ;
}
function OnServerWebSocket ( msg , s , head ) {
settings . webchannel = s ;
s . on ( 'data' , function ( msg ) {
var command = JSON . parse ( msg ) ;
switch ( command . action ) {
case 'close' : {
if ( command . cause == 'noauth' ) {
if ( command . msg == 'tokenrequired' ) {
if ( command . email2fasent === true ) {
console . log ( "Login token email sent." ) ;
} else if ( command . email2fa === true ) {
console . log ( "Login token required, use --token [token], or --emailtoken get a token." ) ;
} else {
console . log ( "Login token required, use --token [token]." ) ;
}
} else { console . log ( "Invalid username or password." ) ; }
} else { console . log ( "Server disconnected: " + command . msg ) ; }
process . exit ( 1 ) ;
return ;
}
case 'serverinfo' : {
s . write ( "{\"action\":\"authcookie\"}" ) ; // Ask for our first authentication cookie
break ;
}
case 'authcookie' : {
if ( settings . acookie == null ) {
settings . acookie = command . cookie ;
settings . rcookie = command . rcookie ;
settings . renewCookieTimer = setInterval ( function ( ) { settings . webchannel . write ( "{\"action\":\"authcookie\"}" ) ; } , 600000 ) ; // Ask for new cookie every 10 minutes
startRouterEx ( ) ;
} else {
settings . acookie = command . cookie ;
settings . rcookie = command . rcookie ;
}
break ;
}
}
} ) ;
s . on ( 'error' , function ( ) { console . log ( "Server connection error." ) ; process . exit ( 1 ) ; return ; } ) ;
s . on ( 'close' , function ( ) { console . log ( "Server closed the connection." ) ; process . exit ( 1 ) ; return ; } ) ;
}
function startRouterEx ( ) {
2017-10-31 19:19:58 -04:00
tcpserver = net . createServer ( OnTcpClientConnected ) ;
2019-10-28 21:25:35 -04:00
tcpserver . on ( 'error' , function ( e ) { console . log ( "ERROR: " + JSON . stringify ( e ) ) ; exit ( 0 ) ; return ; } ) ;
2020-04-03 19:06:38 -04:00
try {
tcpserver . listen ( settings . localport , function ( ) {
// We started listening.
if ( settings . remotetarget == null ) {
console . log ( 'Redirecting local port ' + settings . localport + ' to remote port ' + settings . remoteport + '.' ) ;
} else {
console . log ( 'Redirecting local port ' + settings . localport + ' to ' + settings . remotetarget + ':' + settings . remoteport + '.' ) ;
}
console . log ( "Press ctrl-c to exit." ) ;
2017-10-31 19:19:58 -04:00
2020-04-03 19:06:38 -04:00
// If settings has a "cmd", run it now.
//process.exec("notepad.exe");
} ) ;
} catch ( ex ) { console . log ( "Unable to bind to local TCP port " + settings . localport + "." ) ; exit ( 1 ) ; return ; }
2017-10-31 19:19:58 -04:00
}
// Called when a TCP connect is received on the local port. Launch a tunnel.
function OnTcpClientConnected ( c ) {
try {
// 'connection' listener
2019-10-28 21:25:35 -04:00
debug ( 1 , "Client connected" ) ;
c . on ( 'end' , function ( ) { disconnectTunnel ( this , this . websocket , "Client closed" ) ; } ) ;
2017-10-31 19:19:58 -04:00
c . pause ( ) ;
2020-04-03 19:06:38 -04:00
var options ;
2017-10-31 19:19:58 -04:00
try {
2020-04-03 19:06:38 -04:00
options = http . parseUri ( settings . serverurl + '?auth=' + settings . acookie + '&nodeid=' + settings . remotenodeid + '&tcpport=' + settings . remoteport + ( settings . remotetarget == null ? '' : '&tcpaddr=' + settings . remotetarget ) ) ;
2019-10-28 21:25:35 -04:00
} catch ( e ) { console . log ( "Unable to parse \"serverUrl\"." ) ; process . exit ( 1 ) ; return ; }
2017-10-31 19:19:58 -04:00
options . checkServerIdentity = onVerifyServer ;
2018-01-26 20:01:38 -05:00
options . rejectUnauthorized = false ;
2017-10-31 19:19:58 -04:00
c . websocket = http . request ( options ) ;
c . websocket . tcp = c ;
c . websocket . tunneling = false ;
c . websocket . upgrade = OnWebSocket ;
2019-10-28 21:25:35 -04:00
c . websocket . on ( 'error' , function ( e ) { console . log ( "ERROR: " + JSON . stringify ( e ) ) ; } ) ;
2017-10-31 19:19:58 -04:00
c . websocket . end ( ) ;
} catch ( e ) { debug ( 2 , e ) ; }
}
// Disconnect both TCP & WebSocket connections and display a message.
function disconnectTunnel ( tcp , ws , msg ) {
if ( ws != null ) { try { ws . end ( ) ; } catch ( e ) { debug ( 2 , e ) ; } }
if ( tcp != null ) { try { tcp . end ( ) ; } catch ( e ) { debug ( 2 , e ) ; } }
2019-10-28 21:25:35 -04:00
debug ( 1 , "Tunnel disconnected: " + msg ) ;
2017-10-31 19:19:58 -04:00
}
// Called when the web socket gets connected
function OnWebSocket ( msg , s , head ) {
2019-10-28 21:25:35 -04:00
debug ( 1 , "Websocket connected" ) ;
2017-10-31 19:19:58 -04:00
s . on ( 'data' , function ( msg ) {
if ( this . parent . tunneling == false ) {
msg = msg . toString ( ) ;
2019-08-13 14:49:05 -04:00
if ( ( msg == 'c' ) || ( msg == 'cr' ) ) {
2019-10-28 21:25:35 -04:00
this . parent . tunneling = true ; this . pipe ( this . parent . tcp ) ; this . parent . tcp . pipe ( this ) ; debug ( 1 , "Tunnel active" ) ;
2017-10-31 19:19:58 -04:00
} else if ( ( msg . length > 6 ) && ( msg . substring ( 0 , 6 ) == 'error:' ) ) {
console . log ( msg . substring ( 6 ) ) ;
disconnectTunnel ( this . tcp , this , msg . substring ( 6 ) ) ;
}
}
} ) ;
2020-04-03 19:06:38 -04:00
s . on ( 'error' , function ( ) { disconnectTunnel ( this . tcp , this , 'Websocket error' ) ; } ) ;
s . on ( 'close' , function ( ) { disconnectTunnel ( this . tcp , this , 'Websocket closed' ) ; } ) ;
2017-10-31 19:19:58 -04:00
s . parent = this ;
}
// Try to discover the location of the mesh server
2019-10-28 21:25:35 -04:00
function discoverMeshServer ( ) { console . log ( "Looking for server..." ) ; discoveryInterval = setInterval ( discoverMeshServerOnce , 5000 ) ; discoverMeshServerOnce ( ) ; }
2017-10-31 19:19:58 -04:00
// Try to discover the location of the mesh server only once
function discoverMeshServerOnce ( ) {
var interfaces = os . networkInterfaces ( ) ;
for ( var adapter in interfaces ) {
if ( interfaces . hasOwnProperty ( adapter ) ) {
2017-12-12 19:04:54 -05:00
for ( var i = 0 ; i < interfaces [ adapter ] . length ; ++ i ) {
2017-10-31 19:19:58 -04:00
var addr = interfaces [ adapter ] [ i ] ;
2019-10-28 21:25:35 -04:00
multicastSockets [ i ] = dgram . createSocket ( { type : ( addr . family == 'IPv4' ? 'udp4' : 'udp6' ) } ) ;
2017-10-31 19:19:58 -04:00
multicastSockets [ i ] . bind ( { address : addr . address , exclusive : false } ) ;
2019-10-28 21:25:35 -04:00
if ( addr . family == 'IPv4' ) {
2018-07-23 20:34:24 -04:00
try {
multicastSockets [ i ] . addMembership ( membershipIPv4 ) ;
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets [ i ] . once ( 'message' , OnMulticastMessage ) ;
2019-03-26 18:18:07 -04:00
multicastSockets [ i ] . send ( settings . serverid , 16989 , membershipIPv4 ) ;
2018-07-23 20:34:24 -04:00
} catch ( e ) { }
2017-10-31 19:19:58 -04:00
}
}
}
}
}
// Called when a multicast packet is received
function OnMulticastMessage ( msg , rinfo ) {
var m = msg . toString ( ) . split ( '|' ) ;
2019-03-26 18:18:07 -04:00
if ( ( m . length == 3 ) && ( m [ 0 ] == 'MeshCentral2' ) && ( m [ 1 ] == settings . serverid ) ) {
settings . serverurl = m [ 2 ] . replace ( '%s' , rinfo . address ) . replace ( '/agent.ashx' , '/meshrelay.ashx' ) ;
2019-10-28 21:25:35 -04:00
console . log ( "Found server at " + settings . serverurl + "." ) ;
2017-10-31 19:19:58 -04:00
if ( discoveryInterval != null ) { clearInterval ( discoveryInterval ) ; discoveryInterval = null ; }
startRouter ( ) ;
}
}
2018-01-30 21:23:57 -05:00
//
// PUSH MESHCOMMANDER INTO FIRMWARE
//
2017-12-12 19:04:54 -05:00
function nextStepStorageUpload ( ) {
debug ( 3 , "nextStepStorageUpload" ) ;
getAmtStorage ( function ( statusCode , data ) {
if ( statusCode == 200 ) {
debug ( 2 , "getAmtStorage: " + JSON . stringify ( data , null , 2 ) ) ;
if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'index.htm' ] != null ) ) { nextStepStorageUpload3 ( 'index.htm' ) ; }
else if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'logon.htm' ] != null ) ) { nextStepStorageUpload3 ( 'logon.htm' ) ; }
else if ( ( data [ 'content' ] != null ) && ( data [ 'content' ] [ 'logon.htm' ] != null ) ) { nextStepStorageUpload3 ( 'logon.htm' ) ; }
else { nextStepStorageUpload2 ( 'index.htm' , null ) ; }
} else {
console . log ( "Unable to read storage state." ) ;
exit ( ) ;
return ;
}
} ) ;
}
function nextStepStorageUpload2 ( uploadName , linkName ) {
debug ( 3 , "nextStepStorageUpload2" ) ;
if ( settings . webapp == null ) { console . log ( "Done." ) ; exit ( ) ; return ; } else {
console . log ( "Uploading MeshCommander..." ) ;
pushToStorage ( uploadName , linkName , Buffer . from ( settings . webapp , 'base64' ) , function ( statusCode ) {
if ( statusCode == 500 ) { console . log ( "Error, check that computer is powered on." ) ; exit ( ) ; return ; }
if ( statusCode != 200 ) {
if ( uploadName == 'index.htm' ) {
nextStepStorageUpload2 ( 'mesh/commander/console' , 'MeshCommander' ) ;
} else {
console . log ( "Unable to upload MeshCommander, status = " + statusCode + "." ) ; exit ( ) ; return ;
}
} else {
console . log ( "Verifying MeshCommander..." ) ;
verifyStorage ( uploadName , Buffer . from ( settings . webapp , 'base64' ) , function ( verified ) {
2019-10-28 21:25:35 -04:00
if ( verified == true ) { console . log ( "Done." ) ; } else { console . log ( "MeshCommander verification failed." ) ; }
2017-12-12 19:04:54 -05:00
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 ) {
2019-10-28 21:25:35 -04:00
var req = digest . request ( { protocol : settings . protocol , method : 'GET' , host : settings . hostname , path : '/amt-storage/' , port : settings . localport } ,
2017-12-12 19:04:54 -05:00
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 ;
2019-04-17 20:08:01 -04:00
data = data . split ( '\t' ) . join ( '' ) . split ( '\r' ) . join ( '' ) . split ( '\n' ) . join ( '' ) ;
2017-12-12 19:04:54 -05:00
try {
2019-04-17 20:08:01 -04:00
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.
2017-12-12 19:04:54 -05:00
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.
2019-04-17 20:08:01 -04:00
var xopen = data . split ( "{" ) . length , xclose = data . split ( "}" ) . length , xadd = '' ;
while ( xopen > xclose ) { data += '}' ; xclose ++ ; } // Close any missing close brackets
2017-12-12 19:04:54 -05:00
amtstorage = JSON . parse ( data ) ;
2019-04-17 20:08:01 -04:00
} catch ( e ) { console . log ( "Error: Unable to parse Intel AMT response: " + data , e ) ; func ( null ) ; }
2017-12-12 19:04:54 -05:00
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 ; }
2019-10-28 21:25:35 -04:00
var req = digest . request ( { protocol : settings . protocol , method : 'PUT' , host : settings . hostname , path : ( '/amt-storage/' + name + ( ( ptr != 0 ) ? '?append=' : '' ) ) , port : settings . localport } ) ;
2017-12-12 19:04:54 -05:00
req . on ( 'error' , function ( e ) { console . log ( "Error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
2018-01-25 19:12:53 -05:00
req . on ( 'response' , function ( response ) {
debug ( 1 , 'Chunk Done' , data . length , ptr ) ;
if ( ( response . statusCode == 200 ) && ( ptr < data . length ) ) { pushToStorage ( name , linkname , data , func , ptr ) ; } else { if ( func != null ) { func ( response . statusCode ) ; } }
} ) ;
2017-12-12 19:04:54 -05:00
var header = ( ptr > 0 ) ? '<metadata></metadata>' : '<metadata><headers><h>Content-Encoding:gzip</h><h>Content-Type:text/html</h></headers>' + ( ( linkname != null ) ? ( '<link>' + linkname + '</link>' ) : '' ) + '</metadata>' ;
var blocklen = ( ( data . length - ptr ) > ( 7000 - header . length ) ) ? ( 7000 - header . length ) : ( data . length - ptr ) ;
req . write ( Buffer . concat ( [ new Buffer ( header ) , data . slice ( ptr , ptr + blocklen ) ] ) ) ;
ptr += blocklen ;
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function verifyStorage ( name , data , func ) {
2019-10-28 21:25:35 -04:00
var req = digest . request ( { protocol : settings . protocol , method : 'GET' , host : settings . hostname , path : ( '/amt-storage/' + name ) , port : settings . localport } ) ;
2017-12-12 19:04:54 -05:00
req . on ( 'error' , function ( e ) { console . log ( "Verify error occured: " + JSON . stringify ( e ) ) ; if ( func != null ) { func ( null ) ; } } ) ;
2018-01-25 19:12:53 -05:00
req . on ( 'response' , function ( response ) {
response . ptr = 0 ;
response . ok = true ;
2018-01-26 20:01:38 -05:00
response . on ( 'data' , function ( data2 ) { if ( data2 . toString ( 'hex' ) != data . slice ( response . ptr , response . ptr + data2 . length ) . toString ( 'hex' ) ) { response . ok = false ; console . log ( 'Verifiy failed (' + response . ptr + ', ' + data2 . length + ').' ) ; } response . ptr += data2 . length ; } ) ;
2018-01-25 19:12:53 -05:00
response . on ( 'end' , function ( ) { if ( func != null ) { func ( response . ok ) ; } } ) ;
} ) ;
2017-12-12 19:04:54 -05:00
req . end ( ) ;
}
// Fetch the Intel AMT storage document
function deleteStorage ( name , func , noretry ) {
2019-10-28 21:25:35 -04:00
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 ) ; } } } } ) ;
2018-01-25 19:12:53 -05:00
req . on ( 'response' , function ( response ) { if ( func != null ) { func ( response . statusCode ) ; } } ) ;
2017-12-12 19:04:54 -05:00
req . end ( ) ;
}
2019-06-06 12:59:13 -04:00
//
// 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 ; } }
2019-06-14 19:33:53 -04:00
2019-06-06 12:59:13 -04:00
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;
2019-06-14 19:33:53 -04:00
ider . Start ( settings . hostname , ( settings . tls == true ) ? 16995 : 16994 , settings . username ? 'admin' : settings . username , settings . password , settings . tls ) ;
2019-06-06 12:59:13 -04:00
} catch ( ex ) { console . log ( ex ) ; }
}
2019-10-28 21:25:35 -04:00
function onIderStateChange ( stack , state ) { console . log ( [ "Disconnected" , "Connecting..." , "Connected..." , "Started IDER..." ] [ state ] ) ; }
2019-06-06 12:59:13 -04:00
function iderSectorStats ( mode , dev , mediaBlocks , lba , len ) {
if ( iderIdleTimer != null ) { clearTimeout ( iderIdleTimer ) ; }
2019-10-28 21:25:35 -04:00
iderIdleTimer = setTimeout ( function ( ) { console . log ( "Idle timeout" ) ; process . exit ( 1 ) ; } , 1000 * settings . timeout ) ;
2019-06-06 12:59:13 -04:00
}
2019-07-15 17:45:36 -04: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.
2019-10-28 21:25:35 -04:00
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
2019-07-15 17:45:36 -04:00
}
// Check if configuration change is required
if ( args ) {
2019-07-16 15:25:21 -04:00
var docall = false ;
var x = JSON . parse ( JSON . stringify ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ) ) ;
var y = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ;
2019-10-28 21:25:35 -04:00
delete x [ 'IpSyncEnabled' ] ;
delete x [ 'LinkIsUp' ] ;
delete x [ 'LinkPolicy' ] ;
delete x [ 'MACAddress' ] ;
delete x [ 'SharedDynamicIP' ] ;
delete x [ 'SharedMAC' ] ;
delete x [ 'SharedStaticIp' ] ;
2019-07-16 15:25:21 -04:00
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-15 17:45:36 -04:00
if ( args . dhcp && ( amtwiredif != - 1 ) && ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] . DHCPEnabled == false ) ) {
// Change to DHCP
x [ 'DHCPEnabled' ] = true ;
2019-07-16 15:25:21 -04:00
docall = true ;
2019-07-15 17:45:36 -04:00
}
else if ( args . static && ( amtwiredif != - 1 ) && ( response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] . DHCPEnabled == true ) ) {
// Change to STATIC
x [ 'DHCPEnabled' ] = false ;
2019-10-28 21:25:35 -04:00
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 15:25:21 -04:00
docall = true ;
}
if ( docall ) {
2019-10-28 21:25:35 -04:00
if ( x [ 'DHCPEnabled' ] == true ) {
delete x [ 'IPAddress' ] ;
delete x [ 'DefaultGateway' ] ;
delete x [ 'PrimaryDNS' ] ;
delete x [ 'SecondaryDNS' ] ;
delete x [ 'SubnetMask' ] ;
2019-07-16 15:25:21 -04:00
}
pendingAmtConfigActions ++ ;
//console.log(JSON.stringify(x, 4, ' '));
2019-10-28 21:25:35 -04:00
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-15 17:45:36 -04:00
}
}
if ( pendingAmtConfigActions == 0 ) {
2019-07-16 15:25:21 -04: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-15 17:45:36 -04:00
if ( amtwiredif != - 1 ) { // Wired
var z = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwiredif ] ;
2019-10-28 21:25:35 -04:00
console . log ( "--WIRED---" ) ;
2019-07-15 17:45:36 -04:00
for ( var i in z ) {
if ( [ 'ElementName' , 'InstanceID' ] . indexOf ( i ) == - 1 ) {
var name = i ;
2019-07-16 15:25:21 -04:00
while ( name . length < maxlen ) { name += ' ' ; }
console . log ( name + ' : ' + z [ i ] ) ;
2019-07-15 17:45:36 -04:00
}
}
}
if ( amtwirelessif != - 1 ) { // Wireless
var z = response [ 'AMT_EthernetPortSettings' ] . responses [ amtwirelessif ] ;
2019-10-28 21:25:35 -04:00
console . log ( "--WIRELESS---" ) ;
2019-07-15 17:45:36 -04:00
for ( var i in z ) {
if ( [ 'ElementName' , 'InstanceID' ] . indexOf ( i ) == - 1 ) {
var name = i ;
2019-07-16 15:25:21 -04:00
while ( name . length < maxlen ) { name += ' ' ; }
console . log ( name + ' : ' + z [ i ] ) ;
2019-07-15 17:45:36 -04:00
}
}
}
process . exit ( 0 ) ;
}
} else {
2019-10-28 21:25:35 -04:00
console . log ( "Error, status " + status + "." ) ;
2019-07-15 17:45:36 -04:00
process . exit ( 1 ) ;
}
}
2020-04-09 15:14:09 -04:00
//
// Intel AMT Wifi configuration
//
function performAmtWifiConfig ( args ) {
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( performAmtWifiConfig0 , false , args ) ;
} else {
performAmtWifiConfig0 ( 1 , args ) ;
}
}
function performAmtWifiConfig0 ( 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 , [ 'CIM_WiFiEndpointSettings' ] , performAmtWifiConfig1 , args ) ;
}
function performAmtWifiConfig1 ( stack , name , response , status , args ) {
if ( status == 200 ) {
var wifiAuthMethod = { 1 : "Other" , 2 : "Open" , 3 : "Shared Key" , 4 : "WPA PSK" , 5 : "WPA 802.1x" , 6 : "WPA2 PSK" , 7 : "WPA2 802.1x" , 32768 : "WPA3 802.1x" } ;
var wifiEncMethod = { 1 : "Other" , 2 : "WEP" , 3 : "TKIP" , 4 : "CCMP" , 5 : "None" }
var wifiProfiles = { } ;
for ( var y in response [ 'CIM_WiFiEndpointSettings' ] . responses ) {
var z = response [ 'CIM_WiFiEndpointSettings' ] . responses [ y ] ;
var n = z [ 'ElementName' ] ;
wifiProfiles [ n ] = { 'Priority' : z [ 'Priority' ] , 'SSID' : z [ 'SSID' ] , 'AuthenticationMethod' : z [ 'AuthenticationMethod' ] , 'EncryptionMethod' : z [ 'EncryptionMethod' ] } ;
}
if ( args ) {
if ( args . list ) {
2020-05-13 03:27:31 -04:00
console . log ( 'List of Intel AMT Wifi profiles:' ) ;
2020-04-09 15:14:09 -04:00
if ( wifiProfiles . length == 0 ) {
console . log ( 'No Wifi profiles is stored.' ) ;
}
for ( var t in wifiProfiles ) {
var w = wifiProfiles [ t ] ;
console . log ( 'Profile Name: ' + t + '; Priority: ' + w [ 'Priority' ] + '; SSID: ' + w [ 'SSID' ] + '; Security: ' + wifiAuthMethod [ w [ 'AuthenticationMethod' ] ] + '/' + wifiEncMethod [ w [ 'EncryptionMethod' ] ] ) ;
}
process . exit ( 0 ) ;
} else if ( args . add ) {
if ( args . auth == null ) { args . auth = 6 } //if not set, default to WPA2 PSK
if ( args . enc == null ) { args . enc = 3 } //if not set, default to TKIP
if ( args . priority == null ) { args . priority = 0 } //if not set, default to 0
var wifiep = {
_ _parameterType : 'reference' ,
_ _resourceUri : 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpoint' ,
Name : 'WiFi Endpoint 0'
} ;
var wifiepsettinginput = {
_ _parameterType : 'instance' ,
_ _namespace : 'http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_WiFiEndpointSettings' ,
ElementName : args . name ,
InstanceID : 'Intel(r) AMT:WiFi Endpoint Settings ' + args . name ,
AuthenticationMethod : args . auth ,
EncryptionMethod : args . enc ,
SSID : args . ssid ,
Priority : args . priority ,
PSKPassPhrase : args . psk
}
stack . AMT _WiFiPortConfigurationService _AddWiFiSettings ( wifiep , wifiepsettinginput , null , null , null ,
function ( stck , nm , resp , sts ) {
if ( sts == 200 ) {
console . log ( "Wifi profile " + args . name + " successfully added." ) ;
} else {
console . log ( "Failed to add wifi profile " + args . name + "." ) ;
}
process . exit ( 0 ) ;
} ) ;
} else if ( args . del ) {
if ( wifiProfiles [ args . name ] == null ) {
console . log ( "Profile " + args . name + " could not be found." ) ;
process . exit ( 0 ) ;
}
stack . Delete ( 'CIM_WiFiEndpointSettings' , { InstanceID : 'Intel(r) AMT:WiFi Endpoint Settings ' + args . name } ,
function ( stck , nm , resp , sts ) {
if ( sts == 200 ) {
console . log ( "Wifi profile " + args . name + " successfully deleted." ) ;
} else {
console . log ( "Failed to delete wifi profile " + args . name + "." ) ;
}
process . exit ( 0 ) ;
} ,
0 , 1 ) ;
}
} else {
process . exit ( 0 ) ;
}
} else {
console . log ( "Error, status " + status + "." ) ;
process . exit ( 1 ) ;
}
}
2019-07-15 17:45:36 -04:00
2020-05-13 03:27:31 -04:00
//
// Intel AMT wake alarm configuration
//
function _fmtdatetime ( str ) {
return str . replace ( 'T' , ' ' ) . replace ( 'Z' , '' ) ;
}
function _fmtinterval ( str ) {
var cl = str . replace ( 'T' , '' ) . substring ( str . indexOf ( 'P' ) + 1 ) ;
cl = ' ' + cl . replace ( 'D' , " days " ) . replace ( 'H' , " hours " ) . replace ( 'M' , " minutes " ) ;
cl = cl . replace ( " 1 days " , " 1 day " ) . replace ( " 1 hours " , " 1 hour " ) . replace ( " 1 minutes " , " 1 minute " ) ;
return cl . substring ( 0 , cl . length - 1 ) ;
}
function _fmttimepad ( str ) {
str = '' + str ;
while ( str . length < 2 ) { str = '0' + str ; }
return str ;
}
function convertAmtDataStr ( str ) {
var timeArray = str . split ( 'Z' ) . join ( '' ) . split ( 'T' ) . join ( '-' ) . split ( ':' ) . join ( '-' ) . split ( '-' ) ;
return new Date ( timeArray [ 0 ] , timeArray [ 1 ] - 1 , timeArray [ 2 ] , timeArray [ 3 ] , timeArray [ 4 ] , timeArray [ 5 ] ) ;
}
function prepareAlarmOccurenceTemplate ( id , nm , start , interval , del ) {
return '<d:AlarmTemplate xmlns:d=\"http://intel.com/wbem/wscim/1/amt-schema/1/AMT_AlarmClockService\" xmlns:s=\"http://intel.com/wbem/wscim/1/ips-schema/1/IPS_AlarmClockOccurrence\"><s:InstanceID>' + id + '</s:InstanceID><s:StartTime><p:Datetime xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/common\">' + start + '</p:Datetime></s:StartTime><s:Interval><p:Interval xmlns:p=\"http://schemas.dmtf.org/wbem/wscim/1/common\">' + interval + '</p:Interval></s:Interval><s:DeleteOnCompletion>' + del + '</s:DeleteOnCompletion></d:AlarmTemplate>' ;
}
function performAmtWakeConfig ( args ) {
if ( ( settings . hostname == '127.0.0.1' ) || ( settings . hostname . toLowerCase ( ) == 'localhost' ) ) {
settings . noconsole = true ; startLms ( performAmtWakeConfig0 , false , args ) ;
} else {
performAmtWakeConfig0 ( 1 , args ) ;
}
}
function performAmtWakeConfig0 ( 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 , [ 'IPS_AlarmClockOccurrence' ] , performAmtWakeConfig1 , args ) ;
}
function performAmtWakeConfig1 ( stack , name , response , status , args ) {
if ( status == 200 ) {
var response = response [ 'IPS_AlarmClockOccurrence' ] . responses ;
if ( ! args ) { process . exit ( 0 ) ; return ; }
if ( args . list ) {
if ( response . length == 0 ) {
console . log ( 'No wake alarms.' ) ;
} else {
for ( var i = 0 ; i < response . length ; i ++ ) {
var waketime = convertAmtDataStr ( response [ i ] [ 'StartTime' ] [ 'Datetime' ] ) ;
var t = waketime . toLocaleString ( ) , tx = t . indexOf ( '.' ) ;
if ( tx >= 0 ) { t = t . substring ( 0 , tx ) ; }
var details = response [ i ] [ 'ElementName' ] + ', wake on ' + t . replace ( ' ' , ' at ' ) ;
if ( response [ i ] [ 'Interval' ] != null ) { details += ' and each' + _fmtinterval ( response [ i ] [ 'Interval' ] [ 'Interval' ] ) ; }
if ( response [ i ] [ 'DeleteOnCompletion' ] == true ) { details += ", delete when done" ; }
console . log ( details ) ;
}
}
process . exit ( 0 ) ;
} else if ( args . del ) {
// Remove a wake alarm, start by looking to see if it exists
var alarmFound = false ;
for ( var i = 0 ; i < response . length ; i ++ ) { if ( response [ i ] [ 'ElementName' ] == args . del ) { alarmFound = true ; } }
if ( alarmFound == false ) { console . log ( "Wake alarm " + args . del + " could not be found." ) ; process . exit ( 0 ) ; return ; }
// Remote the alarm
stack . Delete ( 'IPS_AlarmClockOccurrence' , { InstanceID : args . del } ,
function ( stck , nm , resp , sts ) {
if ( sts == 200 ) { console . log ( "Done." ) ; } else { console . log ( "Failed to delete wake alarm " + args . del + "." ) ; }
process . exit ( 0 ) ;
} ,
0 , 1 ) ;
} else if ( args . add ) {
// Add a wake alarm
var alarmFound = false ;
for ( var i = 0 ; i < response . length ; i ++ ) { if ( response [ i ] [ 'ElementName' ] == args . add ) { alarmFound = true ; } }
if ( alarmFound ) { console . log ( "Wake alarm " + args . add + " already exists." ) ; process . exit ( 0 ) ; return ; }
if ( typeof args . time != 'string' ) { args . time = '00:00:00' ; }
if ( typeof args . interval != 'string' ) { args . interval = '' ; }
var alarm _name = args . add ;
var x1 = args . date . split ( '-' ) ;
var x2 = args . time . split ( ':' ) ;
var t = new Date ( x1 [ 0 ] , x1 [ 1 ] - 1 , x1 [ 2 ] , x2 [ 0 ] , x2 [ 1 ] , 0 , 0 ) ; // Not sure why, but month is 0 = JAN, 11 = DEC, seconds must be 00.
var alarm _starttime = _fmttimepad ( t . getFullYear ( ) ) + '-' + _fmttimepad ( t . getMonth ( ) + 1 ) + '-' + _fmttimepad ( t . getDate ( ) ) + 'T' + _fmttimepad ( t . getHours ( ) ) + ':' + _fmttimepad ( t . getMinutes ( ) ) + ':' + _fmttimepad ( t . getSeconds ( ) ) + 'Z' ;
var x = args . interval . split ( '-' ) ;
if ( x . length != 3 ) { x = [ 0 , 0 , 0 ] ; }
var alarm _interval = 'P' + x [ 0 ] + 'DT' + x [ 1 ] + 'H' + x [ 2 ] + 'M' ;
var alarm _doc = ( args . deletewhendone != null ) ;
var tpl = prepareAlarmOccurenceTemplate ( alarm _name , alarm _name , alarm _starttime , alarm _interval , alarm _doc ) ;
stack . wsman . ExecMethodXml ( amtstack . CompleteName ( 'AMT_AlarmClockService' ) , 'AddAlarm' , tpl ,
function ( ws , resuri , response , status ) {
if ( status != 200 ) { console . log ( "Failed to add alarm. Status: " + status + ". Verify the alarm is for a future time." ) ; }
else if ( response . Body [ 'ReturnValue' ] != 0 ) { console . log ( "Failed to add alarm " + response . Body [ 'ReturnValueStr' ] + ". Verify the alarm is for a future time." ) ; }
else { console . log ( "Done." ) ; }
process . exit ( 0 ) ;
}
) ;
} else {
console . log ( "Unknown action, specify --list, --del or --add." ) ;
process . exit ( 0 ) ;
}
} else {
console . log ( "Error, status " + status + "." ) ;
process . exit ( 1 ) ;
}
}
2019-07-15 15:55:52 -04:00
//
// Intel AMT feature configuration action
//
function performAmtFeatureConfig ( args ) {
2019-07-15 17:45:36 -04: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 15:55:52 -04: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
2019-10-28 21:25:35 -04:00
var optinrequired = response [ 'IPS_OptInService' ] . response [ 'OptInRequired' ] ;
2019-07-15 15:55:52 -04:00
if ( args ) {
if ( ( args . userconsent == 'none' ) && ( optinrequired != 0 ) ) {
pendingAmtConfigActions ++ ;
2019-10-28 21:25:35 -04:00
response [ 'IPS_OptInService' ] . response [ 'OptInRequired' ] = 0 ;
amtstack . Put ( 'IPS_OptInService' , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 15:55:52 -04:00
}
else if ( ( args . userconsent == 'kvm' ) && ( optinrequired != 1 ) ) {
pendingAmtConfigActions ++ ;
2019-10-28 21:25:35 -04:00
response [ 'IPS_OptInService' ] . response [ 'OptInRequired' ] = 1 ;
amtstack . Put ( 'IPS_OptInService' , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 15:55:52 -04:00
}
else if ( ( args . userconsent == 'all' ) && ( optinrequired != 0xFFFFFFFF ) ) {
pendingAmtConfigActions ++ ;
2019-10-28 21:25:35 -04:00
response [ 'IPS_OptInService' ] . response [ 'OptInRequired' ] = 0xFFFFFFFF ;
amtstack . Put ( 'IPS_OptInService' , response [ 'IPS_OptInService' ] . response , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ;
2019-07-15 15:55:52 -04:00
}
}
// Redirection ports
var redirportchange = false ;
var redirchange = false ;
2019-10-28 21:25:35 -04:00
var redir = ( response [ 'AMT_RedirectionService' ] . response [ 'ListenerEnabled' ] == true ) ;
2019-07-15 15:55:52 -04:00
2019-10-28 21:25:35 -04:00
var sol = ( ( response [ 'AMT_RedirectionService' ] . response [ 'EnabledState' ] & 2 ) != 0 ) ;
var ider = ( ( response [ 'AMT_RedirectionService' ] . response [ 'EnabledState' ] & 1 ) != 0 ) ;
2019-07-15 15:55:52 -04:00
if ( args ) {
2019-10-28 21:25:35 -04:00
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 ; }
2019-07-15 15:55:52 -04:00
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-15 17:45:36 -04: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 15:55:52 -04:00
}
// KVM
var kvm = false ;
var kvmchange = false ;
if ( response [ 'CIM_KVMRedirectionSAP' ] != null ) {
2019-10-28 21:25:35 -04:00
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 ) ;
2019-07-15 15:55:52 -04:00
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-15 17:45:36 -04:00
if ( kvmchange ) { pendingAmtConfigActions ++ ; amtstack . CIM _KVMRedirectionSAP _RequestStateChange ( kvm ? 2 : 3 , 0 , function ( stack , name , response , status ) { if ( -- pendingAmtConfigActions == 0 ) { performAmtFeatureConfig0 ( ) ; } } ) ; }
2019-07-15 15:55:52 -04:00
}
}
if ( pendingAmtConfigActions == 0 ) {
2019-10-28 21:25:35 -04: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 15:55:52 -04:00
process . exit ( 0 ) ;
}
} else {
2019-10-28 21:25:35 -04:00
console . log ( "Error, status " + status + "." ) ;
2019-07-15 15:55:52 -04:00
process . exit ( 1 ) ;
}
}
2019-07-11 19:54:27 -04: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
2019-10-28 21:25:35 -04:00
amtstack . Get ( 'CIM_AssociatedPowerManagementService' , performAmtPowerActionEx2 , 0 , 1 ) ;
2019-07-11 19:54:27 -04:00
}
}
function performAmtPowerActionEx ( stack , name , response , status ) {
if ( status == 200 ) {
console . log ( response . Body . ReturnValueStr . split ( '_' ) . join ( ' ' ) ) ;
process . exit ( 0 ) ;
} else {
2019-10-28 21:25:35 -04:00
console . log ( "Error, status " + status + "." ) ;
2019-07-11 19:54:27 -04:00
process . exit ( 1 ) ;
}
}
2019-10-28 21:25:35 -04:00
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)" ] ;
2019-07-11 19:54:27 -04:00
function performAmtPowerActionEx2 ( stack , name , response , status ) {
if ( status == 200 ) {
var powerNumber = parseInt ( response . Body . PowerState ) ;
if ( ( powerNumber >= DMTFPowerStates . length ) && ( powerNumber > 1 ) ) {
2019-10-28 21:25:35 -04:00
console . log ( "Unknown power state: " + response . Body . PowerState ) ;
2019-07-11 19:54:27 -04:00
} else {
2019-10-28 21:25:35 -04:00
console . log ( "Current power state: " + DMTFPowerStates [ powerNumber ] ) ;
2019-07-11 19:54:27 -04:00
}
process . exit ( 0 ) ;
} else {
2019-10-28 21:25:35 -04:00
console . log ( "Error, status " + status + "." ) ;
2019-07-11 19:54:27 -04:00
process . exit ( 1 ) ;
}
}
2019-06-06 12:59:13 -04:00
//
// Startup
//
2018-03-19 20:31:54 -04:00
// Parse URL arguments
function parseUrlArguments ( url ) {
var r = { } , x = url . split ( '?' ) ;
if ( x . length < 2 ) return r ;
x = x [ 1 ] . split ( '&' ) ;
for ( var i in x ) { var j = x [ i ] . indexOf ( '=' ) ; if ( j > 0 ) { r [ x [ i ] . substring ( 0 , j ) . toLowerCase ( ) ] = x [ i ] . substring ( j + 1 ) ; } }
return r ;
}
2018-03-20 20:48:03 -04:00
// Remove a element from a array
function removeItemFromArray ( array , element ) {
2018-12-29 18:24:33 -05:00
var index = array . indexOf ( element ) ;
2018-03-20 20:48:03 -04:00
if ( index !== - 1 ) { array . splice ( index , 1 ) ; }
}
2018-04-03 20:07:48 -04:00
// Run MeshCmd, but before we do, we need to see if what type of service we are going to be
2019-10-25 02:58:39 -04:00
var serviceName = null , serviceDisplayName = null , serviceDesc = null ;
2018-04-04 15:08:28 -04:00
for ( var i in process . argv ) {
2019-10-25 02:58:39 -04:00
if ( process . argv [ i ] . toLowerCase ( ) == 'install' ) { process . argv [ i ] = '-install' ; }
if ( process . argv [ i ] . toLowerCase ( ) == 'uninstall' ) { process . argv [ i ] = '-uninstall' ; }
if ( ( process . argv [ i ] . toLowerCase ( ) == 'microlms' ) || ( process . argv [ i ] . toLowerCase ( ) == 'amtlms' ) || ( process . argv [ i ] . toLowerCase ( ) == 'lms' ) ) {
serviceName = 'MicroLMS' ;
2019-10-28 21:25:35 -04:00
serviceDisplayName = "MicroLMS Service for Intel(R) AMT" ;
serviceDesc = "Intel AMT Micro Local Manageability Service (MicroLMS)" ;
2019-10-25 02:58:39 -04:00
} else if ( ( process . argv [ i ] . toLowerCase ( ) == 'intellms' ) ) {
serviceName = 'LMS' ;
2019-10-28 21:25:35 -04:00
serviceDisplayName = "Intel(R) Management and Security Application Local Management Service" ;
serviceDesc = "Intel(R) Management and Security Application Local Management Service - Provides OS-related Intel(R) ME functionality." ;
2019-10-25 02:58:39 -04:00
} else if ( ( process . argv [ i ] . toLowerCase ( ) == 'meshcommander' ) || ( process . argv [ i ] . toLowerCase ( ) == 'commander' ) ) {
serviceName = 'MeshCommander' ;
2019-10-28 21:25:35 -04:00
serviceDisplayName = "MeshCommander, Intel AMT Management console" ;
serviceDesc = "MeshCommander is a Intel AMT management console." ;
2019-10-25 02:58:39 -04:00
}
2018-04-03 20:07:48 -04:00
}
2018-04-04 15:08:28 -04:00
if ( serviceName == null ) {
if ( process . execPath . includes ( 'MicroLMS' ) ) { serviceName = 'MicroLMS' ; }
2019-10-25 02:58:39 -04:00
else if ( process . execPath . includes ( 'LMS' ) ) { serviceName = 'LMS' ; }
2018-04-04 15:08:28 -04:00
else if ( process . execPath . includes ( 'MeshCommander' ) ) { serviceName = 'MeshCommander' ; }
2019-10-25 02:58:39 -04:00
if ( serviceName == null ) { for ( var i in process . argv ) { if ( ( process . argv [ i ] . toLowerCase ( ) == '-install' ) || ( process . argv [ i ] . toLowerCase ( ) == '-uninstall' ) ) { console . log ( 'In order to install/uninstall, a service type must be specified.' ) ; process . exit ( ) ; } } }
2019-10-28 21:25:35 -04:00
if ( serviceName == null ) { try { run ( process . argv ) ; } catch ( e ) { console . log ( "ERROR: " + e ) ; } }
} else {
var serviceHost = require ( 'service-host' ) ;
var meshcmdService = new serviceHost ( { name : serviceName , displayName : serviceDisplayName , startType : 'AUTO_START' , description : serviceDesc } ) ;
// Called when the background service is started.
meshcmdService . on ( 'serviceStart' , function onStart ( ) {
//process.coreDumpLocation = 'C:\\tmp\\meshcommander.dmp';
//process.on('exit', function () { console.log('exit3'); _debugCrash(); });
console . setDestination ( console . Destinations . DISABLED ) ; // Disable console.log().
//console.setDestination(console.Destinations.LOGFILE);
//attachDebuger({ webport: 0, wait: 1 }).then(console.log, console.log);
if ( process . execPath . includes ( 'MicroLMS' ) ) { run ( [ process . execPath , 'microlms' ] ) ; } // Start MicroLMS
else if ( process . execPath . includes ( 'LMS' ) ) { run ( [ process . execPath , 'microlms' ] ) ; } // Start MicroLMS
else if ( process . execPath . includes ( 'MeshCommander' ) ) { run ( [ process . execPath , 'meshcommander' ] ) ; } // Start MeshCommander
else { console . log ( "Aborting Service Start, because unknown binary: " + process . execPath ) ; process . exit ( 1 ) ; }
} ) ;
2018-04-03 20:07:48 -04:00
2019-10-28 21:25:35 -04:00
// Called when the background service is stopping
meshcmdService . on ( 'serviceStop' , function onStop ( ) { console . log ( "Stopping service" ) ; process . exit ( ) ; } ) ; // The console.log() is for debugging, will be ignored unless "console.setDestination()" is set.
2019-10-25 02:58:39 -04:00
2019-10-28 21:25:35 -04:00
// Called when the executable is not running as a service, run normally.
meshcmdService . on ( 'normalStart' , function onNormalStart ( ) { try { run ( process . argv ) ; } catch ( e ) { console . log ( "ERROR: " + e ) ; } } ) ;
meshcmdService . run ( ) ;
2020-04-09 15:22:15 -04:00
}