WGDashboard/src/static/app/dist/assets/restoreConfiguration-CVzQ-3U1.js

5 lines
14 KiB
JavaScript
Raw Normal View History

2025-03-16 00:42:40 +08:00
import{_ as T,r as k,o as A,a as n,c as r,b as e,t as x,F as N,h as D,i as f,d as l,n as v,A as W,e as w,E as z,W as F,p as C,H as G,D as E,I as H,m as g,x as _,f as $,z as Z,g as J,w as B,T as V,j as Q}from"./index-Bja4Mv1s.js";import{L as o}from"./localeText-8y47teqm.js";import{d as X}from"./dayjs.min-CXXFlLxk.js";import{_ as q}from"./protocolBadge-1mLYDB9f.js";import{p as O}from"./index-L60y6kc9.js";const ee={class:"card rounded-3 shadow-sm"},te={class:"mb-0 d-flex align-items-center gap-3"},se={class:"text-muted ms-auto d-block"},oe={key:0,class:"card-footer p-3 d-flex flex-column gap-2"},le=["onClick","id"],ne={class:"card-body d-flex p-3 gap-3 align-items-center"},ae={__name:"backupGroup",props:{configurationName:String,backups:Array,open:!1,selectedConfigurationBackup:Object,protocol:Array},emits:["select"],setup(m,{emit:u}){const t=m,y=u,p=k(t.open);return A(()=>{t.selectedConfigurationBackup&&document.querySelector(`#${t.selectedConfigurationBackup.filename.replace(".conf","")}`).scrollIntoView({behavior:"smooth"})}),(h,a)=>(n(),r("div",ee,[e("a",{role:"button",class:"card-body d-flex align-items-center text-decoration-none d-flex gap-3",onClick:a[0]||(a[0]=c=>p.value=!p.value)},[e("h6",te,[e("samp",null,x(m.configurationName),1),(n(!0),r(N,null,D(m.protocol,c=>(n(),f(q,{protocol:c},null,8,["protocol"]))),256))]),e("small",se,[l(o,{t:m.backups.length+(m.backups.length>1?" Backups":" Backup")},null,8,["t"])]),e("h5",{class:v(["mb-0 dropdownIcon text-muted",{active:p.value}])},a[1]||(a[1]=[e("i",{class:"bi bi-chevron-down"},null,-1)]),2)]),p.value?(n(),r("div",oe,[(n(!0),r(N,null,D(m.backups,c=>(n(),r("div",{class:"card rounded-3 shadow-sm animate__animated",key:c.filename,onClick:()=>{y("select",c)},id:c.filename.replace(".conf",""),role:"button"},[e("div",ne,[e("small",null,[a[2]||(a[2]=e("i",{class:"bi bi-file-earmark me-2"},null,-1)),e("samp",null,x(c.filename),1)]),e("small",null,[a[3]||(a[3]=e("i",{class:"bi bi-clock-history me-2"},null,-1)),e("samp",null,x(W(X)(c.backupDate).format("YYYY-MM-DD HH:mm:ss")),1)]),e("small",null,[a[4]||(a[4]=e("i",{class:"bi bi-database me-2"},null,-1)),c.database?(n(),f(o,{key:0,t:"Yes"})):(n(),f(o,{key:1,t:"No"}))]),a[5]||(a[5]=e("small",{class:"text-muted ms-auto"},[e("i",{class:"bi bi-chevron-right"})],-1))])],8,le))),128))])):w("",!0)]))}},ie=T(ae,[["__scopeId","data-v-ccf48ac7"]]),re={class:"d-flex flex-column gap-5",id:"confirmBackup"},de={class:"d-flex flex-column gap-3"},ue={class:"d-flex flex-column flex-sm-row align-items-start align-items-sm-center gap-3"},ce={class:"mb-0"},me={class:"text-muted mb-1"},fe={class:"mb-0"},pe={class:"text-muted mb-1",for:"ConfigurationName"},ve={class:"invalid-feedback"},be={key:0},ge={key:1},_e={class:"mb-0"},ke={class:"row g-3"},xe={class:"col-sm"},ye={class:"text-muted mb-1",for:"PrivateKey"},he={class:"input-group"},Ce={class:"col-sm"},Pe={class:"text-muted mb-1",for:"PublicKey"},we={class:"text-muted mb-1",for:"ListenPort"},$e={class:"invalid-feedback"},Be={key:0},Ne={key:1},De={class:"mb-0"},Ae={class:"text-muted mb-1 d-flex",for:"ListenPort"},Ie={class:"invalid-feedback"},Le={key:0},Se={key:1},Ue={class:"accordion",id:"newConfigurationOptionalAccordion"},Ke={class:"accordion-item"},Re={class:"accordion-header"},Ve={class:"accordion-button collapsed rounded-3",type:"button","data-bs-toggle":"collapse","data-bs-target":"#newConfigurationOptionalAccordionCollapse"},Oe={id:"newConfigurationOptionalAccordionCollapse",class:"accordion-collapse collapse","data-bs-parent":"#newConfigurationOptionalAccordion"},Te={class:"accordion-body d-flex flex-column gap-3"},Ee={class:"text-muted mb-1",for:"PreUp"},qe={class:"text-muted mb-1",for:"PreDown"},je={class:"text-muted mb-1",for:"PostUp"},Me={class:"text-muted mb-1",for:"PostDown"},Ye={class:"d-flex flex-column gap-3"},We={class:"d-flex flex-column flex-sm-row align-items-start align-items-sm-center gap-3"},ze={class:"mb-0"},Fe={key:0},Ge={class:"row g-3"},He={class:"col-sm"},Ze={class:"card text-bg-success rounded-3"},Je={class:"card-body"},Qe={class:"col-sm"},Xe={class:"card text-bg-warn
2025-02-17 14:01:56 +08:00
`);for(let i of y){if(i==="[Peer]")break;if(i.length>0){let s=i.replace(" = ","=").split("=");s[0]==="ListenPort"?t[s[0]]=parseInt(s[1]):t[s[0]]=s[1]}}const p=k(!1),h=k(!1),a=k(""),c=F(),b=C(()=>/^[a-zA-Z0-9_=+.-]{1,15}$/.test(t.ConfigurationName)&&t.ConfigurationName.length>0&&!c.Configurations.find(i=>i.Name===t.ConfigurationName)),P=C(()=>{try{window.wireguard.generatePublicKey(t.PrivateKey)}catch{return!1}return!0}),I=C(()=>t.ListenPort>0&&t.ListenPort<=65353&&Number.isInteger(t.ListenPort)&&!c.Configurations.find(i=>parseInt(i.ListenPort)===t.ListenPort)),L=C(()=>{try{return O(t.Address),!0}catch{return!1}}),S=C(()=>L.value&&I.value&&P.value&&b.value);A(()=>{document.querySelector("main").scrollTo({top:0,behavior:"smooth"}),G(()=>P,i=>{i&&(t.PublicKey=window.wireguard.generatePublicKey(t.PrivateKey))},{immediate:!0})});const U=C(()=>{let i;try{i=O(t.Address)}catch{return 0}return i.end-i.start}),K=C(()=>u.selectedConfigurationBackup.database?u.selectedConfigurationBackup.databaseContent.split(`
`).filter(s=>s.search(`INSERT INTO "${t.ConfigurationName}"`)>=0).length:0),R=C(()=>u.selectedConfigurationBackup.database?u.selectedConfigurationBackup.databaseContent.split(`
`).filter(s=>s.search(`INSERT INTO "${t.ConfigurationName}_restrict_access"`)>=0).length:0),j=E(),M=H(),Y=async()=>{S.value&&(h.value=!0,await Z("/api/addWireguardConfiguration",t,async i=>{i.status?(j.newMessage("Server","Configuration restored","success"),await c.getConfigurations(),await M.push(`/configuration/${t.ConfigurationName}/peers`)):h.value=!1}))};return(i,s)=>(n(),r("div",re,[e("form",de,[e("div",ue,[e("h4",ce,[l(o,{t:"Configuration"})])]),e("div",null,[e("label",me,[e("small",null,[l(o,{t:"Protocol"})])]),e("h5",fe,[l(q,{protocol:m.selectedConfigurationBackup.protocol,mini:!0},null,8,["protocol"])])]),e("div",null,[e("label",pe,[e("small",null,[l(o,{t:"Configuration Name"})])]),g(e("input",{type:"text",class:v(["form-control rounded-3",[b.value?"is-valid":"is-invalid"]]),placeholder:"ex. wg1",id:"ConfigurationName","onUpdate:modelValue":s[0]||(s[0]=d=>t.ConfigurationName=d),disabled:"",required:""},null,2),[[_,t.ConfigurationName]]),e("div",ve,[p.value?(n(),r("div",be,x(a.value),1)):(n(),r("div",ge,[l(o,{t:"Configuration name is invalid. Possible reasons:"}),e("ul",_e,[e("li",null,[l(o,{t:"Configuration name already exist."})]),e("li",null,[l(o,{t:"Configuration name can only contain 15 lower/uppercase alphabet, numbers, underscore, equal sign, plus sign, period and hyphen."})])])]))])]),e("div",ke,[e("div",xe,[e("div",null,[e("label",ye,[e("small",null,[l(o,{t:"Private Key"})])]),e("div",he,[g(e("input",{type:"text",class:v(["form-control rounded-start-3",[P.value?"is-valid":"is-invalid"]]),id:"PrivateKey",required:"","onUpdate:modelValue":s[1]||(s[1]=d=>t.PrivateKey=d),disabled:""},null,2),[[_,t.PrivateKey]])])])]),e("div",Ce,[e("div",null,[e("label",Pe,[e("small",null,[l(o,{t:"Public Key"})])]),g(e("input",{type:"text",class:"form-control rounded-3",id:"PublicKey","onUpdate:modelValue":s[2]||(s[2]=d=>t.PublicKey=d),disabled:""},null,512),[[_,t.PublicKey]])])])]),e("div",null,[e("label",we,[e("small",null,[l(o,{t:"Listen Port"})])]),g(e("input",{type:"number",class:v(["form-control rounded-3",[I.value?"is-valid":"is-invalid"]]),placeholder:"0-65353",id:"ListenPort",min:"1",max:"65353","onUpdate:modelValue":s[3]||(s[3]=d=>t.ListenPort=d),disabled:"",required:""},null,2),[[_,t.ListenPort]]),e("div",$e,[p.value?(n(),r("div",Be,x(a.value),1)):(n(),r("div",Ne,[l(o,{t:"Listen Port is invalid. Possible reasons:"}),e("ul",De,[e("li",null,[l(o,{t:"Invalid port."})]),e("li",null,[l(o,{t:"Port is assigned to existing WireGuard Configuration."})])])]))])]),e("div",null,[e("label",Ae,[e("small",null,[l(o,{t:"IP Address/CIDR"})]),e("small",{class:v(["ms-auto",[U.value>0?"text-success":"text-danger"]])},[l(o,{t:U.value+" Available IP Address"},null,8,["t"])],2)]),g(e("input",{type:"text",class:v(["form-control",[L.value?"is-valid":"is-invalid"]]),placeholder:"Ex: 10.0.0.1/24",id:"Address","onUpdate:modelValue":s[4]||(s[4]=d=>t.Address=d),disabled:"",required:""},null,2),[[_,t.Address]]),e("div",Ie,[p.value?(n(),r("div",Le,x(a.value),1)):(n(),r("div",Se,[l(o,{t:"IP Address/CIDR is invalid"})]))])]),e("div",Ue,[e("div",Ke,[e("h2",Re,[e("button",Ve,[l(o,{t:"Optional Settings"})])]),e("div",Oe,[e("div",Te,[e("div",null,[e("label",Ee,[e("small",null,[l(o,{t:"PreUp"})])]),g(e("input",{type:"text",class:"form-control rounded-3",id:"PreUp",disabled:"","onUpdate:modelValue":s[5]||(s[5]=d=>t.PreUp=d)},null,512),[[_,t.PreUp]])]),e("div",null,[e("label",qe,[e("small",null,[l(o,{t:"PreDown"})])]),g(e("input",{type:"text",class:"form-control rounded-3",id:"PreDown",disabled:"","onUpdate:modelValue":s[6]||(s[6]=d=>t.PreDown=d)},null,512),[[_,t.PreDown]])]),e("div",null,[e("label",je,[e("small",null,[l(o,{t:"PostUp"})])]),g(e("input",{type:"text",class:"form-control rounded-3",id:"PostUp",disabled:"","onUpdate:modelValue":s[7]||(s[7]=d=>t.PostUp=d)},null,512),[[_,t.PostUp]])]),e("div",null,[e("label",Me,[e("small",null,[l(o,{t:"PostDown"})])]),g(e("input",{type:"text",class:"form-control rounded-3",id:"PostDown",disabled:"","onUpdate:modelValue":s[8]||(s[8]=d=>t.PostDown=d)},null,512),[[_,t.PostDown]])])])])])])]),e("div",Ye,[e("div",