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

16 lines
9.3 KiB
JavaScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
"use strict";exports.id=3496,exports.ids=[3496],exports.modules={96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,t){return t in r?r[t]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,t)):"function"==typeof r&&"default"===t?r:void 0}}})},69842:(e,r,t)=>{t.d(r,{A:()=>l});var s=t(48786),n=t(95969),a=t(29021),i=t.n(a),o=t(89159);async function l(e,r,t){let{keyCookieName:a,csrfCookieName:l}=(0,o.A)();if(!e.cookies?.[a]?.match(/./))return null;let u=(0,n.A)({encryptedString:e.cookies[a]});if(!u)return null;let c=JSON.parse(u);if(!c.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))return null;let E=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!E)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!i().existsSync(`${E}/${c.csrf_k}`))return null;if(0==c.verification_status&&!t){let e=await (0,s.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}},89159:(e,r,t)=>{t.d(r,{A:()=>s});function s(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",s=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+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=t;let o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=s;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:i,csrfCookieName:o,oneTimeCodeName:l+=n}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var s=t(29021),n=t.n(s);async function a({user:e,message:r,component:t,noMail:s,req:a}){let i=new Date,o=(()=>{if(!a)return null;try{let e=a.headers["x-forwarded-for"],r=a.headers["x-real-ip"],t=a.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||s||r||a.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),a?.url&&(s+=`
URL: ${a.url}`),a?.body&&(s+=`
Request Body: ${JSON.stringify(a.body,null,4)}`),o&&(s+=`
IP: ${o}`),s+=`
Date: ${i.toDateString()}
========================================`,n().existsSync("./.tmp/error.log")||n().writeFileSync("./.tmp/error.log","","utf-8");let l=n().readFileSync("./.tmp/error.log","utf-8");n().writeFileSync("./.tmp/error.log",s),n().appendFileSync("./.tmp/error.log",`
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(55511),n=t(79428);function a({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=t||process.env.DSQL_ENCRYPTION_SALT,o=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 l=(0,s.scryptSync)(a,i,o),u=n.Buffer.alloc(16,0),c=(0,s.createDecipheriv)("aes-192-cbc",l,u);try{let r=c.update(e,"hex","utf8");return r+=c.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},68829:(e,r,t)=>{t.r(r),t.d(r,{default:()=>a});var s=t(55511),n=t(79428);function a({data:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let a=r||process.env.DSQL_ENCRYPTION_PASSWORD,i=t||process.env.DSQL_ENCRYPTION_SALT,o=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 l=(0,s.scryptSync)(a,i,o),u=n.Buffer.alloc(16,0),c=(0,s.createCipheriv)("aes-192-cbc",l,u);try{let r=c.update(e,"utf8","hex");return r+=c.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},5437:(e,r,t)=>{t.d(r,{A:()=>_});var s=t(33873),n=t.n(s),a=t(47795),i=t.n(a),o=t(66866),l=t(41864);async function u({username:e,host:r,grants:t,userId:s}){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(`No Host provided. \x1b[35m\`--host\`\x1b[0m flag is required`),n;if(!t)return console.log("No grants Array provided."),n;try{let a=await (0,o.A)(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(a?.[0]?.User){let n=await (0,o.A)(`SHOW GRANTS FOR '${e}'@'${r}'`);for(let e=0;e<n.length;e++){let r=n[e],t=r?.[Object.keys(r)[0]];if(t?.match(/GRANT .* PRIVILEGES ON .* TO/)){let e=t.replace(/GRANT/,"REVOKE").replace(/ TO /," FROM ");await (0,o.A)(e)}}for(let n=0;n<t.length;n++){let{database:a,table:i,privileges:l}=t[n],u="*"==i?"*":`\`${i}\``,c="*"==a?`\`${process.env.DSQL_USER_DB_PREFIX}${s}_%\``:`\`${a}\``,E=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),d=`GRANT ${E} ON ${c}.${u} TO '${e}'@'${r}'`;await (0,o.A)(d)}}n=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}return n}var c=t(68829),E=t(95969);t(60818).config({path:n().resolve(__dirname,"../../../.env")});let d=process.env.DSQL_DB_HOST||"127.0.0.1";async function _({userId:e,mariadbUserHost:r,mariadbUsername:t,sqlUserID:s}){let n=await (0,l.A)({query:"SELECT * FROM mariadb_users"});if(!n?.[0])return;let a=!!e&&e==Number(process.env.DSQL_SU_USER_ID);for(let _=0;_<n.length;_++){let S=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,o.A)(`SELECT * FROM mysql.user WHERE User = '${n}' AND Host = '${_}'`),A=e&&s?await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[s,e]}):null,g=Array.isArray(A)?A?.[0]:void 0,N=!!g&&!!String(g.primary)?.match(/1/),m=!!y?.[0]?.User,R=a?t:`dsql_user_${p}`,O=g?.password?g.password:m?f:i().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),v=g?.password?g.password:m?f:(0,c.default)({data:O,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(m||s||N||r||t)!m&&r&&await (0,o.A)(`CREATE USER IF NOT EXISTS '${R}'@'${r}' IDENTIFIED BY '${O}'`);else{let e=await (0,o.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