"use strict";(()=>{var e={};e.id=3821,e.ids=[3821],e.modules={95755:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.r(r),s.d(r,{config:()=>v,default:()=>p,getServerSideProps:()=>_,getStaticPaths:()=>S,getStaticProps:()=>u,reportWebVitals:()=>h,routeModule:()=>j,unstable_getServerProps:()=>f,unstable_getServerSideProps:()=>m,unstable_getStaticParams:()=>x,unstable_getStaticPaths:()=>g,unstable_getStaticProps:()=>D});var n=s(63865),a=s(9455),o=s(30671),i=s(5583),c=s(19796),l=s(49690),d=e([l]);l=(d.then?(await d)():d)[0];let p=(0,o.M)(l,"default"),u=(0,o.M)(l,"getStaticProps"),S=(0,o.M)(l,"getStaticPaths"),_=(0,o.M)(l,"getServerSideProps"),v=(0,o.M)(l,"config"),h=(0,o.M)(l,"reportWebVitals"),D=(0,o.M)(l,"unstable_getStaticProps"),g=(0,o.M)(l,"unstable_getStaticPaths"),x=(0,o.M)(l,"unstable_getStaticParams"),f=(0,o.M)(l,"unstable_getServerProps"),m=(0,o.M)(l,"unstable_getServerSideProps"),j=new n.PagesRouteModule({definition:{kind:a.A.PAGES,page:"/su/servers",pathname:"/su/servers",bundlePath:"",filename:""},components:{App:c.default,Document:i.default},userland:l});t()}catch(e){t(e)}})},73872:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.d(r,{A:()=>c});var n=s(8732);s(82015);var a=s(96089),o=s(75979),i=e([o]);function c({slugText:e,justIcon:r,noIcon:s,title:t,outlined:i,extraClasses:c}){return(0,n.jsxs)("div",{className:(0,o.twMerge)("button small-text hover:!bg-transparent",i?" outlined gray bg-white":" ghost light-gray",c),onClick:r=>{navigator.clipboard.writeText(e).then(()=>{alert(`Copied: "${e}"`)})},style:i?void 0:{padding:0},children:[!s&&(0,n.jsx)(a.A,{size:i?15:20}),!r&&(0,n.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:t||"Copy Slug"})]})}o=(i.then?(await i)():i)[0],t()}catch(e){t(e)}})},57168:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.d(r,{A:()=>l});var n=s(8732),a=s(73872),o=s(2459),i=s(75979),c=e([a,i]);function l({server:e,noLoadBalance:r}){return(0,n.jsxs)("div",{className:"stack w-full",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(o.A,{size:15,opacity:.5}),(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{children:e.host}),r?(0,n.jsx)(n.Fragment,{}):e.loadBalanced?(0,n.jsx)("span",{className:"info green small",children:"Load Balanced"}):(0,n.jsx)("button",{children:"Add to Load Balancer"})]})]}),(0,n.jsx)("div",{className:(0,i.twMerge)("stack border-0 border-l border-solid border-s-slate-200 dark:border-white/20","pl-6 ml-2 -mt-4 pt-2 w-full gap-0"),children:(0,n.jsx)("ul",{className:"p-0 m-0 pl-4",children:e.users?.map((e,r)=>n.jsx(d,{user:e},r))})})]})}function d({user:e}){return(0,n.jsx)("li",{className:(0,i.twMerge)("w-full"),children:(0,n.jsxs)("div",{className:"stack gap-0",children:[(0,n.jsxs)("span",{children:["user: ",(0,n.jsx)("b",{children:e.name})]}),(0,n.jsxs)("span",{children:["pass:"," ",(0,n.jsx)("b",{children:(0,n.jsx)(a.A,{slugText:e.password,title:"********",extraClasses:"inline",noIcon:!0})})]})]})})}[a,i]=c.then?(await c)():c,t()}catch(e){t(e)}})},66097:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.d(r,{A:()=>d});var n=s(8732),a=s(19796),o=s(82015),i=s.n(o),c=s(57168),l=e([c]);function d(){let e=i().useContext(a.AppContext).pageProps.servers;return(0,n.jsxs)(i().Fragment,{children:[(0,n.jsxs)("div",{className:"w-full justify-between",children:[(0,n.jsxs)("div",{className:"flex-col items-start gap-2",children:[(0,n.jsx)("h2",{className:"text-xl m-0",children:"Servers"}),(0,n.jsx)("span",{children:"All Servers"})]}),(0,n.jsx)("div",{children:(0,n.jsx)("button",{children:"Add Server"})})]}),(0,n.jsxs)("section",{className:"paper",children:[(0,n.jsx)("div",{className:"flex flex-col gap-2 w-full",children:e.map((e,r)=>(0,n.jsx)(c.A,{server:e,noLoadBalance:!0},r))}),(0,n.jsx)("button",{className:"w-full outlined dashed gray",children:"Add Server"})]})]})}c=(l.then?(await l)():l)[0],t()}catch(e){t(e)}})},24934:(e,r,s)=>{s.d(r,{A:()=>l});var t=s(29021),n=s.n(t),a=s(60374),o=s(33873),i=s.n(o);function c(){let{userDirPath:e}=function(e){let r=process.env.DSQL_APP_DIR,s=process.env.DSQL_DB_SCHEMA_DIR,t=".tmp";if(!r)throw Error("Please provide the `DSQL_APP_DIR` env variable.");if(!s)throw Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");let n=i().join(r,"package-shared"),a=i().join(n,"types/dsql.ts"),o=i().join(s,"main.json"),c=i().join(n,"data/defaultFields.json"),l=i().join(s,"users"),d=e?.user?.id?i().join(l,`user-${e.user.id}`):e?.userId?i().join(l,`user-${e.userId}`):void 0,p=d?i().join(d,"main.json"):void 0,u=d?i().join(d,"media"):void 0,S=d?i().join(d,"export"):void 0,_=S?i().join(S,"sql"):void 0,v=_?i().join(_,t):void 0,h=v?i().join(v,"schema.json"):void 0,D="db-export.zip",g=_?i().join(_,D):void 0,x="db-export.zip",f=_?i().join(_,x):void 0;return{schemasDir:s,userDirPath:d,mainShemaJSONFilePath:o,mainDbTypeDefFile:a,tempDirName:t,defaultTableFieldsJSONFilePath:c,usersSchemaDir:l,userSchemaMainJSONFilePath:p,userPrivateMediaDir:u,userPrivateExportsDir:S,userPrivateSQLExportsDir:_,userPrivateTempSQLExportsDir:v,userPrivateTempJSONSchemaFilePath:h,userPrivateDbExportZipFileName:D,userPrivateDbExportZipFilePath:g,userPrivateDbImportZipFileName:x,userPrivateDbImportZipFilePath:f}}({userId:process.env.DSQL_SU_USER_ID||"1"}),r=`${e}/servers.json`;return{dir:e,path:r}}function l(){try{!function(){try{let e=c();if(!n().existsSync(e.path)){let r={host:String(process.env.DSQL_DB_TARGET_IP_ADDRESS),port:3306,primary:!0,loadBalanced:!0,users:[{host:String(process.env.DSQL_DB_HOST),name:"root",password:process.env.DSQL_MARIADB_ROOT_PASSWORD||"password"}]};n().writeFileSync(e.path,JSON.stringify([r]))}}catch(e){return console.log(`Error checking servers ${e.message}`),!1}}();let e=c();return a.A.parse(n().readFileSync(e.path,"utf-8"))}catch(e){console.log(`Error getting servers ${e.message}`);return}}},96089:(e,r,s)=>{s.d(r,{A:()=>t});let t=(0,s(82544).A)("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]])},71934:(e,r,s)=>{s.d(r,{A:()=>n});var t=s(51779);async function n(...e){let r=(0,t.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},60374:(e,r,s)=>{s.d(r,{A:()=>t});let t={parse:function(e,r){if(e){if("object"==typeof e)return e;if("string"==typeof e)try{return JSON.parse(e,r)}catch(e){return}}},stringify:function(e,r,s){try{return JSON.stringify(e,r||void 0,s)}catch(e){return}}}},51779:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(9973),n=s.n(t);function a(e){return global.DSQL_USE_LOCAL||e?.local?global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.ro?global.DSQL_READ_ONLY_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},49690:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.r(r),s.d(r,{default:()=>h,getServerSideProps:()=>D});var n=s(8732);s(82015);var a=s(29021),o=s.n(a),i=s(61197),c=s(40778),l=s(24934),d=s(66097),p=s(71934),u=s(33873),S=s.n(u),_=s(60374),v=e([d]);function h({user:e,data:r}){let s=(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("title",{children:"Load Balancing"}),(0,n.jsx)("meta",{name:"description",content:"Distribute db load accross servers"})]});return(0,n.jsx)(c.A,{head:s,user:e,children:(0,n.jsx)(d.A,{})})}async function D({req:e,res:r,query:s}){try{let r=await (0,i.A)(e);if(!r?.logged_in_status)return{redirect:{destination:"/su/login",permanent:!1}};let s=(0,l.A)();if(!s)throw Error("No servers found");s.find(e=>e.primary);let t=(await (0,p.A)("SELECT user,host,password FROM mysql.user")).filter(e=>e.User.match(/^dsql_user|^root/i));return o().writeFileSync(S().resolve(process.cwd(),"./.tmp/wrt.json"),String(_.A.stringify(t,null,4)),"utf8"),{props:{user:r,servers:s}}}catch(e){return{redirect:{destination:"/su",permanent:!1}}}}d=(v.then?(await v)():v)[0],t()}catch(e){t(e)}})},13893:e=>{e.exports=require("@moduletrace/datasquirel/dist/client/fetch")},40361:e=>{e.exports=require("next/dist/compiled/next-server/pages.runtime.prod.js")},27912:e=>{e.exports=require("next/head")},82015:e=>{e.exports=require("react")},22326:e=>{e.exports=require("react-dom")},8732:e=>{e.exports=require("react/jsx-runtime")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},75979:e=>{e.exports=import("tailwind-merge")}};var r=require("../../webpack-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[883,9821,9796,6622],()=>s(95755));module.exports=t})();