diff options
-rw-r--r-- | mode-watch.lua | 16 | ||||
-rw-r--r-- | silence-watch.lua | 16 | ||||
-rw-r--r-- | utils.lua | 35 |
3 files changed, 41 insertions, 26 deletions
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 <equinox@helsinki.at> +-- +-- 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 <http://www.gnu.org/licenses/>. +-- + +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 |