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

28 lines
7.5 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")},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}}})},89496:(e,r,t)=>{t.r(r),t.d(r,{config:()=>f,default:()=>S,routeModule:()=>_});var s={};t.r(s),t.d(s,{default:()=>m});var n=t(89947),a=t(2706),o=t(96762),l=t(57638),c=t.n(l),u=t(77538),i=t.n(u),d=t(19131),p=t.n(d);async function m(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Wrong Method"});let t=await p()(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{if(!n?.match(/^select .* from .*|^show tables$|^show indexes from .*|show columns from .*|^update |^delete from /i)||n?.match(/^create user|INFORMATION_SCHEMA/i))return r.json({success:!1,msg:"Disallowed query"});let e=await c()({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),i()({component:"/api/runUserDbQuery/main-catch-error",message:e.message}),r.json({success:!1})}}t(29021);let S=(0,o.M)(s,"default"),f=(0,o.M)(s,"config"),_=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/admin/runUserDbQuery",pathname:"/api/admin/runUserDbQuery",bundlePath:"",filename:""},userland:s})},77538:(e,r,t)=>{let s=t(29021),{IncomingMessage:n}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:n,req:a}){let o=new Date,l=(()=>{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 n=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(n+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),a?.url&&(n+=`
URL: ${a.url}`),a?.body&&(n+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),l&&(n+=`
IP: ${l}`),n+=`
Date: ${o.toDateString()}
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let c=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},19131:(e,r,t)=>{let{IncomingMessage:s}=t(81630),n=t(72907);e.exports=async function(e){if(!e.cookies?.datasquirelSuAdminUserAuthKey)return console.log("No auth key cookie found"),null;let r=n(e.cookies.datasquirelSuAdminUserAuthKey);if(!r)return console.log("No user payload found"),null;let t=JSON.parse(r);return t.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):t.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):t}},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:a}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},30003:e=>{e.exports=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/},6061:(e,r,t)=>{let s=t(72907),n=t(30003);e.exports=async function({unparsedResults:e,tableSchema:r}){let t=[];try{for(let a=0;a<e.length;a++){let o=e[a],l=Object.keys(o);for(let e=0;e<l.length;e++){let t=l[e],a=r?.fields[e];if(t?.match(n))continue;let c=o[t];("number"==typeof c||c)&&a?.encrypted&&c?.match(/./)&&(o[t]=s(c))}t.push(o)}return t}catch(r){return console.log("ERROR in parseDbResults Function =>",r.message),e}}},48225:(e,r,t)=>{let s=t(29021);e.exports=async function({user:e,message:r,component:t,noMail:n}){let a=`🚀 SERVER ERROR ===========================
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}
Error Message: ${r}
Component: ${t}
Date: ${Date()}
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",`
${o}`)}},57638:(e,r,t)=>{t(29021);let s=t(6061),n=t(48225),a=t(51348),o=t(21339);e.exports=async function({queryString:e,queryValuesArray:r,database:t,tableSchema:l}){let c;let u=!!t?.match(/^datasquirel$/),i=u?a:o;try{c=e&&r&&Array.isArray(r)&&r[0]?u?await i(e,r):await i({paradigm:"Full Access",database:t,queryString:e,queryValues:r}):u?await i(e):await i({paradigm:"Full Access",database:t,queryString:e})}catch(e){n({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(c&&l)try{let e=c;return await s({unparsedResults:e,tableSchema:l})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),n({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(c)return c;else return null}},51348:(e,r,t)=>{let s=t(9973),n=t(21580),a=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:n()}});async function o(...e){try{let r=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21339:(e,r,t)=>{let s=t(29021);t(33873);let n=t(9973),a=t(21580),o=n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:a()}});e.exports=function({paradigm:e,database:r,queryString:t,queryValues:l}){try{return new Promise((c,u)=>{let i=!!e?.match(/full.access|^fa$/i);try{function d(e){o.end(),c(JSON.parse(JSON.stringify(e)))}function p(e){o.end(),c({error:e.message,queryStringGenerated:t,queryValuesGenerated:l,sql:e.sql})}o=i?n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:r,ssl:a()}}):n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:r,ssl:a()}}),l&&Array.isArray(l)&&l[0]?o.query(t,l).then(d).catch(p):o.query(t).then(d).catch(p)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),c({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},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=89496);module.exports=t})();