16 lines
6.0 KiB
JavaScript
16 lines
6.0 KiB
JavaScript
"use strict";(()=>{var e={};e.id=460,e.ids=[460],e.modules={27825:e=>{e.exports=require("lodash")},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")},81630:e=>{e.exports=require("http")},33873:e=>{e.exports=require("path")},14373:(e,r,t)=>{t.r(r),t.d(r,{config:()=>_,default:()=>E,routeModule:()=>b});var a={};t.r(a),t.d(a,{default:()=>f});var s=t(89947),l=t(2706),i=t(96762),o=t(96771),n=t.n(o),d=t(47670),u=t.n(d);t(51348),t(21339);let c=t(73677),p=t(39831),g=t(77538),m=t(6420);async function f(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await m(e,r,!0);if(!t)return r.json({success:!1,msg:"User Auth Failed"});let{tableName:a,payload:s,tableSchema:l,dbSlug:i,dbId:o,delegated:d}=e.body;try{let d=await p({databaseSlug:i,request:e,user:t,query:e.query});if(!await c({user:t,confirmedDelegetedUser:d,database:i,table:a,dbId:o,priviledgeRegex:/Update Entries/i}))return r.json({success:!1,msg:"Unauthorized"});let g=d?.rootUserId?`datasquirel_user_${d.rootUserId}_${i}`:`datasquirel_user_${t.id}_${i}`,m=await u()({dbContext:"Dsql User",paradigm:"Full Access",dbFullName:g,tableName:a,data:s,tableSchema:l});if(!m.insertId)throw console.log("Table Insertion Failed =>",m),Error("Table Insertion Failed");await n()({dbName:g,entryId:m.insertId,entryOrder:s.order,tableName:a,tableSchema:l}),r.json({success:!0})}catch(e){g({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 E=(0,i.M)(a,"default"),_=(0,i.M)(a,"config"),b=new s.PagesAPIRouteModule({definition:{kind:l.A.PAGES_API,page:"/api/addTableEntry",pathname:"/api/addTableEntry",bundlePath:"",filename:""},userland:a})},73677:(e,r,t)=>{let a=t(51348),s=t(77538);e.exports=async function({user:e,confirmedDelegetedUser:r,database:t,table:l,priviledgeRegex:i,dbId:o}){let n,d;try{r?.delegated?(n=await a("SELECT priviledge FROM delegated_user_tables WHERE root_user_id=? AND delegated_user_id=? AND `database`=? AND `table`=?",[r.rootUserId,e.id,t,l]),d=n[0]?.priviledge?.match(i)):(n=await a("SELECT table_slug FROM user_database_tables WHERE user_id=? AND table_slug=? AND db_id=?",[e.id,l,o]),d=!0)}catch(r){s({component:"checkUserRights",message:r.message,user:e})}return!!n&&!!n[0]&&!!d}},39831:(e,r,t)=>{t(81630);let a=t(72907);e.exports=async function({request:e,databaseSlug:r,user:t,query:s}){try{let l=t.id,i=null;if(!s?.delegated)return{dbUserId:l};let o=s.dbUserId,n=`${process.env.DSQL_USER_DB_PREFIX}${o}_${r}`,d=`${process.env.DSQL_USER_DELEGATED_DB_COOKIE_PREFIX}${n}`;try{if(!e.cookies?.[d])throw Error("Cookie not present");let t=a(e.cookies[d]);if(!t)throw Error("Invalid Token");if((i=JSON.parse(t)).databaseSlug===r)return{dbUserId:l=i.rootUserId,rootUserId:i.rootUserId,rootUserName:i.rootUserName,rootUserEmail:i.rootUserEmail,rootUserImage:i.rootUserImage,databaseFullName:i.databaseFullName,databaseSlug:i.databaseSlug,allowedTables:i.allowedTables,priviledges:i.priviledges,database:i.databaseSlug,delegated:!0}}catch(e){}return{dbUserId:l}}catch(e){return null}}},96771:(e,r,t)=>{let a=t(21339);e.exports=async function({dbName:e,entryId:r,entryOrder:t,tableName:s,tableSchema:l}){try{if(l.fields.find(e=>!!e.fieldName?.match(/^order$/i))&&t){let l=await a({database:e,paradigm:"Full Access",queryString:`SELECT * FROM ${s} WHERE \`order\` = '${t}' AND id != ?`,queryValues:[String(r)]});if(!l?.[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}}},77538:(e,r,t)=>{let a=t(29021),{IncomingMessage:s}=t(81630);e.exports=async function({user:e,message:r,component:t,noMail:s,req:l}){let i=new Date,o=(()=>{if(!l)return null;try{let e=l.headers["x-forwarded-for"],r=l.headers["x-real-ip"],t=l.headers["cf-connecting-ip"],a=Array.isArray(e)?e[0]:e?.split(",")[0],s=t||a||r||l.socket.remoteAddress;if(!s)return null;return String(s)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
|
|
Error Message: ${r}
|
|
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
|
|
User Id: ${e?.id}
|
|
User Name: ${e?.first_name} ${e?.last_name}
|
|
User Email: ${e?.email}`),l?.url&&(s+=`
|
|
URL: ${l.url}`),l?.body&&(s+=`
|
|
Request Body: ${JSON.stringify(l.body,null,4)}`),o&&(s+=`
|
|
IP: ${o}`),s+=`
|
|
Date: ${i.toDateString()}
|
|
========================================`,a.existsSync("./.tmp/error.log")||a.writeFileSync("./.tmp/error.log","","utf-8");let n=a.readFileSync("./.tmp/error.log","utf-8");a.writeFileSync("./.tmp/error.log",s),a.appendFileSync("./.tmp/error.log",`
|
|
|
|
|
|
|
|
|
|
${n}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}},6420:(e,r,t)=>{t(81630);let a=t(51348),s=t(72907),l=t(29021);async function i(e,r,t,i){if(!e.cookies?.datasquirelAuthKey?.match(/./))return null;let o=s(e.cookies.datasquirelAuthKey);if(!o)return null;let n=JSON.parse(o);if(!n.csrf_k||t&&!e.headers["x-csrf-auth"]?.match(RegExp(`${n.csrf_k}`)))return null;let d=process.env.DSQL_USER_LOGIN_KEYS_PATH;if(!d)return console.log("DSQL_USER_LOGIN_KEYS_PATH env variable not found. Please set this variable."),null;if(t&&!l.existsSync(`${d}/${n.csrf_k}`))return null;if(0==n.verification_status&&!t){let e=await a(`SELECT verification_status FROM users WHERE id='${n.id}'`);e&&e[0]&&1==e[0].verification_status&&r.setHeader("Set-Cookie",["user_refresh=1"])}return n?.date&&Date.now()-n.date>6048e5?null:n}e.exports=i},72907:(e,r,t)=>{let{scryptSync:a,createDecipheriv:s}=t(55511),{Buffer:l}=t(79428);e.exports=e=>{let r=s("aes-192-cbc",a(process.env.DSQL_ENCRYPTION_PASSWORD||"",process.env.DSQL_ENCRYPTION_SALT||"",24),l.alloc(16,0));try{let t=r.update(e,"hex","utf8");return t+=r.final("utf8")}catch(e){return null}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),a=r.X(0,[4050],()=>t(14373));module.exports=a})(); |