MeshCentral/public/scripts/amt-wsman-ws-0.2.0-min.js

1 line
6.1 KiB
JavaScript
Raw Normal View History

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