route : better relative support

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2084 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-04-28 09:07:31 +00:00
parent 6bd4c44a15
commit da8d0d9925

View File

@@ -63,10 +63,8 @@ class route
{ {
// Calculate the root in relative // Calculate the root in relative
$request = $this->requestURL (); $request = $this->requestURL ();
$root = dirname ($_SERVER["SCRIPT_NAME"]);
$requestdir = substr ($request, 1+strlen ($root));
$this->baseURL = str_repeat ("../", $this->baseURL = str_repeat ("../",
substr_count ($requestdir, "/")). substr_count ($request, "/")).
$this->baseURL; $this->baseURL;
if ($this->baseURL === "") if ($this->baseURL === "")
$this->baseURL = "./"; $this->baseURL = "./";
@@ -121,7 +119,7 @@ class route
$url .= "//".$_SERVER["SERVER_NAME"].$port; $url .= "//".$_SERVER["SERVER_NAME"].$port;
} }
if (isset ($_SERVER["REQUEST_URI"])) if (isset ($_SERVER["REQUEST_URI"]))
$url .= $_SERVER["REQUEST_URI"]; $url .= substr ($_SERVER["REQUEST_URI"], 1+strlen (dirname ($_SERVER["SCRIPT_NAME"])));
return $url; return $url;
} }
@@ -155,7 +153,7 @@ class route
// Allow to redirect from POST to GET, but not GET to GET (can loop) // Allow to redirect from POST to GET, but not GET to GET (can loop)
if ($destURL === $requestURL && $_SERVER["REQUEST_METHOD"] === "GET") if ($destURL === $requestURL && $_SERVER["REQUEST_METHOD"] === "GET")
throw new Exception ("Redirect to myself", 508); throw new Exception ("Redirect to myself", 508);
if (substr ($destURL, 0, strlen ($baseURL)) !== $baseURL) if (substr_count ("../", $baseURL) > 1+ substr_count ("/", $destURL))
throw new Exception ("Can't redirect outside this site (Base $baseURL)", throw new Exception ("Can't redirect outside this site (Base $baseURL)",
405); 405);
@@ -314,7 +312,7 @@ file_put_contents ("/tmp/csrf.log", date ("Y-m-d H:i:s")." DELETE route->map ($r
public function map ($route, $function) public function map ($route, $function)
{ {
$url = substr ($this->requestURL (), strlen ($this->baseURLmodule ())); $url = substr ($this->requestURL (), strlen ($this->baseURLmodule ()));
$url = substr ($this->requestURL (), 1+ strlen (dirname ($_SERVER["SCRIPT_NAME"]))); $url = $this->requestURL ();
if ($this->debug) if ($this->debug)
echo "$url "; echo "$url ";
if ($url === $route) if ($url === $route)