summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-05-22 17:18:09 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-05-22 17:18:09 -0400
commit649ff4041359190e5390ede9c1a895bdf2fd2d58 (patch)
treec331b4ca575cf3a7e039aa9a2fb38c87d5a558c3
parent7a1b09444b845ddad2222e1a9f37e3fbd2f75366 (diff)
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.
-rw-r--r--mirror.php21
1 files 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)];
}
}