diff options
-rw-r--r-- | mirror.php | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -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)]; } } |