diff --git a/emhttp/plugins/dynamix/ShareList.page b/emhttp/plugins/dynamix/ShareList.page index 22f068a4e..93332fa3a 100644 --- a/emhttp/plugins/dynamix/ShareList.page +++ b/emhttp/plugins/dynamix/ShareList.page @@ -16,20 +16,33 @@ Cond="_var($var,'fsState')!='Stopped' && _var($var,'shareUser')=='e'" */ ?> "._('There are no mountable array or pool disks - cannot add shares')."."; if (!checkDisks($disks)) die($nodisks); @@ -38,18 +45,28 @@ $nodisks = "valid() ? '0' : '1'); + $dirPath = "/mnt/user/{$_POST['scan']}"; + + /* Check if the directory exists. */ + if (!is_dir($dirPath)) { + die('1'); // Directory does not exist + } + + $iterator = new FilesystemIterator($dirPath); + $hasNonDSStoreFiles = false; + + /* Iterate over the directory contents. */ + foreach ($iterator as $fileinfo) { + if ($fileinfo->isFile() && $fileinfo->getFilename() !== '.DS_Store') { + $hasNonDSStoreFiles = true; + break; + } + } + + die($hasNonDSStoreFiles ? '0' : '1'); } + if (isset($_POST['cleanup'])) { $n = 0; // active shares @@ -46,6 +66,13 @@ $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); + +/* If the configuration is pools only, then no array disks are available. */ +$poolsOnly = ((int)$var['sbNumDisks'] == 2) ? true : false; + // exit when no mountable array disks $nodisks = ""._('There are no mountable array or pool disks - cannot add shares')."."; if (!checkDisks($disks)) die($nodisks); @@ -57,24 +84,31 @@ if (!$shares) die($noshares); // GUI settings extract(parse_plugin_cfg('dynamix',true)); -$pools_check = pools_filter(cache_filter($disks)); -$pools = implode(',', $pools_check); - // Natural sorting of share names uksort($shares,'strnatcasecmp'); -// Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device. +/* Function to filter out unwanted disks, check if any valid disks exist, and ignore disks with a blank device. */ function checkDisks($disks) { - foreach ($disks as $disk) { - // Check the disk type, fsStatus, and ensure the device is not blank. - if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && $disk['fsStatus'] !== "Unmountable: unsupported or no file system" && !empty($disk['device'])) { - // A valid disk with a non-blank device is found, return true. - return true; - } - } + global $pools, $poolsOnly; - // No valid disks found, return false. - return false; + $rc = false; + + if (!$poolsOnly) { + foreach ($disks as $disk) { + /* Check the disk type, fsStatus, and ensure the device is not blank. */ + if (!in_array($disk['name'], ['flash', 'parity', 'parity2']) && strpos($disk['fsStatus'], 'Unmountable') === false && !empty($disk['device'])) { + /* A valid disk with a non-blank device is found. */ + $rc = true; + + break; + } + } + } else { + /* See if there are any pools. */ + $rc = !empty($pools); + } + + return $rc; } // Display export settings