"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}}})},55153:(e,r,s)=>{s.d(r,{On:()=>t.a,_n:()=>a}),s(76102);var n=s(65967),t=s.n(n);s(30889);var o=s(93726);let a=s.n(o)()},69842:(e,r,s)=>{s.d(r,{A:()=>a});var n=s(39383),t=s.n(n),o=s(55153);async function a(e,r,s,n){let a=t()({req:e,level:s?"deep":void 0}),i={DSQL_REMOTE_SQL_HOST:process.env.DSQL_REMOTE_SQL_HOST,DSQL_SU_USER_ID:process.env.DSQL_SU_USER_ID,DSQL_HOST_ENV:process.env.DSQL_HOST_ENV,DSQL_HOST:process.env.DSQL_HOST,DSQL_STATIC_HOST:process.env.DSQL_STATIC_HOST,DSQL_GOOGLE_CLIENT_ID:process.env.DSQL_GOOGLE_CLIENT_ID,DSQL_TINY_MCE_API_KEY:process.env.DSQL_TINY_MCE_API_KEY};return n&&a.payload?.id&&(0,o._n)(process.env.DSQL_SU_USER_ID)!==a.payload.id?{user:null,appData:i}:{user:a.payload,appData:i}}},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(31542);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:_}=(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 S=(0,n.scryptSync)(a,i,l),u=t.Buffer.alloc(_,0),E=(0,n.createDecipheriv)(c,S,u);try{let r=E.update(e,"hex","utf8");return r+=E.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(31542);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:_}=(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 S=(0,n.scryptSync)(a,i,l),u=t.Buffer.alloc(_,0),E=(0,n.createCipheriv)(c,S,u);try{let r=E.update(e,"utf8","hex");return r+=E.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},5437:(e,r,s)=>{s.d(r,{A:()=>E});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}\``,_="*"==o?`\`${process.env.DSQL_USER_DB_PREFIX}${n}_%\``:`\`${o}\``,S=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),u=`GRANT ${S} ON ${_}.${c} TO '${e}'@'${r}'`;await (0,i.A)(u)}}t=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}return t}var _=s(68829),S=s(95969);s(60818).config({path:t().resolve(__dirname,"../../../.env")});let u=process.env.DSQL_DB_HOST||"127.0.0.1";async function E({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 E=0;E<t.length;E++){let p=t[E];if(p&&(!e||p.user_id==e))try{let{mariadb_user:t,mariadb_host:E,mariadb_pass:d,user_id:D}=p,A=await (0,i.A)(`SELECT * FROM mysql.user WHERE User = '${t}' AND Host = '${E}'`),L=e&&n?await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[n,e]}):null,y=Array.isArray(L)?L?.[0]:void 0,f=!!y&&!!String(y.primary)?.match(/1/),R=!!A?.[0]?.User,v=o?s:`dsql_user_${D}`,N=y?.password?y.password:R?d:a().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),O=y?.password?y.password:R?d:(0,_.A)({data:N,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(R||n||f||r||s)!R&&r&&await (0,i.A)(`CREATE USER IF NOT EXISTS '${v}'@'${r}' IDENTIFIED BY '${N}'`);else{let e=await (0,i.A)(`CREATE USER IF NOT EXISTS '${v}'@'${u}' IDENTIFIED BY '${N}'`);console.log("createNewUser",e),console.log(`User ${p.id}: ${p.first_name} ${p.last_name} SQL credentials successfully updated.`),await (0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[v,u,O,p.id]})}if(f){let e=r||E;await (0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[v,e,O,p.id]})}let g=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` = 1",values:[D]}),m=!!(Array.isArray(g)&&g?.[0]?.user_id),T=[{database:"*",table:"*",privileges:["ALL"]}];m||await (0,l.A)({query:"INSERT INTO mariadb_users (user_id, username, password, `primary`, grants) VALUES (?, ?, ?, ?, ?)",values:[D,v,O,"1",JSON.stringify(T)]});let Q=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` != '1'",values:[D]});if(Array.isArray(Q))for(let n=0;n<Q.length;n++){let t=Q[n];if(t&&t.username!=s||r&&t.host!=r)continue;let o=(0,S.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(r){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",r.message),console.log(r),console.log(n.config());let e=a().resolve(process.cwd(),"./.tmp");t().existsSync(e)||t().mkdirSync(e,{recursive:!0}),t().appendFileSync(a().resolve(e,"./dbErrorLogs.txt"),JSON.stringify(r,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 global.DSQL_USE_LOCAL||e?.local?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"}}):e?.ro?global.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"}})}},31542:(e,r,s)=>{s.d(r,{A:()=>t});var n=s(82535);function t(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?(0,n.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,s)=>{s.d(r,{A:()=>n});function n(e,r){try{let s=Number(e);if("number"!=typeof s||isNaN(s))return 0;if(r)return Number(s.toFixed(r));return Math.round(s)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}},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)}};