diff options
author | filip <filip.komar@gmail.com> | 2020-09-24 19:21:12 +0200 |
---|---|---|
committer | filip <filip.komar@gmail.com> | 2020-09-24 19:21:12 +0200 |
commit | ffb96f67b017187927558afbe3cdffa7d3b558e6 (patch) | |
tree | 84a467b4c94a1f422873caf2e6fe423c65324565 | |
parent | c2287f71f371a8a7c1fee7ef77059d2bce58da62 (diff) | |
download | www-ffb96f67b017187927558afbe3cdffa7d3b558e6.tar www-ffb96f67b017187927558afbe3cdffa7d3b558e6.tar.gz www-ffb96f67b017187927558afbe3cdffa7d3b558e6.tar.bz2 www-ffb96f67b017187927558afbe3cdffa7d3b558e6.tar.xz www-ffb96f67b017187927558afbe3cdffa7d3b558e6.zip |
automatic DL link is now https only
-rw-r--r-- | en/downloads/get/index.php | 2 | ||||
-rw-r--r-- | en/downloads/get/lib.php | 4 | ||||
-rw-r--r-- | lib/Downloads.php | 147 |
3 files changed, 106 insertions, 47 deletions
diff --git a/en/downloads/get/index.php b/en/downloads/get/index.php index add253c0f..21e0fb782 100644 --- a/en/downloads/get/index.php +++ b/en/downloads/get/index.php @@ -83,7 +83,7 @@ try { $product['file'] = $release . '-' . $type . '-' . $lang . '.' . $extension; $product['name'] = $product['file']; } - $all_mirrors = get_mirrors_for($product['file'], 'en', get('country'), true, $documentation); + $all_mirrors = get_mirrors_for($product['file'], 'en', get('country'), true, $documentation, true); $one_mirror = $all_mirrors[0]; $alt_mirrors = $all_mirrors[1]; $download_tmpl = get_download_link($product, $torrent); diff --git a/en/downloads/get/lib.php b/en/downloads/get/lib.php index 79374d2af..40a2cb238 100644 --- a/en/downloads/get/lib.php +++ b/en/downloads/get/lib.php @@ -172,13 +172,13 @@ function get_info_for_product($product, $def_file = null) * speed * link */ -function get_mirrors_for($file, $locale = null, $country = null, $prod = true, $documentation = false) +function get_mirrors_for($file, $locale = null, $country = null, $prod = true, $documentation = false, $https_only = false) { //include '../../../lib/Downloads.php'; $mirrors = Downloads::get_all_mirrors($prod, $documentation); $wsd = new Downloads(); - $one = $wsd->prepare_download(true, $country, $prod, $documentation); + $one = $wsd->prepare_download(true, $country, $prod, $documentation, false, $https_only); return array($one, $mirrors); } diff --git a/lib/Downloads.php b/lib/Downloads.php index a20070c1d..12535c58b 100644 --- a/lib/Downloads.php +++ b/lib/Downloads.php @@ -285,7 +285,7 @@ class Downloads * * @return array */ - function get_mirror($country, $continent = null, $prod = true, $documentation = false, $mirrorlist = false) + function get_mirror($country, $continent = null, $prod = true, $documentation = false, $mirrorlist = false, $https_only = false) { $mirs = self::get_all_mirrors($prod, $documentation, $mirrorlist); $continent = '_C:' . $continent; @@ -299,75 +299,134 @@ class Downloads ); $hostnames = array(); $list_of_mirrs['country_alternate_protocol'] = array(); + $continent_https_only = array(); + $other_continents_https_only = array(); foreach ($mirs as $curr_continent => $continent_mirrors) { - if ($continent != $curr_continent) - { - if ($mirrorlist) + foreach ($continent_mirrors as $mirror) { + if ($continent != $curr_continent) { - foreach ($continent_mirrors as $mirror) { + if ($mirrorlist) + { $list_of_mirrs['other_continents'][] = $mirror['url']; } + elseif (true === $https_only) + { + $pu = parse_url($mirror['url']); + if ('https' == $pu['scheme']) + { + $other_continents_https_only[$curr_continent][] = $mirror; + } + } } - 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 (DE before FR) - if ($country == 'FR' && $mirror['country'] == 'FR' && count($fr_mirr_asist) > 0) - { - $mirrors[$continent] = $fr_mirr_asist; - $fr_mirr_asist = array(); - } - if ($mirrorlist) + else { - $pu = parse_url($mirror['url']); - if (in_array($pu['host'], $hostnames)) { - $list_of_mirrs['country_alternate_protocol'][] = $mirror['url']; + 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 ($country == 'FR' && $mirror['country'] == 'DE') + { + $pu = parse_url($mirror['url']); + if ('https' == $pu['scheme']) { + $fr_mirr_asist[] = $mirror; + } + } + // only add german mirrors when french are on turn + // 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 ($mirrorlist) + { + $pu = parse_url($mirror['url']); + if (in_array($pu['host'], $hostnames)) + { + $list_of_mirrs['country_alternate_protocol'][] = $mirror['url']; + } + else + { + $hostnames[] = $pu['host']; + if ($mirror['country'] == $country) + { + $list_of_mirrs['country'][] = $mirror['url']; + } + else + { + $list_of_mirrs['continent_minus_country'][] = $mirror['url']; + } + } } else { - $hostnames[] = $pu['host']; if ($mirror['country'] == $country) { - $list_of_mirrs['country'][] = $mirror['url']; + if (true === $https_only) + { + $pu = parse_url($mirror['url']); + if ('https' == $pu['scheme']) { + $mirrors[$continent][] = $mirror; + } + } + else + { + $mirrors[$continent][] = $mirror; + } } else { - $list_of_mirrs['continent_minus_country'][] = $mirror['url']; + if (true === $https_only) + { + $pu = parse_url($mirror['url']); + if ('https' == $pu['scheme']) { + $continent_https_only[$curr_continent][] = $mirror; + } + } } } } - else + } + } + if (count($mirrors) == 0) + { + if (true === $https_only) + { + if (count($continent_https_only) > 0) { - if ($mirror['country'] == $country) - { - $mirrors[$continent][] = $mirror; - } + $mirrors = $continent_https_only; + } + if (count($mirrors) == 0 && count($other_continents_https_only) > 0) + { + $mirrors = $other_continents_https_only; } } - if (count($mirrors) == 0) + else { // add all continent mirrors if country doesn't have any $mirrors[$continent] = $continent_mirrors; } } + // falback if selection fails if (count($mirrors) > 0) { $mirs = $mirrors; } - shuffle($mirs); - $mirr_continent = $mirs[0]; + // a workaround as shuffle() doesn't preserve assoc. keys + if (count($mirs) > 1) + { + $mirs_keys = array_keys($mirs); + shuffle($mirs_keys); + foreach($mirs_keys as $key) { + $shuffled[$key] = $mirs[$key]; + } + $mirs = $shuffled; + } + + $mirr_continent = array_keys($mirs)[0]; $mirs = array_shift($mirs); shuffle($mirs); $one_mirror = array_shift($mirs); @@ -390,9 +449,9 @@ class Downloads return $one_mirror; } - function prepare_download($force = false, $country = null, $prod = true, $documentation = false, $mirrorlist = false) + function prepare_download($force = false, $country = null, $prod = true, $documentation = false, $mirrorlist = false, $https_only = false) { - return $this->get_one_mirror($force, $country, $prod, $documentation, $mirrorlist); + return $this->get_one_mirror($force, $country, $prod, $documentation, $mirrorlist, $https_only); } /** @@ -408,7 +467,7 @@ class Downloads * * TODO extract as much as possible $_SESSION(read) and $_SERVER and $_GET */ - function get_one_mirror($force = false, $country = null, $prod = true, $documentation = false, $mirrorlist = false) + function get_one_mirror($force = false, $country = null, $prod = true, $documentation = false, $mirrorlist = false, $https_only = false) { $fuzzy_mirror = false; @@ -470,7 +529,7 @@ class Downloads $continent = null; } - $mirror = $this->get_mirror($country, $continent, $prod, $documentation, $mirrorlist); + $mirror = $this->get_mirror($country, $continent, $prod, $documentation, $mirrorlist, $https_only); $mirror['purl'] = parse_url($mirror['url']); // reassign country, as get_one_mirror() may have decided |