16 lines
5.0 KiB
JavaScript
16 lines
5.0 KiB
JavaScript
"use strict";(()=>{var e={};e.id=9785,e.ids=[9785],e.modules={28187:e=>{e.exports=require("@moduletrace/datasquirel")},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 a=t(89947),s=t(2706),n=t(96762),l=t(6420),u=t.n(l),d=t(98968),o=t.n(d);async function _(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await u()(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 o()({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 a.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:i})},98968:(e,r,t)=>{t(29021),t(28187);let i=t(77538),a=t(51348),s=t(47670);e.exports=async function({query:e,user:r}){try{let{invite:t,database_access:i,priviledge:n,email:l}=e,u=await a("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,l]);if(!u||!u[0])throw Error("No Invitation Found");let d=await a("SELECT first_name,last_name,email FROM users WHERE id=?",[t]);if(d?.[0]){let e=await a("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{s({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 a("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[t,l]);if(await a("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[a,l]=i[e].split("-");await s({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:t,database:a,table:l,priviledge:n}})}}}await a("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})}}},77538:(e,r,t)=>{let i=t(29021),{IncomingMessage:a}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:a,req:s}){let n=new Date,l=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],i=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||i||r||s.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),s?.url&&(a+=`
|
|
URL: ${s.url}`),s?.body&&(a+=`
|
|
Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(a+=`
|
|
IP: ${l}`),a+=`
|
|
Date: ${n.toDateString()}
|
|
========================================`,i.existsSync("./.tmp/error.log")||i.writeFileSync("./.tmp/error.log","","utf-8");let u=i.readFileSync("./.tmp/error.log","utf-8");i.writeFileSync("./.tmp/error.log",a),i.appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let i=t(51348),a=t(72907),s=t(29021);async function n(e,r,t,n){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let l=a(e.cookies.datasquirelAuthKey);if(!l)return null;let u=JSON.parse(l);if(!u.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!s.existsSync(`${d}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await i(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=n},72907:(e,r,t)=>{let{scryptSync:i,createDecipheriv:a}=t(55511),{Buffer:s}=t(79428);e.exports=e=>{let r=a("aes-192-cbc",i(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),s.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}}};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})(); |