From eb0827c59747a135046553149f90b2ec19474661 Mon Sep 17 00:00:00 2001 From: TheRed Date: Mon, 11 Apr 2022 22:33:22 +0300 Subject: [PATCH] whoops --- pages/api/submit.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pages/api/submit.js b/pages/api/submit.js index 19969bf..d05d3b9 100644 --- a/pages/api/submit.js +++ b/pages/api/submit.js @@ -1,27 +1,30 @@ -let amogus = ['127.0.0.1', '1', '192.168.1.254'] -export default async function handle(REQ, RES) { +const local = ['127.0.0.1', '1', '192.168.1.254']; +const allowed_chars = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,\/?;:'\[\]\{\}\\<>\-_+=*!#$0123456789\^]*$/; +export default async function handle(req, res) { // Check if IP matches with the local IP - // if(!amogus.includes(REQ.socket.remoteAddress.split('::ffff:')[1])) { - // return RES.status(403).send('Forbidden. IP: '+REQ.socket.remoteAddress.split('::ffff:')[1]+'; Your IP in no way is logged!'); + // const ip = req.socket.remoteAddress.split('::ffff:')[1]; + // if(!local.includes(ip)) { + // return res.status(403).send('Forbidden. IP: ' + ip + '; Your IP in no way is logged!'); // } - if(!/^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,/?;:'\[\]\{\}\\<>\-_+=*!#$0123456789\^]*$/.test(""+REQ?.body?.text)) return RES.status(400).send("The message you were trying to send contains disallowed symbols!"); - let RESPONSE = await fetch(process.env.WEBHOOK, { + const text = req.body?.text; + if(!text) return res.status(400).send("Illegal request!"); + if(!allowed_chars.test(text)) return res.status(400).send("The message you were trying to send contains disallowed symbols!"); + const webhookRes = await fetch(process.env.WEBHOOK, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: "TheRed.SH / User Feedback", - content: REQ?.body?.text ?? "The request that was sent was an illegal request!", + content: text, avatar_url: "https://cdn.discordapp.com/avatars/574110505254256640/049c51674d7ccd748ca123556d351da5.webp?size=1024" }) }) - if(RESPONSE.ok) { - RES.status(200).send("Your message has been successfully sent!"); - await RESPONSE.text().then(i => console.log(i)); - + if(webhookRes.ok) { + res.status(200).send("Your message has been successfully sent!"); + webhookRes.text().then(i => console.log(i)); } else { - RES.status(500).send("Error! The message has failed to send!"); - await RESPONSE.text().then(i => console.log(i)); + res.status(500).send("Error! The message has failed to send!"); + webhookRes.text().then(i => console.log(i)); } -} +} \ No newline at end of file