aboutsummaryrefslogtreecommitdiffstats
path: root/en/downloads/get/index.php
blob: ecb5f22cfbd96a31bf8d3c05b0256c63836ccc33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?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
 *
 *
 * PHP version 5.4
 *
 * @category Mageia
 * @package  Mageia\Web\www
 * @author   rda <rda@mageia.org>
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GPL-2+
 * @link     http://www.mageia.org/
 *
*/

require 'lib.php';
require_once '../../../lib/mga_geoip.php';

// request
$product = get('q');
$doc     = get('doc');
$debug   = get('d');
if (isset($_GET['torrent'])) {
    $torrent = strip_tags(trim($_GET['torrent']));
}
$torrent = isset($torrent) ? true : false;

if (is_null($product)) {
    header('Location: /downloads/');
    die;
}

define('HLANG', true);
define('ALIGNMENT', 'Center');
require '../../../langs.php';
$dictionary = read_translation_file($locale, array('downloads/get', 'common_footer'));

session_start();

$download    = null;
$js_redirect = null;
$reason      = null;
if ($doc == 'yes') {
    $def_file = 'definitions_doc.ini';
    list($release, $type, $lang, $extension) = explode('-', $product); // 'Mageia4-DrakX-pt_br-epub'
    $product = implode('_', array($release, $type, 'en', $extension));
    $documentation = true;
} else {
    $def_file = 'definitions.ini';
    $documentation = false;
}

try {
    // TODO simplify and wrap all this in a single interface:
    // list(dl_template, mirrors) = get_download_options_for(product)
    // Step 1.
    include '../../../lib/Downloads.php';
    $product     = get_info_for_product($product, $def_file);
    if ($doc == 'yes') {
        $langs = explode('|', $product['langs']);
        if (!in_array($lang, $langs)) {
            $lang = 'en'; // fallback language
        }
        $product['file'] = $release . '-' . $type . '-' . $lang . '.' . $extension;
        $product['name'] = $product['file'];
    }
    $all_mirrors = get_mirrors_for($product['file'], 'en', get('country'), true, $documentation);
    $one_mirror  = $all_mirrors[0];
    $alt_mirrors = $all_mirrors[1];
    $download_tmpl = get_download_link($product, $torrent);

    // Step 2. Make the actual download link against the preferred mirror returned.
    $download = str_replace('$MIRROR', $one_mirror['mirror_url'], $download_tmpl);

    // TODO do not redirect if it's a bot!
    $js_redirect = sprintf(
        '<script>(function(){setTimeout("document.location=\'%s\';", 6000);})();</script>',
        $download
    );

    // Step 3. Build alternative mirrors list of links (URL manipulation, HTML)
    $g_mirs2 = array();
    foreach ($alt_mirrors as $mirs):
        foreach ($mirs as $mir):
            $country = $mir['country'];
            if (!array_key_exists($country, $countries)) {
                $countries[$country] = "country: $country";
            }
            $g_mirs2[$countries[$country]][$mir['city']][] = $mir['url'];
        endforeach;
    endforeach;

    ksort($g_mirs2);

    $alternative_mirrors = PHP_EOL;
    foreach ($g_mirs2 as $country => $cities) {
        $s = array();
        foreach ($cities as $city => $mirrors2) {
            $mirs = array();
            rsort($mirrors2);
            foreach ($mirrors2 as $m) {
                $pm = parse_url($m);
                $alt_dl_link = str_replace('$MIRROR', $m, $download_tmpl);
                $mirs[] = sprintf(
                    '<a href="%s" rel="nofollow" class="mirror-link"><span class="p">%s</span> %s</a>',
                    $alt_dl_link, strtoupper($pm['scheme']), $pm['host']
                );
            }
            $s[] = sprintf('<td>%s</td><td>%s</td>', rewrite_city($city), implode(', ', $mirs));
        }
        $alternative_mirrors .= sprintf('<tr><td rowspan="%d">%s</td>%s</tr>' . PHP_EOL, count($cities), $country, implode('</tr><tr>', $s));
    }

    // Feedback about current mirror location + trigger for alt mirrors.
    if (array_key_exists($one_mirror['country'], $countries)) {
        $mirrors_country_name = $countries[$one_mirror['country']];
    } else if (array_key_exists($one_mirror['country'], MGA_Geoip::$MGA_COUNTRY_CODE_TO_COUNTRY_NAME)) {
        $mirrors_country_name = MGA_Geoip::$MGA_COUNTRY_CODE_TO_COUNTRY_NAME[$one_mirror['country']];
    } else {
        $mirrors_country_name = $one_mirror['country'];
    }
    $dl2_mirror_alt = sprintf(
        _r('This <a href="%s">%s</a> download mirror is located in %s (%s).', ' '),
        $one_mirror['mirror_url'],
        $one_mirror['mirror_host'],
        rewrite_city($one_mirror['city']),
        $mirrors_country_name
    );
    $dl2_mirror_alt .= _r('If it does not work well for you, <a href="#om" id="other_mirrors_btn">check out these other mirrors</a>.', ' ');
    if (array_key_exists($_SESSION['country'], $countries)) {
        $country_name = $countries[$_SESSION['country']];
    } else if (array_key_exists($_SESSION['country'], MGA_Geoip::$MGA_COUNTRY_CODE_TO_COUNTRY_NAME)) {
        $country_name = MGA_Geoip::$MGA_COUNTRY_CODE_TO_COUNTRY_NAME[$_SESSION['country']];
    } else {
        $country_name = $_SESSION['country'];
    }

    if (array_key_exists($_SESSION['continent'], MGA_Geoip::$MGA_CONTINENT_CODE_TO_CONTINENT_NAME)) {
        $continent_name = MGA_Geoip::$MGA_CONTINENT_CODE_TO_CONTINENT_NAME[$_SESSION['continent']];
    } else {
        $continent_name = $_SESSION['continent'];
    }
    $dl2_mirror_alt .= sprintf(
        _r('Your IP address is %s and you seem to be in %s, %s.'),
        $_SESSION['ip'], $country_name, $continent_name
    );


    // at the end of this block we expect the following vars to be available from here:
    // - $product (mixed)
    // - $download (URL)
    // - $js_redirect (JS snippet)
    // - $alternative_mirrors (HTML snippet)
    // - $dl2_mirror_alt (HTML snippet)
}
catch (NoProductFoundError $e) {
    // sorry, no such product found/available. redirect?
    $reason = 'The file '. $product .' is not available for download.';
}
catch (NoMirrorFoundError $e) {
    // sorry, no mirror found. next time?
    $reason = 'No mirror found for this file to download.';
}
catch (Exception $e) {
    // don't translate $reason as it's for debuging purposes
    $reason = 'I do not know either!';
}

