MeshCentral/public/scripts/amt-redir-ws-0.1.0-min.js

1 line
5.9 KiB
JavaScript
Raw Normal View History

2022-10-27 14:13:23 -04:00
var CreateAmtRedirect=function(e,o){var y={};function x(e){return String.fromCharCode.apply(null,e)}return((y.m=e).parent=y).authCookie=o,y.State=0,y.socket=null,y.host=null,y.port=0,y.user=null,y.pass=null,y.authuri="/RedirectionService",y.tlsv1only=0,y.inDataCount=0,y.connectstate=0,y.protocol=e.protocol,y.acc=null,y.amtsequence=1,y.amtkeepalivetimer=null,y.onStateChanged=null,y.Start=function(e,t,n,r,a){y.host=e,y.port=t,y.user=n,y.pass=r,y.connectstate=0,y.inDataCount=0;e=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/webrelay.ashx?p=2&host="+e+"&port="+t+"&tls="+a+("*"==n?"&serverauth=1":"")+(void 0===r?"&serverauth=1&user="+n:"");null!=o&&""!=o&&(e+="&auth="+o),y.socket=new WebSocket(e),y.socket.binaryType="arraybuffer",y.socket.onopen=y.xxOnSocketConnected,y.socket.onmessage=y.xxOnMessage,y.socket.onclose=y.xxOnSocketClosed,y.xxStateChange(1)},y.xxOnSocketConnected=function(){y.xxStateChange(2),1==y.protocol&&y.directSend(new Uint8Array([16,0,0,0,83,79,76,32])),2==y.protocol&&y.directSend(new Uint8Array([16,1,0,0,75,86,77,82])),3==y.protocol&&y.directSend(new Uint8Array([16,0,0,0,73,68,69,82]))},y.xxOnMessage=function(e){if(e.data&&-1!=y.connectstate){if(y.inDataCount++,1==y.connectstate&&(2==y.protocol||3==y.protocol))return y.m.ProcessBinaryData?y.m.ProcessBinaryData(e.data):y.m.ProcessData(x(e.data));var t;for(null==y.acc?y.acc=e.data:((t=new Uint8Array(y.acc.byteLength+e.data.byteLength)).set(new Uint8Array(y.acc),0),t.set(new Uint8Array(e.data),y.acc.byteLength),y.acc=t.buffer);null!=y.acc&&1<=y.acc.byteLength;){var n=0,r=new Uint8Array(y.acc);switch(r[0]){case 17:if(r.byteLength<4)return;var a=r[1];if(0===a){if(r.byteLength<13)return;a=r[12];if(r.byteLength<13+a)return;y.directSend(new Uint8Array([19,0,0,0,0,0,0,0,0])),n=13+a}else y.Stop(1);break;case 20:if(r.byteLength<9)return;var o=new DataView(y.acc).getUint32(5,!0);if(r.byteLength<9+o)return;var a=r[1],c=r[4],s=[];for(i=0;i<o;i++)s.push(r[9+i]);var l=new Uint8Array(y.acc.slice(9,9+o)),n=9+o;if(0==c)0<=s.indexOf(4)?y.xxSend(String.fromCharCode(19,0,0,0,4)+IntToStrX(y.user.length+y.authuri.length+8)+String.fromCharCode(y.user.length)+y.user+String.fromCharCode(0,0)+String.fromCharCode(y.authuri.length)+y.authuri+String.fromCharCode(0,0,0,0)):y.Stop(2);else if(3!=c&&4!=c||1!=a)if(0==a)switch(y.protocol){case 1:y.xxSend(String.fromCharCode(32,0,0,0)+IntToStrX(y.amtsequence++)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+IntToStrX(0));break;case 2:y.directSend(new Uint8Array([64,0,0,0,0,0,0,0]));break;case 3:y.connectstate=1,y.xxStateChange(3)}else y.Stop(3);else{var h=0,u=l[0],S=x(new Uint8Array(l.buffer.slice(1,1+u))),u=l[h+=u+1],d=x(new Uint8Array(l.buffer.slice(h+1,h+1+u))),u=(h+=u+1,null),f=function(e){for(var t="",n=0;n<e;n++)t+="abcdef0123456789".charAt(Math.floor(16*Math.random()));return t}(32),g="00000002",C="",l=(4==c&&(m=l[h],u=x(new Uint8Array(l.buffer.slice(h+1,h+1+m))),C=g+":"+f+":"+u+":"),hex_md5(hex_md5(y.user+":"+S+":"+y.pass)+":"+d+":"+C+hex_md5("POST:"+y.authuri))),h=y.user.length+S.length+d.length+y.authuri.length+f.length+g.length+l.length+7,m=(4==c&&(h+=u.length+1),String.fromCharCode(19,0,0,0,c)+IntToStrX(h)+String.fromCharCode(y.user.length)+y.user+String.fromCharCode(S.length)+S+String.fromCharCode(d.length)+d+String.fromCharCode(y.authuri.length)+y.authuri+String.fromCharCode(f.length)+f+String.fromCharCode(g.length)+g+String.fromCharCode(l.length)+l);4==c&&(m+=String.fromCharCode(u.length)+u),y.xxSend(m)}break;case 33:r.byteLength<23||(n=23,y.xxSend(String.fromCharCode(39,0,0,0)+IntToStrX(y.amtsequence++)+String.fromCharCode(0,0,27,0,0,0)),1==y.protocol&&(y.amtkeepalivetimer=setInterval(y.xxSendAmtKeepAlive,2e3)),y.connectstate=1,y.xxStateChange(3));break;case 41:r.byteLength<10||(n=10);break;case 42:r.byteLength<10||(C=10+(r[9]<<8)+r[8],r.byteLength<C)||(y.m.ProcessBinaryData?y.m.ProcessBinaryData(new Uint8Array(r.buffer.slice(10,C))):y.m.ProcessData(x(new Uint8Array(r.bu