2 lines
21 KiB
JavaScript
2 lines
21 KiB
JavaScript
|
|
import{r as l,l as lt,j as e,L as ee,D as o,a as at,c as nt,s as it,b as ct,d as Pe,e as rt,f as te,h as Ee,i as ot,k as dt,m as mt,n as ht,o as ut,u as xt,p as pt,q as jt}from"./index-Cvh4tLHo.js";import{M as n}from"./Modal-CCihVZTY.js";import{A as F}from"./AdminAlert-Bt3L8_zJ.js";import{A as _}from"./AdminButton-BKglG8kI.js";import{A as bt}from"./AdminTable-BQ5Lf7EC.js";import{E as Te}from"./EmptyState-D6lCh4WN.js";import{P as se}from"./PageHeader-D6k34vvM.js";function gt(d){return{74:"7.4",80:"8.0",81:"8.1",82:"8.2"}[d]||d}function wt(){const[d,le]=l.useState([]),[Re,ae]=l.useState(!0),[P,c]=l.useState(""),[De,E]=l.useState(!1),[ne,ie]=l.useState(!1),[ce,M]=l.useState(""),[j,T]=l.useState(null),[re,$]=l.useState([]),[G,R]=l.useState(!1),[q,D]=l.useState(null),[i,m]=l.useState(null),[oe,de]=l.useState(!1),[me,C]=l.useState(""),[he,ue]=l.useState(null),[g,W]=l.useState(null),[xe,U]=l.useState([]),[O,V]=l.useState(""),[Q,K]=l.useState(""),[pe,je]=l.useState(301),[Ie,be]=l.useState(!1),[w,v]=l.useState(null),[J,ge]=l.useState(""),[fe,Ne]=l.useState("main"),[I,b]=l.useState(null),[L,H]=l.useState(!1),[B,Le]=l.useState(""),[h,A]=l.useState(()=>new Set),[f,z]=l.useState(1),[S,He]=l.useState(25),[ve,Se]=l.useState(null),[X,ye]=l.useState(!1),[ke,Ce]=l.useState(null),u=()=>{ae(!0),at().then(le).catch(t=>c(t.message)).finally(()=>ae(!1))};l.useEffect(()=>{u()},[]),l.useEffect(()=>{lt().then(t=>{const s=t.services.find(a=>a.id==="nginx");Se((s==null?void 0:s.status)??null)}).catch(()=>Se(null))},[]);const y=l.useMemo(()=>{const t=B.trim().toLowerCase();return t?d.filter(s=>[s.name,s.path,s.ps,s.primary_domain,...s.domains||[]].join(" ").toLowerCase().includes(t)):d},[d,B]);l.useEffect(()=>z(1),[B,S]);const k=Math.max(1,Math.ceil(y.length/S)),N=l.useMemo(()=>{const t=(f-1)*S;return y.slice(t,t+S)},[y,f,S]);l.useEffect(()=>{f>k&&z(k)},[f,k]);const Ae=t=>{A(s=>{const a=new Set(s);return a.has(t)?a.delete(t):a.add(t),a})},ze=()=>{const t=new Set(N.map(a=>a.id)),s=N.length>0&&N.every(a=>h.has(a.id));A(s?a=>{const r=new Set(a);return N.forEach(x=>r.delete(x.id)),r}:a=>new Set([...a,...t]))},Y=async t=>{const s=[...h];if(s.length===0)return;const a=t==="delete"?`Delete ${s.length} site(s)? This cannot be undone.`:`${t==="enable"?"Enable":"Disable"} ${s.length} site(s)?`;if(confirm(a)){ye(!0);try{const x=(await it(t,s)).results.filter(p=>!p.ok);x.length?c(x.map(p=>`${p.id}: ${p.msg}`).join("; ")):c(""),A(new Set),u()}catch(r){c(r instanceof Error?r.message:"Batch failed")}finally{ye(!1)}}},Fe=t=>{Ce(t),Pe(t).then(()=>u()).catch(s=>c(s.message)).finally(()=>Ce(null))},Me=t=>{var Be,_e;t.preventDefault();const s=t.currentTarget,a=s.elements.namedItem("name").value.trim(),r=s.elements.namedItem("domains").value.trim(),x=s.elements.namedItem("path").value.trim(),p=s.elements.namedItem("ps").value.trim();if(!a||!r){M("Name and domain(s) are required");return}const Z=r.split(/[\s,]+/).filter(Boolean),et=((Be=s.elements.namedItem("php_version"))==null?void 0:Be.value)||"74",tt=((_e=s.elements.namedItem("force_https"))==null?void 0:_e.checked)||!1;ie(!0),M(""),nt({name:a,domains:Z,path:x||void 0,ps:p||void 0,php_version:et,force_https:tt}).then(()=>{E(!1),s.reset(),u()}).catch(st=>M(st.message)).finally(()=>ie(!1))},$e=(t,s)=>{confirm(`Delete site "${s}"? This cannot be undone.`)&&ot(t).then(u).catch(a=>c(a.message))},Ge=t=>{T(t),$([]),Ee(t).then(s=>$(s.backups)).catch(s=>c(s.message))},qe=()=>{j&&(R(!0),Pe(j).then(()=>Ee(j).then(t=>$(t.backups))).catch(t=>c(t.message)).finally(()=>R(!1)))},We=t=>{!j||!confirm(`Restore from ${t}? This will overwrite existing files.`)||(R(!0),jt(j,t).then(()=>T(null)).catch(s=>c(s.message)).finally(()=>R(!1)))},Ue=t=>{j&&pt(j,t).catch(s=>c(s.message))},Oe=t=>{D(t),C(""),rt(t).then(s=>m({domains:(s.domains||[]).join(", "),path:s.path||"",ps:s.ps||"",php_version:s.php_version||"74",force_https:!!(s.force_https&&s.force_https!==0)})).catch(s=>C(s.message))},Ve=t=>{if(t.preventDefault(),!q||!i)return;const s=i.domains.split(/[\s,]+/).filter(Boolean);if(s.length===0){C("At least one domain is required");return}de(!0
|