isFile() && $fileinfo->getFilename() !== '.DS_Store') { $hasFiles = true; break; } } /* Output 0 if files are found, 1 if no files are found */ die($hasFiles ? '0' : '1'); } else { /* Output 1 if the directory does not exist */ die('1'); } } /* Remove all '.DS_Store' files from a directory recursively and delete empty directories. */ if (isset($_POST['delete'])) { $nameToDelete = $_POST['delete']; $dirPath = "/mnt/user/{$nameToDelete}"; if (is_dir($dirPath)) { removeDSStoreFilesAndEmptyDirs($dirPath); } die("success"); } /* Function to remove '.DS_Store' files and empty directories from a share. */ function removeDSStoreFilesAndEmptyDirs($dir) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST ); foreach ($iterator as $file) { if ($file->isFile() && $file->getFilename() === '.DS_Store') { unlink($file->getRealPath()); } } /* Second pass to remove empty directories */ foreach ($iterator as $file) { if ($file->isDir() && !(new \FilesystemIterator($file->getRealPath()))->valid()) { rmdir($file->getRealPath()); } } } if (isset($_POST['cleanup'])) { $n = 0; // active shares $shares = array_map('strtolower',array_keys(parse_ini_file('state/shares.ini',true))); // stored shares foreach (glob("/boot/config/shares/*.cfg",GLOB_NOSORT) as $name) { if (!in_array(strtolower(basename($name,'.cfg')),$shares)) { $n++; if ($_POST['cleanup']==1) unlink($name); } } // return number of deleted files die((string)$n); } $compute = rawurldecode(_var($_POST,'compute')); $path = rawurldecode(_var($_POST,'path')); $all = _var($_POST,'all'); $shares = parse_ini_file('state/shares.ini',true); $disks = parse_ini_file('state/disks.ini',true); $var = parse_ini_file('state/var.ini'); $sec = parse_ini_file('state/sec.ini',true); $sec_nfs = parse_ini_file('state/sec_nfs.ini',true); /* Get the pools from the disks.ini. */ $pools_check = pools_filter(cache_filter($disks)); $pools = implode(',', $pools_check); // exit when no mountable array disks $nodisks = ""._('There are no mounted array or pool disks - cannot add shares')."."; if (!checkDisks($disks)) die($nodisks); // exit when no shares $noshares = ""._('There are no exportable user shares').""; if (!$shares) die($noshares); // GUI settings extract(parse_plugin_cfg('dynamix',true)); // Natural sorting of share names uksort($shares,'strnatcasecmp'); /* Function to test if any Mouned volumes exist. */ function checkDisks(&$disks) { $rc = false; foreach ($disks as $disk) { if ($disk['name']!=='flash' && _var($disk,'fsStatus',"")==='Mounted') { $rc = true; break; } } return $rc; } // Display export settings function user_share_settings($protocol,$share) { if (empty($share)) return; if ($protocol!='yes' || $share['export']=='-') return "-"; return ($share['export']=='e') ? _(ucfirst($share['security'])) : ''._(ucfirst($share['security'])).''; } function globalInclude($name) { global $var; return substr($name,0,4)!='disk' || !$var['shareUserInclude'] || strpos("{$var['shareUserInclude']},","$name,")!==false; } function shareInclude($name) { global $include; return !$include || substr($name,0,4)!='disk' || strpos("$include,", "$name,")!==false; } // Compute user shares & check encryption $crypto = false; foreach ($shares as $name => $share) { if ($all!=0 && (!$compute || $compute==$name)) exec("$docroot/webGui/scripts/share_size ".escapeshellarg($name)." ssz1 ".escapeshellarg($pools)); $crypto |= _var($share,'luksStatus',0)>0; } // global shares include/exclude $myDisks = array_filter(array_diff(array_keys($disks), explode(',',$var['shareUserExclude'])), 'globalInclude'); // Share size per disk $ssz1 = []; if ($all==0) { exec("rm -f /var/local/emhttp/*.ssz1"); } else { foreach (glob("state/*.ssz1",GLOB_NOSORT) as $entry) $ssz1[basename($entry,'.ssz1')] = parse_ini_file($entry); } /* Define constants for magic strings */ define('STATUS_GREEN_ON', 'green-on'); define('STATUS_YELLOW_ON', 'yellow-on'); define('LUKS_STATUS_UNKNOWN', 0); define('LUKS_STATUS_ENCRYPTED', 1); define('LUKS_STATUS_UNENCRYPTED', 2); // Build table $row = 0; /* Get the first pool if needed. */ $firstPool = $pools_check[0] ?? ""; foreach ($shares as $name => $share) { /* Correct a situation in previous Unraid versions where an array only share has a useCache defined. */ if ((!$poolsOnly) && ($share['useCache'] == "no")) { $share['cachePool'] = ""; } else if (($poolsOnly) && (!$share['cachePool'])) { $share['cachePool'] = $firstPool; } /* Is cachePool2 defined? If it is we need to show the cache pool 2 device name instead of 'Array'. */ if ($share['cachePool2']) { $array = compress(my_disk($share['cachePool2'],$display['raw'])); $indicator = ""; } else { $array = _('Array'); $indicator = ""; } /* Check that the share storage assignments are valid. */ if (($share['cachePool']) && (! in_array($share['cachePool'], $pools_check))) { $array = compress(my_disk($share['cachePool'],$display['raw'])); $indicator = ""; $share_valid = false; } else if (($share['cachePool2']) && (! in_array($share['cachePool2'], $pools_check))) { $array = compress(my_disk($share['cachePool2'],$display['raw'])); $indicator = ""; $share_valid = false; } else if (($poolsOnly) && (! $share['cachePool']) && (! $share['cachePool2'])) { $share_valid = false; } else { /* Is the share exclusive? */ $exclusive = _var($share, 'exclusive') == 'yes' ? " " : ""; $share_valid = true; } /* When there is no array, all pools are treated as 'only' cache. */ if (($poolsOnly) && (! $share['cachePool2'])) { $share['useCache'] = 'only'; } $row++; $color = $share['color'] ?? ''; $orb = ''; $help = ''; switch ($color) { case STATUS_GREEN_ON: $orb = 'circle'; $color = 'green'; $help = _('All files protected'); break; case STATUS_YELLOW_ON: $orb = 'warning'; $color = 'yellow'; $help = _('Some or all files unprotected'); break; default: /* Handle unexpected color values */ $orb = 'question'; $color = 'grey'; $help = _('Unknown protection status'); break; } $luks = ''; if ($crypto) { switch ($share['luksStatus'] ?? LUKS_STATUS_UNKNOWN) { case LUKS_STATUS_UNKNOWN: $luks = ""; break; case LUKS_STATUS_ENCRYPTED: $luks = ""._('All files encrypted').""; break; case LUKS_STATUS_UNENCRYPTED: $luks = ""._('Some or all files unencrypted').""; break; default: $luks = ""._('Unknown encryption state').""; break; } } echo ""; echo "$help$luks$name"; echo "", htmlspecialchars(_var($share,'comment')), ""; echo "", user_share_settings($var['shareSMBEnabled'], $sec[$name]), ""; echo "", user_share_settings($var['shareNFSEnabled'], $sec_nfs[$name]), ""; /* If the share pool or array is not valid, indicate that to the user. */ if (!$share_valid) { $cache = "".$indicator." ".$array.""._('This share is invalid').'; '. _('It references storage that does not exist').""; } else { switch ($share['useCache']) { case 'no': $cache = "".$indicator.$exclusive.$array."".sprintf(_('Primary storage %s'), $array).""; break; case 'yes': $cache = "".compress(my_disk($share['cachePool'], $display['raw']))." ".$indicator.$array.""._('Primary storage to Secondary storage').""; break; case 'prefer': $cache = "".compress(my_disk($share['cachePool'], $display['raw']))." ".$indicator.$array.""._('Secondary storage to Primary storage').""; break; case 'only': $cache = "$exclusive".my_disk($share['cachePool'], $display['raw'])."".sprintf(_('Primary storage %s'), $share['cachePool']).($exclusive ? ", "._('Exclusive access') : "").""; break; default: /* Handle unexpected useCache values */ $cache = "". $indicator . $array . ""._('Unknown cache usage').""; break; } } if (array_key_exists($name, $ssz1)) { echo "$cache"; echo "", my_scale($ssz1[$name]['disk.total'], $unit), " $unit"; echo "", my_scale($share['free'] * 1024, $unit), " $unit"; echo ""; foreach ($ssz1[$name] as $diskname => $disksize) { if ($diskname == 'disk.total') continue; $include = $share['include']; $inside = in_array($diskname, array_filter(array_diff($myDisks, explode(',', $share['exclude'])), 'shareInclude')); echo "" : "warning'>"); echo " ", _(my_disk($diskname, $display['raw']), 3), ""; echo "", ($inside ? "" : ""._('Share is outside the list of designated disks').""), ""; echo ""; echo ""; echo ""; echo "", my_scale($disksize, $unit), " $unit"; echo "", my_scale($disks[$diskname]['fsFree'] * 1024, $unit), " $unit"; echo ""; } } else { echo "$cache"; echo "", _('Compute'), "..."; echo "", my_scale($share['free'] * 1024, $unit), " $unit"; echo ""; } } if ($row==0) echo $noshares; ?>