# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See the ./COPYING file for more details.
// Configuration
$repos_arch_project = [ 'core', 'extra', 'staging', 'testing', 'gnome-unstable', 'kde-unstable' ];
$repos_arch_community = [ 'community', 'community-staging', 'community-testing',
'multilib', 'multilib-staging', 'multilib-testing' ];
$repos_para_project = [ 'libre', 'libre-testing',
'libre-multilib', 'libre-multilib-testing' ];
$repos_para_community = [ 'cross', 'java', 'kernels', 'nonprism', 'pcr' ];
// Automatic configuration
$asseturl = dirname($_SERVER["SCRIPT_NAME"]);
$assetdir = dirname($_SERVER["SCRIPT_FILENAME"]);
$root = $_SERVER["DOCUMENT_ROOT"];
$dirname = explode("?", $_SERVER["REQUEST_URI"], 2)[0];
////////////////////////////////////////////////////////////////////////////////
function normalizeN($filename) {
$parts = preg_split("|/+|", $filename, -1, PREG_SPLIT_NO_EMPTY);
$abs = substr($filename, 0, 1) === '/';
return array(($abs?'/':'').implode('/', $parts), count($parts));
}
function normalize($filename) {
list ($new_filename, $n) = normalizeN($filename);
return $new_filename;
}
function is_root($root, $dirname) {
$path = $root.'/'.$dirname;
return (normalize($path) === normalize($root));
}
function classify($root, $dirname, $filename) {
global $repos_arch_project, $repos_arch_community, $repos_para_project, $repos_para_community;
if ($filename === '.') { return [ 'dir' ]; }
if ($filename === '..') { return [ 'dir', 'parent' ]; }
list ($dirname, $parts) = normalizeN($dirname);
$dirpath = normalize($root.'/'.$dirname);
$filepath = normalize($dirpath.'/'.$filename);
$classes = array();
if ($parts == 0) {
// in the top-level
if (is_dir($filepath) && is_dir($filepath.'/os')) {
array_push($classes, 'repo');
if (in_array($filename, $repos_arch_project )) { array_push($classes, 'arch'); }
if (in_array($filename, $repos_para_project )) { array_push($classes, 'para'); }
if (in_array($filename, $repos_arch_community)) { array_push($classes, 'arch', 'community'); }
if (in_array($filename, $repos_para_community)) { array_push($classes, 'para', 'community'); }
if ($filename[0] === '~' ) { array_push($classes, 'para', 'community'); }
}
} elseif ($dirname == "pool" || $dirname == "sources") {
switch($filename) {
case "packages": array_push($classes, 'pool', 'arch' ); break;
case "community": array_push($classes, 'pool', 'arch', 'community'); break;
case "parabola": array_push($classes, 'pool', 'para' ); break;
}
}
if ($filename[0] === '.' || substr($filename, -1) === '~') { $classes[] = 'hidden'; }
if (is_link($filepath)) { $classes[] = 'link'; }
if (is_dir( $filepath)) { $classes[] = 'dir'; }
if (is_file($filepath)) { $classes[] = 'file'; }
if (preg_match("/\.pkg\.tar(\..z)?$/" , $filename) == 1) { $classes[] = 'pkg'; }
if (preg_match("/\.tar(\..z|\.bz2)?$/", $filename) == 1) { $classes[] = 'tar'; }
$classes[] = pathinfo($filename, PATHINFO_EXTENSION);
return $classes;
}
////////////////////////////////////////////////////////////////////////////////
if (!is_dir($root.'/'.$dirname)) {
if (is_file($root.'/'.$dirname)) {
header('Content-Type: text/plain'); // gross, but if Nginx is "properly" configured, this only happens when serving itself, which is text
readfile($root.'/'.$dirname);
} else {
require $assetdir.'/404.php';
}
exit(0);
}
////////////////////////////////////////////////////////////////////////////////
?>
Parabola GNU/Linux-libre - Index of
" />
Index of
";
if (is_link($filepath)) {
echo "".htmlentities($filename)." -> ".htmlentities(readlink($filepath))." | ";
} else {
echo "".htmlentities($filename)." | ";
}
if ($filename == '..') {
echo ' | | ';
} else {
echo "".date("Y-m-d H:i", filemtime($filepath))." | ";
if (is_dir($filepath)) {
echo "- | ";
} else {
echo "".filesize($filepath)." | ";
}
echo "\n";
}
}
}
?>