dsql-admin/dsql-app/.local_dist/server/chunks/5264.js

16 lines
9.2 KiB
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
"use strict";exports.id=5264,exports.ids=[5264],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}}})},6420:(e,r,s)=>{s(81630);let t=s(51348),n=s(72835),o=s(29021),a=s(31341);async function i(e,r,s,i){let{keyCookieName:l,csrfCookieName:c}=a();if(!e.cookies?.[l]?.match(/./))return null;let u=n({encryptedString:e.cookies[l]});if(!u)return null;let E=JSON.parse(u);if(!E.csrf_k||s&&!e.headers["x-csrf-auth"]?.match(RegExp(`${E.csrf_k}`)))return null;let S=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!S)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!o.existsSync(`${S}/${E.csrf_k}`))return null;if(0==E.verification_status&&!s){let e=await t(`SELECT verification_status FROM users WHERE id='${E.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return E?.date&&Date.now()-E.date>6048e5?null:E}e.exports=i},31341:e=>{e.exports=function(){let e=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},48225:(e,r,s)=>{let t=s(29021),{IncomingMessage:n}=s(81630);e.exports=async function({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"],t=Array.isArray(e)?e[0]:e?.split(",")[0],n=s||t||r||o.socket.remoteAddress;if(!n)return null;return String(n)}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)}}},72835:(e,r,s)=>{let{scryptSync:t,createDecipheriv:n}=s(55511),{Buffer:o}=s(79428);e.exports=({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,i=s||process.env.DSQL_ENCRYPTION_SALT,l=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(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=n("aes-192-cbc",t(a,i,l),o.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:o}=s(79428);e.exports=({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,i=s||process.env.DSQL_ENCRYPTION_SALT,l=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(!i?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let c=n("aes-192-cbc",t(a,i,l),o.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 o=!1;if(console.log("Handling Grants for User =>",e,r),!e)return console.log("No username provided."),o;if(!r)return console.log(`No Host provided. \x1b[35m\`--host\`\x1b[0m flag is required`),o;if(!s)return console.log("No grants Array provided."),o;try{let a=await t(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(a?.[0]?.User){let o=await t(`SHOW GRANTS FOR '${e}'@'${r}'`);for(let e=0;e<o.length;e++){let r=o[e],s=r?.[Object.keys(r)[0]];if(s?.match(/GRANT .* PRIVILEGES ON .* TO/)){let e=s.replace(/GRANT/,"REVOKE").replace(/ TO /," FROM ");await t(e)}}for(let o=0;o<s.length;o++){let{database:a,table:i,privileges:l}=s[o],c="*"==i?"*":`\`${i}\``,u="*"==a?`\`${process.env.DSQL_USER_DB_PREFIX}${n}_%\``:`\`${a}\``,E=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),S=`GRANT ${E} ON ${u}.${c} TO '${e}'@'${r}'`;await t(S)}}o=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}return o}e.exports=n},46889:(e,r,s)=>{let t=s(33873);s(60818).config({path:t.resolve(__dirname,"../../../.env")});let n=s(47795),o=s(3444),a=s(16926),i=s(31819),l=s(20503),c=s(72835),u=process.env.DSQL_DB_HOST||"127.0.0.1";async function E({userId:e,mariadbUserHost:r,mariadbUser:s,sqlUserID:t}){let E=await a({query:"SELECT * FROM users"});E?.[0]||process.exit();for(let S=0;S<E.length;S++){let _=E[S];if(_&&(!e||_.id==e))try{let{mariadb_user:E,mariadb_host:S,mariadb_pass:p,id:d}=_,f=await o(`SELECT * FROM mysql.user WHERE User = '${E}' AND Host = '${S}'`),y=e&&t?await a({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[t,e]}):null,R=Array.isArray(y)?y?.[0]:void 0,g=!!R&&!!String(R.primary)?.match(/1/),D=!!f?.[0]?.User,m=`dsql_user_${d}`,N=R?.password?R.password:D?p:n.generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),O=R?.password?R.password:D?p:l({data:N,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(!D&&!t&&!g&&!r&&!s){let e=await o(`CREATE USER IF NOT EXISTS '${m}'@'${u}' IDENTIFIED BY '${N}' REQUIRE SSL`);console.log("createNewUser",e),console.log(`User ${_.id}: ${_.first_name} ${_.last_name} SQL credentials successfully updated.`),await a({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[m,u,O,_.id]})}if(g){let e=r||S;await a({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[m,e,O,_.id]})}let L=await a({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` =