mirror of
https://github.com/WGDashboard/WGDashboard.git
synced 2026-08-03 22:42:59 +00:00
2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{L as h}from"./localeText-9CAvqGoH.js";import{_ as b,a as i,c as n,b as t,d as l,m as d,x as p,n as u,j as m,D as v,W as y,v as w,G as K,w as S,F as g,h as I,f as A,t as k,k as P,e as x}from"./index-Cn-2kELJ.js";const L={name:"nameInput",components:{LocaleText:h},props:{bulk:Boolean,data:Object,saving:Boolean}},D={for:"peer_name_textbox",class:"form-label"},T={class:"text-muted"},B=["disabled"];function N(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",{class:u({inactiveField:this.bulk})},[t("label",D,[t("small",T,[l(o,{t:"Name"})])]),d(t("input",{type:"text",class:"form-control form-control-sm rounded-3",disabled:this.saving||this.bulk,"onUpdate:modelValue":e[0]||(e[0]=s=>this.data.name=s),id:"peer_name_textbox",placeholder:""},null,8,B),[[p,this.data.name]])],2)}const Ze=b(L,[["render",N]]),C={name:"privatePublicKeyInput",components:{LocaleText:h},props:{data:Object,saving:Boolean,bulk:Boolean},setup(){const a=v(),e=y();return{dashboardStore:a,wgStore:e}},data(){return{keypair:{publicKey:"",privateKey:"",presharedKey:""},editKey:!1,error:!1}},methods:{genKeyPair(){this.editKey=!1,this.keypair=window.wireguard.generateKeypair(),this.data.private_key=this.keypair.privateKey,this.data.public_key=this.keypair.publicKey},testKey(a){return/^[A-Za-z0-9+/]{43}=?=?$/.test(a)},checkMatching(){try{this.keypair.privateKey&&this.wgStore.checkWGKeyLength(this.keypair.privateKey)&&(this.keypair.publicKey=window.wireguard.generatePublicKey(this.keypair.privateKey),window.wireguard.generatePublicKey(this.keypair.privateKey)!==this.keypair.publicKey?(this.error=!0,this.dashboardStore.newMessage("WGDashboard","Private key does not match with the public key","danger")):(this.data.private_key=this.keypair.privateKey,this.data.public_key=this.keypair.publicKey))}catch{this.error=!0,this.data.private_key="",this.data.public_key=""}}},mounted(){this.genKeyPair()},watch:{keypair:{deep:!0,handler(){this.error=!1,this.checkMatching()}}}},V={for:"peer_private_key_textbox",class:"form-label"},U={class:"text-muted"},M={class:"input-group"},O=["disabled"],E=["disabled"],G={class:"d-flex"},j={for:"public_key",class:"form-label"},F={class:"text-muted"},R={class:"form-check form-switch ms-auto"},W=["disabled"],q={class:"form-check-label",for:"enablePublicKeyEdit"},J=["disabled"];function z(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",{class:u(["d-flex gap-2 flex-column",{inactiveField:this.bulk}])},[t("div",null,[t("label",V,[t("small",U,[l(o,{t:"Private Key"}),t("code",null,[l(o,{t:"(Required for QR Code and Download)"})])])]),t("div",M,[d(t("input",{type:"text",class:u(["form-control form-control-sm rounded-start-3",{"is-invalid":this.error}]),"onUpdate:modelValue":e[0]||(e[0]=s=>this.keypair.privateKey=s),disabled:!this.editKey||this.bulk,onBlur:e[1]||(e[1]=s=>this.checkMatching()),id:"peer_private_key_textbox"},null,42,O),[[p,this.keypair.privateKey]]),t("button",{class:"btn btn-outline-info btn-sm rounded-end-3",onClick:e[2]||(e[2]=s=>this.genKeyPair()),disabled:this.bulk,type:"button",id:"button-addon2"},e[6]||(e[6]=[t("i",{class:"bi bi-arrow-repeat"},null,-1)]),8,E)])]),t("div",null,[t("div",G,[t("label",j,[t("small",F,[l(o,{t:"Public Key"}),t("code",null,[l(o,{t:"(Required)"})])])]),t("div",R,[d(t("input",{class:"form-check-input",type:"checkbox",role:"switch",disabled:this.bulk,id:"enablePublicKeyEdit","onUpdate:modelValue":e[3]||(e[3]=s=>this.editKey=s)},null,8,W),[[w,this.editKey]]),t("label",q,[t("small",null,[l(o,{t:"Use your own Private and Public Key"})])])])]),d(t("input",{class:u(["form-control-sm form-control rounded-3",{"is-invalid":this.error}]),"onUpdate:modelValue":e[4]||(e[4]=s=>this.keypair.publicKey=s),onBlur:e[5]||(e[5]=s=>this.checkMatching()),disabled:!this.editKey||this.bulk,type:"text",id:"public_key"},null,42,J),[[p,this.keypair.publicKey]])])],2)}const Xe=b(C,[["render",z]]),H={name:"allowedIPsInput",components:{LocaleText:h},props:{data:Object,saving:Boolean,bulk:Boolean,availableIp:void 0},data(){return{allowedIp:[],availableIpSearchString:"",customAvailableIp:"",allowedIpFormatError:!1}},setup(){const a=y(),e=v();return{store:a,dashboardStore:e}},computed:{searchAvailableIps(){return this.availableIpSearchString?this.availableIp.filter(a=>a.includes(this.availableIpSearchString)&&!this.data.allowed_ips.includes(a)):this.availableIp.filter(a=>!this.data.allowed_ips.includes(a))},inputGetLocale(){return K("Enter IP Address/CIDR")}},methods:{addAllowedIp(a){return this.store.checkCIDR(a)?(this.data.allowed_ips.push(a),this.customAvailableIp="",!0):(this.allowedIpFormatError=!0,this.dashboardStore.newMessage("WGDashboard","Allowed IPs is invalid","danger"),!1)}},watch:{customAvailableIp(){this.allowedIpFormatError=!1},availableIp(){}},mounted(){this.availableIp!==void 0&&this.availableIp.length>0&&this.data.allowed_ips.length===0&&this.addAllowedIp(this.availableIp[0])}},Q={for:"peer_allowed_ip_textbox",class:"form-label"},Y={class:"text-muted"},Z=["onClick"],X={class:"d-flex gap-2 align-items-center"},ee={class:"input-group"},te=["placeholder","disabled"],se=["disabled"],ae={class:"text-muted"},oe={class:"dropdown flex-grow-1"},le=["disabled"],ie={key:0,class:"dropdown-menu mt-2 shadow w-100 dropdown-menu-end rounded-3",style:{"overflow-y":"scroll","max-height":"270px",width:"300px !important"}},ne={class:"px-3 pb-2 pt-1 d-flex gap-3 align-items-center"},de=["onClick"],re={class:"me-auto"},ce={key:0},pe={class:"px-3 text-muted"};function ue(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",{class:u({inactiveField:this.bulk})},[t("label",Q,[t("small",Y,[l(o,{t:"Allowed IPs"}),t("code",null,[l(o,{t:"(Required)"})])])]),t("div",{class:u(["d-flex gap-2 flex-wrap",{"mb-2":this.data.allowed_ips.length>0}])},[l(P,{name:"list"},{default:S(()=>[(i(!0),n(g,null,I(this.data.allowed_ips,(s,$)=>(i(),n("span",{class:"badge rounded-pill text-bg-success",key:s},[A(k(s)+" ",1),t("a",{role:"button",onClick:He=>this.data.allowed_ips.splice($,1)},e[3]||(e[3]=[t("i",{class:"bi bi-x-circle-fill ms-1"},null,-1)]),8,Z)]))),128))]),_:1})],2),t("div",X,[t("div",ee,[d(t("input",{type:"text",class:u(["form-control form-control-sm rounded-start-3",{"is-invalid":this.allowedIpFormatError}]),placeholder:this.inputGetLocale,"onUpdate:modelValue":e[0]||(e[0]=s=>c.customAvailableIp=s),id:"peer_allowed_ip_textbox",disabled:r.bulk},null,10,te),[[p,c.customAvailableIp]]),t("button",{class:"btn btn-outline-success btn-sm rounded-end-3",disabled:r.bulk||!this.customAvailableIp,onClick:e[1]||(e[1]=s=>this.addAllowedIp(this.customAvailableIp)),type:"button",id:"button-addon2"},e[4]||(e[4]=[t("i",{class:"bi bi-plus-lg"},null,-1)]),8,se)]),t("small",ae,[l(o,{t:"or"})]),t("div",oe,[t("button",{class:"btn btn-outline-secondary btn-sm dropdown-toggle rounded-3 w-100",disabled:!r.availableIp||r.bulk,"data-bs-auto-close":"outside",type:"button","data-bs-toggle":"dropdown","aria-expanded":"false"},[e[5]||(e[5]=t("i",{class:"bi bi-filter-circle me-2"},null,-1)),l(o,{t:"Pick Available IP"})],8,le),this.availableIp?(i(),n("ul",ie,[t("li",null,[t("div",ne,[e[6]||(e[6]=t("label",{for:"availableIpSearchString",class:"text-muted"},[t("i",{class:"bi bi-search"})],-1)),d(t("input",{id:"availableIpSearchString",class:"form-control form-control-sm rounded-3","onUpdate:modelValue":e[2]||(e[2]=s=>this.availableIpSearchString=s)},null,512),[[p,this.availableIpSearchString]])])]),(i(!0),n(g,null,I(this.searchAvailableIps,s=>(i(),n("li",null,[t("a",{class:"dropdown-item d-flex",role:"button",onClick:$=>this.addAllowedIp(s)},[t("span",re,[t("small",null,k(s),1)])],8,de)]))),256)),this.searchAvailableIps.length===0?(i(),n("li",ce,[t("small",pe,[l(o,{t:"No available IP containing"}),A(' "'+k(this.availableIpSearchString)+'"',1)])])):x("",!0)])):x("",!0)])])],2)}const et=b(H,[["render",ue],["__scopeId","data-v-33f98fd0"]]),he={name:"dnsInput",components:{LocaleText:h},props:{data:Object,saving:Boolean},data(){return{error:!1,dns:JSON.parse(JSON.stringify(this.data.DNS))}},setup(){const a=y(),e=v();return{store:a,dashboardStore:e}},methods:{checkDNS(){if(this.dns){let a=this.dns.split(",").map(e=>e.replaceAll(" ",""));for(let e in a)if(!this.store.regexCheckIP(a[e])){this.error||this.dashboardStore.newMessage("WGDashboard","DNS format is incorrect","danger"),this.error=!0,this.data.DNS="";return}this.error=!1,this.data.DNS=this.dns}}},watch:{dns(){this.checkDNS()}}},be={for:"peer_DNS_textbox",class:"form-label"},me={class:"text-muted"},_e=["disabled"];function fe(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("label",be,[t("small",me,[l(o,{t:"DNS"})])]),d(t("input",{type:"text",class:u(["form-control form-control-sm rounded-3",{"is-invalid":this.error}]),disabled:this.saving,"onUpdate:modelValue":e[0]||(e[0]=s=>this.dns=s),id:"peer_DNS_textbox"},null,10,_e),[[p,this.dns]])])}const tt=b(he,[["render",fe]]),ve={name:"endpointAllowedIps",components:{LocaleText:h},props:{data:Object,saving:Boolean},setup(){const a=y(),e=v();return{store:a,dashboardStore:e}},data(){return{endpointAllowedIps:JSON.parse(JSON.stringify(this.data.endpoint_allowed_ip)),error:!1}},methods:{checkAllowedIP(){let a=this.endpointAllowedIps.split(",").map(e=>e.replaceAll(" ",""));for(let e in a)if(!this.store.checkCIDR(a[e])){this.error||this.dashboardStore.newMessage("WGDashboard","Endpoint Allowed IPs format is incorrect","danger"),this.data.endpoint_allowed_ip="",this.error=!0;return}this.error=!1,this.data.endpoint_allowed_ip=this.endpointAllowedIps}},watch:{endpointAllowedIps(){this.checkAllowedIP()}}},ye={for:"peer_endpoint_allowed_ips",class:"form-label"},ke={class:"text-muted"},xe=["disabled"];function we(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("label",ye,[t("small",ke,[l(o,{t:"Endpoint Allowed IPs"}),t("code",null,[l(o,{t:"(Required)"})])])]),d(t("input",{type:"text",class:u(["form-control form-control-sm rounded-3",{"is-invalid":c.error}]),disabled:this.saving,"onUpdate:modelValue":e[0]||(e[0]=s=>this.endpointAllowedIps=s),onBlur:e[1]||(e[1]=s=>this.checkAllowedIP()),id:"peer_endpoint_allowed_ips"},null,42,xe),[[p,this.endpointAllowedIps]])])}const st=b(ve,[["render",we]]),$e={name:"presharedKeyInput",components:{LocaleText:h},props:{data:Object,saving:Boolean},data(){return{enable:!1}},watch:{enable(){this.enable?this.data.preshared_key=window.wireguard.generateKeypair().presharedKey:this.data.preshared_key=""}}},ge={class:"d-flex align-items-start"},Ie={for:"peer_preshared_key_textbox",class:"form-label"},Ae={class:"text-muted"},Ke={class:"form-check form-switch ms-auto"},Se=["disabled"];function Pe(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("div",ge,[t("label",Ie,[t("small",Ae,[l(o,{t:"Pre-Shared Key"})])]),t("div",Ke,[d(t("input",{class:"form-check-input",type:"checkbox",role:"switch","onUpdate:modelValue":e[0]||(e[0]=s=>this.enable=s),id:"peer_preshared_key_switch"},null,512),[[w,this.enable]])])]),d(t("input",{type:"text",class:"form-control form-control-sm rounded-3",disabled:this.saving||!this.enable,"onUpdate:modelValue":e[1]||(e[1]=s=>this.data.preshared_key=s),id:"peer_preshared_key_textbox"},null,8,Se),[[p,this.data.preshared_key]])])}const at=b($e,[["render",Pe]]),Le={name:"mtuInput",components:{LocaleText:h},props:{data:Object,saving:Boolean}},De={for:"peer_mtu",class:"form-label"},Te={class:"text-muted"},Be=["disabled"];function Ne(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("label",De,[t("small",Te,[l(o,{t:"MTU"})])]),d(t("input",{type:"number",class:"form-control form-control-sm rounded-3",disabled:this.saving,"onUpdate:modelValue":e[0]||(e[0]=s=>this.data.mtu=s),min:"0",id:"peer_mtu"},null,8,Be),[[p,this.data.mtu]])])}const ot=b(Le,[["render",Ne]]),Ce={name:"persistentKeepAliveInput",components:{LocaleText:h},props:{data:Object,saving:Boolean}},Ve={for:"peer_keep_alive",class:"form-label"},Ue={class:"text-muted"},Me=["disabled"];function Oe(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("label",Ve,[t("small",Ue,[l(o,{t:"Persistent Keepalive"})])]),d(t("input",{type:"number",class:"form-control form-control-sm rounded-3",disabled:this.saving,"onUpdate:modelValue":e[0]||(e[0]=s=>this.data.keepalive=s),id:"peer_keep_alive"},null,8,Me),[[p,this.data.keepalive]])])}const lt=b(Ce,[["render",Oe]]),Ee={name:"bulkAdd",components:{LocaleText:h},props:{saving:Boolean,data:Object,availableIp:void 0},computed:{bulkAddGetLocale(){return K("How many peers you want to add?")}}},Ge={class:"form-check form-switch"},je=["disabled"],Fe={class:"form-check-label me-2",for:"bulk_add"},Re={class:"text-muted d-block"},We={key:0,class:"form-group"},qe=["max","placeholder"],Je={class:"text-muted"};function ze(a,e,r,_,c,f){const o=m("LocaleText");return i(),n("div",null,[t("div",Ge,[d(t("input",{class:"form-check-input",type:"checkbox",role:"switch",disabled:!this.availableIp,id:"bulk_add","onUpdate:modelValue":e[0]||(e[0]=s=>this.data.bulkAdd=s)},null,8,je),[[w,this.data.bulkAdd]]),t("label",Fe,[t("small",null,[t("strong",null,[l(o,{t:"Bulk Add"})])])])]),t("p",{class:u({"mb-0":!this.data.bulkAdd})},[t("small",Re,[l(o,{t:"By adding peers by bulk, each peer's name will be auto generated, and Allowed IP will be assign to the next available IP."})])],2),this.data.bulkAdd?(i(),n("div",We,[d(t("input",{class:"form-control form-control-sm rounded-3 mb-1",type:"number",min:"1",id:"bulk_add_count",max:this.availableIp.length,"onUpdate:modelValue":e[1]||(e[1]=s=>this.data.bulkAddAmount=s),placeholder:this.bulkAddGetLocale},null,8,qe),[[p,this.data.bulkAddAmount]]),t("small",Je,[l(o,{t:"You can add up to "+this.availableIp.length+" peers"},null,8,["t"])])])):x("",!0)])}const it=b(Ee,[["render",ze]]);export{et as A,it as B,tt as D,st as E,ot as M,Ze as N,lt as P,at as a,Xe as b};
|