WGDashboard/src/static/app/dist/assets/configurationList-CL6wqEfT.js
Donald Zou 7c70fbec30 Build
2025-02-14 23:24:16 +08:00

2 lines
13 KiB
JavaScript

import{_ as D,D as M,g as I,a as i,c as n,b as t,d as r,w as S,n as m,t as u,f as v,i as _,e as y,m as U,v as V,u as B,j as p,r as O,p as K,T as G,q as L,o as R,s as W,F as w,h as k,W as q,G as $,k as F,x as z}from"./index-DlNxBlsu.js";import{L as x}from"./localeText-DIMmLZFF.js";import{_ as j}from"./protocolBadge-Czb9ddM9.js";import{C as J}from"./storageMount.vue_vue_type_style_index_0_scoped_a382214a_lang-D053-ZX1.js";const N={name:"configurationCard",components:{ProtocolBadge:j,LocaleText:x},props:{c:{Name:String,Status:Boolean,PublicKey:String,PrivateKey:String},delay:String,display:String},data(){return{configurationToggling:!1}},setup(){return{dashboardConfigurationStore:M()}},methods:{toggle(){this.configurationToggling=!0,I("/api/toggleWireguardConfiguration/",{configurationName:this.c.Name},e=>{e.status?this.dashboardConfigurationStore.newMessage("Server",`${this.c.Name} ${e.data?"is on":"is off"}`):this.dashboardConfigurationStore.newMessage("Server",e.message,"danger"),this.c.Status=e.data,this.configurationToggling=!1})}}},T=()=>{B(e=>({d75b06ae:e.delay}))},P=N.setup;N.setup=P?(e,s)=>(T(),P(e,s)):T;const E={class:"card conf_card rounded-3 shadow text-decoration-none"},H={class:"mb-0"},Y={class:"card-title mb-0 d-flex align-items-center gap-2"},A={class:"card-footer d-flex gap-2 flex-column"},Q={class:"row"},X={class:"d-flex gap-2 align-items-center"},Z={class:"text-muted"},tt={class:"mb-0 d-block d-lg-inline-block"},et={style:{"line-break":"anywhere"}},st={class:"form-check form-switch ms-auto"},ot=["for"],it={key:4,class:"spinner-border spinner-border-sm ms-2","aria-hidden":"true"},nt=["disabled","id"];function at(e,s,o,f,a,g){const c=p("ProtocolBadge"),l=p("RouterLink"),d=p("LocaleText");return i(),n("div",{class:m(["col-12",{"col-lg-6 col-xl-4":this.display==="Grid"}])},[t("div",E,[r(l,{to:"/configuration/"+o.c.Name+"/peers",class:"card-body d-flex align-items-center gap-3 flex-wrap text-decoration-none"},{default:S(()=>[t("h6",H,[t("span",{class:m(["dot",{active:o.c.Status}])},null,2)]),t("h6",Y,[t("samp",null,u(o.c.Name),1),t("small",null,[r(c,{protocol:o.c.Protocol,mini:!0},null,8,["protocol"])])]),s[2]||(s[2]=t("h6",{class:"mb-0 ms-auto"},[t("i",{class:"bi bi-chevron-right"})],-1))]),_:1},8,["to"]),t("div",A,[t("div",Q,[t("small",{class:m(["col-6",{"col-md-3":this.display==="List"}])},[s[3]||(s[3]=t("i",{class:"bi bi-arrow-down-up me-2"},null,-1)),v(u(o.c.DataUsage.Total>0?o.c.DataUsage.Total.toFixed(4):0)+" GB ",1)],2),t("small",{class:m(["text-primary-emphasis col-6",{"col-md-3":this.display==="List"}])},[s[4]||(s[4]=t("i",{class:"bi bi-arrow-down me-2"},null,-1)),v(u(o.c.DataUsage.Receive>0?o.c.DataUsage.Receive.toFixed(4):0)+" GB ",1)],2),t("small",{class:m(["text-success-emphasis col-6",{"col-md-3":this.display==="List"}])},[s[5]||(s[5]=t("i",{class:"bi bi-arrow-up me-2"},null,-1)),v(u(o.c.DataUsage.Sent>0?o.c.DataUsage.Sent.toFixed(4):0)+" GB ",1)],2),t("small",{class:m(["col-6",{"col-md-3 text-md-end ":this.display==="List"}])},[t("span",{class:m(["dot me-2",{active:o.c.ConnectedPeers>0}])},null,2),v(" "+u(o.c.ConnectedPeers)+" / "+u(o.c.TotalPeers)+" ",1),r(d,{t:"Peers"})],2)]),t("div",{class:m(["d-flex gap-2",[this.display==="Grid"?"flex-column":"gap-lg-3 flex-column flex-lg-row"]])},[t("div",X,[t("small",Z,[t("strong",null,[r(d,{t:"Public Key"})])]),t("small",tt,[t("samp",et,u(o.c.PublicKey),1)])]),t("div",st,[t("label",{class:"form-check-label",style:{cursor:"pointer"},for:"switch"+o.c.PrivateKey},[!o.c.Status&&this.configurationToggling?(i(),_(d,{key:0,t:"Turning Off..."})):o.c.Status&&this.configurationToggling?(i(),_(d,{key:1,t:"Turning On..."})):o.c.Status&&!this.configurationToggling?(i(),_(d,{key:2,t:"On"})):!o.c.Status&&!this.configurationToggling?(i(),_(d,{key:3,t:"Off"})):y("",!0),this.configurationToggling?(i(),n("span",it)):y("",!0)],8,ot),U(t("input",{class:"form-check-input",style:{cursor:"pointer"},disabled:this.configurationToggling,type:"checkbox",role:"switch",id:"switch"+o.c.PrivateKey,onChange:s[0]||(s[0]=C=>this.toggle()),"onUpdate:modelValue":s[1]||(s[1]=C=>o.c.Status=C)},null,40,nt),[[V,o.c.Status]])])],2)])])],2)}const rt=D(N,[["render",at],["__scopeId","data-v-6451623a"]]),lt={class:"text-muted me-2"},ct={class:"fw-bold"},dt={__name:"storageMount",props:{mount:Object,align:Boolean,square:Boolean},setup(e){B(a=>({"38705f32":f.value}));const s=e,o=O(!1),f=K(()=>s.square?"40px":"25px");return(a,g)=>(i(),n("div",{class:"flex-grow-1 square rounded-3 border position-relative",onMouseenter:g[0]||(g[0]=c=>o.value=!0),onMouseleave:g[1]||(g[1]=c=>o.value=!1),style:L({"background-color":`rgb(25 135 84 / ${e.mount.percent}%)`})},[r(G,{name:"zoomReversed"},{default:S(()=>[o.value?(i(),n("div",{key:0,style:{"white-space":"nowrap"},class:m(["floatingLabel z-3 border position-absolute d-block p-1 px-2 bg-body text-body rounded-3 border shadow d-flex",[e.align?"end-0":"start-0"]])},[t("small",lt,[t("samp",null,u(e.mount.mountPoint),1)]),t("small",ct,u(e.mount.percent)+"% ",1)],2)):y("",!0)]),_:1})],36))}},ut=D(dt,[["__scopeId","data-v-a382214a"]]),mt={class:"row text-body g-3 mb-5"},gt={class:"col-md-6 col-sm-12 col-xl-3"},ht={class:"d-flex align-items-center"},ft={class:"text-muted"},_t={class:"ms-auto"},pt={key:0},yt={key:1,class:"spinner-border spinner-border-sm"},bt={class:"progress",role:"progressbar",style:{height:"6px"}},St={class:"d-flex mt-2 gap-1"},vt={class:"col-md-6 col-sm-12 col-xl-3"},xt={class:"d-flex align-items-center"},wt={class:"text-muted"},kt={class:"ms-auto"},Ct={key:0},Lt={key:1,class:"spinner-border spinner-border-sm"},Dt={class:"progress",role:"progressbar",style:{height:"6px"}},$t={class:"d-flex mt-2 gap-1"},Nt={class:"col-md-6 col-sm-12 col-xl-3"},Tt={class:"d-flex align-items-center"},Pt={class:"text-muted"},Mt={class:"ms-auto"},It={key:0},Ut={key:1,class:"spinner-border spinner-border-sm"},Bt={class:"progress",role:"progressbar",style:{height:"6px"}},Kt={class:"col-md-6 col-sm-12 col-xl-3"},Gt={class:"d-flex align-items-center"},Vt={class:"text-muted"},Ot={class:"ms-auto"},Rt={key:0},Wt={key:1,class:"spinner-border spinner-border-sm"},qt={__name:"systemStatusWidget",setup(e){const s=M();let o=null;R(()=>{f(),o=setInterval(()=>{f()},5e3)}),W(()=>{clearInterval(o)});const f=()=>{I("/api/systemStatus",{},g=>{s.SystemStatus=g.data})},a=K(()=>s.SystemStatus);return(g,c)=>(i(),n("div",mt,[t("div",gt,[t("div",ht,[t("h6",ft,[c[0]||(c[0]=t("i",{class:"bi bi-cpu-fill me-2"},null,-1)),r(x,{t:"CPU"})]),t("h6",_t,[a.value?(i(),n("span",pt,u(a.value.CPU.cpu_percent)+"% ",1)):(i(),n("span",yt))])]),t("div",bt,[t("div",{class:"progress-bar",style:L({width:`${a.value?.CPU.cpu_percent}%`})},null,4)]),t("div",St,[(i(!0),n(w,null,k(a.value?.CPU.cpu_percent_per_cpu,(l,d)=>(i(),_(J,{key:d,align:d+1>Math.round(a.value?.CPU.cpu_percent_per_cpu.length/2),core_number:d,percentage:l},null,8,["align","core_number","percentage"]))),128))])]),t("div",vt,[t("div",xt,[t("h6",wt,[c[1]||(c[1]=t("i",{class:"bi bi-device-ssd-fill me-2"},null,-1)),r(x,{t:"Storage"})]),t("h6",kt,[a.value?(i(),n("span",Ct,u(a.value?.Disks.find(l=>l.mountPoint==="/").percent)+"% ",1)):(i(),n("span",Lt))])]),t("div",Dt,[t("div",{class:"progress-bar bg-success",style:L({width:`${a.value?.Disks.find(l=>l.mountPoint==="/").percent}%`})},null,4)]),t("div",$t,[a.value?(i(!0),n(w,{key:0},k(a.value?.Disks,(l,d)=>(i(),_(ut,{key:l.mountPoint,align:d+1>Math.round(a.value?.Disks.length/2),mount:l},null,8,["align","mount"]))),128)):y("",!0)])]),t("div",Nt,[t("div",Tt,[t("h6",Pt,[c[2]||(c[2]=t("i",{class:"bi bi-memory me-2"},null,-1)),r(x,{t:"Memory"})]),t("h6",Mt,[a.value?(i(),n("span",It,u(a.value?.Memory.VirtualMemory.percent)+"% ",1)):(i(),n("span",Ut))])]),t("div",Bt,[t("div",{class:"progress-bar bg-info",style:L({width:`${a.value?.Memory.VirtualMemory.percent}%`})},null,4)])]),t("div",Kt,[t("div",Gt,[t("h6",Vt,[c[3]||(c[3]=t("i",{class:"bi bi-memory me-2"},null,-1)),r(x,{t:"Swap Memory"})]),t("h6",Ot,[a.value?(i(),n("span",Rt,u(a.value?.Memory.SwapMemory.percent)+"% ",1)):(i(),n("span",Wt))])]),c[4]||(c[4]=t("div",{class:"progress",role:"progressbar",style:{height:"6px"}},[t("div",{class:"progress-bar bg-warning",style:{width:"$ data?.Memory.SwapMemory.percent}%"}})],-1))])]))}},Ft=D(qt,[["__scopeId","data-v-c7f6d1a1"]]),zt={name:"configurationList",components:{SystemStatus:Ft,LocaleText:x,ConfigurationCard:rt},async setup(){return{wireguardConfigurationsStore:q()}},data(){return{configurationLoaded:!1,sort:{Name:$("Name"),Status:$("Status"),"DataUsage.Total":$("Total Usage")},currentSort:{key:"Name",order:"asc"},currentDisplay:"List",searchKey:""}},async mounted(){window.localStorage.getItem("ConfigurationListSort")?this.currentSort=JSON.parse(window.localStorage.getItem("ConfigurationListSort")):window.localStorage.setItem("ConfigurationListSort",JSON.stringify(this.currentSort)),window.localStorage.getItem("ConfigurationListDisplay")?this.currentDisplay=window.localStorage.getItem("ConfigurationListDisplay"):window.localStorage.setItem("ConfigurationListDisplay",this.currentDisplay),await this.wireguardConfigurationsStore.getConfigurations(),this.configurationLoaded=!0,this.wireguardConfigurationsStore.ConfigurationListInterval=setInterval(()=>{this.wireguardConfigurationsStore.getConfigurations()},1e4)},beforeUnmount(){clearInterval(this.wireguardConfigurationsStore.ConfigurationListInterval)},computed:{configurations(){return[...this.wireguardConfigurationsStore.Configurations].filter(e=>e.Name.toLowerCase().includes(this.searchKey)||e.PublicKey.includes(this.searchKey)||!this.searchKey).sort((e,s)=>this.currentSort.order==="desc"?this.dotNotation(e,this.currentSort.key)<this.dotNotation(s,this.currentSort.key)?1:this.dotNotation(e,this.currentSort.key)>this.dotNotation(s,this.currentSort.key)?-1:0:this.dotNotation(e,this.currentSort.key)>this.dotNotation(s,this.currentSort.key)?1:this.dotNotation(e,this.currentSort.key)<this.dotNotation(s,this.currentSort.key)?-1:0)}},methods:{dotNotation(e,s){let o=s.split(".").reduce((f,a)=>f&&f[a],e);return typeof o=="string"?o.toLowerCase():o},updateSort(e){this.currentSort.key===e?this.currentSort.order==="asc"?this.currentSort.order="desc":this.currentSort.order="asc":this.currentSort.key=e,window.localStorage.setItem("ConfigurationListSort",JSON.stringify(this.currentSort))},updateDisplay(e){this.currentDisplay!==e&&(this.currentDisplay=e,window.localStorage.setItem("ConfigurationListDisplay",this.currentDisplay))}}},jt={class:"mt-md-5 mt-3"},Jt={class:"container-fluid"},Et={class:"d-flex mb-4 configurationListTitle align-items-md-center gap-2 flex-column flex-md-row"},Ht={class:"text-body d-flex mb-0"},Yt={key:0,class:"text-body filter mb-3 d-flex gap-2 flex-column flex-md-row"},At={class:"d-flex align-items-center gap-3 align-items-center mb-3 mb-md-0"},Qt={class:"text-muted"},Xt={class:"d-flex ms-auto ms-lg-0"},Zt=["onClick"],te={class:"align-items-center gap-3 align-items-center mb-3 mb-md-0 d-none d-lg-flex"},ee={class:"text-muted"},se={class:"d-flex ms-auto ms-lg-0"},oe=["onClick"],ie={class:"d-flex align-items-center ms-md-auto"},ne={class:"row g-3 mb-2"},ae={class:"text-muted col-12",key:"noConfiguration"};function re(e,s,o,f,a,g){const c=p("SystemStatus"),l=p("LocaleText"),d=p("RouterLink"),C=p("ConfigurationCard");return i(),n("div",jt,[t("div",Jt,[r(c),t("div",Et,[t("h2",Ht,[r(l,{t:"WireGuard Configurations"})]),r(d,{to:"/new_configuration",class:"ms-md-auto py-2 text-decoration-none btn text-primary-emphasis bg-primary-subtle rounded-3 border-1 border-primary-subtle"},{default:S(()=>[s[1]||(s[1]=t("i",{class:"bi bi-plus-circle me-2"},null,-1)),r(l,{t:"Configuration"})]),_:1}),r(d,{to:"/restore_configuration",class:"py-2 text-decoration-none btn text-primary-emphasis bg-primary-subtle rounded-3 border-1 border-primary-subtle"},{default:S(()=>[s[2]||(s[2]=t("i",{class:"bi bi-clock-history me-2"},null,-1)),r(l,{t:"Restore"})]),_:1})]),r(G,{name:"fade"},{default:S(()=>[this.configurationLoaded?(i(),n("div",Yt,[t("div",At,[t("small",Qt,[r(l,{t:"Sort By"})]),t("div",Xt,[(i(!0),n(w,null,k(this.sort,(h,b)=>(i(),n("a",{role:"button",onClick:le=>g.updateSort(b),class:m([{"bg-primary-subtle text-primary-emphasis":this.currentSort.key===b},"px-2 py-1 rounded-3"])},[t("small",null,[this.currentSort.key===b?(i(),n("i",{key:0,class:m(["bi me-2",[this.currentSort.order==="asc"?"bi-sort-up":"bi-sort-down"]])},null,2)):y("",!0),v(u(h),1)])],10,Zt))),256))])]),t("div",te,[t("small",ee,[r(l,{t:"Display as"})]),t("div",se,[(i(),n(w,null,k([{name:"List",key:"list"},{name:"Grid",key:"grid"}],h=>t("a",{role:"button",onClick:b=>g.updateDisplay(h.name),class:m([{"bg-primary-subtle text-primary-emphasis":this.currentDisplay===h.name},"px-2 py-1 rounded-3"])},[t("small",null,[t("i",{class:m(["bi me-2","bi-"+h.key])},null,2),v(" "+u(h.name),1)])],10,oe)),64))])]),t("div",ie,[s[3]||(s[3]=t("label",{for:"configurationSearch",class:"text-muted"},[t("i",{class:"bi bi-search me-2"})],-1)),U(t("input",{class:"form-control form-control-sm rounded-3","onUpdate:modelValue":s[0]||(s[0]=h=>this.searchKey=h),id:"configurationSearch"},null,512),[[z,this.searchKey]])])])):y("",!0)]),_:1}),t("div",ne,[r(F,{name:"fade"},{default:S(()=>[this.configurationLoaded&&this.wireguardConfigurationsStore.Configurations.length===0?(i(),n("p",ae,[r(l,{t:"You don't have any WireGuard configurations yet. Please check the configuration folder or change it in Settings. By default the folder is /etc/wireguard."})])):this.configurationLoaded?(i(!0),n(w,{key:1},k(g.configurations,(h,b)=>(i(),_(C,{display:this.currentDisplay,delay:b*.03+"s",key:h.Name,c:h},null,8,["display","delay","c"]))),128)):y("",!0)]),_:1})])])])}const ge=D(zt,[["render",re],["__scopeId","data-v-0ac2bdcc"]]);export{ge as default};