"use strict";exports.id=3496,exports.ids=[3496],exports.modules={96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){returnfunctione(r,s){returnsinr?r[s]:"then"inr&&"function"==typeofr.then?r.then(r=>e(r,s)):"function"==typeofr&&"default"===s?r:void0}}})},69842:(e,r,s)=>{s.d(r,{A:()=>l});vart=s(48786),n=s(95969),a=s(29021),o=s.n(a),i=s(89159);asyncfunctionl(e,r,s){try{let{keyCookieName:a,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))throwError("Request Cookies not Found!");letc=(0,n.A)({encryptedString:e.cookies[a]});if(!c)throwError("Couldn't decrypt auth cookie!");letu=JSON.parse(c);if(!u.csrf_k)throwError("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throwconsole.log("req.headers",e.headers),console.log("userObject",u),Error("Deep Auth Failed. `csrf` key not found in request headers!");letE=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!E)throwError("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(s&&!o().existsSync(`${E}/${u.csrf_k}`))throwError("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!s){lete=await(0,t.A)(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(u?.date&&Date.now()-u.date>6048e5)throwError("Key expired!");returnu}catch(e){returnconsole.log(`userAuth Error: ${e.message}`),null}}},89159:(e,r,s)=>{s.d(r,{A:()=>t});functiont(e){letr=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",a=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=s;leti=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=t;letl=r;returne?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:l+=n}}},67619:(e,r,s)=>{s.d(r,{A:()=>a});vart=s(29021),n=s.n(t);asyncfunctiona({user:e,message:r,component:s,noMail:t,req:a}){leto=newDate,i=(()=>{if(!a)returnnull;try{lete=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],s=a.headers["cf-connecting-ip"],t=Array.isArray(e)?e[0]:e?.split(",")[0],n=s||t||r||a.socket.remoteAddress;if(!n)returnnull;returnString(n)}catch(e){returnnull}})();try{lett=`🚀 SERVER ERROR ===========================
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511),n=s(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,i=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let l=(0,t.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,t.createDecipheriv)("aes-192-cbc",l,c);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511),n=s(79428);function a({data:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,o=s||process.env.DSQL_ENCRYPTION_SALT,i=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!a?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!o?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let l=(0,t.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,t.createCipheriv)("aes-192-cbc",l,c);try{let r=u.update(e,"utf8","hex");return r+=u.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},5437:(e,r,s)=>{s.d(r,{A:()=>_});var t=s(33873),n=s.n(t),a=s(47795),o=s.n(a),i=s(66866),l=s(41864);async function c({username:e,host:r,grants:s,userId:t}){let n=!1;if(console.log("Handling Grants for User =>",e,r),!e)return console.log("No username provided."),n;if(!r)return console.log(`NoHostprovided.\x1b[35m\`--host\`\x1b[0m flag is required`),n;if(!s)returnconsole.log("No grants Array provided."),n;try{leta=await(0,i.A)(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(a?.[0]?.User){letn=await(0,i.A)(`SHOW GRANTS FOR '${e}'@'${r}'`);for(lete=0;e<n.length;e++){letr=n[e],s=r?.[Object.keys(r)[0]];if(s?.match(/GRANT .* PRIVILEGES ON .* TO/)){lete=s.replace(/GRANT/,"REVOKE").replace(/ TO /," FROM ");await(0,i.A)(e)}}for(letn=0;n<s.length;n++){let{database:a,table:o,privileges:l}=s[n],c="*"==o?"*":`\`${o}\``,u="*"==a?`\`${process.env.DSQL_USER_DB_PREFIX}${t}_%\``:`\`${a}\``,E=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),d=`GRANT ${E} ON ${u}.${c} TO '${e}'@'${r}'`;await(0,i.A)(d)}}n=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}returnn}varu=s(68829),E=s(95969);s(60818).config({path:n().resolve(__dirname,"../../../.env")});letd=process.env.DSQL_DB_HOST||"127.0.0.1";asyncfunction_({userId:e,mariadbUserHost:r,mariadbUsername:s,sqlUserID:t}){letn=await(0,l.A)({query:"SELECT * FROM mariadb_users"});if(!n?.[0])return;leta=!!e&&e==Number(process.env.DSQL_SU_USER_ID);for(let_=0;_<n.length;_++){letS=n[_];if(S&&(!e||S.user_id==e))try{let{mariadb_user:n,mariadb_host:_,mariadb_pass:f,user_id:p}=S,y=await(0,i.A)(`SELECT * FROM mysql.user WHERE User = '${n}' AND Host = '${_}'`),A=e&&t?await(0,l.A)({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[t,e]}):null,g=Array.isArray(A)?A?.[0]:void0,N=!!g&&!!String(g.primary)?.match(/1/),m=!!y?.[0]?.User,R=a?s:`dsql_user_${p}`,O=g?.password?g.password:m?f:o().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),h=g?.password?g.password:m?f:(0,u.A)({data:O,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(m||t||N||r||s)!m&&r&&await(0,i.A)(`CREATE USER IF NOT EXISTS '${R}'@'${r}' IDENTIFIED BY '${O}'`);else{lete=await(0,i.A)(`CREATE USER IF NOT EXISTS '${R}'@'${d}' IDENTIFIED BY '${O}'`);console.log("createNewUser",e),console.log(`User ${S.id}: ${S.first_name}${S.last_name} SQL credentials successfully updated.`),await(0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",v