Files
yakpanel-core/YakPanel-server/frontend/dist/assets/ConfigPage-BIvuvwCK.js
2026-04-07 05:05:28 +05:30

2 lines
7.8 KiB
JavaScript

import{r as l,a,j as e,J as B,K as Q}from"./index-cE9w-Kq7.js";import{A as j}from"./AdminAlert-yrdXFH0e.js";import{A as b}from"./AdminButton-ByutG8m-.js";import{A as p}from"./AdminCard-BvdkSQBp.js";import{P as N}from"./PageHeader-HdM4gpcn.js";function Y(){const[r,E]=l.useState(null),[m,I]=l.useState({}),[q,J]=l.useState(!0),[i,v]=l.useState(""),[A,y]=l.useState(!1),[R,w]=l.useState(!1),[g,o]=l.useState(""),[u,h]=l.useState(null);l.useEffect(()=>{Promise.all([a("/config/panel"),a("/config/keys")]).then(([t,s])=>{E(t),I(s||{})}).catch(t=>v(t.message)).finally(()=>J(!1))},[]);const L=t=>{t.preventDefault(),w(!1),o("");const s=t.currentTarget,c=s.elements.namedItem("old_password").value,n=s.elements.namedItem("new_password").value,x=s.elements.namedItem("confirm_password").value;if(!c||!n){o("All fields required");return}if(n!==x){o("New passwords do not match");return}if(n.length<6){o("Password must be at least 6 characters");return}Q(c,n).then(()=>{w(!0),s.reset()}).catch(f=>o(f.message))},V=()=>{h(null),B().then(()=>h("Test email sent!")).catch(t=>h(`Failed: ${t.message}`))},M=t=>{var P,k,O,T,C;t.preventDefault(),y(!1);const s=t.currentTarget,c=s.elements.namedItem("panel_port").value,n=s.elements.namedItem("www_root").value,x=s.elements.namedItem("setup_path").value,f=s.elements.namedItem("webserver_type").value,S=s.elements.namedItem("mysql_root").value,F=((P=s.elements.namedItem("email_to"))==null?void 0:P.value)||"",W=((k=s.elements.namedItem("smtp_server"))==null?void 0:k.value)||"",U=((O=s.elements.namedItem("smtp_port"))==null?void 0:O.value)||"587",D=((T=s.elements.namedItem("smtp_user"))==null?void 0:T.value)||"",_=((C=s.elements.namedItem("smtp_password"))==null?void 0:C.value)||"",d=[a("/config/set",{method:"POST",body:JSON.stringify({key:"panel_port",value:c})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"www_root",value:n})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"setup_path",value:x})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"webserver_type",value:f})})];S&&d.push(a("/config/set",{method:"POST",body:JSON.stringify({key:"mysql_root",value:S})})),d.push(a("/config/set",{method:"POST",body:JSON.stringify({key:"email_to",value:F})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"smtp_server",value:W})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"smtp_port",value:U})}),a("/config/set",{method:"POST",body:JSON.stringify({key:"smtp_user",value:D})})),_&&d.push(a("/config/set",{method:"POST",body:JSON.stringify({key:"smtp_password",value:_})})),Promise.all(d).then(()=>y(!0)).catch(K=>v(K.message))};return q?e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Settings"}),e.jsx("p",{className:"text-secondary",children:"Loading…"})]}):r?e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Settings"}),i?e.jsx(j,{className:"mb-3",children:i}):null,e.jsxs("form",{onSubmit:M,className:"row g-3",children:[e.jsx("div",{className:"col-12 col-xl-6",children:e.jsxs(p,{title:"Panel",iconClass:"ti ti-adjustments-horizontal",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Panel Port"}),e.jsx("input",{name:"panel_port",type:"number",defaultValue:r.panel_port,className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"WWW Root"}),e.jsx("input",{name:"www_root",type:"text",defaultValue:r.www_root,className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Setup Path"}),e.jsx("input",{name:"setup_path",type:"text",defaultValue:r.setup_path,className:"form-control"})]}),e.jsxs("div",{className:"mb-0",children:[e.jsx("label",{className:"form-label",children:"Webserver"}),e.jsxs("select",{name:"webserver_type",defaultValue:r.webserver_type,className:"form-select",children:[e.jsx("option",{value:"nginx",children:"Nginx"}),e.jsx("option",{value:"apache",children:"Apache"}),e.jsx("option",{value:"openlitespeed",children:"OpenLiteSpeed"})]})]})]})}),e.jsx("div",{className:"col-12 col-xl-6",children:e.jsxs(p,{title:"Notifications (Email)",iconClass:"ti ti-mail",children:[e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Email To"}),e.jsx("input",{name:"email_to",type:"email",defaultValue:m.email_to,placeholder:"admin@example.com",className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"SMTP Server"}),e.jsx("input",{name:"smtp_server",type:"text",defaultValue:m.smtp_server,placeholder:"smtp.gmail.com",className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"SMTP Port"}),e.jsx("input",{name:"smtp_port",type:"number",defaultValue:m.smtp_port||"587",className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"SMTP User"}),e.jsx("input",{name:"smtp_user",type:"text",defaultValue:m.smtp_user,className:"form-control"})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"SMTP Password"}),e.jsx("input",{name:"smtp_password",type:"password",placeholder:m.smtp_password?"•••••••• (leave blank to keep)":"Optional",className:"form-control"})]}),e.jsx("p",{className:"small text-secondary",children:"Used for panel alerts (e.g. backup completion, security warnings)."}),e.jsxs(b,{type:"button",variant:"warning",className:"mt-2",onClick:V,children:[e.jsx("i",{className:"ti ti-mail me-1","aria-hidden":!0}),"Send Test Email"]}),u?e.jsx("p",{className:`small mt-2 mb-0 ${u.startsWith("Failed")?"text-danger":"text-success"}`,children:u}):null]})}),e.jsx("div",{className:"col-12 col-xl-6",children:e.jsx(p,{title:"MySQL",iconClass:"ti ti-database",children:e.jsxs("div",{className:"mb-0",children:[e.jsx("label",{className:"form-label",children:"Root Password"}),e.jsx("input",{name:"mysql_root",type:"password",placeholder:r.mysql_root_set?"•••••••• (leave blank to keep)":"Required for real DB creation",className:"form-control"}),e.jsx("p",{className:"small text-secondary mt-2 mb-0",children:"Used to create/drop MySQL databases. Leave blank to keep current."})]})})}),e.jsxs("div",{className:"col-12",children:[e.jsxs(b,{type:"submit",variant:"primary",children:[e.jsx("i",{className:"ti ti-device-floppy me-1","aria-hidden":!0}),"Save"]}),A?e.jsx("span",{className:"text-success ms-3 small",children:"Saved"}):null]})]}),e.jsx("div",{className:"col-12 col-xl-6 mt-3 px-0",children:e.jsx(p,{title:"Change Password",iconClass:"ti ti-key",children:e.jsxs("form",{onSubmit:L,children:[g?e.jsx(j,{className:"mb-3",children:g}):null,e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Current Password"}),e.jsx("input",{name:"old_password",type:"password",className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"New Password"}),e.jsx("input",{name:"new_password",type:"password",minLength:6,className:"form-control",required:!0})]}),e.jsxs("div",{className:"mb-3",children:[e.jsx("label",{className:"form-label",children:"Confirm New Password"}),e.jsx("input",{name:"confirm_password",type:"password",minLength:6,className:"form-control",required:!0})]}),e.jsxs(b,{type:"submit",variant:"warning",children:[e.jsx("i",{className:"ti ti-key me-1","aria-hidden":!0}),"Change Password"]}),R?e.jsx("span",{className:"text-success ms-3 small",children:"Password changed"}):null]})})}),e.jsxs("div",{className:"alert alert-secondary mt-4 mb-0",children:[e.jsxs("p",{className:"mb-1",children:[e.jsx("strong",{children:"App:"})," ",r.app_name," v",r.app_version]}),e.jsx("p",{className:"mb-0 small",children:"Note: Some settings require a panel restart to take effect."})]})]}):e.jsxs(e.Fragment,{children:[e.jsx(N,{title:"Settings"}),i?e.jsx(j,{children:i}):null]})}export{Y as ConfigPage};