1 line
8.9 KiB
JavaScript
1 line
8.9 KiB
JavaScript
"use strict";(()=>{var e={};e.id=4065,e.ids=[4065],e.modules={60818:e=>{e.exports=require("dotenv")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},79646:e=>{e.exports=require("child_process")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},79551:e=>{e.exports=require("url")},28354:e=>{e.exports=require("util")},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}}})},83919:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>m,routeModule:()=>h});var s={};t.r(s),t.d(s,{default:()=>f});var n=t(89947),a=t(2706),o=t(96762),c=t(7753),i=t(48225),l=t.n(i),u=t(6420),_=t.n(u),d=t(33364),p=t.n(d);t(29021),t(28354);let{URL:S}=t(79551);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await _()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{url:s,key:n,database:a,dbSchema:o,type:i,remoteDbs:u,targetDb:d}=e.body;try{if(!d?.tables)throw Error("No Target Database");await p()({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:s,remote_connection_key:n,remote_connection_type:i,remote_db_full_name:d.dbFullName},identifierColumnName:"db_full_name",identifierValue:a.db_full_name}),await (0,c.e)({dbSchema:d,database:a,userId:t.id}),r.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),l()({component:"/api/connect/verify/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Operation Failed!"})}}let m=(0,o.M)(s,"default"),g=(0,o.M)(s,"config"),h=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/connect/handshake",pathname:"/api/connect/handshake",bundlePath:"",filename:""},userland:s})},7753:(e,r,t)=>{let s=t(19261),{execSync:n}=t(79646),a=t(29021),o=t(33873),c=async({userId:e,dbSchema:r,targetDb:t})=>(await s({userId:e,targetDatabase:t}),`User ${e} Db Schema Updated`),i=async({userId:e,dbSchema:r,database:t})=>{let s=o.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),n=JSON.parse(a.readFileSync(s,"utf-8")),i=n.findIndex(e=>e.dbFullName==t.db_full_name);if(i<0)throw Error("Target Database not found in user schema data");let l={...n[i]};return n[i]=r,n[i].dbName=l.dbName,n[i].dbFullName=l.dbFullName,n[i].dbSlug=l.dbSlug,n[i].dbImage=l.dbImage,await c({dbSchema:n,userId:e,targetDb:t.db_full_name})};r.e=i},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72835),a=t(29021),o=t(31341);async function c(e,r,t,c){let{keyCookieName:i,csrfCookieName:l}=o();if(!e.cookies?.[i]?.match(/./))return null;let u=n({encryptedString:e.cookies[i]});if(!u)return null;let _=JSON.parse(u);if(!_.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${_.csrf_k}`)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${d}/${_.csrf_k}`))return null;if(0==_.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${_.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return _?.date&&Date.now()-_.date>6048e5?null:_}e.exports=c},31341:e=>{e.exports=function(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=r;e?.userId&&(n+=`user_${e.userId}_`),e?.database&&(n+=`${e.database}_`),n+=t;let a=r;return e?.userId&&(a+=`user_${e.userId}_`),e?.database&&(a+=`${e.database}_`),{keyCookieName:n,csrfCookieName:a+=s}}},33364:(e,r,t)=>{let s=t(72583),n=t(16570),a=t(51348),o=t(21339),c=t(20503),i=t(44900);async function l({dbContext:e,paradigm:r,dbFullName:t,tableName:l,data:u,tableSchema:_,identifierColumnName:d,identifierValue:p,encryptionKey:S,encryptionSalt:f,useLocal:m}){if(!u||!Object.keys(u).length)return null;let g=!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),h=m?i:g?a:o,D=Object.keys(u),E=[],b=[];for(let e=0;e<D.length;e++)try{let r=D[e],t=u[r],a=_?_?.fields?.filter(e=>e.fieldName===r):null,o=a&&a[0]?a[0]:null;if(null==t||void 0==t)continue;o?.richText&&(t=s(t,n)),o?.encrypted&&(t=c({data:t,encryptionKey:S,encryptionSalt:f})),"object"==typeof t&&(t=JSON.stringify(t)),o?.pattern&&!new RegExp(o.pattern,o.patternFlags||"").test(t)&&(console.log("DSQL: Pattern not matched =>",t),t=""),"string"==typeof t&&t.match(/^null$/i)&&(t={toSqlString:function(){return"NULL"}}),"string"!=typeof t||t.match(/./i)||(t={toSqlString:function(){return"NULL"}}),E.push(`\`${r}\`=?`),"number"==typeof t?b.push(String(t)):b.push(t)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}E.push(`date_updated='${Date()}'`),E.push(`date_updated_code='${Date.now()}'`);let y=`UPDATE ${l} SET ${E.join(",")} WHERE \`${d}\`=?`;return b.push(p),g?await h(y,b):await h({paradigm:r,database:t,queryString:y,queryValues:b})}e.exports=l},16570:e=>{e.exports={allowedTags:["b","i","em","strong","a","p","span","ul","ol","li","h1","h2","h3","h4","h5","h6","img","div","button","pre","code","br"],allowedAttributes:{a:["href"],img:["src","alt","width","height","class","style"],"*":["style","class"]}}},20503:(e,r,t)=>{let{scryptSync:s,createCipheriv:n}=t(55511),{Buffer:a}=t(79428);e.exports=({data:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encryption string is invalid"),e;let o=r||process.env.DSQL_ENCRYPTION_PASSWORD,c=t||process.env.DSQL_ENCRYPTION_SALT,i=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(!c?.match(/.{8,}/))return console.log("Encryption salt is invalid"),e;let l=n("aes-192-cbc",s(o,c,i),a.alloc(16,0));try{let r=l.update(e,"utf8","hex");return r+=l.final("hex")}catch(r){return console.log("Error in encrypting =>",r.message),e}}},51348:(e,r,t)=>{let s=t(9973),n=t(21580),a=s({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},21339:(e,r,t)=>{let s=t(29021);t(33873);let n=t(9973),a=t(21580),o=n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,charset:"utf8mb4",ssl:a()}});e.exports=function({paradigm:e,database:r,queryString:t,queryValues:c}){try{return new Promise((i,l)=>{let u=!!e?.match(/full.access|^fa$/i);try{function _(e){o.end(),i(JSON.parse(JSON.stringify(e)))}function d(e){o.end(),i({error:e.message,queryStringGenerated:t,queryValuesGenerated:c,sql:e.sql})}o=u?n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_FULL_ACCESS_USERNAME,password:process.env.DSQL_DB_FULL_ACCESS_PASSWORD,database:r,ssl:a()}}):n({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_READ_ONLY_USERNAME,password:process.env.DSQL_DB_READ_ONLY_PASSWORD,database:r,ssl:a()}}),c&&Array.isArray(c)&&c[0]?o.query(t,c).then(_).catch(d):o.query(t).then(_).catch(d)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),i({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},44900:(e,r,t)=>{let s=t(9973),n=t(21580);async function a(...e){let r=s({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()},onConnect:()=>{console.log("Connection Successful!")},onConnectError:e=>{console.log("Connection Error",e.message)},onError:e=>{console.log("Client Error",e.message)}});console.log("Querying ...");try{let t=await r.query(...e);return await r.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e.message),{success:!1,error:e.message}}}e.exports=a},21580:(e,r,t)=>{let s=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,r)=>{var t;Object.defineProperty(r,"A",{enumerable:!0,get:function(){return t}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(t||(t={}))},89947:(e,r,t)=>{e.exports=t(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[2451],()=>t(83919));module.exports=s})(); |