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

1 line
9.2 KiB
JavaScript

var Q=require("queue");function amt_heci(){var d=require("events").inherits(this);d.createEvent("error");var u=require("heci");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 E(G){if(this.Parent._rq.isEmpty()){this.Parent.emit("error",G)}else{var I=this.Parent._rq.deQueue();var H=I.optional;var F=I.func;H.unshift({Status:-1});F.apply(this.Parent,H);if(!this.Parent._rq.isEmpty()){this.connect(u.GUIDS.AMT,{noPipeline:1})}}});this._amt.on("connect",function D(){this.on("data",function F(H){var I=this.Parent.getCommand(H);var K=this.Parent._rq.deQueue();var J=K.optional;var G=K.func;J.unshift(I);G.apply(this.Parent,J);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 A(D){var E=D.indexOf("\0");if(E>=0){return D.substring(0,E)}else{return D}}this.getCommand=function g(D){var E=D.length==0?(this._rq.peekQueue().cmd|8388608):D.readUInt32LE(4);var F={IsResponse:(E&8388608)==8388608?true:false,Command:(E&8388607),Status:D.length!=0?D.readUInt32LE(12):-1,Data:D.length!=0?D.slice(16):null};return(F)};this.sendCommand=function x(){if(arguments.length<3||typeof(arguments[0])!="number"||typeof(arguments[1])!="object"||typeof(arguments[2])!="function"){throw ("invalid parameters")}var D=[];for(var F=3;F<arguments.length;++F){D.push(arguments[F])}var E=Buffer.from("010100000000000000000000","hex");E.writeUInt32LE(arguments[0]|67108864,4);E.writeUInt32LE(arguments[1]==null?0:arguments[1].length,8);this._rq.enQueue({cmd:arguments[0],func:arguments[2],optional:D,send:(arguments[1]==null?E:Buffer.concat([E,arguments[1]]))});if(!this._amt){this._setupPTHI();this._amt.connect(u.GUIDS.AMT,{noPipeline:1})}};this.getVersion=function t(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(26,null,function(I,H,K){if(I.Status==0){var J,G=I.Data,M={BiosVersion:G.slice(0,this._amt.BiosVersionLen).toString(),Versions:[]},L=G.slice(this._amt.BiosVersionLen+4);for(J=0;J<G.readUInt32LE(this._amt.BiosVersionLen);++J){M.Versions[J]={Description:L.slice(2,L.readUInt16LE(0)+2).toString(),Version:L.slice(4+this._amt.UnicodeStringLen,4+this._amt.UnicodeStringLen+L.readUInt16LE(2+this._amt.UnicodeStringLen)).toString()};L=L.slice(4+(2*this._amt.UnicodeStringLen))}if(M.BiosVersion.indexOf("\0")>0){M.BiosVersion=M.BiosVersion.substring(0,M.BiosVersion.indexOf("\0"))}K.unshift(M)}else{K.unshift(null)}H.apply(this,K)},D,F)};function C(F,E){if((E==null)&&(typeof(E)!="number")){return null}if(F==null){F=""}var G="";for(var D=0;D<E-F.length;D++){G+="0"}return G+F}this.getUuid=function s(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(92,null,function(H,G,I){if(H.Status==0){var J={};J.uuid=[C(H.Data.readUInt32LE(0).toString(16),8),C(H.Data.readUInt16LE(4).toString(16),4),C(H.Data.readUInt16LE(6).toString(16),4),C(H.Data.readUInt16BE(8).toString(16),4),C(H.Data.slice(10).toString("hex").toLowerCase(),12)].join("-");I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getProvisioningState=function q(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(17,null,function(H,G,I){if(H.Status==0){var J={};J.state=H.Data.readUInt32LE(0);if(J.state<3){J.stateStr=["PRE","IN","POST"][J.state]}I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getProvisioningMode=function p(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(8,null,function(H,G,I){if(H.Status==0){var J={};J.mode=H.Data.readUInt32LE(0);if(J.mode<4){J.modeStr=["NONE","ENTERPRISE","SMALL_BUSINESS","REMOTE_ASSISTANCE"][J.mode]}J.legacy=H.Data.readUInt32LE(4)==0?false:true;I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getEHBCState=function j(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(132,null,function(H,G,I){if(H.Status==0){I.unshift({EHBC:H.Data.readUInt32LE(0)!=0})}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getControlMode=function h(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(107,null,function(H,G,I){if(H.Status==0){var J={};J.controlMode=H.Data.readUInt32LE(0);if(J.controlMode<3){J.controlModeStr=["NONE_RPAT","CLIENT","ADMIN","REMOTE_ASSISTANCE"][J.controlMode]}I.unshift(J)}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getMACAddresses=function n(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(37,null,function(H,G,I){if(H.Status==0){I.unshift({DedicatedMAC:H.Data.slice(0,6).toString("hex:"),HostMAC:H.Data.slice(6,12).toString("hex:")})}else{I.unshift({DedicatedMAC:null,HostMAC:null})}G.apply(this,I)},D,F)};this.getDnsSuffix=function i(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(54,null,function(H,G,I){if(H.Status==0){var J=H.Data.readUInt16LE(0);if(J>0){I.unshift(H.Data.slice(2,2+J).toString())}else{I.unshift(null)}}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getHashHandles=function k(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(44,null,function(H,G,J){var K=[];if(H.Status==0){var L=H.Data.readUInt32LE(0);for(var I=0;I<L;++I){K.push(H.Data.readUInt32LE(4+(4*I)))}}J.unshift(K);G.apply(this,J)},D,F)};this.getCertHashEntry=function f(F,D){var H=[];for(var G=2;G<arguments.length;++G){H.push(arguments[G])}var E=Buffer.alloc(4);E.writeUInt32LE(F,0);this.sendCommand(45,E,function(J,I,K){if(J.Status==0){var L={};L.isDefault=J.Data.readUInt32LE(0);L.isActive=J.Data.readUInt32LE(4);L.hashAlgorithm=J.Data.readUInt8(72);if(L.hashAlgorithm<4){L.hashAlgorithmStr=["MD5","SHA1","SHA256","SHA512"][L.hashAlgorithm];L.hashAlgorithmSize=[16,20,32,64][L.hashAlgorithm];L.certificateHash=J.Data.slice(8,8+L.hashAlgorithmSize).toString("hex")}L.name=J.Data.slice(73+2,73+2+J.Data.readUInt16LE(73)).toString();K.unshift(L)}else{K.unshift(null)}I.apply(this,K)},D,H)};this.getCertHashEntries=function e(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.getHashHandles(function(I,H,J){var G=[];this.getCertHashEntry(I.shift(),this._getHashEntrySink,H,J,G,I)},D,F)};this._getHashEntrySink=function a(H,E,G,D,F){D.push(H);if(F.length>0){this.getCertHashEntry(F.shift(),this._getHashEntrySink,E,G,D,F)}else{G.unshift(D);E.apply(this,G)}};this.getLocalSystemAccount=function m(D){var F=[];for(var E=1;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(103,Buffer.alloc(40),function(H,G,I){if(H.Status==0&&H.Data.length==68){I.unshift({user:A(H.Data.slice(0,33).toString()),pass:A(H.Data.slice(33,67).toString()),raw:H.Data})}else{I.unshift(null)}G.apply(this,I)},D,F)};this.getLanInterfaceSettings=function l(G,D){var I=[];for(var E=2;E<arguments.length;++E){I.push(arguments[E])}var F=Buffer.alloc(4);F.writeUInt32LE(G);this.sendCommand(72,F,function H(L,K,N){if(L.Status==0){var M={};M.enabled=L.Data.readUInt32LE(0);M.dhcpEnabled=L.Data.readUInt32LE(8);switch(L.Data[12]){case 1:M.dhcpMode="ACTIVE";break;case 2:M.dhcpMode="PASSIVE";break;default:M.dhcpMode="UNKNOWN";break}M.mac=L.Data.slice(14).toString("hex:");var J=L.Data.readUInt32LE(4);M.address=((J>>24)&255)+"."+((J>>16)&255)+"."+((J>>8)&255)+"."+(J&255);N.unshift(M);K.apply(this,N)}else{N.unshift(null);K.apply(this,N)}},D,I)};this.unprovision=function B(G,D){var H=[];for(var F=2;F<arguments.length;++F){H.push(arguments[F])}var E=Buffer.alloc(4);E.writeUInt32LE(G,0);this.sendCommand(16,E,function(J,I,K){K.unshift(J.Status);I.apply(this,K)},D,H)};this.startConfiguration=function y(){var E=[];for(var D=2;D<arguments.length;++D){E.push(arguments[D])}this.sendCommand(41,data,function(G,F,H){H.unshift(G.Status);F.apply(this,H)},callback,E)};this.stopConfiguration=function z(){var E=[];for(var D=2;D<arguments.length;++D){E.push(arguments[D])}this.sendCommand(94,data,function(G,F,H){H.unshift(G.Status);F.apply(this,H)},callback,E)};this.openUserInitiatedConnection=function w(){var E=[];for(var D=2;D<arguments.length;++D){E.push(arguments[D])}this.sendCommand(68,data,function(G,F,H){H.unshift(G.Status);F.apply(this,H)},callback,E)};this.closeUserInitiatedConnection=function c(){var E=[];for(var D=2;D<arguments.length;++D){E.push(arguments[D])}this.sendCommand(69,data,function(G,F,H){H.unshift(G.Status);F.apply(this,H)},callback,E)};this.getRemoteAccessConnectionStatus=function r(){var E=[];for(var D=2;D<arguments.length;++D){E.push(arguments[D])}this.sendCommand(70,data,function(G,F,I){if(G.Status==0){var H=v.slice(14,G.Data.readUInt16LE(12)+14).toString();I.unshift({status:G.Status,networkStatus:G.Data.readUInt32LE(0),remoteAccessStatus:G.Data.readUInt32LE(4),remoteAccessTrigger:G.Data.readUInt32LE(8),mpsHostname:H,raw:G.Data})}else{I.unshift({status:G.Status})}F.apply(this,I)},callback,E)};this.getProtocolVersion=function o(D){var F=[];for(var E=1;E<arguments.length;++E){opt.push(arguments[E])}u.doIoctl(u.IOCTL.HECI_VERSION,Buffer.alloc(5),Buffer.alloc(5),function(L,G,K,H,I){if(L==0){var J=G.readUInt8(0).toString()+"."+G.readUInt8(1).toString()+"."+G.readUInt8(2).toString()+"."+G.readUInt16BE(3).toString();I.unshift(J);H.apply(K,I)}else{I.unshift(null);H.apply(K,I)}},this,D,F)}}module.exports=amt_heci;