"use strict";(()=>{var e={};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});var t={};s.r(t),s.d(t,{default:()=>q});var a=s(89947),i=s(2706),o=s(96762),n=s(6420),u=s.n(n),d=s(48225),l=s.n(d);s(27825);var c=s(51348),h=s.n(c),m=s(20503),p=s.n(m),g=s(46889),f=s.n(g);s(29021);let E=s(47795);async function q(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let s=await u()(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{data:t,edit:a,grants:i}=e.body;try{let e=process.env.DSQL_DB_HOST||"127.0.0.1",a=`dsql_user_${s.id}`,{host:o,password:n}=t;if(!o.match(/./))throw Error("Invalid host");if(o.match(/^%$/))throw Error("Cannot set a catch-all host for this user.");let u=String(o).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,""),d=n?.match(/./)?n:E.generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),l=await h()("SELECT * FROM mysql.user WHERE User = ? AND (Host = ? OR Host = ?)",[a,u,e]);if(l?.[0]?.User)throw Error("SQL User already exists. Remember if you have the '%' host on your primary user, it catches all other hosts.");if(u.match(/^%$/))throw Error("Can't create a catch-all host for this username. Catch-all host is only allowed on the primary user.");let c=await h()("SELECT COUNT(*) FROM mariadb_users WHERE user_id = ?",[s.id]);if(c?.[0]?.["COUNT(*)"]>=10)throw Error("User limit reached");let m=p()({data:d}),g=await h()("INSERT INTO mariadb_users (user_id, username, host, password, grants) VALUES (?, ?, ?, ?, ?)",[s.id,a,u,m,JSON.stringify(i)]);if(!g?.insertId)throw Error("Error in adding SQL user");await f()({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})}}let w=(0,o.M)(t,"default"),x=(0,o.M)(t,"config"),y=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/sql-users/create",pathname:"/api/sql-users/create",bundlePath:"",filename:""},userland:t})}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[5264],()=>s(66650));module.exports=t})();