From 2bdc987d53c159f84ef6b44468598e01c98e2a7d Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 10 Aug 2015 15:41:41 +0200 Subject: apcupsd - code style cleanup - Fix copyright header - Fix indendation - Fix file permissions (no need for these to be executable) - Remove useless empty tags - Attempt to make the descriptions more readable. --- config/apcupsd/apcupsd.xml | 347 +++++++++++++++++++++++---------------------- 1 file changed, 177 insertions(+), 170 deletions(-) diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 364db8b8..38c84e81 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -1,46 +1,48 @@ - - + - - All rights reserved. - */ -/* ========================================================================== */ + apcupsd.xml + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2013-2015 Danilo G. Baio + Copyright (C) 2015 ESF, LLC + All rights reserved. +*/ +/* ====================================================================================== */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + 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. + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 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. - */ -/* ========================================================================== */ + 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. +*/ +/* ====================================================================================== */ ]]> Apcupsd Services: Apcupsd (General) Monitoring - 0.3.5 + 0.3.7 /usr/local/pkg/apcupsd.inc Apcupsd has been created/modified. Apcupsd has been deleted. @@ -48,22 +50,18 @@ https://packages.pfsense.org/packages/config/apcupsd/apcupsd.inc /usr/local/pkg/ - 0755 https://packages.pfsense.org/packages/config/apcupsd/apcupsd_status.php /usr/local/www/ - 0755 https://packages.pfsense.org/packages/config/apcupsd/apcupsd.conf.php /usr/local/pkg/ - 0755 https://packages.pfsense.org/packages/config/apcupsd/apcupsd_mail.php /usr/local/pkg/ - 0755 Apcupsd @@ -103,92 +101,99 @@ UPS Name upsname Use this to give your UPS a name in log files and such - input - 60 + input + 60 true UPS Cable upscable - -
-Possible generic choices for are:
- simple, smart, ether, usb
-
-Or a specific cable model number may be used:
- 940-0119A, 940-0127A, 940-0128A, 940-0020B,
- 940-0020C, 940-0023A, 940-0024B, 940-0024C,
- 940-1524C, 940-0024G, 940-0095A, 940-0095B,
- 940-0095C, M-04-02-2000 - ]]>
- input - 60 + +
+ Possible generic choices for 'cable' are:
+ simple, smart, ether, usb +

