From 3435b6a2237f0386c0d41c9e6e24d78b63070ef0 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 17 Sep 2013 17:31:28 +0000 Subject: moved mail sending function to own module diff --git a/mode-watch.lua b/mode-watch.lua index 7f1e745..b603661 100644 --- a/mode-watch.lua +++ b/mode-watch.lua @@ -20,6 +20,7 @@ -- socket = require("socket") +utils = require("utils") function set_master_led() os.execute("/sbin/led.sh set master") @@ -36,17 +37,6 @@ function clear_leds() os.execute("/sbin/led.sh clear standby") end -function send_mail(address, subject, bodytext) - local fp = assert(io.popen("/usr/sbin/mini_sendmail -smailrelay -fnoreply@helsinki.at " .. address, "w")) - - fp:write("Subject: " .. subject .. "\n") - fp:write("To: " .. address .. "\n") - fp:write("\n") - fp:write(bodytext) - fp:write("\n") - fp:close() -end - current_mode = nil function process_cmd(message) @@ -73,10 +63,10 @@ function process_cmd(message) if(new_mode and new_mode ~= current_mode) then log.printf(log.NOTICE, "mode is now " .. new_mode) if(current_mode == nil) then - send_mail("logs@helsinki.at", "[RHCTL] (re)started mode is now " .. new_mode, + utils.send_mail("logs@helsinki.at", "[RHCTL] (re)started mode is now " .. new_mode, "RHCTL just (re)started current mode is " .. new_mode) else - send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, + utils.send_mail("logs@helsinki.at", "[RHCTL] mode changed to " .. new_mode, "RHCTL just switched from " .. current_mode .. " to " .. new_mode) end current_mode = new_mode diff --git a/silence-watch.lua b/silence-watch.lua index d3c1b48..91d999e 100644 --- a/silence-watch.lua +++ b/silence-watch.lua @@ -20,17 +20,7 @@ -- socket = require("socket") - -function send_mail(address, subject, bodytext) - local fp = assert(io.popen("/usr/sbin/mini_sendmail -smailrelay -fnoreply@helsinki.at " .. address, "w")) - - fp:write("Subject: " .. subject .. "\n") - fp:write("To: " .. address .. "\n") - fp:write("\n") - fp:write(bodytext) - fp:write("\n") - fp:close() -end +utils = require("utils") current_state = nil @@ -42,12 +32,12 @@ function process_cmd(message) if(silence_state and silence_state ~= current_state) then if(silence_state == "0") then log.printf(log.NOTICE, "seen some noise") - send_mail("silence@helsinki.at", "[RHCTL] sees some noise", + utils.send_mail("silence@helsinki.at", "[RHCTL] sees some noise", "There is some noise at output 1 of the audioswitch\nCurrent State is: " .. message) else if (silence_state == "1") then log.printf(log.NOTICE, "silence detected") - send_mail("silence@helsinki.at", "[RHCTL] silence detected ", + utils.send_mail("silence@helsinki.at", "[RHCTL] silence detected ", "Silence detected at output 1 of the audioswitch, make some noise!!\nCurrent State is: " .. message) end end diff --git a/utils.lua b/utils.lua new file mode 100644 index 0000000..950ca58 --- /dev/null +++ b/utils.lua @@ -0,0 +1,35 @@ +-- +-- rhctl +-- +-- Copyright (C) 2009-2013 Christian Pointner +-- +-- This file is part of rhctl. +-- +-- rhctl is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- any later version. +-- +-- rhctl is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with rhctl. If not, see . +-- + +local utils = {} + +function utils.send_mail(address, subject, bodytext) + local fp = assert(io.popen("/usr/sbin/msmtp " .. address, "w")) + + fp:write("Subject: " .. subject .. "\n") + fp:write("To: " .. address .. "\n") + fp:write("\n") + fp:write(bodytext) + fp:write("\n") + fp:close() +end + +return utils \ No newline at end of file -- cgit v0.10.2