mirror of
https://github.com/unraid/webgui.git
synced 2026-04-29 06:19:30 -05:00
129 lines
4.7 KiB
PHP
Executable File
129 lines
4.7 KiB
PHP
Executable File
#!/usr/bin/php -q
|
|
<?PHP
|
|
/* Copyright 2005-2022, Lime Technology
|
|
* Copyright 2012-2022, 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,
|
|
* as published by the Free Software Foundation.
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*/
|
|
?>
|
|
<?
|
|
session_start();
|
|
$docroot = '/usr/local/emhttp';
|
|
$varroot = '/var/local/emhttp';
|
|
$log = '/boot/config/parity-checks.log';
|
|
$stamps = '/var/tmp/stamps.ini';
|
|
$resync = '/var/tmp/resync.ini';
|
|
$syncSz = '/var/tmp/syncSz.ini';
|
|
|
|
require_once "$docroot/webGui/include/Helpers.php";
|
|
require_once "$docroot/webGui/include/publish.php";
|
|
extract(parse_plugin_cfg('dynamix',true));
|
|
|
|
// add translations
|
|
$_SERVER['REQUEST_URI'] = 'main';
|
|
$_SESSION['locale'] = $display['locale'];
|
|
require_once "$docroot/webGui/include/Translations.php";
|
|
// remember current language
|
|
$locale_init = $locale;
|
|
|
|
// close session, it is not needed anymore
|
|
session_unset();
|
|
session_destroy();
|
|
|
|
function new_parity_log($log,$timestamp) {
|
|
if (file_exists($log)) {
|
|
$handle = fopen($log, 'r');
|
|
while (($line = fgets($handle))!==false) {if (substr_compare($line,$timestamp,0,strlen($timestamp))==0) break;}
|
|
fclose($handle);
|
|
}
|
|
return empty($line);
|
|
}
|
|
function my_clock($time) {
|
|
if (!$time) return _('less than a minute');
|
|
$days = floor($time/1440);
|
|
$hour = $time/60%24;
|
|
$mins = $time%60;
|
|
return plus($days,'day',($hour|$mins)==0).plus($hour,'hour',$mins==0).plus($mins,'minute',true);
|
|
}
|
|
function update_translation($locale) {
|
|
global $docroot,$language;
|
|
$language = [];
|
|
if ($locale) {
|
|
$text = "$docroot/languages/$locale/translations.txt";
|
|
if (file_exists($text)) {
|
|
$store = "$docroot/languages/$locale/translations.dot";
|
|
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
|
|
$language = unserialize(file_get_contents($store));
|
|
}
|
|
$text = "$docroot/languages/$locale/main.txt";
|
|
if (file_exists($text)) {
|
|
$store = "$docroot/languages/$locale/main.dot";
|
|
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
|
|
$language = array_merge($language,unserialize(file_get_contents($store)));
|
|
}
|
|
}
|
|
}
|
|
function create_file($file,$data) {
|
|
if (!file_exists($file)) file_put_contents($file,$data);
|
|
}
|
|
while (true) {
|
|
$var = (array)parse_ini_file("$varroot/var.ini");
|
|
// check for language changes
|
|
extract(parse_plugin_cfg('dynamix',true));
|
|
if ($display['locale'] != $locale_init) {
|
|
$locale_init = $display['locale'];
|
|
update_translation($locale_init);
|
|
}
|
|
$synced = file_exists($stamps) ? explode(',',file_get_contents($stamps)) : [];
|
|
$sbSynced = array_shift($synced) ?: $var['sbSynced'];
|
|
$data = [];
|
|
$spot = $var['mdResyncPos'];
|
|
if ($spot) {
|
|
$size = $var['mdResyncSize'];
|
|
$delta = $var['mdResyncDt'];
|
|
$bytes = $var['mdResyncDb'];
|
|
create_file($syncSz,$size);
|
|
create_file($resync,$var['mdResyncAction']);
|
|
$data[] = my_scale($size*1024,$unit,-1)." $unit";
|
|
$data[] = _(my_clock(floor((time()-$sbSynced)/60)),2).($delta ? '' : ' ('._('paused').')');
|
|
$data[] = my_scale($spot*1024,$unit)." $unit (".number_format($spot/($size/100+1),1,$display['number'][0],'')." %)";
|
|
$data[] = $delta ? my_scale($bytes*1024/$delta,$unit, 1)." $unit/sec" : '---';
|
|
$data[] = $bytes ? _(my_clock(round(((($delta*(($size-$spot)/($bytes/100+1)))/100)/60),0)),2) : _('Unknown');
|
|
$data[] = $var['sbSyncErrs'];
|
|
} elseif ($var['sbSynced'] && $var['sbSynced2']) {
|
|
$timestamp = date('Y',$var['sbSynced2']).' '.str_replace(['.0','.'],[' ',' '],date('M.d H:i:s',$var['sbSynced2']));
|
|
if (new_parity_log($log,$timestamp)) {
|
|
$idle = []; while (count($synced)>1) $idle[] = array_pop($synced)-array_pop($synced);
|
|
$duration = $var['sbSynced2']-$sbSynced;
|
|
$status = $var['sbSyncExit'];
|
|
$action = file_get_contents($resync);
|
|
$size = file_get_contents($syncSz);
|
|
$speed = $status==0 ? my_scale($size*1024/($duration-array_sum($idle)),$unit,1)." $unit/s" : 0;
|
|
$error = $var['sbSyncErrs'];
|
|
file_put_contents($log,"$timestamp|$duration|$speed|$status|$error|$action\n",FILE_APPEND);
|
|
}
|
|
array_map('unlink',array_filter([$stamps,$resync,$syncSz],'file_exists'));
|
|
}
|
|
switch ($var['fsState']) {
|
|
case 'Copying':
|
|
$fsState = $var['fsCopyPrcnt']."% "._('completed');
|
|
break;
|
|
case 'Clearing':
|
|
$fsState = $var['fsClearPrcnt']."% "._('completed');
|
|
break;
|
|
default:
|
|
$fsState = substr($var['fsState'],-3)!='ing' ? 'stop' : '';
|
|
break;
|
|
}
|
|
publish('parity', implode(';',$data));
|
|
publish('monitor', $spot);
|
|
publish('fsState', $fsState);
|
|
sleep(1);
|
|
}
|
|
?>
|