dsql-admin/dsql-app/.local_dist/server/pages/api/admin/createNewBackup.js
Benjamin Toby bc037e839f Updates
2024-12-15 12:27:16 +01:00

16 lines
5.6 KiB
JavaScript

"use strict";(()=>{var e={};e.id=9885,e.ids=[9885],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},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")},21820:e=>{e.exports=require("os")},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}}})},75865:(e,r,t)=>{t.r(r),t.d(r,{config:()=>y,default:()=>E,routeModule:()=>g});var s={};t.r(s),t.d(s,{default:()=>f});var n=t(89947),o=t(2706),a=t(96762),l=t(93209),i=t.n(l),c=t(48225),u=t.n(c),d=t(19131),p=t.n(d);let _=t(29021),S=t(21820),{execSync:m}=t(79646);async function f(e,r){if("GET"!==e.method)return r.json({success:!1,msg:"Failed"});let t=await p()(e);if(!t?.logged_in_status)return r.json({success:!1,log:"No Logs"});let s="./.tmp/backups";_.existsSync(s)||_.mkdirSync("./.tmp/backups");let n=Date.now().toString();_.mkdirSync(`${s}/${n}`);let o=S.platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe'":"mysqldump";try{let e={cwd:process.cwd()},t=`${s}/${n}/datasquirel.sql`;S.platform().match(/win/i)&&(e.shell="bash.exe");let a=`${o} -u ${process.env.DSQL_DB_USERNAME} -h ${process.env.DSQL_DB_HOST} -p${process.env.DSQL_DB_PASSWORD} datasquirel > ${t}`;console.log(`createNewBackup.js exe => ${a}`),m(a,e),_.copyFileSync("./jsonData/dbSchemas/main.json",`${s}/${n}/datasquirelSchema.json`),i()({rootFolderPath:`${process.env.DSQL_USER_DB_SCHEMA_PATH}`,destinationFolderPath:`${s}/${n}/userSchemas`}),r.json({success:!0})}catch(e){r.json({success:!1}),u()({component:"/api/admin/createNewBackup/lines-73-90",message:e.message})}}let E=(0,a.M)(s,"default"),y=(0,a.M)(s,"config"),g=new n.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/admin/createNewBackup",pathname:"/api/admin/createNewBackup",bundlePath:"",filename:""},userland:s})},93209:(e,r,t)=>{let s=t(29021);e.exports=function({rootFolderPath:e,destinationFolderPath:r}){try{return s.mkdirSync(r),function e(r,t){let n=s.readdirSync(r);for(let o=0;o<n.length;o++){let a=n[o];a?.match(/\..{2,5}$/)?s.copyFileSync(`${r}/${a}`,`${t}/${a}`):(s.mkdirSync(`${t}/${a}`,{recursive:!0}),e(`${r}/${a}`,`${t}/${a}`))}}(e,r),!0}catch(e){return console.log(e.message),!1}}},19131:(e,r,t)=>{let{IncomingMessage:s}=t(81630),n=t(72835),o=t(31341);e.exports=async function(e){let{keyCookieName:r,csrfCookieName:t}=o(),s=`${r}_su`;if(!e.cookies?.[s])return console.log("No auth key cookie found"),null;let a=n({encryptedString:e.cookies[s]});if(!a)return console.log("No user payload found"),null;let l=JSON.parse(a);return l.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):l.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):l}},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=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",o=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),a=r;e?.userId&&(a+=`user_${e.userId}_`),o&&(a+=`${o}_`),a+=t;let l=r;e?.userId&&(l+=`user_${e.userId}_`),o&&(l+=`${o}_`),l+=s;let i=r;return e?.userId&&(i+=`user_${e.userId}_`),o&&(i+=`${o}_`),{keyCookieName:a,csrfCookieName:l,oneTimeCodeName:i+=n}}},48225:(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,l=(()=>{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)}`),l&&(n+=`
IP: ${l}`),n+=`
Date: ${a.toDateString()}
========================================`,s.existsSync("./.tmp/error.log")||s.writeFileSync("./.tmp/error.log","","utf-8");let i=s.readFileSync("./.tmp/error.log","utf-8");s.writeFileSync("./.tmp/error.log",n),s.appendFileSync("./.tmp/error.log",`
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:o}=t(79428);e.exports=({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,l=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(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let c=n("aes-192-cbc",s(a,l,i),o.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}}},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=75865);module.exports=t})();