mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2026-07-25 09:58:11 +00:00
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{_ as x,G as v,A as D,c as i,a as t,t as V,n as T,m as p,y as b,b as a,h as g,d as _,F as $,i as w,f as r,D as E,j as C,$ as P,r as I,E as M,g as y,v as U,e as L,w as A,T as O,z as R}from"./index-DM7YJCOo.js";import{M as B}from"./message-BLvFM11v.js";import{d as S}from"./dayjs.min-DZl6XMNW.js";import{L as k}from"./localeText-BJvnc1lF.js";const j={name:"RemoteServer",components:{LocaleText:k},props:{server:Object},data(){return{active:!1,startTime:void 0,endTime:void 0,errorMsg:"",refreshing:!1}},methods:{addHeaders(){this.server.headers||(this.server.headers={}),this.server.headers[D().toString()]={key:"",value:""}},async handshake(){this.active=!1,this.server.host&&this.server.apiKey&&(this.refreshing=!0,this.startTime=void 0,this.endTime=void 0,this.startTime=S(),await fetch(`${this.server.host}/api/handshake`,{headers:this.getHeaders,method:"GET",signal:AbortSignal.timeout(5e3)}).then(s=>{if(s.status===200)return s.json();throw new Error(s.statusText)}).then(()=>{this.endTime=S(),this.active=!0}).catch(s=>{this.active=!1,this.errorMsg=s}),this.refreshing=!1)},async connect(){await fetch(`${this.server.host}/api/authenticate`,{headers:this.getHeaders,body:JSON.stringify({host:window.location.hostname}),method:"POST",signal:AbortSignal.timeout(5e3)}).then(s=>s.json()).then(s=>{this.$emit("setActiveServer"),this.$router.push("/")})}},mounted(){this.handshake()},computed:{getHandshakeTime(){return this.startTime&&this.endTime?`${S().subtract(this.startTime).millisecond()}ms`:this.refreshing?v("Pinging..."):this.errorMsg?this.errorMsg:"N/A"},getHeaders(){let s={"Content-Type":"application/json","wg-dashboard-apikey":this.server.apiKey};if(this.server.headers)for(let e of Object.values(this.server.headers))e.key&&e.value&&!Object.keys(s).includes(e.key)&&(s[e.key]=e.value);return s}}},q={class:"card rounded-3"},G={class:"gap-2 d-flex align-items-center"},H={key:0,class:"spin ms-auto text-white"},N={class:"card-body"},W={class:"d-flex gap-2 w-100 remoteServerContainer flex-column"},K={class:"d-flex gap-3 align-items-center flex-grow-1"},z={class:"d-flex gap-3 align-items-center flex-grow-1"},F={class:"d-flex gap-2 button-group"},J={class:"card rounded-3"},Q={class:"card-body d-flex gap-2 flex-column"},X={class:"d-flex gap-2"},Y={class:"flex-grow-1"},Z=["onUpdate:modelValue"],ee={class:"flex-grow-1"},te=["onUpdate:modelValue"],se=["onClick"];function oe(s,e,h,m,l,f){const o=g("LocaleText");return r(),i("div",q,[t("div",{class:T(["card-header",[this.active?"text-bg-success":"text-bg-danger"]])},[t("div",G,[e[12]||(e[12]=t("i",{class:"bi bi-person-walking"},null,-1)),t("small",null,V(this.getHandshakeTime),1),this.refreshing?(r(),i("div",H,[...e[10]||(e[10]=[t("i",{class:"bi bi-arrow-clockwise"},null,-1)])])):(r(),i("a",{key:1,role:"button",onClick:e[0]||(e[0]=n=>this.handshake()),class:"text-white text-decoration-none ms-auto disabled"},[...e[11]||(e[11]=[t("i",{class:"bi bi-arrow-clockwise me"},null,-1)])]))])],2),t("div",N,[t("div",W,[t("div",K,[e[13]||(e[13]=t("small",null,[t("i",{class:"bi bi-hdd-rack-fill"})],-1)),p(t("input",{class:"form-control form-control-sm rounded-3",onBlur:e[1]||(e[1]=n=>this.handshake()),"onUpdate:modelValue":e[2]||(e[2]=n=>this.server.host=n),type:"url"},null,544),[[b,this.server.host]])]),t("div",z,[e[14]||(e[14]=t("i",{class:"bi bi-key-fill"},null,-1)),p(t("input",{class:"form-control form-control-sm rounded-3 font-monospace",onBlur:e[3]||(e[3]=n=>this.handshake()),"onUpdate:modelValue":e[4]||(e[4]=n=>this.server.apiKey=n),type:"text"},null,544),[[b,this.server.apiKey]])]),t("div",F,[t("button",{style:{flex:"1 0 0"},onClick:e[5]||(e[5]=n=>this.$emit("delete")),class:"ms-auto btn btn-sm bg-danger-subtle text-danger-emphasis border-1 border-danger-subtle rounded-3"},[e[15]||(e[15]=t("i",{class:"bi bi-trash me-2"},null,-1)),a(o,{t:"Delete"})]),t("button",{style:{flex:"1 0 0"},onClick:e[6]||(e[6]=n=>this.connect()),class:T([{disabled:!this.active},"ms-auto btn btn-sm bg-success-subtle text-success-emphasis border-1 border-success-subtle rounded-3"])},[e[16]||(e[16]=t("i",{class:"bi bi-arrow-right-circle me-2"},null,-1)),a(o,{t:"Connect"})],2)]),t("div",J,[t("div",Q,[t("button",{style:{flex:"1 0 0"},onClick:e[7]||(e[7]=n=>f.addHeaders()),class:"btn btn-sm bg-primary-subtle text-primary-emphasis border-1 border-primary-subtle rounded-3"},[e[17]||(e[17]=t("i",{class:"bi bi-plus-lg me-2"},null,-1)),a(o,{t:"Headers"})]),this.server.headers?(r(!0),i($,{key:0},w(this.server.headers,(n,d)=>(r(),i("div",X,[t("div",Y,[p(t("input",{class:"form-control rounded-3 form-control-sm",onBlur:e[8]||(e[8]=c=>this.handshake()),"onUpdate:modelValue":c=>n.key=c,placeholder:"Key"},null,40,Z),[[b,n.key]])]),t("div",ee,[p(t("input",{class:"form-control rounded-3 form-control-sm",onBlur:e[9]||(e[9]=c=>this.handshake()),"onUpdate:modelValue":c=>n.value=c,placeholder:"Value"},null,40,te),[[b,n.value]])]),t("button",{type:"button",onClick:c=>delete this.server.headers[d],class:"btn btn-sm bg-danger-subtle text-danger-emphasis border-danger-subtle rounded-3"},[...e[18]||(e[18]=[t("i",{class:"bi bi-trash-fill"},null,-1)])],8,se)]))),256)):_("",!0)])])])])])}const ne=x(j,[["render",oe],["__scopeId","data-v-87b9c3d8"]]),re={name:"RemoteServerList",setup(){return{store:E()}},components:{LocaleText:k,RemoteServer:ne}},ie={class:"w-100 mt-3"},ae={class:"d-flex align-items-center mb-3"},le={class:"mb-0"},de={class:"w-100 d-flex gap-3 flex-column p-3 border border-1 border-secondary-subtle rounded-3",style:{height:"400px","overflow-y":"scroll"}},ue={key:0,class:"text-muted m-auto"};function ce(s,e,h,m,l,f){const o=g("LocaleText"),n=g("RemoteServer");return r(),i("div",ie,[t("div",ae,[t("h5",le,[a(o,{t:"Server List"})]),t("button",{onClick:e[0]||(e[0]=d=>this.store.addCrossServerConfiguration()),class:"btn bg-primary-subtle text-primary-emphasis border-1 border-primary-subtle shadow-sm ms-auto"},[e[1]||(e[1]=t("i",{class:"bi bi-plus-circle-fill me-2"},null,-1)),a(o,{t:"Server"})])]),t("div",de,[(r(!0),i($,null,w(this.store.CrossServerConfiguration.ServerList,(d,c)=>(r(),C(n,{onSetActiveServer:u=>this.store.setActiveCrossServer(c),onDelete:u=>this.store.deleteCrossServerConfiguration(c),key:c,server:d},null,8,["onSetActiveServer","onDelete","server"]))),128)),Object.keys(this.store.CrossServerConfiguration.ServerList).length===0?(r(),i("h6",ue,[a(o,{t:"Click"}),e[2]||(e[2]=t("i",{class:"bi bi-plus-circle-fill mx-1"},null,-1)),a(o,{t:"to add your server"})])):_("",!0)])])}const me=x(re,[["render",ce]]),he={name:"signInInput",methods:{GetLocale:v},props:{id:"",data:"",type:"",placeholder:""},computed:{getLocaleText(){return v(this.placeholder)}}},pe=["type","id","name","placeholder"];function fe(s,e,h,m,l,f){return p((r(),i("input",{type:h.type,"onUpdate:modelValue":e[0]||(e[0]=o=>this.data[this.id]=o),class:"form-control rounded-3",id:this.id,name:this.id,autocomplete:"on",placeholder:this.getLocaleText,required:""},null,8,pe)),[[P,this.data[this.id]]])}const be=x(he,[["render",fe]]),ge={name:"signInTOTP",methods:{GetLocale:v},props:{data:""},computed:{getLocaleText(){return v("OTP from your authenticator")}}},ve=["placeholder"];function _e(s,e,h,m,l,f){return p((r(),i("input",{class:"form-control totp",required:"",id:"totp",maxlength:"6",type:"text",inputmode:"numeric",autocomplete:"one-time-code",placeholder:this.getLocaleText,"onUpdate:modelValue":e[0]||(e[0]=o=>this.data.totp=o)},null,8,ve)),[[b,this.data.totp]])}const xe=x(ge,[["render",_e]]),ye={key:0},$e={class:"d-flex gap-2"},we=["href"],ke={__name:"signInOIDC",async setup(s){let e,h;const m=I([]),l=I(!1);[e,h]=M(async()=>y("/api/oidc/providers",{},async o=>{o.status&&(await Promise.all(Object.entries(o.data).map(([n,d])=>fetch(`${d.issuer}/.well-known/openid-configuration`).then(c=>{m.value.push({Provider:n,ProviderInfo:d})}).catch(()=>{console.log("Failed to request "+n)}))),l.value=m.value.length>0)})),await e,h(),console.log(m.value);const f=o=>{const n=new URLSearchParams({client_id:o.ProviderInfo.client_id,redirect_uri:window.location.protocol+"//"+window.location.host+window.location.pathname,response_type:"code",state:o.Provider,scope:"openid email profile"});console.log(n.entries());const d=new URL(o.ProviderInfo.openid_configuration.authorization_endpoint);return d.search=n.toString(),d};return(o,n)=>(r(),i("div",null,[l.value?(r(),i("div",ye,[n[0]||(n[0]=t("hr",{class:"mb-4"},null,-1)),t("div",$e,[(r(!0),i($,null,w(m.value,d=>(r(),i("a",{class:"btn bg-body border w-100 rounded-3",href:f(d),style:{flex:"1 1 0"}},[a(k,{t:"Sign In With "+d.Provider},null,8,["t"])],8,we))),256))])])):_("",!0)]))}},Se={name:"signin",components:{SignInOIDC:ke,SignInTOTP:xe,SignInInput:be,LocaleText:k,RemoteServerList:me,Message:B},async setup(){const s=E();let e="dark",h=!1,m;return s.IsElectronApp||await Promise.all([y("/api/getDashboardTheme",{},l=>{e=l.data}),y("/api/isTotpEnabled",{},l=>{h=l.data}),y("/api/getDashboardVersion",{},l=>{m=l.data})]),s.removeActiveCrossServer(),{store:s,theme:e,totpEnabled:h,version:m}},data(){return{data:{username:"",password:"",totp:""},loginError:!1,loginErrorMessage:"",loading:!1}},computed:{getMessages(){return this.store.Messages.filter(s=>s.show)},applyLocale(s){return v(s)},formValid(){return this.data.username&&this.data.password&&(this.totpEnabled&&this.data.totp||!this.totpEnabled)}},methods:{GetLocale:v,async auth(){this.formValid?(this.loading=!0,await R("/api/authenticate",this.data,s=>{s.status?(this.loginError=!1,this.$refs.signInBtn.classList.add("signedIn"),s.message?this.$router.push("/welcome"):this.store.Redirect!==void 0?this.$router.push(this.store.Redirect):this.$router.push("/")):(this.store.newMessage("Server",s.message,"danger"),document.querySelectorAll("input[required]").forEach(e=>{e.classList.remove("is-valid"),e.classList.add("is-invalid")}),this.loading=!1)})):document.querySelectorAll("input[required]").forEach(s=>{s.value.length===0?(s.classList.remove("is-valid"),s.classList.add("is-invalid")):(s.classList.remove("is-invalid"),s.classList.add("is-valid"))})}}},Ce=["data-bs-theme"],Te={class:"login-box m-auto"},Ie={class:"m-auto signInContainer",style:{width:"700px"}},Le={class:"mb-0 text-body"},Ve={class:"form-floating mb-2"},Ee=["disabled"],De={for:"floatingInput",class:"d-flex"},Pe={class:"form-floating mb-2"},Me=["disabled"],Ue={for:"floatingInput",class:"d-flex"},Ae={key:0,class:"form-floating mb-2"},Oe=["disabled"],Re={for:"floatingInput",class:"d-flex"},Be=["disabled"],je={key:0,class:"d-flex w-100"},qe={key:1,class:"d-flex w-100 align-items-center"},Ge={key:2,class:"d-flex mt-3 flex-column"},He={class:"form-check form-switch ms-auto"},Ne=["disabled"],We={class:"form-check-label",for:"flexSwitchCheckChecked"},Ke={class:"d-flex container-fluid align-items-center my-1 w-100"},ze={class:"text-muted"},Fe={href:"./client",target:"_blank",class:"text-decoration-none ms-auto text-body",style:{"white-space":"nowrap"}},Je={class:"messageCentre text-body position-absolute d-flex"};function Qe(s,e,h,m,l,f){const o=g("LocaleText"),n=g("RemoteServerList"),d=g("SignInOIDC"),c=g("Message");return r(),i("div",{class:"container-fluid login-container-fluid d-flex main flex-column py-4 text-body h-100",style:{"overflow-y":"scroll"},"data-bs-theme":this.theme},[t("div",Te,[t("div",Ie,[t("h4",Le,[a(o,{t:"Welcome to"})]),e[10]||(e[10]=t("span",{class:"dashboardLogo display-3"},[t("strong",null,"WGDashboard")],-1)),this.store.CrossServerConfiguration.Enable?(r(),C(n,{key:1})):(r(),i("form",{key:0,onSubmit:e[3]||(e[3]=u=>{u.preventDefault(),this.auth()}),class:"mt-3"},[t("div",Ve,[p(t("input",{type:"text",required:"",disabled:l.loading,"onUpdate:modelValue":e[0]||(e[0]=u=>this.data.username=u),name:"username",autocomplete:"username",autofocus:"",class:"form-control rounded-3",id:"username",placeholder:"Username"},null,8,Ee),[[b,this.data.username]]),t("label",De,[e[5]||(e[5]=t("i",{class:"bi bi-person-circle me-2"},null,-1)),a(o,{t:"Username"})])]),t("div",Pe,[p(t("input",{type:"password",required:"",disabled:l.loading,autocomplete:"current-password","onUpdate:modelValue":e[1]||(e[1]=u=>this.data.password=u),class:"form-control rounded-3",id:"password",placeholder:"Password"},null,8,Me),[[b,this.data.password]]),t("label",Ue,[e[6]||(e[6]=t("i",{class:"bi bi-key-fill me-2"},null,-1)),a(o,{t:"Password"})])]),this.totpEnabled?(r(),i("div",Ae,[p(t("input",{type:"text",id:"totp",required:"",disabled:l.loading,placeholder:"totp","onUpdate:modelValue":e[2]||(e[2]=u=>this.data.totp=u),class:"form-control rounded-3",maxlength:"6",inputmode:"numeric",autocomplete:"one-time-code"},null,8,Oe),[[b,this.data.totp]]),t("label",Re,[e[7]||(e[7]=t("i",{class:"bi bi-lock-fill me-2"},null,-1)),a(o,{t:"OTP from your authenticator"})])])):_("",!0),t("button",{class:"btn btn-lg btn-dark ms-auto mt-5 w-100 d-flex btn-brand signInBtn rounded-3",disabled:this.loading||!this.formValid,ref:"signInBtn"},[this.loading?(r(),i("span",qe,[a(o,{t:"Signing In..."}),e[9]||(e[9]=t("span",{class:"spinner-border ms-auto spinner-border-sm",role:"status"},null,-1))])):(r(),i("span",je,[a(o,{t:"Sign In"}),e[8]||(e[8]=t("i",{class:"ms-auto bi bi-chevron-right"},null,-1))]))],8,Be)],32)),this.store.IsElectronApp?_("",!0):(r(),i("div",Ge,[t("div",He,[p(t("input",{"onUpdate:modelValue":e[4]||(e[4]=u=>this.store.CrossServerConfiguration.Enable=u),disabled:l.loading,class:"form-check-input",type:"checkbox",role:"switch",id:"flexSwitchCheckChecked"},null,8,Ne),[[U,this.store.CrossServerConfiguration.Enable]]),t("label",We,[a(o,{t:"Access Remote Server"})])]),a(d)]))])]),t("div",Ke,[t("small",ze,[e[11]||(e[11]=L(" WGDashboard ",-1)),t("strong",null,V(this.version),1),e[12]||(e[12]=L(" | Made with ❤️ by ",-1)),e[13]||(e[13]=t("a",{href:"https://github.com/WGDashboard",class:"text-decoration-none text-body",target:"_blank"},[t("strong",null,"WGDashboard")],-1))]),t("a",Fe,[t("small",null,[e[14]||(e[14]=t("i",{class:"bi bi-box-arrow-up-right me-1"},null,-1)),a(o,{t:"Client App"})])])]),t("div",Je,[a(O,{name:"message",tag:"div",class:"position-relative flex-sm-grow-0 flex-grow-1 d-flex align-items-end ms-sm-auto flex-column gap-2"},{default:A(()=>[(r(!0),i($,null,w(f.getMessages.slice().reverse(),u=>(r(),C(c,{message:u,key:u.id},null,8,["message"]))),128))]),_:1})])],8,Ce)}const tt=x(Se,[["render",Qe],["__scopeId","data-v-9f90d4ac"]]);export{tt as default};
|