dsql-admin/dsql-app/.local_dist/server/pages/api/addApiKey.js

16 lines
3.5 KiB
JavaScript
Raw Normal View History

2025-01-14 15:27:08 +00:00
"use strict";(()=>{var e={};e.id=1385,e.ids=[1385],e.modules={39908:e=>{e.exports=require("@moduletrace/datasquirel/dist/users/user-auth")},47795:e=>{e.exports=require("generate-password")},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")},15420:(e,r,t)=>{t.r(r),t.d(r,{config:()=>A,default:()=>g,routeModule:()=>S});var s={};t.r(s),t.d(s,{default:()=>y});var a=t(89947),n=t(2706),i=t(96762),o=t(29021),l=t.n(o),d=t(47795),u=t.n(d),c=t(68829),p=t(67619),m=t(69842),f=t(98e3);async function y(e,r){if("POST"!==e.method)return r.json({msg:"Failed!"});let t=await (0,m.A)(e,r,!0);if(!t)return r.json({success:!1,msg:"Unauthorized"});let{api_key_name:s,api_key_slug:a,api_key_scope:n,target_database:i,target_table:o}=e.body;if(!s?.match(/./)||!a?.match(/./)||!n?.match(/./))return r.json({success:!1,msg:"Wrong Input"});try{let e=process.env.DSQL_API_KEYS_PATH;if(!e)throw Error("process.env.DSQL_API_KEYS_PATH variable not found");l().existsSync(e)||l().mkdirSync(e,{recursive:!0});let d=u().generate({length:24,numbers:!0,uppercase:!0,lowercase:!0,symbols:"-"})+"-"+Date.now(),p={user_id:t.id,date_code:Date.now(),sign:d,target_database:i,target_table:o};"fullAccess"==n&&(p={...p,full_access:!0});let m=(0,c.A)({data:JSON.stringify(p)});if(!m)return r.json({success:!1,msg:"Couldn't encrypt API key"});let y=(0,c.A)({data:m}),g={dbFullName:"datasquirel",tableName:"api_keys",data:{user_id:t.id,name:s,slug:a,key:y,scope:n}};d&&(g.data.csrf=d);let A=await (0,f.A)(g);if(!A.insertId)throw Error(A?.error||"Api Key Couldn't be added");l().writeFileSync(`${e}/${d}`,JSON.stringify(p),"utf-8"),r.json({success:!0})}catch(e){(0,p.A)({component:"/api/addApiKey/catch-error",message:e.message,user:t}),r.json({success:!1,msg:"Database Files could not be written!"})}}let g=(0,i.M)(s,"default"),A=(0,i.M)(s,"config"),S=new a.PagesAPIRouteModule({definition:{kind:n.A.PAGES_API,page:"/api/addApiKey",pathname:"/api/addApiKey",bundlePath:"",filename:""},userland:s})},69842:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(39908),a=t.n(s);async function n(e,r,t){let s=a()({req:e,level:t?"deep":void 0});return console.log(s),s.payload}},67619:(e,r,t)=>{t.d(r,{A:()=>n});var s=t(29021),a=t.n(s);async function n({user:e,message:r,component:t,noMail:s,req:n}){let i=new Date,o=(()=>{if(!n)return null;try{let e=n.headers["x-forwarded-for"],r=n.headers["x-real-ip"],t=n.headers["cf-connecting-ip"],s=Array.isArray(e)?e[0]:e?.split(",")[0],a=t||s||r||n.socket.remoteAddress;if(!a)return null;return String(a)}catch(e){return null}})();try{let s=`🚀 SERVER ERROR ===========================
2024-12-08 19:56:57 +00:00
Error Message: ${r}
2025-01-13 08:00:21 +00:00
Component: ${t}`;e?.id&&e?.first_name&&e?.last_name&&e?.email&&(s+=`
2024-12-08 19:56:57 +00:00
User Id: ${e?.id}
User Name: ${e?.first_name} ${e?.last_name}
2025-01-14 06:19:19 +00:00
User Email: ${e?.email}`),n?.url&&(s+=`
URL: ${n.url}`),n?.body&&(s+=`
2025-01-14 15:27:08 +00:00
Request Body: ${JSON.stringify(n.body,null,4)}`),o&&(s+=`
IP: ${o}`),s+=`
2025-01-14 06:42:13 +00:00
Date: ${i.toDateString()}
2025-01-14 15:27:08 +00:00
========================================`,a().existsSync("./.tmp/error.log")||a().writeFileSync("./.tmp/error.log","","utf-8");let l=a().readFileSync("./.tmp/error.log","utf-8");a().writeFileSync("./.tmp/error.log",s),a().appendFileSync("./.tmp/error.log",`
2024-12-08 19:56:57 +00:00
2025-01-14 15:27:08 +00:00
${l}`)}catch(e){console.log("Server Error Reporting Error:",e.message)}}}};var r=require("../../webpack-api-runtime.js");r.C(e);var t=e=>r(r.s=e),s=r.X(0,[1251],()=>t(15420));module.exports=s})();