dsql-admin/dsql-app/.local_dist/server/pages/api/getDatabaseTables.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

16 lines
4.9 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")},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")},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}}})},34029:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>_,routeModule:()=>E});var s={};t.r(s),t.d(s,{default:()=>p});var a=t(89947),n=t(2706),i=t(96762),o=t(6420),l=t.n(o),u=t(77538),c=t.n(u),d=t(51348),f=t.n(d);async function p(e,r){if("GET"!==e.method)return r.json({user:null,msg:"Registration Failed!"});let t=await l()(e,r);if(!t)return r.json({success:!1,msg:"Unauthorized"});let s=e.query.dbSlug,a=e.query.dbOwnerId,n=e.query.delegatedUserId;try{let e=await f()("SELECT id FROM user_databases WHERE user_id=? AND db_slug=?",[a,s]);if(!e||!e[0])return r.json({success:!1,msg:"Database not found"});let t=await f()("SELECT table_name,table_slug FROM user_database_tables WHERE user_id=? AND db_id=?",[a,e[0].id]),i=await f()("SELECT `database`,`table` FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[a,n]);r.json({success:!0,tables:t,accessed_tables:i})}catch(e){c()({component:"/api/getDatabaseTables/main-catch-error",message:e.message,user:t}),r.json({success:!1})}}t(29021);let _=(0,i.M)(s,"default"),S=(0,i.M)(s,"config"),E=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/getDatabaseTables",pathname:"/api/getDatabaseTables",bundlePath:"",filename:""},userland:s})},77538:(e,r,t)=>{let s=t(29021),{IncomingMessage:a}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:a,req:n}){let i=new Date,o=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.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}`),n?.url&&(a+=`
URL: ${n.url}`),n?.body&&(a+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(a+=`
IP: ${o}`),a+=`
Date: ${i.toDateString()}
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let l=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",`
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let s=t(51348),a=t(72907),n=t(29021);async function i(e,r,t,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=a(e.cookies.datasquirelAuthKey);if(!o)return null;let l=JSON.parse(o);if(!l.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let u=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!u)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!n.existsSync(`${u}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=i},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:a}=t(55511),{Buffer:n}=t(79428);e.exports=e=>{let r=a("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},51348:(e,r,t)=>{let s=t(9973),a=t(21580),n=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:a()}});async function i(...e){try{let r=await n.query(...e);return await n.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=i},21580:(e,r,t)=>{let s=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=r(r.s=34029);module.exports=t})();