aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-05-11 12:23:42 +0400
committerGeorgy Redkozubov <georgy.redkozubov@linaro.org>2012-05-11 12:23:42 +0400
commitcedb46f813e9a597b80b8a730f027ded90903316 (patch)
treeeb880ca705914de49207d2aa60033d280a644846
parent716594af8fddd535a0c36a9daf60c791cd010ac1 (diff)
Added proper redirection handling from license.php back to mod_rewrite
-rw-r--r--.htaccess7
-rw-r--r--licenses/LicenseHelper.php34
-rw-r--r--licenses/license.php14
3 files changed, 24 insertions, 31 deletions
diff --git a/.htaccess b/.htaccess
index df272d6..2073ec8 100644
--- a/.htaccess
+++ b/.htaccess
@@ -85,7 +85,12 @@ RewriteCond %{ENV:LP_DOWNLOAD_DIR}/OPEN-EULA.txt -f
RewriteRule .* - [L]
## Unset cookie indicating redirect from license.php
-RewriteCond %{HTTP_COOKIE} redirectlicensephp=yes
+## and redirect to reqested locations with status
+RewriteCond %{HTTP_COOKIE} redirectlicensephp=403
+RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L,F]
+
+RewriteCond %{HTTP_COOKIE} redirectlicensephp=200 [OR]
+RewriteCond %{HTTP_COOKIE} redirectlicensephp=404
RewriteRule .* - [CO=redirectlicensephp:INVALID:.%{ENV:CO_DOMAIN}:-1,L]
## Redirect to the Samsung license file protected builds.
diff --git a/licenses/LicenseHelper.php b/licenses/LicenseHelper.php
index b55ac49..27b9e52 100644
--- a/licenses/LicenseHelper.php
+++ b/licenses/LicenseHelper.php
@@ -73,30 +73,18 @@ class LicenseHelper
return $theme;
}
- public static function status_forbidden($dir)
+ public static function redirect_with_status($dir, $domain, $status)
{
- header("Status: 403");
- header("HTTP/1.1 403 Forbidden");
- echo "<h1>Forbidden</h1>";
- echo "You don't have permission to access ".$dir." on this server.";
+ static $http = array (
+ 200 => "HTTP/1.1 200 OK",
+ 403 => "HTTP/1.1 403 Forbidden",
+ 404 => "HTTP/1.1 404 Not Found"
+ );
+ header($http[$status]);
+ header ("Location: $dir");
+ header("Status: ".$status);
+ setcookie("redirectlicensephp", $status, 0, "/", ".".$domain);
exit;
}
+}
- public static function status_ok($dir, $domain)
- {
- header("Status: 200");
- header("Location: ".$dir);
- setcookie("redirectlicensephp", "yes", 0, "/", ".".$domain);
- exit;
- }
-
- public static function status_not_found()
- {
- header("Status: 404");
- header("HTTP/1.0 404 Not Found");
- echo "<h1>404 Not Found</h1>";
- echo "The requested URL was not found on this server.";
- exit;
- }
-
-} \ No newline at end of file
diff --git a/licenses/license.php b/licenses/license.php
index aac10de..28de265 100644
--- a/licenses/license.php
+++ b/licenses/license.php
@@ -11,7 +11,7 @@ $flist = array();
$eula = '';
if (preg_match("/.*openid.*/", $fn) or preg_match("/.*restricted.*/", $fn) or preg_match("/.*private.*/", $fn)) {
- LicenseHelper::status_ok($down, $domain);
+ LicenseHelper::redirect_with_status($down, $domain, 200);
}
if (file_exists($fn) and LicenseHelper::checkFile($fn)) { // Requested download is file
@@ -23,7 +23,7 @@ if (file_exists($fn) and LicenseHelper::checkFile($fn)) { // Requested download
$repl = $down;
$name_only = array();
} else { // Requested download not found on server
- LicenseHelper::status_not_found();
+ LicenseHelper::redirect_with_status($down, $domain, 404);
}
$flist = LicenseHelper::getFilesList($search_dir);
@@ -41,18 +41,18 @@ if (LicenseHelper::checkFile($fn)) {
} elseif (LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) {
// If file is requested but no special EULA for it and no EULA.txt is present,
// look for any EULA and if found decide that current file is not protected.
- LicenseHelper::status_ok($down, $domain);
+ LicenseHelper::redirect_with_status($down, $domain, 200);
} else {
- LicenseHelper::status_forbidden($down);
+ LicenseHelper::redirect_with_status($down, $domain, 403);
}
} elseif (is_dir($fn)) {
if (empty($flist) or LicenseHelper::findFileByPattern($flist, "/.*EULA.txt.*/")) { // Directory contains only subdirs or any EULA
- LicenseHelper::status_ok($down, $domain);
+ LicenseHelper::redirect_with_status($down, $domain, 200);
} else { // No special EULA, no EULA.txt, no OPEN-EULA.txt found
- LicenseHelper::status_forbidden($down);
+ LicenseHelper::redirect_with_status($down, $domain, 403);
}
} else {
- LicenseHelper::status_forbidden($down);
+ LicenseHelper::redirect_with_status($down, $domain, 403);
}
$template_content = file_get_contents($doc."/licenses/".$theme.".html");