mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-26 23:42:32 +03:00
1 line
34 KiB
JavaScript
1 line
34 KiB
JavaScript
|
var MemoryStream=require("MemoryStream");var lme_id=0;var lme_port_offset=0;var xmlParser=require("amt-xml");var APF_DISCONNECT=1;var APF_SERVICE_REQUEST=5;var APF_SERVICE_ACCEPT=6;var APF_USERAUTH_REQUEST=50;var APF_USERAUTH_FAILURE=51;var APF_USERAUTH_SUCCESS=52;var APF_GLOBAL_REQUEST=80;var APF_REQUEST_SUCCESS=81;var APF_REQUEST_FAILURE=82;var APF_CHANNEL_OPEN=90;var APF_CHANNEL_OPEN_CONFIRMATION=91;var APF_CHANNEL_OPEN_FAILURE=92;var APF_CHANNEL_WINDOW_ADJUST=93;var APF_CHANNEL_DATA=94;var APF_CHANNEL_CLOSE=97;var APF_PROTOCOLVERSION=192;function lme_object(){this.ourId=++lme_id;this.amtId=-1;this.LME_CHANNEL_STATUS="LME_CS_FREE";this.txWindow=0;this.rxWindow=0;this.localPort=0;this.errorCount=0}function stream_bufferedWrite(){var a=require("events").inherits(this);this.buffer=[];this._readCheckImmediate=undefined;this._ObjectID="bufferedWriteStream";a.createEvent("close");a.createEvent("drain");a.createEvent("error");a.createEvent("finish");a.createEvent("pipe");a.createEvent("unpipe");a.createEvent("readable");this.isEmpty=function(){return(this.buffer.length==0)};this.isWaiting=function(){return(this._readCheckImmediate==undefined)};this.write=function(c){for(var b in arguments){if(typeof(arguments[b])=="function"){this.once("drain",arguments[b]);break}}var d=Buffer.alloc(c.length);c.copy(d);this.buffer.push({offset:0,data:d});this.emit("readable");return(this.buffer.length==0?true:false)};this.read=function(){var f=arguments.length==0?undefined:arguments[0];var b=0;var d=[];while((f==undefined||b<f)&&this.buffer.length>0){var c=this.buffer[0].data.length-this.buffer[0].offset;var e=this.buffer[0].offset;if(c>(f-b)){d.push(this.buffer[0].data.slice(e,e+f-b));this.buffer[0].offset+=(f-b);b+=(f-b)}else{d.push(this.buffer[0].data.slice(e));b+=c;this.buffer.shift()}}this._readCheckImmediate=setImmediate(function(g){g._readCheckImmediate=undefined;if(g.buffer.length==0){g.emit("drain")}else{g.emit("readable")}},this);return(Buffer.concat(d))}}function lme_heci(c){var a=require("events").inherits(this);a.createEvent("error");a.createEvent("connect");a.createEvent("notify");a.createEvent("bind");if((c!=null)&&(c.debug==true)){lme_port_offset=-100}var b=require("heci");this.INITIAL_RXWINDOW_SIZE=4096;this._ObjectID="lme";this._LME=b.create();this._LME._binded={};this._LME.LMS=this;this._LME.on("error",function(d){this.LMS.emit("error",d)});this._LME.on("connect",function(){this.on("data",function(k){var l=k.readUInt8(0);switch(l){default:console.log("Unhandled LME Command "+l+", "+k.length+" byte(s).");break;case APF_SERVICE_REQUEST:var z=k.readUInt32BE(1);var y=k.slice(5,z+5);if(y=="pfwd@amt.intel.com"||y=="auth@amt.intel.com"){var F=Buffer.alloc(5+z);F.writeUInt8(6,0);F.writeUInt32BE(z,1);F.write(y.toString(),5);this.write(F)}else{}break;case APF_GLOBAL_REQUEST:var z=k.readUInt32BE(1);var y=k.slice(5,z+5).toString();switch(y){case"tcpip-forward":var v=k.readUInt32BE(z+6);var G=k.readUInt32BE(z+10+v);if(this[y]==undefined){this[y]={}}if(this[y][G]!=null){for(var s in this.sockets){var h=this.sockets[s];if(h.localPort==G){this.sockets[s].end();delete this.sockets[s]}}}if(this[y][G]==null){this[y][G]=require("net").createServer();this[y][G].HECI=this;if(lme_port_offset==0){this[y][G].listen({port:G,host:"127.0.0.1"})}else{this[y][G].listen({port:(G+lme_port_offset)})}this[y][G].on("connection",function(e){this.HECI.LMS.bindDuplexStream(e,e.remoteFamily,e.localPort-lme_port_offset)});this._binded[G]=true;this.LMS.emit("bind",this._binded)}var F=Buffer.alloc(5);F.writeUInt8(81,0);F.writeUInt32BE(G,1);this.write(F);break;case"cancel-tcpip-forward":var F=Buffer.alloc(1);F.writeUInt8(APF_REQUEST_SUCCESS,0);this.write(F);break;case"udp-send-to@amt.intel.com":var F=Buffer.alloc(1);F.writeUInt8(APF_REQUEST_FAILURE,0);this.write(F);break;default:break}break;case APF_CHANNEL_OPEN_CONFIRMATION:var I=k.readUInt32BE(1);var M=k.readUInt32BE(5);var N=k.readUInt32BE(9);if(this.sockets[I]!=undefined){this.sockets[I].lme.amtId=M;this.sockets[I].lme.rxWindow=N;this.sockets[I].lme.txWindow=N;this.sockets[I].lme.LME_CHANNEL_STATUS="LME_CS_CON
|