(()=>{"use strict";var e={n:n=>{var t=n&&n.__esModule?()=>n.default:()=>n;return e.d(t,{a:t}),t},d:(n,t)=>{for(var a in t)e.o(t,a)&&!e.o(n,a)&&Object.defineProperty(n,a,{enumerable:!0,get:t[a]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n)};(()=>{const n=cockpit;var t,a=e.n(n),o=null,r=null,d=null,l=null,i=0,c=null;function s(){var e=document.getElementById("speed");o||r?(e.innerHTML=a().format_bytes_per_sec(1e3*i/(Date.now()-l)),console.log(i)):e.innerHTML="";var n=document.getElementById("memory"),t=document.getElementById("pid");c||(c=a().script("echo $PPID && cat /proc/$PPID/statm")).then((function(e){var a=e.split("\n");t.innerHTML=a[0],n.innerHTML=a[1],c=null}),(function(e){n.innerHTML=String(e),c=null}))}function u(e){f();var n="echo-sideband"==e.target.id;var t=parseInt(document.getElementById("message").value,10),c=parseInt(document.getElementById("batch").value,10),s=parseInt(document.getElementById("interval").value,10);if(isNaN(t)||isNaN(s)||isNaN(c))window.alert("Bad value");else{var u=document.getElementById.checked,m={payload:"echo"},p=function(e,n){return n?new window.ArrayBuffer(e):new Array(e).join("x")}(t,u);if(l=new Date,i=0,n)u&&(m.binary="raw"),(r=new window.WebSocket(a().transport.uri("channel/"+a().transport.csrf_token)+"?"+window.btoa(JSON.stringify(m)))).binaryType="arraybuffer",r.onopen=function(){for(var e=0;e<c;e++)r.send(p);d=window.setInterval((function(){for(var e=0;e<c;e++)r.send(p)}),s)},r.onmessage=function(e){i+=u?e.data.byteLength:e.data.length},r.onclose=function(e){r&&window.alert("channel closed"),f()};else{u&&(m.binary=!0),(o=a().channel(m)).addEventListener("message",(function(e,n){i+=n.length})),o.addEventListener("close",(function(e,n){n.problem&&window.alert(n.problem),f()}));for(var w=0;w<c;w++)o.send(p);d=window.setInterval((function(){for(var e=0;e<c;e++)o.send(p)}),s)}}}function m(e){f();var n="read-sideband"==e.target.id,t={payload:"fsread1",path:document.getElementById("read-path").value,max_read_size:107374182400,binary:!n||"raw"};l=Date.now(),i=0,n?((r=new window.WebSocket(a().transport.uri("channel/"+a().transport.csrf_token)+"?"+window.btoa(JSON.stringify(t)))).binaryType="arraybuffer",r.onmessage=function(e){i+=e.data.byteLength},r.onclose=function(e){r&&window.alert("channel closed"),f()}):((o=a().channel(t)).addEventListener("message",(function(e,n){i+=n.length})),o.addEventListener("close",(function(e,n){n.problem&&window.alert(n.problem),f()})))}function p(e){f();var n,t=document.getElementById("download-path"),o={binary:"raw",max_read_size:107374182400,external:{"content-disposition":'attachment; filename="download"',"content-type":"application/octet-stream"}};0===t.value.indexOf("http")?((n=document.createElement("a")).href=t.value,o.payload="http-stream2",o.address=n.hostname,o.port=parseInt(n.port,10),o.path=n.pathname,o.method="GET"):(o.payload="fsread1",o.path=t.value),console.log("Download",o),l=Date.now(),i=0;var r=new URL(a().transport.uri("channel/"+a().transport.csrf_token)).pathname,d=window.btoa(JSON.stringify(o));window.open(r+"?"+d)}function w(){f(),document.getElementById("spawn-result").innerHTML="Running...";const e=document.getElementById("spawn-command").value;l=Date.now(),i=0,t="terminated",console.log("spawning",e),(o=a().script(e,{err:"message"})).stream((e=>{console.log("spawn: stream block length",e.length),i+=e.length,document.getElementById("spawn-output").innerHTML=e})),o.then((()=>{console.log("spawn: command finished successfully"),f(),document.getElementById("spawn-result").innerHTML="success"})),o.catch((e=>{console.log("spawn: command failed",JSON.stringify(e)),f(),document.getElementById("spawn-result").innerHTML=`failed with exit code ${e.exit_status}: ${e.message}`}))}function f(){s(),o&&o.close(t),o=null,t=void 0;var e=r;r=null,e&&e.close(),window.clearInterval(d),d=null}a().transport.wait((function(){document.getElementById("echo-normal").addEventListener("click",u),document.getElementById("echo-sideband").addEventListener("click",u),document.getElementById("read-normal").addEventListener("click",m),document.getElementById("read-sideband").addEventListener("click",m),document.getElementById("download-external").addEventListener("click",p),document.getElementById("spawn").addEventListener("click",w),document.getElementById("stop").addEventListener("click",f),window.setInterval(s,500),document.body.removeAttribute("hidden")}))})()})();