1 line
4.3 KiB
JavaScript
1 line
4.3 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:()=>l,routeModule:()=>p});var t={};s.r(t),s.d(t,{default:()=>c});var a=s(89947),i=s(2706),o=s(96762),n=s(83919),d=s(69842),u=s(98e3);async function c(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,n.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 l=(0,o.M)(t,"default"),_=(0,o.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),o=s.n(i),n=s(89159);async function d(e,r,s){try{let{keyCookieName:i,csrfCookieName:d}=(0,n.A)();if(!e.cookies?.[i]?.match(/./))throw Error("Request Cookies not Found!");let u=(0,a.A)({encryptedString:e.cookies[i]});if(!u)throw Error("Couldn't decrypt auth cookie!");let c=JSON.parse(u);if(!c.csrf_k)throw Error("No `csrf_k` present in user Object!");if(s&&!Object.keys(e.headers).find(e=>e.includes(c.csrf_k)))throw Error("Deep Auth Failed. `csrf` key not found in request headers!");let l=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!l)throw Error("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable.");if(s&&!o().existsSync(`${l}/${c.csrf_k}`))throw Error("Key not found in Auth Keys Folder!");if(0==c.verification_status&&!s){let e=await (0,t.A)(`SELECT verification_status FROM users WHERE id='${c.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}if(c?.date&&Date.now()-c.date>6048e5)throw Error("Key expired!");return c}catch(r){return console.log(`userAuth Error for ${e.url}: ${r.message}`),null}}},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+_/,""),o=r;e?.userId&&(o+=`user_${e.userId}_`),i&&(o+=`${i}_`),o+=s;let n=r;e?.userId&&(n+=`user_${e.userId}_`),i&&(n+=`${i}_`),n+=t;let d=r;return e?.userId&&(d+=`user_${e.userId}_`),i&&(d+=`${i}_`),{keyCookieName:o,csrfCookieName:n,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,o=s||process.env.DSQL_ENCRYPTION_SALT,n=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(!o?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let d=(0,t.scryptSync)(i,o,n),u=a.Buffer.alloc(16,0),c=(0,t.createDecipheriv)("aes-192-cbc",d,u);try{let r=c.update(e,"hex","utf8");return r+=c.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})(); |