dsql-admin/dsql-app/.local_dist/server/pages/api/sql-users/update.js
Benjamin Toby 7a06e83a46 Updates
2024-12-08 20:56:57 +01:00

1 line
2.5 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")},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")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},46849:(e,r,s)=>{s.r(r),s.d(r,{config:()=>q,default:()=>w,routeModule:()=>x});var t={};s.r(t),s.d(t,{default:()=>g});var i=s(89947),a=s(2706),o=s(96762),d=s(6420),u=s.n(d),n=s(48225),l=s.n(n);s(27825);var p=s(51348),h=s.n(p);s(33873),s(79646);var c=s(20503),m=s.n(c),E=s(46889),f=s.n(E);async function g(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:i,prev:a,grants:o}=e.body;try{if(!a?.id)throw Error("Invalid existing DB entry");let e=await h()("SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",[a.id,s.id]),i=e?.[0];if(!i?.id)throw Error("Active User couldn't be verified");let d=`dsql_user_${s.id}`,{host:u,password:n}=t;if(!u)throw Error("No host provided");if(u.match(/^%$/))throw Error("Cannot set a catch-all host for this user.");let l=String(u).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,"");if(i.host!=t.host){let e=await h()("SELECT * FROM mariadb_users WHERE user_id = ? AND host = ?",[s.id,l]);if(e?.[0]?.id)throw Error("User already exists with this host. Please choose another host.");await h()(`RENAME USER '${d}'@'${i.host}' TO '${d}'@'${l}'`)}let p=m()({data:n}),c=p==i.password?i.password:p;await h()("UPDATE mariadb_users SET host = ?, password = ?, grants = ? WHERE id = ?",[l,c,JSON.stringify(o),i.id]),await h()(`SET PASSWORD FOR '${d}'@'${l}' = PASSWORD('${n}');`),await f()({userId:s.id,mariadbUser:d,mariadbUserHost:l,sqlUserID:i.id}),r.json({success:!0})}catch(e){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})}}s(29021);let w=(0,o.M)(t,"default"),q=(0,o.M)(t,"config"),x=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/sql-users/update",pathname:"/api/sql-users/update",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(46849));module.exports=t})();