MeshCentral/agents/modules_meshcore_min/amt-manage.min.js

1 line
16 KiB
JavaScript
Raw Normal View History

2019-06-14 19:34:36 -04:00
function AmtManager(d,q,v){var L=function(R){d.SendCommand({action:"msg",type:"console",value:R})};var r=function(R){if(v){L("amt-manager: "+R+"<br />")}};var h=null,i=0;var f=null,g=0;var e=null;var H=null;var G=null;var k=null;var F=this;var E;F.state=0;F.lmsstate=0;F.onStateChange=null;F.setDebug=function(R){v=R};F.setPolicy=function(R){if(JSON.stringify(k)!=JSON.stringify(R)){k=R;if(m==null){F.applyPolicy()}}};var K=0;F.reset=function(){++K;h=null,i=0,f=null,g=0,F.state=0,F.lmsstate=0;try{var R=require("amt-mei");h=new R();h.on("error",function(T){r("MEI error");h=null;i=-1;F.state=-1;F.onStateChange(i)});h.getVersion(function(T){if(T==null){i=-1;F.state=-1;if(F.onStateChange!=null){F.onStateChange(i)}if(K<10){setTimeout(F.reset,10000)}}else{e=T;i=2;F.state=2;K=0;if(F.onStateChange!=null){F.onStateChange(i)}F.lmsreset()}})}catch(S){r("MEI exception: "+S);h=null;i=-1;F.state=-1}};var j=null;F.getAmtInfo=function(S){if((h==null)||(i<2)){if(S!=null){S(null)}return}try{j={Flags:0};h.getProtocolVersion(function(T){if(T!=null){j.MeiVersion=T}});h.getVersion(function(T){if(T){j.Versions={};for(var U in T.Versions){j.Versions[T.Versions[U].Description]=T.Versions[U].Version}}});h.getProvisioningMode(function(T){if(T){j.ProvisioningMode=T.mode}});h.getProvisioningState(function(T){if(T){j.ProvisioningState=T.state}});h.getEHBCState(function(T){if((T!=null)&&(T.EHBC==true)){j.Flags+=1}});h.getControlMode(function(T){if(T!=null){if(T.controlMode==1){j.Flags+=2}if(T.controlMode==2){j.Flags+=4}}});h.getLanInterfaceSettings(0,function(T){if(T){j.net0=T}});h.getLanInterfaceSettings(1,function(T){if(T){j.net1=T}});h.getUuid(function(T){if((T!=null)&&(T.uuid!=null)){j.UUID=T.uuid}});h.getDnsSuffix(function(T){if(T!=null){j.DNS=T}if(S!=null){S(j)}})}catch(R){if(S!=null){S(null)}return}};var t=function(U){if((U==null)||(U.Body==null)||(U.Body.MessageID==null)||(U.Body.MessageArguments==null)){return null}var R=U.Body.MessageID,S=U.Body.MessageArguments[0],T=null;switch(R){case"iAMT0050":if(S=="48"){T="Intel&reg; AMT Serial-over-LAN connected"}else{if(S=="49"){T="Intel&reg; AMT Serial-over-LAN disconnected"}}break;case"iAMT0052":if(S=="1"){T="Intel&reg; AMT KVM connected"}else{if(S=="2"){T="Intel&reg; AMT KVM disconnected"}}break;default:break}if(T!=null){d.SendCommand({action:"msg",type:"notify",value:T,tag:"general"})}};F.lmsreset=function(){var R=null,S=0;F.lmsstate=0;try{var U=require("amt-lme");S=1;F.lmsstate=1;R=new U();R.on("error",function(V){S=0;F.lmsstate=0;R=null;r("LMS error");M(1)});R.on("connect",function(){S=2;F.lmsstate=2;r("LMS connected");M(2)});R.on("notify",function(W,X,Y,V){if(V=="iAMT0052-3"){y()}else{t(W)}})}catch(T){S=-1;F.lmsstate=-1;R=null}};var M=function(R){if((h==null)||(i<2)||(e==null)){return}h.getLocalSystemAccount(function(Y){if(Y==null){return}var W=require("amt-wsman-duk");var X=require("amt-wsman");var S=require("amt");H=new X(W,"127.0.0.1",16992,Y.user,Y.pass,false);G=new S(H);i=3;F.state=3;if(F.onStateChange!=null){F.onStateChange(i)}if(m==null){F.applyPolicy()}var T=null;try{for(var V in e.Versions){if(e.Versions[V].Description=="AMT"){T=parseInt(e.Versions[V].Version.split(".")[0])}}}catch(U){}if((T!=null)&&(T>=12)){y("skip");F.kvmTempTimer=setInterval(function(){y()},2000);A(JSON.stringify({action:"restart",ver:1}))}})};var y=function(R){G.IPS_KVMRedirectionSettingData_DataChannelRead(F.kvmDataGetResponse,R)};var x=function(U,S,T,V,W){if((W!="skip")&&(V==200)&&(T.Body.ReturnValue==0)){var X=null;try{X=Buffer.from(T.Body.DataMessage,"base64").toString()}catch(R){return}if(X!=null){F.kvmProcessData(T.Body.RealmsBitmap,T.Body.MessageId,X)}}};var O=null;var z=function(U,T,W){var R=null;try{R=JSON.parse(W)}catch(S){}if((R!=null)&&(R.action)){if(R.action=="present"){A(JSON.stringify({action:"present",ver:1,platform:process.platform}))}if(R.action=="offer"){O={};var V=require("ILibWebRTC");O.webrtc=V.createConnection();O.webrtc.on("connected",function(){});O.webrtc.on("disconnected",function(){F.webRtcCleanUp()});O.webrtc.on("dataChannel",function(X){O.rtcchannel=X;O.kvm=mesh.getRemoteDesktopStream();O