16 lines
7.1 KiB
JavaScript
16 lines
7.1 KiB
JavaScript
"use strict";(()=>{var e={};e.id=460,e.ids=[460],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")},66912:(e,r,t)=>{t.r(r),t.d(r,{config:()=>g,default:()=>f,routeModule:()=>p});var a={};t.r(a),t.d(a,{default:()=>E});var s=t(89947),i=t(2706),l=t(96762),n=t(77377),o=t(98e3),d=t(31495),u=t(60125),c=t(67619),_=t(69842);async function E(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,_.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"User Auth Failed"});let{tableName:a,payload:s,tableSchema:i,dbSlug:l,dbId:E,delegated:f}=e.body;try{let c=await (0,u.A)({databaseSlug:l,request:e,user:t,query:e.query});if(!await (0,d.A)({user:t,confirmedDelegetedUser:c,database:l,table:a,dbId:E,priviledgeRegex:/Update Entries/i}))return r.json({success:!1,msg:"Unauthorized"});let _=c?.rootUserId?`datasquirel_user_${c.rootUserId}_${l}`:`datasquirel_user_${t.id}_${l}`,f=await (0,o.A)({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:_,tableName:a,data:s,tableSchema:i});if(!f.insertId)throw console.log("Table Insertion Failed =>",f),Error(f?.error||"Table Insertion Failed");await (0,n.A)({dbName:_,entryId:f.insertId,entryOrder:s.order,tableName:a,tableSchema:i}),r.json({success:!0})}catch(e){(0,c.default)({component:"/api/addTableEntry/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!",err:e.message})}}let f=(0,l.M)(a,"default"),g=(0,l.M)(a,"config"),p=new s.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:a})},31495:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(48786),s=t(67619);async function i({user:e,confirmedDelegetedUser:r,database:t,table:i,priviledgeRegex:l,dbId:n}){let o,d;try{r?.delegated?(o=await (0,a.A)("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,i]),d=o[0]?.priviledge?.match(l)):(o=await (0,a.A)("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,i,n]),d=!0)}catch(r){(0,s.default)({component:"checkUserRights",message:r.message,user:e})}return!!o&&!!o[0]&&!!d}},60125:(e,r,t)=>{t.d(r,{A:()=>s});var a=t(95969);async function s({request:e,databaseSlug:r,user:t,query:s}){try{let i=t.id,l=null;if(!s?.delegated)return{dbUserId:i};let n=s.dbUserId,o=`${process.env.DSQL_USER_DB_PREFIX}${n}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${o}`;try{if(!e.cookies?.[d])throw Error("Cookie not present");let t=(0,a.A)({encryptedString:e.cookies[d]});if(!t)throw Error("Invalid Token");if((l=JSON.parse(t)).databaseSlug===r)return{dbUserId:i=l.rootUserId,rootUserId:l.rootUserId,rootUserName:l.rootUserName,rootUserEmail:l.rootUserEmail,rootUserImage:l.rootUserImage,databaseFullName:l.databaseFullName,databaseSlug:l.databaseSlug,allowedTables:l.allowedTables,priviledges:l.priviledges,database:l.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:i}}catch(e){return null}}},77377:(e,r,t)=>{t.d(r,{A:()=>s});let a=t(37275);async function s({dbName:e,entryId:r,entryOrder:t,tableName:s,tableSchema:i}){try{if(i.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let i=await a({database:e,paradigm:"Full Access",queryString:`SELECT * FROM ${s} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!i?.[0])throw Error("No Existing Order");await a({database:e,paradigm:"Full Access",queryString:`UPDATE ${s} SET \`order\` = \`order\` + 1 WHERE \`order\` >= ${t} AND id != ?`,queryValues:[String(r)]})}return!0}catch(e){return!1}}},69842:(e,r,t)=>{t.d(r,{A:()=>o});var a=t(48786),s=t(95969),i=t(29021),l=t.n(i),n=t(89159);async function o(e,r,t){let{keyCookieName:i,csrfCookieName:o}=(0,n.A)();if(!e.cookies?.[i]?.match(/./))return null;let d=(0,s.A)({encryptedString:e.cookies[i]});if(!d)return null;let u=JSON.parse(d);if(!u.csrf_k||t&&!Object.keys(e.headers).find(e=>e.includes(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&&!l().existsSync(`${c}/${u.csrf_k}`))return null;if(0==u.verification_status&&!t){let e=await (0,a.A)(`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}},89159:(e,r,t)=>{t.d(r,{A:()=>a});function a(e){let r=process.env.DSQL_COOKIES_PREFIX||"dsql_",t=process.env.DSQL_COOKIES_KEY_NAME||"key",a=process.env.DSQL_COOKIES_CSRF_NAME||"csrf",s=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+_/,""),l=r;e?.userId&&(l+=`user_${e.userId}_`),i&&(l+=`${i}_`),l+=t;let n=r;e?.userId&&(n+=`user_${e.userId}_`),i&&(n+=`${i}_`),n+=a;let o=r;return e?.userId&&(o+=`user_${e.userId}_`),i&&(o+=`${i}_`),{keyCookieName:l,csrfCookieName:n,oneTimeCodeName:o+=s}}},67619:(e,r,t)=>{t.r(r),t.d(r,{default:()=>i});var a=t(29021),s=t.n(a);async function i({user:e,message:r,component:t,noMail:a,req:i}){let l=new Date,n=(()=>{if(!i)return null;try{let e=i.headers["x-forwarded-for"],r=i.headers["x-real-ip"],t=i.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||i.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let a=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(a+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),i?.url&&(a+=`
|
|
URL: ${i.url}`),i?.body&&(a+=`
|
|
Request Body: ${JSON.stringify(i.body,null,4)}`),n&&(a+=`
|
|
IP: ${n}`),a+=`
|
|
Date: ${l.toDateString()}
|
|
========================================`,s().existsSync("./.tmp/error.log")||s().writeFileSync("./.tmp/error.log","","utf-8");let o=s().readFileSync("./.tmp/error.log","utf-8");s().writeFileSync("./.tmp/error.log",a),s().appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${o}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},95969:(e,r,t)=>{t.d(r,{A:()=>i});var a=t(55511),s=t(79428);function i({encryptedString:e,encryptionKey:r,encryptionSalt:t}){if(!e?.match(/./))return console.log("Encrypted string is invalid"),e;let i=r||process.env.DSQL_ENCRYPTION_PASSWORD,l=t||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(!l?.match(/.{8,}/))return console.log("Decrption salt is invalid"),e;let o=(0,a.scryptSync)(i,l,n),d=s.Buffer.alloc(16,0),u=(0,a.createDecipheriv)("aes-192-cbc",o,d);try{let r=u.update(e,"hex","utf8");return r+=u.final("utf8")}catch(r){return console.log("Error in decrypting =>",r.message),e}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[1251],()=>t(66912));module.exports=a})(); |