aboutsummaryrefslogtreecommitdiff
path: root/install/ElggRewriteTester.php
diff options
context:
space:
mode:
Diffstat (limited to 'install/ElggRewriteTester.php')
-rw-r--r--install/ElggRewriteTester.php38
1 files changed, 28 insertions, 10 deletions
diff --git a/install/ElggRewriteTester.php b/install/ElggRewriteTester.php
index 7f3501059..ab68da2b7 100644
--- a/install/ElggRewriteTester.php
+++ b/install/ElggRewriteTester.php
@@ -1,19 +1,21 @@
<?php
+
/**
* Elgg RewriteTester.
* Test if URL rewriting is working.
*
- * @package Elgg
+ * @package Elgg.Core
* @subpackage Installer
*/
-
-
class ElggRewriteTester {
protected $webserver;
protected $serverSupportsRemoteRead;
protected $rewriteTestPassed;
protected $htaccessIssue;
+ /**
+ * Set the webserver as unknown.
+ */
public function __construct() {
$this->webserver = 'unknown';
}
@@ -21,13 +23,14 @@ class ElggRewriteTester {
/**
* Run the rewrite test and return a status array
*
- * @param string $url URL of rewrite test
+ * @param string $url URL of rewrite test
* @param string $path Root directory of Elgg with trailing slash
+ *
* @return array
*/
public function run($url, $path) {
- $this->guessWebServer();
+ $this->webserver = ElggRewriteTester::guessWebServer();
$this->rewriteTestPassed = $this->runRewriteTest($url);
@@ -44,22 +47,25 @@ class ElggRewriteTester {
/**
* Guess the web server from $_SERVER['SERVER_SOFTWARE']
+ *
+ * @return string
*/
- protected function guessWebServer() {
+ public static function guessWebServer() {
$serverString = strtolower($_SERVER['SERVER_SOFTWARE']);
$possibleServers = array('apache', 'nginx', 'lighttpd', 'iis');
foreach ($possibleServers as $server) {
if (strpos($serverString, $server) !== FALSE) {
- $this->webserver = $server;
- return;
+ return $server;
}
}
+ return 'unknown';
}
/**
* Hit the rewrite test URL to determine if the rewrite rules are working
*
* @param string $url Rewrite test URL
+ *
* @return bool
*/
protected function runRewriteTest($url) {
@@ -72,6 +78,7 @@ class ElggRewriteTester {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
return $response === 'success';
@@ -89,9 +96,10 @@ class ElggRewriteTester {
* Create Elgg's .htaccess file or confirm that it exists
*
* @param string $path Elgg's root directory with trailing slash
+ *
* @return bool
*/
- protected function createHtaccess($path) {
+ public function createHtaccess($path) {
$filename = "{$path}.htaccess";
if (file_exists($filename)) {
// check that this is the Elgg .htaccess
@@ -105,6 +113,11 @@ class ElggRewriteTester {
$this->htaccessIssue = 'non_elgg_htaccess';
return FALSE;
} else {
+ // check if this is an old Elgg htaccess
+ if (strpos($data, 'RewriteRule ^rewrite.php$ install.php') == FALSE) {
+ $this->htaccessIssue = 'old_elgg_htaccess';
+ return FALSE;
+ }
return TRUE;
}
}
@@ -128,6 +141,7 @@ class ElggRewriteTester {
* Create the status array required by the ElggInstaller
*
* @param string $url Rewrite test URL
+ *
* @return array
*/
protected function returnStatus($url) {
@@ -139,7 +153,9 @@ class ElggRewriteTester {
}
if ($this->serverSupportsRemoteRead == FALSE) {
- $msg = sprintf(elgg_echo('install:warning:rewrite:unknown'), $url);
+ $msg = elgg_echo('install:warning:rewrite:unknown', array($url));
+ $msg .= elgg_view('install/js_rewrite_check', array('url' => $url));
+
return array(
'severity' => 'warning',
'message' => $msg,
@@ -151,6 +167,8 @@ class ElggRewriteTester {
$msg = "$serverString\n\n";
if (!isset($this->htaccessIssue)) {
$msg .= elgg_echo('install:error:rewrite:allowoverride');
+ $msg .= elgg_view('install/js_rewrite_check', array('url' => $url));
+
return array(
'severity' => 'failure',
'message' => $msg,