+ Or a specific cable model number may be used:
+ 940-0119A, 940-0127A, 940-0128A, 940-0020B,
+ 940-0020C, 940-0023A, 940-0024B, 940-0024C,
+ 940-1524C, 940-0024G, 940-0095A, 940-0095B,
+ 940-0095C, M-04-02-2000 + ]]> +
+ input + 60 true
UPS Type / Device upstype - -
-UPSTYPE DEVICE Description
-
-apcsmart /dev/tty** Newer serial character device, appropriate for - SmartUPS models using a serial cable (not USB).
-
-usb BLANK Most new UPSes are USB. A blank DEVICE - setting enables autodetection, which is - the best choice for most installations.
-
-net hostname:port Network link to a master apcupsd through apcupsd's - Network Information Server. This is used if the - UPS powering your computer is connected to a - different computer for monitoring.
-
-snmp hostname:port:vendor:community - SNMP network link to an SNMP-enabled UPS device. - Hostname is the ip address or hostname of the UPS - on the network. Vendor can be can be "APC" or - "APC_NOTRAP". "APC_NOTRAP" will disable SNMP trap - catching; you usually want "APC". Port is usually - 161. Community is usually "private".
-
-dumb /dev/tty** Old serial character device for use with - simple-signaling UPSes.
-
-pcnet ipaddr:username:passphrase:port - PowerChute Network Shutdown protocol which can be - used as an alternative to SNMP with the AP9617 - family of smart slot cards. ipaddr is the IP - address of the UPS management card. username and - passphrase are the credentials for which the card - has been configured. port is the port number on - which to listen for messages from the UPS, normally - 3052. If this parameter is empty or missing, the - default of 3052 will be used.
-
- ]]>
- input - 60 + + + For USB UPSes, please leave the DEVICE directive blank. For other UPS types, you must specify an appropriate port or address.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
UPSTYPEDEVICEDescription
apcsmart/dev/tty**Newer serial character device, appropriate for SmartUPS models using a serial cable (not USB).
usbBLANKMost new UPSes are USB. A blank DEVICE setting enables autodetection, which is the best choice for most installations.
nethostname:portNetwork link to a master apcupsd through apcupsd's Network Information Server. This is used if the  + UPS powering your computer is connected to a different computer for monitoring.
snmphostname:port:vendor:communitySNMP network link to an SNMP-enabled UPS device. Hostname is the ip address or hostname of the UPS on the network.
+ Vendor can be can be "APC" or "APC_NOTRAP". "APC_NOTRAP" will disable SNMP trap catching; you usually want "APC".
+ Port is usually 161. Community is usually "private".
dumb/dev/tty**Old serial character device for use with simple-signaling UPSes.
pcnetipaddr:username:passphrase:portPowerChute Network Shutdown protocol which can be used as an alternative to SNMP with the AP9617 family of smart slot cards.
+ ipaddr is the IP address of the UPS management card; username and passphrase are the credentials for which the card has been configured.
+ Port is the port number on which to listen for messages from the UPS, normally 3052. If this parameter is empty or missing, the default of 3052 will be used.
+ ]]> +
+ input + 60 true
Device device - input - 60 + input + 60 Poll Time polltime - Interval (in seconds) at which apcupsd polls the UPS for status. Default is 60 - input - 10 + Interval (in seconds) at which apcupsd polls the UPS for status. (Default: 60) + input + 10 60 @@ -200,9 +205,9 @@ UPSTYPE DEVICE Description
Lock File lockfile - Path for device lock file. Default is /var/tmp - input - 60 + Path for device lock file. (Default: /var/tmp) + input + 60 Configuration parameters used during power failures @@ -211,62 +216,65 @@ UPSTYPE DEVICE Description
OnBattery Delay onbatterydelay - Time in seconds from when a power failure is detected until we react to it with an onbattery event. Default is 6 - input - 10 + Time in seconds from when a power failure is detected until we react to it with an onbattery event. (Default: 6) + input + 10 6 Battery Level batterylevel If during a power failure, the remaining battery percentage (as reported by the UPS) is - below or equal to BATTERYLEVEL, apcupsd will initiate a system shutdown. Default is 5 - input - 10 + below or equal to BATTERYLEVEL, apcupsd will initiate a system shutdown. (Default: 5) + input + 10 5 Minutes minutes If during a power failure, the remaining runtime in minutes (as calculated internally - by the UPS) is below or equal to MINUTES, apcupsd, will initiate a system shutdown. Default is 3 - input - 10 + by the UPS) is below or equal to MINUTES, apcupsd, will initiate a system shutdown. (Default: 3) + input + 10 3 Timeout timeout If during a power failure, the UPS has run on batteries for TIMEOUT many seconds - or longer, apcupsd will initiate a system shutdown. A value of 0 (default) disables this timer - input - 10 + or longer, apcupsd will initiate a system shutdown. A value of 0 (default) disables this timer. + input + 10 0 Annoy annoy - Time in seconds between annoying users to signoff prior to system shutdown. 0 disables. Default is 300 - input - 10 + Time in seconds between annoying users to signoff prior to system shutdown. 0 disables. (Default: 300) + input + 10 300 Annoy Delay annoydelay - Initial delay after power failure before warning users to get off the system. Default is 60 - input - 10 + Initial delay after power failure before warning users to get off the system. (Default: 60) + input + 10 60 Kill Delay killdelay - If KILLDELAY is non-zero, apcupsd will continue running after a shutdown has been - requested, and after the specified time in seconds attempt to kill the power. This is for use - on systems where apcupsd cannot regain control after a shutdown. 0 disables (default) - input - 10 + + + This is for use on systems where apcupsd cannot regain control after a shutdown. 0 disables (default). + ]]> + + input + 10 0 @@ -277,7 +285,7 @@ UPSTYPE DEVICE Description
Net Server netserver If netstatus is on, a network information server process will be started for serving - the STATUS and EVENT data over the network (used by CGI programs) + the STATUS and EVENT data over the network (used by CGI programs). select on @@ -286,25 +294,31 @@ UPSTYPE DEVICE Description
- NIS Ip + NIS IP nisip - IP address on which NIS server will listen for incoming connections. Default value is - 0.0.0.0 which means any incoming request will be serviced. Alternatively, you can configure this - setting to any specific IP address of your server and NIS will listen for connections only on that - interface. Use the loopback address (127.0.0.1) to accept connections only from the local machine - input - 10 + + + Alternatively, you can configure this setting to any specific IP address of your server and NIS will listen for connections only on that interface.
+ Use the loopback address (127.0.0.1) to accept connections only from the local machine. + ]]> +
+ input + 10 0.0.0.0
NIS Port nisport - Port to use for sending STATUS and EVENTS data over the network. - It is not used unless NETSERVER is on. If you change this port, - you will need to change the corresponding value in the cgi directory - and rebuild the cgi programs. Default is 3551 as registered with the IANA - input - 10 + + + (Default is 3551 as registered with the IANA.) + ]]> + + input + 10 3551 @@ -314,7 +328,7 @@ UPSTYPE DEVICE Description
UPS Class upsclass - Normally standalone unless you share an UPS using an APC ShareUPS card + Normally standalone unless you share an UPS using an APC ShareUPS card. select standalone @@ -326,7 +340,7 @@ UPSTYPE DEVICE Description
UPS Mode upsmode - Normally disable unless you share an UPS using an APC ShareUPS card + Normally disable unless you share an UPS using an APC ShareUPS card. select disable @@ -339,20 +353,17 @@ UPSTYPE DEVICE Description
listtopic
- E-mail notification + E-mail notifications emailnotification - -
-phpMailer - In order to receive e-mail notifications through phpMailer, you need -to configure SMTP Email Notifications on Advanced/Notifications section, and also, -install mailreport package.
-This feature is currently broken on pfSense 2.2, for more info see pfSense forum: -APCupsd package status for pfSense.
-
-SMTP built-in - A simple SMTP mail client for apcupsd. -It does not have smtp authentication of any kind. -
- ]]>
+ +
+ phpMailer - In order to receive e-mail notifications through phpMailer, you need to configure SMTP Email Notifications on Advanced/Notifications section,  + and also install mailreport package.
+ This feature is currently broken on pfSense 2.2; for more info see pfSense forum: APCupsd package status for pfSense.

