dsql-admin/dsql-app/.local_dist/server/pages/api/updateAdminUserAccess.js
Benjamin Toby 885c11f674 Updates
2025-01-14 07:42:13 +01:00

1 line
4.1 KiB
JavaScript

"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),o=s(2706),a=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:o,db_tables:a,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,o,s.id,t.email]),_=a.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:o}})}r.json({success:!!c?.affectedRows})}let c=(0,a.M)(t,"default"),_=(0,a.M)(t,"config"),f=new i.PagesAPIRouteModule({definition:{kind:o.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),o=s(29021),a=s.n(o),n=s(89159);async function d(e,r,s){try{let{keyCookieName:o,csrfCookieName:d}=(0,n.A)();if(!e.cookies?.[o]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,i.A)({encryptedString:e.cookies[o]});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 console.log("req.headers",e.headers),console.log("userObject",l),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&&!a().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(e){return console.log(`userAuth Error: ${e.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",o=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),o&&(a+=`${o}_`),a+=s;let n=r;e?.userId&&(n+=`user_${e.userId}_`),o&&(n+=`${o}_`),n+=t;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),o&&(d+=`${o}_`),{keyCookieName:a,csrfCookieName:n,oneTimeCodeName:d+=i}}},95969:(e,r,s)=>{s.d(r,{A:()=>o});var t=s(55511),i=s(79428);function o({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,a=s||process.env.DSQL_ENCRYPTION_SALT,n=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(o,a,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));module.exports=t})();