summaryrefslogtreecommitdiff
path: root/pool.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-06-06 16:13:37 +0200
committerErich Eckner <git@eckner.net>2019-06-06 16:13:37 +0200
commitdf3209e099e7d781e60a574a263a9f8e33f10ad8 (patch)
tree9d71f6504659fa8dd996c9237c72124120e5f2d2 /pool.php
parentdd342d1d9863834d9aba120b4a78d2ac959e33f7 (diff)
downloadarchweb32-df3209e099e7d781e60a574a263a9f8e33f10ad8.tar.xz
pool.php new for pool.mirror.archlinux32.org
Diffstat (limited to 'pool.php')
-rw-r--r--pool.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/pool.php b/pool.php
new file mode 100644
index 0000000..19c0b87
--- /dev/null
+++ b/pool.php
@@ -0,0 +1,44 @@
+<?php
+
+require_once "init.php";
+
+require_once BASE . "/lib/mysql.php";
+require_once BASE . "/lib/http.php";
+
+$cutoff = 24*60*60;
+
+if (array_key_exists('HTTPS',$_SERVER) && ($_SERVER['HTTPS']=='on'))
+ $protocol = 'https';
+else
+ $protocol = 'http';
+
+$result = mysql_run_query(
+ 'SELECT `mirror_statuses`.`url` FROM `mirror_statuses`' .
+ ' WHERE `mirror_statuses`.`active`' .
+ ' AND `mirror_statuses`.`start` > UNIX_TIMESTAMP(NOW())-' . $cutoff .
+ ' AND `mirror_statuses`.`protocol` = "' . $protocol . '"' .
+ ' GROUP BY `mirror_statuses`.`url`' .
+ ' ORDER BY SHA2(' .
+ 'CONCAT(' .
+ '`mirror_statuses`.`url`,' .
+ 'NOW(),' .
+ '"' . base64_encode(
+ $_SERVER['REMOTE_PORT'] . ' ' .
+ $_SERVER['REMOTE_ADDR']
+ ) . '"' .
+ '),' .
+ '256' .
+ ')' .
+ ' LIMIT 1'
+);
+
+$mirror = $result -> fetch_assoc();
+if (! array_key_exists('url',$mirror))
+ die_500('no mirror reachable');
+
+$request_uri = $_SERVER['REQUEST_URI'];
+
+if (substr($request_uri, 0, 1) == '/')
+ $request_uri = substr($request_uri, 1);
+
+redirect_temporarily($mirror['url'] . $request_uri);