dsql-admin/dsql-app/.local_dist/server/chunks/8540.js
Benjamin Toby d9d32a4643 Updates
2024-12-09 13:27:08 +01:00

16 lines
6.1 KiB
JavaScript

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