// Pass back to the webserver for files that exist if (php_sapi_name() === 'cli-server' && file_exists(BASE_PATH . $url) && is_file(BASE_PATH . $url)) { return false; } } // Remove base folders from the URL if webroot is hosted in a subfolder if (substr(strtolower($url), 0, strlen(BASE_URL)) == strtolower(BASE_URL)) { $url = substr($url, strlen(BASE_URL)); } /** * Include SilverStripe's core code */ require_once 'core/startup/ErrorControlChain.php'; require_once 'core/startup/ParameterConfirmationToken.php'; // Prepare tokens and execute chain $reloadToken = ParameterConfirmationToken::prepare_tokens(array('isTest', 'isDev', 'flush')); $chain = new ErrorControlChain(); $chain->then(function ($chain) use($reloadToken) { // If no redirection is necessary then we can disable error supression if (!$reloadToken) { $chain->setSuppression(false); } // Load in core require_once 'core/Core.php'; // Connect to database require_once 'model/DB.php'; global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); } // Check if a token is requesting a redirect
/** * currentAbsoluteURL needs to handle base or url being missing, or any combination of slashes. * * There should always be exactly one slash between each part in the result, and any trailing slash * should be preserved. */ public function testCurrentAbsoluteURLHandlesSlashes() { global $url; $token = new ParameterConfirmationTokenTest_Token('parameterconfirmationtokentest_parameter'); foreach (array('foo', 'foo/') as $host) { list($hostAnswer, $hostSlash) = $this->addPart(array(), '', $host); foreach (array('', '/', 'bar', 'bar/', '/bar', '/bar/') as $base) { list($baseAnswer, $baseSlash) = $this->addPart($hostAnswer, $hostSlash, $base); foreach (array('', '/', 'baz', 'baz/', '/baz', '/baz/') as $url) { list($urlAnswer, $urlSlash) = $this->addPart($baseAnswer, $baseSlash, $url); $_SERVER['HTTP_HOST'] = $host; ParameterConfirmationToken::$alternateBaseURL = $base; $this->assertEquals('http://' . implode('/', $urlAnswer) . $urlSlash, $token->currentAbsoluteURL()); } } } }
/** * Given a list of token names, suppress all tokens that have not been validated, and * return the non-validated token with the highest priority * * @param type $keys List of token keys in ascending priority (low to high) * @return ParameterConfirmationToken The token container for the unvalidated $key given with the highest priority */ public static function prepare_tokens($keys) { $target = null; foreach ($keys as $key) { $token = new ParameterConfirmationToken($key); // Validate this token if ($token->reloadRequired()) { $token->suppress(); $target = $token; } } return $target; }
public function checkRewrite() { require_once 'core/startup/ParameterConfirmationToken.php'; $token = new ParameterConfirmationToken('flush'); $params = http_build_query($token->params()); $destinationURL = str_replace('install.php', '', $_SERVER['SCRIPT_NAME']) . ($this->checkModuleExists('cms') ? "home/successfullyinstalled?{$params}" : "?{$params}"); echo <<<HTML <li id="ModRewriteResult">Testing...</li> <script> \tif(typeof \$ == 'undefined') { \t\tdocument.getElemenyById('ModeRewriteResult').innerHTML = "I can't run jQuery ajax to set rewriting; I will redirect you to the homepage to see if everything is working."; \t\tsetTimeout(function() { \t\t\twindow.location = "{$destinationURL}"; \t\t}, 10000); \t} else { \t\t\$.ajax({ \t\t\tmethod: 'get', \t\t\turl: 'InstallerTest/testrewrite', \t\t\tcomplete: function(response) { \t\t\t\tvar r = response.responseText.replace(/[^A-Z]?/g,""); \t\t\t\tif(r === "OK") { \t\t\t\t\t\$('#ModRewriteResult').html("Friendly URLs set up successfully; I am now redirecting you to your SilverStripe site...") \t\t\t\t\tsetTimeout(function() { \t\t\t\t\t\twindow.location = "{$destinationURL}"; \t\t\t\t\t}, 2000); \t\t\t\t} else { \t\t\t\t\t\$('#ModRewriteResult').html("Friendly URLs are not working. This is most likely because a rewrite module isn't configured " \t\t\t\t\t\t+ "correctly on your site. You may need to get your web host or server administrator to do this for you: " \t\t\t\t\t\t+ "<ul>" \t\t\t\t\t\t+ "<li><strong>mod_rewrite</strong> or other rewrite module is enabled on your web server</li>" \t\t\t\t\t\t+ "<li><strong>AllowOverride All</strong> is set for the directory where SilverStripe is installed</li>" \t\t\t\t\t\t+ "</ul>"); \t\t\t\t} \t\t\t} \t\t}); \t} </script> <noscript> \t<li><a href="{$destinationURL}">Click here</a> to check friendly URLs are working. If you get a 404 then something is wrong.</li> </noscript> HTML; }
} else { $url = $_SERVER["REQUEST_URI"]; } } } // Remove base folders from the URL if webroot is hosted in a subfolder if (substr(strtolower($url), 0, strlen(BASE_URL)) == strtolower(BASE_URL)) { $url = substr($url, strlen(BASE_URL)); } /** * Include SilverStripe's core code */ require_once 'core/startup/ErrorControlChain.php'; require_once 'core/startup/ParameterConfirmationToken.php'; $chain = new ErrorControlChain(); $token = new ParameterConfirmationToken('flush'); $chain->then(function ($chain) use($token) { // First, if $_GET['flush'] was set, but no valid token, suppress the flush if (isset($_GET['flush']) && !$token->tokenProvided()) { unset($_GET['flush']); } else { $chain->setSuppression(false); } // Load in core require_once 'core/Core.php'; // Connect to database require_once 'model/DB.php'; global $databaseConfig; if ($databaseConfig) { DB::connect($databaseConfig); }