dsql-admin/dsql-app/.local_dist/server/pages/api/admin/runUserDbQuery.js
Benjamin Toby 81cf010cb5 Updates
2025-01-14 16:27:08 +01:00

16 lines
7.8 KiB
JavaScript

"use strict";(()=>{var e={};e.id=6799,e.ids=[6799],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")},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}}})},74336:(e,r,t)=>{t.r(r),t.d(r,{config:()=>d,default:()=>_,routeModule:()=>p});var s={};t.r(s),t.d(s,{default:()=>i});var n=t(89947),o=t(2706),a=t(96762),l=t(30944),u=t(67619),c=t(87369);async function i(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Wrong Method"});let t=await (0,c.A)(e);if(!t?.logged_in_status)return r.json({success:!1,log:"No Logs"});let{database:s,query:n}=e.body;e.body.user;try{let e=await (0,l.A)({database:s,queryString:n});if(!e)return r.json({success:!1,msg:"Query Failed!"});r.json({success:!0,result:e})}catch(e){console.log(e.message),(0,u.A)({component:"/api/runUserDbQuery/main-catch-error",message:e.message}),r.json({success:!1})}}let _=(0,a.M)(s,"default"),d=(0,a.M)(s,"config"),p=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/admin/runUserDbQuery",pathname:"/api/admin/runUserDbQuery",bundlePath:"",filename:""},userland:s})},87369:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(95969),n=t(89159);async function o(e){let{keyCookieName:r,csrfCookieName:t}=(0,n.A)(),o=`${r}_su`;if(!e.cookies?.[o])return console.log("No auth key cookie found"),null;let a=(0,s.A)({encryptedString:e.cookies[o]});if(!a)return console.log("No user payload found"),null;let l=JSON.parse(a);return l.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):l.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):l}},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",o=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),o&&(a+=`${o}_`),a+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),o&&(l+=`${o}_`),l+=s;let u=r;return e?.userId&&(u+=`user_${e.userId}_`),o&&(u+=`${o}_`),{keyCookieName:a,csrfCookieName:l,oneTimeCodeName:u+=n}}},43775:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(95969);let n=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function o({unparsedResults:e,tableSchema:r}){let t=[];try{for(let o=0;o<e.length;o++){let a=e[o],l=Object.keys(a);for(let e=0;e<l.length;e++){let t=l[e],o=r?.fields[e];if(t?.match(n))continue;let u=a[t];("number"==typeof u||u)&&o?.encrypted&&u?.match(/./)&&(a[t]=(0,s.A)({encryptedString:u}))}t.push(a)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},67619:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(29021),n=t.n(s);async function o({user:e,message:r,component:t,noMail:s,req:o}){let a=new Date,l=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],t=o.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||s||r||o.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}`),o?.url&&(s+=`
URL: ${o.url}`),o?.body&&(s+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),l&&(s+=`
IP: ${l}`),s+=`
Date: ${a.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)}}},30944:(e,r,t)=>{t.d(r,{A:()=>l});var s=t(43775),n=t(67619),o=t(7447),a=t(64292);async function l({queryString:e,queryValuesArray:r,database:t,tableSchema:l,useLocal:u,debug:c}){let i=(0,o.A)({fa:!0});u&&(i=(0,o.A)({local:!0})),t?.match(/^datasquirel$/)&&(i=(0,o.A)()),c&&(console.log("varDatabaseDbHandler:query:",e),console.log("varDatabaseDbHandler:values:",r));let _=await (0,a.A)(i,e,r);if(c&&console.log("varDatabaseDbHandler:results:",_),_&&l)try{return await (0,s.A)({unparsedResults:_,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,n.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(_)return _;else return null}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(55511),n=t(79428),o=t(32443);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:a,salt:l,keyLen:u,algorithm:c,bufferAllocSize:i}=(0,o.A)({encryptionKey:r});if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let _=(0,s.scryptSync)(a,l,u),d=n.Buffer.alloc(i,0),p=(0,s.createDecipheriv)(c,_,d);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},64292:(e,r,t)=>{async function s(e,r,t){try{if("string"==typeof r){let s=await e.query(n(r),t);return JSON.parse(JSON.stringify(s))}if("object"!=typeof r)return null;{let t=[];for(let s=0;s<r.length;s++)try{let o=r[s],a=await e.query(n(o.query),o.values);t.push(JSON.parse(JSON.stringify(a)))}catch(e){t.push(null)}return t}}catch(e){return null}finally{e.end()}}function n(e){return e.replace(/\n/gm,"").replace(/ {2,}/g,"").trim()}t.d(r,{A:()=>s})},7447:(e,r,t)=>{t.d(r,{A:()=>o});var s=t(9973),n=t.n(s);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):e?.fa?global.DSQL_FULL_ACCESS_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}}):global.DSQL_DB_CONN||n()({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:e?.noDb?void 0:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4"}})}},32443:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?function(e,r){try{let r=Number(e);if("number"!=typeof r||isNaN(r))return 0;return Math.round(r)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},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=74336);module.exports=t})();