mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 15:56:17 +00:00
8 lines
32 KiB
JavaScript
8 lines
32 KiB
JavaScript
![]() |
import{_ as M,E as J,W as Y,o as z,H as q,D as H,r as y,I as G,c as h,f as v,a as e,b as s,m as C,y as S,n as B,z as L,t as P,h as Q,a3 as X,d as N,s as D,j as R,F as V,i as K,C as ee,a4 as te,e as O,K as A,L as se,u as T,g as I,p as ne,q as oe,w as U,k as j,a5 as le,T as Z,J as ie,v as ae}from"./index-B0dMp2t9.js";import{L as n}from"./localeText-BGcLidCW.js";import{d as de}from"./dayjs.min-D1w58XPc.js";const re={class:"card rounded-3 flex-grow-1 bg-danger-subtle border-danger-subtle border shadow"},ue={class:"card-body"},ce={class:"d-flex align-items-center gap-3 inputGroup"},me=["value"],fe={class:"mb-0"},ge={class:"d-flex mt-3"},be=["disabled"],ve={__name:"updateConfigurationName",props:{configurationName:String},emits:["close"],setup(d,{emit:r}){const t=d,f=r,o=J({data:"",valid:!1}),g=Y();z(()=>{q(()=>o.data,b=>{o.valid=/^[a-zA-Z0-9_=+.-]{1,15}$/.test(b)&&b.length>0&&!g.Configurations.find(_=>_.Name===b)})});const u=H(),x=y(!1),c=G(),a=async()=>{o.data&&(x.value=!0,clearInterval(u.Peers.RefreshInterval),await L("/api/renameWireguardConfiguration",{ConfigurationName:t.configurationName,NewConfigurationName:o.data},async b=>{b.status?(await g.getConfigurations(),u.newMessage("Server","Configuration renamed","success"),c.push(`/configuration/${o.data}/peers`)):(u.newMessage("Server",b.message,"danger"),x.value=!1)}))};return(b,_)=>(v(),h("div",re,[e("div",ue,[e("p",null,[s(n,{t:"To update this configuration's name, WGDashboard will execute the following operations:"})]),e("ol",null,[e("li",null,[s(n,{t:"Duplicate current configuration's database table and .conf file with the new name"})]),e("li",null,[s(n,{t:"Delete current configuration's database table and .conf file"})])]),e("div",ce,[e("input",{class:"form-control form-control-sm rounded-3",value:d.configurationName,disabled:""},null,8,me),_[3]||(_[3]=e("h3",{class:"mb-0"},[e("i",{class:"bi bi-arrow-right"})],-1)),C(e("input",{class:B(["form-control form-control-sm rounded-3",[o.data?o.valid?"is-valid":"is-invalid":""]]),id:"newConfigurationName","onUpdate:modelValue":_[0]||(_[0]=w=>o.data=w)},null,2),[[S,o.data]])]),e("div",{class:B(["invalid-feedback",{"d-block":!o.valid&&o.data}])},[s(n,{t:"Configuration name is invalid. Possible reasons:"}),e("ul",fe,[e("li",null,[s(n,{t:"Configuration name already exist"})]),e("li",null,[s(n,{t:"Configuration name can only contain 15 lower/uppercase alphabet, numbers, underscore, equal sign, plus sign, period and hyphen."})])])],2),e("div",ge,[e("button",{onClick:_[1]||(_[1]=w=>f("close")),class:"btn btn-sm bg-secondary-subtle border-secondary-subtle text-secondary-emphasis rounded-3"},[s(n,{t:"Cancel"})]),e("button",{onClick:_[2]||(_[2]=w=>a()),disabled:!o.data||x.value,class:"btn btn-sm btn-danger rounded-3 ms-auto"},[s(n,{t:"Save"})],8,be)])])]))}},pe=M(ve,[["__scopeId","data-v-33ea9576"]]),he={name:"Dropdown",props:{width:{type:String,default:"80px"},height:{type:String,default:"auto"},title:{type:String,default:""},disabled:{type:Boolean,default:!1},defaultDisplay:{type:Boolean,default:!1}}},ye={class:"title"};function xe(d,r,t,f,o,g){return v(),h("div",{class:B(["dropdown",{disabled:t.disabled}]),onClick:r[0]||(r[0]=(...u)=>d.toggleDropdown&&d.toggleDropdown(...u)),onFocusout:r[1]||(r[1]=(...u)=>d.hideDropdown&&d.hideDropdown(...u)),tabindex:"0"},[e("div",ye,[e("div",null,P(t.title),1)])],34)}const _e=M(he,[["render",xe]]),we={components:{Dropdown:_e},name:"CodeEditor",props:{lineNums:{type:Boolean,default:!1},modelValue:{type:String},value:{type:String},theme:{type:String,default:"github-dark"},tabSpaces:{type:Number,default:2},wrap:{type:Boolean,default:!1},readOnly:{type:Boolean,default:!1},autofocus:{type:Boolean,default:!1},header:{type:Boolean,default:!0},width:{type:String,default:"540px"},height:{type:String,default:"auto"},maxWidth:{type:String},minWidth:{type:String},maxHeight:{type:String},minHeight:{type:String},borderRadius:{type:String,default:"12px"},languages:{type:Array,default:function(){return[["javascript","JS"]]}},langListWidth:{type:String,default:"110px"},langListHeight:{type:String,default:"auto"}
|
|||
|
`:this.modelValue+`
|
|||
|
`},scroll(){return this.height!="auto"}},methods:{updateValue(d){this.modelValue==null?this.content=d.target.value:this.$emit("update:modelValue",d.target.value)},changeLang(d){this.languageTitle=d[1]?d[1]:d[0],this.languageClass="language-"+d[0],this.$emit("lang",d[0])},tab(){if(document.execCommand("insertText"))document.execCommand("insertText",!1,this.tabWidth);else{const d=this.$refs.textarea.selectionStart;this.content=this.content.substring(0,d)+this.tabWidth+this.content.substring(d),this.cursorPosition=d+this.tabWidth.length,this.insertTab=!0}},calcScrollDistance(d){this.$refs.code.scrolling=!0,this.scrolling=!0,this.top=-d.target.scrollTop,this.left=-d.target.scrollLeft},resizer(){new ResizeObserver(t=>{this.scrollBarWidth=t[0].target.offsetWidth-t[0].target.clientWidth,this.scrollBarHeight=t[0].target.offsetHeight-t[0].target.clientHeight,this.textareaHeight=t[0].target.offsetHeight}).observe(this.$refs.textarea);const r=new ResizeObserver(t=>{this.lineNumsWidth=t[0].target.offsetWidth});this.$refs.lineNums&&r.observe(this.$refs.lineNums)},copy(){document.execCommand("copy")?(this.$refs.textarea.select(),document.execCommand("copy"),window.getSelection().removeAllRanges()):navigator.clipboard.writeText(this.$refs.textarea.value)},getLineNum(){const d=this.$refs.textarea.value;let r=0,t=d.indexOf(`
|
|||
|
`);for(;t!==-1;)r++,t=d.indexOf(`
|
|||
|
`,t+1);const f=this.$refs.lineNums.firstChild.offsetHeight,o=parseInt(this.textareaHeight/f)-1;this.lineNum=this.height=="auto"||r>o?r:o}},mounted(){this.$emit("lang",this.languages[0][0]),this.$emit("content",this.content),this.$emit("textarea",this.$refs.textarea),this.resizer()},updated(){this.insertTab&&(this.$refs.textarea.setSelectionRange(this.cursorPosition,this.cursorPosition),this.insertTab=!1),this.lineNums&&(this.scrolling?this.scrolling=!1:this.getLineNum())}},ke=["theme"],Ce=["readOnly","autofocus","value"];function $e(d,r,t,f,o,g){const u=Q("Dropdown"),x=X("highlight");return v(),h("div",{theme:t.theme,class:B(["code-editor",{"hide-header":!t.header,scroll:g.scroll,"read-only":t.readOnly,wrap:t.wrap}]),style:D({width:t.width,height:t.height,zIndex:t.zIndex,maxWidth:t.maxWidth,minWidth:t.minWidth,maxHeight:t.maxHeight,minHeight:t.minHeight})},[e("div",{class:"hljs",style:D({borderRadius:t.borderRadius})},[t.header?(v(),h("div",{key:0,class:B(["header",{border:o.showLineNums}]),style:D({borderRadius:t.borderRadius+" "+t.borderRadius+" 0 0"})},[t.displayLanguage?(v(),R(u,{key:0,width:t.langListWidth,title:o.languageTitle,disabled:t.languages.length<=1,defaultDisplay:t.langListDisplay},null,8,["width","title","disabled","defaultDisplay"])):N("",!0)],6)):N("",!0),e("div",{class:"code-area",style:D({borderRadius:t.header?"0 0 "+t.borderRadius+" "+t.borderRadius:t.borderRadius})},[o.showLineNums?(v(),h("div",{key:0,ref:"lineNums",class:"line-nums hljs",style:D({fontSize:t.fontSize,paddingTop:t.header?"10px":t.padding,paddingBottom:t.padding,top:o.top+"px"})},[r[3]||(r[3]=e("div",null,"1",-1)),(v(!0),h(V,null,K(o.lineNum,c=>(v(),h("div",null,P(c+1),1))),256)),r[4]||(r[4]=e("div",null," ",-1))],4)):N("",!0),e("textarea",{title:"textarea",readOnly:t.readOnly,style:D({fontSize:t.fontSize,padding:t.header?t.lineNums?"10px "+t.padding+" "+t.padding:"0 "+t.padding+" "+t.padding:t.padding,marginLeft:o.showLineNums?o.lineNumsWidth+"px":"0",width:o.showLineNums?"calc(100% - "+o.lineNumsWidth+"px)":"100%"}),ref:"textarea",autofocus:t.autofocus,spellcheck:"false",onKeydown:r[0]||(r[0]=ee(te((...c)=>g.tab&&g.tab(...c),["prevent","stop"]),["tab"])),onScroll:r[1]||(r[1]=(...c)=>g.calcScrollDistance&&g.calcScrollDistance(...c)),value:t.modelValue==null?o.content:t.modelValue,onInput:r[2]||(r[2]=(...c)=>g.updateValue&&g.updateValue(...c))},null,44,Ce),e("pre",{style:D({paddingRight:o.scrollBarWidth+"px",paddingBottom:o.scrollBarHeight+"px",marginLeft:o.showLineNums?o.lineNumsWidth+"px":"0",width:o.showLineNums?"calc(100% - "+o.lineNumsWidth+"px)":"100%"})},[r[6]||(r[6]=O(" ")),C((v(),h("code",{ref:"code",class:B(o.languageClass),style:D({top:o.top+"px",left:o.left+"px",fontSize:t.fontSize,padding:t.header?t.lineNums?"10px "+t.padding+" "+t.padding:"0 "+t.padding+" "+t.padding:t.padding})},r[5]||(r[5]=[O(`
|
|||
|
`)]),6)),[[x,g.contentValue]]),r[7]||(r[7]=O(`
|
|||
|
`))],4)],4)],4)],14,ke)}const Se=M(we,[["render",$e]]),Ne={class:"peerSettingContainer w-100 h-100 position-absolute top-0 start-0 overflow-y-scroll"},Pe={class:"container d-flex h-100 w-100"},Be={class:"m-auto modal-dialog-centered dashboardModal",style:{width:"1000px"}},Re={class:"card rounded-3 shadow flex-grow-1",id:"deleteConfigurationContainer"},De={class:"card-header bg-transparent d-flex align-items-center gap-2 border-0 p-4 pb-0"},Le={class:"mb-0"},We={class:"card-body px-4 d-flex flex-column gap-3"},Ve={key:0,class:"alert alert-danger rounded-3 mb-0"},Oe={class:"mb-2"},Ie={class:"bg-body w-100 p-2 rounded-3"},Me={class:"d-flex gap-2"},He=["disabled"],Ke=["disabled"],Te={__name:"editRawConfigurationFile",emits:["close"],async setup(d,{emit:r}){let t,f;const o=r,g=A(),u=y(""),x=y(""),c=y(!1),a=y(""),b=async()=>{await I("/api/getWireguardConfigurationRawFile",{configurationName:g.params.id},m=>{u.value=m.data.content,x.value=m.data.path})};[t,f]=se(()=>b()),await t,f();const _=H(),w=y(!1),$=async()=>{w.value=!0,await L("/api/updateWireguardConfigurationRawFile",{configurationName:g.params.id,rawConfiguration:u.value},m=>{m.status?(c.value=!1,_.newMessage("Server","Configuration saved","success")):(c.value=!0,a.value=m.message),w.value=!1})};return(m,i)=>(v(),h("div",Ne,[e("div",Pe,[e("div",Be,[e("div",Re,[e("div",De,[e("h5",Le,[s(n,{t:"Edit Raw Configuration File"})]),e("button",{type:"button",class:"btn-close ms-auto",onClick:i[0]||(i[0]=k=>o("close"))})]),e("div",We,[c.value?(v(),h("div",Ve,[e("div",Oe,[e("strong",null,[s(n,{t:"Failed to save configuration. Please see the following error message:"})])]),e("div",Ie,[e("pre",null,P(a.value),1)])])):N("",!0),s(Se,{disabled:!0,"read-only":w.value,modelValue:u.value,"onUpdate:modelValue":i[1]||(i[1]=k=>u.value=k),theme:T(_).Configuration.Server.dashboard_theme==="dark"?"github-dark":"github",languages:[["ini",x.value]],width:"100%",height:"600px"},null,8,["read-only","modelValue","theme","languages"]),e("div",Me,[e("button",{class:"btn bg-secondary-subtle border-secondary-subtle text-secondary-emphasis rounded-3 shadow ms-auto px-3 py-2",disabled:w.value,onClick:i[2]||(i[2]=k=>b())},[i[4]||(i[4]=e("i",{class:"bi bi-arrow-clockwise me-2"},null,-1)),s(n,{t:"Reset"})],8,He),e("button",{onClick:i[3]||(i[3]=k=>$()),disabled:w.value,class:"btn bg-danger-subtle border-danger-subtle text-danger-emphasis rounded-3 px-3 py-2 shadow"},[i[5]||(i[5]=e("i",{class:"bi bi-save-fill me-2"},null,-1)),w.value?(v(),R(n,{key:1,t:"Saving..."})):(v(),R(n,{key:0,t:"Save"}))],8,Ke)])])])])])]))}},Ue={class:"peerSettingContainer w-100 h-100 position-absolute top-0 start-0 overflow-y-scroll"},ze={class:"container d-flex h-100 w-100"},Ae={class:"m-auto modal-dialog-centered dashboardModal",style:{width:"700px"}},Ee={class:"card rounded-3 shadow flex-grow-1 bg-danger-subtle border-danger-subtle",id:"deleteConfigurationContainer"},Fe={class:"card-header bg-transparent d-flex align-items-center gap-2 border-0 p-4 pb-0"},Je={class:"mb-0"},je={class:"card-body px-4 text-muted"},Ye={class:"mb-0"},qe={key:0},Ge={key:1},Ze={key:2,class:"d-flex align-items-center gap-2"},Qe=["placeholder"],Xe=["disabled"],et={__name:"deleteConfiguration",emits:["backup","close"],setup(d,{emit:r}){const f=A().params.id,o=y(""),g=G(),u=H(),x=y(!1),c=()=>{clearInterval(u.Peers.RefreshInterval),x.value=!0,L("/api/deleteWireguardConfiguration",{ConfigurationName:f},$=>{$.status?(g.push("/"),u.newMessage("Server","Configuration deleted","success")):x.value=!1})},a=y(!0),b=y([]),_=()=>{a.value=!0,I("/api/getWireguardConfigurationBackup",{configurationName:f},$=>{b.value=$.data,a.value=!1})};z(()=>{_()});const w=r;return($,m)=>(v(),h("div",Ue,[e("div",ze,[e("div",Ae,[e("div",Ee,[e("div",Fe,[e("h5",Je,[s(n,{t:"Are you sure to delete this configuration?"})]),e("button",{type:"button",class:"btn-close ms-auto",onClick:m[0]||(m[0]=i=>w("close"))})]),e("div",je,[e("p",Ye,[s(n,{t:"Once you deleted this configuration:"})]),e("ul",null,[e("li",null,[s(n,{t:"All connected peers will get disconnected"})]),e("li",null,[s(n,{t:"Both
|