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

1 line
3.5 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +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,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>E,routeModule:()=>m});var s={};t.r(s),t.d(s,{default:()=>f});var i=t(89947),a=t(2706),n=t(96762),o=t(51348),l=t.n(o),u=t(6420),d=t.n(u),c=t(47670),_=t.n(c);t(29021),t(33873);let{execSync:p}=t(79646);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await d()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{userObject:s,database_access:i,user_priviledge:a,db_tables:n,inv_user_id:o}=e.body,u=await l()("UPDATE user_users SET database_access = ? ,user_priviledge = ? WHERE user_id = ? AND email = ?",[i,a,t.id,s.email]),c=n.split("|");await l()(`DELETE FROM delegated_user_tables WHERE root_user_id='${t.id}' AND delegated_user_id='${o}'`);for(let e=0;e<c.length;e++){let[r,s]=c[e].split("-");await _()({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:o,root_user_id:t.id,database:r,table:s,priviledge:a}})}r.json({success:!!u?.affectedRows})}let E=(0,n.M)(s,"default"),S=(0,n.M)(s,"config"),m=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateAdminUserAccess",pathname:"/api/updateAdminUserAccess",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),i=t(72835),a=t(29021),n=t(31341);async function o(e,r,t,o){let{keyCookieName:l,csrfCookieName:u}=n();if(!e.cookies?.[l]?.match(/./))return null;let d=i({encryptedString:e.cookies[l]});if(!d)return null;let c=JSON.parse(d);if(!c.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${_}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=o},31341:e=>{e.exports=function(){let e=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},72835:(e,r,t)=>{let{scryptSync:s,createDecipheriv:i}=t(55511),{Buffer:a}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let n=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=t||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!n?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=i("aes-192-cbc",s(n,o,l),a.alloc(16,0));try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[4050],()=>t(98397));module.exports=s})();