summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2013-09-17 17:31:28 (GMT)
committerChristian Pointner <equinox@helsinki.at>2013-09-17 17:31:28 (GMT)
commit3435b6a2237f0386c0d41c9e6e24d78b63070ef0 (patch)
treef05d5b5d9e7b09da09f76ec09d6a88474dde71d1
parent57ce536f59698a376c938b74c25e951f3d01836c (diff)
moved mail sending function to own module
-rw-r--r--mode-watch.lua16
-rw-r--r--silence-watch.lua16
-rw-r--r--utils.lua35
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