if (!$download) {
    header('HTTP/1.0 404 Not Found');
    header('Status: 404 Not Found');
    header('Cache-Control: public, max-age=600, s-max-age=900');
    $title       = '404 Not Found';
    $js_redirect = null;
} else {
    header('Pragma: no-cache');
    header('Cache-Control: s-maxage=0, max-age=0, must-revalidate, no-cache');
    $title = $product['name'];
}
if(is_array($product) && !isset($product['magnet'])) {
    $product['magnet'] = null;
}
if(is_array($product) && !isset($product['obsolete'])) {
    $product['obsolete'] = null ;
}
if(isset($product['size'])) {
    preg_match("/\D*(\d+.*)/", $product['size'], $product_size);
}
if ($debug)
    $js_redirect = null;

?><!DOCTYPE html>
<html lang="<?php echo $locale; ?>">
<head>
    <meta charset="utf-8">
    <title><?php echo $title; ?> | <?php _g('Mageia Downloads') ?></title>
    <meta name="robots" content="noindex,nofollow,nosnippet">
    <?php echo common_header(); ?>
    <?php
if (!isset($_SERVER['APP_MODE']) || $_SERVER['APP_MODE'] == 'prod') {
    include '../../../analytics.php';
    echo $js_redirect;
}
    ?>
</head>
<body class="downloads">
    <?php echo $hsnav; ?>
    <h1 id="mgnavt"><?php echo sprintf(_r('Download %s'), '<em class="tag">' . $title . '</em>')?></h1>
    <div id="doc4" class="yui-t7" style="margin-bottom: 0px;">
        <div id="bd" role="main">
            <?php if (!is_null($download)): ?>
                <div class="yui-g"><div class="para" style="padding-top: 2em;">
                <p><?php

