From 649ff4041359190e5390ede9c1a895bdf2fd2d58 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 22 May 2016 17:18:09 -0400 Subject: mirror: fix stuff - use ctime, not mtime for checking if s lastsync is recent enough - allow a list of mirror status URLs. - exclude tier 0 mirrors from the possibilities - Add an X-Repomirror-Mirrors header for debugging. --- mirror.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mirror.php b/mirror.php index c8ad031..57b01cf 100644 --- a/mirror.php +++ b/mirror.php @@ -9,7 +9,9 @@ $_SERVER["SCRIPT_NAME"] = '/.fancyindex/mirror.php'; // Configuration $tier0_url = 'https://repo.parabola.nu'; -$mirrors_url = 'https://www.parabola.nu/mirrors/status/json'; +$mirrors_urls = [ 'https://www.parabola.nu/mirrors/status/tier/1/json' + //, 'https://www.parabola.nu/mirrors/status/tier/2/json' + ]; function should_force_tier0($filename) { return file_exists('/srv/repo/http/'.$filename) || (preg_match("/\.(db|files)(\.tar(\..z)?)?$/" , $filename) == 1); } @@ -33,16 +35,19 @@ if (!file_exists($root.'/'.$filename)) { } else { $mirror = $tier0_url; if (!should_force_tier0($filename)) { - $mtime = filemtime($root.'/'.$filename); - $json = json_decode(file_get_contents($mirrors_url), true); - // TODO: weight by geoip or something? + $ctime = filectime($root.'/'.$filename); + // TODO: weight by GeoIP or quality or something? $mirrors = array(); - foreach ($json['urls'] as $urldata) { - if (!in_array($urldata['protocol'], ['http', 'https', 'ftp'])) { continue; } - if (strtotime($urldata['last_sync']) < $mtime) { continue; } - array_push($mirrors, $urldata['url']); + foreach ($mirrors_urls as $mirrors_url) { + $json = json_decode(file_get_contents($mirrors_url), true); + foreach ($json['urls'] as $urldata) { + if (!in_array($urldata['protocol'], ['http', 'https', 'ftp'])) { continue; } + if (strtotime($urldata['last_sync']) < $ctime) { continue; } + $mirrors[] = $urldata['url']; + } } if (count($mirrors) > 0) { + header('X-Repomirror-Mirrors: '.implode(' ', $mirrors)); $mirror = $mirrors[array_rand($mirrors)]; } } -- cgit v1.2.3