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

1 line
4.0 KiB
JavaScript
Raw Normal View History

2025-01-14 07:24:54 +00:00
"use strict";(()=>{var e={};e.id=294,e.ids=[294],e.modules={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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},7522:(e,r,s)=>{s.r(r),s.d(r,{config:()=>_,default:()=>c,routeModule:()=>f});var t={};s.r(t),s.d(t,{default:()=>l});var i=s(89947),a=s(2706),o=s(96762),n=s(48786),d=s(69842),u=s(98e3);async function l(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await (0,d.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{userObject:t,database_access:i,user_priviledge:a,db_tables:o,inv_user_id:l}=e.body,c=await (0,n.A)("UPDATE user_users SET database_access = ? ,user_priviledge = ? WHERE user_id = ? AND email = ?",[i,a,s.id,t.email]),_=o.split("|");await (0,n.A)(`DELETE FROM delegated_user_tables WHERE root_user_id='${s.id}' AND delegated_user_id='${l}'`);for(let e=0;e<_.length;e++){let[r,t]=_[e].split("-");await (0,u.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:l,root_user_id:s.id,database:r,table:t,priviledge:a}})}r.json({success:!!c?.affectedRows})}let c=(0,o.M)(t,"default"),_=(0,o.M)(t,"config"),f=new i.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/updateAdminUserAccess",pathname:"/api/updateAdminUserAccess",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>d});var t=s(48786),i=s(95969),a=s(29021),o=s.n(a),n=s(89159);async function d(e,r,s){try{let{keyCookieName:a,csrfCookieName:d}=(0,n.A)();if(!e.cookies?.[a]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,i.A)({encryptedString:e.cookies[a]});if(!u)throw Error("Couldn't decrypt auth cookie!");let l=JSON.parse(u);if(!l.csrf_k)throw Error("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(l.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(s&&!o().existsSync(`${c}/${l.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==l.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(l?.date&&Date.now()-l.date>6048e5)throw Error("Key expired!");return l}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.message}`),null}}},89159:(e,r,s)=>{s.d(r,{A:()=>t});function t(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",i=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=s;let n=r;e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),n+=t;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),a&&(d+=`${a}_`),{keyCookieName:o,csrfCookieName:n,oneTimeCodeName:d+=i}}},95969:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511),i=s(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,n=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(a,o,n),u=i.Buffer.alloc(16,0),l=(0,t.createDecipheriv)("aes-192-cbc",d,u);try{let r=l.update(e,"hex","utf8");return r+=l.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[1251],()=>s(7522));modu