aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Botelho <garga@FreeBSD.org>2015-04-09 09:47:36 -0300
committerRenato Botelho <garga@FreeBSD.org>2015-04-09 09:47:36 -0300
commite0068ed58ddec92031c4d5c903913db0f443ed83 (patch)
tree5fb31efd889caf4c723bd2de49c206e1fc4558fe
parent6477fcaeef04b041d05d8fa1dd57ebac94355c5f (diff)
parentceaa0cc548063cf8e5964667a3fefef474fab3bc (diff)
downloadpfsense-packages-e0068ed58ddec92031c4d5c903913db0f443ed83.tar.gz
pfsense-packages-e0068ed58ddec92031c4d5c903913db0f443ed83.tar.bz2
pfsense-packages-e0068ed58ddec92031c4d5c903913db0f443ed83.zip
Merge pull request #848 from dbaio/apcupsd
-rw-r--r--config/apcupsd/apcupsd.inc72
-rw-r--r--config/apcupsd/apcupsd.xml66
-rw-r--r--pkg_config.10.xml2
-rw-r--r--pkg_config.8.xml2
-rw-r--r--pkg_config.8.xml.amd642
5 files changed, 133 insertions, 11 deletions
diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc
index 9ebb263b..0a99982d 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_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.';
+ }
+
+ 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,52 @@ 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=<<<EOF
+ if ($emailnotification == "smtpbuiltin"){
+
+ 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)){
+ $smtpcc_cmd = "";
+ }else{
+ $smtpcc_cmd = "-c {$smtpcc}";
+ }
+ }
+ }
+
+ $pfSense_hostname = gethostname();
+
+ $apccontrol_script_file=<<<EOF
+#!/bin/sh
+
+HOSTNAME="{$pfSense_hostname}"
+MSG="{$apcstatus["{$apccontrol_script}"]}"
+#
+(
+ echo " "
+ echo "\$MSG"
+ echo " "
+ /usr/local/sbin/apcaccess status
+) | /usr/local/sbin/smtp -s "\$MSG" -h {$smtphost}:{$smtpport} -f {$smtpfrom} {$smtpcc_cmd} {$smtpto}
+exit 0
+
+EOF;
+ }else{
+ $apccontrol_script_file=<<<EOF
#!/bin/sh
/usr/local/bin/php -f /usr/local/pkg/apcupsd_mail.php {$apccontrol_script} > /dev/null
@@ -218,6 +285,7 @@ function apccontrol_scripts_install(){
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 bef6c330..364db8b8 100644
--- a/config/apcupsd/apcupsd.xml
+++ b/config/apcupsd/apcupsd.xml
@@ -40,7 +40,7 @@
<name>Apcupsd</name>
<title>Services: Apcupsd (General)</title>
<category>Monitoring</category>
- <version>0.3.4</version>
+ <version>0.3.5</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>
@@ -339,11 +339,65 @@ UPSTYPE DEVICE Description <br>
<type>listtopic</type>
</field>
<field>
- <fieldname>notification_info</fieldname>
- <type>info</type>
- <description>In order to receive e-mail notifications, you need to configure
- SMTP Email Notifications on Advanced/Notifications section, and also,
- install mailreport package.</description>
+ <fielddescr>E-mail notification</fielddescr>
+ <fieldname>emailnotification</fieldname>
+ <description><![CDATA[Choose how APCUpsd will send email notifications.<br>
+<br>
+<strong>phpMailer</strong> - 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.<br>
+This feature is currently broken on pfSense 2.2, for more info see pfSense forum:
+<a href="https://forum.pfsense.org/index.php?topic=89901.0">APCupsd package status for pfSense.</a><br>
+<br>
+<strong>SMTP built-in</strong> - A simple SMTP mail client for apcupsd.
+It does not have smtp authentication of any kind.
+<br>
+ ]]></description>
+ <type>select</type>
+ <default_value>phpmailer</default_value>
+ <options>
+ <option><name>phpMailer</name><value>phpmailer</value></option>
+ <option><name>SMTP built-in</name><value>smtpbuiltin</value></option>
+ </options>
+ </field>
+ <field>
+ <name>SMTP built-in</name>
+ <type>listtopic</type>
+ </field>
+ <field>
+ <fielddescr>SMTP Host</fielddescr>
+ <fieldname>smtphost</fieldname>
+ <description></description>
+ <type>input</type>
+ <size>20</size>
+ </field>
+ <field>
+ <fielddescr>SMTP Port</fielddescr>
+ <fieldname>smtpport</fieldname>
+ <description></description>
+ <type>input</type>
+ <size>5</size>
+ </field>
+ <field>
+ <fielddescr>From</fielddescr>
+ <fieldname>smtpfrom</fieldname>
+ <description></description>
+ <type>input</type>
+ <size>20</size>
+ </field>
+ <field>
+ <fielddescr>To</fielddescr>
+ <fieldname>smtpto</fieldname>
+ <description></description>
+ <type>input</type>
+ <size>20</size>
+ </field>
+ <field>
+ <fielddescr>Cc</fielddescr>
+ <fieldname>smtpcc</fieldname>
+ <description></description>
+ <type>input</type>
+ <size>20</size>
</field>
</fields>
<custom_php_install_command>php_install_apcupsd();</custom_php_install_command>
diff --git a/pkg_config.10.xml b/pkg_config.10.xml
index 6e35c82a..b40b0eda 100644
--- a/pkg_config.10.xml
+++ b/pkg_config.10.xml
@@ -1452,7 +1452,7 @@
<descr>Set of programs for controlling APC UPS.</descr>
<category>Services</category>
<config_file>https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml</config_file>
- <version>apcupsd-3.14.12_1 pkg v0.3.4</version>
+ <version>apcupsd-3.14.12_1 pkg v0.3.5</version>
<status>BETA</status>
<required_version>2.2</required_version>
<configurationfile>apcupsd.xml</configurationfile>
diff --git a/pkg_config.8.xml b/pkg_config.8.xml
index 5251bb19..5ce0ada2 100644
--- a/pkg_config.8.xml
+++ b/pkg_config.8.xml
@@ -1883,7 +1883,7 @@
<descr>Set of programs for controlling APC UPS.</descr>
<category>Services</category>
<config_file>https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml</config_file>
- <version>apcupsd-3.14.10_1 pkg v0.3.4</version>
+ <version>apcupsd-3.14.10_1 pkg v0.3.5</version>
<status>BETA</status>
<required_version>2.0</required_version>
<configurationfile>apcupsd.xml</configurationfile>
diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64
index ac0df460..dcc56d0c 100644
--- a/pkg_config.8.xml.amd64
+++ b/pkg_config.8.xml.amd64
@@ -1870,7 +1870,7 @@
<descr>Set of programs for controlling APC UPS.</descr>
<category>Services</category>
<config_file>https://packages.pfsense.org/packages/config/apcupsd/apcupsd.xml</config_file>
- <version>apcupsd-3.14.10_1 pkg v0.3.4</version>
+ <version>apcupsd-3.14.10_1 pkg v0.3.5</version>
<status>BETA</status>
<required_version>2.0</required_version>
<configurationfile>apcupsd.xml</configurationfile>