16 lines
5.8 KiB
JavaScript
16 lines
5.8 KiB
JavaScript
"use strict";(()=>{var e={};e.id=245,e.ids=[245],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},37811:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>d,routeModule:()=>f});var s={};t.r(s),t.d(s,{default:()=>c});var n=t(89947),a=t(2706),o=t(96762),i=t(69842),u=t(67619),l=t(48786);async function c(e,r){if("GET"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await (0,i.A)(e,r);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=e.query.dbSlug,n=e.query.dbOwnerId,a=e.query.delegatedUserId;try{let e=await (0,l.A)("SELECT id FROM user_databases WHERE user_id=? AND db_slug=?",[n,s]);if(!e||!e[0])return r.json({success:!1,msg:"Database not found"});let t=await (0,l.A)("SELECT table_name,table_slug FROM user_database_tables WHERE user_id=? AND db_id=?",[n,e[0].id]),o=await (0,l.A)("SELECT `database`,`table` FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[n,a]);r.json({success:!0,tables:t,accessed_tables:o})}catch(e){(0,u.default)({component:"/api/getDatabaseTables/main-catch-error",message:e.message,user:t}),r.json({success:!1})}}t(29021);let d=(0,o.M)(s,"default"),_=(0,o.M)(s,"config"),f=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/getDatabaseTables",pathname:"/api/getDatabaseTables",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>u});var s=t(48786),n=t(95969),a=t(29021),o=t.n(a),i=t(89159);async function u(e,r,t){try{let{keyCookieName:a,csrfCookieName:u}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))throw Error("Request Cookies not Found!");let l=(0,n.A)({encryptedString:e.cookies[a]});if(!l)throw Error("Couldn't decrypt auth cookie!");let c=JSON.parse(l);if(!c.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!o().existsSync(`${d}/${c.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==c.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(c?.date&&Date.now()-c.date>6048e5)throw Error("Key expired!");return c}catch(e){return console.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=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+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=t;let i=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=s;let u=r;return e?.userId&&(u+=`user_${e.userId}_`),a&&(u+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:u+=n}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var s=t(29021),n=t.n(s);async function a({user:e,message:r,component:t,noMail:s,req:a}){let o=new Date,i=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||s||r||a.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),a?.url&&(s+=`
|
|
URL: ${a.url}`),a?.body&&(s+=`
|
|
Request Body: ${JSON.stringify(a.body,null,4)}`),i&&(s+=`
|
|
IP: ${i}`),s+=`
|
|
Date: ${o.toDateString()}
|
|
========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let u=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",s),n().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${u}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(55511),n=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,o=t||process.env.DSQL_ENCRYPTION_SALT,i=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(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let u=(0,s.scryptSync)(a,o,i),l=n.Buffer.alloc(16,0),c=(0,s.createDecipheriv)("aes-192-cbc",u,l);try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=37811);module.exports=t})(); |