diff options
author | PiBa-NL <pba_2k3@yahoo.com> | 2014-03-19 17:10:49 +0100 |
---|---|---|
committer | PiBa-NL <pba_2k3@yahoo.com> | 2014-03-19 17:10:49 +0100 |
commit | 39b3fe5d22482d16a161193167c00af90390343a (patch) | |
tree | 53b19691d90440731195eb2325db2ecd8511feb2 /config/apcupsd | |
parent | 2a4f986325ccd3a08273bee285993415da12aeb2 (diff) | |
parent | fd710b1c45207f551d7b0a38eb95b5b5e353ac77 (diff) | |
download | pfsense-packages-39b3fe5d22482d16a161193167c00af90390343a.tar.gz pfsense-packages-39b3fe5d22482d16a161193167c00af90390343a.tar.bz2 pfsense-packages-39b3fe5d22482d16a161193167c00af90390343a.zip |
Merge branch 'master' of https://github.com/pfsense/pfsense-packages into hap_de-install_logging
Conflicts:
config/haproxy-devel/haproxy.inc
Diffstat (limited to 'config/apcupsd')
-rw-r--r-- | config/apcupsd/apcupsd.conf.php | 1 | ||||
-rw-r--r-- | config/apcupsd/apcupsd.inc | 34 | ||||
-rw-r--r-- | config/apcupsd/apcupsd.xml | 28 | ||||
-rwxr-xr-x | config/apcupsd/apcupsd_mail.php | 95 | ||||
-rwxr-xr-x | config/apcupsd/apcupsd_status.php | 2 |
5 files changed, 147 insertions, 13 deletions
diff --git a/config/apcupsd/apcupsd.conf.php b/config/apcupsd/apcupsd.conf.php index 6a19b915..7a0340cd 100644 --- a/config/apcupsd/apcupsd.conf.php +++ b/config/apcupsd/apcupsd.conf.php @@ -109,6 +109,7 @@ UPSCABLE {$upscable} # default of 3052 will be used. # UPSTYPE {$upstype} +{$device} # POLLTIME <int> # Interval (in seconds) at which apcupsd polls the UPS for status. This diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 9abc23ba..a2b8d2ff 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -39,6 +39,7 @@ require_once("globals.inc"); function php_install_apcupsd(){ sync_package_apcupsd(); + apccontrol_scripts_install(); } function php_deinstall_apcupsd(){ @@ -138,6 +139,7 @@ function sync_package_apcupsd(){ $upsname=$apcupsd_config['upsname']; $upscable=$apcupsd_config['upscable']; $upstype=$apcupsd_config['upstype']; + $device=($apcupsd_config['device'] != ''? "DEVICE {$apcupsd_config['device']}" : "#DEVICE"); $polltime=($apcupsd_config['polltime'] != ''? $apcupsd_config['polltime'] : "60"); $onbatterydelay=($apcupsd_config['onbatterydelay'] != ''? $apcupsd_config['onbatterydelay'] : "6"); $batterylevel=($apcupsd_config['batterylevel'] != ''? $apcupsd_config['batterylevel'] : "5"); @@ -185,7 +187,37 @@ function sync_package_apcupsd(){ unlink($apcupsd_rcfile); } } - + conf_mount_ro(); } + +function apccontrol_scripts_install(){ + + // check pfsense version + $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); + if ($pfs_version > 2.0){ + define('APCUPSD_BASE', '/usr/pbi/apcupsd-' . php_uname("m")); + } + else { + define('APCUPSD_BASE', '/usr/local'); + } + + $apccontrol_scripts = array("offbattery","onbattery","commfailure","commok","changeme"); + foreach($apccontrol_scripts as $apccontrol_script) { + + $apccontrol_script_file=<<<EOF +#!/bin/sh + +/usr/local/bin/php -f /usr/local/pkg/apcupsd_mail.php {$apccontrol_script} > /dev/null + +exit 0 + +EOF; + + file_put_contents(APCUPSD_BASE . "/etc/apcupsd/" . $apccontrol_script, $apccontrol_script_file, LOCK_EX); + } + +} + ?> + diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 8674af61..e69344fc 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -40,23 +40,28 @@ <name>Apcupsd</name> <title>Services: Apcupsd (General)</title> <category>Monitoring</category> - <version>0.1</version> + <version>0.2</version> <include_file>/usr/local/pkg/apcupsd.inc</include_file> <addedit_string>Apcupsd has been created/modified.</addedit_string> <delete_string>Apcupsd has been deleted.</delete_string> <restart_command>/usr/local/etc/rc.d/apcupsd.sh restart</restart_command> <additional_files_needed> - <item>http://www.pfsense.org/packages/config/apcupsd/apcupsd.inc</item> + <item>https://packages.pfsense.org/packages/config/apcupsd/apcupsd.inc</item> <prefix>/usr/local/pkg/</prefix> <chmod>0755</chmod> </additional_files_needed> <additional_files_needed> - <item>http://www.pfsense.org/packages/config/apcupsd/apcupsd_status.php</item> + <item>https://packages.pfsense.org/packages/config/apcupsd/apcupsd_status.php</item> <prefix>/usr/local/www/</prefix> <chmod>0755</chmod> </additional_files_needed> <additional_files_needed> - <item>http://www.pfsense.org/packages/config/apcupsd/apcupsd.conf.php</item> + <item>https://packages.pfsense.org/packages/config/apcupsd/apcupsd.conf.php</item> + <prefix>/usr/local/pkg/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> + <item>https://packages.pfsense.org/packages/config/apcupsd/apcupsd_mail.php</item> <prefix>/usr/local/pkg/</prefix> <chmod>0755</chmod> </additional_files_needed> @@ -152,12 +157,6 @@ UPSTYPE DEVICE Description <br> catching; you usually want "APC". Port is usually 161. Community is usually "private".<br> <br> -<strong>netsnmp hostname:port:vendor:community</strong> - OBSOLETE - Same as SNMP above but requires use of the - net-snmp library. Unless you have a specific need - for this old driver, you should use 'snmp' instead.<br> -<br> <strong>dumb /dev/tty**</strong> Old serial character device for use with simple-signaling UPSes.<br> <br> @@ -178,6 +177,13 @@ UPSTYPE DEVICE Description <br> <required>true</required> </field> <field> + <fielddescr>Device</fielddescr> + <fieldname>device</fieldname> + <description></description> + <type>input</type> + <size>60</size> + </field> + <field> <fielddescr>Poll Time</fielddescr> <fieldname>polltime</fieldname> <description>Interval (in seconds) at which apcupsd polls the UPS for status. Default is 60</description> @@ -322,7 +328,7 @@ UPSTYPE DEVICE Description <br> </options> </field> </fields> - <custom_php_install_command>sync_package_apcupsd();</custom_php_install_command> + <custom_php_install_command>php_install_apcupsd();</custom_php_install_command> <custom_php_command_before_form></custom_php_command_before_form> <custom_php_after_head_command></custom_php_after_head_command> <custom_php_after_form_command></custom_php_after_form_command> diff --git a/config/apcupsd/apcupsd_mail.php b/config/apcupsd/apcupsd_mail.php new file mode 100755 index 00000000..d5b97f92 --- /dev/null +++ b/config/apcupsd/apcupsd_mail.php @@ -0,0 +1,95 @@ +<?php +/* + apcupsd_mail.php + part of pfSense (https://www.pfsense.org/) + 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] = "Communications with UPS restored"; +$apcstatus[onbattery] = "Power failure. Running on UPS batteries"; +$apcstatus[offbattery] = "Power has returned..."; +$apcstatus[failing] = "UPS battery power exhausted. 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; +} + +?> diff --git a/config/apcupsd/apcupsd_status.php b/config/apcupsd/apcupsd_status.php index e465f62c..8450bb6d 100755 --- a/config/apcupsd/apcupsd_status.php +++ b/config/apcupsd/apcupsd_status.php @@ -1,7 +1,7 @@ <?php /* apcupsd_status.php - part of pfSense (http://www.pfsense.com/) + part of pfSense (https://www.pfsense.org/) Copyright (C) 2013 Danilo G. Baio <dbaio@bsd.com.br> All rights reserved. |