dsql-admin/dsql-app/.local_dist/server/pages/api/sql-users/update.js

1 line
2.3 KiB
JavaScript
Raw Normal View History

2025-01-14 06:42:13 +00:00
"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:()=>A,default:()=>c,routeModule:()=>E});var i={};s.r(i),s.d(i,{default:()=>m});var a=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:i,edit:a,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]),a=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}=i,A=a&&c||`dsql_user_${s.id}`;if(!u)throw Error("No host provided");let E=String(u).replace(/[^a-zA-Z0-9-\.\:\/\%]/g,"");if(o.host!=i.host||o.username!=A){let e=await (0,n.A)("SELECT * FROM mariadb_users WHERE user_id=? AND username=? AND host=?",[s.id,A,E]);e?.[0]?.id||await (0,n.A)(`RENAME USER '${t.username}'@'${o.host}' TO '${A}'@'${E}'`)}let g=(0,p.A)({data:m}),f=g==o.password?o.password:g;await (0,n.A)("UPDATE mariadb_users SET username=?, host=?, password=?, grants=? WHERE id=?",[A,E,f,JSON.stringify(d),o.id]),await (0,n.A)(`SET PASSWORD FOR '${A}'@'${E}' = PASSWORD('${m}');`),await (0,l.A)({userId:s.id,mariadbUsername:A,mariadbUserHost:E,sqlUserID:o.id}),r.json({success:!0})}catch(e){(0,u.A)({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 c=(0,d.M)(i,"default"),A=(0,d.M)(i,"config"),E=new a.PagesAPIRouteModule({definition:{kind:t.A.PAGES_API,page:"/api/sql-users/update",pathname:"/api/sql-users/update",bundlePath:"",filename:""},userland:i})}};var r=require("../../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),i=r.X(0,[3496],()=>s(49844));module.exports=i})();