16 lines
11 KiB
JavaScript
16 lines
11 KiB
JavaScript
"use strict";exports.id=3704,exports.ids=[3704],exports.modules={83704:(e,a,t)=>{t.d(a,{A:()=>g});var s=t(29021),r=t.n(s),i=t(96052),l=t(33873),n=t.n(l),o=t(67580),d=t(30944),u=t(68829),c=t(98e3),m=t(49941);async function _({user:e,social_platform:a,invitation:t,database:s,additionalFields:r,useLocal:i}){let l=s||"datasquirel",n=`SELECT * FROM \`${l}\`.\`users\` WHERE email=? AND social_id=? AND social_platform=?`,o=[e.email,e.social_id,a],u=await (0,d.A)({database:l,queryString:n,queryValuesArray:o,useLocal:i});if(!u?.[0])return{success:!1,payload:null};let c=Math.random().toString(36).substring(2)+"-"+Math.random().toString(36).substring(2),_={id:u[0].id,first_name:u[0].first_name,last_name:u[0].last_name,username:u[0].username,user_type:u[0].user_type,email:u[0].email,social_id:u[0].social_id,image:u[0].image,image_thumbnail:u[0].image_thumbnail,verification_status:u[0].verification_status,social_login:u[0].social_login,social_platform:u[0].social_platform,csrf_k:c,logged_in_status:!0,date:Date.now()};return r?.[0]&&r.forEach(e=>{_[e]=u[0][e]}),t&&(!s||s?.match(/^datasquirel$/))&&(0,m.A)({query:t,user:_,useLocal:i}),{success:!0,payload:_,csrf:c}}async function g({database:e,social_id:a,email:t,social_platform:s,payload:l,invitation:m,supEmail:g,additionalFields:p,useLocal:E}){try{let y=[a.toString(),s],A=await (0,d.A)({database:e||"datasquirel",queryString:"SELECT * FROM datasquirel.users WHERE social_id = ? AND social_login='1' AND social_platform = ? ",queryValuesArray:y,useLocal:E});if(A&&A[0])return await _({user:A[0],social_platform:s,invitation:m,database:e,additionalFields:p,useLocal:E});let S=t||g||null;if(!S)return{success:!1,payload:null,msg:"No Email Present"};let f=`SELECT * FROM datasquirel.users WHERE email='${S}'`,b=await (0,d.A)({database:e||"datasquirel",queryString:f,useLocal:E});if(b&&b[0])return{success:!1,payload:null,msg:"This Email is already taken"};let D=[S,s,a],h=await (0,d.A)({database:e||"datasquirel",queryString:"SELECT * FROM datasquirel.users WHERE email=? AND social_login='1' AND social_platform=? AND social_id=?",queryValuesArray:D,useLocal:E});if(h&&h[0])return await _({user:l,social_platform:s,invitation:m,database:e,additionalFields:p,useLocal:E});let R=(0,u.A)({data:a.toString()}),v={social_login:"1",verification_status:g?"0":"1",password:R};Object.keys(l).forEach(e=>{v[e]=l[e]});let N=await (0,c.A)({dbContext:e?"Dsql User":void 0,paradigm:e?"Full Access":void 0,dbFullName:e||"datasquirel",tableName:"users",duplicateColumnName:"email",duplicateColumnValue:S,data:{...v,email:S},useLocal:E});if(!N?.insertId)return console.log("Social User Failed to insert in 'handleSocialDb.ts' backend function =>",N),{success:!1,payload:null,msg:"Social User Failed to insert in 'handleSocialDb.ts' backend function"};{e||await (0,o.A)({userId:N.insertId,useLocal:E});let a=`SELECT * FROM datasquirel.users WHERE id='${N.insertId}'`,t=await (0,d.A)({database:e||"datasquirel",queryString:a,useLocal:E});if(!t||!t[0])return{success:!1,payload:null,msg:"User Insertion Failed!"};if(g&&e?.match(/^datasquirel$/)){let e=(0,u.A)({data:JSON.stringify({id:N.insertId,email:g,dateCode:Date.now()})});(0,i.A)({to:g,subject:"Verify Email Address",text:"Please click the link to verify your email address",html:r().readFileSync("./email/send-email-verification-link.html","utf8").replace(/{{host}}/,process.env.DSQL_HOST||"").replace(/{{token}}/,e||"")}).then(()=>{})}let l=process.env.DSQL_STATIC_SERVER_DIR;if(!l)return console.log("Static File ENV not Found!"),{success:!1,payload:null,msg:"Static File ENV not Found!"};if(!e||e?.match(/^datasquirel$/)){let e=`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${N.insertId}`,a=n().join(l,`images/user-images/user-${N.insertId}`);r().mkdirSync(e),r().mkdirSync(a),r().writeFileSync(`${e}/main.json`,JSON.stringify([]),"utf8")}return await _({user:t[0],social_platform:s,invitation:m,database:e,additionalFields:p,useLocal:E})}}catch(e){return console.log("ERROR in 'handleSocialDb.ts' backend function =>",e.message),{success:!1,payload:null,msg:e.message}}}},49941:(e,a,t)=>{t.d(a,{A:()=>n});var s=t(67619),r=t(48786),i=t(98e3),l=t(7971);async function n({query:e,user:a,useLocal:t}){try{let s=t?l.A:r.A,{invite:n,database_access:o,priviledge:d,email:u}=e,c=[n,u],m=await s("SELECT date_created_code FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",c);if(!m||!m[0])throw Error("No Invitation Found");let _=[n],g=await s("SELECT first_name,last_name,email FROM users WHERE id=?",_);if(g?.[0]){let e=await s("SELECT email FROM user_users WHERE user_id=? AND invited_user_id=? AND user_type='admin' AND email=?",[n,a.id,u]);if(e?.[0])console.log("User already added");else{(0,i.A)({dbFullName:"datasquirel",tableName:"user_users",data:{user_id:n,invited_user_id:a.id,database_access:o,first_name:a.first_name,last_name:a.last_name,phone:a.phone,email:a.email,username:a.username,user_type:"admin",user_priviledge:d,image:a.image,image_thumbnail:a.image_thumbnail},useLocal:t});let e=await s("SELECT db_tables_data FROM invitations WHERE inviting_user_id=? AND invited_user_email=?",[n,u]);if(await s("DELETE FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=?",[n,a.id]),e&&e[0]){let s=e[0].db_tables_data.split("|");for(let e=0;e<s.length;e++){let[r,l]=s[e].split("-");await (0,i.A)({dbFullName:"datasquirel",tableName:"delegated_user_tables",data:{delegated_user_id:a.id,root_user_id:n,database:r,table:l,priviledge:d},useLocal:t})}}}await s("UPDATE invitations SET invitation_status='Accepted' WHERE inviting_user_id=? AND invited_user_email=?",[n,u])}}catch(e){(0,s.A)({component:"addAdminUserOnLogin",message:e.message,user:a})}}},67580:(e,a,t)=>{t.d(a,{A:()=>u});var s=t(47795),r=t.n(s),i=t(48786),l=t(47546),n=t(98e3),o=t(68829),d=t(7971);async function u({userId:e,useLocal:a}){try{let t=process.env.DSQL_DB_HOST||"127.0.0.1",s=`dsql_user_${e}`,u=r().generate({length:16,numbers:!0,symbols:!0,uppercase:!0,exclude:"*#.'`\""}),c=(0,o.A)({data:u}),m=`CREATE USER IF NOT EXISTS '${s}'@'127.0.0.1' IDENTIFIED BY '${u}'`;a?await (0,d.A)(m):await (0,l.A)(m);let _="UPDATE users SET mariadb_user = ?, mariadb_host = '127.0.0.1', mariadb_pass = ? WHERE id = ?",g=[s,c,e];a?await (0,d.A)(_,g):await (0,i.A)(_,g),await (0,n.A)({tableName:"mariadb_users",data:{user_id:e,username:s,host:t,password:c,primary:"1",grants:'[{"database":"*","table":"*","privileges":["ALL"]}]'},dbContext:"Master",useLocal:a}),console.log(`User ${e} SQL credentials successfully added.`)}catch(e){console.log("Error in adding SQL user in 'addMariadbUser' function =>",e.message)}}},96052:(e,a,t)=>{t.d(a,{A:()=>n});var s=t(29021),r=t.n(s),i=t(21572);let l=t.n(i)().createTransport({host:process.env.DSQL_MAIL_HOST,port:465,secure:!0,auth:{user:process.env.DSQL_MAIL_EMAIL,pass:process.env.DSQL_MAIL_PASSWORD}});async function n({to:e,subject:a,text:t,html:s,alias:i,senderName:n}){let o;if(!process.env.DSQL_MAIL_HOST||!process.env.DSQL_MAIL_EMAIL||!process.env.DSQL_MAIL_PASSWORD)return null;let d=(i?.match(/support/i),process.env.DSQL_MAIL_EMAIL);if(!r().existsSync("./email/index.html"))return;let u=r().readFileSync("./email/index.html","utf8").replace(/{{email_body}}/,s||"").replace(/{{issue_date}}/,Date().substring(0,24));try{let s={};s.from=`"${n||"Datasquirel"}" <${d}>`,s.sender=d,i&&(s.replyTo=d),s.to=e,s.subject=a,s.text=t,s.html=u,o=await l.sendMail(s)}catch(e){console.log("ERROR in handleNodemailer Function =>",e.message)}return o}},43775:(e,a,t)=>{t.d(a,{A:()=>i});var s=t(95969);let r=/^id$|^uuid$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;async function i({unparsedResults:e,tableSchema:a}){let t=[];try{for(let i=0;i<e.length;i++){let l=e[i],n=Object.keys(l);for(let e=0;e<n.length;e++){let t=n[e],i=a?.fields[e];if(t?.match(r))continue;let o=l[t];("number"==typeof o||o)&&i?.encrypted&&o?.match(/./)&&(l[t]=(0,s.A)({encryptedString:o}))}t.push(l)}return t}catch(a){return console.log("ERROR in parseDbResults Function =>",a.message),e}}},67619:(e,a,t)=>{t.d(a,{A:()=>i});var s=t(29021),r=t.n(s);async function i({user:e,message:a,component:t,noMail:s,req:i}){let l=new Date,n=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],a=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],r=t||s||a||i.socket.remoteAddress;if(!r)return null;return String(r)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${a}
|
|
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}`),i?.url&&(s+=`
|
|
URL: ${i.url}`),i?.body&&(s+=`
|
|
Request Body: ${JSON.stringify(i.body,null,4)}`),n&&(s+=`
|
|
IP: ${n}`),s+=`
|
|
Date: ${l.toDateString()}
|
|
========================================`,r().existsSync("./.tmp/error.log")||r().writeFileSync("./.tmp/error.log","","utf-8");let o=r().readFileSync("./.tmp/error.log","utf-8");r().writeFileSync("./.tmp/error.log",s),r().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},30944:(e,a,t)=>{t.d(a,{A:()=>o});var s=t(43775),r=t(67619),i=t(48786),l=t(37275),n=t(7971);async function o({queryString:e,queryValuesArray:a,database:t,tableSchema:o,useLocal:d}){let u;let c=!!d||!!t?.match(/^datasquirel$/),m=d?n.A:c?i.A:l.A;try{u=e&&a&&Array.isArray(a)&&a[0]?c?await m(e,a):await m({paradigm:"Full Access",queryString:e,queryValues:a}):c?await m(e):await m({paradigm:"Full Access",queryString:e})}catch(e){console.log(`varDatabaseDbHandler Error: ${e.message}`),(0,r.A)({component:"varDatabaseDbHandler/lines-29-32",message:e.message})}if(u&&o)try{let e=u;return await (0,s.A)({unparsedResults:e,tableSchema:o})}catch(e){return console.log("\x1b[31mvarDatabaseDbHandler ERROR\x1b[0m =>",t,e),(0,r.A)({component:"varDatabaseDbHandler/lines-52-53",message:e.message}),null}else if(u)return u;else return null}},95969:(e,a,t)=>{t.d(a,{A:()=>i});var s=t(55511),r=t(79428);function i({encryptedString:e,encryptionKey:a,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=a||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,n=process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24;if(!i?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=(0,s.scryptSync)(i,l,n),d=r.Buffer.alloc(16,0),u=(0,s.createDecipheriv)("aes-192-cbc",o,d);try{let a=u.update(e,"hex","utf8");return a+=u.final("utf8")}catch(a){return console.log("Error in decrypting =>",a.message),e}}},47546:(e,a,t)=>{t.d(a,{A:()=>s});function s(...e){let a=global.DSQL_DB_CONN;try{return new Promise((t,s)=>{a.query(...e).then(e=>{a.end(),t(JSON.parse(JSON.stringify(e)))}).catch(e=>{a.end(),t({error:e.message,sql:e.sql})})})}catch(e){return{success:!1,error:e.message}}}}}; |