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

16 lines
4.1 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";(()=>{var e={};e.id=7539,e.ids=[7539],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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},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}}})},8953:(e,r,t)=>{t.r(r),t.d(r,{config:()=>P,default:()=>_,routeModule:()=>A});var n={};t.r(n),t.d(n,{default:()=>m});var i=t(89947),s=t(2706),a=t(96762),o=t(77538),l=t.n(o),u=t(77619),c=t.n(u),d=t(72907),p=t.n(d),f=t(33873),g=t.n(f);let S=t(29021);async function m(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=e.body,{url:n,key:i,database:s,dbSchema:a,type:o}=t;try{let e=c()({key:i,database:s?.db_slug,user_id:t.user_id});if(!e?.user_id)throw Error("Api Credentials invalid!");let n=p()(i),{user_id:a,full_access:o,csrf:l}=n?JSON.parse(n):null;if(!o||!l)return r.json({success:!1,msg:"Unauthorized"});let u=g().resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${a}`,"main.json");if(!S.existsSync(u))throw Error("User Shcema data file doesn't exist!");let d=JSON.parse(S.readFileSync(u,"utf-8"));r.json({success:!0,payload:d})}catch(e){console.log("Connect Verification Error, =>",e.message),l()({component:"/api/connect/main-catch-error",message:e.message}),r.json({success:!1,msg:"Connect Verification Operation Failed!"})}}let _=(0,a.M)(n,"default"),P=(0,a.M)(n,"config"),A=new i.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/connect",pathname:"/api/connect",bundlePath:"",filename:""},userland:n})},77538:(e,r,t)=>{let n=t(29021),{IncomingMessage:i}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:i,req:s}){let a=new Date,o=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],i=t||n||r||s.socket.remoteAddress;if(!i)return null;return String(i)}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}`),s?.url&&(i+=`
URL: ${s.url}`),s?.body&&(i+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),o&&(i+=`
IP: ${o}`),i+=`
Date: ${a.toDateString()}
========================================`,n.existsSync("./.tmp/error.log")||n.writeFileSync("./.tmp/error.log","","utf-8");let l=n.readFileSync("./.tmp/error.log","utf-8");n.writeFileSync("./.tmp/error.log",i),n.appendFileSync("./.tmp/error.log",`
2024-11-05 11:12:42 +00:00
2024-12-05 07:03:33 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},77619:(e,r,t)=>{let n=t(29021),i=t(72907);e.exports=({key:e,database:r,table:t,user_id:s})=>{if(!e||!s)return null;try{let a=process.env.DSQL_API_KEYS_PATH;if(!a)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let o=i(e),l=JSON.parse(o||""),u=n.existsSync(`${a}/${l.sign}`);if(String(l.user_id)!==String(s)||!u)return null;if(!l.target_database)return l;if(!r&&l.target_database)return null;let c=l.target_database?.split(",").includes(String(r));if(c&&!l.target_table)return l;if(c&&!t&&l.target_table)return null;if(l.target_table?.split(",").includes(String(t)))return l;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},72907:(e,r,t)=>{let{scryptSync:n,createDecipheriv:i}=t(55511),{Buffer:s}=t(79428);e.exports=e=>{let r=i("aes-192-cbc",n(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}}},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=8953);module.exports=t})();