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

16 lines
9.4 KiB
JavaScript

"use strict";exports.id=6133,exports.ids=[6133],exports.modules={96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,s){return s in r?r[s]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,s)):"function"==typeof r&&"default"===s?r:void 0}}})},69842:(e,r,s)=>{s.d(r,{A:()=>o});var n=s(39908),t=s.n(n);async function o(e,r,s){let n=t()({req:e,level:s?"deep":void 0});return console.log(n),n.payload}},67619:(e,r,s)=>{s.d(r,{A:()=>o});var n=s(29021),t=s.n(n);async function o({user:e,message:r,component:s,noMail:n,req:o}){let a=new Date,i=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],s=o.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],t=s||n||r||o.socket.remoteAddress;if(!t)return null;return String(t)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${s}`;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}`),o?.url&&(n+=`
URL: ${o.url}`),o?.body&&(n+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(n+=`
IP: ${i}`),n+=`
Date: ${a.toDateString()}
========================================`,t().existsSync("./.tmp/error.log")||t().writeFileSync("./.tmp/error.log","","utf-8");let l=t().readFileSync("./.tmp/error.log","utf-8");t().writeFileSync("./.tmp/error.log",n),t().appendFileSync("./.tmp/error.log",`
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,s)=>{s.d(r,{A:()=>a});var n=s(55511),t=s(79428),o=s(32443);function a({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:a,salt:i,keyLen:l,algorithm:c,bufferAllocSize:u}=(0,o.A)({encryptionKey:r});if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let E=(0,n.scryptSync)(a,i,l),S=t.Buffer.alloc(u,0),_=(0,n.createDecipheriv)(c,E,S);try{let r=_.update(e,"hex","utf8");return r+=_.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,s)=>{s.d(r,{A:()=>a});var n=s(55511),t=s(79428),o=s(32443);function a({data:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let{key:a,salt:i,keyLen:l,algorithm:c,bufferAllocSize:u}=(0,o.A)({encryptionKey:r});if(!a?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let E=(0,n.scryptSync)(a,i,l),S=t.Buffer.alloc(u,0),_=(0,n.createCipheriv)(c,E,S);try{let r=_.update(e,"utf8","hex");return r+=_.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},5437:(e,r,s)=>{s.d(r,{A:()=>_});var n=s(33873),t=s.n(n),o=s(47795),a=s.n(o),i=s(66866),l=s(41864);async function c({username:e,host:r,grants:s,userId:n}){let t=!1;if(console.log("Handling Grants for User =>",e,r),!e)return console.log("No username provided."),t;if(!r)return console.log(`No Host provided. \x1b[35m\`--host\`\x1b[0m flag is required`),t;if(!s)return console.log("No grants Array provided."),t;try{let o=await (0,i.A)(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(o?.[0]?.User){let t=await (0,i.A)(`SHOW GRANTS FOR '${e}'@'${r}'`);for(let e=0;e<t.length;e++){let r=t[e],s=r?.[Object.keys(r)[0]];if(s?.match(/GRANT .* PRIVILEGES ON .* TO/)){let e=s.replace(/GRANT/,"REVOKE").replace(/ TO /," FROM ");await (0,i.A)(e)}}for(let t=0;t<s.length;t++){let{database:o,table:a,privileges:l}=s[t],c="*"==a?"*":`\`${a}\``,u="*"==o?`\`${process.env.DSQL_USER_DB_PREFIX}${n}_%\``:`\`${o}\``,E=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),S=`GRANT ${E} ON ${u}.${c} TO '${e}'@'${r}'`;await (0,i.A)(S)}}t=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}return t}var u=s(68829),E=s(95969);s(60818).config({path:t().resolve(__dirname,"../../../.env")});let S=process.env.DSQL_DB_HOST||"127.0.0.1";async function _({userId:e,mariadbUserHost:r,mariadbUsername:s,sqlUserID:n}){let t=await (0,l.A)({query:"SELECT * FROM mariadb_users"});if(!t?.[0])return;let o=!!e&&e==Number(process.env.DSQL_SU_USER_ID);for(let _=0;_<t.length;_++){let d=t[_];if(d&&(!e||d.user_id==e))try{let{mariadb_user:t,mariadb_host:_,mariadb_pass:p,user_id:A}=d,y=await (0,i.A)(`SELECT * FROM mysql.user WHERE User = '${t}' AND Host = '${_}'`),f=e&&n?await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[n,e]}):null,D=Array.isArray(f)?f?.[0]:void 0,g=!!D&&!!String(D.primary)?.match(/1/),R=!!y?.[0]?.User,N=o?s:`dsql_user_${A}`,m=D?.password?D.password:R?p:a().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),L=D?.password?D.password:R?p:(0,u.A)({data:m,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(R||n||g||r||s)!R&&r&&await (0,i.A)(`CREATE USER IF NOT EXISTS '${N}'@'${r}' IDENTIFIED BY '${m}'`);else{let e=await (0,i.A)(`CREATE USER IF NOT EXISTS '${N}'@'${S}' IDENTIFIED BY '${m}'`);console.log("createNewUser",e),console.log(`User ${d.id}: ${d.first_name} ${d.last_name} SQL credentials successfully updated.`),await (0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,S,L,d.id]})}if(g){let e=r||_;await (0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,e,L,d.id]})}let v=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` = 1",values:[A]}),O=!!(Array.isArray(v)&&v?.[0]?.user_id),T=[{database:"*",table:"*",privileges:["ALL"]}];O||await (0,l.A)({query:"INSERT INTO mariadb_users (user_id, username, password, `primary`, grants) VALUES (?, ?, ?, ?, ?)",values:[A,N,L,"1",JSON.stringify(T)]});let h=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` != '1'",values:[A]});if(Array.isArray(h))for(let n=0;n<h.length;n++){let t=h[n];if(t&&t.username!=s||r&&t.host!=r)continue;let o=(0,E.A)({encryptedString:t.password||"",encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT}),a=await (0,i.A)(`SELECT * FROM mysql.user WHERE User='${t.username}' AND Host='${t.host}'`);a?.[0]?.User||await (0,i.A)(`CREATE USER IF NOT EXISTS '${t.username}'@'${t.host}' IDENTIFIED BY '${o}'`),await c({username:t.username,host:t.host,grants:t.grants&&"string"==typeof t.grants?JSON.parse(t.grants):[],userId:String(e)})||console.log(`Error in handling grants for user ${t.username}@${t.host}`)}}catch(e){console.log("Error in adding SQL user =>",e.message)}}}},41864:(e,r,s)=>{s.d(r,{A:()=>l});var n=s(29021),t=s.n(n),o=s(33873),a=s.n(o),i=s(7447);async function l({query:e,values:r}){let s;let n=(0,i.A)();try{s=e&&r?await n.query(e,r):await n.query(e)}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(n.config()),t().appendFileSync(a().resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),s=null}finally{await n?.end()}return s?JSON.parse(JSON.stringify(s)):null}},66866:(e,r,s)=>{s.d(r,{A:()=>t});var n=s(41864);async function t(e){let r;try{r=await (0,n.A)({query:e})}catch(e){console.log("ERROR in noDatabaseDbHandler =>",e.message)}return r||null}},48786:(e,r,s)=>{s.d(r,{A:()=>t});var n=s(7447);async function t(...e){let r=(0,n.A)();try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let s=await r.query(...e);return JSON.parse(JSON.stringify(s))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},7447:(e,r,s)=>{s.d(r,{A:()=>o});var n=s(9973),t=s.n(n);function o(e){return e?.ro?DSQL_READ_ONLY_DB_CONN||t()({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||t()({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||t()({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,s)=>{s.d(r,{A:()=>n});function n(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 s}});var s=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,s)=>{e.exports=s(75600)}};