diff options
-rw-r--r-- | en/downloads/get/index.php | 1 | ||||
-rw-r--r-- | lib/Downloads.php | 84 | ||||
-rw-r--r-- | mirrorlist/index.php | 52 |
3 files changed, 99 insertions, 38 deletions
diff --git a/en/downloads/get/index.php b/en/downloads/get/index.php index 4583b82f3..34826e7b9 100644 --- a/en/downloads/get/index.php +++ b/en/downloads/get/index.php @@ -34,6 +34,7 @@ */ require 'lib.php'; +require_once '../../../lib/mga_geoip.php'; // request $product = get('q'); diff --git a/lib/Downloads.php b/lib/Downloads.php index 9ea8ec756..85cff758b 100644 --- a/lib/Downloads.php +++ b/lib/Downloads.php @@ -129,6 +129,10 @@ class Downloads * Note that the mirrors list doesn't change with versions, for now; * it's a full or nothing list. * + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist + * * @return array */ public static function get_all_mirrors($prod = true, $documentation = false, $mirrorlist = false) @@ -205,9 +209,13 @@ class Downloads * - if it exists in the country otherwise * - on continent if it exists otherwise * - random mirror + * It can also prepare a list of mirrors for mirrorlist page * * @param string $country * @param string $continent + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist * * @return array */ @@ -216,31 +224,66 @@ class Downloads $mirs = self::get_all_mirrors($prod, $documentation, $mirrorlist); $continent = '_C:' . $continent; - $mirrors = array(); + $mirrors = array(); $fr_mirr_asist = array(); + $list_of_mirrs = array( + 'country' => array(), + 'continent_minus_country' => array(), + 'other_continents' => array() + ); foreach ($mirs as $curr_continent => $continent_mirrors) { - if (!is_null($continent) && $continent != $curr_continent) + if ($continent != $curr_continent) { + if ($mirrorlist) + { + foreach ($continent_mirrors as $mirror) { + $list_of_mirrs['other_continents'][] = $mirror['url']; + } + } continue; } foreach ($continent_mirrors as $mirror) { + if (strpos($mirror['url'], 'distrib-coffee.ipsl.jussieu.fr') !== false) + { + // exclude source server to drop it's DL load + continue; + } // keep assisting the french mirrors with german ones if ($mirror['country'] == 'DE') { $fr_mirr_asist[] = $mirror; } // only add german mirrors when french are on turn - // sorting of mirror db cache must be kept to work properly + // sorting of mirror db cache must be kept to work properly (DE before FR) if ($country == 'FR' && $mirror['country'] == 'FR' && count($fr_mirr_asist) > 0) { $mirrors[$continent] = $fr_mirr_asist; $fr_mirr_asist = array(); } - if ($mirror['country'] == $country) + if ($mirrorlist) { - $mirrors[$continent][] = $mirror; + if ($mirror['country'] == $country) + { + $list_of_mirrs['country'][] = $mirror['url']; + } + else + { + $list_of_mirrs['continent_minus_country'][] = $mirror['url']; + } + } + else + { + if ($mirror['country'] == $country) + { + $mirrors[$continent][] = $mirror; + } } } + if (count($mirrors) == 0) + { + // add all continent mirrors if country doesn't have any + $mirrors[$continent] = $continent_mirrors; + } } if (count($mirrors) > 0) { @@ -254,6 +297,19 @@ class Downloads $one_mirror = array_shift($mirs); $one_mirror['continent'] = $mirr_continent; + if ($mirrorlist) + { + shuffle($list_of_mirrs['country']); + shuffle($list_of_mirrs['continent_minus_country']); + shuffle($list_of_mirrs['other_continents']); + $resulting_mirrs = array_merge( + $list_of_mirrs['country'], + $list_of_mirrs['continent_minus_country'], + $list_of_mirrs['other_continents'] + ); + $one_mirror['mirrors_list'] = array_slice($resulting_mirrs, 0, 10); + } + return $one_mirror; } @@ -266,6 +322,10 @@ class Downloads * Setup session data about current visitor for downloads. * * @param boolean $force + * @param string $country + * @param boolean $prod + * @param boolean $documentation + * @param boolean $mirrorlist * * @return array * @@ -328,10 +388,14 @@ class Downloads $_SESSION['country'] = $country; $_SESSION['continent'] = $continent; } + if (!isset($continent)) + { + $continent = null; + } $mirror = $this->get_mirror($country, $continent, $prod, $documentation, $mirrorlist); $mirror['purl'] = parse_url($mirror['url']); - + // reassign country, as get_one_mirror() may have decided // to return a mirror from another country than the one // requested initially - @see get_one_mirror() @@ -351,7 +415,10 @@ class Downloads 'mirror' => $mirror ); } - // + if (!isset($mirror['mirrors_list'])) + { + $mirror['mirrors_list'] = array(); + } return array( 'arch' => $system['arch'], 'mirror_host' => $mirror['purl']['host'], @@ -360,7 +427,8 @@ class Downloads 'country' => $country, 'continent' => $continent, 'city' => $mirror['city'], - 'fuzzy_mirror' => $fuzzy_mirror + 'fuzzy_mirror' => $fuzzy_mirror, + 'mirrors_list' => $mirror['mirrors_list'], ); } } diff --git a/mirrorlist/index.php b/mirrorlist/index.php index 082b8ce3a..2960a107a 100644 --- a/mirrorlist/index.php +++ b/mirrorlist/index.php @@ -1,27 +1,19 @@ <?php - require realpath(__DIR__ . '/../lib/Downloads.php'); function get($s){ - return $string_var = (string) filter_input(INPUT_GET, $s, FILTER_SANITIZE_STRING); + return (string) filter_input(INPUT_GET, $s, FILTER_SANITIZE_STRING); } -//TODO function check($array){ -foreach ($array as $key => $v) { -$getvar = get("$key"); - -$list = implode(", ", $v); - if (in_array($getvar, $v)) { - //$out = array($key => $getvar); - }else{ - $out = "Error $key: $getvar - not in list - $list"; - return $out; - } + foreach ($array as $key => $v) { + $getvar = get("$key"); + if (!in_array($getvar, $v)) { + $out = "Error $key: $getvar - not in list - " . implode(", ", $v); + return $out; + } + } } -} - - $source = $debug = false; @@ -41,24 +33,24 @@ $arraycheck =array( ); if ($source){ - $link = "MIRROR/distrib/$release/SRPMS/media/$section/$repo/"; + $link = "MIRROR/distrib/$release/SRPMS/media/$section/$repo/"; }elseif ($debug){ - $link = "MIRROR/distrib/$release/$arch/media/debug/$section/$repo/"; + $link = "MIRROR/distrib/$release/$arch/media/debug/$section/$repo/"; }else{ - $link = "MIRROR/distrib/$release/$arch/media/$section/$repo/"; + $link = "MIRROR/distrib/$release/$arch/media/$section/$repo/"; } - if ($release && $arch && $section && $repo){ - - $out = check($arraycheck); - if (empty($out)){ - $wsd = new Downloads(); - $dl = $wsd->prepare_download(true, null); - $out= str_replace('MIRROR', $dl['mirror_url'], $link); - //print_r($out); - } + $out = check($arraycheck); + if (empty($out)){ + $wsd = new Downloads(); + $dl = $wsd->prepare_download(true, null, true, false, true); + foreach ($dl['mirrors_list'] as $one_mirror) { + $out .= str_replace('MIRROR', $one_mirror, $link) . "\n"; + } + } }else{ - $out = "Invalid options"; + $out = "Invalid options"; } -echo $out; +header('Content-Type: text/plain'); +echo "$out\n"; |