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

1 line
15 KiB
JavaScript
Raw Normal View History

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