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

1 line
3.8 KiB
JavaScript

"use strict";(()=>{var e={};e.id=7963,e.ids=[7963],e.modules={43499:e=>{e.exports=require("@moduletrace/datasquirel/functions/hashPassword")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},9973:e=>{e.exports=require("serverless-mysql")},79428:e=>{e.exports=require("buffer")},55511:e=>{e.exports=require("crypto")},29021:e=>{e.exports=require("fs")},81630:e=>{e.exports=require("http")},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}}})},6523:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>S,routeModule:()=>P});var s={};t.r(s),t.d(s,{default:()=>p});var n=t(89947),a=t(2706),o=t(96762),i=t(51348),u=t.n(i),c=t(6420),l=t.n(c),d=t(43499),f=t.n(d);async function p(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});if(!await l()(e,r,!0))return r.json({success:!1,msg:"Unauthorized"});let{userId:t,password:s,dbId:n}=e.body;try{let e=!!String(n).match(/^\d+$/),a=!!String(t).match(/^\d+$/),o=!!String(s).match(/ /);if(!e||!a)throw Error("Invalud Parameters!");if(o)throw Error("Invalid Password!");let i=await u()("SELECT * FROM user_databases WHERE id = ?",[n]),c=i?.[0]?.db_full_name,l=f()({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:s});await u()(`UPDATE \`${c}\`.\`users\` SET password = ? WHERE id = ?`,[l,t]),r.json({success:!0,msg:"DB user Password Changed!"})}catch(e){r.json({success:!1,msg:e.message})}}let S=(0,o.M)(s,"default"),_=(0,o.M)(s,"config"),P=new n.PagesAPIRouteModule({definition:{kind:a.A.PAGES_API,page:"/api/changeDbUserPassword",pathname:"/api/changeDbUserPassword",bundlePath:"",filename:""},userland:s})},6420:(e,r,t)=>{t(81630);let s=t(51348),n=t(72907),a=t(29021);async function o(e,r,t,o){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let i=n(e.cookies.datasquirelAuthKey);if(!i)return null;let u=JSON.parse(i);if(!u.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${u.csrf_k}`)))return null;let c=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!c)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!a.existsSync(`${c}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await s(`SELECT verification_status FROM users WHERE id='${u.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return u?.date&&Date.now()-u.date>6048e5?null:u}e.exports=o},72907:(e,r,t)=>{let{scryptSync:s,createDecipheriv:n}=t(55511),{Buffer:a}=t(79428);e.exports=e=>{let r=n("aes-192-cbc",s(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),a.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}},51348:(e,r,t)=>{let s=t(9973),n=t(21580),a=s({config:{host:process.env.DSQL_DB_HOST,user:process.env.DSQL_DB_USERNAME,password:process.env.DSQL_DB_PASSWORD,database:process.env.DSQL_DB_NAME,port:process.env.DSQL_DB_PORT?Number(process.env.DSQL_DB_PORT):void 0,charset:"utf8mb4",ssl:n()}});async function o(...e){try{let r=await a.query(...e);return await a.end(),JSON.parse(JSON.stringify(r))}catch(e){return console.log("DB Error =>",e),{success:!1,error:e.message}}}e.exports=o},21580:(e,r,t)=>{let s=t(29021);e.exports=function(){let e=process.env.DSQL_SSL_DIR;if(!e?.match(/./))return;let r=`${e}/ca-cert.pem`;if(!s.existsSync(r)){console.log(`${r} does not exist`);return}return{ca:s.readFileSync(`${e}/ca-cert.pem`)}}},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=6523);module.exports=t})();