mirror of
https://github.com/unraid/webgui.git
synced 2026-05-20 21:29:35 -05:00
@@ -3,8 +3,8 @@ Title="UPS Details"
|
||||
Tag="battery-3"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
* Copyright 2015, Dan Landon.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -17,13 +17,13 @@ Tag="battery-3"
|
||||
?>
|
||||
<script>
|
||||
function getUPSstatus() {
|
||||
$.get('/plugins/dynamix.apcupsd/include/UPSstatus.php',{all:'true'},function(data) {
|
||||
$.post('/plugins/dynamix.apcupsd/include/UPSstatus.php',{level:<?=$cfg['BATTERYLEVEL']?>,runtime:<?=$cfg['MINUTES']?>},function(data) {
|
||||
if (data) {
|
||||
data = data.split(/\n/);
|
||||
$('#ups_summary').html(data[0]);
|
||||
$('#ups_summary').html(data[0].replace(/Percent/g,'%').replace(/Watt(s|age)/g,'W').replace('Minutes',"_(minutes)_").replace('Volts','V'));
|
||||
$('#ups_status').html(data[1]);
|
||||
}
|
||||
setTimeout(getUPSstatus,15000);
|
||||
setTimeout(getUPSstatus,3000);
|
||||
});
|
||||
}
|
||||
$(getUPSstatus);
|
||||
|
||||
@@ -5,9 +5,9 @@ Icon="icon-ups"
|
||||
Tag="battery-3"
|
||||
---
|
||||
<?PHP
|
||||
/* Copyright 2005-2020, Lime Technology
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
* Copyright 2015, Dan Landon.
|
||||
* Copyright 2012-2020, Bergware International.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2,
|
||||
@@ -26,6 +26,7 @@ $cfg = parse_plugin_cfg($sName);
|
||||
<style>
|
||||
table.ups thead tr th{width:16.6%;padding-left:10px;}
|
||||
table.ups tbody tr td{padding-left:10px;font-weight:bold;}
|
||||
i.ups{margin-right:8px}
|
||||
</style>
|
||||
<script>
|
||||
function toggleCustomCable(form) {
|
||||
@@ -45,14 +46,14 @@ $(function() {
|
||||
});
|
||||
</script>
|
||||
<table class="tablesorter shift ups" <?if (!file_exists("/var/run/apcupsd.pid")):?>style="display:none"<?endif;?>>
|
||||
<thead><tr><th>_(UPS Status)_</th><th>_(Battery Charge)_</th><th>_(Runtime Left)_</th><th>_(Nominal Power)_</th><th>_(UPS Load)_</th><th>_(UPS Load)_ %</th></tr></thead>
|
||||
<thead><tr><th><i class='ups fa fa-plug'></i>_(UPS Status)_</th><th><i class='ups fa fa-battery'></i>_(Battery Charge)_</th><th><i class='ups fa fa-clock-o'></i>_(Runtime Left)_</th><th><i class='ups fa fa-bolt'></i>_(Nominal Power)_</th><th><i class='ups fa fa-bars'></i>_(UPS Load)_</th><th><i class='ups fa fa-ellipsis-h'></i>_(Output Voltage)_</th></tr></thead>
|
||||
<tbody id="ups_summary"><tr><td colspan="6"> </td></tr></tbody>
|
||||
</table>
|
||||
|
||||
<span style="float:right;margin-right:10px"><a href="http://apcupsd.org/manual/manual.html" target="_blank" title="_(APC UPS Daemon user manual)_"><i class="fa fa-file-text-o"></i> <u>_(Online Manual)_</u></a></span>
|
||||
<form markdown="1" name="apcupsd_settings" method="POST" action="/update.php" target="progressFrame">
|
||||
<input type="hidden" name="#file" value="<?=$sName?>/<?=$sName?>.cfg">
|
||||
<input type="hidden" name="#include" value="/plugins/<?=$sName?>/include/update.apcupsd.php">
|
||||
<span style="float:right;margin-right:10px"><a href="http://apcupsd.org/manual/manual.html" target="_blank" title="_(APC UPS Daemon user manual)_"><i class="fa fa-file-text-o"></i> <u>_(Online Manual)_</u></a></span>
|
||||
|
||||
_(Start APC UPS daemon)_:
|
||||
: <select name="SERVICE">
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
# Send system notify message from apcupsd
|
||||
#
|
||||
read MESSAGE
|
||||
/usr/local/emhttp/webGui/scripts/notify -l "/Settings/UPSsettings" -e "Unraid Server Alert" -s "UPS Alert" -d "$MESSAGE" -i "alert"
|
||||
[[ "$MESSAGE" == *restored* ]] && LEVEL=normal || LEVEL=alert
|
||||
/usr/local/emhttp/webGui/scripts/notify -l "/Settings/UPSsettings" -e "Unraid Server Alert" -s "UPS Alert" -d "$MESSAGE" -i $LEVEL
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2021, Lime Technology
|
||||
* Copyright 2012-2021, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
* Copyright 2015, Dan Landon.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -16,39 +16,43 @@ $docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
// add translations
|
||||
$_SERVER['REQUEST_URI'] = 'settings';
|
||||
require_once "$docroot/webGui/include/Translations.php";
|
||||
require_once "$docroot/webGui/include/Secure.php";
|
||||
|
||||
$state = [
|
||||
'TRIM ONLINE' => _('Online (trim)'),
|
||||
'BOOST ONLINE' => _('Online (boost)'),
|
||||
'ONLINE' => _('Online'),
|
||||
'SLAVE' => '('._('Slave').')',
|
||||
'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,"<td>-</td>");
|
||||
$all = unscript($_GET['all']??'')=='true';
|
||||
$result = [];
|
||||
$red = "class='red-text'";
|
||||
$green = "class='green-text'";
|
||||
$orange = "class='orange-text'";
|
||||
$status = array_fill(0,6,"<td>-</td>");
|
||||
$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<count($rows); $i++) {
|
||||
$row = array_map('trim', explode(':', $rows[$i], 2));
|
||||
$key = $row[0];
|
||||
$val = strtr($row[1], $state);
|
||||
[$key,$val] = array_map('trim', explode(':', $rows[$i], 2));
|
||||
switch ($key) {
|
||||
case 'STATUS':
|
||||
$status[0] = $val ? (stripos($val,'online')===false ? "<td $red>$val</td>" : "<td $green>$val</td>") : "<td $orange>"._('Refreshing')."...</td>";
|
||||
$var = strtr($val, $state);
|
||||
$status[0] = $var ? (stripos($var,'online')!==false ? "<td $green>$var</td>" : "<td $red>$var</td>") : "<td $orange>"._('Refreshing')."...</td>";
|
||||
break;
|
||||
case 'BCHARGE':
|
||||
$status[1] = strtok($val,' ')<=10 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
[$charge,$unit] = explode(' ', $val, 2);
|
||||
$charge = intval($charge);
|
||||
$status[1] = $charge>$level ? "<td $green>$charge $unit</td>" : "<td $red>$charge $unit</td>";
|
||||
break;
|
||||
case 'TIMELEFT':
|
||||
$status[2] = strtok($val,' ')<=5 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
[$left,$unit] = explode(' ', $val, 2);
|
||||
$left = intval($left);
|
||||
$status[2] = $left>$runtime ? "<td $green>$left $unit</td>" : "<td $red>$left $unit</td>";
|
||||
break;
|
||||
case 'NOMPOWER':
|
||||
$power = strtok($val,' ');
|
||||
@@ -56,20 +60,31 @@ if (file_exists("/var/run/apcupsd.pid")) {
|
||||
break;
|
||||
case 'LOADPCT':
|
||||
$load = strtok($val,' ');
|
||||
$status[5] = $load>=90 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
$status[4] = $val;
|
||||
break;
|
||||
case 'OUTPUTV':
|
||||
$output = strtok($val,' ');
|
||||
$status[5] = $val;
|
||||
break;
|
||||
case 'NOMINV':
|
||||
$volt = strtok($val,' ');
|
||||
$minv = $volt / 1.1; // +/- 10% tolerance
|
||||
$maxv = $volt * 1.1;
|
||||
break;
|
||||
case 'LINEFREQ':
|
||||
$freq = $val;
|
||||
break;
|
||||
}
|
||||
if ($all) {
|
||||
if ($i%2==0) $result[] = "<tr>";
|
||||
$result[]= "<td><strong>$key</strong></td><td>$val</td>";
|
||||
if ($i%2==1) $result[] = "</tr>";
|
||||
}
|
||||
if ($i%2==0) $result[] = "<tr>";
|
||||
$result[]= "<td><strong>$key</strong></td><td>$val</td>";
|
||||
if ($i%2==1) $result[] = "</tr>";
|
||||
}
|
||||
if ($all && count($rows)%2==1) $result[] = "<td></td><td></td></tr>";
|
||||
if ($power && $load) $status[4] = ($load>=90 ? "<td $red>" : "<td $green>").intval($power*$load/100)." "._('Watts')."</td>";
|
||||
if (count($rows)%2==1) $result[] = "<td></td><td></td></tr>";
|
||||
if ($power && isset($load)) $status[4] = ($load<90 ? "<td $green>" : "<td $red>").intval($power*$load/100)." W (".$status[4].")</td>";
|
||||
elseif (isset($load)) $status[4] = ($load<90 ? "<td $green>" : "<td $red>").$status[4]."</td>";
|
||||
$status[5] = $output ? (($output<$minv||$output>$maxv ? "<td $red>" : "<td $green>").$status[5].($freq ? " / $freq" : "")."</td>") : $status[5];
|
||||
}
|
||||
if ($all && !$rows) $result[] = "<tr><td colspan='4' style='text-align:center'>"._('No information available')."</td></tr>";
|
||||
if (!$rows) $result[] = "<tr><td colspan='4' style='text-align:center'>"._('No information available')."</td></tr>";
|
||||
|
||||
echo "<tr>".implode('', $status)."</tr>";
|
||||
if ($all) echo "\n".implode('', $result);
|
||||
echo "<tr>",implode($status),"</tr>\n",implode($result);
|
||||
?>
|
||||
|
||||
@@ -175,7 +175,7 @@ div[id$=chart]{margin-top:-12px;margin-bottom:-24px;padding:0}
|
||||
span.ctrl{float:right;margin-right:10px}
|
||||
span.outer{float:left}
|
||||
span.inner{width:<?=$themes1?153:140?>px}
|
||||
span.ups{width:200px;display:inline-block}
|
||||
span.ups{width:200px;display:inline-block;margin-bottom:4px}
|
||||
span.tx{width:75px;display:inline-block}
|
||||
span.busy,i.inactive{opacity:0.5}
|
||||
span#inbound{width:75px;display:inline-block}
|
||||
@@ -184,6 +184,7 @@ span#util{margin-left:20px}
|
||||
span[id^=cpu],span[id^=sys]{width:0}
|
||||
select#cpuline,select#netline{border:none;padding:0 12px 0 0}
|
||||
i.heat{margin-left:8px}
|
||||
i.ups{margin-right:8px}
|
||||
a.cpu_close,span.hand{cursor:pointer;z-index:1001}
|
||||
tr.hidden{display:none;height:0;lineheight:0}
|
||||
td.none{text-align:center;padding-top:12px}
|
||||
@@ -264,7 +265,7 @@ form[name=boot]{display:none}
|
||||
<thead sort='<?=++$N?>'><tr class='hidden'><td></td><td colspan='3'></td><td></td></tr></thead>
|
||||
<tbody sort='<?=$N?>' class='sortable'>
|
||||
<tr><td></td><td colspan='3' class='next'><i class='icon-cpu'></i><div class='section'>_(Processor)_<br>
|
||||
<span id='load'>_(Load)_: <span class='cpu'>0%</span></span><span id='cpu-temp'></span><br><br></div>
|
||||
<span id='load'><i class='ups fa fa-bars'></i>_(Load)_: <span class='cpu'>0%</span></span><span id='cpu-temp'></span><br><br></div>
|
||||
<i class='fa fa-fw chevron' id='cpu_view' onclick='toggleChevron("cpu_view",1)'></i>
|
||||
<a href='/Dashboard/Settings/CPUset' title="_(Go to CPU pinning settings)_"><i class='fa fa-fw fa-cog chevron'></i></a>
|
||||
</td><td></td></tr>
|
||||
@@ -368,15 +369,16 @@ foreach ($ports as $port) {
|
||||
<thead sort='<?=++$N?>'><tr class='hidden'><td></td><td colspan='3'></td><td></td></tr></thead>
|
||||
<tbody sort='<?=$N?>' class='sortable'>
|
||||
<tr><td></td><td colspan='3' class='next'><i class='icon-ups'></i><div class='section'>_(Power)_<br>
|
||||
<span>_(UPS Load)_: <span id='ups_loadpct'></span></span><br><br></div>
|
||||
<span><i class='ups fa fa-bars'></i>_(UPS Load)_: </span><span id='ups_loadpct'></span><br><br></div>
|
||||
<i class='fa fa-fw chevron' id='ups_view' onclick='toggleChevron("ups_view",0)'></i>
|
||||
<a href='/Dashboard/Settings/UPSsettings' title="_(Go to UPS settings)_"><i class='fa fa-fw fa-cog chevron'></i></a>
|
||||
</td><td></td></tr>
|
||||
<tr class='ups_view'><td></td><td colspan='3'>
|
||||
<span class='ups'>_(UPS status)_:</span><span id='ups_status'></span><br>
|
||||
<span class='ups'>_(Battery charge)_:</span><span id='ups_bcharge'></span><br>
|
||||
<span class='ups'>_(Runtime left)_:</span><span id='ups_timeleft'></span><br>
|
||||
<span class='ups'>_(Nominal power)_:</span><span id='ups_nompower'></span><br>
|
||||
<span class='ups'><i class='ups fa fa-fw fa-plug'></i>_(UPS status)_:</span><span id='ups_status'></span><br>
|
||||
<span class='ups'><i class='ups fa fa-fw fa-battery'></i>_(Battery charge)_:</span><span id='ups_bcharge'></span><br>
|
||||
<span class='ups'><i class='ups fa fa-fw fa-clock-o'></i>_(Runtime left)_:</span><span id='ups_timeleft'></span><br>
|
||||
<span class='ups'><i class='ups fa fa-fw fa-bolt'></i>_(Nominal power)_:</span><span id='ups_nompower'></span><br>
|
||||
<span class='ups'><i class='ups fa fa-fw fa-ellipsis-h'></i>_(Output voltage)_:</span><span id='ups_outputv'></span><br>
|
||||
</td><td></td></tr>
|
||||
</tbody>
|
||||
<?endif;?>
|
||||
@@ -1125,12 +1127,13 @@ dashboard.on('message',function(msg,meta) {
|
||||
<?if ($apcupsd):?>
|
||||
var apcups = new NchanSubscriber('/sub/apcups',{subscriber:'websocket'});
|
||||
apcups.on('message',function(d) {
|
||||
var data = d.replace(/<\/?tr>/g,'').replace(/<td/g,'<span').replace(/td>/g,'span>;').split(';');
|
||||
var data = d.split(';');
|
||||
$('#ups_status').html(data[0]);
|
||||
$('#ups_bcharge').html(data[1]);
|
||||
$('#ups_timeleft').html(data[2]);
|
||||
$('#ups_nompower').html(data[3]);
|
||||
$('#ups_loadpct').html(data[5].replace('Percent','%')+' - '+data[4]);
|
||||
$('#ups_bcharge').html(data[1].replace('Percent','%'));
|
||||
$('#ups_timeleft').html(data[2].replace('Minutes',"_(minutes)_"));
|
||||
$('#ups_nompower').html(data[3].replace('Watts','W'));
|
||||
$('#ups_loadpct').html(data[4].replace('Percent','%'));
|
||||
$('#ups_outputv').html(data[5].replace('Volts','V'));
|
||||
});
|
||||
<?endif;?>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/php -q
|
||||
<?PHP
|
||||
/* Copyright 2005-2021, Lime Technology
|
||||
* Copyright 2012-2021, Bergware International.
|
||||
/* Copyright 2005-2022, Lime Technology
|
||||
* Copyright 2012-2022, Bergware International.
|
||||
* Copyright 2015, Dan Landon.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -28,12 +28,13 @@ require_once "$docroot/webGui/include/Translations.php";
|
||||
$locale_init = $locale;
|
||||
|
||||
$state = [
|
||||
'TRIM ONLINE' => 'Online (trim)',
|
||||
'BOOST ONLINE' => 'Online (boost)',
|
||||
'ONLINE' => 'Online',
|
||||
'ONBATT' => 'On battery',
|
||||
'COMMLOST' => 'Lost communication',
|
||||
'NOBATT' => 'No battery detected'
|
||||
'TRIM ONLINE' => _('Online (trim)'),
|
||||
'BOOST ONLINE' => _('Online (boost)'),
|
||||
'ONLINE' => _('Online'),
|
||||
'SLAVE' => '('._('Slave').')',
|
||||
'ONBATT' => _('On battery'),
|
||||
'COMMLOST' => _('Lost communication'),
|
||||
'NOBATT' => _('No battery detected')
|
||||
];
|
||||
|
||||
$red = "class='red-text'";
|
||||
@@ -59,44 +60,64 @@ function update_translation($locale) {
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
$status = array_fill(0,6,"<td>-</td>");
|
||||
$power = $load = false;
|
||||
// check for language changes
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
if ($display['locale'] != $locale_init) {
|
||||
$locale_init = $display['locale'];
|
||||
update_translation($locale_init);
|
||||
}
|
||||
unset($status,$rows,$power,$load,$freq,$output);
|
||||
$status = array_fill(0,6,"<span>-</span>");
|
||||
if (file_exists("/var/run/apcupsd.pid")) {
|
||||
// get battery-level and runtime settings
|
||||
$cfg = parse_plugin_cfg('dynamix.apcupsd');
|
||||
$level = $cfg['BATTERYLEVEL'] ?: 10;
|
||||
$runtime = $cfg['MINUTES'] ?: 5;
|
||||
exec("/sbin/apcaccess 2>/dev/null", $rows);
|
||||
for ($i=0; $i<count($rows); $i++) {
|
||||
$row = array_map('trim', explode(':', $rows[$i], 2));
|
||||
$key = $row[0];
|
||||
$val = strtr($row[1], $state);
|
||||
foreach ($rows as $row) {
|
||||
[$key, $val] = array_map('trim', explode(':', $row, 2));
|
||||
switch ($key) {
|
||||
case 'STATUS':
|
||||
$status[0] = $val ? (stripos($val,'online')===false ? "<td $red>$val</td>" : "<td $green>$val</td>") : "<td $orange>"._('Refreshing')."...</td>";
|
||||
$val = strtr($val, $state);
|
||||
$status[0] = $val ? (stripos($val,'online')!==false ? "<span $green>$val</span>" : "<span $red>$val</span>") : "<span $orange>"._('Refreshing')."...</span>";
|
||||
break;
|
||||
case 'BCHARGE':
|
||||
$status[1] = strtok($val,' ')<=10 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
[$val,$unit] = explode(' ', $val, 2);
|
||||
$val = intval($val);
|
||||
$status[1] = strtok($val,' ')>$level ? "<span $green>$val $unit</span>" : "<span $red>$val $unit</span>";
|
||||
break;
|
||||
case 'TIMELEFT':
|
||||
$status[2] = strtok($val,' ')<=5 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
[$val,$unit] = explode(' ', $val, 2);
|
||||
$val = intval($val);
|
||||
$status[2] = $val>$runtime ? "<span $green>$val $unit</span>" : "<span $red>$val $unit</span>";
|
||||
break;
|
||||
case 'NOMPOWER':
|
||||
$power = strtok($val,' ');
|
||||
$status[3] = $power==0 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
$status[3] = $power==0 ? "<span $red>$val</span>" : "<span $green>$val</span>";
|
||||
break;
|
||||
case 'LOADPCT':
|
||||
$load = strtok($val,' ');
|
||||
$status[5] = $load>=90 ? "<td $red>$val</td>" : "<td $green>$val</td>";
|
||||
$status[4] = $val;
|
||||
break;
|
||||
case 'OUTPUTV':
|
||||
$output = strtok($val,' ');
|
||||
$status[5] = $val;
|
||||
break;
|
||||
case 'NOMINV':
|
||||
$volt = strtok($val,' ');
|
||||
$minv = $volt / 1.1; // +/- 10% tolerance
|
||||
$maxv = $volt * 1.1;
|
||||
break;
|
||||
case 'LINEFREQ':
|
||||
$freq = $val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($power && $load) $status[4] = ($load>=90 ? "<td $red>" : "<td $green>").intval($power*$load/100)." "._('Watts')."</td>";
|
||||
if ($power && isset($load)) $status[4] = ($load<90 ? "<span>" : "<span $red>").intval($power*$load/100)." W (".$status[4].")</span>";
|
||||
elseif (isset($load)) $status[4] = ($load<90 ? "<span>" : "<span $red>").$status[4]."</span>";
|
||||
$status[5] = $output ? (($output<$minv||$output>$maxv ? "<span $red>" : "<span $green>").$status[5].($freq ? " / $freq" : "")."</span>") : $status[5];
|
||||
}
|
||||
|
||||
publish('apcups',"<tr>".implode('', $status)."</tr>");
|
||||
sleep(5);
|
||||
publish('apcups',implode(';', $status));
|
||||
sleep(3);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user