index : website | |
Archlinux32 website - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2019-06-06 16:13:37 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-06-06 16:13:37 +0200 |
commit | df3209e099e7d781e60a574a263a9f8e33f10ad8 (patch) | |
tree | 9d71f6504659fa8dd996c9237c72124120e5f2d2 | |
parent | dd342d1d9863834d9aba120b4a78d2ac959e33f7 (diff) |
-rw-r--r-- | pool.php | 44 |
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); |