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

16 lines
5.5 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";(()=>{var e={};e.id=9785,e.ids=[9785],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")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},81764:(e,r,t)=>{t.r(r),t.d(r,{config:()=>m,default:()=>c,routeModule:()=>p});var i={};t.r(i),t.d(i,{default:()=>_});var s=t(89947),a=t(2706),n=t(96762),l=t(6420),o=t.n(l),d=t(44767),u=t.n(d);async function _(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await o()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});console.log("Invitation Received by current logged in user, Loggin in VIA API ...");let i=await u()({query:e.body.query,user:t});r.json({success:!0,result:i})}let c=(0,n.M)(i,"default"),m=(0,n.M)(i,"config"),p=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:i})},6420:(e,r,t)=>{t(81630);let i=t(51348),s=t(72835),a=t(29021),n=t(31341);async function l(e,r,t,l){let{keyCookieName:o,csrfCookieName:d}=n();if(!e.cookies?.[o]?.match(/./))return null;let u=s({encryptedString:e.cookies[o]});if(!u)return null;let _=JSON.parse(u);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)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==_.verification_status&&!t){let e=await i(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return _?.date&&Date.now()-_.date>6048e5?null:_}e.exports=l},44767:(e,r,t)=>{let i=t(48225),s=t(51348),a=t(47670);e.exports=async function({query:e,user:r}){try{let{invite:t,database_access:i,priviledge:n,email:l}=e,o=await s("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,l]);if(!o||!o[0])throw Error("No Invitation Found");let d=await s("SELECT first_name,last_name,email FROM users WHERE id=?",[t]);if(d?.[0]){let e=await s("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[t,r.id,l]);if(e?.[0])console.log("User already added");else{a({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:t,invited_user_id:r.id,database_access:i,first_name:r.first_name,last_name:r.last_name,phone:r.phone,email:r.email,username:r.username,user_type:"admin",user_priviledge:n,image:r.image,image_thumbnail:r.image_thumbnail}});let e=await s("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,l]);if(await s("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[t,r.id]),e&&e[0]){let i=e[0].db_tables_data.split("|");for(let e=0;e<i.length;e++){let[s,l]=i[e].split("-");await a({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:t,database:s,table:l,priviledge:n}})}}}await s("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[t,l])}}catch(e){i({component:"addAdminUserOnLogin",message:e.message,user:r})}}},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")}}},48225:(e,r,t)=>{let i=t(29021),{IncomingMessage:s}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:s,req:a}){let n=new Date,l=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],i=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||i||r||a.socket.remoteAddress;if(!s)return null;return String(s
2024-12-05 07:03:33 +00:00
Error Message: ${r}
2024-12-06 13:24:26 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
2024-12-05 07:03:33 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2024-12-06 13:24:26 +00:00
User Email: ${e?.email}`),a?.url&&(s+=`
URL: ${a.url}`),a?.body&&(s+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),l&&(s+=`
IP: ${l}`),s+=`
2024-12-05 07:03:33 +00:00
Date: ${n.toDateString()}
2024-12-06 13:24:26 +00:00
========================================`,i.existsSync("./.tmp/error.log")||i.writeFileSync("./.tmp/error.log","","utf-8");let o=i.readFileSync("./.tmp/error.log","utf-8");i.writeFileSync("./.tmp/error.log",s),i.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-06 13:24:26 +00:00
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:i,createDecipheriv:s}=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,l=t||process.env.DSQL_ENCRYPTION_SALT,o=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(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=s("aes-192-cbc",i(n,l,o),a.alloc(16,0));try{let r=d.update(e,"hex","utf8");return r+=d.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),i=r.X(0,[4050],()=>t(81764));module.exports=i})();