(()=>{function w(...c){(window.debugging==="all"||window.debugging?.includes("login"))&&console.debug("login:",...c)}(function(){let c;try{c=window.localStorage,window.localStorage.removeItem("url-root"),window.localStorage.removeItem("standard-login")}catch(e){c=window.sessionStorage,console.warn(String(e))}let O=c.getItem("shell:style")||"auto";window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches&&O==="auto"||O==="dark"?document.documentElement.classList.add("pf-v6-theme-dark"):document.documentElement.classList.remove("pf-v6-theme-dark"),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{e.matches&&O==="auto"||O==="dark"?document.documentElement.classList.add("pf-v6-theme-dark"):document.documentElement.classList.remove("pf-v6-theme-dark")});let m,s=window.environment||{},b=s.OAuth||null;b&&(b.TokenParam||(b.TokenParam="access_token"),b.ErrorParam||(b.ErrorParam="error_description"));let ne=/\$\{([^}]+)\}|\$([a-zA-Z0-9_]+)/g;function y(e){let o=Array.prototype.slice.call(arguments,1);return e.replace(ne,function(n,t,i){return o[t||i]||""})}function J(e){if(window.cockpit_po){let o=window.cockpit_po[e];if(o&&o[1])return o[1]}return e}function re(){let e=document.querySelectorAll("[translate]");for(let o=0;o{g("#login-fatal"),R()},p("#login-again");let o=r("login-fatal-message");o.textContent="",o.appendChild(document.createTextNode(e))}function k(e){console.warn("fatal:",e),g("#login-again","#login-wait-validating"),C&&(r("login-again").href=C,p("#login-again")),g("#login","#login-details"),p("#login-fatal");let o=r("login-fatal-message");o.textContent="",o.appendChild(document.createTextNode(e))}function A(e,o){let n=r(e),t=n&&window.getComputedStyle?window.getComputedStyle(n,":before"):null;if(!t)return;let i=t.content;if(i&&i!="none"&&i!="normal"){let a=i.length;(i[0]==='"'||i[0]==="'")&&a>2&&i[a-1]===i[0]&&(i=i.substring(1,a-1)),n.innerHTML=i||o}else n.removeAttribute("class")}function le(){function e(a){a?(p("#login","#login-details","#login-override"),g("#get-out-link"),r("login-override-content").appendChild(r("login")),r("login-button").classList.add("pf-m-warning"),document.querySelector("#login .login-actions").insertAdjacentHTML("beforebegin","
"+l("Cockpit might not render correctly in your browser")+"
")):g("#login","#login-details","#login-override")}function o(a,f){a==="supports"&&(a="@supports API");let S=y(l("This web browser is too old to run the Web Console (missing $0)"),a);console.warn(S),r("login-error-message").textContent=S,p("#unsupported-browser","#error-group"),document.body.classList.add("unsupported-browser"),e(f)}function n(a,f){let S;try{S=f&&f[a]}catch(he){throw k(y(l("The web browser configuration prevents Cockpit from running (inaccessible $0)"),a)),he}return S===void 0?(o(a),!1):!0}function t(){let a=[].join.call(arguments,": ");return!window.CSS||!window.CSS.supports.apply(this,arguments)?(o(a,"bypass"),!1):!0}return n("WebSocket",window)&&n("XMLHttpRequest",window)&&n("sessionStorage",window)&&n("JSON",window)&&n("defineProperty",Object)&&n("pushState",window.history)&&n("textContent",document)&&n("replaceAll",String.prototype)&&n("finally",Promise.prototype)&&n("supports",window.CSS)?(t("display","flex")&&t("display","grid")&&t("selector(test)")&&t("selector(:is(*):where(*))"),!0):!1}function W(e){let o=document.createElement("a"),n=document.baseURI;e=e||"/",o.href=n,o.pathname!="/"&&(m=o.pathname.replace(/^\/+|\/+$/g,""),c.setItem("url-root",m),m&&e.indexOf("/"+m)===0&&(e=e.replace("/"+m,"")||"/")),e.indexOf("/=")===0?(s.hostname=e.substring(2).split("/")[0],r("server-field").value=s.hostname,L(null,!0),e="/cockpit+"+e.split("/")[1]):e.indexOf("/cockpit/")!==0&&e.indexOf("/cockpit+")!==0&&(e="/cockpit"),h=e.split("/")[1],x="/"+h+"/login",m&&(x="/"+m+x),z=h,q=x}function L(e,o){e&&e.type==="keypress"&&e.key!==" "||(e&&e.type==="click"&&e.preventDefault(),o===void 0&&(o=r("server-group").hidden),v("#server-group",!o),r("option-group").setAttribute("data-state",o))}function se(e){let o=r("login-password-input");o.setAttribute("type",o.getAttribute("type")==="password"?"text":"password"),e.stopPropagation()}function ce(){let e=s.logged_into||[],o=e.length>0?e[0]:null;function n(){P(o==="."?"/":"/="+o)}o&&!s.page.allow_multihost&&n()}function de(){window.onload=null,re(),window.cockpit_po&&window.cockpit_po[""]&&(document.documentElement.lang=window.cockpit_po[""].language,window.cockpit_po[""]["language-direction"]&&(document.documentElement.dir=window.cockpit_po[""]["language-direction"])),ce(),W(window.location.pathname),(window.location.pathname.indexOf("/"+m+"/cockpit/")===0||window.location.pathname.indexOf("/"+m+"/cockpit+")===0)&&document.documentElement.setAttribute("class","inline");let e=s.page.title;if(s.is_cockpit_client&&(e=l("Login")),(!e||h.indexOf("cockpit+=")===0)&&(e=s.hostname),document.title=e,h.indexOf("cockpit+=")===0?g("#brand","#badge"):(A("badge",""),A("brand","Cockpit")),!le())return;s.banner&&(p("#banner"),r("banner-message").textContent=s.banner.trimEnd()),r("bypass-browser-check").addEventListener("click",L),r("bypass-browser-check").addEventListener("keypress",L),r("show-other-login-options").addEventListener("click",L),r("show-other-login-options").addEventListener("keypress",L),r("server-clear").addEventListener("click",function(){let t=r("server-field");t.value="",t.focus()});let o=window.sessionStorage.getItem("logout-intent")=="explicit";o&&window.sessionStorage.removeItem("logout-intent");let n=window.sessionStorage.getItem("logout-reason");n&&window.sessionStorage.removeItem("logout-reason"),b?(g("#login-details","#login"),o?(D(),r("login-again").textContent=l("Login again"),k(l("Logout successful"))):pe()):o?R(n):B()?R():ge()}function ge(){let e=new XMLHttpRequest;e.open("GET",x,!0),e.onreadystatechange=function(){e.readyState==4&&(e.status==200?U(JSON.parse(e.responseText)):e.status==401?R():e.statusText?k(decodeURIComponent(e.statusText)):e.status===0?R():k(y(l("$0 error"),e.status)))},e.send()}function D(){let e=window.location.href.split("#",2);C=b.URL,b.URL.indexOf("?")>-1?C+="&":C+="?",C+="redirect_uri="+encodeURIComponent(e[0])}function pe(){let e=document.createElement("a");if(!b.URL)return k(l("Cockpit authentication is configured incorrectly."));let o=!window.location.search&&window.location.hash?$(window.location.hash.slice(1)):$(window.location.search);if(D(),o[b.TokenParam]){window.sessionStorage.getItem("login-wanted")&&(e.href=window.sessionStorage.getItem("login-wanted"),W(e.pathname));let n=o[b.TokenParam];p("#login-wait-validating");let t=new XMLHttpRequest;t.open("GET",x,!0),t.setRequestHeader("Authorization","Bearer "+n),t.onreadystatechange=function(){if(t.readyState==4)if(t.status==200)U(JSON.parse(t.responseText));else{let i=ee(t.getResponseHeader("WWW-Authenticate"),t.responseText);i?Z(i):k(decodeURIComponent(t.statusText))}},t.send()}else o[b.ErrorParam]?k(o[b.ErrorParam]):(window.sessionStorage.setItem("login-wanted",window.location.href),window.location=C)}function X(){g("#error-group"),r("login-error-message").textContent=""}function j(){g("#info-group"),r("login-info-message").textContent=""}function u(e,o,n){X(),e&&(b?k(e):(E(n||"login"),r("login-error-title").textContent=e,r("login-error-message").textContent=o,v("#error-group .pf-v6-c-alert__description",!o),p("#error-group")))}function ue(e){j(),e&&(r("login-info-message").textContent=e,p("#info-group"))}function H(e,o){d?(X(),r("login-error-title").textContent=e,r("login-error-message").textContent=o,v("#error-group .pf-v6-c-alert__description",!o),p("#error-group"),L(null,!0),E("login")):u(o)}function fe(e){let o=r("login-note");e?(p(o),o.textContent=e):o.innerHTML=" "}function B(){return s.page.require_host&&z.indexOf("cockpit+=")===-1}function F(){let e=[];try{e=JSON.parse(c.getItem("cockpit-client-sessions")||"[]")}catch(o){console.log("Failed to parse 'cockpit-client-sessions':",o)}return e}let d=null,T=null,_=null;function I(){u(null),d=r("server-field").value,T=null;let e=r("login-user-input").value.trim();if(e===""&&!s.is_cockpit_client)u(l("User name cannot be empty"));else if(B()&&d==="")u(l("Please specify the host to connect to"));else{d?(h="cockpit+="+d,x=q.replace("/"+z+"/","/"+h+"/"),r("brand").style.display="none",r("badge").style.visibility="hidden"):(h=z,x=q,A("badge",""),A("brand","Cockpit")),r("server-name").textContent=d||s.hostname,r("login-button").removeEventListener("click",I);let o=r("login-password-input").value,n="superuser:"+e+(d?":"+d:""),t=c.getItem(n)||"none";c.setItem("superuser-key",n),c.setItem(n,t),c.setItem("standard-login",!0);let i="";if(d)if(_==d)w("call_login(): previous login attempt into",d,"failed due to changed key");else{let f=Q(d);f?(w("call_login(): sending known_host key",f,"for logging into",d),i=f):w("call_login(): no known_hosts entry for logging into",d)}let a={Authorization:"Basic "+window.btoa(K(e+":"+o+"\0"+i)),"X-Superuser":t};d&&(a["X-SSH-Connect-Unknown-Hosts"]="yes"),oe("GET",a,!1)}}function G(){let e=F(),o=r("recent-hosts-list");o.innerHTML="",e.forEach(n=>{let t=document.createElement("div");t.classList.add("host-line"),t.setAttribute("data-host-id",n);let i=document.createElement("button");i.textContent=n,i.classList.add("pf-v6-c-button","pf-m-tertiary","host-name"),i.addEventListener("click",()=>{r("server-field").value=n,I()});let a=document.createElement("button");a.title=l("Remove host"),a.ariaLabel=a.title,a.classList.add("host-remove"),a.addEventListener("click",()=>{let f=e.indexOf(n);e.splice(f,1),c.setItem("cockpit-client-sessions",JSON.stringify(e)),G()}),t.append(i,a),o.append(t)}),v("#recent-hosts",e.length==0)}function E(e){let o=s.page.connect,n=r("option-group").getAttribute("data-state");if(g("#login-wait-validating"),p("#login"),v("#login-details",s.is_cockpit_client),v("#server-field-label",s.is_cockpit_client),s.is_cockpit_client){let t=r("brand");t.textContent=l("Connect to:"),t.classList.add("text-brand")}v(["#user-group","#password-group"],e!="login"||s.is_cockpit_client),v("#conversation-group",e!="conversation"),v("#hostkey-group",e!="hostkey"),r("login-button-text").textContent=e=="hostkey"?l("Accept key and log in"):l("Log in"),e!="login"&&(r("login-password-input").value=""),s.page.require_host?(g("#option-group"),n=!0):v("#option-group",!o||e!="login"),!o||e!="login"?g("#server-group"):v("#server-group",!n),r("login-button").removeAttribute("disabled"),r("login-button").removeAttribute("spinning"),r("login-button").classList.remove("pf-m-danger"),r("login-button").classList.add("pf-m-primary"),g("#get-out-link"),e=="login"&&r("login-button").addEventListener("click",I),s.is_cockpit_client&&(G(),document.body.classList.add("cockpit-client"))}function R(e){ue(e),r("server-name").textContent=document.title,fe(l("Log in with your server user account.")),r("login-user-input").addEventListener("keydown",function(n){u(null),j(),n.which==13&&r("login-password-input").focus()},!1);let o=function(n){u(null),n.which==13&&I()};r("login-password-input").addEventListener("keydown",o),r("login-password-toggle").addEventListener("click",se),E("login"),s.is_cockpit_client?s.page.require_host&&r("server-field").focus():r("login-user-input").focus()}function V(){try{return JSON.parse(c.getItem("known_hosts")||"{ }")}catch(e){return console.warn("Can't parse known_hosts database in localStorage",e),{}}}function Q(e){return V()[M(e)]}function Y(e,o){try{let n=V();n[M(e)]=o,c.setItem("known_hosts",JSON.stringify(n))}catch(n){console.warn("Can't write known_hosts database to localStorage",n)}}function be(e){let o=e["host-key"],n=o.split(" ")[0],t=o.split(" ")[1],i=Q(n);i?(w("do_hostkey_verification: received key fingerprint",e.default,"for host",n,"does not match key in known_hosts database:",i,"; treating as changed"),r("hostkey-title").textContent=y(l("$0 key changed"),d),p("#hostkey-warning-group"),r("hostkey-message-1").textContent=""):(w("do_hostkey_verification: received key fingerprint",e.default,"for host",n,"not in known_hosts database; treating as new host"),r("hostkey-title").textContent=l("New host"),g("#hostkey-warning-group"),r("hostkey-message-1").textContent=y(l("You are connecting to $0 for the first time."),d)),r("hostkey-verify-help-1").textContent=y(l("To verify a fingerprint, run the following on $0 while physically sitting at the machine or through a trusted network:"),d),r("hostkey-verify-help-cmds").textContent=y("ssh-keyscan$0 localhost | ssh-keygen -lf -",t?" -t "+t:""),r("hostkey-fingerprint").textContent=e.default,t?(r("hostkey-type").textContent=y("($0)",t),p("#hostkey-type")):g("#hostkey-type"),u("");function a(){r("login-button").removeEventListener("click",a),u(null,null,"hostkey"),o.endsWith(" login-data")?(T=n,w("call_converse(): got placeholder host keyfor",T,", deferring db update"),te(e.id,e.default)):(console.error("login: got unexpected host key prompt, expecting login-data placeholder:",o),k(l("Internal protocol error")))}r("login-button").addEventListener("click",a),E("hostkey"),p("#get-out-link"),i&&(r("login-button").classList.add("pf-m-danger"),r("login-button").classList.remove("pf-m-primary"))}function Z(e){if(e["host-key"]){be(e);return}let o=e.echo?"text":"password";r("conversation-prompt").textContent=e.prompt;let n=r("conversation-message"),t=e.error||e.message;t?(n.textContent=t,p(n)):g(n);let i=r("conversation-input");i.value="",e.default&&(i.value=e.default),i.setAttribute("type",o),u("");function a(){r("conversation-input").removeEventListener("keydown",f),r("login-button").removeEventListener("click",a),u(null,null,"conversation"),te(e.id,r("conversation-input").value)}function f(S){u(null,null,"conversation"),S.which==13&&a()}r("conversation-input").addEventListener("keydown",f),r("login-button").addEventListener("click",a),E("conversation"),i.focus()}function K(e){return window.unescape(encodeURIComponent(e))}function ee(e,o){if(!e)return null;let n=e.split(" ");if(n[0].toLowerCase()!=="x-conversation"||n.length!==3)return null;let t=n[1],i;try{i=window.atob(n[2])}catch(f){return console.error("Invalid prompt data",f),null}let a;try{a=JSON.parse(o)}catch(f){console.log("Got invalid JSON response for prompt data",f),a={}}return a.id=t,a.prompt=i,a}function oe(e,o,n){w("send_login_request():",e,"headers:",JSON.stringify(o)),r("login-button").setAttribute("disabled","true"),r("login-button").setAttribute("spinning","true");let t=new XMLHttpRequest;t.open(e,x,!0);for(let i in o)t.setRequestHeader(i,o[i]);t.onreadystatechange=function(){if(t.readyState==4)if(t.status==200){let i=JSON.parse(t.responseText);U(i)}else if(t.status==401){w("send_login_request():",e,"got 401, status:",t.statusText,"; response:",t.responseText);let i=t.getResponseHeader("WWW-Authenticate");if(i&&i.toLowerCase().indexOf("x-conversation")===0){let a=ee(i,t.responseText);a?Z(a):k(l("Internal error: Invalid challenge header"))}else{if(console.log(t.statusText),_)try{let a=JSON.parse(t.responseText)["known-hosts"];a?(w("send_login_request(): got updated known-hosts for changed host keys of",_,":",a),Y(_,a),_=null):w("send_login_request():",_,"changed key, but did not get an updated key from response")}catch(a){console.error("Failed to parse response text as JSON:",t.responseText,":",JSON.stringify(a))}if(t.statusText.startsWith("captured-stderr:"))ae(decodeURIComponent(t.statusText.replace(/^captured-stderr:/,"")));else if(t.statusText.indexOf("authentication-not-supported")>-1){let a=r("login-user-input").value.trim();k(y(l("The server refused to authenticate '$0' using password authentication, and no other supported authentication methods are available."),a))}else t.statusText.indexOf("terminated")>-1?u(l("Authentication failed"),l("Server closed connection")):t.statusText.indexOf("no-host")>-1?H(l("Unable to connect to that address")):t.statusText.indexOf("unknown-hostkey")>-1?H(l("Refusing to connect"),l("Hostkey is unknown")):t.statusText.indexOf("unknown-host")>-1?H(l("Refusing to connect"),l("Host is unknown")):t.statusText.indexOf("invalid-hostkey")>-1?_===null?(w("send_login_request(): invalid-hostkey, trying again to let the user confirm"),_=d,I()):(w("send_login_request(): invalid-hostkey, and already retried, giving up"),H(l("Refusing to connect"),l("Hostkey does not match"))):n?u(l("Authentication failed")):u(l("Authentication failed"),l("Wrong user name or password"))}}else if(t.status==403){let i=decodeURIComponent(t.statusText).trim();u(l("Permission denied"),i==="Permission denied"?"":i)}else if(t.status==500&&t.statusText.indexOf("no-cockpit")>-1){let i=y(l("Install the cockpit-system package (and optionally other cockpit packages) on $0 to enable web console access."),d||"localhost");u(l("Packageless session unavailable"),i)}else t.status==500&&t.statusText.indexOf("unsupported-shell")>-1?u(l("Authentication failed"),l("Unsupported shell. Check the journal for details.")):t.statusText?k(decodeURIComponent(t.statusText)):k(y(l("$0 error"),t.status))},t.send()}function te(e,o){let n={Authorization:"X-Conversation "+e+" "+window.btoa(K(o))};oe("GET",n,!0)}function P(e){let o=window.setTimeout(function(){o=null,window.location.reload(!0)},100);e&&e!=window.location.href&&(window.location=e),window.onbeforeunload=function(){o&&window.clearTimeout(o),o=null}}function N(e,o,n){let t=0;for(;t