16 lines
9.4 KiB
JavaScript
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)(
|