$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = 'shares';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
$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);
$compute = unscript($_GET['compute']??'');
$path = unscript($_GET['path']??'');
$fill = unscript($_GET['fill']??'');
$display = [];
$display['scale'] = unscript($_GET['scale']??'');
$display['number'] = unscript($_GET['number']??'');
$display['raw'] = unscript($_GET['raw']??'');
$pools = implode(',',pools_filter(cache_filter($disks)));
if (!$shares) {
echo "
| "._('There are no exportable user shares')." |
";
exit;
}
// Natural sorting of share names
uksort($shares,'strnatcasecmp');
// 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 all user shares & check encryption
$crypto = false;
foreach ($shares as $name => $share) {
if ($compute=='yes') exec("webGui/scripts/share_size ".escapeshellarg($name)." ssz1 ".escapeshellarg($pools));
$crypto |= $share['luksStatus']>0;
}
// global shares include/exclude
$myDisks = array_filter(array_diff(array_keys($disks), explode(',',$var['shareUserExclude'])), 'globalInclude');
// Share size per disk
$ssz1 = [];
if ($fill)
foreach (glob("state/*.ssz1", GLOB_NOSORT) as $entry) $ssz1[basename($entry, ".ssz1")] = parse_ini_file($entry);
else
exec("rm -f /var/local/emhttp/*.ssz1");
// Build table
$row = 0;
foreach ($shares as $name => $share) {
$row++;
$color = $share['color'];
switch ($color) {
case 'green-on' : $orb = 'circle'; $color = 'green'; $help = _('All files protected'); break;
case 'yellow-on': $orb = 'warning'; $color = 'yellow'; $help = _('Some or all files unprotected'); break;
}
if ($crypto) switch ($share['luksStatus']) {
case 0: $luks = ""; break;
case 1: $luks = ""._('All files encrypted').""; break;
case 2: $luks = ""._('Some or all files unencrypted').""; break;
default: $luks = ""._('Unknown encryption state').""; break;
} else $luks = "";
echo "";
echo "| $help$luks".compress($name)." | ";
echo "{$share['comment']} | ";
echo "".user_share_settings($var['shareSMBEnabled'], $sec[$name])." | ";
echo "".user_share_settings($var['shareNFSEnabled'], $sec_nfs[$name])." | ";
$cmd="/webGui/scripts/share_size"."&arg1=".urlencode($name)."&arg2=ssz1&arg3=".urlencode($pools);
$cache = _(ucfirst($share['useCache'])).($share['useCache']!='no'?' : '.compress(my_disk($share['cachePool'],$display['raw'])):'');
if (array_key_exists($name, $ssz1)) {
echo "$cache | ";
echo "".my_scale($ssz1[$name]['disk.total']*1024, $unit)." $unit | ";
echo "".my_scale($share['free']*1024, $unit)." $unit | ";
echo " | ";
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*1024, $unit)." $unit | ";
echo "".my_scale($disks[$diskname]['fsFree']*1024, $unit)." $unit | ";
echo " | ";
echo "
";
}
} else {
echo "$cache | ";
echo ""._('Compute')."... | ";
echo "".my_scale($share['free']*1024, $unit)." $unit | ";
echo " | ";
echo "";
}
}
if ($row==0) {
echo "| "._('There are no exportable user shares')." |
";
}