# 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 = [ 'packages' => [ 'core', 'extra', 'staging', 'testing', 'gnome-unstable', 'kde-unstable' ], 'community' => [ 'community', 'multilib' ], 'parabola' => [ 'libre', 'libre-multilib', 'cross', 'java', 'kernels', 'nonprism', 'pcr' ], 'testing' => ['gnome-unstable', 'kde-unstable'] ]; // 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 = $filename[0] === '/'; return [ ($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 has_suffix($str, $suffix) { return substr($str, -strlen($suffix)) === $suffix; } function trim_suffix($str, $suffix) { return has_suffix($str, $suffix) ? substr($str, 0, -strlen($suffix)) : $str; } function s_is_type($mode, $mask) { return ($mode & 0170000/*:S_IFMT*/) === $mask; } // :__S_ISTYPE function stat_is_dir( $stat) { return s_is_type($stat['mode'], 0040000/*:S_IFDIR*/); } function stat_is_file($stat) { return s_is_type($stat['mode'], 0100000/*:S_IFREG*/); } function stat_is_link($stat) { return s_is_type($stat['mode'], 0120000/*:S_IFLNK*/); } function classify($root, $dirname, $filename) { global $repos; list ($dirname, $parts) = normalizeN($dirname); $filepath = $root.'/'.$dirname.'/'.$filename; $stat = lstat($filepath); if ($filename === '.' ) { return [ [ 'dir' ], $stat]; } if ($filename === '..') { return [ [ 'dir', 'parent' ], $stat]; } $classes = array(); if (stat_is_link($stat)) { $classes[] = 'link'; $lstat = $stat; $stat = stat($filepath); } if ($parts == 0) { // in the top-level if (stat_is_dir($stat) && is_dir($filepath.'/os')) { array_push($classes, 'repo'); foreach (array_keys($repos) as $category) { if (in_array($filename, $repos[$category])) { array_push($classes, $category); } if (in_array(trim_suffix($filename, "-staging"), $repos[$category])) { array_push($classes, $category); } if (in_array(trim_suffix($filename, "-testing"), $repos[$category])) { array_push($classes, $category); } } if (has_suffix($filename, "staging")) { array_push($classes, 'staging'); } if (has_suffix($filename, "testing")) { array_push($classes, 'testing'); } if ($filename[0] === '~') { array_push($classes, 'parabola'); } } } elseif ($dirname == "/pool" || $dirname == "/sources") { array_push($classes, 'pool', $filename); } if ($filename[0] === '.' || substr($filename, -1) === '~') { $classes[] = 'hidden'; } if (stat_is_dir( $stat)) { $classes[] = 'dir'; } if (stat_is_file($stat)) { $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); if (isset($lstat)) { $stat = $lstat; } return [ $classes, $stat ]; } //////////////////////////////////////////////////////////////////////////////// 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 <?php echo htmlentities($dirname); ?> " />

Index of

"; echo ""; if ($filename === '..') { echo ''; } else { echo ""; if (stat_is_dir($stat)) { echo ""; } else { echo ""; } } echo "\n"; } } ?>
"; echo "".htmlentities($filename).""; if (stat_is_link($stat)) { $target = readlink($root.'/'.$dirname.'/'.$filename); echo " -> ".htmlentities($target).""; } echo "".date("Y-m-d H:i", $stat['mtime'])."-".$stat['size']."