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

1 line
3.8 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +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")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},33873:e=>{e.exports=require("path")},7522:(e,r,s)=>{s.r(r),s.d(r,{config:()=>p,default:()=>c,routeModule:()=>f});var t={};s.r(t),s.d(t,{default:()=>_});var i=s(89947),a=s(2706),n=s(96762),u=s(48786),l=s(69842),d=s(98e3);s(29021),s(33873);let{execSync:o}=s(79646);async function _(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let s=await (0,l.A)(e,r,!0);if(!s)return r.json({success:!1,msg:"Unauthorized"});let{userObject:t,database_access:i,user_priviledge:a,db_tables:n,inv_user_id:o}=e.body,_=await (0,u.A)("UPDATE user_users SET database_access = ? ,user_priviledge = ? WHERE user_id = ? AND email = ?",[i,a,s.id,t.email]),c=n.split("|");await (0,u.A)(`DELETE FROM delegated_user_tables WHERE root_user_id='${s.id}' AND delegated_user_id='${o}'`);for(let e=0;e<c.length;e++){let[r,t]=c[e].split("-");await (0,d.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:o,root_user_id:s.id,database:r,table:t,priviledge:a}})}r.json({success:!!_?.affectedRows})}let c=(0,n.M)(t,"default"),p=(0,n.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:()=>l});var t=s(48786),i=s(95969),a=s(29021),n=s.n(a),u=s(89159);async function l(e,r,s){let{keyCookieName:a,csrfCookieName:l}=(0,u.A)();if(!e.cookies?.[a]?.match(/./))return null;let d=(0,i.A)({encryptedString:e.cookies[a]});if(!d)return null;let o=JSON.parse(d);if(!o.csrf_k||s&&!Object.keys(e.headers).find(e=>e.includes(o.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(s&&!n().existsSync(`${_}/${o.csrf_k}`))return null;if(0==o.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${o.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return o?.date&&Date.now()-o.date>6048e5?null:o}},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+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),a&&(n+=`${a}_`),n+=s;let u=r;e?.userId&&(u+=`user_${e.userId}_`),a&&(u+=`${a}_`),u+=t;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:n,csrfCookieName:u,oneTimeCodeName:l+=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,n=s||process.env.DSQL_ENCRYPTION_SALT,u=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(!n?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,t.scryptSync)(a,n,u),d=i.Buffer.alloc(16,0),o=(0,t.createDecipheriv)("aes-192-cbc",l,d);try{let r=o.update(e,"hex","utf8");return r+=o.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));module.exports=t})();