Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);