diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2014-12-04 00:23:56 +0000 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2014-12-04 00:23:56 +0000 |
commit | 260c20d47aad928550874d92599da4a05efcbb2f (patch) | |
tree | 2b146e75f28489e88170c32ee97e744c3b8dba21 | |
parent | a2e6a54a311bdc9fba52f028d2ea41a653491f8a (diff) |
clean up index
-rw-r--r-- | index.php | 56 |
1 files changed, 41 insertions, 15 deletions
@@ -1,4 +1,5 @@ <?php +// 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' ]; @@ -6,19 +7,18 @@ $repos_para_project = [ 'libre', 'libre-testing', 'libre-multilib', 'libre-multilib-testing' ]; $repos_para_community = [ 'cross', 'java', 'kernels', 'nonprism', 'pcr' ]; +// Automatic configuration $assetdir = dirname($_SERVER["SCRIPT_NAME"]); $root = $_SERVER["DOCUMENT_ROOT"]; -//$root = "/srv/http/repo/public/main"; $dirname = explode("?", $_SERVER["REQUEST_URI"], 2)[0]; -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 { - header("HTTP/1.0 404 Not Found"); - // This is the template used by Nginx internally; if you want something else, have Nginx intercept it. Separation of concerns. - ?><html> +//////////////////////////////////////////////////////////////////////////////// + +function show_404() { + // This is the template used by Nginx internally; + // if you want something else, have Nginx intercept it. + // Separation of concerns. + ?><html> <head><title>404 Not Found</title></head> <body bgcolor="white"> <center><h1>404 Not Found</h1></center> @@ -26,8 +26,18 @@ if (!is_dir($root.'/'.$dirname)) { </body> </html> <?php - } - exit(0); +} + +function is_root($root, $dirname) { + $path = $root.'/'.$dirname; + + $parts = preg_split("|/+|", $root, -1, PREG_SPLIT_NO_EMPTY); + $root = implode('/', $parts); + + $parts = preg_split("|/+|", $path, -1, PREG_SPLIT_NO_EMPTY); + $path = implode('/', $parts); + + return ($path === $root); } function classify($root, $dirname, $filename) { @@ -49,22 +59,37 @@ function classify($root, $dirname, $filename) { if ($filename[0] === '~' ) { array_push($classes, 'repo', 'para', 'community'); } } elseif ($dirname == "pool" || $dirname == "sources") { switch($filename) { - case "packages": array_push($classes, 'pool', 'arch'); break; + 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; + case "parabola": array_push($classes, 'pool', 'para' ); break; } } if ($filename[0] === '.' || substr($filename, -1) === '~') { $classes[] = 'hidden'; } if (is_link($root.'/'.$dirname.'/'.$filename)) { $classes[] = 'link'; } - if (is_dir($root.'/'.$dirname.'/'.$filename)) { $classes[] = 'dir'; } + if (is_dir( $root.'/'.$dirname.'/'.$filename)) { $classes[] = 'dir'; } if (is_file($root.'/'.$dirname.'/'.$filename)) { $classes[] = 'file'; } - if (preg_match("/\.pkg\.tar(\..z)?$/", $filename) == 1) { $classes[] = 'pkg'; } + 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 { + header("HTTP/1.0 404 Not Found"); + show_404(); + } + exit(0); +} + +//////////////////////////////////////////////////////////////////////////////// ?> <!DOCTYPE html> <html lang="en"> @@ -112,6 +137,7 @@ function classify($root, $dirname, $filename) { sort($filenames); foreach ($filenames as $filename) { if ($filename === '.') { continue; } + if ($filename === '..' && is_root($root,$dirname)) { continue; } $classes = classify($root, $dirname, $filename); echo "\t\t\t\t<tr class=\"".implode(' ', $classes)."\">"; if (is_link($root.'/'.$dirname.'/'.$filename)) { |