Last active
December 19, 2015 05:48
-
-
Save pascalchevrel/5906395 to your computer and use it in GitHub Desktop.
check fx version is valid
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isValidFirefoxDownload() { | |
if (!isset($_GET['product'])) { | |
return false; | |
} | |
global $config; | |
$versionDetails = (int) str_replace('firefox-', '', $_GET['product']); | |
// If $versionDetails == 0 it means that the version number is a | |
// potentially valid keyword such as latest, stub, beta... | |
$majorVersion = ($versionDetails == 0) ? LATEST_FIREFOX_VERSION : $versionDetails; | |
// List of validity checks. Can be extended. Boolean values. | |
$valid = array( | |
isset($_SERVER['HTTP_REFERER']), | |
(bool) strstr($_SERVER['HTTP_REFERER'], $config['server_name']), | |
($majorVersion < (int) LATEST_FIREFOX_VERSION) ? false : true, | |
); | |
// We don't want to redirect requests for ESR or Thunderbird | |
if ((bool) strstr($_GET['product'], 'esr') | |
|| (bool) strstr($_GET['product'], 'thunderbird')) { | |
return true; | |
} | |
// If we have failed constraints, a filtered array will be smaller | |
if (count($valid) > count(array_filter($valid))) { | |
return false; | |
} | |
return true; | |
} | |
// Redirect non-latest versions of Firefox download requests (Bug 887940) | |
if (!isValidFirefoxDownload()) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: /firefox/new/'); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment