From 5aae8ca26baf933ad189022899476056cc69a46c Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 1 Aug 2015 21:22:11 +0200 Subject: nut - code style fixes --- config/nut/status_nut.php | 104 ++++++++++++++++++++++++---------------------- 1 file changed, 54 insertions(+), 50 deletions(-) (limited to 'config/nut/status_nut.php') diff --git a/config/nut/status_nut.php b/config/nut/status_nut.php index 0bb1145c..64b11112 100644 --- a/config/nut/status_nut.php +++ b/config/nut/status_nut.php @@ -2,8 +2,8 @@ /* status_nut.php part of pfSense (https://www.pfsense.org/) - Copyright (C) 2007 Ryan Wagoner . + Copyright (C) 2015 ESF, LLC All rights reserved. Redistribution and use in source and binary forms, with or without @@ -29,13 +29,15 @@ */ require("guiconfig.inc"); - +global $nut_config; $nut_config = $config['installedpackages']['nut']['config'][0]; /* functions */ function secs2hms($secs) { - if ($secs<0) return false; + if ($secs < 0 ) { + return false; + } $m = (int)($secs / 60); $s = $secs % 60; $h = (int)($m / 60); $m = $m % 60; return "{$h}h {$m}m {$s}s"; @@ -50,25 +52,29 @@ function tblclose () { } function tblrow ($name, $value, $symbol = null) { - if(!$value) return; - - if($symbol == '°') + if (!$value) { + return; + } + if ($symbol == '°') { $value = sprintf("%.1f", $value); - - if($symbol == 'Hz') + } + if ($symbol == 'Hz') { $value = sprintf("%d", $value); + } print(<< - {$name} - {$value}{$symbol} + {$name} + {$value}{$symbol} EOD ."\n"); } function tblrowbar ($name, $value, $symbol, $red, $yellow, $green) { - if(!$value) return; + if (!$value) { + return; + } $value = sprintf("%.1f", $value); @@ -80,57 +86,54 @@ function tblrowbar ($name, $value, $symbol, $red, $yellow, $green) { sort($yellow); sort($green); - if($value >= $red[0] && $value <= ($red[0]+9)) { + if ($value >= $red[0] && $value <= ($red[0]+9)) { $color = 'black'; $bgcolor = 'red'; } - if($value >= ($red[0]+10) && $value <= $red[1]) { + if ($value >= ($red[0]+10) && $value <= $red[1]) { $color = 'white'; $bgcolor = 'red'; } - if($value >= $yellow[0] && $value <= $yellow[1]) { + if ($value >= $yellow[0] && $value <= $yellow[1]) { $color = 'black'; $bgcolor = 'yellow'; } - if($value >= $green[0] && $value <= ($green[0]+9)) { + if ($value >= $green[0] && $value <= ($green[0]+9)) { $color = 'black'; $bgcolor = 'green'; } - if($value >= ($green[0]+10) && $value <= $green[1]) { + if ($value >= ($green[0]+10) && $value <= $green[1]) { $color = 'white'; $bgcolor = 'green'; } print(<< - {$name} - -
-
-
{$value}{$symbol}
-
-
- + {$name} + +
+
+
{$value}{$symbol}
+
+
+ EOD ."\n"); } /* defaults to this page but if no settings are present, redirect to setup page */ -if(!$nut_config['monitor']) +if (!$nut_config['monitor']) { Header("Location: /pkg_edit.php?xml=nut.xml&id=0"); +} $pgtitle = "Status: NUT Status"; include("head.inc"); -/* put your custom HTML head content here */ -/* using some of the $pfSenseHead function calls */ -//$pfSenseHead->addMeta(""); -//echo $pfSenseHead->getHTML(); ?> -

+

@@ -143,32 +146,33 @@ include("head.inc"); ?> - + - + +
0) ? true : false; + $running = ((int)exec('/bin/pgrep upsmon | /usr/bin/wc -l') > 0) ? true : false; - if($nut_config['monitor'] == 'local') { + if ($nut_config['monitor'] == 'local') { tblrow('Monitoring:','Local UPS'); - $cmd = "upsc {$nut_config['name']}@localhost"; - } elseif($nut_config['monitor'] == 'remote') { + $cmd = "/usr/local/bin/upsc {$nut_config['name']}@localhost"; + } elseif ($nut_config['monitor'] == 'remote') { tblrow('Monitoring:','Remote UPS'); - $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; - } elseif($nut_config['monitor'] == 'snmp') { + $cmd = "/usr/local/bin/upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; + } elseif ($nut_config['monitor'] == 'snmp') { tblrow('Monitoring:','SNMP UPS'); - $cmd = "upsc {$nut_config['snmpname']}@localhost"; + $cmd = "/usr/local/bin/upsc {$nut_config['snmpname']}@localhost"; } - if($running) + if ($running) { $handle = popen($cmd, 'r'); - elseif($nut_config['monitor'] == 'snmp') + } elseif ($nut_config['monitor'] == 'snmp') { tblrow('ERROR:','NUT is enabled, however the service is not running! The SNMP UPS may be unreachable.'); - else + } else { tblrow('ERROR:','NUT is enabled, however the service is not running!'); + } - if($handle) { + if ($handle) { $read = fread($handle, 4096); pclose($handle); @@ -179,14 +183,17 @@ include("head.inc"); $ups[$line[0]] = trim($line[1]); } - if(count($lines) == 1) + if (count($lines) == 1) { tblrow('ERROR:', 'Data stale!'); + } tblrow('Model:', $ups['ups.model']); $status = explode(' ', $ups['ups.status']); foreach($status as $condition) { - if($disp_status) $disp_status .= ', '; + if ($disp_status) { + $disp_status .= ', '; + } switch ($condition) { case 'WAIT': $disp_status .= 'Waiting'; @@ -241,14 +248,11 @@ include("head.inc"); tblclose(); ?> -
-'); print_r($ups); print('');*/ -?>
+ -- cgit v1.2.3