aboutsummaryrefslogtreecommitdiffstats
path: root/config/apcupsd/apcupsd_mail.php
diff options
context:
space:
mode:
authorDanilo G. Baio (dbaio) <dbaio@bsd.com.br>2014-01-26 13:23:31 -0200
committerDanilo G. Baio (dbaio) <dbaio@bsd.com.br>2014-01-26 13:23:31 -0200
commit6e4487e155682494cf72e59cf8423f60c05a35c0 (patch)
tree9c60387e2d4de868630b5b4d913e2c3a47cb84f6 /config/apcupsd/apcupsd_mail.php
parent81d43d9b8f6c66de409b24be746fa742473329ff (diff)
downloadpfsense-packages-6e4487e155682494cf72e59cf8423f60c05a35c0.tar.gz
pfsense-packages-6e4487e155682494cf72e59cf8423f60c05a35c0.tar.bz2
pfsense-packages-6e4487e155682494cf72e59cf8423f60c05a35c0.zip
apcupsd - add script to send mail reports
Diffstat (limited to 'config/apcupsd/apcupsd_mail.php')
-rwxr-xr-xconfig/apcupsd/apcupsd_mail.php96
1 files changed, 96 insertions, 0 deletions
diff --git a/config/apcupsd/apcupsd_mail.php b/config/apcupsd/apcupsd_mail.php
new file mode 100755
index 00000000..3b1e40be
--- /dev/null
+++ b/config/apcupsd/apcupsd_mail.php
@@ -0,0 +1,96 @@
+<?php
+/*
+ apcupsd_mail.php
+ part of pfSense (http://www.pfsense.com/)
+ Copyright (C) 2014 Danilo G. Baio <dbaio@bsd.com.br>
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+
+require_once("pkg-utils.inc");
+require_once("globals.inc");
+require_once("phpmailer/class.phpmailer.php");
+
+global $config, $g;
+
+$apcstatus[killpower] = "UPS now committed to shut down";
+$apcstatus[commfailure] = "Communications with UPS lost";
+$apcstatus[commok] = "Communciations with UPS restored";
+$apcstatus[onbattery] = "Power failure. Running on UPS batteries";
+$apcstatus[offbattery] = "Power has returned...";
+$apcstatus[failing] = "UPS battery power exhaused. Doing shutdown";
+$apcstatus[timeout] = "UPS battery runtime limit exceeded. Doing shutdown";
+$apcstatus[loadlimit] = "UPS battery discharge limit reached. Doing shutdown";
+$apcstatus[runlimit] = "UPS battery runtime percent reached. Doing shutdown";
+$apcstatus[doreboot] = "Beginning Reboot Sequence";
+$apcstatus[doshutdown] = "Beginning Shutdown Sequence";
+$apcstatus[annoyme] = "Power problems please logoff";
+$apcstatus[emergency] = "Emergency Shutdown. Possible UPS battery failure";
+$apcstatus[changeme] = "Emergency! UPS batteries have failed. Change them NOW";
+$apcstatus[remotedown] = "Remote Shutdown. Beginning Shutdown Sequence";
+
+if (empty($argv[1]) || empty($apcstatus["$argv[1]"]))
+ return;
+
+$apcsubject = $apcstatus["$argv[1]"];
+
+if (empty($config['notifications']['smtp']['ipaddress']))
+ return;
+
+$mail = new PHPMailer();
+$mail->IsSMTP();
+$mail->Host = $config['notifications']['smtp']['ipaddress'];
+
+if ($config['notifications']['smtp']['ssl'] == "checked")
+ $mail->SMTPSecure = "ssl";
+
+$mail->Port = empty($config['notifications']['smtp']['port']) ? 25 : $config['notifications']['smtp']['port'];
+
+if($config['notifications']['smtp']['username'] &&
+ $config['notifications']['smtp']['password']) {
+ $mail->SMTPAuth = true;
+ $mail->Username = $config['notifications']['smtp']['username'];
+ $mail->Password = $config['notifications']['smtp']['password'];
+}
+
+$mail->ContentType = 'text/html';
+$mail->IsHTML(true);
+$mail->AddReplyTo($config['notifications']['smtp']['fromaddress'], "Apcupsd");
+$mail->SetFrom($config['notifications']['smtp']['fromaddress'], "Apcupsd");
+$address = $config['notifications']['smtp']['notifyemailaddress'];
+$mail->AddAddress($address, "Apcupsd Recipient");
+$mail->Subject = "{$config['system']['hostname']}.{$config['system']['domain']} - {$apcsubject}";
+
+putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
+$mail->Body = "<pre>";
+$ph = popen('apcaccess status 2>&1', "r" );
+while ($line = fgets($ph)) $mail->Body .= htmlspecialchars($line);
+pclose($ph);
+$mail->Body .= "</pre>";
+
+if(!$mail->Send()) {
+ echo "Mailer Error: " . $mail->ErrorInfo;
+}
+
+?>
+