mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-27 15:45:53 -05:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
|
function AmtManager(c,m,r){var E=function(K){c.SendCommand({action:"msg",type:"console",value:K})};var n=function(K){if(r){E("amt-manager: "+K)}};var g=null,h=0;var e=null,f=0;var d=null;var B=null;var A=null;var j=null;var z=this;z.state=0;z.lmsstate=0;z.onStateChange=null;z.setDebug=function(K){r=K};z.setPolicy=function(K){if(JSON.stringify(j)!=JSON.stringify(K)){j=K;z.applyPolicy()}};var D=0;z.reset=function(){++D;g=null,h=0,e=null,f=0,z.state=0,z.lmsstate=0;try{var K=require("amt-mei");g=new K();g.on("error",function(M){n("MEI error");g=null;h=-1;z.state=-1;z.onStateChange(h)});g.getVersion(function(M){if(M==null){h=-1;z.state=-1;if(z.onStateChange!=null){z.onStateChange(h)}if(D<10){setTimeout(z.reset,10000)}}else{d=M;h=2;z.state=2;D=0;if(z.onStateChange!=null){z.onStateChange(h)}z.lmsreset()}})}catch(L){n("MEI exception: "+L);g=null;h=-1;z.state=-1}};var i=null;z.getAmtInfo=function(L){if((g==null)||(h<2)){if(L!=null){L(null)}return}try{i={Flags:0};g.getProtocolVersion(function(M){if(M!=null){i.MeiVersion=M}});g.getVersion(function(M){if(M){i.Versions={};for(var N in M.Versions){i.Versions[M.Versions[N].Description]=M.Versions[N].Version}}});g.getProvisioningMode(function(M){if(M){i.ProvisioningMode=M.mode}});g.getProvisioningState(function(M){if(M){i.ProvisioningState=M.state}});g.getEHBCState(function(M){if((M!=null)&&(M.EHBC==true)){i.Flags+=1}});g.getControlMode(function(M){if(M!=null){if(M.controlMode==1){i.Flags+=2}if(M.controlMode==2){i.Flags+=4}}});g.getLanInterfaceSettings(0,function(M){if(M){i.net0=M}});g.getLanInterfaceSettings(1,function(M){if(M){i.net1=M}});g.getUuid(function(M){if((M!=null)&&(M.uuid!=null)){i.UUID=M.uuid}});g.getDnsSuffix(function(M){if(M!=null){i.dns=M}if(L!=null){L(i)}})}catch(K){if(L!=null){L(null)}return}};var p=function(N){if((N==null)||(N.Body==null)||(N.Body.MessageID==null)||(N.Body.MessageArguments==null)){return null}var K=N.Body.MessageID,L=N.Body.MessageArguments[0],M=null;switch(K){case"iAMT0050":if(L=="48"){M="Intel® AMT Serial-over-LAN connected"}else{if(L=="49"){M="Intel® AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(L=="1"){M="Intel® AMT KVM connected"}else{if(L=="2"){M="Intel® AMT KVM disconnected"}}break;default:break}if(M!=null){c.SendCommand({action:"msg",type:"notify",value:M,tag:"general"})}};z.lmsreset=function(){var K=null,L=0;z.lmsstate=0;try{var N=require("amt-lme");L=1;z.lmsstate=1;K=new N();K.on("error",function(O){L=0;z.lmsstate=0;K=null;n("LMS error");F(1)});K.on("connect",function(){L=2;z.lmsstate=2;n("LMS connected");F(2)});K.on("notify",function(P,Q,R,O){if(O=="iAMT0052-3"){u()}else{p(P)}})}catch(M){L=-1;z.lmsstate=-1;K=null}};var F=function(K){if((g==null)||(h<2)||(d==null)){return}g.getLocalSystemAccount(function(R){if(R==null){return}var P=require("amt-wsman-duk");var Q=require("amt-wsman");var L=require("amt");B=new Q(P,"127.0.0.1",16992,R.user,R.pass,false);A=new L(B);h=3;z.state=3;if(z.onStateChange!=null){z.onStateChange(h)}z.applyPolicy();var M=null;try{for(var O in d.Versions){if(d.Versions[O].Description=="AMT"){M=parseInt(d.Versions[O].Version.split(".")[0])}}}catch(N){}if((M!=null)&&(M>=12)){n("KVM data channel setup");u("skip");z.kvmTempTimer=setInterval(function(){u()},2000);w(JSON.stringify({action:"restart",ver:1}))}})};var u=function(K){A.IPS_KVMRedirectionSettingData_DataChannelRead(z.kvmDataGetResponse,K)};var t=function(N,L,M,O,P){if((P!="skip")&&(O==200)&&(M.Body.ReturnValue==0)){var Q=null;try{Q=Buffer.from(M.Body.DataMessage,"base64").toString()}catch(K){return}if(Q!=null){z.kvmProcessData(M.Body.RealmsBitmap,M.Body.MessageId,Q)}}};var H=null;var v=function(N,M,P){var K=null;try{K=JSON.parse(P)}catch(L){}if((K!=null)&&(K.action)){if(K.action=="present"){w(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(K.action=="offer"){H={};var O=require("ILibWebRTC");H.webrtc=O.createConnection();H.webrtc.on("connected",function(){});H.webrtc.on("disconnected",function(){z.webRtcCleanUp()});H.webrtc.on("dataChannel",function(Q){H.rtcchannel=Q;H.kvm=mesh.getRemoteDesktopStream();H.kvm.pipe(H.
|