diff --git a/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php b/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php index c18eb7c1..02c33d47 100755 --- a/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php +++ b/source/nut/usr/local/emhttp/plugins/nut/include/nut_status.php @@ -1,6 +1,71 @@ ".shell_exec("/usr/bin/upsc ups").""; - echo $sStatus; +$state = [ + 'TRIM ONLINE' => 'Online (trim)', + 'BOOST ONLINE' => 'Online (boost)', + 'OL' => 'Online', + 'ONBATT' => 'On battery', + 'COMMLOST' => 'Lost communication', + 'NOBATT' => 'No battery detected' +]; + +$red = "class='red-text'"; +$green = "class='green-text'"; +$orange = "class='orange-text'"; +$status = array_fill(0,6,"-"); +$all = $_GET['all']=='true'; +$result = []; + +if (file_exists('/var/run/upsmon.pid')) { + exec('/usr/bin/upsc ups 2>/dev/null', $rows); + for ($i=0; $i$val" : "$val") : "Refreshing..."; + break; + case 'battery.charge': + $status[1] = strtok($val,' ')<=10 ? "$val" : "$val"; + break; + case 'battery.runtime': + $val = $val/60; + $status[2] = strtok($val,' ')<=5 ? "$val" : "$val"; + break; + case 'ups.realpower.nominal': + $power = strtok($val,' '); + $status[3] = $power==0 ? "$val" : "$val"; + break; + case 'ups.load': + $load = strtok($val,' '); + $status[5] = $load>=90 ? "$val" : "$val"; + break; + } + if ($all) { + if ($i%2==0) $result[] = ""; + $result[]= "$key$val"; + if ($i%2==1) $result[] = ""; + } + } + if ($all && count($rows)%2==1) $result[] = ""; + if ($power && $load) $status[4] = ($load>=90 ? "" : "").intval($power*$load/100)." Watts"; +} +if ($all && !$rows) $result[] = "No information available"; + +echo "".implode('', $status).""; +if ($all) echo "\n".implode('', $result); ?>