From 8c75b002bedbd391647d7ccb0070e5893d129e23 Mon Sep 17 00:00:00 2001 From: Ryan Wagoner Date: Fri, 16 Feb 2007 04:26:00 +0000 Subject: -add graphical percentage bars -wrap repetitive code into functions --- packages/nut/status_nut.php | 89 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 19 deletions(-) (limited to 'packages/nut/status_nut.php') diff --git a/packages/nut/status_nut.php b/packages/nut/status_nut.php index 8410406e..42d5979e 100644 --- a/packages/nut/status_nut.php +++ b/packages/nut/status_nut.php @@ -32,7 +32,56 @@ require("guiconfig.inc"); $nut_config = $config['installedpackages']['nut']['config'][0]; -/* Defaults to this page but if no settings are present, redirect to setup page */ +/* functions */ + +function tblrow ($name, $value) { + print(<< + {$name} + {$value} + +EOD + ."\n"); +} + +function tblrowbar ($name, $value, $red, $yellow, $green) { + $red = explode('-',$red); + $yellow = explode('-',$yellow); + $green = explode('-',$green); + + sort($red); + sort($yellow); + sort($green); + + if($value >= $red[0] && $value <= $red[1]) { + $color = 'white'; + $bgcolor = 'red'; + } + if($value >= $yellow[0] && $value <= $yellow[1]) { + $color = 'black'; + $bgcolor = 'yellow'; + } + if($value >= $green[0] && $value <= $green[1]) { + $color = 'white'; + $bgcolor = 'green'; + } + + print(<< + {$name} + +
+
+
{$value}%
+
+
+ + +EOD + ."\n"); +} + +/* defaults to this page but if no settings are present, redirect to setup page */ if(!$nut_config['monitor']) Header("Location: /pkg_edit.php?xml=nut.xml&id=0"); @@ -64,10 +113,10 @@ include("head.inc"); \n"); + tblrow('Monitoring:','Local UPS'); $handle = popen("upsc {$nut_config['name']}@localhost","r"); } elseif($nut_config['monitor'] == 'remote') { - print("\n"); + tblrow('Monitoring:','Remote UPS'); $handle = popen("upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}","r"); } @@ -82,38 +131,40 @@ include("head.inc"); $line = explode(':', $line); $ups[$line[0]] = trim($line[1]); } - - print("\n"); - print('\n"); - - print("\n"); - print("\n"); - print("\n"); - print("\n"); - print("\n"); - print("\n"); + tblrow('Status:',$disp_status); + + tblrowbar('Load:',$ups['ups.load'],'100-80','79-60','59-0'); + tblrowbar('Battery Charge:',$ups['battery.charge'],'0-29','30-79','80-100'); + tblrow('Battery Voltage:',$ups['battery.voltage'].'V'); + tblrow('Input Voltage:',$ups['input.voltage'].'V'); + tblrow('Output Voltage:',$ups['output.voltage'].'V'); + tblrow('Temperature:',$ups['ups.temperature'].'°'); } else { /* display error */ - print("\n"); + tblrow('ERROR:','Can\'t parse data from upsc!'); } ?>
Monitoring:Local UPS
Monitoring:Remote UPS
Model:{$ups['ups.model']}
Status:'); + tblrow('Model:',$ups['ups.model']); + $status = explode(' ',$ups['ups.status']); foreach($status as $condition) { switch ($condition) { case WAIT: - print('Waiting... '); + $disp_status .= 'Waiting... '; break; case OL: - print('On Line '); + $disp_status .= 'On Line '; + break; + case OB: + $disp_status .= 'On Battery '; break; case LB: - print('Battery Low '); + $disp_status .= 'Battery Low '; break; default: - print("{$condition} "); + $disp_status .= $condition.' '; break; } } - print("
Load:{$ups['ups.load']}%
Battery Charge:{$ups['battery.charge']}%
Battery Voltage:{$ups['battery.voltage']}
Input Voltage:{$ups['input.voltage']}V
Output Voltage:{$ups['output.voltage']}V
Temperature:{$ups['ups.temperature']}
ERROR:Can\'t parse data from upsc!
-- cgit v1.2.3