$docroot = $docroot ?? $_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp';
// add translations
$_SERVER['REQUEST_URI'] = '';
require_once "$docroot/webGui/include/Translations.php";
require_once "$docroot/webGui/include/Helpers.php";
function parent_link() {
global $dir,$path;
return ($dir && dirname($dir)!='/' && dirname($dir)!='/mnt' && dirname($dir)!='/mnt/user') ? "Parent Directory" : "";
}
function trim_slash($url){
return preg_replace('://+:','/',$url);
}
function my_devs(&$devs) {
global $disks;
$text = []; $i = 0;
foreach ($devs as $dev) {
switch ($disks[$dev]['luksState']) {
case 0: $text[$i] = ""._('Not encrypted').""; break;
case 1: $text[$i] = ""._('Encrypted and unlocked').""; break;
case 2: $text[$i] = ""._('Locked: missing encryption key').""; break;
case 3: $text[$i] = ""._('Locked: wrong encryption key').""; break;
default: $text[$i] = ""._('Locked: unknown error').""; break;
}
$text[$i++] .= compress($dev,8,0);
}
return implode(', ',$text);
}
extract(parse_plugin_cfg('dynamix',true));
$disks = parse_ini_file('state/disks.ini',true);
$dir = realpath(htmlspecialchars_decode(rawurldecode($_GET['dir'])));
$path = unscript($_GET['path']);
[$root,$main,$rest] = my_explode('/',mb_substr($dir,1),3);
$fix = $root=='mnt' ? ($main ?: '---') : ($root=='boot' ? _('flash') : '---');
$user = $root=='mnt' && in_array($main,['user','user0']);
$fmt = "%F {$display['time']}";
$dirs = $files = [];
$total = $i = 0;
if ($user) {
$tag = implode('|',array_merge(['disk'],pools_filter($disks)));
$set = explode(';',str_replace(',;',',',preg_replace("/($tag)/",';$1',exec("shopt -s dotglob; getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".escapeshellarg($dir)."/* 2>/dev/null"))));
}
$stat = popen("shopt -s dotglob; stat -L -c'%F|%n|%s|%Y' ".escapeshellarg($dir)."/* 2>/dev/null",'r');
while (($row = fgets($stat))!==false) {
$row .= $user ? "|{$set[++$i]}" : "|$fix";
if ($row[0]=='d') $dirs[] = $row; else $files[] = $row;
}
pclose($stat);
echo " ";
if ($link = parent_link()) echo ""._('Type')." "._('Name')." "._('Size')." "._('Last Modified')." "._('Location')."