_('Online'), 'SLAVE' => '('._('slave').')', 'TRIM' => '('._('trim').')', 'BOOST' => '('._('boost').')', 'COMMLOST' => _('Lost communication'), 'ONBATT' => _('On battery'), 'NOBATT' => _('No battery detected'), 'LOWBATT' => _('Low on battery'), 'OVERLOAD' => _('UPS overloaded'), 'SHUTTING DOWN' => _('System goes down') ]; $red = "class='red-text'"; $green = "class='green-text'"; $orange = "class='orange-text'"; $status = array_fill(0,7,"-"); $result = []; $level = $_POST['level'] ?: 10; $runtime = $_POST['runtime'] ?: 5; if (file_exists("/var/run/apcupsd.pid")) { exec("/sbin/apcaccess 2>/dev/null", $rows); for ($i=0; $i$text" : "$text") : ""._('Refreshing')."..."; break; case 'BCHARGE': $charge = round(strtok($val,' ')); $status[2] = $charge>$level ? "$charge %" : "$charge %"; break; case 'TIMELEFT': $time = round(strtok($val,' ')); $unit = _('minutes'); $status[3] = $time>$runtime ? "$time $unit" : "$time $unit"; break; case 'NOMPOWER': $power = strtok($val,' '); $status[4] = $power>0 ? "$power W" : "$power W"; break; case 'LOADPCT': $load = strtok($val,' '); $status[5] = round($load)." %"; break; case 'OUTPUTV': $output = round(strtok($val,' ')); $status[6] = "$output V"; break; case 'NOMINV': $volt = strtok($val,' '); $minv = floor($volt / 1.1); // +/- 10% tolerance $maxv = ceil($volt * 1.1); break; case 'LINEFREQ': $freq = round(strtok($val,' ')); break; } if ($i%2==0) $result[] = ""; $result[]= "$key$val"; if ($i%2==1) $result[] = ""; } if (count($rows)%2==1) $result[] = ""; if ($power && isset($load)) $status[5] = ($load<90 ? "" : "").round($power*$load/100)." W (".$status[5].")"; elseif (isset($load)) $status[5] = ($load<90 ? "" : "").$status[5].""; $status[6] = $output ? ((!$volt || ($minv<$output && $output<$maxv) ? "" : "").$status[6].($freq ? " ~ $freq Hz" : "")."") : $status[6]; } if (!$rows) $result[] = ""._('No information available').""; echo "",implode($status),"\n",implode($result); ?>