dsql-admin/dsql-app/.local_dist/server/chunks/4237.js

16 lines
6.2 KiB
JavaScript
Raw Normal View History

2024-12-05 07:03:33 +00:00
"use strict";exports.id=4237,exports.ids=[4237],exports.modules={77538:(e,t,r)=>{let a=r(29021),{IncomingMessage:s}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:s,req:n}){let l=new Date,o=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],t=n.headers["x-real-ip"],r=n.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=r||a||t||n.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
Error Message: ${t}
Component: ${r}`;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}`),n?.url&&(s+=`
URL: ${n.url}`),n?.body&&(s+=`
Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(s+=`
IP: ${o}`),s+=`
Date: ${l.toDateString()}
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let c=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",s),a.appendFileSync("./.tmp/error.log",`
${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},77619:(e,t,r)=>{let a=r(29021),s=r(72907);e.exports=({key:e,database:t,table:r,user_id:n})=>{if(!e||!n)return null;try{let l=process.env.DSQL_API_KEYS_PATH;if(!l)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");let o=s(e),c=JSON.parse(o||""),i=a.existsSync(`${l}/${c.sign}`);if(String(c.user_id)!==String(n)||!i)return null;if(!c.target_database)return c;if(!t&&c.target_database)return null;let u=c.target_database?.split(",").includes(String(t));if(u&&!c.target_table)return c;if(u&&!r&&c.target_table)return null;if(c.target_table?.split(",").includes(String(r)))return c;return null}catch(e){return console.log(`api-cred ERROR: ${e.message}`),null}}},64122:(e,t,r)=>{let a=r(51348),s=r(21339);async function n({dbContext:e,paradigm:t,dbFullName:r,tableName:n,identifierColumnName:l,identifierValue:o}){try{let c=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),i=c?a:s,u=`DELETE FROM ${n} WHERE \`${l}\`=?`;return c?await i(u,[o]):await i({paradigm:t,queryString:u,database:r,queryValues:[o]})}catch(e){return null}}e.exports=n},8238:(e,t,r)=>{r(29021);let a=r(44900),s=r(94709),n=r(96064),l=r(48225),o=r(47670),c=r(33364),i=r(64122),u=r(6061),d=r(33872);async function p({dbFullName:e,query:t,readOnly:r,dbSchema:p,queryValuesArray:m,tableName:g,local:f}){let y,_,b;if(p)try{let e=g||("string"==typeof t?null:t?t?.table:null);if(!e)throw Error("No table name provided");b=p.tables.filter(t=>t?.tableName===e)[0]}catch(e){}try{if("string"==typeof t){let l=d(t);if(r&&l.match(/^alter|^delete|information_schema|databases|^create/i))throw Error("Wrong Input!");if(f){let e=await a(l,m);y=b?u({unparsedResults:e,tableSchema:b}):e}else y=r?await n({queryString:l,queryValuesArray:m,database:e,tableSchema:b}):await s({queryString:l,queryValuesArray:m,database:e,tableSchema:b})}else if("object"==typeof t){let{data:r,action:a,table:s,identifierColumnName:n,identifierValue:l,update:u,duplicateColumnName:d,duplicateColumnValue:p}=t;switch(a.toLowerCase()){case"insert":y=await o({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:s,data:r,update:u,duplicateColumnName:d,duplicateColumnValue:p,tableSchema:b}),y?.insertId||(_=Error("Couldn't insert data"));break;case"update":y=await c({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:s,data:r,identifierColumnName:n,identifierValue:l,tableSchema:b});break;case"delete":y=await i({dbContext:f?"Master":"Dsql User",paradigm:"Full Access",dbFullName:e,tableName:s,identifierColumnName:n,identifierValue:l,tableSchema:b});break;default:y=null}}}catch(e){l({component:"functions/backend/runQuery",message:e.message}),y=null,e=e.message}return{result:y,error:_}}e.exports=p},72907:(e,t,r)=>{let{scryptSync:a,createDecipheriv:s}=r(55511),{Buffer:n}=r(79428);e.exports=e=>{let t=s("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),n.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.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$/},94709:(e,t,r)=>{let a=r(21339),s=r(6061),n=r(48225);e.exports=async function({queryString:e,database:t,tableSchema:r,queryValuesArray:l,local:o}){let c;try{c=await a({paradigm:"Full Access",database:t,queryString:e,queryValues:l})}catch(e){return n({component:"fullAccessDbHandler",message:e.message}),e.message}if(c&&r){let e=c;return await s({unparsedResults:e,tableSchema:r})}return c||null}},6061:(e,t,r)=>{let a=r(72907),s=r(30003);e.exports=async function({unparsedResults:e,tableSchema:t}){let r=[];try{for(let n=0;n<e.length;n++){let l=e[n],o=Object.keys(l);for(let e=0;e<o.length;e++){let r=o[e],n=t?.fields[e];if(r?.match(s))continue;let c=l[r];("number"==typeof c||c)&&n?.encrypted&&c?.match(/./)&&(l[r]=a(c))}r.push(l)}return r}catch(t){return console.log("ERROR in parseDbResults Function =>",t.message),e}}},96064:(e,t,r)=>{r(29021);let a=r(48225