aboutsummaryrefslogtreecommitdiffstats
path: root/config/apcupsd/apcupsd.inc
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2014-02-20 22:29:10 +0100
committerErmal Luçi <eri@pfsense.org>2014-02-20 22:29:10 +0100
commitdcbf50c67a193b828ef23454bfd0595011ea084f (patch)
tree636f288384f0d9fe60fb6e2897f337838a9e6869 /config/apcupsd/apcupsd.inc
parent0e1a16d5aec9663660478f7936fc2b954122550a (diff)
parent0bb5cb1d7b77b16b4c0ae9ab058ea2fc116dce58 (diff)
downloadpfsense-packages-dcbf50c67a193b828ef23454bfd0595011ea084f.tar.gz
pfsense-packages-dcbf50c67a193b828ef23454bfd0595011ea084f.tar.bz2
pfsense-packages-dcbf50c67a193b828ef23454bfd0595011ea084f.zip
Merge pull request #598 from dbaio/master
apcupsd - fix config and improve package
Diffstat (limited to 'config/apcupsd/apcupsd.inc')
-rw-r--r--config/apcupsd/apcupsd.inc34
1 files changed, 33 insertions, 1 deletions
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);
+ }
+
+}
+
?>
+