1 line
2.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
"use strict";(()=>{var e={};e.id=2350,e.ids=[2350],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")},49844:(e,r,s)=>{s.r(r),s.d(r,{config:()=>E,default:()=>c,routeModule:()=>f});var a={};s.r(a),s.d(a,{default:()=>m});var i=s(89947),t=s(2706),d=s(96762),o=s(69842),u=s(67619),n=s(48786),p=s(68829),l=s(5437);async function m(e,r){if("POST"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let s=await (0,o.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{data:a,edit:i,prev:t,grants:d}=e.body;try{if(!t?.id)throw Error("Invalid existing DB entry");let e=await (0,n.A)("SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",[t.id,s.id]),i=s?.id==Number(process.env.DSQL_SU_USER_ID),o=e?.[0];if(!o?.id)throw Error("Active User couldn't be verified");let{host:u,password:m,username:c}=a,E=i&&c||`dsql_user_${s.id}`;if(!u)throw Error("No host provided");let f=String(u).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,"");if(o.host!=a.host||o.username!=E){let e=await (0,n.A)("SELECT * FROM mariadb_users WHERE user_id=? AND username=? AND host=?",[s.id,E,f]);e?.[0]?.id||await (0,n.A)(`RENAME USER '${t.username}'@'${o.host}' TO '${E}'@'${f}'`)}let g=(0,p.default)({data:m}),A=g==o.password?o.password:g;await (0,n.A)("UPDATE mariadb_users SET username=?, host=?, password=?, grants=? WHERE id=?",[E,f,A,JSON.stringify(d),o.id]),await (0,n.A)(`SET PASSWORD FOR '${E}'@'${f}' = PASSWORD('${m}');`),await (0,l.A)({userId:s.id,mariadbUsername:E,mariadbUserHost:f,sqlUserID:o.id}),r.json({success:!0})}catch(e){(0,u.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})}}s(29021);let c=(0,d.M)(a,"default"),E=(0,d.M)(a,"config"),f=new i.PagesAPIRouteModule({definition:{kind:t.A.PAGES_API,page:"/api/sql-users/update",pathname:"/api/sql-users/update",bundlePath:"",filename:""},userland:a})}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),a=r.X(0,[3496],()=>s(49844));module.exports=a})(); |