Menu="Share:1" Title="Share Settings" Tag="share-alt-square" --- $width = [123,300]; if ($name == "") { /* default values when adding new share. */ $share = [ "nameOrig" => "", "name" => "", "comment" => "", "allocator" => "highwater", "floor" => "", "splitLevel" => "", "include" => "", "exclude" => "", "useCache" => "", "cachePool" => "", "cachePool2" => "", "cow" => "auto" ]; } elseif (array_key_exists($name, $shares)) { /* edit existing share. */ $share = $shares[$name]; } else { /* handle share deleted case. */ echo "
"._('Share')." '".htmlspecialchars($name)."' "._('has been deleted').".
"; return; } /* If the configuration is pools only, then no array disks are available. */ $poolsOnly = ((int)$var['SYS_ARRAY_SLOTS'] <= 2) ? true : false; /* Remove subpools from the array of pools. */ $pools = array_filter($pools, function($pool) { return !isSubpool($pool); }); /* Check for non existent pool device. */ if ($share['cachePool'] && !in_array($share['cachePool'], $pools)) { $poolDefined = false; $share['useCache'] = $share['cachePool2'] ? "yes" : ($poolsOnly ? "no" : "yes"); } else { $share['useCache'] = $share['useCache'] ?: ($poolsOnly ? "only" : "no"); $poolDefined = true; } /* Check for pool 2 (or array) being defined. */ if ((($share['useCache'] == "yes") || ($share['useCache'] == "prefer")) && ($poolsOnly) && (!$share['cachePool2'])) { $poolDefined2 = false; $share['useCache'] = "yes"; } else if ($share['cachePool2']) { $poolDefined2 = in_array($share['cachePool2'], $pools); } else { $poolDefined2 = true; } $cachePoolCapitalized = ucfirst($share['cachePool']); $cachePoolCapitalized2 = $share['cachePool2'] ? ucfirst($share['cachePool2']) : _("Array"); function globalInclude($name) { global $var; return substr($name,0,4)=='disk' && (!$var['shareUserInclude'] || in_array($name,explode(',',$var['shareUserInclude']))); } function sanitize(&$val) { $data = explode('.',str_replace([' ',','],['','.'],$val)); $last = array_pop($data); $val = count($data) ? implode($data).".$last" : $last; } /** * Preset space calculation and formatting. * * @param float|string $val Value to calculate preset space for. * @return string|null Formatted space string or null. */ function presetSpace($val) { global $disks, $shares, $name, $pools, $display; /* Return if the value is invalid or NaN */ if (!$val || strcasecmp($val, 'NaN') == 0) return null; /* Sanitize the value */ sanitize($val); /* Prepare the largest array disk */ $large = []; foreach (data_filter($disks) as $disk) { $large[] = _var($disk, 'fsSize'); } /* Prepare the fsSize array for each pool */ foreach ($pools as $pool) { $fsSize[$pool] = _var($disks[$pool], 'fsSize', 0); } /* Get the maximum value from the large array, filtering out non-numeric values */ if (!empty($large)) { $fsSize[''] = max(array_filter($large, 'is_numeric')); } else { $fsSize[''] = $fsSize[$pool]; } /* Get the cache pool size */ $pool = _var($shares[$name], 'cachePool'); $size = _var($fsSize, $pool, 0); /* Calculate the size */ $size = $size > 0 ? round(100 * $val / $size, 1) : 0; /* Units for size formatting */ $units = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; $base = $val > 0 ? floor(log($val, 1000)) : 0; $formattedSize = round($val / pow(1000, $base), 1); $unit = _var($units, $base); /* Get number format settings */ [$dot, $comma] = str_split(_var($display, 'number', '.,')); /* Return the formatted size */ return $formattedSize > 0 ? number_format($formattedSize, $formattedSize - floor($formattedSize) ? 1 : 0, $dot, $comma) . ' ' . $unit : ''; } /** * Function to get enabled disks based on include and exclude rules. * * @global array $disks Array of disk names to check. * @global array $share Array containing include and exclude rules. * * @return array Array of keys for enabled disk names. */ function enabledDisks() { global $disks, $share; /* Prepare the resultant array */ $trueKeys = []; /* Process each disk in the array */ foreach ($disks as $key => $disk) { $include = true; /* Default to true */ /* Check the include field */ if (!empty($share['include'])) { $includedDisks = explode(',', $share['include']); if (!in_array($key, $includedDisks)) { $include = false; } } /* Check the exclude field */ if (!empty($share['exclude'])) { $excludedDisks = explode(',', $share['exclude']); if (in_array($key, $excludedDisks)) { $include = false; } } /* Add to trueKeys array if the disk should be included */ if ($include) { $trueKeys[] = $key; } } return $trueKeys; } function fsSize() { global $disks, $pools, $share; /* Initialize an array to hold filesystem sizes */ $fsSize = []; /* Initialize an array to hold sizes of enabled disks */ $small = []; /* Get a list of enabled disks */ $enabledDisks = enabledDisks(); /* Iterate over the filtered disk data */ foreach (data_filter($disks) as $key => $disk) { /* Check if the disk is in the list of enabled disks */ if (in_array($key, $enabledDisks)) { /* Add the filesystem size of the enabled disk to the array */ $small[] = _var($disk, 'fsSize'); } } /* Set the minimum filesystem size from the array of enabled disks */ if (!empty($small)) { $fsSize[''] = min(array_filter($small)); } else { $fsSize[''] = 0; } /* Iterate over the pool names and add their filesystem sizes */ foreach ($pools as $pool) { /* Set the filesystem size for each pool, defaulting to 0 if not set */ $fsSize[$pool] = _var($disks[$pool], 'fsSize', 0); } /* Return the filesystem sizes as a JSON encoded string */ return json_encode($fsSize); } function fsFree() { global $disks, $pools; /* Initialize an array to hold free filesystem space */ $fsFree = []; /* Initialize an array to hold free space of enabled disks */ $large = []; /* Get a list of enabled disks */ $enabledDisks = enabledDisks(); /* Iterate over the filtered disk data */ foreach (data_filter($disks) as $key => $disk) { /* Check if the disk is in the list of enabled disks */ if (in_array($key, $enabledDisks)) { /* Add the free filesystem space of the enabled disk to the array */ $large[] = _var($disk, 'fsFree'); } } /* Iterate over the pool names and add their free filesystem space */ foreach ($pools as $pool) { /* Set the free filesystem space for each pool, defaulting to 0 if not set */ $fsFree[$pool] = _var($disks[$pool], 'fsFree', 0); } /* Determine the free filesystem space based on the poolsOnly flag */ if (!empty($large)) { /* Set the maximum free filesystem space from the array of enabled disks */ $fsFree[''] = max(array_filter($large)); } else { /* Set the minimum free filesystem space from the pool array */ $fsFree[''] = min(array_filter($fsFree)); } /* Return the free filesystem space as a JSON encoded string */ return json_encode($fsFree); } function fsType() { global $disks,$pools; $fsType = []; foreach ($pools as $pool) { $fsType[] = '"'.$pool.'":"'.str_replace('luks:','',_var($disks[$pool],'fsType')).'"'; } return implode(',',$fsType); } function primary() { global $share; return $share['useCache']=='no' ? '' : $share['cachePool']; } function secondary() { global $share; $rc = in_array($share['useCache'],['no','only']) ? '0' : '1'; return $rc; } function direction() { global $share; return $share['useCache']=='prefer' ? '1' : '0'; } /* global shares include/exclude. */ $myDisks = array_filter(array_diff(array_keys(array_filter($disks,'my_disks')), explode(',',$var['shareUserExclude'])), 'globalInclude'); ?> :share_edit_global1_help: :share_edit_global2_help: