diff options
author | Romain d'Alverny <rda@mageia.org> | 2011-11-23 22:53:13 +0000 |
---|---|---|
committer | Romain d'Alverny <rda@mageia.org> | 2011-11-23 22:53:13 +0000 |
commit | 66875da97b0db2fcb9431e78bd102e92eeb5bb33 (patch) | |
tree | 6286f7ae6c5568c5e59988b3b458f78570b39a5e /en/downloads/get | |
parent | 48631ff7ba2b341e01b453aa9051c32dcaca0f67 (diff) | |
download | www-66875da97b0db2fcb9431e78bd102e92eeb5bb33.tar www-66875da97b0db2fcb9431e78bd102e92eeb5bb33.tar.gz www-66875da97b0db2fcb9431e78bd102e92eeb5bb33.tar.bz2 www-66875da97b0db2fcb9431e78bd102e92eeb5bb33.tar.xz www-66875da97b0db2fcb9431e78bd102e92eeb5bb33.zip |
next download redirector - not to be used yet
Diffstat (limited to 'en/downloads/get')
-rw-r--r-- | en/downloads/get/definitions.ini | 38 | ||||
-rw-r--r-- | en/downloads/get/index.php | 199 | ||||
-rw-r--r-- | en/downloads/get/lib.php | 72 |
3 files changed, 309 insertions, 0 deletions
diff --git a/en/downloads/get/definitions.ini b/en/downloads/get/definitions.ini new file mode 100644 index 000000000..876a2351e --- /dev/null +++ b/en/downloads/get/definitions.ini @@ -0,0 +1,38 @@ +; Downloads definitions file. +; This is a whitelist for what can be downloaded from mageia.org +; through the download redirector (to official Mageia mirrors). +; + +[Mageia-2-alpha1-i586-DVD.iso] +file = Mageia-2-alpha1-i586-DVD.iso +path = iso/cauldron +torrent = torrents/Mageia-2-alpha1-i586-DVD.torrent +md5 = dummy +sha1 = dimmy +name = Mageia 2 alpha1 32bit DVD +size = 4.2GB + +; +[mageia-livecd-1-GNOME-africa-india-cdrom-i586.iso] +file = mageia-livecd-1-GNOME-africa-india-cdrom-i586.iso +path = iso/1 +torrent = torrents/mageia-livecd-1-GNOME-africa-india-cdrom-i586.torrent +md5 = 621f4e965c04e49b8602b4ec670e8466 +sha1 = 753afcd28978ff89dc0a8840f8f33b65bf8dad30 +name = Mageia 1 LiveCD GNOME Africa India CD 32bit +page_title = Mageia 1 LiveCD GNOME 32bit +post_link = +post_title = + + +; mgaonline RPM +[mgaonline] +type = rpm +hidden = true +name = mgaonline +size = 196 KB +page_title = mgaonline +post_link = /migrate/ +post_title = Go back to the migration page +path = distrib/1/i586/media/core/release/ +file = mgaonline-2.77.29-1.mga1.noarch.rpm diff --git a/en/downloads/get/index.php b/en/downloads/get/index.php new file mode 100644 index 000000000..d3d012277 --- /dev/null +++ b/en/downloads/get/index.php @@ -0,0 +1,199 @@ +<?php +/** + * Main download redirector. + * + * Takes these data: + * - product to download (GET[product]) + * - download mode (normal or GET[torrent] is set) + * - products whitelist with a checksum for each one + * - list of available up-to-date mirrors for this product + +product: + id + name + checksums + size + +mirror(product): + name + host + country + city + speed + link + +*/ + +require 'lib.php'; + +// request +$product = get('q'); +$torrent = isset($_GET['torrent']) ? true : false; + +if (is_null($product)) { + header('Location: /downloads/'); + die; +} + +define('HLANG', true); +require '../../../langs.php'; +require '../locales.php'; + +$_t = i18n::get_strings($_t, $locale, $i18n_fallback_rules); + +session_start(); + +$download = null; +$js_redirect = null; +$reason = null; + +try { + $product = get_info_for_product($product); + $all_mirrors = get_mirrors_for($product['file'], 'en', get('country')); + $one_mirror = $all_mirrors[0]; + $alt_mirrors = $all_mirrors[1]; + + $path = $product['path'] . '/' . $product['file']; + $download = $one_mirror['mirror_url'] . '/' . $path; + + $js_redirect = sprintf('<script>(function(){setTimeout("document.location=\'%s\';", 3000);})();</script>', + $download); + + $g_mirs2 = array(); + foreach ($alt_mirrors as $country => $mirs): + foreach ($mirs as $mir): + $g_mirs2[$countries[$country]][$mir['city']][] = $mir['url']; + endforeach; + endforeach; + + ksort($g_mirs2); + + $alternative_mirrors = ''; + foreach ($g_mirs2 as $country => $cities): + foreach ($cities as $city => $mirrors2) { + $mirs = array(); + foreach ($mirrors2 as $m) { + $pm = parse_url($m); + $alt_dl_link = $m . '/' . $path; + $mirs[] = sprintf('%s://<a href="%s" rel="nofollow">%s</a>', + $pm['scheme'], $alt_dl_link, $pm['host']); + } + $alternative_mirrors .= sprintf('<tr><td nowrap>%s</td><td>%s</td><td>%s</td></tr>', $country, $city, implode(', ', $mirs)); + } + endforeach; + + $dl2_mirror_alt = sprintf($_t['dl_mirror_loc'], + $one_mirror['mirror_url'], + $one_mirror['mirror_host'], + $one_mirror['city'] . ', ' . $countries[$one_mirror['country']], + $one_mirror['country']) + . ' ' . $_t['dl_alt_mirrors']; +} +catch (NoProductFoundError $e) { + // sorry, no such product found/available. redirect? + $reason = 'This file is not available for download.'; +} +catch (NoMirrorFoundError $e) { + // sorry, not mirror found. next time? + $reason = 'No mirror found for this file to download.'; + +} +catch (Exception $e) { + $reason = 'I do not know either!'; +} + +if (!$download) { + header('HTTP/1.0 404 Not Found'); + header('Status: 404 Not Found'); + $title = '404 Not Found'; + $js_redirect = null; +} +else { + $title = $product['name']; +} + +$_t['page_h1'] = sprintf($_t['page_h1'], '<em class="tag">' . $title . '</em>'); +$_t['page_title'] = sprintf($_t['page_title'], '<em class="tag">' . $title . '</em>'); + +?><!DOCTYPE html> +<html lang="<?php echo $locale; ?>"> +<head> + <meta charset="utf-8"> + <title><?php echo $title; ?> | Mageia Downloads</title> + <meta name="robots" content="noindex,nofollow,nosnippet"> + <link rel="stylesheet" type="text/css" href="/g/style/all.css"> + <?php if (!isset($_ENV['APP_MODE']) || $_ENV['APP_MODE'] == 'prod') { + include '../../../analytics.php'; + echo $js_redirect; + } ?> +</head> +<body> + <?php echo $hsnav; ?> + <div id="doc4" class="yui-t7"> + <div id="hd" role="banner"><h1><a id="logo" href="/"><span>Mageia</span></a> <span class="lsep"> </span> + <span class="subh"><?php echo $_t['page_h1']; ?></span></h1></div> + <div id="bd" role="main"> + <?php if (!is_null($download)): ?> + <div class="yui-g"><div class="para"> + + <h2><?php echo $_t['page_title']; ?></h2> + <p><?php + echo + sprintf($_t['dl_shld_start'], '<em class="tag">' . $product['name'] . '</em>' . ($torrent ? ' (torrent)' : '')), + ' ', sprintf($_t['dl_size'], $product['size']), + ' ', sprintf($_t['alt_download'], $download, $download); + ?></p> + + <div class="dlinfo"> + <p><?php echo $dl2_mirror_alt; ?></p> + <?php if ((isset($product['md5']) || isset($product['sha1'])) && !$torrent): ?> + <p><?php echo $_t['signs_check_1']; ?></p> + <div id="check-signs"> + <pre class="term"> +<?php if (isset($product['md5'])): ?>$ md5sum <?php echo basename($download), "\n", $product['md5'], "\n"; endif; ?> + +<?php if (isset($product['sha1'])): ?>$ sha1sum <?php echo basename($download), "\n", $product['sha1'], "\n"; endif; ?> +</pre> + <p><?php echo $_t['signs_check_2']; ?></p> + </div> + <?php endif; ?> + </div> + + <!-- alternative mirrors table --> + <table class="dlt2 dlinfo" id="other_mirrors" style="display: none;"> + <thead><tr><th><?php echo $_t['Country']; ?></th> + <th><?php echo $_t['City']; ?></th> + <th><?php echo $_t['Download mirrors']; ?></th></tr></thead> + <tbody><?php echo $alternative_mirrors; ?></tbody> + </table> + + <hr /> + <h2><?php echo sprintf($_t['wanttohelp?'], '<strong><a href="http://mageia.org/contribute/">', '</a></strong>'); ?></h2> + </div></div> + <?php else: ?> + <div class="yui-g"><div class="para"> + <p>Sorry, your download could not complete, as we could not find this file. + Please try again from the <a href="/downloads/">main downloads page</a>.</p> + + <p>If you still encounter this error, please warn us through:</p> + <ul> + <li><a href="irc://irc.freenode.net/#mageia-web">#mageia-web on Freenode IRC</a>,</li> + <li>a <a href="http://twitter.com/mageia_org">notice on our Tweeter account</a>,</li> + <li>a <a href="https://www.mageia.org/mailman/listinfo/mageia-webteam">notice on the Web team mailing-list</a>,</li> + <li>or a <a href="https://bugs.mageia.org/">bug report</a>.</li> + </ul> + + <p>You may embed this debug info if you like:</p> + <pre class="term small"><?php echo $reason, "\n", (json_encode($_GET)); ?></pre> + <p>Thanks!</p> + </div></div> + <?php endif; ?> + </div> +<script> +document.getElementById("other_mirrors_btn").onclick = function () { + var el = document.getElementById("other_mirrors"); + el.style.display = (el.style.display != 'none' ? 'none' : '' ); +}; +</script> +</body> +</html> diff --git a/en/downloads/get/lib.php b/en/downloads/get/lib.php new file mode 100644 index 000000000..527675d81 --- /dev/null +++ b/en/downloads/get/lib.php @@ -0,0 +1,72 @@ +<?php +/** +*/ + +$countries = array( + 'AU' => 'Australia', + 'BE' => 'Belgium', + 'BR' => 'Brasil', + 'CA' => 'Canada', + 'CH' => 'Switzerland', + 'CN' => 'China', + 'CZ' => 'Czechia', + 'DE' => 'Deutschland', + 'FR' => 'France', + 'GR' => 'Greece', + 'GT' => 'Guatemala', + 'JP' => 'Japan', + 'NC' => 'Nouvelle-Calédonie', + 'NL' => 'Nederlands', + 'TW' => 'Taiwan', + 'UK' => 'the UK', + 'US' => 'the USA', +); + +function get($s) { + return isset($_GET[$s]) ? trim($_GET[$s]) : null; +} + +class NoProductFoundError extends Exception {} +class NoMirrorFoundError extends Exception {} + +/** +*/ +function get_info_for_product($product) +{ + $defs = parse_ini_file('definitions.ini', true); + + if (array_key_exists($product, $defs)) { + return $defs[$product]; + } + + throw new NoProductFoundError; +} + +/** + * Return mirrors for $file. + * First mirror returned is the preferred one for auto redirection. + * + * @param string $file id of the file to download/find a mirror for + * @param string $locale hint for selecting a mirror + * @param string $country hint for selecting a mirror + * + * @return array + * mirror(product): + * name + * host + * country + * city + * speed + * link +*/ +function get_mirrors_for($file, + $locale = null, $country = null) +{ + include '../../../lib/Downloads.php'; + + $mirrors = Downloads::get_all_mirrors(); + $wsd = new Downloads(); + $one = $wsd->prepare_download(true, $country); + + return array($one, $mirrors); +}
\ No newline at end of file |