1 line
6.6 KiB
JavaScript
1 line
6.6 KiB
JavaScript
|
var CreateWsmanComm=function(e,t,r,n,a){var u={};function o(){for(i in u.socketState=2,u.pendingAjaxCall)u.sendRequest(u.pendingAjaxCall[i][0],u.pendingAjaxCall[i][3],u.pendingAjaxCall[i][4])}u.PendingAjax=[],u.ActiveAjaxCount=0,u.MaxActiveAjaxCount=1,u.FailAllError=0,u.challengeParams=null,u.noncecounter=1,u.authcounter=0,u.socket=null,u.socketState=0,u.host=e,u.port=t,u.user=r,u.pass=n,u.tls=a,u.tlsv1only=1,u.cnonce=Math.random().toString(36).substring(7),u.PerformAjax=function(e,t,r,n,a,o){u.ActiveAjaxCount<u.MaxActiveAjaxCount&&0==u.PendingAjax.length?u.PerformAjaxEx(e,t,r,a,o):1==n?u.PendingAjax.unshift([e,t,r,a,o]):u.PendingAjax.push([e,t,r,a,o])},u.PerformNextAjax=function(){if(!(u.ActiveAjaxCount>=u.MaxActiveAjaxCount||0==u.PendingAjax.length)){var e=u.PendingAjax.shift();u.PerformAjaxEx(e[0],e[1],e[2],e[3],e[4]),u.PerformNextAjax()}},u.PerformAjaxEx=function(e,t,r,n,a){if(0==u.FailAllError)return e=e||"",u.ActiveAjaxCount++,u.PerformAjaxExNodeJS(e,t,r,n,a);u.gotNextMessagesError({status:u.FailAllError},"error",null,[e,t,r,n,a])},u.pendingAjaxCall=[],u.PerformAjaxExNodeJS=function(e,t,r,n,a){u.PerformAjaxExNodeJS2(e,t,r,n,a,3)},u.PerformAjaxExNodeJS2=function(e,t,r,n,a,o){if(o<=0||0!=u.FailAllError)return u.ActiveAjaxCount--,999!=u.FailAllError&&u.gotNextMessages(null,"error",{status:0==u.FailAllError?408:u.FailAllError},[e,t,r,n,a]),void u.PerformNextAjax();u.pendingAjaxCall.push([e,t,r,n,a,o]),0==u.socketState?u.xxConnectHttpSocket():2==u.socketState&&u.sendRequest(e,n,a)},u.sendRequest=function(e,t,r){var n=(r=r||"POST")+" "+(t=t||"/wsman")+" HTTP/1.1\r\n";if(null!=u.challengeParams){var a=hex_md5(hex_md5(u.user+":"+u.challengeParams.realm+":"+u.pass)+":"+u.challengeParams.nonce+":"+u.noncecounter+":"+u.cnonce+":"+u.challengeParams.qop+":"+hex_md5(r+":"+t+("auth-int"==u.challengeParams.qop?":"+hex_md5(e):"")));n+="Authorization: "+u.renderDigest({username:u.user,realm:u.challengeParams.realm,nonce:u.challengeParams.nonce,uri:t,qop:u.challengeParams.qop,response:a,nc:u.noncecounter++,cnonce:u.cnonce})+"\r\n"}!function(e){if(2==u.socketState&&null!=u.socket&&u.socket.readyState==WebSocket.OPEN){for(var t=new Uint8Array(e.length),r=0;r<e.length;++r)t[r]=e.charCodeAt(r);try{u.socket.send(t.buffer)}catch(e){}}}(n+="Host: "+u.host+":"+u.port+"\r\nTransfer-Encoding: chunked\r\n\r\n"+e.length.toString(16).toUpperCase()+"\r\n"+e+"\r\n0\r\n\r\n")},u.parseDigest=function(e){return function(e){return e.split(",").reduce(function(e,t){return e.ic?e.st[e.st.length-1]+=","+t:e.st.push(t),t.split('"').length%2==0&&(e.ic=!e.ic),e},{st:[],ic:!1}).st}(e.substring(7)).reduce(function(e,t){var r=t.trim().split("=");return e[r[0]]=r[1].replace(new RegExp('"',"g"),""),e},{})},u.renderDigest=function(r){var e=[];for(i in r)e.push(i);return"Digest "+e.reduce(function(e,t){return e+","+t+'="'+r[t]+'"'},"").substring(1)},u.xxConnectHttpSocket=function(){u.socketParseState=0,u.socketAccumulator="",u.socketHeader=null,u.socketData="",u.socketState=1,console.log(u.tlsv1only),u.socket=new WebSocket(window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/webrelay.ashx?p=1&host="+u.host+"&port="+u.port+"&tls="+u.tls+"&tlsv1only="+u.tlsv1only+("*"==r?"&serverauth=1":"")+(void 0===n?"&serverauth=1&user="+r:"")),u.socket.onopen=o,u.socket.onmessage=f,u.socket.onclose=g};var s=new FileReader,c=!1,l=[];function f(e){if("object"==typeof e.data){if(1==c)return void l.push(e.data);if(s.readAsBinaryString)c=!0,s.readAsBinaryString(new Blob([e.data]));else if(s.readAsArrayBuffer)c=!0,s.readAsArrayBuffer(e.data);else{for(var t="",r=new Uint8Array(e.data),n=r.byteLength,a=0;a<n;a++)t+=String.fromCharCode(r[a]);A(t)}}else A(e.data)}function A(e){if("object"==typeof e){for(var t="",r=new Uint8Array(e),n=r.byteLength,a=0;a<n;a++)t+=String.fromCharCode(r[a]);e=t}else if("string"!=typeof e)return;for(u.socketAccumulator+=e;;){if(0==u.socketParseState){var o=u.socketAccumulator.indexOf("\r\n\r\n");if(o<0)return;for(a in u.socketHeader=u.socketAccumulator.substrin
|