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

1 line
9.3 KiB
JavaScript
Raw Normal View History

2019-09-24 02:47:08 +03:00
var Q=require("queue");function amt_heci(){var d=require("events").inherits(this);d.createEvent("error");var u=require("heci");var y=function(F){try{require("MeshAgent").SendCommand({action:"msg",type:"console",value:F})}catch(E){}};this._ObjectID="pthi";this._rq=new Q();this._setupPTHI=function b(){this._amt=u.create();this._amt.BiosVersionLen=65;this._amt.UnicodeStringLen=20;this._amt.Parent=this;this._amt.on("error",function F(H){if(this.Parent._rq.isEmpty()){this.Parent.emit("error",H)}else{var J=this.Parent._rq.deQueue();var I=J.optional;var G=J.func;I.unshift({Status:-1});G.apply(this.Parent,I);if(!this.Parent._rq.isEmpty()){this.connect(u.GUIDS.AMT,{noPipeline:1})}}});this._amt.on("connect",function E(){this.on("data",function G(I){var J=this.Parent.getCommand(I);var L=this.Parent._rq.deQueue();var K=L.optional;var H=L.func;K.unshift(J);H.apply(this.Parent,K);if(this.Parent._rq.isEmpty()){this.Parent._amt.disconnect();this.Parent._amt=null}else{this.write(this.Parent._rq.peekQueue().send)}});this.write(this.Parent._rq.peekQueue().send)})};function B(E){var F=E.indexOf("\0");if(F>=0){return E.substring(0,F)}else{return E}}this.getCommand=function g(E){var F=E.length==0?(this._rq.peekQueue().cmd|8388608):E.readUInt32LE(4);var G={IsResponse:(F&8388608)==8388608?true:false,Command:(F&8388607),Status:E.length!=0?E.readUInt32LE(12):-1,Data:E.length!=0?E.slice(16):null};return(G)};this.sendCommand=function x(){if(arguments.length<3||typeof(arguments[0])!="number"||typeof(arguments[1])!="object"||typeof(arguments[2])!="function"){throw ("invalid parameters")}var E=[];for(var G=3;G<arguments.length;++G){E.push(arguments[G])}var F=Buffer.from("010100000000000000000000","hex");F.writeUInt32LE(arguments[0]|67108864,4);F.writeUInt32LE(arguments[1]==null?0:arguments[1].length,8);this._rq.enQueue({cmd:arguments[0],func:arguments[2],optional:E,send:(arguments[1]==null?F:Buffer.concat([F,arguments[1]]))});if(!this._amt){this._setupPTHI();this._amt.connect(u.GUIDS.AMT,{noPipeline:1})}};this.getVersion=function t(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(26,null,function(J,I,L){if(J.Status==0){var K,H=J.Data,N={BiosVersion:H.slice(0,this._amt.BiosVersionLen).toString(),Versions:[]},M=H.slice(this._amt.BiosVersionLen+4);for(K=0;K<H.readUInt32LE(this._amt.BiosVersionLen);++K){N.Versions[K]={Description:M.slice(2,M.readUInt16LE(0)+2).toString(),Version:M.slice(4+this._amt.UnicodeStringLen,4+this._amt.UnicodeStringLen+M.readUInt16LE(2+this._amt.UnicodeStringLen)).toString()};M=M.slice(4+(2*this._amt.UnicodeStringLen))}if(N.BiosVersion.indexOf("\0")>0){N.BiosVersion=N.BiosVersion.substring(0,N.BiosVersion.indexOf("\0"))}L.unshift(N)}else{L.unshift(null)}I.apply(this,L)},E,G)};function D(G,F){if((F==null)&&(typeof(F)!="number")){return null}if(G==null){G=""}var H="";for(var E=0;E<F-G.length;E++){H+="0"}return H+G}this.getUuid=function s(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(92,null,function(I,H,J){if(I.Status==0){var K={};K.uuid=[D(I.Data.readUInt32LE(0).toString(16),8),D(I.Data.readUInt16LE(4).toString(16),4),D(I.Data.readUInt16LE(6).toString(16),4),D(I.Data.readUInt16BE(8).toString(16),4),D(I.Data.slice(10).toString("hex").toLowerCase(),12)].join("-");J.unshift(K)}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getProvisioningState=function q(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(17,null,function(I,H,J){if(I.Status==0){var K={};K.state=I.Data.readUInt32LE(0);if(K.state<3){K.stateStr=["PRE","IN","POST"][K.state]}J.unshift(K)}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getProvisioningMode=function p(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(8,null,function(I,H,J){if(I.Status==0){var K={};K.mode=I.Data.readUInt32LE(0);if(K.mode<4){K.modeStr=["NONE","ENTERPRISE","SMALL_BUSINESS","REMOTE_ASSISTANCE"][K.mode]}K.legacy=I.Data.readUInt32LE(4)==0?false:true;J.unshift(K)}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getEHBCState=function j(E){var G=[];for(