2007-08-08 00:19:05 +02:00
|
|
|
<?php
|
|
|
|
|
2007-08-20 02:30:16 +02:00
|
|
|
createHtaccess();
|
2007-08-08 00:19:05 +02:00
|
|
|
|
|
|
|
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
|
if($baseURL == "/") {
|
|
|
|
$baseURL = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($_REQUEST['force'])) {
|
2007-09-28 01:27:47 +02:00
|
|
|
echo "Forced continue, attempting to redirect to <a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a>.
|
|
|
|
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>";
|
2007-08-08 00:19:05 +02:00
|
|
|
} else {
|
|
|
|
$modRewriteWorking = performModRewriteTest();
|
|
|
|
|
|
|
|
if(!$modRewriteWorking) {
|
2007-08-20 02:30:16 +02:00
|
|
|
createHtaccessAlternative();
|
2007-08-08 00:19:05 +02:00
|
|
|
$modRewriteWorking = performModRewriteTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
if($modRewriteWorking) {
|
|
|
|
echo "mod_rewrite is working! I will now try and direct you to
|
2007-09-18 00:00:48 +02:00
|
|
|
<a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a> to confirm that the installation was successful.
|
|
|
|
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
|
2007-08-08 00:19:05 +02:00
|
|
|
";
|
|
|
|
} else {
|
2007-08-20 02:30:16 +02:00
|
|
|
restoreHtaccess();
|
|
|
|
|
2007-08-08 00:19:05 +02:00
|
|
|
echo "mod_rewrite doesn't appear to be working. Make sure:" .
|
|
|
|
"<ul>" .
|
|
|
|
"<li>mod_rewrite is enabled in your httpd.conf</li>" .
|
|
|
|
"<li>AllowOverride is enabled for the current path.</li>" .
|
|
|
|
"</ul>" .
|
|
|
|
"Please check these options, then refresh this page." .
|
|
|
|
"If you believe that your configuration is correct, <a href=\"rewritetest.php?force=1\">click here to proceed anyway.</a>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function performModRewriteTest() {
|
|
|
|
$baseURL = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
|
if($baseURL == "/") {
|
|
|
|
$baseURL = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if mod_rewrite works properly
|
2008-03-07 02:17:15 +01:00
|
|
|
$location = 'http://' . (isset($_SERVER['PHP_AUTH_USER']) ? "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@" : '') . $_SERVER['HTTP_HOST'] . $baseURL . '/InstallerTest/testrewrite';
|
|
|
|
$testrewriting = file_get_contents($location);
|
2007-08-08 00:19:05 +02:00
|
|
|
|
|
|
|
if($testrewriting == 'OK') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Workaround for 'URL file-access is disabled in the server configuration' using curl
|
|
|
|
if(function_exists('curl_init')) {
|
|
|
|
$ch = curl_init($location);
|
2007-08-20 02:30:16 +02:00
|
|
|
$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
|
2007-09-17 03:19:15 +02:00
|
|
|
|
|
|
|
if($fp) {
|
|
|
|
curl_setopt($ch, CURLOPT_FILE, $fp);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
|
curl_exec($ch);
|
|
|
|
curl_close($ch);
|
|
|
|
fclose($fp);
|
|
|
|
$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
|
|
|
|
unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
|
|
|
|
if($testrewriting == 'OK') {
|
|
|
|
return true;
|
|
|
|
}
|
2007-08-08 00:19:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-20 02:30:16 +02:00
|
|
|
|
|
|
|
function createHtaccess() {
|
|
|
|
$start = "### SILVERSTRIPE START ###\n";
|
|
|
|
$end= "\n### SILVERSTRIPE END ###";
|
2008-01-11 00:40:26 +01:00
|
|
|
$base = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
|
|
2007-08-20 02:30:16 +02:00
|
|
|
$rewrite = <<<TEXT
|
|
|
|
RewriteEngine On
|
2008-01-11 00:40:26 +01:00
|
|
|
RewriteBase $base
|
2007-08-20 02:30:16 +02:00
|
|
|
|
2009-07-15 02:01:52 +02:00
|
|
|
RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)
|
2007-08-20 02:30:16 +02:00
|
|
|
|
|
|
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
|
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
|
|
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
|
|
|
|
TEXT
|
|
|
|
;
|
|
|
|
|
|
|
|
if(file_exists('.htaccess')) {
|
|
|
|
$htaccess = file_get_contents('.htaccess');
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
|
|
|
|
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
|
|
|
|
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
|
|
|
|
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createFile('.htaccess', $start . $rewrite . $end);
|
|
|
|
}
|
|
|
|
|
|
|
|
function createHtaccessAlternative() {
|
|
|
|
$start = "### SILVERSTRIPE START ###\n";
|
|
|
|
$end= "\n### SILVERSTRIPE END ###";
|
2008-01-11 00:40:26 +01:00
|
|
|
$base = dirname($_SERVER['SCRIPT_NAME']);
|
|
|
|
|
2007-08-20 02:30:16 +02:00
|
|
|
$rewrite = <<<TEXT
|
|
|
|
RewriteEngine On
|
2008-01-11 00:40:26 +01:00
|
|
|
RewriteBase $base
|
2007-08-20 02:30:16 +02:00
|
|
|
|
2009-07-15 02:01:52 +02:00
|
|
|
RewriteCond %{REQUEST_URI} !(\.gif$)|(\.jpg$)|(\.png$)|(\.css$)|(\.js$)
|
2007-08-20 02:30:16 +02:00
|
|
|
|
|
|
|
RewriteCond %{REQUEST_URI} ^(.*)$
|
|
|
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
|
|
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
|
|
|
|
TEXT
|
|
|
|
;
|
2008-01-11 00:40:26 +01:00
|
|
|
|
2007-08-20 02:30:16 +02:00
|
|
|
if(file_exists('.htaccess')) {
|
|
|
|
$htaccess = file_get_contents('.htaccess');
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
|
|
|
|
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
|
|
|
|
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
|
|
|
|
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createFile('.htaccess', $start . $rewrite . $end);
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreHtaccess() {
|
|
|
|
$start = "### SILVERSTRIPE START ###\n";
|
|
|
|
$end= "\n### SILVERSTRIPE END ###";
|
|
|
|
|
|
|
|
if(file_exists('.htaccess')) {
|
|
|
|
$htaccess = file_get_contents('.htaccess');
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
|
|
|
|
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) {
|
|
|
|
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n";
|
|
|
|
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createFile('.htaccess', $start . $end);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getBaseDir() {
|
|
|
|
return dirname($_SERVER['SCRIPT_FILENAME']) . '/';
|
|
|
|
}
|
|
|
|
|
|
|
|
function createFile($filename, $content) {
|
|
|
|
$base = getBaseDir();
|
|
|
|
if(($fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh))
|
|
|
|
return true;
|
|
|
|
}
|
2007-08-08 00:19:05 +02:00
|
|
|
?>
|