2025-09-17 15:23:09 +08:00
` ),o=[];let f=-1;const l=t.indexOf("[Peer]");if(l===-1)return!1;for(let d=l;d<t.length;d++)if(t[d]==="[Peer]")f+=1,o.push({}),o[f].name="";else{let b=t[d].replace(" = ","=");b.indexOf("=")>-1&&(b=[b.slice(0,b.indexOf("=")),b.slice(b.indexOf("=")+1)],o[f][b[0]]=b[1])}return o};te();const ne={class:"card rounded-3"},ie={class:"card-body"},ae={class:"row"},le={class:"col-sm"},re={class:"d-flex flex-column gap-2"},de={class:"d-flex align-items-center"},ue={class:"text-muted"},ce={key:0,class:"mb-0 ms-auto"},pe={key:0,class:"d-flex gap-2 flex-column"},me={class:"text-muted d-flex align-items-center gap-1",style:{"white-space":"nowrap"}},fe={class:"badge rounded-pill text-bg-success ms-auto"},be={value:void 0,disabled:""},ve=["value"],ge={class:"col-sm"},he={class:"d-flex flex-column gap-2 h-100"},we={class:"d-flex align-items-center"},ye={class:"text-muted"},_e={key:0,class:"mb-0 ms-auto"},Ce={key:1,class:"d-flex ms-auto align-items-center"},Pe={key:0,class:"d-flex gap-2 flex-column mt-auto"},xe={class:"text-muted d-flex align-items-center gap-1",style:{"white-space":"nowrap"}},Se={class:"badge rounded-pill text-bg-success ms-auto"}, $ e={value:void 0,disabled:""},Le=["value"],ke={key:0,class:"d-flex gap-2"},Te={key:1,class:"d-flex gap-2"},M=G({__name:"newConfigurationTemplate",props:["template","edit","isNew","peersCount"],emits:["subnet","port","update","remove"],setup(s,{emit:t}){const o=s,f=B(),l=h(!1);o.edit&&(l.value=!0);const d=h({...o.template});h(256);const b=h([]);h(20);const u=t,S=h(void 0),i=h(void 0),x=h([]), $ =()=>{if(b.value=[],o.template.Subnet){let v=new Set([...V(o.template.Subnet)]);if(o.peersCount&&o.peersCount>0){for(let k of f.Configurations){let K=k.Address.replace(" ","").split(",");for(let E of K)W(o.template.Subnet,E)&&(v=v.difference(new Set([...V(E)])))}let c=Math.floor(v.size/o.peersCount),p=0;v=Array.from(v);for(let k=0;k<(c>10?10:c);k++)b.value.push(z(v.slice(p,p+o.peersCount))),p+=o.peersCount}}},m=()=>{if(o.template.ListenPortStart&&o.template.ListenPortEnd){let v=o.template.ListenPortStart,c=o.template.ListenPortEnd;v>c&&(v=o.template.ListenPortEnd,c=o.template.ListenPortStart);let p=new Set(Array.from({length:c-v+1},(k,K)=>v+K));x.value=[...p.difference(new Set(f.Configurations.map(k=>Number(k.ListenPort))))]}};J(()=>{o.isNew||( $ (),m())}),N(()=>o.peersCount,()=>{ $ ()}),N(S,()=>{u("subnet",S.value)}),N(i,()=>{u("port",i.value)}),N(()=>o.template,()=>{ $ (),m()},{deep:!0});const y=j(()=>{try{const{start:v,end:c}=F(d.value.Subnet);if(c-v>=1000000n)throw new Error("Too many IPs");return d.value.Subnet&&d.value.ListenPortStart&&d.value.ListenPortEnd&&d.value.ListenPortEnd>=d.value.ListenPortStart}catch{return!1}}),L=async()=>{await q("/api/newConfigurationTemplates/updateTemplate",{Template:d.value},v=>{v.status&&(u("update",d.value),l.value=!1)})},C=async()=>{await q("/api/newConfigurationTemplates/deleteTemplate",{Template:d.value},v=>{v.status&&u("remove",d)})};return(v,c)=>(n(),a("div",ne,[e("div",ie,[e("div",ae,[e("div",le,[e("div",re,[e("div",de,[e("label",ue,[e("small",null,[r(g,{t:"Subnet"})])]),l.value?w((n(),a("input",{key:1,class:"form-control-sm form-control rounded-3 w-auto ms-auto","onUpdate:modelValue":c[0]||(c[0]=p=>d.value.Subnet=p)},null,512)),[[P,d.value.Subnet]]):(n(),a("p",ce,[e("small",null,_(s.template.Subnet),1)]))]),l.value?T("",!0):(n(),a("div",pe,[e("label",me,[e("small",null,[r(g,{t:"Available Subnets"})]),e("span",fe,_(b.value.length),1)]),w(e("select",{"onUpdate:modelValue":c[1]||(c[1]=p=>S.value=p),class:"form-select form-select-sm rounded-3 w-100 ms-auto"},[e("option",be,[r(g,{t:"Select..."})]),(n(!0),a(A,null,I(b.value,p=>(n(),a("option",{value:p.join(", ")},_(p.join(", ")),9,ve))),256))],512),[[H,S.value]])]))])]),e("div",ge,[e("div",he,[e("div",we,[e("label",ye,[e("small",null,[r(g,{t:"Listen Port Range"})])]),l.value?(n(),a("div",Ce,[w(e("input",{class:"form-control-sm form-control rounded-3 ms-auto",style:{width:"80px"},"onUpdate:modelValue":c[2]||(c[2]=p=>d.value.ListenPortStart=p),type:"number"},null,512),[[P,d.value.ListenPortStart]]),c[10]||(c[10]=e("i",{class: