|
|
|
|
`),s=[];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,s.push({}),s[f].name="";else{let b=t[d].replace(" = ","=");b.indexOf("=")>-1&&(b=[b.slice(0,b.indexOf("=")),b.slice(b.indexOf("=")+1)],s[f][b[0]]=b[1])}return s};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"},ye={class:"d-flex align-items-center"},we={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"},Ie={key:1,class:"d-flex gap-2"},M=G({__name:"newConfigurationTemplate",props:["template","edit","isNew","peersCount"],emits:["subnet","port","update","remove"],setup(o,{emit:t}){const s=o,f=B(),l=P(!1);s.edit&&(l.value=!0);const d=P({...s.template}),b=P([]),u=t,S=P(void 0),i=P(void 0),x=P([]),$=()=>{if(b.value=[],s.template.Subnet){let v=new Set([...V(s.template.Subnet)]);if(s.peersCount&&s.peersCount>0){for(let k of f.Configurations){let K=k.Address.replace(" ","").split(",");for(let R of K)W(s.template.Subnet,R)&&(v=v.difference(new Set([...V(R)])))}let c=Math.floor(v.size/s.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+s.peersCount))),p+=s.peersCount}}},m=()=>{if(s.template.ListenPortStart&&s.template.ListenPortEnd){let v=s.template.ListenPortStart,c=s.template.ListenPortEnd;v>c&&(v=s.template.ListenPortEnd,c=s.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(()=>{s.isNew||($(),m())}),N(()=>s.peersCount,()=>{$()}),N(S,()=>{u("subnet",S.value)}),N(i,()=>{u("port",i.value)}),N(()=>s.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 E("/api/newConfigurationTemplates/updateTemplate",{Template:d.value},v=>{v.status&&(u("update",d.value),l.value=!1)})},_=async()=>{await E("/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?h((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)),[[C,d.value.Subnet]]):(n(),a("p",ce,[e("small",null,w(o.template.Subnet),1)]))]),l.value?I("",!0):(n(),a("div",pe,[e("label",me,[e("small",null,[r(g,{t:"Available Subnets"})]),e("span",fe,w(b.value.length),1)]),h(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(T,null,A(b.value,p=>(n(),a("option",{value:p.join(", ")},w(p.join(", ")),9,ve))),256))],512),[[H,S.value]])]))])]),e("div",ge,[e("div",he,[e("div",ye,[e("label",we,[e("small",null,[r(g,{t:"Listen Port Range"})])]),l.value?(n(),a("div",Ce,[h(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),[[C,d.value.ListenPortStart]]),c[10]||(c[10]=e("i",{class:"bi bi-arrow-right mx-2"}
|