Updates
This commit is contained in:
@@ -1,179 +1,28 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 7160;
|
||||
exports.ids = [7160];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6109:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("sanitize-html");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7131:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(5886);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
"use strict";(()=>{var e={};e.id=964,e.ids=[964],e.modules={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")},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,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,r){return r in t?t[r]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,r)):"function"==typeof t&&"default"===r?t:void 0}}})},85617:(e,t,r)=>{r.r(t),r.d(t,{config:()=>m,default:()=>_,routeModule:()=>g});var s={};r.r(s),r.d(s,{default:()=>S});var n=r(89947),o=r(2706),a=r(96762),i=r(77538),c=r.n(i),l=r(6420),u=r.n(l),p=r(33364),d=r.n(p);r(29021),r(28354);let{URL:f}=r(79551);async function S(e,t){if("POST"!==e.method)return t.json({msg:"Failed!"});let r=await u()(e,t,!0);if(!r)return t.json({success:!1,msg:"Unauthorized"});let{dbId:s}=e.body;try{if(!s)throw Error("No Target Database ID provided");await d()({tableName:"user_databases",data:{remote_connected:0,remote_connection_host:"",remote_connection_key:"",remote_connection_type:"",remote_db_full_name:""},identifierColumnName:"id",identifierValue:s}),t.json({success:!0})}catch(e){console.log("Disconnect Error, =>",e.message),c()({component:"/api/connect/verify/main-catch-error",message:e.message,user:r}),t.json({success:!1,msg:"Operation Failed!"})}}let _=(0,a.M)(s,"default"),m=(0,a.M)(s,"config"),g=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/connect/disconnect",pathname:"/api/connect/disconnect",bundlePath:"",filename:""},userland:s})},77538:(e,t,r)=>{let s=r(29021),{IncomingMessage:n}=r(81630);e.exports=async function({user:e,message:t,component:r,noMail:n,req:o}){let a=new Date,i=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],t=o.headers["x-real-ip"],r=o.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=r||s||t||o.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
|
||||
Error Message: ${t}
|
||||
Component: ${r}`;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}`),o?.url&&(n+=`
|
||||
URL: ${o.url}`),o?.body&&(n+=`
|
||||
Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(n+=`
|
||||
IP: ${i}`),n+=`
|
||||
Date: ${a.toDateString()}
|
||||
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let c=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_1___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
const { dbId } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
if (!dbId) throw new Error("No Target Database ID provided");
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const updateDb = await _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_2___default()({
|
||||
tableName: "user_databases",
|
||||
data: {
|
||||
remote_connected: 0,
|
||||
remote_connection_host: "",
|
||||
remote_connection_key: "",
|
||||
remote_connection_type: "",
|
||||
remote_db_full_name: ""
|
||||
},
|
||||
identifierColumnName: "id",
|
||||
identifierValue: dbId
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Disconnect Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,t,r)=>{r(81630);let s=r(51348),n=r(72907),o=r(29021);async function a(e,t,r,a){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=n(e.cookies.datasquirelAuthKey);if(!i)return null;let c=JSON.parse(i);if(!c.csrf_k||r&&!e.headers["x-csrf-auth"]?.match(RegExp(`${c.csrf_k}`)))return null;let l=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!l)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(r&&!o.existsSync(`${l}/${c.csrf_k}`))return null;if(0==c.verification_status&&!r){let e=await s(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&t.setHeader("Set-Cookie",["user_refresh=1"])}return c?.date&&Date.now()-c.date>6048e5?null:c}e.exports=a},33364:(e,t,r)=>{let s=r(82703),n=r(72583),o=r(16570),a=r(51348),i=r(21339);async function c({dbContext:e,paradigm:t,dbFullName:r,tableName:c,data:l,tableSchema:u,identifierColumnName:p,identifierValue:d,encryptionKey:f,encryptionSalt:S}){if(!l||!Object.keys(l).length)return null;let _=!e?.match(/dsql.user/i)&&(!r||!!r.match(/^datasquirel$/)),m=_?a:i,g=Object.keys(l),h=[],y=[];for(let e=0;e<g.length;e++)try{let t=g[e],r=l[t],a=u?u?.fields?.filter(e=>e.fieldName===t):null,i=a&&a[0]?a[0]:null;if(null==r||void 0==r)continue;i?.richText&&(r=n(r,o)),i?.encrypted&&(r=s(r,f,S)),"object"==typeof r&&(r=JSON.stringify(r)),i?.pattern&&!new RegExp(i.pattern,i.patternFlags||"").test(r)&&(console.log("DSQL: Pattern not matched =>",r),r=""),"string"==typeof r&&r.match(/^null$/i)&&(r={toSqlString:function(){return"NULL"}}),"string"!=typeof r||r.match(/./i)||(r={toSqlString:function(){return"NULL"}}),h.push(`\`${t}\`=?`),"number"==typeof r?y.push(String(r)):y.push(r)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}h.push(`date_updated='${Date()}'`),h.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE ${c} SET ${h.join(",")} WHERE \`${p}\`=?`;return y.push(d),_?await m(D,y):await m({paradigm:t,database:r,queryString:D,queryValues:y})}e.exports=c},72907:(e,t,r)=>{let{scryptSync:s,createDecipheriv:n}=r(55511),{Buffer:o}=r(79428);e.exports=e=>{let t=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let r=t.update(e,"hex","utf8");return r+=t.final("utf8")}catch(e){return null}}},82703:(e,t,r)=>{let{scryptSync:s,createCipheriv:n}=r(55511),{Buffer:o}=r(79428),a=r(48225);e.exports=(e,t,r)=>{let i=n("aes-192-cbc",s(t||process.env.DSQL_ENCRYPTION_PASSWORD||"",r||process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let t=i.update(e,"utf8","hex");return t+=i.final("hex")}catch(e){return a({component:"encrypt",message:e.message}),null}}},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"]}}},48225:(e,t,r)=>{let s=r(29021);e.exports=async function({user:e,message:t,component:r,noMail:n}){let o=`🚀 SERVER ERROR ===========================
|
||||
User Id: ${e?.id}
|
||||
User Name: ${e?.first_name} ${e?.last_name}
|
||||
User Email: ${e?.email}
|
||||
Error Message: ${t}
|
||||
Component: ${r}
|
||||
Date: ${Date()}
|
||||
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let a=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",o),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,6825,3017,3403,7547,5886], () => (__webpack_exec__(7131)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
${a}`)}},51348:(e,t,r)=>{let s=r(9973),n=r(21580),o=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 a(...e){try{let t=await o.query(...e);return await o.end(),JSON.parse(JSON.stringify(t))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=a},21339:(e,t,r)=>{let s=r(29021);r(33873);let n=r(9973),o=r(21580),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,charset:"utf8mb4",ssl:o()}});e.exports=function({paradigm:e,database:t,queryString:r,queryValues:i}){try{return new Promise((c,l)=>{let u=!!e?.match(/full.access|^fa$/i);try{function p(e){a.end(),c(JSON.parse(JSON.stringify(e)))}function d(e){a.end(),c({error:e.message,queryStringGenerated:r,queryValuesGenerated:i,sql:e.sql})}a=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:t,ssl: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,database:t,ssl:o()}}),i&&Array.isArray(i)&&i[0]?a.query(r,i).then(p).catch(d):a.query(r).then(p).catch(d)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),c({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},21580:(e,t,r)=>{let s=r(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let t=`${e}/ca-cert.pem`;if(!s.existsSync(t)){console.log(`${t} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},2706:(e,t)=>{var r;Object.defineProperty(t,"A",{enumerable:!0,get:function(){return r}}),function(e){e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE"}(r||(r={}))},89947:(e,t,r)=>{e.exports=r(75600)}};var t=require("../../../webpack-api-runtime.js");t.C(e);var r=t(t.s=85617);module.exports=r})();
|
||||
File diff suppressed because one or more lines are too long
@@ -1,263 +1,28 @@
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 9569;
|
||||
exports.ids = [9569];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 6109:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("sanitize-html");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2081:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("child_process");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 1017:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("path");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 8518:
|
||||
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
||||
|
||||
var __webpack_unused_export__;
|
||||
// @ts-check
|
||||
const { execSync } = __webpack_require__(2081);
|
||||
const fs = __webpack_require__(7147);
|
||||
const path = __webpack_require__(1017);
|
||||
// const serverError = require("./serverError");
|
||||
/**
|
||||
* @async
|
||||
* @param {object} params
|
||||
* @param {number | string} params.userId
|
||||
* @param {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} params.dbSchema
|
||||
* @param {string} [params.targetDb] - Eg `datasquirel_user_7_db_name`
|
||||
* @returns {string}
|
||||
*/ const dbSchemaExec = ({ userId , dbSchema , targetDb })=>{
|
||||
const userSchemaPath = path.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `user-${userId}`, "main.json");
|
||||
fs.writeFileSync(userSchemaPath, JSON.stringify(dbSchema), "utf-8");
|
||||
const targetPath = path.join(process.cwd(), "shell");
|
||||
const dbShellUpdate = execSync(`node createDbFromSchema.js --user ${userId}${targetDb ? " --database " + targetDb : ""}`, {
|
||||
cwd: targetPath
|
||||
});
|
||||
return `User ${userId} Db Schema Updated => ${dbShellUpdate.toString("utf-8")}`;
|
||||
};
|
||||
/**
|
||||
* @async
|
||||
* @param {object} params
|
||||
* @param {number | string} params.userId
|
||||
* @param {import("@/package-shared/types").DSQL_DatabaseSchemaType} params.dbSchema - New Db Schema for `targetDbFullName` variable
|
||||
* @param {import("@/package-shared/types").DSQL_MYSQL_user_databases_Type} params.database - Db entry
|
||||
* @returns {string}
|
||||
*/ const dbSchemaExecDbUpdate = ({ userId , dbSchema , database })=>{
|
||||
const userSchemaPath = path.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH), `user-${userId}`, "main.json");
|
||||
/** @type {import("@/package-shared/types").DSQL_DatabaseSchemaType[]} */ let userDbSchema = JSON.parse(fs.readFileSync(userSchemaPath, "utf-8"));
|
||||
const targetDbIndex = userDbSchema.findIndex((db)=>db.dbFullName == database.db_full_name);
|
||||
if (targetDbIndex < 0) {
|
||||
throw new Error("Target Database not found in user schema data");
|
||||
}
|
||||
const targetDb = {
|
||||
...userDbSchema[targetDbIndex]
|
||||
};
|
||||
userDbSchema[targetDbIndex] = dbSchema;
|
||||
userDbSchema[targetDbIndex].dbName = targetDb.dbName;
|
||||
userDbSchema[targetDbIndex].dbFullName = targetDb.dbFullName;
|
||||
userDbSchema[targetDbIndex].dbSlug = targetDb.dbSlug;
|
||||
userDbSchema[targetDbIndex].dbImage = targetDb.dbImage;
|
||||
return dbSchemaExec({
|
||||
dbSchema: userDbSchema,
|
||||
userId,
|
||||
targetDb: database.db_full_name
|
||||
});
|
||||
};
|
||||
__webpack_unused_export__ = dbSchemaExec;
|
||||
exports.H = dbSchemaExecDbUpdate;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2917:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
"use strict";
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _functions_backend_dbSchemaExec__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8518);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(5886);
|
||||
/* harmony import */ var _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
"use strict";(()=>{var e={};e.id=4065,e.ids=[4065],e.modules={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:()=>h,default:()=>m,routeModule:()=>g});var s={};t.r(s),t.d(s,{default:()=>f});var n=t(89947),a=t(2706),o=t(96762),i=t(7753),l=t(77538),c=t.n(l),u=t(6420),d=t.n(u),p=t(33364),S=t.n(p);t(29021),t(28354);let{URL:_}=t(79551);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await d()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{url:s,key:n,database:a,dbSchema:o,type:l,remoteDbs:u,targetDb:p}=e.body;try{if(!p?.tables)throw Error("No Target Database");await S()({tableName:"user_databases",data:{remote_connected:1,remote_connection_host:s,remote_connection_key:n,remote_connection_type:l,remote_db_full_name:p.dbFullName},identifierColumnName:"db_full_name",identifierValue:a.db_full_name}),(0,i.e)({dbSchema:p,database:a,userId:t.id}),r.json({success:!0})}catch(e){console.log("Connect Handshake Error, =>",e.message),c()({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"),h=(0,o.M)(s,"config"),g=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{execSync:s}=t(79646),n=t(29021),a=t(33873),o=({userId:e,dbSchema:r,targetDb:t})=>{let o=a.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json");n.writeFileSync(o,JSON.stringify(r),"utf-8");let i=s(`node createDbFromSchema.js --user ${e}${t?" --database "+t:""}`,{cwd:a.join(process.cwd(),"shell")});return`User ${e} Db Schema Updated => ${i.toString("utf-8")}`};r.e=({userId:e,dbSchema:r,database:t})=>{let s=a.resolve(String(process.env.DSQL_USER_DB_SCHEMA_PATH),`user-${e}`,"main.json"),i=JSON.parse(n.readFileSync(s,"utf-8")),l=i.findIndex(e=>e.dbFullName==t.db_full_name);if(l<0)throw Error("Target Database not found in user schema data");let c={...i[l]};return i[l]=r,i[l].dbName=c.dbName,i[l].dbFullName=c.dbFullName,i[l].dbSlug=c.dbSlug,i[l].dbImage=c.dbImage,o({dbSchema:i,userId:e,targetDb:t.db_full_name})}},77538:(e,r,t)=>{let s=t(29021),{IncomingMessage:n}=t(81630);e.exports=async function({user:e,message:r,component:t,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"],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 n=`🚀 SERVER ERROR ===========================
|
||||
Error Message: ${r}
|
||||
Component: ${t}`;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()}
|
||||
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let l=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
/** @type {import("@/package-shared/types").DbConnectType} */ const { url , key , database , dbSchema , type , remoteDbs , targetDb } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
if (!targetDb?.tables) throw new Error("No Target Database");
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const updateDb = await _package_shared_functions_backend_db_updateDbEntry__WEBPACK_IMPORTED_MODULE_3___default()({
|
||||
tableName: "user_databases",
|
||||
// /** @type {DSQL_MYSQL_user_databases_Type} */
|
||||
data: {
|
||||
remote_connected: 1,
|
||||
remote_connection_host: url,
|
||||
remote_connection_key: key,
|
||||
remote_connection_type: type,
|
||||
remote_db_full_name: targetDb.dbFullName
|
||||
},
|
||||
identifierColumnName: "db_full_name",
|
||||
identifierValue: database.db_full_name
|
||||
});
|
||||
const update = (0,_functions_backend_dbSchemaExec__WEBPACK_IMPORTED_MODULE_0__/* .dbSchemaExecDbUpdate */ .H)({
|
||||
dbSchema: targetDb,
|
||||
database: database,
|
||||
userId: user.id
|
||||
});
|
||||
res.json({
|
||||
success: true
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Connect Handshake Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72907),a=t(29021);async function o(e,r,t,o){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=n(e.cookies.datasquirelAuthKey);if(!i)return null;let l=JSON.parse(i);if(!l.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=o},33364:(e,r,t)=>{let s=t(82703),n=t(72583),a=t(16570),o=t(51348),i=t(21339);async function l({dbContext:e,paradigm:r,dbFullName:t,tableName:l,data:c,tableSchema:u,identifierColumnName:d,identifierValue:p,encryptionKey:S,encryptionSalt:_}){if(!c||!Object.keys(c).length)return null;let f=!e?.match(/dsql.user/i)&&(!t||!!t.match(/^datasquirel$/)),m=f?o:i,h=Object.keys(c),g=[],y=[];for(let e=0;e<h.length;e++)try{let r=h[e],t=c[r],o=u?u?.fields?.filter(e=>e.fieldName===r):null,i=o&&o[0]?o[0]:null;if(null==t||void 0==t)continue;i?.richText&&(t=n(t,a)),i?.encrypted&&(t=s(t,S,_)),"object"==typeof t&&(t=JSON.stringify(t)),i?.pattern&&!new RegExp(i.pattern,i.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"}}),g.push(`\`${r}\`=?`),"number"==typeof t?y.push(String(t)):y.push(t)}catch(e){console.log("DSQL: Error in parsing data keys in update function =>",e.message);continue}g.push(`date_updated='${Date()}'`),g.push(`date_updated_code='${Date.now()}'`);let D=`UPDATE ${l} SET ${g.join(",")} WHERE \`${d}\`=?`;return y.push(p),f?await m(D,y):await m({paradigm:r,database:t,queryString:D,queryValues:y})}e.exports=l},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:a}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},82703:(e,r,t)=>{let{scryptSync:s,createCipheriv:n}=t(55511),{Buffer:a}=t(79428),o=t(48225);e.exports=(e,r,t)=>{let i=n("aes-192-cbc",s(r||process.env.DSQL_ENCRYPTION_PASSWORD||"",t||process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let r=i.update(e,"utf8","hex");return r+=i.final("hex")}catch(e){return o({component:"encrypt",message:e.message}),null}}},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"]}}},48225:(e,r,t)=>{let s=t(29021);e.exports=async function({user:e,message:r,component:t,noMail:n}){let a=`🚀 SERVER ERROR ===========================
|
||||
User Id: ${e?.id}
|
||||
User Name: ${e?.first_name} ${e?.last_name}
|
||||
User Email: ${e?.email}
|
||||
Error Message: ${r}
|
||||
Component: ${t}
|
||||
Date: ${Date()}
|
||||
========================================`;s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let o=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",a),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,6825,3017,3403,7547,5886], () => (__webpack_exec__(2917)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
${o}`)}},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:i}){try{return new Promise((l,c)=>{let u=!!e?.match(/full.access|^fa$/i);try{function d(e){o.end(),l(JSON.parse(JSON.stringify(e)))}function p(e){o.end(),l({error:e.message,queryStringGenerated:t,queryValuesGenerated:i,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()}}),i&&Array.isArray(i)&&i[0]?o.query(t,i).then(d).catch(p):o.query(t).then(d).catch(p)}catch(e){s.appendFileSync("./.tmp/dbErrorLogs.txt",e.message+"\n"+Date()+"\n\n\n","utf8"),l({error:e.message})}})}catch(e){return{success:!1,error:e.message}}}},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=r(r.s=83919);module.exports=t})();
|
||||
File diff suppressed because one or more lines are too long
@@ -1,181 +1,16 @@
|
||||
"use strict";
|
||||
(() => {
|
||||
var exports = {};
|
||||
exports.id = 2519;
|
||||
exports.ids = [2519];
|
||||
exports.modules = {
|
||||
|
||||
/***/ 2261:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("serverless-mysql");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4300:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("buffer");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 6113:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("crypto");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7147:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("http");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 5687:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("https");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7310:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("url");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3837:
|
||||
/***/ ((module) => {
|
||||
|
||||
module.exports = require("util");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7034:
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "default": () => (/* binding */ handler)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(722);
|
||||
/* harmony import */ var _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0__);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2163);
|
||||
/* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1__);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6825);
|
||||
/* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2__);
|
||||
// @ts-check
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Imports
|
||||
* ==============================================================================
|
||||
*/ const fs = __webpack_require__(7147);
|
||||
const utils = __webpack_require__(3837);
|
||||
const { URL } = __webpack_require__(7310);
|
||||
"use strict";(()=>{var e={};e.id=3033,e.ids=[3033],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},55591:e=>{e.exports=require("https")},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}}})},94871:(e,r,t)=>{t.r(r),t.d(r,{config:()=>S,default:()=>h,routeModule:()=>g});var s={};t.r(s),t.d(s,{default:()=>m});var n=t(89947),o=t(2706),a=t(96762),i=t(10779),l=t.n(i),c=t(77538),u=t.n(c),p=t(6420),f=t.n(p);t(29021),t(28354);let{URL:d}=t(79551);async function m(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await f()(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{url:s,key:n,database:o,dbSchema:a,type:i}=e.body;try{let{hostname:e,port:t,protocol:o}=new d(s),a=await l()({scheme:o,headers:{Authorization:n},hostname:e,port:t,path:"/api/connect",method:"POST",body:{url:s,key:n}}),i=JSON.parse(a);if(!i?.success)throw Error(i.msg||"Remote request failed");r.json({success:!0,payload:i.payload})}catch(e){console.log("Connect Verification Initialtor Error, =>",e.message),u()({component:"/api/connect/verify/main-catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Operation Failed!"})}}let h=(0,a.M)(s,"default"),S=(0,a.M)(s,"config"),g=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/connect/verify",pathname:"/api/connect/verify",bundlePath:"",filename:""},userland:s})},10779:(e,r,t)=>{let s=t(55591),n=t(81630),{URL:o}=t(79551);e.exports=function({url:e,method:r,hostname:t,path:a,headers:i,body:l,port:c,scheme:u}){let p=l?JSON.stringify(l):null,f=e?new o(e):null,d={method:r||"GET",hostname:f?f.hostname:t,port:u?.match(/https/i)?443:f?f.protocol?.match(/https/i)?443:f.port:c?Number(c):80,headers:{}};return a&&(d.path=a),i&&(d.headers=i),l&&(d.headers["Content-Type"]="application/json",d.headers["Content-Length"]=p?Buffer.from(p).length:void 0),new Promise((e,r)=>{let t=(u?.match(/https/i)?s:f?.protocol?.match(/https/i)?s:n).request(d,t=>{var s="";t.on("data",function(e){s+=e}),t.on("end",function(){e(s)}),t.on("error",e=>{console.log("HTTP response error =>",e.message),r(`HTTP response error =>, ${e.message}`)}),t.on("close",()=>{console.log("HTTP(S) Response Closed Successfully")})});l&&t.write(p),t.on("error",e=>{console.log("HTTPS request ERROR =>",e.message),r(`HTTP request error =>, ${e.message}`)}),t.end()})}},77538:(e,r,t)=>{let s=t(29021),{IncomingMessage:n}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:n,req:o}){let a=new Date,i=(()=>{if(!o)return null;try{let e=o.headers["x-forwarded-for"],r=o.headers["x-real-ip"],t=o.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],n=t||s||r||o.socket.remoteAddress;if(!n)return null;return String(n)}catch(e){return null}})();try{let n=`🚀 SERVER ERROR ===========================
|
||||
Error Message: ${r}
|
||||
Component: ${t}`;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}`),o?.url&&(n+=`
|
||||
URL: ${o.url}`),o?.body&&(n+=`
|
||||
Request Body: ${JSON.stringify(o.body,null,4)}`),i&&(n+=`
|
||||
IP: ${i}`),n+=`
|
||||
Date: ${a.toDateString()}
|
||||
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let l=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
|
||||
|
||||
|
||||
|
||||
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
||||
* API handler
|
||||
* ==============================================================================
|
||||
* @type {import("next").NextApiHandler}
|
||||
*/ async function handler(req, res) {
|
||||
/**
|
||||
* Check method
|
||||
*
|
||||
* @description Check request method and return if invalid
|
||||
*/ if (req.method !== "POST") return res.json({
|
||||
msg: "Failed!"
|
||||
});
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_2___default()(req, res, true);
|
||||
if (!user) {
|
||||
return res.json({
|
||||
success: false,
|
||||
msg: "Unauthorized"
|
||||
});
|
||||
}
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const sanitizedReqBody = req.body;
|
||||
/** @type {{ url:string, key: string, database: import("@/package-shared/types").DSQL_MYSQL_user_databases_Type, dbSchema: import("@/package-shared/types").DSQL_DatabaseSchemaType, type: "pull" | "push" }} */ const { url , key , database , dbSchema , type } = sanitizedReqBody;
|
||||
/**
|
||||
* Send Response
|
||||
*
|
||||
* @description Send a boolean response
|
||||
*/ try {
|
||||
/**
|
||||
* User auth
|
||||
*
|
||||
* @description Authenticate user
|
||||
*/ const REMOTE_URL = new URL(url);
|
||||
const { hostname , port , protocol } = REMOTE_URL;
|
||||
const pingBody = {
|
||||
url,
|
||||
key
|
||||
};
|
||||
const pingRemote = await _functions_backend_httpsRequest__WEBPACK_IMPORTED_MODULE_0___default()({
|
||||
scheme: protocol,
|
||||
headers: {
|
||||
Authorization: key
|
||||
},
|
||||
hostname: hostname,
|
||||
port: port,
|
||||
path: "/api/connect",
|
||||
method: "POST",
|
||||
body: pingBody
|
||||
});
|
||||
const resultObject = JSON.parse(pingRemote);
|
||||
if (!resultObject?.success) {
|
||||
throw new Error(resultObject.msg || "Remote request failed");
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
payload: resultObject.payload
|
||||
});
|
||||
////////////////////////////////////////
|
||||
} catch (/** @type {any} */ error) {
|
||||
////////////////////////////////////////
|
||||
console.log("Connect Verification Initialtor Error, =>", error.message);
|
||||
_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_1___default()({
|
||||
component: "/api/connect/verify/main-catch-error",
|
||||
message: error.message,
|
||||
user: user
|
||||
});
|
||||
res.json({
|
||||
success: false,
|
||||
msg: "Operation Failed!"
|
||||
});
|
||||
////////////////////////////////////////
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***/ })
|
||||
|
||||
};
|
||||
;
|
||||
|
||||
// load runtime
|
||||
var __webpack_require__ = require("../../../webpack-api-runtime.js");
|
||||
__webpack_require__.C(exports);
|
||||
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
|
||||
var __webpack_exports__ = __webpack_require__.X(0, [2224,2163,6825,722], () => (__webpack_exec__(7034)));
|
||||
module.exports = __webpack_exports__;
|
||||
|
||||
})();
|
||||
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72907),o=t(29021);async function a(e,r,t,a){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=n(e.cookies.datasquirelAuthKey);if(!i)return null;let l=JSON.parse(i);if(!l.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${l.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!o.existsSync(`${c}/${l.csrf_k}`))return null;if(0==l.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}e.exports=a},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:o}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),o.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},51348:(e,r,t)=>{let s=t(9973),n=t(21580),o=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 a(...e){try{let r=await o.query(...e);return await o.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{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=r(r.s=94871);module.exports=t})();
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user