"use strict";(()=>{vare={};e.id=7889,e.ids=[7889],e.modules={60818:e=>{e.exports=require("dotenv")},47795:e=>{e.exports=require("generate-password")},27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},66650:(e,r,s)=>{s.r(r),s.d(r,{config:()=>x,default:()=>w,routeModule:()=>y});vart={};s.r(t),s.d(t,{default:()=>q});vara=s(89947),i=s(2706),o=s(96762),n=s(6420),u=s.n(n),d=s(48225),l=s.n(d);s(27825);varc=s(51348),h=s.n(c),m=s(20503),p=s.n(m),g=s(46889),f=s.n(g);s(29021);letE=s(47795);asyncfunctionq(e,r){if("POST"!==e.method)returnr.json({user:null,msg:"Registration Failed!"});lets=awaitu()(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=`dsql_user_${s.id}`,{host:o,password:n}=t;if(!o.match(/./))throwError("Invalid host");if(o.match(/^%$/))throwError("Cannot set a catch-all host for this user.");letu=String(o).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,""),d=n?.match(/./)?n:E.generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),l=awaith()("SELECT * FROM mysql.user WHERE User = ? AND (Host = ? OR Host = ?)",[a,u,e]);if(l?.[0]?.User)throwError("SQL User already exists. Remember if you have the '%' host on your primary user, it catches all other hosts.");if(u.match(/^%$/))throwError("Can't create a catch-all host for this username. Catch-all host is only allowed on the primary user.");letc=awaith()("SELECT COUNT(*) FROM mariadb_users WHERE user_id = ?",[s.id]);if(c?.[0]?.["COUNT(*)"]>=10)throwError("User limit reached");letm=p()({data:d}),g=awaith()("INSERT INTO mariadb_users (user_id, username, host, password, grants) VALUES (?, ?, ?, ?, ?)",[s.id,a,u,m,JSON.stringify(i)]);if(!g?.insertId)throwError("Error in adding SQL user");awaitf()({userId:s.id,mariadbUser:a,mariadbUserHost:u}),r.json({success:!0})}catch(e){console.log("Create MariaDB user ERROR:",e.message),l()({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})}}letw=(0,o.M)(t,"default"),x=(0,o.M)(t,"config"),y=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,[5264],()=>s(66650));module.exports=t})();