mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-30 09:03:20 -05:00
1 line
7.4 KiB
JavaScript
1 line
7.4 KiB
JavaScript
|
var CreateAmtRedirect=function(t,c){var O={};((O.m=t).parent=O).authCookie=c,O.State=0,O.socket=null,O.host=null,O.port=0,O.user=null,O.pass=null,O.authuri="/RedirectionService",O.tlsv1only=0,O.inDataCount=0,O.connectstate=0,O.protocol=t.protocol,O.debugmode=0,O.amtaccumulator="",O.amtsequence=1,O.amtkeepalivetimer=null,O.onStateChanged=null,O.Start=function(t,e,r,a,o){O.host=t,O.port=e,O.user=r,O.pass=a,O.connectstate=0,O.inDataCount=0;var n=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/webrelay.ashx?p=2&host="+t+"&port="+e+"&tls="+o+("*"==r?"&serverauth=1":"")+(void 0===a?"&serverauth=1&user="+r:"");null!=c&&""!=c&&(n+="&auth="+c),O.socket=new WebSocket(n),O.socket.onopen=O.xxOnSocketConnected,O.socket.onmessage=O.xxOnMessage,O.socket.onclose=O.xxOnSocketClosed,O.xxStateChange(1)},O.xxOnSocketConnected=function(){1==O.debugmode&&console.log("onSocketConnected"),O.xxStateChange(2),1==O.protocol&&O.xxSend(O.RedirectStartSol),2==O.protocol&&O.xxSend(O.RedirectStartKvm),3==O.protocol&&O.xxSend(O.RedirectStartIder)};var n=new FileReader,l=!1,u=[];return n.readAsBinaryString?n.onload=function(t){O.xxOnSocketData(t.target.result),0==u.length?l=!1:n.readAsBinaryString(new Blob([u.shift()]))}:n.readAsArrayBuffer&&(n.onloadend=function(t){O.xxOnSocketData(t.target.result),0==u.length?l=!1:n.readAsArrayBuffer(u.shift())}),O.xxOnMessage=function(t){if(O.inDataCount++,"object"==typeof t.data){if(1==l)return void u.push(t.data);if(n.readAsBinaryString)l=!0,n.readAsBinaryString(new Blob([t.data]));else if(n.readAsArrayBuffer)l=!0,n.readAsArrayBuffer(t.data);else{for(var e="",r=new Uint8Array(t.data),a=r.byteLength,o=0;o<a;o++)e+=String.fromCharCode(r[o]);O.xxOnSocketData(e)}}else O.xxOnSocketData(t.data)},O.xxOnSocketData=function(t){if(t&&-1!=O.connectstate){if("object"==typeof t){for(var e="",r=new Uint8Array(t),a=r.byteLength,o=0;o<a;o++)e+=String.fromCharCode(r[o]);t=e}else if("string"!=typeof t)return;if((2==O.protocol||3==O.protocol)&&1==O.connectstate)return O.m.ProcessData(t);for(O.amtaccumulator+=t;1<=O.amtaccumulator.length;){var n=0;switch(O.amtaccumulator.charCodeAt(0)){case 17:if(O.amtaccumulator.length<4)return;switch(O.amtaccumulator.charCodeAt(1)){case 0:if(O.amtaccumulator.length<13)return;var c=O.amtaccumulator.charCodeAt(12);if(O.amtaccumulator.length<13+c)return;O.xxSend(String.fromCharCode(19,0,0,0,0,0,0,0,0)),n=13+c;break;default:O.Stop(1)}break;case 20:if(O.amtaccumulator.length<9)return;var l=ReadIntX(O.amtaccumulator,5);if(O.amtaccumulator.length<9+l)return;var u=O.amtaccumulator.charCodeAt(1),s=O.amtaccumulator.charCodeAt(4),i=[];for(o=0;o<l;o++)i.push(O.amtaccumulator.charCodeAt(9+o));var h=O.amtaccumulator.substring(9,9+l);if(n=9+l,0==s)0<=i.indexOf(4)?O.xxSend(String.fromCharCode(19,0,0,0,4)+IntToStrX(O.user.length+O.authuri.length+8)+String.fromCharCode(O.user.length)+O.user+String.fromCharCode(0,0)+String.fromCharCode(O.authuri.length)+O.authuri+String.fromCharCode(0,0,0,0)):0<=i.indexOf(3)?O.xxSend(String.fromCharCode(19,0,0,0,3)+IntToStrX(O.user.length+O.authuri.length+7)+String.fromCharCode(O.user.length)+O.user+String.fromCharCode(0,0)+String.fromCharCode(O.authuri.length)+O.authuri+String.fromCharCode(0,0,0)):0<=i.indexOf(1)?O.xxSend(String.fromCharCode(19,0,0,0,1)+IntToStrX(O.user.length+O.pass.length+2)+String.fromCharCode(O.user.length)+O.user+String.fromCharCode(O.pass.length)+O.pass):O.Stop(2);else if(3!=s&&4!=s||1!=u)if(0==u){if(1==O.protocol){O.xxSend(String.fromCharCode(32,0,0,0)+IntToStrX(O.amtsequence++)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+IntToStrX(0))}2==O.protocol&&O.xxSend(String.fromCharCode(64,0,0,0,0,0,0,0)),3==O.protocol&&(O.connectstate=1,O.xxStateChange(3))}else O.Stop(3);else{var d=0,m=h.charCodeAt(d),S=h.substring(d+1,d+1+m);d+=m+1;var g=h.charCodeAt(d),f=h.substring(d+1,d+1+g);d+=g+1;var C=0,x=null,p=O.xxRandomNonce(32),k="00000002",b="";4==s&&(C=h.charCodeAt(d),x=h.substring(d+1,d+1+C),d+=C+1,b=k+":"+p+":"+
|