mirror of
https://github.com/unraid/webgui.git
synced 2026-04-29 22:39:20 -05:00
Merge from master
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2016, Lime Technology
|
||||
* Copyright 2012-2016, Bergware International.
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, 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,
|
||||
@@ -18,9 +18,8 @@ $path = $_POST['path'];
|
||||
$var = parse_ini_file('state/var.ini');
|
||||
$devs = parse_ini_file('state/devs.ini',true);
|
||||
$disks = parse_ini_file('state/disks.ini',true);
|
||||
$sum = ['count'=>0, 'temp'=>0, 'fsSize'=>0, 'fsUsed'=>0, 'fsFree'=>0, 'numReads'=>0, 'numWrites'=>0, 'numErrors'=>0];
|
||||
$new = '/var/tmp/diskio';
|
||||
$old = '/var/tmp/lastio';
|
||||
$diskio= parse_ini_file('state/diskload.ini');
|
||||
$sum = ['count'=>0, 'temp'=>0, 'fsSize'=>0, 'fsUsed'=>0, 'fsFree'=>0, 'ioReads'=>0, 'ioWrites'=>0, 'numReads'=>0, 'numWrites'=>0, 'numErrors'=>0];
|
||||
extract(parse_plugin_cfg('dynamix',true));
|
||||
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
@@ -113,29 +112,8 @@ function fs_info(&$disk) {
|
||||
echo "<td colspan='2'></td><td>{$disk['fsStatus']}</td><td></td>";
|
||||
echo "<td>".device_browse($disk)."</td>";
|
||||
}
|
||||
function disk_map(&$rows) {
|
||||
$map = [];
|
||||
foreach ($rows as $row) {
|
||||
$key = explode(' ',$row);
|
||||
$map[$key[0]] = $key[3].' '.$key[7];
|
||||
}
|
||||
$rows = $map;
|
||||
}
|
||||
function sectors(&$data,$i) {
|
||||
return $data ? explode(' ',$data)[$i] : 0;
|
||||
}
|
||||
function my_diskio($id,$i) {
|
||||
global $diskio, $lastio, $disks;
|
||||
if (empty($diskio) || empty($lastio)) return my_scale(0,$unit,1)." $unit/s";
|
||||
$time = max($diskio['time']-$lastio['time'],1);
|
||||
if ($id=='A' || $id=='P') {
|
||||
$type = $id=='A' ? '/Parity|Data/' : '/Cache/';
|
||||
$disksum = 0;
|
||||
foreach ($disks as $disk) if (preg_match($type,$disk['type'])) $disksum += sectors($diskio[$disk['device']],$i)-sectors($lastio[$disk['device']],$i);
|
||||
return my_scale($disksum*512/$time,$unit,1)." $unit/s";
|
||||
} else {
|
||||
return my_scale((sectors($diskio[$id],$i)-sectors($lastio[$id],$i))*512/$time,$unit,1)." $unit/s";
|
||||
}
|
||||
function my_diskio($data) {
|
||||
return my_scale($data,$unit,1)." $unit/s";
|
||||
}
|
||||
function array_offline(&$disk,$w) {
|
||||
$warning = $w ? '<span class="red-text"><em>ALL DATA ON THIS DISK WILL BE ERASED WHEN ARRAY IS STARTED</em></span>' : '';
|
||||
@@ -174,11 +152,14 @@ function array_offline(&$disk,$w) {
|
||||
echo "</tr>";
|
||||
}
|
||||
function array_online(&$disk) {
|
||||
global $sum;
|
||||
global $sum, $diskio;
|
||||
$data = explode(' ',$diskio[$disk['device']]);
|
||||
if (is_numeric($disk['temp'])) {
|
||||
$sum['count']++;
|
||||
$sum['temp'] += $disk['temp'];
|
||||
}
|
||||
$sum['ioReads'] += $data[0];
|
||||
$sum['ioWrites'] += $data[1];
|
||||
$sum['numReads'] += $disk['numReads'];
|
||||
$sum['numWrites'] += $disk['numWrites'];
|
||||
$sum['numErrors'] += $disk['numErrors'];
|
||||
@@ -208,8 +189,8 @@ function array_online(&$disk) {
|
||||
echo "<td>".device_info($disk)."</td>";
|
||||
echo "<td>".device_desc($disk)."</td>";
|
||||
echo "<td>".my_temp($disk['temp'])."</td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($disk['device'],0)."</span><span class='number'>".my_number($disk['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($disk['device'],1)."</span><span class='number'>".my_number($disk['numWrites'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[0])."</span><span class='number'>".my_number($disk['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[1])."</span><span class='number'>".my_number($disk['numWrites'])."</span></td>";
|
||||
echo "<td>".my_number($disk['numErrors'])."</td>";
|
||||
fs_info($disk);
|
||||
break;
|
||||
@@ -223,14 +204,14 @@ function my_clock($time) {
|
||||
$mins = $time%60;
|
||||
return plus($days,'day',($hour|$mins)==0).plus($hour,'hour',$mins==0).plus($mins,'minute',true);
|
||||
}
|
||||
function read_disk(&$device, $item) {
|
||||
function read_disk($dev, $part) {
|
||||
global $var;
|
||||
switch ($item) {
|
||||
switch ($part) {
|
||||
case 'color':
|
||||
return exec("hdparm -C ".escapeshellarg("/dev/$device")."|grep -Po active") ? 'blue-on' : 'blue-blink';
|
||||
return exec("hdparm -C ".escapeshellarg("/dev/$dev")."|grep -Po active") ? 'blue-on' : 'blue-blink';
|
||||
case 'temp':
|
||||
$smart = "/var/local/emhttp/smart/$device";
|
||||
if (!file_exists($smart) || (time()-filemtime($smart)>=$var['poll_attributes'])) exec("smartctl -n standby -A ".escapeshellarg("/dev/$device")." >".escapeshellarg($smart)." &");
|
||||
$smart = "/var/local/emhttp/smart/$dev";
|
||||
if (!file_exists($smart) || (time()-filemtime($smart)>=$var['poll_attributes'])) exec("smartctl -n standby -A ".escapeshellarg("/dev/$dev")." >".escapeshellarg($smart)." &");
|
||||
$temp = exec("awk '\$1==190||\$1==194{print \$10;exit}' $smart");
|
||||
return $temp ?: '*';
|
||||
}
|
||||
@@ -241,8 +222,8 @@ function show_totals($text) {
|
||||
echo "<td><img src='/webGui/images/sum.png' class='icon'>Total</td>";
|
||||
echo "<td>$text</td>";
|
||||
echo "<td>".($sum['count']>0 ? my_temp(round($sum['temp']/$sum['count'],1)) : '*')."</td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($text[0],0)."</span><span class='number'>".my_number($sum['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($text[0],1)."</span><span class='number'>".my_number($sum['numWrites'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($sum['ioReads'])."</span><span class='number'>".my_number($sum['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($sum['ioWrites'])."</span><span class='number'>".my_number($sum['numWrites'])."</span></td>";
|
||||
echo "<td>".my_number($sum['numErrors'])."</td>";
|
||||
echo "<td></td>";
|
||||
if (strstr($text,'Array') && ($var['startMode']=='Normal')) {
|
||||
@@ -295,21 +276,6 @@ function cache_slots() {
|
||||
$out .= "</select></form>";
|
||||
return $out;
|
||||
}
|
||||
$time = time();
|
||||
$last = @parse_ini_file($new);
|
||||
if ($_POST['diskio'] && $time-$last['time']>8) {
|
||||
@copy($new, $old);
|
||||
$lastio = $last;
|
||||
exec("grep -o '\(sd[a-z]*\|nvme[0-9]n1\) .*' /proc/diskstats",$diskio);
|
||||
disk_map($diskio);
|
||||
$diskio['time'] = $time;
|
||||
$keys = [];
|
||||
foreach ($diskio as $key => $data) $keys[] = "$key=$data";
|
||||
file_put_contents($new, implode("\n",$keys));
|
||||
} else {
|
||||
$lastio = @parse_ini_file($old);
|
||||
$diskio = $last;
|
||||
}
|
||||
switch ($_POST['device']) {
|
||||
case 'array':
|
||||
if ($var['fsState']=='Stopped') {
|
||||
@@ -325,13 +291,14 @@ case 'array':
|
||||
break;
|
||||
case 'flash':
|
||||
$disk = &$disks['flash'];
|
||||
$data = explode(' ',$diskio[$disk['device']]);
|
||||
$disk['fsUsed'] = $disk['fsSize']-$disk['fsFree'];
|
||||
echo "<tr>";
|
||||
echo "<td>".device_info($disk)."</td>";
|
||||
echo "<td>".device_desc($disk)."</td>";
|
||||
echo "<td>*</td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($disk['device'],0)."</span><span class='number'>".my_number($disk['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($disk['device'],1)."</span><span class='number'>".my_number($disk['numWrites'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[0])."</span><span class='number'>".my_number($disk['numReads'])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[1])."</span><span class='number'>".my_number($disk['numWrites'])."</span></td>";
|
||||
echo "<td>".my_number($disk['numErrors'])."</td>";
|
||||
fs_info($disk);
|
||||
echo "</tr>";
|
||||
@@ -346,19 +313,21 @@ case 'cache':
|
||||
}
|
||||
break;
|
||||
case 'open':
|
||||
foreach ($devs as $dev) {
|
||||
$dev['name'] = $dev['device'];
|
||||
$dev['type'] = 'New';
|
||||
$dev['color'] = read_disk($dev['device'],'color');
|
||||
$dev['temp'] = read_disk($dev['device'],'temp');
|
||||
foreach ($devs as $disk) {
|
||||
$dev = $disk['device'];
|
||||
$data = explode(' ',$diskio[$dev]);
|
||||
$disk['name'] = $dev;
|
||||
$disk['type'] = 'New';
|
||||
$disk['color'] = read_disk($dev,'color');
|
||||
$disk['temp'] = read_disk($dev,'temp');
|
||||
echo "<tr>";
|
||||
echo "<td>".device_info($dev)."</td>";
|
||||
echo "<td>".device_desc($dev)."</td>";
|
||||
echo "<td>".my_temp($dev['temp'])."</td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($dev['device'],0)."</span><span class='number'>-</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($dev['device'],1)."</span><span class='number'>-</span></td>";
|
||||
if (file_exists("/tmp/preclear_stat_{$dev['device']}")) {
|
||||
$text = exec("cut -d'|' -f3 /tmp/preclear_stat_{$dev['device']}|sed 's:\^n:\<br\>:g'");
|
||||
echo "<td>".device_info($disk)."</td>";
|
||||
echo "<td>".device_desc($disk)."</td>";
|
||||
echo "<td>".my_temp($disk['temp'])."</td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[0])."</span><span class='number'>".my_number($data[2])."</span></td>";
|
||||
echo "<td><span class='diskio'>".my_diskio($data[1])."</span><span class='number'>".my_number($data[3])."</span></td>";
|
||||
if (file_exists("/tmp/preclear_stat_$dev")) {
|
||||
$text = exec("cut -d'|' -f3 /tmp/preclear_stat_$dev|sed 's:\^n:\<br\>:g'");
|
||||
if (strpos($text,'Total time')===false) $text = 'Preclear in progress... '.$text;
|
||||
echo "<td colspan='6' style='text-align:right'><em>$text</em></td>";
|
||||
} else
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2016, Lime Technology
|
||||
* Copyright 2012-2016, Bergware International.
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, 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,
|
||||
@@ -20,8 +20,9 @@ foreach ($_POST as $field => $value) {
|
||||
$keys[$section][$key] = $value;
|
||||
}
|
||||
foreach ($keys as $section => $block) {
|
||||
$text .= "[$section]\n";
|
||||
foreach ($block as $key => $value) $text .= "$key=\"$value\"\n";
|
||||
$pairs = "";
|
||||
foreach ($block as $key => $value) if (strlen($value) && $value != -1) $pairs .= "$key=\"$value\"\n";
|
||||
if ($pairs) $text .= "[$section]\n".$pairs;
|
||||
}
|
||||
file_put_contents($_POST['#cfg'], $text);
|
||||
if ($text) file_put_contents($_POST['#cfg'], $text); else @unlink($_POST['#cfg']);
|
||||
?>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2016, Lime Technology
|
||||
* Copyright 2012-2016, Bergware International.
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, 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,
|
||||
@@ -20,4 +20,5 @@ $preselect = [['code' => 5, 'set' => true, 'text' => 'Reallocated sectors coun
|
||||
['code' => 198, 'set' => true, 'text' => 'Uncorrectable sector count']];
|
||||
|
||||
for ($x = 0; $x < count($preselect); $x++) if ($preselect[$x]['set']) $numbers[] = $preselect[$x]['code'];
|
||||
$numbers = implode('|',$numbers);
|
||||
?>
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2016, Lime Technology
|
||||
* Copyright 2012-2016, Bergware International.
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, 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,
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
$docroot = $docroot ?: @$_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
|
||||
$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?? '/usr/local/emhttp';
|
||||
|
||||
function normalize($text, $glue='_') {
|
||||
$words = explode($glue,$text);
|
||||
@@ -31,32 +31,40 @@ function spindownDelay($port) {
|
||||
if ($disk['device']==$port) { file_put_contents("/var/tmp/diskSpindownDelay.{$disk['idx']}", $disk['spindownDelay']); break; }
|
||||
}
|
||||
}
|
||||
function get(&$ref,$n,$d) {
|
||||
global $var;
|
||||
$val = $ref[$n] ?? -1; if ($val==-1) $val = $var[$n] ?? $d;
|
||||
return $val;
|
||||
}
|
||||
function exist(&$ref) {
|
||||
return isset($ref) && strlen($ref);
|
||||
}
|
||||
function append(&$ref, &$info) {
|
||||
if (isset($info)) $ref .= ($ref ? " " : "").$info;
|
||||
}
|
||||
$disks = []; $var = [];
|
||||
require_once "$docroot/webGui/include/CustomMerge.php";
|
||||
$name = isset($_POST['name']) ? $_POST['name'] : '';
|
||||
$port = isset($_POST['port']) ? $_POST['port'] : '';
|
||||
$name = $_POST['name'] ?? '';
|
||||
$port = $_POST['port'] ?? '';
|
||||
if ($name) {
|
||||
$disk = &$disks[$name];
|
||||
$type = isset($disk['smType']) ? $disk['smType'] : -1; if ($type==-1) $type = isset($var['smType']) ? $var['smType'] : '';
|
||||
$type = get($disk,'smType','');
|
||||
if ($type) {
|
||||
$ports = [];
|
||||
if (isset($disk['smDevice']) && strlen($disk['smDevice'])) $port = $disk['smDevice'];
|
||||
if (isset($disk['smPort1']) && strlen($disk['smPort1'])) $ports[] = $disk['smPort1'];
|
||||
if (isset($disk['smPort2']) && strlen($disk['smPort2'])) $ports[] = $disk['smPort2'];
|
||||
if (isset($disk['smPort3']) && strlen($disk['smPort3'])) $ports[] = $disk['smPort3'];
|
||||
if ($ports) {
|
||||
$glue = isset($disk['smGlue']) ? $disk['smGlue'] : ',';
|
||||
$type .= ','.implode($glue,$ports);
|
||||
}
|
||||
if (exist($disk['smDevice'])) $port = $disk['smDevice'];
|
||||
if (exist($disk['smPort1'])) $ports[] = $disk['smPort1'];
|
||||
if (exist($disk['smPort2'])) $ports[] = $disk['smPort2'];
|
||||
if (exist($disk['smPort3'])) $ports[] = $disk['smPort3'];
|
||||
if ($ports) $type .= ','.implode($disk['smGlue'] ?? ',',$ports);
|
||||
}
|
||||
}
|
||||
switch ($_POST['cmd']) {
|
||||
case "attributes":
|
||||
require_once "$docroot/webGui/include/Wrappers.php";
|
||||
require_once "$docroot/webGui/include/Preselect.php";
|
||||
$select = isset($disk['smSelect']) ? $disk['smSelect'] : -1; if ($select==-1) $select = isset($var['smSelect']) ? $var['smSelect'] : 0;
|
||||
$level = isset($disk['smLevel']) ? $disk['smLevel'] : -1; if ($level==-1) $level = isset($var['smLevel']) ? $var['smLevel'] : 1;
|
||||
$events = isset($disk['smEvents']) ? explode('|',$disk['smEvents']) : (isset($var['smEvents']) ? explode('|',$var['smEvents']) : $numbers);
|
||||
$select = get($disk,'smSelect',0);
|
||||
$level = get($disk,'smLevel',1);
|
||||
$events = explode('|',$disk['smEvents'] ?? $var['smEvents'] ?? $numbers);
|
||||
$temps = [190,194];
|
||||
$unraid = parse_plugin_cfg('dynamix',true);
|
||||
$max = $unraid['display']['max'];
|
||||
@@ -87,9 +95,9 @@ case "capabilities":
|
||||
if (!$line) continue;
|
||||
$line = preg_replace('/^_/','__',preg_replace(['/__+/','/_ +_/'],'_',str_replace([chr(9),')','('],'_',$line)));
|
||||
$info = array_map('trim', explode('_', preg_replace('/_( +)_ /','__',$line), 3));
|
||||
if (isset($info[0])) $row[0] .= ($row[0] ? " " : "").$info[0];
|
||||
if (isset($info[1])) $row[1] .= ($row[1] ? " " : "").$info[1];
|
||||
if (isset($info[2])) $row[2] .= ($row[2] ? " " : "").$info[2];
|
||||
append($row[0],$info[0]);
|
||||
append($row[1],$info[1]);
|
||||
append($row[2],$info[2]);
|
||||
if (substr($row[2],-1)=='.') {
|
||||
echo "<tr><td>${row[0]}</td><td>${row[1]}</td><td>${row[2]}</td></tr>";
|
||||
$row = ['','',''];
|
||||
@@ -116,7 +124,7 @@ case "identify":
|
||||
if ($empty) echo "<tr><td colspan='2' style='text-align:center;padding-top:12px'>Can not read identification</td></tr>";
|
||||
break;
|
||||
case "save":
|
||||
exec("smartctl -a $type ".escapeshellarg("/dev/$port")." >".escapeshellarg("{$_SERVER['DOCUMENT_ROOT']}/{$_POST['file']}"));
|
||||
exec("smartctl -a $type ".escapeshellarg("/dev/$port")." >".escapeshellarg("$docroot/{$_POST['file']}"));
|
||||
break;
|
||||
case "delete":
|
||||
if (strpos(realpath("/var/tmp/{$_POST['file']}"), "/var/tmp/") === 0) {
|
||||
@@ -137,7 +145,7 @@ case "stop":
|
||||
case "update":
|
||||
if (!exec("hdparm -C ".escapeshellarg("/dev/$port")."|grep -Pom1 'active|unknown'")) {
|
||||
$cmd = $_POST['type']=='New' ? "cmd=/webGui/scripts/hd_parm&arg1=up&arg2=$name" : "cmdSpinup=$name";
|
||||
echo "<a href='/update.htm?$cmd&csrf_token={$var['csrf_token']}' class='info' target='progressFrame'><input type='button' value='Spin Up'></a><span class='orange-text'><span class='big'>Unavailable - disk must be spun up</span></span>";
|
||||
echo "<a href='/update.htm?$cmd&csrf_token={$_POST['csrf']}' class='info' target='progressFrame'><input type='button' value='Spin Up'></a><span class='big orange-text'>Unavailable - disk must be spun up</span>";
|
||||
break;
|
||||
}
|
||||
$progress = exec("smartctl -c $type ".escapeshellarg("/dev/$port")."|grep -Pom1 '\d+%'");
|
||||
@@ -151,14 +159,14 @@ case "update":
|
||||
break;
|
||||
}
|
||||
if (strpos($result, "Completed without error")!==false) {
|
||||
echo "<span class='green-text'><span class='big'>$result</span></span>";
|
||||
echo "<span class='big green-text'>$result</span>";
|
||||
break;
|
||||
}
|
||||
if (strpos($result, "Aborted")!==false or strpos($result, "Interrupted")!==false) {
|
||||
echo "<span class='orange-text'><span class='big'>$result</span></span>";
|
||||
echo "<span class='big orange-text'>$result</span>";
|
||||
break;
|
||||
}
|
||||
echo "<span class='red-text'><span class='big'>Errors occurred - Check SMART report</span></span>";
|
||||
echo "<span class='big red-text'>Errors occurred - Check SMART report</span>";
|
||||
break;
|
||||
case "selftest":
|
||||
echo shell_exec("smartctl -l selftest $type ".escapeshellarg("/dev/$port")."|awk 'NR>5'");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?PHP
|
||||
/* Copyright 2005-2016, Lime Technology
|
||||
* Copyright 2012-2016, Bergware International.
|
||||
/* Copyright 2005-2017, Lime Technology
|
||||
* Copyright 2012-2017, 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,
|
||||
@@ -11,8 +11,16 @@
|
||||
*/
|
||||
?>
|
||||
<?
|
||||
if (isset($_POST['#default'])) {
|
||||
$text = '';
|
||||
if (!isset($_POST['#default'])) {
|
||||
$top = isset($_POST['#top']);
|
||||
foreach ($_POST as $key => $value) if ($key[0] != '#') {
|
||||
if (!strlen($value) || ($top && !$value) || $value == -1) {
|
||||
unset($_POST[$key]);
|
||||
if (isset($_POST['#section'])) unset($keys[$_POST['#section']][$key]); else unset($keys[$key]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$text = "";
|
||||
if (isset($_POST['#section'])) {
|
||||
unset($keys[$_POST['#section']]);
|
||||
foreach ($keys as $section => $block) {
|
||||
|
||||
Reference in New Issue
Block a user