diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2019-10-27 20:40:05 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2019-10-27 20:40:05 +0100 |
commit | 1890f10c40472c3600b10a4d8c86edb3c9ae3bf3 (patch) | |
tree | 5220f65da403eab8fd1ed33fafb25a0dba5b3789 | |
parent | a4e890eac03cfeb782ce2133e9cec7fe90271873 (diff) | |
download | website-core-1890f10c40472c3600b10a4d8c86edb3c9ae3bf3.tar.gz website-core-1890f10c40472c3600b10a4d8c86edb3c9ae3bf3.zip |
Add a page to check and list active mirrors.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
-rw-r--r-- | mirrors.json | 22 | ||||
-rw-r--r-- | mirrorstatus.php | 120 |
2 files changed, 142 insertions, 0 deletions
diff --git a/mirrors.json b/mirrors.json new file mode 100644 index 0000000..635bfad --- /dev/null +++ b/mirrors.json @@ -0,0 +1,22 @@ +{ + "master": { + "descr": "Primary Redirector", + "url": "http://mirror.ppa.trinitydesktop.org/trinity/" + }, + "yosemite": { + "descr": "Mike Bird (Yosemite Network)", + "url": "http://tde-mirror.yosemite.net/trinity/" + }, + "kuiper": { + "descr": "UK Mirror Service (kuiper)", + "url": "http://kuiper.mirrorservice.org/sites/trinitydesktop.org/trinity/" + }, + "copernicus": { + "descr": "UK Mirror Service (copernicus)", + "url": "http://copernicus.mirrorservice.org/sites/trinitydesktop.org/trinity/" + }, + "fau": { + "descr": "Friedrich-Alexander Universität Erlangen-Nürnberg", + "url": "http://ftp.fau.de/trinity/" + } +} diff --git a/mirrorstatus.php b/mirrorstatus.php new file mode 100644 index 0000000..b248140 --- /dev/null +++ b/mirrorstatus.php @@ -0,0 +1,120 @@ +<?php + if(!isset($_GET['mr'])) + { + include("tde-head-and-foot.php"); + doHeader("Active TDE Mirrors", "Developlment", "TDE Team"); +?> + +<p>Please note that this list may change from time to time as mirrors are added and removed.</p> + +<table cellpadding="4"> +<?php + } + else + { + header('Content-Type: text/plain'); + } + + $mirrorsJson = file_get_contents("mirrors.json"); + $mirrors = json_decode($mirrorsJson, true); + + $statusType = array( + "active" => "green", + "inaccessible" => "red", + "outdated" => "orange", + "unknown" => "gray", + ); + + $redis = new Redis(); + $redis->connect('127.0.0.1', 6379, 2); + foreach( $mirrors as $mirrorName => $mirrorInfo ) + { + $savedResult = $redis->isConnected() ? $redis->get('mirrorStatus-'.$mirrorName) : false; + if($savedResult) + { + $mirrors[$mirrorName]['synctime'] = $savedResult; + } + else + { + $cs = curl_init(); + curl_setopt( $cs, CURLOPT_URL, $mirrorInfo['url'].'-synctime' ); + curl_setopt( $cs, CURLOPT_TIMEOUT, 3 ); + curl_setopt( $cs, CURLOPT_HEADER, true ); + curl_setopt( $cs, CURLOPT_FOLLOWLOCATION, true ); + curl_setopt( $cs, CURLOPT_RETURNTRANSFER, true ); + $ret = curl_exec( $cs ); + curl_close( $cs ); + if(!empty( $ret )) + { + if(!preg_match('#(^|\n)HTTP/1.1 200 OK#', $ret)) + { + $mirrors[$mirrorName]['synctime'] = '0'; + } + else + { + $mirrors[$mirrorName]['synctime'] = strtotime(preg_replace( "#.*\r\n#", '', $ret)); + } + } + else + { + $mirrors[$mirrorName]['synctime'] = '-1'; + } + if($redis->isConnected()) + { + $redis->setEx( 'mirrorStatus-'.$mirrorName, + $mirrors[$mirrorName]['synctime'] > 0 ? 1800 : 300, + $mirrors[$mirrorName]['synctime'] ); + } + } + } + + foreach( $mirrors as $mirrorName => $mirrorInfo ) + { + if( $mirrorInfo['synctime'] < 0 ) + { + $mirrorStatus = 'inaccessible'; + } + if( $mirrorInfo['synctime'] == 0 || + $mirrors['master']['synctime'] == 0 ) + { + $mirrorStatus = 'unknown'; + } + if( $mirrorInfo['synctime'] > 0 ) + { + $mirrorStatus = ( abs($mirrorInfo['synctime'] - + $mirrors['master']['synctime']) + > (60*60*30) /* 30 hours */ + ? 'outdated' : 'active' ); + } + if(!isset($_GET['mr'])) + { + if(isset($statusType[$mirrorStatus])) + { + $mirrorStatus = ("<font color=\"".$statusType[$mirrorStatus]."\">". + $mirrorStatus."</font>"); + } + echo( "<tr valign=\"top\">\n". + "<td><b>".$mirrorInfo['descr'].": </b>\n". + "<br/><a href=\"".$mirrorInfo['url']."\">".$mirrorInfo['url']."</a></td>\n". + "<td><b>".$mirrorStatus."</b></td>\n". + "</tr>\n"); + } + else + { + if($mirrorStatus == 'active') + { + echo( $mirrorInfo['url']."\n" ); + } + } + } + $redis->close(); + + if(!isset($_GET['mr'])) + { +?> +</table> + +<?php + doFooter(); + } +?> |