"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")},21820:e=>{e.exports=require("os")},33873:e=>{e.exports=require("path")},96762:(e,r)=>{Object.defineProperty(r,"M",{enumerable:!0,get:function(){return function e(r,n){return n in r?r[n]:"then"in r&&"function"==typeof r.then?r.then(r=>e(r,n)):"function"==typeof r&&"default"===n?r:void 0}}})},57856:(e,r,n)=>{n.r(r),n.d(r,{config:()=>E,default:()=>f,routeModule:()=>y});var o={};n.r(o),n.d(o,{default:()=>m});var t=n(89947),s=n(2706),i=n(96762),a=n(29021),c=n.n(a),l=n(21820),u=n.n(l),d=n(79646),p=n(67619),_=n(87369),S=n(6346);async function m(e,r){if("GET"!==e.method)return r.json({success:!1,msg:"Failed"});let n=await (0,_.A)(e);if(!n?.logged_in_status)return r.json({success:!1,log:"No Logs"});let o="./.tmp/backups";c().existsSync(o)||c().mkdirSync("./.tmp/backups");let t=Date.now().toString();c().mkdirSync(`${o}/${t}`);let s=u().platform().match(/win/i)?"'C:\\Program Files\\MySQL\\MySQL Server 8.0\\bin\\mysqldump.exe'":"mysqldump";try{let e={cwd:process.cwd()},n=`${o}/${t}/datasquirel.sql`;u().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 > ${n}`;console.log(`createNewBackup.ts exe => ${i}`),(0,d.execSync)(i,e);let{mainShemaJSONFilePath:a}=(0,S.A)();c().copyFileSync(a,`${o}/${t}/datasquirelSchema.json`),function({rootFolderPath:e,destinationFolderPath:r}){try{c().mkdirSync(r),function e(r,n){let o=c().readdirSync(r);for(let t=0;t<o.length;t++){let s=o[t];s?.match(/\..{2,5}$/)?c().copyFileSync(`${r}/${s}`,`${n}/${s}`):(c().mkdirSync(`${n}/${s}`,{recursive:!0}),e(`${r}/${s}`,`${n}/${s}`))}}(e,r)}catch(e){return console.log(e.message),!1}}({rootFolderPath:`${process.env.DSQL_USER_DB_SCHEMA_PATH}`,destinationFolderPath:`${o}/${t}/userSchemas`}),r.json({success:!0})}catch(e){r.json({success:!1}),(0,p.A)({component:"/api/admin/createNewBackup/lines-73-90",message:e.message})}}let f=(0,i.M)(o,"default"),E=(0,i.M)(o,"config"),y=new t.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/admin/createNewBackup",pathname:"/api/admin/createNewBackup",bundlePath:"",filename:""},userland:o})},87369:(e,r,n)=>{n.d(r,{A:()=>s});var o=n(95969),t=n(89159);async function s(e){let{keyCookieName:r,csrfCookieName:n}=(0,t.A)(),s=`${r}_su`;if(!e.cookies?.[s])return console.log("No auth key cookie found"),null;let i=(0,o.A)({encryptedString:e.cookies[s]});if(!i)return console.log("No user payload found"),null;let a=JSON.parse(i);return a.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):a.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):a}},89159:(e,r,n)=>{n.d(r,{A:()=>o});function o(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",n=process.env.DSQL_COOKIES_KEY_NAME||"key",o=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",t=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",s=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),i=r;e?.userId&&(i+=`user_${e.userId}_`),s&&(i+=`${s}_`),i+=n;let a=r;e?.userId&&(a+=`user_${e.userId}_`),s&&(a+=`${s}_`),a+=o;let c=r;return e?.userId&&(c+=`user_${e.userId}_`),s&&(c+=`${s}_`),{keyCookieName:i,csrfCookieName:a,oneTimeCodeName:c+=t}}},67619:(e,r,n)=>{n.d(r,{A:()=>s});var o=n(29021),t=n.n(o);async function s({user:e,message:r,component:n,noMail:o,req:s}){let i=new Date,a=(()=>{if(!s)return null;try{let e=s.headers["x-forwarded-for"],r=s.headers["x-real-ip"],n=s.headers["cf-connecting-ip"],o=Array.isArray(e)?e[0]:e?.split(",")[0],t=n||o||r||s.socket.remoteAddress;if(!t)return null;return String(t)}catch(e){return null}})();try{let o=`🚀 SERVER ERROR ===========================
Error Message: ${r}
Component: ${n}`;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)}`),a&&(o+=`
IP: ${a}`),o+=`
Date: ${i.toDateString()}
========================================`,t().existsSync("./.tmp/error.log")||t().writeFileSync("./.tmp/error.log","","utf-8");let c=t().readFileSync("./.tmp/error.log","utf-8");t().writeFileSync("./.tmp/error.log",o),t().appendFileSync("./.tmp/error.log",`




${c}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,n)=>{n.d(r,{A:()=>i});var o=n(55511),t=n(79428),s=n(31542);function i({encryptedString:e,encryptionKey:r,encryptionSalt:n}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:i,salt:a,keyLen:c,algorithm:l,bufferAllocSize:u}=(0,s.A)({encryptionKey:r});if(!i?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!a?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,o.scryptSync)(i,a,c),p=t.Buffer.alloc(u,0),_=(0,o.createDecipheriv)(l,d,p);try{let r=_.update(e,"hex","utf8");return r+=_.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},6346:(e,r,n)=>{n.d(r,{A:()=>s});var o=n(33873),t=n.n(o);function s(e){let r=process.env.DSQL_APP_DIR,n=process.env.DSQL_DB_SCHEMA_DIR,o=".tmp";if(!r)throw Error("Please provide the `DSQL_APP_DIR` env variable.");if(!n)throw Error("Please provide the `DSQL_DB_SCHEMA_DIR` env variable.");let s=t().join(r,"package-shared"),i=t().join(s,"types/dsql.ts"),a=t().join(n,"main.json"),c=t().join(s,"data/defaultFields.json"),l=t().join(n,"users"),u=e?.user?.id?t().join(l,`user-${e.user.id}`):e?.userId?t().join(l,`user-${e.userId}`):void 0,d=u?t().join(u,"main.json"):void 0,p=u?t().join(u,"media"):void 0,_=u?t().join(u,"export"):void 0,S=_?t().join(_,"sql"):void 0,m=S?t().join(S,o):void 0,f=m?t().join(m,"schema.json"):void 0,E="db-export.zip",y=S?t().join(S,E):void 0,v="db-export.zip",A=S?t().join(S,v):void 0;return{schemasDir:n,userDirPath:u,mainShemaJSONFilePath:a,mainDbTypeDefFile:i,tempDirName:o,defaultTableFieldsJSONFilePath:c,usersSchemaDir:l,userSchemaMainJSONFilePath:d,userPrivateMediaDir:p,userPrivateExportsDir:_,userPrivateSQLExportsDir:S,userPrivateTempSQLExportsDir:m,userPrivateTempJSONSchemaFilePath:f,userPrivateDbExportZipFileName:E,userPrivateDbExportZipFilePath:y,userPrivateDbImportZipFileName:v,userPrivateDbImportZipFilePath:A,dbNginxLoadBalancerConfigFile:t().join(r,"docker/mariadb/load-balancer/config/template/nginx.conf")}}},31542:(e,r,n)=>{n.d(r,{A:()=>t});var o=n(82535);function t(e){return{key:e?.encryptionKey||process.env.DSQL_ENCRYPTION_PASSWORD,keyLen:process.env.DSQL_ENCRYPTION_KEY_LENGTH?Number(process.env.DSQL_ENCRYPTION_KEY_LENGTH):24,salt:e?.encryptionSalt||process.env.DSQL_ENCRYPTION_SALT,apiKey:e?.apiKey||process.env.DSQL_API_KEY,algorithm:e?.algorithm||process.env.DSQL_ENCRYPTION_ALGORITHM||"aes-192-cbc",bufferAllocSize:e?.bufferAllocSize||(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE?(0,o.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,n)=>{n.d(r,{A:()=>o});function o(e,r){try{let n=Number(e);if("number"!=typeof n||isNaN(n))return 0;if(r)return Number(n.toFixed(r));return Math.round(n)}catch(e){return console.log(`Numberfy ERROR: ${e.message}`),0}}},2706:(e,r)=>{Object.defineProperty(r,"A",{enumerable:!0,get:function(){return n}});var n=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},89947:(e,r,n)=>{e.exports=n(75600)}};var r=require("../../../webpack-api-runtime.js");r.C(e);var n=r(r.s=57856);module.exports=n})();