if(isset($product['obsolete'])) {
	echo '<div class="alert alert-danger" role="alert">';
           _g('Warning !', null, 'h4');
           _g('This file is obsolete, please <a %s>download</a> the latest version.', 'href="../" class="alert-link"', 'p');
	echo '</div>';
}
                    echo
                        sprintf(_r('Your download of %s should start within a few seconds'), '<em class="tag">' . $product['name'] . '</em>' . ($torrent ? ' (torrent)' : '')),
                        ' ', sprintf(_r('(download size is about %s).'), $product_size[1]),
                        ' ', sprintf(_r('If the download does not start, <a href="%s" rel="nofollow" title="%s">click here</a>.'), $download, $download),
                        sprintf( '%s', ($product['magnet'] && $torrent ? ' | <a href="' . $product['magnet'] .'">Magnet</a>' : '' ));
                ?></p>

                <div class="dlinfo">
                    <p><?php echo $dl2_mirror_alt; ?></p>
<?php
$checksums = array('md5', 'sha1', 'sha512');
$sum_links = array();
$chksm_cmd = '';
$sig_links = array();
foreach ($checksums as $checksum) {
    if (isset($product[$checksum])) {
        $sum_links[] = "<a href=\"$download.$checksum\">" . basename($download) . ".$checksum</a>";
        $chksm_cmd .= '$ ' . $checksum . 'sum ' . basename($download) . "\n<strong>" . $product[$checksum] . "</strong>\n" . PHP_EOL;
        if (isset($product["$checksum.gpg"])) {
            $sig_links[] = "<a href=\"$download.$checksum.gpg\">" . basename($download) . ".$checksum.gpg</a>";
        }
    }
}
?>
<?php
$num_checksums = count($sum_links);
// only output for nontorrent DL and if there are any checksums files present
if ($num_checksums > 0 && !$torrent) {
    _g('As soon as your download is complete, you should check that the checksums match:', null, 'p');
    echo PHP_EOL . '<div id="check-signs">' . PHP_EOL;
    echo '<pre class="term pre-scrollable">' . PHP_EOL;
    echo $chksm_cmd;
    echo '</pre>' . PHP_EOL . '<p>';
    _g('If checksums do not match, <strong>DO NOT use this ISO</strong>. Double-check and try to download again.', null, ' ');
    $checksum_links = array_to_list($sum_links, ' ' . _r('and', ' '), _r(',', ' '));
    $signature_links = array_to_list($sig_links, ' ' . _r('and', ' '), _r(',', ' '));
    _g('Checksums are available for download as files:', null, ' ');
    echo "$checksum_links.</p>";
?>
<?php if (count($sig_links) > 0) { // only output if there are any signatures files present ?>
<p><?php _g('You can also verify the signature of an ISO.', null, ' ');
_g('They are also available for download as files:', null, ' ');
echo "$signature_links. ";
echo sprintf(_r('First you need to import the "Mageia Release" key from a <a href="%s">MIT PGP Public Key Server</a>:'), 'https://pgp.mit.edu/'); ?></p>
<pre class="term pre-scrollable">
$ gpg --keyserver pgp.mit.edu --recv-keys EDCA7A90
</pre>
<p><?php _g('In response there should be one of the following lines:'); ?></p>
<pre class="term pre-scrollable">
<strong>gpg: key EDCA7A90: public key "Mageia Release &lt;release&#x40;mageia.org&gt;" imported</strong>

<?php _g('or if you already imported the key before:'); echo PHP_EOL; ?>

<strong>gpg: key EDCA7A90: "Mageia Release &lt;release&#x40;mageia.org&gt;" not changed</strong>
</pre>
<p><?php _g('Then you need to verify the signature for the ISO.'); ?></p>
<pre class="term">
$ gpg --verify /your/download/location/<?php echo basename($download); ?>.md5.gpg
</pre>
<p><?php _g('In response there should be lines like:'); ?></p>
<pre class="term pre-scrollable">
<strong>gpg: Good signature from "Mageia Release &lt;release&#x40;mageia.org&gt;"</strong>
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
<strong>Primary key fingerprint: B210 76A0 CBE4 D93D 66A9  D08D 835E 41F4 EDCA 7A90</strong>
</pre>
<p><?php _g('The warning about uncertified signature is expected.'); ?></p>
<?php } // signatures check end ?>
                        </div>
<?php } // checksums check end ?>
                </div>

                <!-- alternative mirrors table -->
                <table class="dlt2 dlinfo table table-sm table-bordered table-striped" id="om" style="display: none;">
                    <thead class="thead-inverse"><tr><th><?php _g('Country'); ?></th>
                        <th><?php _g('City'); ?></th>
                        <th><?php _g('Download mirrors'); ?></th></tr></thead>
                    <tbody><?php echo $alternative_mirrors; ?></tbody>
                </table>

                <hr />

                </div></div>
                <div class="yui-g" style="border-top: 1px solid #ddd;">
                    <div class="yui-g first"><div class="para">
                    </div></div>
                    <div class="yui-g" style="border-left: 1px solid #ddd"><div class="para">
                        <p><?php echo sprintf(_r('The making and the distribution of Mageia worldwide is made possible by all the <a href="%s">people and organizations that mirror our software</a> and that <a href="%s">donate money, hardware, hosting and more</a>.'), '//mirrors.mageia.org/', '../../thank-you/'); ?></p>
                        <p><?php echo sprintf(_r('Want to help? %sJoin Us!%s'), '<a href="../../contribute/">', '</a>'); ?></p>
                    </div></div>
                </div>
            <?php else: ?>
                <div class="yui-g"><div class="para" style="padding-top: 2em;">
                    <h2><?php _g('Sorry!'); ?> :-(</h2>
                    <p><?php echo sprintf(_r('Your download could not complete, as we could not find this file. Please try again from the <a href="%s">main downloads page</a>.'), '../../downloads/'); ?></p>

                    <p><?php echo sprintf(_r('If you still encounter this error and think IT SHOULD NOT HAPPEN &ndash; please tell us:')); ?></p>
                    <ul>
                        <li><?php _g('directly on <a href="irc://irc.freenode.net/#mageia-atelier">#mageia-atelier on Freenode IRC</a>,'); ?></li>
                        <li><?php _g('or <a href="https://twitter.com/mageia_org">via our Twitter account</a>,'); ?></li>
                        <li><?php _g('or with a <a href="https://ml.mageia.org/l/info/atelier-discuss">notice on the Atelier team mailing-list</a>,'); ?></li>
                        <li><?php _g('or a <a href="https://bugs.mageia.org/enter_bug.cgi?product=Websites&amp;format=guided&amp;component=www.mageia.org">bug report</a>.'); ?></li>
                    </ul>

                    <p><?php _g('Please copy and report us the above address that returned you to this page.', null, ' '); _g('Thanks!'); ?></p>
                    <p><a href="/<?php echo $locale; ?>">&laquo; <?php _g('back to that awesome Mageia home page'); ?></a></p>
                </div></div>
            <?php endif; ?>
    </div>
    <div class="d-flex justify-content-center">
    <button type="button" class="btn btn-secondary btn-sm share-icon" title="<?php _g('By clicking this button, you agree to the use of HTTP cookies.', null, ' '); _g('They enable you to share content from this page via social network sharing buttons.'); ?>"><?php _g('Share')?></button>
        <div class="row">
        <span class="col"><a href="https://twitter.com/mageia_org" class="twitter-follow-button" data-show-count="true" data-lang="<?php echo $locale; ?>"></a></span>
        <span class="col"><div class="fb-like" data-href="https://www.facebook.com/Mageia" data-layout="button_count" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div></span>
        <span class="col"><div class="g-plusone" data-annotation="inline" data-size="medium" data-width="120"></div></span>
        </div>
    </div>
</div>

<?php echo common_footer($locale); ?>
<script>
document.getElementById("other_mirrors_btn").onclick = function () {
    var el = document.getElementById("om");
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
};

<?php
/* workaround for https://developers.facebook.com/docs/internationalization */
function getFBlocale($locale){
    $FBlocal = array(
        'de'    => 'de_DE',
        'es'    => 'es_ES',
        'fr'    => 'fr_FR',
        'pt-br' => 'pt_BR',
    );
    if (array_key_exists($locale, $FBlocal)) {
        return $FBlocal[$locale];
    } else {
        return 'en_US';
    }
};?>

$(function() {
    $('.share-icon').on('click', function(){
        $.getScript('//platform.twitter.com/widgets.js');

        (function(d,s,id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/<?php echo getFBlocale($locale); ?>/sdk.js#xfbml=1&version=v2.9";
            fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk')
        );

        $.getScript('https://apis.google.com/js/plusone.js');
        {lang: '<?php echo $locale; ?>'}

    });
});
</script>
</body>
</html>