"use strict";exports.id=5264,exports.ids=[5264],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}}})},6420:(e,r,s)=>{s(81630);lett=s(51348),n=s(72835),a=s(29021),o=s(31341);asyncfunctioni(e,r,s,i){let{keyCookieName:l,csrfCookieName:c}=o();if(!e.cookies?.[l]?.match(/./))returnnull;letu=n({encryptedString:e.cookies[l]});if(!u)returnnull;let_=JSON.parse(u);if(!_.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))returnnull;letE=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!E)returnconsole.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!a.existsSync(`${E}/${_.csrf_k}`))returnnull;if(0==_.verification_status&&!s){lete=awaitt(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return_?.date&&Date.now()-_.date>6048e5?null:_}e.exports=i},31341:e=>{e.exports=function(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}}},48225:(e,r,s)=>{lett=s(29021),{IncomingMessage:n}=s(81630);e.exports=asyncfunction({user:e,message:r,component:s,noMail:n,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{letn=`🚀 SERVER ERROR ===========================
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,s)=>{let{scryptSync:t,createDecipheriv:n}=s(55511),{Buffer:a}=s(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:s})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=s||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=n("aes-192-cbc",t(o,i,l),a.alloc(16,0));try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},20503:(e,r,s)=>{let{scryptSync:t,createCipheriv:n}=s(55511),{Buffer:a}=s(79428);e.exports=({data:e,encryptionKey:r,encryptionSalt:s})=>{if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=s||process.env.DSQL_ENCRYPTION_SALT,l=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!o?.match(/.{8,}/))return console.log("Encryption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let c=n("aes-192-cbc",t(o,i,l),a.alloc(16,0));try{let r=c.update(e,"utf8","hex");return r+=c.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},31819:(e,r,s)=>{let t=s(3444);async function n({username:e,host:r,grants:s,userId:n}){let a=!1;if(console.log("Handling Grants for User =>",e,r),!e)return console.log("No username provided."),a;if(!r)return console.log(`NoHostprovided.\x1b[35m\`--host\`\x1b[0m flag is required`),a;if(!s)returnconsole.log("No grants Array provided."),a;try{leto=awaitt(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(o?.[0]?.User){leta=awaitt(`SHOW GRANTS FOR '${e}'@'${r}'`);for(lete=0;e<a.length;e++){letr=a[e],s=r?.[Object.keys(r)[0]];if(s?.match(/GRANT .* PRIVILEGES ON .* TO/)){lete=s.replace(/GRANT/,"REVOKE").replace(/ TO /," FROM ");awaitt(e)}}for(leta=0;a<s.length;a++){let{database:o,table:i,privileges:l}=s[a],c="*"==i?"*":`\`${i}\``,u="*"==o?`\`${process.env.DSQL_USER_DB_PREFIX}${n}_%\``:`\`${o}\``,_=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),E=`GRANT ${_} ON ${u}.${c} TO '${e}'@'${r}'`;awaitt(E)}}a=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}returna}e.exports=n},46889:(e,r,s)=>{lett=s(33873);s(60818).config({path:t.resolve(__dirname,"../../../.env")});letn=s(47795),a=s(3444),o=s(16926),i=s(31819),l=s(20503),c=s(72835),u=process.env.DSQL_DB_HOST||"127.0.0.1";asyncfunction_({userId:e,mariadbUserHost:r,mariadbUser:s,sqlUserID:t}){let_=awaito({query:"SELECT * FROM users"});_?.[0]||process.exit();for(letE=0;E<_.length;E++){letS=_[E];if(S&&(!e||S.id==e))try{let{mariadb_user:_,mariadb_host:E,mariadb_pass:d,id:p}=S,f=awaita(`SELECT * FROM mysql.user WHERE User = '${_}' AND Host = '${E}'`),y=e&&t?awaito({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[t,e]}):null,g=Array.isArray(y)?y?.[0]:void0,D=!!g&&!!String(g.primary)?.match(/1/),R=!!f?.[0]?.User,N=`dsql_user_${p}`,m=g?.password?g.password:R?d:n.generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),O=g?.password?g.password:R?d:l({data:m,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(!R&&!t&&!D&&!r&&!s){lete=awaita(`CREATE USER IF NOT EXISTS '${N}'@'${u}' IDENTIFIED BY '${m}'`);console.log("createNewUser",e),console.log(`User ${S.id}: ${S.first_name}${S.last_name} SQL credentials successfully updated.`),awaito({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,u,O,S.id]})}if(D){lete=r||E;awaito({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,e,O,S.id]})}letL=awaito({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` = 1",values:[p