From e82480ae6c4f6ae60904ac82071ca38d570d5be6 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 11 Feb 2025 22:28:42 +0100 Subject: Put disabled modules in modules/$disabled --- modules/$disabled/$email/.gitignore | 2 ++ modules/$disabled/$email/email.js | 71 +++++++++++++++++++++++++++++++++++++ modules/$email/.gitignore | 2 -- modules/$email/email.js | 71 ------------------------------------- 4 files changed, 73 insertions(+), 73 deletions(-) create mode 100644 modules/$disabled/$email/.gitignore create mode 100644 modules/$disabled/$email/email.js delete mode 100644 modules/$email/.gitignore delete mode 100644 modules/$email/email.js (limited to 'modules') diff --git a/modules/$disabled/$email/.gitignore b/modules/$disabled/$email/.gitignore new file mode 100644 index 0000000..df02057 --- /dev/null +++ b/modules/$disabled/$email/.gitignore @@ -0,0 +1,2 @@ +allowed_recipients.txt +password.txt diff --git a/modules/$disabled/$email/email.js b/modules/$disabled/$email/email.js new file mode 100644 index 0000000..d7fe171 --- /dev/null +++ b/modules/$disabled/$email/email.js @@ -0,0 +1,71 @@ +var cmn = require("../$common.js"), + fs = require("fs"), + child_process = require("child_process"), + bodyParser = require("body-parser"); + +var ratelimitAllowed = (function() { + var numEvents = 20, period = 24 * 3600 * 1000; + var eventList = []; + + return function ratelimitAllowed() { + var now = new Date(); + while (now - eventList[0] > period) eventList.unshift(); + if (eventList.length >= numEvents) return false; + eventList.push(now); + return true; + }; +})(); + +function sendEmail(recip, text) { + var opts = { + stdio: ["pipe", "inherit", "inherit"] + }; + var proc = child_process.spawn("msmtp", ["--read-recipients"], opts); + + // Make sure it doesn't run indefinitely + var timeout = setTimeout(() => {proc.kill();}, 5000); + proc.on("exit", () => clearTimeout(timeout)); + proc.on("error", err => { + console.log("email: Failed to start msmtp:", err); + clearTimeout(timeout); + }); + proc.stdin.on("error", err => { + console.log("email: Failed to write to msmtp:", err); + clearTimeout(timeout); + }); + proc.stdin.end( + "To: " + recip + "\n" + + "Subject: Mail from email module\n\n" + + text + ); +} + +module.exports = function(app, io, moddir) { + var allowedRecipients, password; + + try { + allowedRecipients = + fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); + password = fs.readFileSync(moddir + "/password.txt").toString().trim(); + } catch (e) { + console.error(e); + return false; + } + + app.post("/email", bodyParser.json(), function(req, res) { + var body = req.body; + console.log(body); + if (typeof body != "object" || + typeof body.password != "string" || + typeof body.to != "string" || + typeof body.text != "string" || + body.password != password || + allowedRecipients.indexOf(body.to) == -1) { + res.status(400).send("Invalid request"); + return; + } + var text = body.text.slice(0, 1000000); // 1 MB is enough + sendEmail(body.to, body.text); + res.end(); + }); +}; diff --git a/modules/$email/.gitignore b/modules/$email/.gitignore deleted file mode 100644 index df02057..0000000 --- a/modules/$email/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -allowed_recipients.txt -password.txt diff --git a/modules/$email/email.js b/modules/$email/email.js deleted file mode 100644 index d7fe171..0000000 --- a/modules/$email/email.js +++ /dev/null @@ -1,71 +0,0 @@ -var cmn = require("../$common.js"), - fs = require("fs"), - child_process = require("child_process"), - bodyParser = require("body-parser"); - -var ratelimitAllowed = (function() { - var numEvents = 20, period = 24 * 3600 * 1000; - var eventList = []; - - return function ratelimitAllowed() { - var now = new Date(); - while (now - eventList[0] > period) eventList.unshift(); - if (eventList.length >= numEvents) return false; - eventList.push(now); - return true; - }; -})(); - -function sendEmail(recip, text) { - var opts = { - stdio: ["pipe", "inherit", "inherit"] - }; - var proc = child_process.spawn("msmtp", ["--read-recipients"], opts); - - // Make sure it doesn't run indefinitely - var timeout = setTimeout(() => {proc.kill();}, 5000); - proc.on("exit", () => clearTimeout(timeout)); - proc.on("error", err => { - console.log("email: Failed to start msmtp:", err); - clearTimeout(timeout); - }); - proc.stdin.on("error", err => { - console.log("email: Failed to write to msmtp:", err); - clearTimeout(timeout); - }); - proc.stdin.end( - "To: " + recip + "\n" + - "Subject: Mail from email module\n\n" + - text - ); -} - -module.exports = function(app, io, moddir) { - var allowedRecipients, password; - - try { - allowedRecipients = - fs.readFileSync(moddir + "/allowed_recipients.txt").toString().trim().split("\n"); - password = fs.readFileSync(moddir + "/password.txt").toString().trim(); - } catch (e) { - console.error(e); - return false; - } - - app.post("/email", bodyParser.json(), function(req, res) { - var body = req.body; - console.log(body); - if (typeof body != "object" || - typeof body.password != "string" || - typeof body.to != "string" || - typeof body.text != "string" || - body.password != password || - allowedRecipients.indexOf(body.to) == -1) { - res.status(400).send("Invalid request"); - return; - } - var text = body.text.slice(0, 1000000); // 1 MB is enough - sendEmail(body.to, body.text); - res.end(); - }); -}; -- cgit v1.2.3-70-g09d2