"use strict";(()=>{vare={};e.id=7889,e.ids=[7889],e.modules={60818:e=>{e.exports=require("dotenv")},47795:e=>{e.exports=require("generate-password")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},52795:(e,r,s)=>{s.r(r),s.d(r,{config:()=>f,default:()=>h,routeModule:()=>E});vart={};s.r(t),s.d(t,{default:()=>g});vara=s(89947),i=s(2706),o=s(96762),u=s(47795),n=s.n(u),d=s(69842),l=s(67619),c=s(48786),m=s(68829),p=s(5437);asyncfunctiong(e,r){if("POST"!==e.method)returnr.json({user:null,msg:"Registration Failed!"});lets=await(0,d.A)(e,r,!0);if(!s)returnr.json({success:!1,msg:"Unauthorized"});let{data:t,edit:a,grants:i}=e.body;try{lete=process.env.DSQL_DB_HOST||"127.0.0.1",a=s?.id==Number(process.env.DSQL_SU_USER_ID),{host:o,password:u,username:d}=t,l=a&&d?.match(/./)?d:`dsql_user_${s.id}`;if(!o.match(/./))throwError("Invalid host");letg=String(o).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,""),h=u?.match(/./)?u:n().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),f=await(0,c.A)("SELECT * FROM mysql.user WHERE User = ? AND (Host = ? OR Host = ?)",[l,g,e]);if(f?.[0]?.User)throwError("SQL User already exists. Remember if you have the '%' host on your primary user, it catches all other hosts.");letE=await(0,c.A)("SELECT COUNT(*) FROM mariadb_users WHERE user_id = ?",[s.id]);if(E?.[0]?.["COUNT(*)"]>=10)throwError("User limit reached");letS=(0,m.default)({data:h}),w=await(0,c.A)("INSERT INTO mariadb_users (user_id, username, host, password, grants) VALUES (?, ?, ?, ?, ?)",[s.id,l,g,S,JSON.stringify(i)]);if(!w?.insertId)throwError("Error in adding SQL user");await(0,p.A)({userId:s.id,mariadbUsername:l,mariadbUserHost:g}),r.json({success:!0})}catch(e){console.log("Create MariaDB user ERROR:",e.message),(0,l.default)({component:"/api/acceptUserInvitation/catch-error",message:e.message,user:s}),r.json({success:!1,msg:"Error in adding SQL user =>"+e.message,err:e.message})}}leth=(0,o.M)(t,"default"),f=(0,o.M)(t,"config"),E=newa.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/sql-users/create",pathname:"/api/sql-users/create",bundlePath:"",filename:""},userland:t})}};varr=require("../../../webpack-api-runtime.js");r.C(e);vars=e=>r(r.s=e),t=r.X(0,[3496],()=>s(52795));module.exports=t})();