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(-) (limited to 'config/apcupsd/apcupsd_status.php') 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.
"; + } + } ?>
+