"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:()=>u,getServerSideProps:()=>h,getStaticPaths:()=>S,getStaticProps:()=>p,reportWebVitals:()=>_,routeModule:()=>y,unstable_getServerProps:()=>m,unstable_getServerSideProps:()=>D,unstable_getStaticParams:()=>f,unstable_getStaticPaths:()=>x,unstable_getStaticProps:()=>g});var a=s(63865),n=s(9455),i=s(30671),o=s(5583),c=s(19796),l=s(49690),d=e([l]);l=(d.then?(await d)():d)[0];let u=(0,i.M)(l,"default"),p=(0,i.M)(l,"getStaticProps"),S=(0,i.M)(l,"getStaticPaths"),h=(0,i.M)(l,"getServerSideProps"),v=(0,i.M)(l,"config"),_=(0,i.M)(l,"reportWebVitals"),g=(0,i.M)(l,"unstable_getStaticProps"),x=(0,i.M)(l,"unstable_getStaticPaths"),f=(0,i.M)(l,"unstable_getStaticParams"),m=(0,i.M)(l,"unstable_getServerProps"),D=(0,i.M)(l,"unstable_getServerSideProps"),y=new a.PagesRouteModule({definition:{kind:n.A.PAGES,page:"/su/servers",pathname:"/su/servers",bundlePath:"",filename:""},components:{App:c.default,Document:o.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 a=s(8732);s(82015);var n=s(96089),i=s(75979),o=e([i]);function c({slugText:e,justIcon:r,noIcon:s,title:t,outlined:o,extraClasses:c}){return(0,a.jsxs)("div",{className:(0,i.twMerge)("button small-text hover:!bg-transparent",o?" outlined gray bg-white":" ghost light-gray",c),onClick:r=>{navigator.clipboard.writeText(e).then(()=>{alert(`Copied: "${e}"`)})},style:o?void 0:{padding:0},children:[!s&&(0,a.jsx)(n.A,{size:o?15:20}),!r&&(0,a.jsx)("span",{className:"text-slate-500 dark:text-slate-300",children:t||"Copy Slug"})]})}i=(o.then?(await o)():o)[0],t()}catch(e){t(e)}})},57168:(e,r,s)=>{s.a(e,async(e,t)=>{try{s.d(r,{A:()=>l});var a=s(8732),n=s(73872),i=s(2459),o=s(75979),c=e([n,o]);function l({server:e,noLoadBalance:r}){return(0,a.jsxs)("div",{className:"stack w-full",children:[(0,a.jsxs)("div",{children:[(0,a.jsx)(i.A,{size:15,opacity:.5}),(0,a.jsxs)("div",{children:[(0,a.jsx)("span",{children:e.host}),r?(0,a.jsx)(a.Fragment,{}):e.loadBalanced?(0,a.jsx)("span",{className:"info green small",children:"Load Balanced"}):(0,a.jsx)("button",{children:"Add to Load Balancer"})]})]}),(0,a.jsx)("div",{className:(0,o.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,a.jsx)("ul",{className:"p-0 m-0 pl-4",children:e.users?.map((e,r)=>a.jsx(d,{user:e},r))})})]})}function d({user:e}){return(0,a.jsx)("li",{className:(0,o.twMerge)("w-full"),children:(0,a.jsxs)("div",{className:"stack gap-0",children:[(0,a.jsxs)("span",{children:["user: ",(0,a.jsx)("b",{children:e.name})]}),(0,a.jsxs)("span",{children:["pass:"," ",(0,a.jsx)("b",{children:(0,a.jsx)(n.A,{slugText:e.password,title:"********",extraClasses:"inline",noIcon:!0})})]})]})})}[n,o]=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 a=s(8732),n=s(19796),i=s(82015),o=s.n(i),c=s(57168),l=e([c]);function d(){let e=o().useContext(n.AppContext).pageProps;e.user;let r=e.servers;return(0,a.jsxs)(o().Fragment,{children:[(0,a.jsxs)("div",{className:"w-full justify-between",children:[(0,a.jsxs)("div",{className:"flex-col items-start gap-2",children:[(0,a.jsx)("h2",{className:"text-xl m-0",children:"Servers"}),(0,a.jsx)("span",{children:"All Servers"})]}),(0,a.jsx)("div",{children:(0,a.jsx)("button",{children:"Add Server"})})]}),(0,a.jsxs)("section",{className:"paper",children:[(0,a.jsx)("div",{className:"flex flex-col gap-2 w-full",children:r.map((e,r)=>(0,a.jsx)(c.A,{server:e,noLoadBalance:!0},r))}),(0,a.jsx)("button",{className:"w-full outlined dashed gray",children:"Add Server"})]})]})}c=(l.then?(await l)():l)[0],t()}catch(e){t(e)}})},77489:(e,r,s)=>{s.d(r,{A:()=>l});var t=s(29021),a=s.n(t),n=s(60374),i=s(33873),o=s.n(i);function c(){let e=process.env.DSQL_SU_USER_ID||"1",r=o().resolve(process.cwd(),`./jsonData/dbSchemas/users/user-${e}`),s=`${r}/servers.json`;return{dir:r,path:s}}function l(){try{!function(){try{let e=c();if(!a().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"}]};a().writeFileSync(e.path,JSON.stringify([r]))}}catch(e){return console.log(`Error checking servers ${e.message}`),!1}}();let e=c();return n.A.parse(a().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:()=>a});var t=s(51779);async function a(...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:()=>n});var t=s(9973),a=s.n(t);function n(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||a()({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||a()({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||a()({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:()=>_,getServerSideProps:()=>g});var a=s(8732);s(82015);var n=s(29021),i=s.n(n),o=s(61197),c=s(40778),l=s(77489),d=s(66097),u=s(71934),p=s(33873),S=s.n(p),h=s(60374),v=e([d]);function _({user:e,data:r}){let s=(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)("title",{children:"Load Balancing"}),(0,a.jsx)("meta",{name:"description",content:"Distribute db load accross servers"})]});return(0,a.jsx)(c.A,{head:s,user:e,children:(0,a.jsx)(d.A,{})})}async function g({req:e,res:r,query:s}){try{let r=await (0,o.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,u.A)("SELECT user,host,password FROM mysql.user")).filter(e=>e.User.match(/^dsql_user|^root/i));return i().writeFileSync(S().resolve(process.cwd(),"./.tmp/wrt.json"),String(h.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})();