(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};(()=>{const t=cockpit;var n=e.n(t);const o=function(){const e=n().dbus(null,{bus:"internal"}).proxy("cockpit.Superuser","/superuser");let t=!1;const o=()=>e.valid&&"init"!=e.Current?"none"!=e.Current:null,d={allowed:o(),reload_page_on_change:function(){t=!0}};function r(e){if(d.allowed!=e)if(null!=d.allowed&&t)window.location.reload(!0);else{const t=d.allowed;d.allowed=e,d.dispatchEvent("changed"),null!=t&&d.dispatchEvent("reconnect")}}return n().event_target(d),e.wait((()=>{if(!e.valid){const e=n().permission({admin:!0}),t=()=>{r(e.allowed)};e.addEventListener("changed",t),t()}})),e.addEventListener("changed",(()=>{r(o())})),d}(),d=n().gettext;let r,s,i;function l(){!function(){document.querySelector("#sos-progress .progress-bar").style.width="0%",document.getElementById("sos-download").setAttribute("hidden","hidden"),document.getElementById("sos-error").setAttribute("hidden","hidden"),document.getElementById("sos-cancel").textContent=d("Cancel"),s=null,i=[];const e=n().spawn(["sosreport","--batch"],{superuser:!0,err:"out",pty:!0});r=e;let t="",o=0;const l=/Running ([0-9]+)\/([0-9]+):/,a=/Finishing plugins.*\[Running: (.*)\]/,u=/Starting ([0-9]+)\/([0-9]+).*\[Running: (.*)\]/,m=/Your sosreport has been generated and saved in:\s+(\/[^\r\n]+)/;e.stream((function(n){if(r==e){let e,d=0;t+=n;const r=t.split("\n");for(let t=r.length-1;t>=0;t--){if(e=u.exec(r[t])){o=parseInt(e[2],10),d=(parseInt(e[1],10)-e[3].split(" ").length)/o*100;break}if(e=a.exec(r[t])){d=o?(o-e[1].split(" ").length)/o*100:100;break}if(e=l.exec(r[t])){d=parseInt(e[1],10)/parseInt(e[2],10)*100;break}}document.getElementById("sos-alert").removeAttribute("hidden"),document.getElementById("sos-progress").removeAttribute("hidden"),document.querySelector("#sos-progress .progress-bar").style.width=d.toString()+"%"}})),e.done((function(){if(r==e){const e=m.exec(t);if(e){let t=e[1];const o=t.replace(/.*\//,"");0===t.indexOf("/host")&&(t=t.substr(5)),i=[t,t+".md5"];const r=window.btoa(JSON.stringify({payload:"fsread1",binary:"raw",path:t,superuser:!0,max_read_size:157286400,external:{"content-disposition":'attachment; filename="'+o+'"',"content-type":"application/x-xz, application/octet-stream"}})),l=new URL(n().transport.uri("channel/"+n().transport.csrf_token)).pathname;s=l+"?"+r,document.getElementById("sos-progress").setAttribute("hidden","hidden"),document.getElementById("sos-error").setAttribute("hidden","hidden"),document.getElementById("sos-alert").removeAttribute("hidden"),document.getElementById("sos-download").removeAttribute("hidden"),document.getElementById("sos-cancel").textContent=d("Close")}else c(d("No archive has been created."),t);r=null}})),e.fail((function(n){r==e&&(c(n.toString(),t),r=null)}))}()}function c(e,t){document.getElementById("sos-alert").setAttribute("hidden","hidden"),document.getElementById("sos-progress").setAttribute("hidden","hidden"),document.getElementById("sos-download").setAttribute("hidden","hidden"),document.querySelector("#sos-error .alert-message").textContent=e;const n=document.getElementById("sos-error-extra");t?(n.textContent=t,n.removeAttribute("hidden")):n.setAttribute("hidden","hidden"),document.getElementById("sos-cancel").textContent=d("Close"),document.getElementById("sos-error").removeAttribute("hidden")}function a(){r&&(r.close("cancelled"),r=null),i.length>0&&n().spawn(["rm"].concat(i),{superuser:!0,err:"message"}).fail((function(e){console.log("failed to remove",i,e)})),s=null,i=[],document.getElementById("sos").setAttribute("hidden","hidden")}function u(){const e=document.createElement("iframe");e.setAttribute("src",s),e.setAttribute("hidden","hidden"),e.addEventListener("load",(()=>{const t=e.contentDocument.title;t&&c(t)})),document.body.appendChild(e)}document.addEventListener("DOMContentLoaded",(()=>{function e(){document.getElementById("switch-instructions").style.display=!1===o.allowed?"block":"none",o.allowed?document.getElementById("create-button").removeAttribute("hidden"):document.getElementById("create-button").setAttribute("hidden","hidden")}document.getElementById("create-button").addEventListener("click",(()=>{document.getElementById("sos").removeAttribute("hidden"),l()})),document.getElementById("sos-cancel").addEventListener("click",a),document.querySelector("#sos-download button").addEventListener("click",u),n().translate(),document.body.removeAttribute("hidden"),o.addEventListener("changed",e),e(),n().transport.wait((()=>{}))}))})()})();