diff --git a/plugins/dynamix/scripts/diagnostics b/plugins/dynamix/scripts/diagnostics index d8bff7157..f17a61b1f 100755 --- a/plugins/dynamix/scripts/diagnostics +++ b/plugins/dynamix/scripts/diagnostics @@ -45,10 +45,10 @@ function run($cmd, &$save=null) { return implode("\n",$save); } function shareDisks($share) { - return exec("shopt -s dotglob; getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".escapeshellarg("/usr/local/emhttp/mnt/user/$share")." 2>/dev/null") ?: ""; + return exec("shopt -s dotglob; getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".escapeshellarg("/mnt/user/$share")." 2>/dev/null") ?: ""; } function anonymize($text,$select) { - global $all, $customShares,$unraid_vars; + global $all,$customShares,$unraid_vars; if ($all) return $text; switch ($select) { case 1: @@ -56,7 +56,7 @@ function anonymize($text,$select) { $text = str_replace(end(explode("-",$unraid_vars['regGUID'])),"...",$text); $rows = explode("\n", $text); - $regex = "/\b((disk|cache|parity|cpu|eth|dev)[0-9]+)|(smart|flash|flashbackup|cache|parity|cpu$customShares)\b/"; + $regex = "/\b((disk|cache|parity|cpu|eth|dev)[0-9]+)|(smart|flash|flashbackup|cache|parity|cpu|$customShares)\b/"; foreach ($rows as &$row) { if (!preg_match($regex, $row)) { $row = preg_replace("/^(\s*\[\S).*(\S\])( => Array)$/","$1..$2$3",$row); @@ -289,18 +289,17 @@ if ($cli) { // don't anonymize system share names $vardomain = (array)@parse_ini_file('/boot/config/domain.cfg'); $vardocker = (array)@parse_ini_file('/boot/config/docker.cfg'); -$showshares = []; -$showshares[] = current(array_slice(explode('/',$vardomain['IMAGE_FILE']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardomain['DOMAINDIR']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardomain['MEDIADIR']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardomain['DISKDIR']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_IMAGE_FILE']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_APP_CONFIG_PATH']), 3, 1)).'.cfg'; -$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_HOME']), 3, 1)).'.cfg'; -foreach ($showshares as $show) { - $showme = str_replace(".cfg","",$show); - if ($showme) $customShares .= "|$showme"; -} +$showshares = $customShares = []; +$showshares[] = current(array_slice(explode('/',$vardomain['IMAGE_FILE']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardomain['DOMAINDIR']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardomain['MEDIADIR']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardomain['DISKDIR']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_IMAGE_FILE']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_APP_CONFIG_PATH']), 3, 1)); +$showshares[] = current(array_slice(explode('/',$vardocker['DOCKER_HOME']), 3, 1)); + +foreach ($showshares as $showme) if ($showme) $customShares[] = $showme; +$customShares = implode('|',$customShares); // create folder structure run("mkdir -p ".escapeshellarg("/$diag/system")." ".escapeshellarg("/$diag/config")." ".escapeshellarg("/$diag/logs")." ".escapeshellarg("/$diag/shares")." ".escapeshellarg("/$diag/smart")." ".escapeshellarg("/$diag/qemu")." ".escapeshellarg("/$diag/xml")); @@ -327,6 +326,7 @@ foreach (glob("$get/*.ini") as $file) { $cpuload = run("uptime")." Cores: ".run("nproc")."\r\n".(string)@file_get_contents("$get/cpuload.ini")."\r\n"; $diskload = (array)@file("$get/diskload.ini"); $disks = (array)@parse_ini_file("$get/disks.ini",true); +$pools = pools_filter($disks); $loadTxt = []; foreach ($diskload as $loadLine) { $load = explode('=',$loadLine); @@ -386,34 +386,27 @@ if (!$all) // copy share information (anonymize if applicable) $files = glob("/boot/config/shares/*.cfg"); +$shareDisk = []; foreach ($files as $file) { $dest = "/$diag/shares/".basename($file); - if (!in_array(basename($file),$showshares)) { - $dest = anonymize($dest,2); - } + $share = basename($file,'.cfg'); + if (!in_array($share,$showshares)) $dest = anonymize($dest,2); @copy($file, $dest); if (!$all) run("sed -ri 's/^(share(Comment|ReadList|WriteList)=\")[^\"]+/\\1.../' ".escapeshellarg($dest)." 2>/dev/null"); - $share = pathinfo(basename($file),PATHINFO_FILENAME); - $shareExists = explode(",",shareDisks($share)); - unset($exists); - foreach ($shareExists as $anon) { - if (!$all) { - if (!preg_match("/\b((disk)[0-9]+)|(cache)\b/", $anon)) { - $len = strlen($anon); - if ($len>2) { - $dash = str_repeat('-',$len-2); - $exists[] = substr($anon,0,1).$dash.substr($anon,-1); - } - } + $location = []; + foreach (explode(",",shareDisks($share)) as $name) { + if ($all || preg_match('/disk[0-9]+/',$name) || in_array($name,$pools)) { + $location[] = $name; } else { - $exists[] = $anon; + $len = strlen($name); + $location[] = $len>2 ? substr($name,0,1).str_repeat('-',$len-2).substr($name,-1) : $name; } } - $shareDisk .= $exists ? str_pad(pathinfo($dest,PATHINFO_FILENAME),34).str_pad(exec("cat ".escapeshellarg($file)." | grep shareUseCache"),22)." Exists on ".implode(", ",$exists)."\r\n" : ""; - $exists = $exists ?: ["no drives"]; - file_put_contents($dest,"# Share exists on ".implode(", ",$exists)."\r\n",FILE_APPEND); + $location = implode(", ",$location); + $shareDisk[] = str_pad(pathinfo($dest,PATHINFO_FILENAME),34).str_pad(exec("cat ".escapeshellarg($file)."|grep shareUseCache"),24).($location ? "Exists on $location\r\n" : "Does not exist\r\n"); + file_put_contents($dest,$location ? "# Share exists on $location\r\n" : "# Share does not exist\r\n",FILE_APPEND); } -file_put_contents("/$diag/shares/shareDisks.txt",$shareDisk); +file_put_contents("/$diag/shares/shareDisks.txt",implode($shareDisk)); // create default user shares information $shares = (array)@parse_ini_file("$get/shares.ini", true); @@ -475,7 +468,7 @@ foreach ($devices as $device) { } // create pool btrfs information -foreach (pools_filter($disks) as $pool) { +foreach ($pools as $pool) { if (strpos($disks[$pool]['fsType'],'btrfs')!==false) { run("echo 'Pool: $pool'|todos >>".escapeshellarg("/$diag/system/btrfs-usage.txt")); run("/sbin/btrfs filesystem usage -T /mnt/$pool 2>/dev/null|todos >>".escapeshellarg("/$diag/system/btrfs-usage.txt"));