16 lines
6.3 KiB
JavaScript
16 lines
6.3 KiB
JavaScript
"use strict";(()=>{var e={};e.id=9785,e.ids=[9785],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")},92145:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>u,routeModule:()=>c});var i={};t.r(i),t.d(i,{default:()=>l});var s=t(89947),a=t(2706),n=t(96762),o=t(69842),d=t(49941);async function l(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,o.A)(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 (0,d.A)({query:e.body.query,user:t});r.json({success:!0,result:i})}let u=(0,n.M)(i,"default"),_=(0,n.M)(i,"config"),c=new s.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/addAdminUserUser",pathname:"/api/addAdminUserUser",bundlePath:"",filename:""},userland:i})},69842:(e,r,t)=>{t.d(r,{A:()=>d});var i=t(48786),s=t(95969),a=t(29021),n=t.n(a),o=t(89159);async function d(e,r,t){try{let{keyCookieName:a,csrfCookieName:d}=(0,o.A)();if(!e.cookies?.[a]?.match(/./))throw Error("Request Cookies not Found!");let l=(0,s.A)({encryptedString:e.cookies[a]});if(!l)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(l);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!n().existsSync(`${_}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,i.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throw Error("Key expired!");return u}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},49941:(e,r,t)=>{t.d(r,{A:()=>o});var i=t(67619),s=t(48786),a=t(98e3),n=t(7971);async function o({query:e,user:r,useLocal:t}){try{let i=t?n.A:s.A,{invite:o,database_access:d,priviledge:l,email:u}=e,_=[o,u],c=await i("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",_);if(!c||!c[0])throw Error("No Invitation Found");let E=[o],m=await i("SELECT first_name,last_name,email FROM users WHERE id=?",E);if(m?.[0]){let e=await i("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[o,r.id,u]);if(e?.[0])console.log("User already added");else{(0,a.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:o,invited_user_id:r.id,database_access:d,first_name:r.first_name,last_name:r.last_name,phone:r.phone,email:r.email,username:r.username,user_type:"admin",user_priviledge:l,image:r.image,image_thumbnail:r.image_thumbnail},useLocal:t});let e=await i("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[o,u]);if(await i("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[o,r.id]),e&&e[0]){let i=e[0].db_tables_data.split("|");for(let e=0;e<i.length;e++){let[s,n]=i[e].split("-");await (0,a.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:r.id,root_user_id:o,database:s,table:n,priviledge:l},useLocal:t})}}}await i("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[o,u])}}catch(e){(0,i.default)({component:"addAdminUserOnLogin",message:e.message,user:r})}}},89159:(e,r,t)=>{t.d(r,{A:()=>i});function i(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",i=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=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+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=i;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),a&&(d+=`${a}_`),{keyCookieName:n,csrfCookieName:o,oneTimeCodeName:d+=s}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var i=t(29021),s=t.n(i);async function a({user:e,message:r,component:t,noMail:i,req:a}){let n=new Date,o=(()=>{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)}catch(e){return null}})();try{let i=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(i+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),a?.url&&(i+=`
|
|
URL: ${a.url}`),a?.body&&(i+=`
|
|
Request Body: ${JSON.stringify(a.body,null,4)}`),o&&(i+=`
|
|
IP: ${o}`),i+=`
|
|
Date: ${n.toDateString()}
|
|
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let d=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",i),s().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${d}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var i=t(55511),s=t(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,n=t||process.env.DSQL_ENCRYPTION_SALT,o=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 d=(0,i.scryptSync)(a,n,o),l=s.Buffer.alloc(16,0),u=(0,i.createDecipheriv)("aes-192-cbc",d,l);try{let r=u.update(e,"hex","utf8");return r+=u.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,[1251],()=>t(92145));module.exports=i})(); |