summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2014-12-04 00:23:56 +0000
committerLuke Shumaker <lukeshu@sbcglobal.net>2014-12-04 00:23:56 +0000
commit260c20d47aad928550874d92599da4a05efcbb2f (patch)
tree2b146e75f28489e88170c32ee97e744c3b8dba21
parenta2e6a54a311bdc9fba52f028d2ea41a653491f8a (diff)
clean up index
-rw-r--r--index.php56
1 files changed, 41 insertions, 15 deletions
diff --git a/index.php b/index.php
index 72c7333..2c06ca3 100644
--- a/index.php
+++ b/index.php
@@ -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)) {