dsql-admin/dsql-app/.local_dist/server/pages/api/admin/createNewBackup.js
Benjamin Toby 8b7ea057d0 Updates
2024-12-06 14:24:26 +01:00

16 lines
5.2 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:()=>g,default:()=>_,routeModule:()=>E});var n={};t.r(n),t.d(n,{default:()=>y});var o=t(89947),s=t(2706),i=t(96762),l=t(93209),a=t.n(l),c=t(48225),u=t.n(c),p=t(19131),d=t.n(p);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 d()(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 o=Date.now().toString();m.mkdirSync(`${n}/${o}`);let s=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}/${o}/datasquirel.sql`;S.platform().match(/win/i)&&(e.shell="bash.exe");let i=`${s} -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 => ${i}`),f(i,e),m.copyFileSync("./jsonData/dbSchemas/main.json",`${n}/${o}/datasquirelSchema.json`),a()({rootFolderPath:`${process.env.DSQL_USER_DB_SCHEMA_PATH}`,destinationFolderPath:`${n}/${o}/userSchemas`}),r.json({success:!0})}catch(e){r.json({success:!1}),u()({component:"/api/admin/createNewBackup/lines-73-90",message:e.message})}}let _=(0,i.M)(n,"default"),g=(0,i.M)(n,"config"),E=new o.PagesAPIRouteModule({definition:{kind:s.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 o=n.readdirSync(r);for(let s=0;s<o.length;s++){let i=o[s];i?.match(/\..{2,5}$/)?n.copyFileSync(`${r}/${i}`,`${t}/${i}`):(n.mkdirSync(`${t}/${i}`,{recursive:!0}),e(`${r}/${i}`,`${t}/${i}`))}}(e,r),!0}catch(e){return console.log(e.message),!1}}},19131:(e,r,t)=>{let{IncomingMessage:n}=t(81630),o=t(72835),s=t(31341);e.exports=async function(e){let{keyCookieName:r,csrfCookieName:t}=s(),n=`${r}_su`;if(!e.cookies?.[n])return console.log("No auth key cookie found"),null;let i=o({encryptedString:e.cookies[n]});if(!i)return console.log("No user payload found"),null;let l=JSON.parse(i);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(){let e=process.env.DSQL_COOKIES_PREFIX||"dsql_";return{keyCookieName:e+(process.env.DSQL_COOKIES_KEY_NAME||"key"),csrfCookieName:e+(process.env.DSQL_COOKIES_CSRF_NAME||"csrf")}}},48225:(e,r,t)=>{let n=t(29021),{IncomingMessage:o}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:o,req:s}){let i=new Date,l=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],t=s.headers["cf-connecting-ip"],n=Array.isArray(e)?e[0]:e?.split(",")[0],o=t||n||r||s.socket.remoteAddress;if(!o)return null;return String(o)}catch(e){return null}})();try{let o=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(o+=`
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
User Email: ${e?.email}`),s?.url&&(o+=`
URL: ${s.url}`),s?.body&&(o+=`
Request Body: ${JSON.stringify(s.body,null,4)}`),l&&(o+=`
IP: ${l}`),o+=`
Date: ${i.toDateString()}
========================================`,n.existsSync("./.tmp/error.log")||n.writeFileSync("./.tmp/error.log","","utf-8");let a=n.readFileSync("./.tmp/error.log","utf-8");n.writeFileSync("./.tmp/error.log",o),n.appendFileSync("./.tmp/error.log",`
${a}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},72835:(e,r,t)=>{let{scryptSync:n,createDecipheriv:o}=t(55511),{Buffer:s}=t(79428);e.exports=({encryptedString:e,encryptionKey:r,encryptionSalt:t})=>{if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||process.env.DSQL_ENCRYPTION_SALT,a=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 c=o("aes-192-cbc",n(i,l,a),s.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})();