dsql-admin/dsql-app/.local_dist/server/pages/api/addDbUser.js
Benjamin Toby e0a030f10d Updates
2025-01-13 09:00:21 +01:00

1 line
4.0 KiB
JavaScript

"use strict";(()=>{var e={};e.id=9187,e.ids=[9187],e.modules={75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},72583:e=>{e.exports=require("sanitize-html")},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")},3931:(e,r,s)=>{s.r(r),s.d(r,{config:()=>_,default:()=>c,routeModule:()=>p});var t={};s.r(t),s.d(t,{default:()=>l});var a=s(89947),i=s(2706),n=s(96762),o=s(83919),d=s(69842),u=s(98e3);async function l(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});if(!await (0,d.A)(e,r,!0))return r.json({success:!1,msg:"Unauthorized"});let{payload:s,dbFullName:t,dbId:a}=e.body,i=await (0,u.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:t,tableName:"users",data:(()=>{let e=Object.keys(s),r={};return e.forEach(e=>{e?.match(/paradigm|priviledge|database_access|databases|confirm/)||(r[e]=s[e])}),r.password=(0,o.A)({encryptionKey:process.env.DSQL_ENCRYPTION_PASSWORD||"",password:s.password}),r.email=s.email_address,r.image="/images/user-preset.png",r.image_thumbnail="/images/user-preset-thumbnail.png",delete r.email_address,r})()});r.json({success:!!i?.insertId,msg:"New User User Added",newUserId:i.insertId})}let c=(0,n.M)(t,"default"),_=(0,n.M)(t,"config"),p=new a.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addDbUser",pathname:"/api/addDbUser",bundlePath:"",filename:""},userland:t})},69842:(e,r,s)=>{s.d(r,{A:()=>d});var t=s(48786),a=s(95969),i=s(29021),n=s.n(i),o=s(89159);async function d(e,r,s){let{keyCookieName:i,csrfCookieName:d}=(0,o.A)();if(!e.cookies?.[i]?.match(/./))return null;let u=(0,a.A)({encryptedString:e.cookies[i]});if(!u)return null;let l=JSON.parse(u);if(!l.csrf_k||s&&!Object.keys(e.headers).find(e=>e.includes(l.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(s&&!n().existsSync(`${c}/${l.csrf_k}`))return null;if(0==l.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${l.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return l?.date&&Date.now()-l.date>6048e5?null:l}},89159:(e,r,s)=>{s.d(r,{A:()=>t});function t(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",s=process.env.DSQL_COOKIES_KEY_NAME||"key",t=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",a=process.env.DSQL_COOKIES_ONE_TIME_CODE_NAME||"one-time-code",i=e?.database?.replace(/^datasquirel_user_\d+_/,"")||process.env.DSQL_DB_NAME?.replace(/^datasquirel_user_\d+_/,""),n=r;e?.userId&&(n+=`user_${e.userId}_`),i&&(n+=`${i}_`),n+=s;let o=r;e?.userId&&(o+=`user_${e.userId}_`),i&&(o+=`${i}_`),o+=t;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),i&&(d+=`${i}_`),{keyCookieName:n,csrfCookieName:o,oneTimeCodeName:d+=a}}},95969:(e,r,s)=>{s.d(r,{A:()=>i});var t=s(55511),a=s(79428);function i({encryptedString:e,encryptionKey:r,encryptionSalt:s}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=r||process.env.DSQL_ENCRYPTION_PASSWORD,n=s||process.env.DSQL_ENCRYPTION_SALT,o=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(!n?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(i,n,o),u=a.Buffer.alloc(16,0),l=(0,t.createDecipheriv)("aes-192-cbc",d,u);try{let r=l.update(e,"hex","utf8");return r+=l.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}},83919:(e,r,s)=>{s.d(r,{A:()=>a});var t=s(55511);function a({password:e,encryptionKey:r}){let s=r||process.env.DSQL_ENCRYPTION_PASSWORD;if(!s?.match(/.{8,}/))throw Error("Encryption key is invalid");let a=(0,t.createHmac)("sha512",s);return a.update(e),a.digest("base64")}}};var r=require("../../webpack-api-runtime.js");r.C(e);var s=e=>r(r.s=e),t=r.X(0,[1251],()=>s(3931));module.exports=t})();