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