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