2020-09-08 23:33:52 +03:00
|
|
|
var CreateWsmanComm=function(e,t,r,n,a){var c={};function o(){for(i in c.socketState=2,c.pendingAjaxCall)c.sendRequest(c.pendingAjaxCall[i][0],c.pendingAjaxCall[i][3],c.pendingAjaxCall[i][4])}function s(e){for(c.socketAccumulator+=function(e){return String.fromCharCode.apply(null,e)}(new Uint8Array(e.data));;){if(0==c.socketParseState){var t=c.socketAccumulator.indexOf("\r\n\r\n");if(t<0)return;if(c.socketHeader=c.socketAccumulator.substring(0,t).split("\r\n"),null==c.amtVersion)for(var r in c.socketHeader)0==c.socketHeader[r].indexOf("Server: Intel(R) Active Management Technology ")&&(c.amtVersion=c.socketHeader[r].substring(46));for(r in c.socketAccumulator=c.socketAccumulator.substring(t+4),c.socketParseState=1,c.socketData="",c.socketXHeader={Directive:c.socketHeader[0].split(" ")},c.socketHeader)if(0!=r){var n=c.socketHeader[r].indexOf(":");c.socketXHeader[c.socketHeader[r].substring(0,n).toLowerCase()]=c.socketHeader[r].substring(n+2)}}if(1==c.socketParseState){var a=-1;if(null==c.socketXHeader.connection||"close"!=c.socketXHeader.connection.toLowerCase()||null!=c.socketXHeader["transfer-encoding"]&&"chunked"==c.socketXHeader["transfer-encoding"].toLowerCase())if(null!=c.socketXHeader["content-length"]){if(a=parseInt(c.socketXHeader["content-length"]),c.socketAccumulator.length<a)return;var o=c.socketAccumulator.substring(0,a);c.socketAccumulator=c.socketAccumulator.substring(a),c.socketData=o,a=0}else{var s=c.socketAccumulator.indexOf("\r\n");if(s<0)return;if(a=parseInt(c.socketAccumulator.substring(0,s),16),isNaN(a))return void(c.websocket&&c.websocket.close());if(c.socketAccumulator.length<s+2+a+2)return;o=c.socketAccumulator.substring(s+2,s+2+a);c.socketAccumulator=c.socketAccumulator.substring(s+2+a+2),c.socketData+=o}else a=0;0==a&&(l(c.socketXHeader,c.socketData),c.socketParseState=0,c.socketHeader=null)}}}function l(e,t){var r=parseInt(e.Directive[1]);if(isNaN(r)&&(r=602),401==r&&++c.authcounter<3){if(c.challengeParams=c.parseDigest(e["www-authenticate"]),null!=c.challengeParams.qop){var n=c.challengeParams.qop.split(",");for(var a in n)n[a]=n[a].trim();0<=n.indexOf("auth-int")?c.challengeParams.qop="auth-int":c.challengeParams.qop="auth"}}else{var o=c.pendingAjaxCall.shift();c.authcounter=0,c.ActiveAjaxCount--,c.gotNextMessages(t,"success",{status:r},o),c.PerformNextAjax()}}function u(e){if(c.socketState=0,null!=c.socket&&(c.socket.close(),c.socket=null),0<c.pendingAjaxCall.length){var t=c.pendingAjaxCall.shift(),r=t[5];c.PerformAjaxExNodeJS2(t[0],t[1],t[2],t[3],t[4],--r)}}return c.PendingAjax=[],c.ActiveAjaxCount=0,c.MaxActiveAjaxCount=1,c.FailAllError=0,c.challengeParams=null,c.noncecounter=1,c.authcounter=0,c.socket=null,c.socketState=0,c.host=e,c.port=t,c.user=r,c.pass=n,c.tls=a,c.tlsv1only=1,c.cnonce=Math.random().toString(36).substring(7),c.PerformAjax=function(e,t,r,n,a,o){c.ActiveAjaxCount<c.MaxActiveAjaxCount&&0==c.PendingAjax.length?c.PerformAjaxEx(e,t,r,a,o):1==n?c.PendingAjax.unshift([e,t,r,a,o]):c.PendingAjax.push([e,t,r,a,o])},c.PerformNextAjax=function(){if(!(c.ActiveAjaxCount>=c.MaxActiveAjaxCount||0==c.PendingAjax.length)){var e=c.PendingAjax.shift();c.PerformAjaxEx(e[0],e[1],e[2],e[3],e[4]),c.PerformNextAjax()}},c.PerformAjaxEx=function(e,t,r,n,a){if(0==c.FailAllError)return e=e||"",c.ActiveAjaxCount++,c.PerformAjaxExNodeJS(e,t,r,n,a);c.gotNextMessagesError({status:c.FailAllError},"error",null,[e,t,r,n,a])},c.pendingAjaxCall=[],c.PerformAjaxExNodeJS=function(e,t,r,n,a){c.PerformAjaxExNodeJS2(e,t,r,n,a,3)},c.PerformAjaxExNodeJS2=function(e,t,r,n,a,o){if(o<=0||0!=c.FailAllError)return c.ActiveAjaxCount--,999!=c.FailAllError&&c.gotNextMessages(null,"error",{status:0==c.FailAllError?408:c.FailAllError},[e,t,r,n,a]),void c.PerformNextAjax();c.pendingAjaxCall.push([e,t,r,n,a,o]),0==c.socketState?c.xxConnectHttpSocket():2==c.socketState&&c.sendRequest(e,n,a)},c.sendRequest=function(e,t,r){var n=(r=r||"POST")+" "+(t=t||"/wsman")+" HTTP/1.1\r\n";if(null!=c.challengeParams){var a=hex_md5(hex_md5(c.user+":"+c.challengeParams.realm+":"+c.pass)+":"+c.challengeParams.nonce+":"+c.noncecounter+":"+c.cno
|