From 9dd9c966de4741eec1e060f4e629bf72406224aa Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Tue, 7 Apr 2015 14:41:48 -0300 Subject: apcupsd - add new fields --- config/apcupsd/apcupsd.xml | 62 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index bef6c330..55d13d6f 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -339,11 +339,63 @@ UPSTYPE DEVICE Description
listtopic - notification_info - info - In order to receive e-mail notifications, you need to configure - SMTP Email Notifications on Advanced/Notifications section, and also, - install mailreport package. + E-mail notification + 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.
+
+SMTP built-in - A simple SMTP mail client for apcupsd. +It does not have smtp authentication of any kind. +
+ ]]>
+ select + phpmailer + + + + +
+ + SMTP built-in + listtopic + + + SMTP Host + smtphost + + input + 20 + + + SMTP Port + smtpport + + input + 5 + + + From + smtpfrom + + input + 20 + + + To + smtpto + + input + 20 + + + Cc + smtpcc + + input + 20 php_install_apcupsd(); -- cgit v1.2.3 From fc674affec886e5fc2bb35e63ae915d86db0be05 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Tue, 7 Apr 2015 14:42:41 -0300 Subject: apcupsd - change function apccontrol_scripts_install() --- config/apcupsd/apcupsd.inc | 70 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 9ebb263b..c46f9cc4 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -115,6 +115,28 @@ function validate_input_apcupsd($post,&$input_errors){ } } + if ($post['emailnotification'] == 'smtpbuiltin') { + + if (empty($post['smtphost'])) { + $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_numericint($post['smtpport'])){ + $input_errors[]='SMTP Port is not numeric.'; + } + + if (empty($post['smtpfrom'])) { + $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..'; + } + + } + } // apcupsdenabled } @@ -154,6 +176,7 @@ function sync_package_apcupsd(){ $upsclass=$apcupsd_config['upsclass']; $upsmode=$apcupsd_config['upsmode']; $lockfile=($apcupsd_config['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); @@ -193,10 +216,12 @@ function sync_package_apcupsd(){ } } + apccontrol_scripts_install($emailnotification); conf_mount_ro(); } -function apccontrol_scripts_install(){ +function apccontrol_scripts_install($emailnotification){ + global $config, $g; // check pfsense version $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); @@ -207,10 +232,50 @@ function apccontrol_scripts_install(){ define('APCUPSD_BASE', '/usr/local'); } + $apcstatus[commfailure] = "\$HOSTNAME - Communications with UPS \$1 lost"; + $apcstatus[commok] = "\$HOSTNAME - Communications with UPS \$1 restored"; + $apcstatus[onbattery] = "\$HOSTNAME - Power failure. Running on UPS \$1 batteries"; + $apcstatus[offbattery] = "\$HOSTNAME - UPS \$1 Power has returned..."; + $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) { - $apccontrol_script_file=<< /dev/null @@ -218,6 +283,7 @@ function apccontrol_scripts_install(){ exit 0 EOF; + } file_put_contents(APCUPSD_BASE . "/etc/apcupsd/" . $apccontrol_script, $apccontrol_script_file, LOCK_EX); } -- cgit v1.2.3 From 6f17b7092e176c7e2fa4d9a1caa4b3ccc9fc5491 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Tue, 7 Apr 2015 14:45:32 -0300 Subject: apcupsd - bump version --- config/apcupsd/apcupsd.xml | 2 +- pkg_config.10.xml | 2 +- pkg_config.8.xml | 2 +- pkg_config.8.xml.amd64 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 55d13d6f..6ba11780 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -40,7 +40,7 @@ Apcupsd Services: Apcupsd (General) Monitoring - 0.3.4 + 0.3.5 /usr/local/pkg/apcupsd.inc Apcupsd has been created/modified. Apcupsd has been deleted. diff --git a/pkg_config.10.xml b/pkg_config.10.xml index e4f10f76..1127d6e1 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -1452,7 +1452,7 @@ Set of programs for controlling APC UPS. Services https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml - apcupsd-3.14.12_1 pkg v0.3.4 + apcupsd-3.14.12_1 pkg v0.3.5 BETA 2.2 apcupsd.xml diff --git a/pkg_config.8.xml b/pkg_config.8.xml index 6eefef46..81be8ab6 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -1883,7 +1883,7 @@ Set of programs for controlling APC UPS. Services https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml - apcupsd-3.14.10_1 pkg v0.3.4 + apcupsd-3.14.10_1 pkg v0.3.5 BETA 2.0 apcupsd.xml diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 582a602e..2b702112 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -1870,7 +1870,7 @@ Set of programs for controlling APC UPS. Services https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml - apcupsd-3.14.10_1 pkg v0.3.4 + apcupsd-3.14.10_1 pkg v0.3.5 BETA 2.0 apcupsd.xml -- cgit v1.2.3 From b790378ebab8de30fc739d3cf2752ea6a463a108 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Tue, 7 Apr 2015 14:53:10 -0300 Subject: apcupsd - add link for pfSense forum --- config/apcupsd/apcupsd.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 6ba11780..364db8b8 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -346,6 +346,8 @@ UPSTYPE DEVICE Description
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. -- cgit v1.2.3 From eabceb73d27cc84ee0035b8016b83d099717c7a2 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Thu, 9 Apr 2015 09:10:41 -0300 Subject: apcupsd - use function is_port() --- config/apcupsd/apcupsd.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index c46f9cc4..86e026a6 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -123,8 +123,8 @@ function validate_input_apcupsd($post,&$input_errors){ if (empty($post['smtpport'])) { $input_errors[]='SMTP Port cannot be empty if SMTP builtin is enabled.'; - }elseif(!is_numericint($post['smtpport'])){ - $input_errors[]='SMTP Port is not numeric.'; + }elseif(!is_port($post['smtpport'])){ + $input_errors[]='SMTP Port is not a valid port.'; } if (empty($post['smtpfrom'])) { -- cgit v1.2.3 From cc9d2f862ca3a44a80a7a98691b31637f8b9b10c Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Thu, 9 Apr 2015 09:12:42 -0300 Subject: apcupsd - use quotes for array key names --- config/apcupsd/apcupsd.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 86e026a6..7255ceb1 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -232,11 +232,11 @@ function apccontrol_scripts_install($emailnotification){ define('APCUPSD_BASE', '/usr/local'); } - $apcstatus[commfailure] = "\$HOSTNAME - Communications with UPS \$1 lost"; - $apcstatus[commok] = "\$HOSTNAME - Communications with UPS \$1 restored"; - $apcstatus[onbattery] = "\$HOSTNAME - Power failure. Running on UPS \$1 batteries"; - $apcstatus[offbattery] = "\$HOSTNAME - UPS \$1 Power has returned..."; - $apcstatus[changeme] = "\$HOSTNAME - Emergency! UPS batteries have failed. Change them NOW"; + $apcstatus['commfailure'] = "\$HOSTNAME - Communications with UPS \$1 lost"; + $apcstatus['commok'] = "\$HOSTNAME - Communications with UPS \$1 restored"; + $apcstatus['onbattery'] = "\$HOSTNAME - Power failure. Running on UPS \$1 batteries"; + $apcstatus['offbattery'] = "\$HOSTNAME - UPS \$1 Power has returned..."; + $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) { -- cgit v1.2.3 From ceaa0cc548063cf8e5964667a3fefef474fab3bc Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Thu, 9 Apr 2015 09:19:46 -0300 Subject: apcupsd - replace system exec `hostname` for php function gethostname() --- config/apcupsd/apcupsd.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 7255ceb1..0a99982d 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -259,10 +259,12 @@ function apccontrol_scripts_install($emailnotification){ } } + $pfSense_hostname = gethostname(); + $apccontrol_script_file=<<