+ SMTP built-in - A simple SMTP mail client for apcupsd. It does not have smtp authentication of any kind. + ]]> +
select phpmailer @@ -361,51 +372,47 @@ It does not have smtp authentication of any kind.
- SMTP built-in + SMTP built-in settings listtopic SMTP Host smtphost - input - 20 + input + 20 SMTP Port smtpport - input - 5 + input + 5 From smtpfrom - input - 20 + input + 20 To smtpto - input - 20 + input + 20 Cc smtpcc - input - 20 + input + 20 php_install_apcupsd(); - - - validate_input_apcupsd($_POST, $input_errors); - sync_package_apcupsd(); php_deinstall_apcupsd(); -- cgit v1.2.3 From accb310a82a4b64275b31c6fd7de2d8dd1438323 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 10 Aug 2015 15:52:26 +0200 Subject: apcupsd - code style cleanup - Fix copyright headers - Code style cleanup - Use stop_service()/restart_service() --- config/apcupsd/apcupsd.inc | 317 ++++++++++++++++++++++----------------------- 1 file changed, 152 insertions(+), 165 deletions(-) diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 0a99982d..2b166994 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -1,53 +1,48 @@ - - 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. - */ -/* ========================================================================== */ + apcupsd.inc + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2013-2015 Danilo G. Baio + Copyright (C) 2015 ESF, LLC + 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("util.inc"); require_once("functions.inc"); require_once("pkg-utils.inc"); require_once("globals.inc"); -function php_install_apcupsd(){ - sync_package_apcupsd(); +function php_install_apcupsd() { + sync_package_apcupsd(); apccontrol_scripts_install(); } -function php_deinstall_apcupsd(){ +function php_deinstall_apcupsd() { global $config, $g; conf_mount_rw(); - $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); - if ($pfs_version > 2.0){ + $pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3); + if ($pfs_version == "2.1" || $pfs_version == "2.2") { define('APCUPSD_BASE', '/usr/pbi/apcupsd-' . php_uname("m")); } else { define('APCUPSD_BASE', '/usr/local'); @@ -59,176 +54,171 @@ function php_deinstall_apcupsd(){ unlink_if_exists("/var/log/apcupsd/apcupsd.log"); unlink_if_exists("/var/run/apcupsd/apcupsd.pid"); - if (is_dir("/var/log/apcupsd")) - exec("/bin/rm -r /var/log/apcupsd/"); - if (is_dir("/var/run/apcupsd")) - exec("/bin/rm -r /var/run/apcupsd/"); + if (is_dir("/var/log/apcupsd")) { + exec("/bin/rm -rf /var/log/apcupsd/"); + } + if (is_dir("/var/run/apcupsd")) { + exec("/bin/rm -rf /var/run/apcupsd/"); + } - conf_mount_ro(); + conf_mount_ro(); } -function validate_input_apcupsd($post,&$input_errors){ +function validate_input_apcupsd($post, &$input_errors) { - if (isset($post['apcupsdenabled'])){ - + if (isset($post['apcupsdenabled'])) { if ($post['polltime'] != '' && !is_numericint($post['polltime'])) { - $input_errors[]='Poll Time is not numeric.'; + $input_errors[] = 'Poll Time is not numeric.'; } if ($post['onbatterydelay'] != '' && !is_numericint($post['onbatterydelay'])) { - $input_errors[]='OnBattery Delay is not numeric.'; + $input_errors[] = 'OnBattery Delay is not numeric.'; } if ($post['batterylevel'] != '' && !is_numericint($post['batterylevel'])) { - $input_errors[]='Battery Level is not numeric.'; + $input_errors[] = 'Battery Level is not numeric.'; } if ($post['minutes'] != '' && !is_numericint($post['minutes'])) { - $input_errors[]='Minutes is not numeric.'; + $input_errors[] = 'Minutes is not numeric.'; } if ($post['timeout'] != '' && !is_numericint($post['timeout'])) { - $input_errors[]='Timeout is not numeric.'; + $input_errors[] = 'Timeout is not numeric.'; } if ($post['annoy'] != '' && !is_numericint($post['annoy'])) { - $input_errors[]='Annoy is not numeric.'; + $input_errors[] = 'Annoy is not numeric.'; } if ($post['annoydelay'] != '' && !is_numericint($post['annoydelay'])) { - $input_errors[]='Annoy Delay is not numeric.'; + $input_errors[] = 'Annoy Delay is not numeric.'; } if ($post['killdelay'] != '' && !is_numericint($post['killdelay'])) { - $input_errors[]='Kill Delay is not numeric.'; + $input_errors[] = 'Kill Delay is not numeric.'; } if ($post['nisip'] != '') { - if (!is_ipaddr_configured($post['nisip']) && !preg_match("/(127.0.0.1|0.0.0.0)/",$post['nisip'])) { - $input_errors[]='NIS Ip is not a configured IP address.'; + if (!is_ipaddr_configured($post['nisip']) && !preg_match("/(127.0.0.1|0.0.0.0)/", $post['nisip'])) { + $input_errors[] = 'NIS Ip is not a configured IP address.'; } } if ($post['nisport'] != '') { if (!preg_match("/^\d+$/", $post['nisport'])) { - $input_errors[]='NIS Port is not numeric.'; - } + $input_errors[] = 'NIS Port is not numeric.'; + } } if ($post['emailnotification'] == 'smtpbuiltin') { - if (empty($post['smtphost'])) { - $input_errors[]='SMTP Host cannot be empty if SMTP builtin is enabled.'; + $input_errors[] = 'SMTP Host cannot be empty if SMTP builtin is enabled.'; } if (empty($post['smtpport'])) { - $input_errors[]='SMTP Port cannot be empty if SMTP builtin is enabled.'; - }elseif(!is_port($post['smtpport'])){ - $input_errors[]='SMTP Port is not a valid port.'; + $input_errors[] = 'SMTP Port cannot be empty if SMTP builtin is enabled.'; + } elseif (!is_port($post['smtpport'])) { + $input_errors[]='SMTP Port is not a valid port.'; } if (empty($post['smtpfrom'])) { - $input_errors[]='From field cannot be empty if SMTP builtin is enabled.'; + $input_errors[] = 'From field cannot be empty if SMTP builtin is enabled.'; } if (empty($post['smtpto'])) { - $input_errors[]='To field cannot be empty if SMTP builtin is enabled..'; + $input_errors[] = 'To field cannot be empty if SMTP builtin is enabled.'; } - } - } // apcupsdenabled + } } -function sync_package_apcupsd(){ +function sync_package_apcupsd() { global $config, $g; conf_mount_rw(); - // check pfsense version - $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); - if ($pfs_version > 2.0){ + $pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3); + if ($pfs_version == "2.1" || $pfs_version == "2.2") { define('APCUPSD_BASE', '/usr/pbi/apcupsd-' . php_uname("m")); - } - else { + } else { define('APCUPSD_BASE', '/usr/local'); } // check apcupsd settings - if (is_array($config['installedpackages']['apcupsd'])){ + if (is_array($config['installedpackages']['apcupsd'])) { $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; - if ($apcupsd_config['apcupsdenabled']=="on"){ - $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"); - $minutes=($apcupsd_config['minutes'] != ''? $apcupsd_config['minutes'] : "3"); - $timeout=($apcupsd_config['timeout'] != ''? $apcupsd_config['timeout'] : "0"); - $annoy=($apcupsd_config['annoy'] != ''? $apcupsd_config['annoy'] : "300"); - $annoydelay=($apcupsd_config['annoydelay'] != ''? $apcupsd_config['annoydelay'] : "60"); - $killdelay=($apcupsd_config['killdelay'] != ''? $apcupsd_config['killdelay'] : "0"); - $netserver=$apcupsd_config['netserver']; - $nisip=($apcupsd_config['nisip'] != ''? $apcupsd_config['nisip'] : "0.0.0.0"); - $nisport=($apcupsd_config['nisport'] != ''? $apcupsd_config['nisport'] : "3551"); - $upsclass=$apcupsd_config['upsclass']; - $upsmode=$apcupsd_config['upsmode']; - $lockfile=($apcupsd_config['lockfile'] != ''? $apcupsd_config['lockfile'] : "/var/tmp"); - $emailnotification=$apcupsd_config['emailnotification']; - + if ($apcupsd_config['apcupsdenabled'] == "on") { + $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'] ?: "60"; + $onbatterydelay = $apcupsd_config['onbatterydelay'] ?: "6"; + $batterylevel= $apcupsd_config['batterylevel'] ?: "5"; + $minutes = $apcupsd_config['minutes'] ?: "3"; + $timeout = $apcupsd_config['timeout'] ?: "0"; + $annoy = $apcupsd_config['annoy'] ?: "300"; + $annoydelay = $apcupsd_config['annoydelay'] ?: "60"; + $killdelay = $apcupsd_config['killdelay'] ?: "0"; + $netserver = $apcupsd_config['netserver']; + $nisip= $apcupsd_config['nisip'] ?: "0.0.0.0"; + $nisport = $apcupsd_config['nisport'] ?: "3551"; + $upsclass = $apcupsd_config['upsclass']; + $upsmode = $apcupsd_config['upsmode']; + $lockfile= $apcupsd_config['lockfile'] ?: "/var/tmp"; + $emailnotification = $apcupsd_config['emailnotification']; + include("/usr/local/pkg/apcupsd.conf.php"); file_put_contents(APCUPSD_BASE . "/etc/apcupsd/apcupsd.conf", $apcupsdconf, LOCK_EX); } } - // RC FILE + // RC FILE $apcupsd_rcfile="/usr/local/etc/rc.d/apcupsd.sh"; - if (is_array($apcupsd_config) && $apcupsd_config['apcupsdenabled']=="on"){ + if (is_array($apcupsd_config) && $apcupsd_config['apcupsdenabled']=="on") { + $apcupsd_start = "echo \"Starting APC UPS Daemon...\"\n"; $apcupsd_start .= " if [ ! -d {$lockfile} ]; then \n"; $apcupsd_start .= " /bin/mkdir -p {$lockfile} \n"; $apcupsd_start .= " fi \n"; $apcupsd_start .= " /bin/rm -f {$lockfile}/*LCK* 2>/dev/null \n"; - if ($apcupsd_config['killonpowerfail']=="on"){ + if ($apcupsd_config['killonpowerfail'] == "on") { $apcupsd_start .= " " . APCUPSD_BASE . "/sbin/apcupsd --kill-on-powerfail"; - }else{ + } else { $apcupsd_start .= " " . APCUPSD_BASE . "/sbin/apcupsd"; } - - $apcupsd_stop = "echo \"Stopping APC UPS Daemon...\"\n"; + + $apcupsd_stop = "echo \"Stopping APC UPS Daemon...\"\n"; $apcupsd_stop .= " /usr/bin/killall apcupsd\n"; $apcupsd_stop .= " /bin/sleep 5"; - + /* write out rc.d start/stop file */ write_rcfile(array( - "file" => "apcupsd.sh", - "start" => "$apcupsd_start", - "stop" => "$apcupsd_stop" - ) + "file" => "apcupsd.sh", + "start" => "$apcupsd_start", + "stop" => "$apcupsd_stop" + ) ); - mwexec("{$apcupsd_rcfile} restart"); - }else{ - if (file_exists($apcupsd_rcfile)){ - mwexec("{$apcupsd_rcfile} stop"); - unlink($apcupsd_rcfile); - } + + restart_service("apcupsd"); + + } else { + stop_service("apcupsd"); + unlink_if_exists($apcupsd_rcfile); } apccontrol_scripts_install($emailnotification); conf_mount_ro(); } -function apccontrol_scripts_install($emailnotification){ +function apccontrol_scripts_install($emailnotification) { global $config, $g; - // check pfsense version - $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); - if ($pfs_version > 2.0){ + if ($pfs_version == "2.1" || $pfs_version == "2.2") { define('APCUPSD_BASE', '/usr/pbi/apcupsd-' . php_uname("m")); - } - else { + } else { define('APCUPSD_BASE', '/usr/local'); } @@ -239,21 +229,21 @@ function apccontrol_scripts_install($emailnotification){ $apcstatus['changeme'] = "\$HOSTNAME - Emergency! UPS batteries have failed. Change them NOW"; $apccontrol_scripts = array("offbattery","onbattery","commfailure","commok","changeme"); - foreach($apccontrol_scripts as $apccontrol_script) { + foreach ($apccontrol_scripts as $apccontrol_script) { - if ($emailnotification == "smtpbuiltin"){ + if ($emailnotification == "smtpbuiltin") { - if (is_array($config['installedpackages']['apcupsd'])){ + if (is_array($config['installedpackages']['apcupsd'])) { $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; - if ($apcupsd_config['apcupsdenabled']=="on"){ - $smtphost=($apcupsd_config['smtphost'] != ''? $apcupsd_config['smtphost'] : "0.0.0.0"); - $smtpport=($apcupsd_config['smtpport'] != ''? $apcupsd_config['smtpport'] : "25"); - $smtpfrom=$apcupsd_config['smtpfrom']; - $smtpto=$apcupsd_config['smtpto']; - $smtpcc=$apcupsd_config['smtpcc']; - if(empty($smtpcc)){ + if ($apcupsd_config['apcupsdenabled'] == "on") { + $smtphost = $apcupsd_config['smtphost'] ?: "0.0.0.0"; + $smtpport = $apcupsd_config['smtpport'] ?: "25"; + $smtpfrom = $apcupsd_config['smtpfrom']; + $smtpto = $apcupsd_config['smtpto']; + $smtpcc = $apcupsd_config['smtpcc']; + if (empty($smtpcc)) { $smtpcc_cmd = ""; - }else{ + } else { $smtpcc_cmd = "-c {$smtpcc}"; } } @@ -261,7 +251,7 @@ function apccontrol_scripts_install($emailnotification){ $pfSense_hostname = gethostname(); - $apccontrol_script_file=<< /dev/null @@ -292,45 +283,41 @@ EOF; } -function check_nis_running_apcupsd(){ - global $config, $g; - - if (is_array($config['installedpackages']['apcupsd'])){ - $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; - - if ($apcupsd_config['apcupsdenabled']=="on" && $apcupsd_config['netserver']=="on" ) - return(true); - } +function check_nis_running_apcupsd() { + global $config, $g; - return(false); + if (is_array($config['installedpackages']['apcupsd'])) { + $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; + if ($apcupsd_config['apcupsdenabled'] == "on" && $apcupsd_config['netserver'] == "on" ) { + return(true); + } + } else { + return(false); + } } - -function check_nis_ip_apcupsd(){ - global $config, $g; - - if (is_array($config['installedpackages']['apcupsd'])){ - $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; - - if ($apcupsd_config['apcupsdenabled']=="on" && $apcupsd_config['netserver']=="on" ) - return($apcupsd_config['nisip']); - } - - return(false); +function check_nis_ip_apcupsd() { + global $config, $g; + if (is_array($config['installedpackages']['apcupsd'])) { + $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; + if ($apcupsd_config['apcupsdenabled']=="on" && $apcupsd_config['netserver']=="on" ) { + return($apcupsd_config['nisip']); + } + } else { + return(false); + } } -function check_nis_port_apcupsd(){ - global $config, $g; - - if (is_array($config['installedpackages']['apcupsd'])){ - $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; - - if ($apcupsd_config['apcupsdenabled']=="on" && $apcupsd_config['netserver']=="on" ) - return($apcupsd_config['nisport']); - } - - return(false); +function check_nis_port_apcupsd() { + global $config, $g; + if (is_array($config['installedpackages']['apcupsd'])) { + $apcupsd_config = $config['installedpackages']['apcupsd']['config'][0]; + if ($apcupsd_config['apcupsdenabled']=="on" && $apcupsd_config['netserver']=="on" ) { + return($apcupsd_config['nisport']); + } + } else { + return(false); + } } ?> - -- cgit v1.2.3 From 81f504540bf34e016665106382386b1424cee7d3 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 10 Aug 2015 15:55:51 +0200 Subject: apcupsd - code style cleanup Fix copyright header --- config/apcupsd/apcupsd.conf.php | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/config/apcupsd/apcupsd.conf.php b/config/apcupsd/apcupsd.conf.php index 7b6096bc..e472846c 100644 --- a/config/apcupsd/apcupsd.conf.php +++ b/config/apcupsd/apcupsd.conf.php @@ -1,35 +1,35 @@ - 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. - + apcupsd.conf.php + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2013-2015 Danilo G. Baio + Copyright (C) 2015 ESF, LLC + 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. */ -// create apcupsd.conf -$apcupsdconf=<< Date: Mon, 10 Aug 2015 16:01:30 +0200 Subject: apcupsd - code style cleanup - Update copyright header - Code style fixes --- config/apcupsd/apcupsd_mail.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/config/apcupsd/apcupsd_mail.php b/config/apcupsd/apcupsd_mail.php index 15c74fd2..30a8b957 100755 --- a/config/apcupsd/apcupsd_mail.php +++ b/config/apcupsd/apcupsd_mail.php @@ -1,8 +1,9 @@ + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2014-2015 Danilo G. Baio + Copyright (C) 2015 ESF, LLC All rights reserved. Redistribution and use in source and binary forms, with or without @@ -26,7 +27,6 @@ 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/PHPMailerAutoload.php"); @@ -49,28 +49,31 @@ $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]"])) +if (empty($argv[1]) || empty($apcstatus["$argv[1]"])) { return; +} $apcsubject = $apcstatus["$argv[1]"]; -if (empty($config['notifications']['smtp']['ipaddress'])) +if (empty($config['notifications']['smtp']['ipaddress'])) { return; +} $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = $config['notifications']['smtp']['ipaddress']; -if ((isset($config['notifications']['smtp']['ssl']) && $config['notifications']['smtp']['ssl'] != "unchecked") || $config['notifications']['smtp']['ssl'] == "checked") +if ((isset($config['notifications']['smtp']['ssl']) && $config['notifications']['smtp']['ssl'] != "unchecked") || $config['notifications']['smtp']['ssl'] == "checked") { $mail->SMTPSecure = "ssl"; +} -if ((isset($config['notifications']['smtp']['tls']) && $config['notifications']['smtp']['tls'] != "unchecked") || $config['notifications']['smtp']['tls'] == "checked") +if ((isset($config['notifications']['smtp']['tls']) && $config['notifications']['smtp']['tls'] != "unchecked") || $config['notifications']['smtp']['tls'] == "checked") { $mail->SMTPSecure = "tls"; +} $mail->Port = empty($config['notifications']['smtp']['port']) ? 25 : $config['notifications']['smtp']['port']; -if($config['notifications']['smtp']['username'] && - $config['notifications']['smtp']['password']) { +if ($config['notifications']['smtp']['username'] && $config['notifications']['smtp']['password']) { $mail->SMTPAuth = true; $mail->Username = $config['notifications']['smtp']['username']; $mail->Password = $config['notifications']['smtp']['password']; @@ -91,7 +94,7 @@ while ($line = fgets($ph)) $mail->Body .= htmlspecialchars($line); pclose($ph); $mail->Body .= ""; -if(!$mail->Send()) { +if (!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } -- cgit v1.2.3 From 0cdd3a1081299e7f7096d9fcd13e36ab8ed67ab2 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 10 Aug 2015 17:03:47 +0200 Subject: apcupsd - code style cleanup - Remove outdated pfSense <=2.0 stuff and other junk - Fix broken pfS version check - Code style cleanup - Valid XHTML --- config/apcupsd/apcupsd_status.php | 130 +++++++++++++++----------------------- 1 file changed, 50 insertions(+), 80 deletions(-) diff --git a/config/apcupsd/apcupsd_status.php b/config/apcupsd/apcupsd_status.php index a8d3776d..04736c65 100755 --- a/config/apcupsd/apcupsd_status.php +++ b/config/apcupsd/apcupsd_status.php @@ -1,8 +1,9 @@ + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2013-2015 Danilo G. Baio + Copyright (C) 2015 ESF, LLC All rights reserved. Redistribution and use in source and binary forms, with or without @@ -26,66 +27,26 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - require("guiconfig.inc"); require_once("apcupsd.inc"); +global $pfs_version; +$pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3); -$pf_version=substr(trim(file_get_contents("/etc/version")),0,3); -if ($pf_version < 2.0) - $one_two = true; - $pgtitle = "Services: Apcupsd (Status)"; include("head.inc"); -function puts( $arg ) { echo "$arg\n"; } - -if (isset($_GET['strapcaccess'])) - $strapcaccess = trim($_GET['strapcaccess']); - -?> - - - - - - - -

- - +
@@ -101,70 +62,79 @@ pre {
-
- + +
+ -
Host: - "> -
+ " /> +
- Default: localhost
- apcaccess uses apcupsd's inbuilt Network Information Server (NIS) to obtain the current status information
- from the UPS on the local or remote computer. It is therefore necessary to have the following configuration directives:
- NETSERVER on
- NISPORT 3551
-
- - + Default: localhost

+ Note: apcaccess uses apcupsd's inbuilt Network Information Server (NIS) to obtain the current status information
+ from the UPS on the local or remote computer. It is therefore necessary to have the following configuration directives:
+ NETSERVER on
+ NISPORT 3551
+
+ + - +
= 2.2){ - if($strapcaccess) { + if ($pfs_version >= 2.2) { + if ($strapcaccess) { echo "Running: apcaccess -h {$strapcaccess}
"; puts("
");
 			putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
 			$ph = popen("apcaccess -h {$strapcaccess} 2>&1", "r" );
-			while ($line = fgets($ph)) echo htmlspecialchars($line);
+			while ($line = fgets($ph)) {
+				echo htmlspecialchars($line);
+			}
 			pclose($ph);
 			puts("
"); - }elseif($nis_server){ - $nisip=(check_nis_ip_apcupsd() != ''? check_nis_ip_apcupsd() : "0.0.0.0"); - $nisport=(check_nis_port_apcupsd() != ''? check_nis_port_apcupsd() : "3551"); + } elseif ($nis_server) { + $nisip = (check_nis_ip_apcupsd() != ''? check_nis_ip_apcupsd() : "0.0.0.0"); + $nisport = (check_nis_port_apcupsd() != '' ? check_nis_port_apcupsd() : "3551"); echo "Running: apcaccess -h {$nisip}:{$nisport}
"; puts("
");
 			putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
 			$ph = popen("apcaccess -h localhost 2>&1", "r" );
-			while ($line = fgets($ph)) echo htmlspecialchars($line);
+			while ($line = fgets($ph)) {
+				echo htmlspecialchars($line);
+			}
 			pclose($ph);
 			puts("
"); - }else - echo "Network Information Server (NIS) not running, in order to run apcaccess on localhost, you need to enable it on APCupsd General settings.
"; - }else{ - echo "pfSense version prior to 2.2 runs APCupsd 3.14.10 and apcaccess doesn't accept host parameter.
"; - if ($nis_server){ + } else { + echo "Network Information Server (NIS) not running; in order to run apcaccess on localhost, you need to enable it on APCupsd General settings.
"; + } + } else { + echo "pfSense version prior to 2.2 runs APCupsd 3.14.10 and apcaccess doesn't accept host parameter.
"; + if ($nis_server) { puts("
");
 			putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
 			$ph = popen("apcaccess 2>&1", "r" );
-			while ($line = fgets($ph)) echo htmlspecialchars($line);
+			while ($line = fgets($ph)) {
+				echo htmlspecialchars($line);
+			}
 			pclose($ph);
 			puts("
"); - }else - echo "Network Information Server (NIS) not running, in order to run apcaccess on localhost, you need to enable it on APCupsd General settings.
"; - } + } else { + echo "Network Information Server (NIS) not running, in order to run apcaccess on localhost, you need to enable it on APCupsd General settings.
"; + } + } ?>
+
Date: Mon, 10 Aug 2015 17:05:09 +0200 Subject: Sanitize and bump apcupsd package version --- pkg_config.10.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 7c9ce26c..81fbd787 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -1683,7 +1683,7 @@ http://www.apcupsd.com/ Services https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml - apcupsd-3.14.12_1 pkg v0.3.6 + 0.3.7 BETA 2.2 apcupsd.xml -- cgit v1.2.3