dsql-admin/dsql-app/.local_dist/server/pages/api/updateAdminUserAccess.js

1 line
2.8 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=294,e.ids=[294],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},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")},98397:(e,t,r)=>{r.r(t),r.d(t,{config:()=>h,default:()=>E,routeModule:()=>m});var s={};r.r(s),r.d(s,{default:()=>f});var a=r(89947),i=r(2706),u=r(96762),l=r(51348),d=r.n(l),n=r(6420),o=r.n(n),c=r(47670),p=r.n(c);r(29021),r(33873);let{execSync:_}=r(79646);async function f(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await o()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{userObject:s,database_access:a,user_priviledge:i,db_tables:u,inv_user_id:l}=e.body,n=await d()("UPDATE user_users SET database_access = ? ,user_priviledge = ? WHERE user_id = ? AND email = ?",[a,i,r.id,s.email]),c=u.split("|");await d()(`DELETE FROM delegated_user_tables WHERE root_user_id='${r.id}' AND delegated_user_id='${l}'`);for(let e=0;e<c.length;e++){let[t,s]=c[e].split("-");await p()({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:l,root_user_id:r.id,database:t,table:s,priviledge:i}})}t.json({success:!!n?.affectedRows})}let E=(0,u.M)(s,"default"),h=(0,u.M)(s,"config"),m=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/updateAdminUserAccess",pathname:"/api/updateAdminUserAccess",bundlePath:"",filename:""},userland:s})},6420:(e,t,r)=>{r(81630);let s=r(51348),a=r(72907),i=r(29021);async function u(e,t,r,u){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let l=a(e.cookies.datasquirelAuthKey);if(!l)return null;let d=JSON.parse(l);if(!d.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${d.csrf_k}`)))return null;let n=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!n)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!i.existsSync(`${n}/${d.csrf_k}`))return null;if(0==d.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${d.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return d?.date&&Date.now()-d.date>6048e5?null:d}e.exports=u},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:a}=r(55511),{Buffer:i}=r(79428);e.exports=e=>{let t=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),i.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}}};var t=require("../../webpack-api-runtime.js");t.C(e);var r=e=>t(t.s=e),s=t.X(0,[4050],()=>r(98397));module.exports=s})();