mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-23 22:13:14 +03:00
1 line
9.3 KiB
JavaScript
1 line
9.3 KiB
JavaScript
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(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(132,null,function(I,H,J){if(I.Status==0){J.unshift({EHBC:I.Data.readUInt32LE(0)!=0})}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getControlMode=function h(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(107,null,function(I,H,J){if(I.Status==0){var K={};K.controlMode=I.Data.readUInt32LE(0);if(K.controlMode<3){K.controlModeStr=["NONE_RPAT","CLIENT","ADMIN","REMOTE_ASSISTANCE"][K.controlMode]}J.unshift(K)}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getMACAddresses=function n(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(37,null,function(I,H,J){if(I.Status==0){J.unshift({DedicatedMAC:I.Data.slice(0,6).toString("hex:"),HostMAC:I.Data.slice(6,12).toString("hex:")})}else{J.unshift({DedicatedMAC:null,HostMAC:null})}H.apply(this,J)},E,G)};this.getDnsSuffix=function i(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(54,null,function(I,H,J){if(I.Status==0){var K=I.Data.readUInt16LE(0);if(K>0){J.unshift(I.Data.slice(2,2+K).toString())}else{J.unshift(null)}}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getHashHandles=function k(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(44,null,function(I,H,K){var L=[];if(I.Status==0){var M=I.Data.readUInt32LE(0);for(var J=0;J<M;++J){L.push(I.Data.readUInt32LE(4+(4*J)))}}K.unshift(L);H.apply(this,K)},E,G)};this.getCertHashEntry=function f(G,E){var I=[];for(var H=2;H<arguments.length;++H){I.push(arguments[H])}var F=Buffer.alloc(4);F.writeUInt32LE(G,0);this.sendCommand(45,F,function(K,J,L){if(K.Status==0){var M={};M.isDefault=K.Data.readUInt32LE(0);M.isActive=K.Data.readUInt32LE(4);M.hashAlgorithm=K.Data.readUInt8(72);if(M.hashAlgorithm<4){M.hashAlgorithmStr=["MD5","SHA1","SHA256","SHA512"][M.hashAlgorithm];M.hashAlgorithmSize=[16,20,32,64][M.hashAlgorithm];M.certificateHash=K.Data.slice(8,8+M.hashAlgorithmSize).toString("hex")}M.name=K.Data.slice(73+2,73+2+K.Data.readUInt16LE(73)).toString();L.unshift(M)}else{L.unshift(null)}J.apply(this,L)},E,I)};this.getCertHashEntries=function e(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.getHashHandles(function(J,I,K){var H=[];this.getCertHashEntry(J.shift(),this._getHashEntrySink,I,K,H,J)},E,G)};this._getHashEntrySink=function a(I,F,H,E,G){E.push(I);if(G.length>0){this.getCertHashEntry(G.shift(),this._getHashEntrySink,F,H,E,G)}else{H.unshift(E);F.apply(this,H)}};this.getLocalSystemAccount=function m(E){var G=[];for(var F=1;F<arguments.length;++F){G.push(arguments[F])}this.sendCommand(103,Buffer.alloc(40),function(I,H,J){if(I.Status==0&&I.Data.length==68){J.unshift({user:B(I.Data.slice(0,33).toString()),pass:B(I.Data.slice(33,67).toString()),raw:I.Data})}else{J.unshift(null)}H.apply(this,J)},E,G)};this.getLanInterfaceSettings=function l(H,E){var J=[];for(var F=2;F<arguments.length;++F){J.push(arguments[F])}var G=Buffer.alloc(4);G.writeUInt32LE(H);this.sendCommand(72,G,function I(M,L,O){if(M.Status==0){var N={};N.enabled=M.Data.readUInt32LE(0);N.dhcpEnabled=M.Data.readUInt32LE(8);switch(M.Data[12]){case 1:N.dhcpMode="ACTIVE";break;case 2:N.dhcpMode="PASSIVE";break;default:N.dhcpMode="UNKNOWN";break}N.mac=M.Data.slice(14).toString("hex:");var K=M.Data.readUInt32LE(4);N.address=((K>>24)&255)+"."+((K>>16)&255)+"."+((K>>8)&255)+"."+(K&255);O.unshift(N);L.apply(this,O)}else{O.unshift(null);L.apply(this,O)}},E,J)};this.unprovision=function C(H,E){var I=[];for(var G=2;G<arguments.length;++G){I.push(arguments[G])}var F=Buffer.alloc(4);F.writeUInt32LE(H,0);this.sendCommand(16,F,function(K,J,L){L.unshift(K.Status);J.apply(this,L)},E,I)};this.startConfiguration=function z(){var F=[];for(var E=2;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(41,data,function(H,G,I){I.unshift(H.Status);G.apply(this,I)},callback,F)};this.stopConfiguration=function A(){var F=[];for(var E=2;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(94,data,function(H,G,I){I.unshift(H.Status);G.apply(this,I)},callback,F)};this.openUserInitiatedConnection=function w(){var F=[];for(var E=2;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(68,data,function(H,G,I){I.unshift(H.Status);G.apply(this,I)},callback,F)};this.closeUserInitiatedConnection=function c(){var F=[];for(var E=2;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(69,data,function(H,G,I){I.unshift(H.Status);G.apply(this,I)},callback,F)};this.getRemoteAccessConnectionStatus=function r(){var F=[];for(var E=2;E<arguments.length;++E){F.push(arguments[E])}this.sendCommand(70,data,function(H,G,J){if(H.Status==0){var I=v.slice(14,H.Data.readUInt16LE(12)+14).toString();J.unshift({status:H.Status,networkStatus:H.Data.readUInt32LE(0),remoteAccessStatus:H.Data.readUInt32LE(4),remoteAccessTrigger:H.Data.readUInt32LE(8),mpsHostname:I,raw:H.Data})}else{J.unshift({status:H.Status})}G.apply(this,J)},callback,F)};this.getProtocolVersion=function o(E){var G=[];for(var F=1;F<arguments.length;++F){opt.push(arguments[F])}u.doIoctl(u.IOCTL.HECI_VERSION,Buffer.alloc(5),Buffer.alloc(5),function(M,H,L,I,J){if(M==0){var K=H.readUInt8(0).toString()+"."+H.readUInt8(1).toString()+"."+H.readUInt8(2).toString()+"."+H.readUInt16BE(3).toString();J.unshift(K);I.apply(L,J)}else{J.unshift(null);I.apply(L,J)}},this,E,G)}}module.exports=amt_heci; |