16 lines
9.6 KiB
JavaScript
16 lines
9.6 KiB
JavaScript
"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),o=t.n(a),i=t(89159);async function l(e,r,t){try{let{keyCookieName:a,csrfCookieName:l}=(0,i.A)();if(!e.cookies?.[a]?.match(/./))throw Error("Request Cookies not Found!");let c=(0,n.A)({encryptedString:e.cookies[a]});if(!c)throw Error("Couldn't decrypt auth cookie!");let u=JSON.parse(c);if(!u.csrf_k)throw Error("No `csrf_k` present in user Object!");if(t&&!Object.keys(e.headers).find(e=>e.includes(u.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let E=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!E)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(t&&!o().existsSync(`${E}/${u.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==u.verification_status&&!t){let e=await (0,s.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)throw Error("Key expired!");return u}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.message}`),null}}},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+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),a&&(o+=`${a}_`),o+=t;let i=r;e?.userId&&(i+=`user_${e.userId}_`),a&&(i+=`${a}_`),i+=s;let l=r;return e?.userId&&(l+=`user_${e.userId}_`),a&&(l+=`${a}_`),{keyCookieName:o,csrfCookieName:i,oneTimeCodeName:l+=n}}},67619:(e,r,t)=>{t.d(r,{A:()=>a});var s=t(29021),n=t.n(s);async function a({user:e,message:r,component:t,noMail:s,req:a}){let o=new Date,i=(()=>{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)}`),i&&(s+=`
|
|
IP: ${i}`),s+=`
|
|
Date: ${o.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,o=t||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,s.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,s.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,t)=>{t.d(r,{A:()=>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,o=t||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,s.scryptSync)(a,o,i),c=n.Buffer.alloc(16,0),u=(0,s.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,t)=>{t.d(r,{A:()=>_});var s=t(33873),n=t.n(s),a=t(47795),o=t.n(a),i=t(66866),l=t(41864);async function c({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,i.A)(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(a?.[0]?.User){let n=await (0,i.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,i.A)(e)}}for(let n=0;n<t.length;n++){let{database:a,table:o,privileges:l}=t[n],c="*"==o?"*":`\`${o}\``,u="*"==a?`\`${process.env.DSQL_USER_DB_PREFIX}${s}_%\``:`\`${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)}return n}var u=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,i.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:o().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),D=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||s||N||r||t)!m&&r&&await (0,i.A)(`CREATE USER IF NOT EXISTS '${R}'@'${r}' IDENTIFIED BY '${O}'`);else{let e=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 = ?",values:[R,d,D,S.id]})}if(N){let e=r||_;await (0,l.A)({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[R,e,D,S.id]})}let h=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` = 1",values:[p]}),v=!!(Array.isArray(h)&&h?.[0]?.user_id),T=[{database:"*",table:"*",privileges:["ALL"]}];v||await (0,l.A)({query:"INSERT INTO mariadb_users (user_id, username, password, `primary`, grants) VALUES (?, ?, ?, ?, ?)",values:[p,R,D,"1",JSON.stringify(T)]});let I=await (0,l.A)({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` != '1'",values:[p]});if(Array.isArray(I))for(let s=0;s<I.length;s++){let n=I[s];if(n&&n.username!=t||r&&n.host!=r)continue;let a=(0,E.A)({encryptedString:n.password||"",encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT}),o=await (0,i.A)(`SELECT * FROM mysql.user WHERE User='${n.username}' AND Host='${n.host}'`);o?.[0]?.User||await (0,i.A)(`CREATE USER IF NOT EXISTS '${n.username}'@'${n.host}' IDENTIFIED BY '${a}'`),await c({username:n.username,host:n.host,grants:n.grants&&"string"==typeof n.grants?JSON.parse(n.grants):[],userId:String(e)})||console.log(`Error in handling grants for user ${n.username}@${n.host}`)}}catch(e){console.log("Error in adding SQL user =>",e.message)}}}},41864:(e,r,t)=>{t.d(r,{A:()=>i});var s=t(29021),n=t.n(s),a=t(33873),o=t.n(a);async function i({query:e,values:r}){let t,s=global.DSQL_DB_CONN;try{t=e&&r?await s.query(e,r):await s.query(e)}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(s.config()),n().appendFileSync(o().resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),t=null}finally{await s?.end()}return t?JSON.parse(JSON.stringify(t)):null}},66866:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(41864);async function n(e){let r;try{r=await (0,s.A)({query:e})}catch(e){console.log("ERROR in noDatabaseDbHandler =>",e.message)}return r||null}},48786:(e,r,t)=>{t.d(r,{A:()=>s});async function s(...e){let r=global.DSQL_DB_CONN;try{if(!r)throw Error("No Connection provided to DB_HANDLER function!");let t=await r.query(...e);return JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}finally{await r?.end()}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}});var t=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,t)=>{e.exports=t(75600)}}; |