16 lines
9.4 KiB
JavaScript
16 lines
9.4 KiB
JavaScript
"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),a=s(29021),o=s(31341);async function i(e,r,s,i){let{keyCookieName:l,csrfCookieName:c}=o();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 _=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!_)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(s&&!a.existsSync(`${_}/${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(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",n=e?.database||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),n&&(a+=`${n}_`),a+=s;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),n&&(o+=`${n}_`),{keyCookieName:a,csrfCookieName:o+=t}}},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:a}){let o=new Date,i=(()=>{if(!a)return null;try{let e=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)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}`),a?.url&&(n+=`
|
|
URL: ${a.url}`),a?.body&&(n+=`
|
|
Request Body: ${JSON.stringify(a.body,null,4)}`),i&&(n+=`
|
|
IP: ${i}`),n+=`
|
|
Date: ${o.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: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(`No Host provided. \x1b[35m\`--host\`\x1b[0m flag is required`),a;if(!s)return console.log("No grants Array provided."),a;try{let o=await t(`SELECT * FROM mysql.user WHERE User = '${e}' AND Host = '${r}'`);if(o?.[0]?.User){let a=await t(`SHOW GRANTS FOR '${e}'@'${r}'`);for(let e=0;e<a.length;e++){let r=a[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 a=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}\``,E=l.includes("ALL")?"ALL PRIVILEGES":l.join(", "),_=`GRANT ${E} ON ${u}.${c} TO '${e}'@'${r}'`;await t(_)}}a=!0}catch(e){console.log("Error in adding SQL user =>",e.message)}return a}e.exports=n},46889:(e,r,s)=>{let t=s(33873);s(60818).config({path:t.resolve(__dirname,"../../../.env")});let n=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";async function E({userId:e,mariadbUserHost:r,mariadbUser:s,sqlUserID:t}){let E=await o({query:"SELECT * FROM users"});E?.[0]||process.exit();for(let _=0;_<E.length;_++){let S=E[_];if(S&&(!e||S.id==e))try{let{mariadb_user:E,mariadb_host:_,mariadb_pass:p,id:d}=S,f=await a(`SELECT * FROM mysql.user WHERE User = '${E}' AND Host = '${_}'`),y=e&&t?await o({query:"SELECT * FROM mariadb_users WHERE id = ? AND user_id = ?",values:[t,e]}):null,g=Array.isArray(y)?y?.[0]:void 0,R=!!g&&!!String(g.primary)?.match(/1/),D=!!f?.[0]?.User,N=`dsql_user_${d}`,m=g?.password?g.password:D?p:n.generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),O=g?.password?g.password:D?p:l({data:m,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT});if(!D&&!t&&!R&&!r&&!s){let e=await a(`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.`),await o({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,u,O,S.id]})}if(R){let e=r||_;await o({query:"UPDATE users SET mariadb_user = ?, mariadb_host = ?, mariadb_pass = ? WHERE id = ?",values:[N,e,O,S.id]})}let L=await o({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` = 1",values:[d]}),v=!!(Array.isArray(L)&&L?.[0]?.user_id),A=[{database:"*",table:"*",privileges:["ALL"]}];v||await o({query:"INSERT INTO mariadb_users (user_id, username, password, `primary`, grants) VALUES (?, ?, ?, ?, ?)",values:[d,N,O,"1",JSON.stringify(A)]});let T=await o({query:"SELECT * FROM mariadb_users WHERE user_id = ? AND `primary` != '1'",values:[d]});if(Array.isArray(T))for(let s=0;s<T.length;s++){let t=T[s],{user_id:n,username:o,host:l,password:u,primary:E,grants:_}=t;if(t&&o!=t||r&&l!=r)continue;let S=c({encryptedString:u,encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD,encryptionSalt:process.env.DSQL_ENCRYPTION_SALT}),p=await a(`SELECT * FROM mysql.user WHERE User = '${o}' AND Host = '${l}'`);p?.[0]?.User||await a(`CREATE USER IF NOT EXISTS '${o}'@'${l}' IDENTIFIED BY '${S}'`),await i({username:o,host:l,grants:_&&"string"==typeof _?JSON.parse(_):[],userId:String(e)})||console.log(`Error in handling grants for user ${o}@${l}`)}}catch(e){console.log("Error in adding SQL user =>",e.message)}}process.exit()}e.exports=E},16926:(e,r,s)=>{let t=s(29021),n=s(33873),a=s(9973),o=s(21580),i=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,charset:"utf8mb4",ssl:o()}});e.exports=async function({query:e,values:r,database:s}){let l;s&&(i=a({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:s,charset:"utf8mb4",ssl:o()}}));try{l=e&&r?await i.query(e,r):await i.query(e),await i.end()}catch(e){if(process.env.FIRST_RUN)return null;console.log("ERROR in dbHandler =>",e.message),console.log(e),console.log(i.config()),t.appendFileSync(n.resolve(__dirname,"../.tmp/dbErrorLogs.txt"),JSON.stringify(e,null,4)+"\n"+Date()+"\n\n\n","utf8"),l=null}return l?JSON.parse(JSON.stringify(l)):null}},3444:(e,r,s)=>{let t=s(16926);e.exports=async function(e){let r;try{r=await t({query:e})}catch(e){console.log("ERROR in noDatabaseDbHandler =>",e.message)}return r||null}},51348:(e,r,s)=>{let t=s(9973),n=s(21580),a=t({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:n()}});async function o(...e){try{let r=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21580:(e,r,s)=>{let t=s(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!t.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:t.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var s;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return s}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(s||(s={}))},89947:(e,r,s)=>{e.exports=s(75600)}}; |