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') 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 From 35ac75a626712a339b7c39cbfdffca2315f32c43 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 1 Aug 2015 21:48:31 +0200 Subject: nut - code style fixes --- config/nut/nut.xml | 80 ++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 44 deletions(-) (limited to 'config') diff --git a/config/nut/nut.xml b/config/nut/nut.xml index d1496a16..ca7ca956 100644 --- a/config/nut/nut.xml +++ b/config/nut/nut.xml @@ -2,51 +2,46 @@ - - + . - All rights reserved. - */ -/* ========================================================================== */ + nut.xml + part of pfSense (https://www.pfSense.org/) + Copyright (C) 2009-2015 ESF, LLC + All rights reserved. +*/ +/* ====================================================================================== */ /* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - POSSIBILITY OF SUCH DAMAGE. - */ -/* ========================================================================== */ - ]]> - - Describe your package here - Describe your package requirements here - Currently there are no FAQ items provided. + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +/* ====================================================================================== */ + ]]> + nut - 2.6.5_1 pkg 2.0.1 + 2.0.5 Services: NUT Change /status_nut.php @@ -75,13 +70,11 @@ - /usr/local/pkg/ - 0755 + /usr/local/pkg/ https://packages.pfsense.org/packages/config/nut/nut.inc - /usr/local/www/ - 0755 + /usr/local/www/ https://packages.pfsense.org/packages/config/nut/status_nut.php enabled @@ -187,8 +180,7 @@ <strong>Local UPS Model</strong> driver - If generic or cable specified in parenthesis you need - to select the appropriate option below. + If generic or cable specified in parenthesis you need to select the appropriate option below. select