dsql-admin/dsql-app/.local_dist/server/pages/api/admin/createNewBackup.js
Benjamin Toby 3ffd2d6777 Updates
2024-12-05 08:03:33 +01:00

16 lines
4.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:()=>$,default:()=>g,routeModule:()=>h});var n={};t.r(n),t.d(n,{default:()=>y});var s=t(89947),o=t(2706),a=t(96762),l=t(93209),i=t.n(l),c=t(77538),u=t.n(c),d=t(19131),p=t.n(d);let m=t(29021),S=t(21820),{execSync:f}=t(79646);async function y(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 n="./.tmp/backups";m.existsSync(n)||m.mkdirSync("./.tmp/backups");let s=Date.now().toString();m.mkdirSync(`${n}/${s}`);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=`${n}/${s}/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}`),f(a,e),m.copyFileSync("./jsonData/dbSchemas/main.json",`${n}/${s}/datasquirelSchema.json`),i()({rootFolderPath:`${process.env.DSQL_USER_DB_SCHEMA_PATH}`,destinationFolderPath:`${n}/${s}/userSchemas`}),r.json({success:!0})}catch(e){r.json({success:!1}),u()({component:"/api/admin/createNewBackup/lines-73-90",message:e.message})}}let g=(0,a.M)(n,"default"),$=(0,a.M)(n,"config"),h=new s.PagesAPIRouteModule({definition:{kind:o.A.PAGES_API,page:"/api/admin/createNewBackup",pathname:"/api/admin/createNewBackup",bundlePath:"",filename:""},userland:n})},93209:(e,r,t)=>{let n=t(29021);e.exports=function({rootFolderPath:e,destinationFolderPath:r}){try{return n.mkdirSync(r),function e(r,t){let s=n.readdirSync(r);for(let o=0;o<s.length;o++){let a=s[o];a?.match(/\..{2,5}$/)?n.copyFileSync(`${r}/${a}`,`${t}/${a}`):(n.mkdirSync(`${t}/${a}`,{recursive:!0}),e(`${r}/${a}`,`${t}/${a}`))}}(e,r),!0}catch(e){return console.log(e.message),!1}}},77538:(e,r,t)=>{let n=t(29021),{IncomingMessage:s}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:s,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"],n=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||n||r||o.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
Error Message: ${r}
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}`),o?.url&&(s+=`
URL: ${o.url}`),o?.body&&(s+=`
Request Body: ${JSON.stringify(o.body,null,4)}`),l&&(s+=`
IP: ${l}`),s+=`
Date: ${a.toDateString()}
========================================`,n.existsSync("./.tmp/error.log")||n.writeFileSync("./.tmp/error.log","","utf-8");let i=n.readFileSync("./.tmp/error.log","utf-8");n.writeFileSync("./.tmp/error.log",s),n.appendFileSync("./.tmp/error.log",`
${i}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},19131:(e,r,t)=>{let{IncomingMessage:n}=t(81630),s=t(72907);e.exports=async function(e){if(!e.cookies?.datasquirelSuAdminUserAuthKey)return console.log("No auth key cookie found"),null;let r=s(e.cookies.datasquirelSuAdminUserAuthKey);if(!r)return console.log("No user payload found"),null;let t=JSON.parse(r);return t.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):t.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):t}},72907:(e,r,t)=>{let{scryptSync:n,createDecipheriv:s}=t(55511),{Buffer:o}=t(79428);e.exports=e=>{let r=s("aes-192-cbc",n(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}}},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})();