0) {
$used = $arraysize ? 100-round(100*$arrayfree/$arraysize) : 0;
echo "{$used}%
";
} else {
echo "".($var['fsState']=='Started'?'Maintenance':'off-line')."
";
}
}
function usage_color(&$disk, $limit, $free) {
global $display;
if (_var($display,'text',0)==1 || intval(_var($display,'text',0)/10)==1) return '';
$critical = _var($disk,'critical')>=0 ? $disk['critical'] : (_var($display,'critical')>=0 ? $display['critical'] : 0);
$warning = _var($disk,'warning')>=0 ? $disk['warning'] : (_var($display,'warning')>=0 ? $display['warning'] : 0);
if (!$free) {
if ($critical>0 && $limit>=$critical) return 'redbar';
if ($warning>0 && $limit>=$warning) return 'orangebar';
return 'greenbar';
} else {
if ($critical>0 && $limit<=100-$critical) return 'redbar';
if ($warning>0 && $limit<=100-$warning) return 'orangebar';
return 'greenbar';
}
}
function my_check($time, $speed) {
if (!$time) return _('unavailable (no parity-check entries logged)');
$days = floor($time/86400);
$hmss = $time-$days*86400;
$hour = floor($hmss/3600);
$mins = floor($hmss/60)%60;
$secs = $hmss%60;
return plus($days,'day',($hour|$mins|$secs)==0).plus($hour,'hour',($mins|$secs)==0).plus($mins,'minute',$secs==0).plus($secs,'second',true).". "._('Average speed').": ".(is_numeric($speed) ? my_scale($speed,$unit,1)." $unit/s" : $speed);
}
function my_error($code) {
switch ($code) {
case -4:
return ""._('aborted')."";
default:
return "$code";
}
}
function mk_option($select, $value, $text, $extra="") {
return "";
}
function mk_option_check($name, $value, $text="") {
if ($text) {
$checked = in_array($value,explode(',',$name)) ? " selected" : "";
return "";
}
if (strpos($name,'disk')!==false) {
$checked = in_array($name,explode(',',$value)) ? " selected" : "";
return "";
}
}
function mk_option_luks($name, $value, $luks) {
if (strpos($name,'disk')!==false) {
$checked = in_array($name,explode(',',$value)) ? " selected" : "";
return "";
}
}
function day_count($time) {
global $var;
if (!$time) return;
$datetz = new DateTimeZone($var['timeZone']);
$date = new DateTime("now", $datetz);
$offset = $datetz->getOffset($date);
$now = new DateTime("@".intval((time()+$offset)/86400)*86400);
$last = new DateTime("@".intval(($time+$offset)/86400)*86400);
$days = date_diff($last,$now)->format('%a');
switch (true) {
case ($days<0):
return;
case ($days==0):
return " ("._('today').")";
case ($days==1):
return " ("._('yesterday').")";
case ($days<=31):
return " (".sprintf(_('%s days ago'),my_word($days)).")";
case ($days<=61):
return " (".sprintf(_('%s days ago'),$days).")";
case ($days>61):
return " (".sprintf(_('%s days ago'),$days).")";
}
}
function plus($val, $word, $last) {
return $val>0 ? (($val || $last) ? ($val.' '._($word.($val!=1?'s':'')).($last ?'':', ')) : '') : '';
}
function compress($name, $size=18, $end=6) {
return mb_strlen($name)<=$size ? $name : mb_substr($name,0,$size-($end?$end+3:0)).'...'.($end?mb_substr($name,-$end):'');
}
function escapestring($name) {
return "\"$name\"";
}
function tail($file, $rows=1) {
$file = new SplFileObject($file);
$file->seek(PHP_INT_MAX);
$file->seek($file->key()-$rows);
$echo = [];
while (!$file->eof()) {
$echo[] = $file->current();
$file->next();
}
return implode($echo);
}
function last_parity_log() {
$log = '/boot/config/parity-checks.log';
[$date,$duration,$speed,$status,$error,$action,$size] = file_exists($log) ? my_explode('|',tail($log),7) : array_fill(0,7,0);
if ($date) {
[$y,$m,$d,$t] = my_preg_split('/ +/',$date,4);
$date = strtotime("$d-$m-$y $t");
}
return [$date,$duration,$speed,$status,$error,$action,$size];
}
function urlencode_path($path) {
return str_replace("%2F", "/", urlencode($path));
}
function pgrep($process_name, $escape_arg=true) {
$pid = exec("pgrep ".($escape_arg?escapeshellarg($process_name):$process_name), $output, $retval);
return $retval==0 ? $pid : false;
}
function is_block($path) {
return (@filetype(realpath($path))=='block');
}
function autov($file,$ret=false) {
global $docroot;
$path = $docroot.$file;
clearstatcache(true, $path);
$time = file_exists($path) ? filemtime($path) : 'autov_fileDoesntExist';
$newFile = "$file?v=".$time;
if ($ret)
return $newFile;
else
echo $newFile;
}
function transpose_user_path($path) {
if (strpos($path,'/mnt/user/')===0 && file_exists($path)) {
$realdisk = trim(shell_exec("getfattr --absolute-names --only-values -n system.LOCATION ".escapeshellarg($path)." 2>/dev/null"));
if (!empty($realdisk))
$path = str_replace('/mnt/user/', "/mnt/$realdisk/", $path);
}
return $path;
}
// custom parse_ini_file/string functions to deal with '#' comment lines
function my_parse_ini_string($text, $sections=false, $scanner=INI_SCANNER_NORMAL) {
return parse_ini_string(preg_replace('/^#/m',';',$text),$sections,$scanner);
}
function my_parse_ini_file($file, $sections=false, $scanner=INI_SCANNER_NORMAL) {
return my_parse_ini_string(file_get_contents($file),$sections,$scanner);
}
function cpu_list() {
exec('cat /sys/devices/system/cpu/*/topology/thread_siblings_list|sort -nu', $cpus);
return $cpus;
}
function my_explode($split, $text, $count=2) {
return array_pad(explode($split,$text,$count),$count,'');
}
function my_preg_split($split, $text, $count=2) {
return array_pad(preg_split($split,$text,$count),$count,'');
}
function delete_file(...$file) {
array_map('unlink',array_filter($file,'file_exists'));
}
?>