2022-04-11 19:33:22 +00:00
|
|
|
const local = ['127.0.0.1', '1', '192.168.1.254'];
|
2022-04-11 20:25:16 +00:00
|
|
|
const disallowRegex = /(https|http):\/\/.*/;
|
2022-04-11 19:33:22 +00:00
|
|
|
const allowed_chars = /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,\/?;:'\[\]\{\}\\<>\-_+=*!#$0123456789\^]*$/;
|
|
|
|
export default async function handle(req, res) {
|
2022-02-15 17:08:29 +00:00
|
|
|
// Check if IP matches with the local IP
|
2022-04-11 19:33:22 +00:00
|
|
|
// 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!');
|
2022-02-15 17:08:29 +00:00
|
|
|
// }
|
2022-04-11 19:33:22 +00:00
|
|
|
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!");
|
2022-04-11 20:25:16 +00:00
|
|
|
if(disallowRegex.test(text)) return res.status(400).send("Nuh-uh! You don't send links here.");
|
2022-04-11 19:33:22 +00:00
|
|
|
const webhookRes = await fetch(process.env.WEBHOOK, {
|
2021-12-22 18:59:23 +00:00
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
username: "TheRed.SH / User Feedback",
|
2022-04-11 19:33:22 +00:00
|
|
|
content: text,
|
2021-12-22 18:59:23 +00:00
|
|
|
avatar_url: "https://cdn.discordapp.com/avatars/574110505254256640/049c51674d7ccd748ca123556d351da5.webp?size=1024"
|
|
|
|
})
|
|
|
|
})
|
2022-04-11 19:33:22 +00:00
|
|
|
if(webhookRes.ok) {
|
|
|
|
res.status(200).send("Your message has been successfully sent!");
|
|
|
|
webhookRes.text().then(i => console.log(i));
|
2021-12-22 18:59:23 +00:00
|
|
|
} else {
|
2022-04-11 19:33:22 +00:00
|
|
|
res.status(500).send("Error! The message has failed to send!");
|
|
|
|
webhookRes.text().then(i => console.log(i));
|
2021-12-22 18:59:23 +00:00
|
|
|
}
|
2022-04-11 19:33:22 +00:00
|
|
|
}
|