Files
yakpanel-core/YakPanel-server/frontend/dist/assets/SitePage-CeCv6Zaa.js
2026-04-07 09:46:22 +05:30

2 lines
15 KiB
JavaScript

import{r as l,j as e,a as Ee,c as Ae,s as He,l as G,b as De,d as ie,e as Fe,f as Ge,h as Le,i as Ie,k as qe,u as Me,m as ze,n as $e,o as Ue}from"./index-CRR9sQ49.js";import{M as a}from"./Modal-B7V4w_St.js";import{A as k}from"./AdminAlert-DW1IRWce.js";import{A as ce}from"./AdminButton-Bd2cLTu3.js";import{A as We}from"./AdminTable-BLiLxfnS.js";import{E as Ve}from"./EmptyState-C61VdEFl.js";import{P as L}from"./PageHeader-BcjNf7GG.js";function et(){const[C,re]=l.useState([]),[oe,I]=l.useState(!0),[b,i]=l.useState(""),[de,j]=l.useState(!1),[q,M]=l.useState(!1),[z,w]=l.useState(""),[r,f]=l.useState(null),[$,B]=l.useState([]),[_,g]=l.useState(!1),[T,N]=l.useState(null),[n,c]=l.useState(null),[U,W]=l.useState(!1),[V,p]=l.useState(""),[K,J]=l.useState(null),[m,P]=l.useState(null),[O,R]=l.useState([]),[E,A]=l.useState(""),[H,D]=l.useState(""),[Q,X]=l.useState(301),[me,Y]=l.useState(!1),[x,h]=l.useState(null),[F,Z]=l.useState(""),[ee,te]=l.useState("main"),[v,o]=l.useState(null),[S,y]=l.useState(!1),u=()=>{I(!0),Ee("/site/list").then(re).catch(t=>i(t.message)).finally(()=>I(!1))};l.useEffect(()=>{u()},[]);const ue=t=>{var ae,ne;t.preventDefault();const s=t.currentTarget,d=s.elements.namedItem("name").value.trim(),le=s.elements.namedItem("domains").value.trim(),we=s.elements.namedItem("path").value.trim(),Be=s.elements.namedItem("ps").value.trim();if(!d||!le){w("Name and domain(s) are required");return}const _e=le.split(/[\s,]+/).filter(Boolean),Te=((ae=s.elements.namedItem("php_version"))==null?void 0:ae.value)||"74",Pe=((ne=s.elements.namedItem("force_https"))==null?void 0:ne.checked)||!1;M(!0),w(""),Ae({name:d,domains:_e,path:we||void 0,ps:Be||void 0,php_version:Te,force_https:Pe}).then(()=>{j(!1),s.reset(),u()}).catch(Re=>w(Re.message)).finally(()=>M(!1))},he=(t,s)=>{confirm(`Delete site "${s}"? This cannot be undone.`)&&Fe(t).then(u).catch(d=>i(d.message))},pe=t=>{f(t),B([]),ie(t).then(s=>B(s.backups)).catch(s=>i(s.message))},xe=()=>{r&&(g(!0),ze(r).then(()=>ie(r).then(t=>B(t.backups))).catch(t=>i(t.message)).finally(()=>g(!1)))},be=t=>{!r||!confirm(`Restore from ${t}? This will overwrite existing files.`)||(g(!0),Ue(r,t).then(()=>f(null)).catch(s=>i(s.message)).finally(()=>g(!1)))},je=t=>{r&&$e(r,t).catch(s=>i(s.message))},fe=t=>{N(t),p(""),De(t).then(s=>c({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=>p(s.message))},ge=t=>{if(t.preventDefault(),!T||!n)return;const s=n.domains.split(/[\s,]+/).filter(Boolean);if(s.length===0){p("At least one domain is required");return}W(!0),p(""),Me(T,{domains:s,path:n.path||void 0,ps:n.ps||void 0,php_version:n.php_version,force_https:n.force_https}).then(()=>{N(null),c(null),u()}).catch(d=>p(d.message)).finally(()=>W(!1))},se=(t,s)=>{J(t),He(t,s).then(u).catch(d=>i(d.message)).finally(()=>J(null))},Ne=t=>{P(t),A(""),D(""),X(301),G(t).then(R).catch(s=>i(s.message))},ve=t=>{t.preventDefault(),!(!m||!E.trim()||!H.trim())&&(Y(!0),Ie(m,E.trim(),H.trim(),Q).then(()=>G(m).then(R)).then(()=>{A(""),D("")}).catch(s=>i(s.message)).finally(()=>Y(!1)))},Se=t=>{m&&qe(m,t).then(()=>G(m).then(R)).catch(s=>i(s.message))},ye=t=>{t.preventDefault(),!(!x||!F.trim())&&(y(!0),Ge(x,F.trim(),ee.trim()||"main").then(()=>{h(null),o(null),u()}).catch(s=>i(s.message)).finally(()=>y(!1)))},ke=()=>{x&&(y(!0),Le(x).then(()=>{h(null),o(null),u()}).catch(t=>i(t.message)).finally(()=>y(!1)))},Ce=t=>t<1024?t+" B":t<1024*1024?(t/1024).toFixed(1)+" KB":(t/1024/1024).toFixed(1)+" MB";return oe?e.jsxs(e.Fragment,{children:[e.jsx(L,{title:"Website"}),e.jsx("div",{className:"text-center py-5 text-muted",children:"Loading…"})]}):b&&!C.length?e.jsxs(e.Fragment,{children:[e.jsx(L,{title:"Website"}),e.jsx(k,{variant:"danger",children:b})]}):e.jsxs(e.Fragment,{children:[e.jsx(L,{title:"Website",actions:e.jsxs(ce,{onClick:()=>j(!0),children:[e.jsx("i",{className:"ti ti-plus me-1"}),"Add Site"]})}),b?e.jsx(k,{variant:"warning",children:b}):null,e.jsxs(a,{show:de,onHide:()=>j(!1),centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Create Site"})}),e.jsxs("form",{onSubmit:ue,children:[e.jsxs(a.Body,{children:[z?e.jsx(k,{variant:"danger",children:z}):null,e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Site Name"}),e.jsx("input",{name:"name",type:"text",placeholder:"example.com",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Domain(s) (comma or space separated)"}),e.jsx("input",{name:"domains",type:"text",placeholder:"example.com www.example.com",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Path (optional)"}),e.jsx("input",{name:"path",type:"text",placeholder:"/www/wwwroot/example.com",className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"PHP Version"}),e.jsxs("select",{name:"php_version",className:"form-select",children:[e.jsx("option",{value:"74",children:"7.4"}),e.jsx("option",{value:"80",children:"8.0"}),e.jsx("option",{value:"81",children:"8.1"}),e.jsx("option",{value:"82",children:"8.2"})]})]}),e.jsxs("div",{className:"form-check mb-3",children:[e.jsx("input",{name:"force_https",type:"checkbox",id:"create_force_https",className:"form-check-input"}),e.jsx("label",{htmlFor:"create_force_https",className:"form-check-label",children:"Force HTTPS (redirect HTTP to HTTPS)"})]}),e.jsxs("div",{className:"mb-0",children:[e.jsx("label",{className:"form-label",children:"Note (optional)"}),e.jsx("input",{name:"ps",type:"text",placeholder:"My website",className:"form-control"})]})]}),e.jsxs(a.Footer,{children:[e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>j(!1),children:"Cancel"}),e.jsx("button",{type:"submit",disabled:q,className:"btn btn-primary",children:q?"Creating…":"Create"})]})]})]}),e.jsx("div",{className:"card shadow-sm border-0",children:e.jsx("div",{className:"card-body p-0",children:e.jsxs(We,{children:[e.jsx("thead",{className:"table-light",children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Path"}),e.jsx("th",{children:"Domains"}),e.jsx("th",{children:"Type"}),e.jsx("th",{className:"text-end",children:"Actions"})]})}),e.jsx("tbody",{children:C.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"p-0",children:e.jsx(Ve,{title:"No sites yet",description:'Click "Add Site" to create one.'})})}):C.map(t=>e.jsxs("tr",{children:[e.jsx("td",{className:"align-middle",children:t.name}),e.jsx("td",{className:"align-middle text-muted",children:t.path}),e.jsx("td",{className:"align-middle",children:t.domain_count}),e.jsx("td",{className:"align-middle",children:t.project_type}),e.jsxs("td",{className:"align-middle text-end text-nowrap",children:[t.status===1?e.jsx("button",{type:"button",onClick:()=>se(t.id,!1),disabled:K===t.id,className:"btn btn-sm btn-outline-warning me-1",title:"Stop",children:e.jsx("i",{className:"ti ti-player-stop"})}):e.jsx("button",{type:"button",onClick:()=>se(t.id,!0),disabled:K===t.id,className:"btn btn-sm btn-outline-success me-1",title:"Start",children:e.jsx("i",{className:"ti ti-player-play"})}),e.jsx("button",{type:"button",onClick:()=>{h(t.id),o("clone"),Z(""),te("main")},className:"btn btn-sm btn-outline-success me-1",title:"Git Deploy",children:e.jsx("i",{className:"ti ti-git-branch"})}),e.jsx("button",{type:"button",onClick:()=>Ne(t.id),className:"btn btn-sm btn-outline-secondary me-1",title:"Redirects",children:e.jsx("i",{className:"ti ti-arrows-right-left"})}),e.jsx("button",{type:"button",onClick:()=>fe(t.id),className:"btn btn-sm btn-outline-primary me-1",title:"Edit",children:e.jsx("i",{className:"ti ti-pencil"})}),e.jsx("button",{type:"button",onClick:()=>pe(t.id),className:"btn btn-sm btn-outline-primary me-1",title:"Backup",children:e.jsx("i",{className:"ti ti-archive"})}),e.jsx("button",{type:"button",onClick:()=>he(t.id,t.name),className:"btn btn-sm btn-outline-danger",title:"Delete",children:e.jsx("i",{className:"ti ti-trash"})})]})]},t.id))})]})})}),e.jsxs(a,{show:!!x&&!!v,onHide:()=>{h(null),o(null)},centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Git Deploy"})}),e.jsxs(a.Body,{children:[e.jsxs("div",{className:"btn-group mb-3",role:"group",children:[e.jsx("button",{type:"button",className:`btn btn-sm ${v==="clone"?"btn-success":"btn-outline-secondary"}`,onClick:()=>o("clone"),children:"Clone"}),e.jsx("button",{type:"button",className:`btn btn-sm ${v==="pull"?"btn-success":"btn-outline-secondary"}`,onClick:()=>o("pull"),children:"Pull"})]}),v==="clone"?e.jsxs("form",{onSubmit:ye,children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Repository URL"}),e.jsx("input",{value:F,onChange:t=>Z(t.target.value),placeholder:"https://github.com/user/repo.git",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Branch"}),e.jsx("input",{value:ee,onChange:t=>te(t.target.value),placeholder:"main",className:"form-control"})]}),e.jsx("p",{className:"small text-muted",children:"Site path must be empty for clone."}),e.jsxs("div",{className:"d-flex justify-content-end gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>{h(null),o(null)},children:"Cancel"}),e.jsx("button",{type:"submit",disabled:S,className:"btn btn-success",children:S?"Cloning…":"Clone"})]})]}):e.jsxs("div",{children:[e.jsx("p",{className:"text-muted small",children:"Pull latest changes from the remote repository."}),e.jsxs("div",{className:"d-flex justify-content-end gap-2",children:[e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>{h(null),o(null)},children:"Cancel"}),e.jsx("button",{type:"button",onClick:ke,disabled:S,className:"btn btn-success",children:S?"Pulling…":"Pull"})]})]})]})]}),e.jsxs(a,{show:m!=null,onHide:()=>P(null),size:"lg",centered:!0,scrollable:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Redirects"})}),e.jsxs(a.Body,{children:[e.jsxs("form",{onSubmit:ve,className:"row g-2 align-items-end mb-3",children:[e.jsxs("div",{className:"col-md-3",children:[e.jsx("label",{className:"form-label small",children:"Source"}),e.jsx("input",{value:E,onChange:t=>A(t.target.value),placeholder:"/old-path",className:"form-control form-control-sm"})]}),e.jsxs("div",{className:"col-md-3",children:[e.jsx("label",{className:"form-label small",children:"Target"}),e.jsx("input",{value:H,onChange:t=>D(t.target.value),placeholder:"/new-path",className:"form-control form-control-sm"})]}),e.jsxs("div",{className:"col-md-2",children:[e.jsx("label",{className:"form-label small",children:"Code"}),e.jsxs("select",{value:Q,onChange:t=>X(Number(t.target.value)),className:"form-select form-select-sm",children:[e.jsx("option",{value:301,children:"301"}),e.jsx("option",{value:302,children:"302"})]})]}),e.jsx("div",{className:"col-md-2",children:e.jsx("button",{type:"submit",disabled:me,className:"btn btn-primary btn-sm w-100",children:"Add"})})]}),O.length===0?e.jsx("p",{className:"text-muted small mb-0",children:"No redirects"}):e.jsx("ul",{className:"list-group list-group-flush",children:O.map(t=>e.jsxs("li",{className:"list-group-item d-flex align-items-center gap-2 small",children:[e.jsx("code",{className:"text-truncate",children:t.source}),e.jsx("span",{className:"text-muted",children:"→"}),e.jsx("code",{className:"text-truncate flex-grow-1",children:t.target}),e.jsx("span",{className:"badge bg-secondary",children:t.code}),e.jsx("button",{type:"button",className:"btn btn-sm btn-link text-danger p-0",onClick:()=>Se(t.id),children:e.jsx("i",{className:"ti ti-trash"})})]},t.id))})]}),e.jsx(a.Footer,{children:e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>P(null),children:"Close"})})]}),e.jsxs(a,{show:T!=null&&n!=null,onHide:()=>{N(null),c(null)},centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Edit Site"})}),n?e.jsxs("form",{onSubmit:ge,children:[e.jsxs(a.Body,{children:[V?e.jsx(k,{variant:"danger",children:V}):null,e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Domain(s)"}),e.jsx("input",{value:n.domains,onChange:t=>c({...n,domains:t.target.value}),type:"text",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Path (optional)"}),e.jsx("input",{value:n.path,onChange:t=>c({...n,path:t.target.value}),type:"text",className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"PHP Version"}),e.jsxs("select",{value:n.php_version,onChange:t=>c({...n,php_version:t.target.value}),className:"form-select",children:[e.jsx("option",{value:"74",children:"7.4"}),e.jsx("option",{value:"80",children:"8.0"}),e.jsx("option",{value:"81",children:"8.1"}),e.jsx("option",{value:"82",children:"8.2"})]})]}),e.jsxs("div",{className:"form-check mb-3",children:[e.jsx("input",{type:"checkbox",id:"edit_force_https",className:"form-check-input",checked:n.force_https,onChange:t=>c({...n,force_https:t.target.checked})}),e.jsx("label",{htmlFor:"edit_force_https",className:"form-check-label",children:"Force HTTPS"})]}),e.jsxs("div",{className:"mb-0",children:[e.jsx("label",{className:"form-label",children:"Note (optional)"}),e.jsx("input",{value:n.ps,onChange:t=>c({...n,ps:t.target.value}),type:"text",className:"form-control"})]})]}),e.jsxs(a.Footer,{children:[e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>{N(null),c(null)},children:"Cancel"}),e.jsx("button",{type:"submit",disabled:U,className:"btn btn-primary",children:U?"Saving…":"Save"})]})]}):null]}),e.jsxs(a,{show:r!=null,onHide:()=>f(null),size:"lg",centered:!0,children:[e.jsx(a.Header,{closeButton:!0,children:e.jsx(a.Title,{children:"Site Backup"})}),e.jsxs(a.Body,{children:[e.jsx("div",{className:"mb-3",children:e.jsxs(ce,{onClick:xe,disabled:_,children:[e.jsx("i",{className:"ti ti-archive me-1"}),_?"Creating…":"Create Backup"]})}),e.jsx("h6",{className:"text-muted small",children:"Existing backups"}),$.length===0?e.jsx("p",{className:"text-muted small",children:"No backups yet"}):e.jsx("ul",{className:"list-group list-group-flush",children:$.map(t=>e.jsxs("li",{className:"list-group-item d-flex align-items-center justify-content-between gap-2",children:[e.jsx("code",{className:"small text-truncate flex-grow-1",children:t.filename}),e.jsx("span",{className:"text-muted small",children:Ce(t.size)}),e.jsx("button",{type:"button",className:"btn btn-sm btn-link",onClick:()=>je(t.filename),title:"Download",children:e.jsx("i",{className:"ti ti-download"})}),e.jsx("button",{type:"button",className:"btn btn-sm btn-link text-warning",onClick:()=>be(t.filename),disabled:_,children:e.jsx("i",{className:"ti ti-restore"})})]},t.filename))})]}),e.jsx(a.Footer,{children:e.jsx("button",{type:"button",className:"btn btn-light",onClick:()=>f(null),children:"Close"})})]})]})}export{et as SitePage};