"use strict";(()=>{var e={};e.id=5989,e.ids=[5989],e.modules={27825:e=>{e.exports=require("lodash")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},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}}})},86181:(e,r,n)=>{n.r(r),n.d(r,{config:()=>A,default:()=>E,routeModule:()=>S});var t={};n.r(t),n.d(t,{default:()=>f});var o=n(89947),s=n(2706),u=n(96762),i=n(29021),c=n.n(i),a=n(33873),l=n.n(a),d=n(87369),_=n(27825),p=n.n(_);async function f(e,r){if("POST"!==e.method)return r.json({success:!1,msg:"Wrong Method"});let n=await (0,d.A)(e);if(!n?.logged_in_status)return r.json({success:!1,log:"No Logs"});try{let n=l().join(process.cwd(),".env"),t=c().readFileSync(n,"utf-8"),o=RegExp(`${p().escapeRegExp(e.body.key)}=.*`);t.match(o);let s=t.replace(o,`${e.body.key}=${e.body.value}`);c().writeFileSync(n,s,"utf-8"),r.json({success:!0})}catch(e){console.log("updating Env error =>",e.message),r.json({success:!1,error:e.message})}}let E=(0,u.M)(t,"default"),A=(0,u.M)(t,"config"),S=new o.PagesAPIRouteModule({definition:{kind:s.A.PAGES_API,page:"/api/admin/updateEnv",pathname:"/api/admin/updateEnv",bundlePath:"",filename:""},userland:t})},87369:(e,r,n)=>{n.d(r,{A:()=>s});var t=n(95969),o=n(89159);async function s(e){let{keyCookieName:r,csrfCookieName:n}=(0,o.A)(),s=`${r}_su`;if(!e.cookies?.[s])return console.log("No auth key cookie found"),null;let u=(0,t.A)({encryptedString:e.cookies[s]});if(!u)return console.log("No user payload found"),null;let i=JSON.parse(u);return i.password!==process.env.DSQL_USER_KEY?(console.log("Invalid password"),null):i.authKey!==process.env.DSQL_SPECIAL_KEY?(console.log("Invalid auth key"),null):i}},89159:(e,r,n)=>{n.d(r,{A:()=>t});function t(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",n=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",o=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+_/,""),u=r;e?.userId&&(u+=`user_${e.userId}_`),s&&(u+=`${s}_`),u+=n;let i=r;e?.userId&&(i+=`user_${e.userId}_`),s&&(i+=`${s}_`),i+=t;let c=r;return e?.userId&&(c+=`user_${e.userId}_`),s&&(c+=`${s}_`),{keyCookieName:u,csrfCookieName:i,oneTimeCodeName:c+=o}}},95969:(e,r,n)=>{n.d(r,{A:()=>u});var t=n(55511),o=n(79428),s=n(31542);function u({encryptedString:e,encryptionKey:r,encryptionSalt:n}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let{key:u,salt:i,keyLen:c,algorithm:a,bufferAllocSize:l}=(0,s.A)({encryptionKey:r});if(!u?.match(/.{8,}/))return console.log("Decrption key is invalid"),e;if(!i?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(u,i,c),_=o.Buffer.alloc(l,0),p=(0,t.createDecipheriv)(a,d,_);try{let r=p.update(e,"hex","utf8");return r+=p.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},31542:(e,r,n)=>{n.d(r,{A:()=>o});var t=n(82535);function o(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,t.A)(process.env.DSQL_ENCRYPTION_BUFFER_ALLOCATION_SIZE):void 0)||16}}},82535:(e,r,n)=>{n.d(r,{A:()=>t});function t(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=86181);module.exports=n})();