Improved file can-write checking on Windows (IIS, in particular)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/phpinstaller/branches/2.3@66314 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
sminnee 2008-11-20 20:01:01 +00:00 committed by Sam Minnee
parent 8aa321743b
commit 292343da48

View File

@ -1,1075 +1,1078 @@
<?php <?php
/** /**
* SilverStripe CMS Installer * SilverStripe CMS Installer
* This installer doesn't use any of the fancy Sapphire stuff in case it's unsupported. * This installer doesn't use any of the fancy Sapphire stuff in case it's unsupported.
*/ */
ini_set('max_execution_time', 0); ini_set('max_execution_time', 0);
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
session_start(); session_start();
// Include environment files // Include environment files
$usingEnv = false; $usingEnv = false;
$envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php'); $envFiles = array('_ss_environment.php', '../_ss_environment.php', '../../_ss_environment.php');
foreach($envFiles as $envFile) { foreach($envFiles as $envFile) {
if(@file_exists($envFile)) { if(@file_exists($envFile)) {
include_once($envFile); include_once($envFile);
$usingEnv = true; $usingEnv = true;
break; break;
} }
} }
// Load database config
if(isset($_REQUEST['mysql'])) { // Load database config
$databaseConfig = $_REQUEST['mysql']; if(isset($_REQUEST['mysql'])) {
} else { $databaseConfig = $_REQUEST['mysql'];
$_REQUEST['mysql'] = $databaseConfig = array( } else {
"type" => "MySQLDatabase", $_REQUEST['mysql'] = $databaseConfig = array(
"server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost", "type" => "MySQLDatabase",
"username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root", "server" => defined('SS_DATABASE_SERVER') ? SS_DATABASE_SERVER : "localhost",
"password" => defined('SS_DATABASE_PASSWORD') ? SS_DATABASE_PASSWORD : "", "username" => defined('SS_DATABASE_USERNAME') ? SS_DATABASE_USERNAME : "root",
"database" => isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : "SS_mysite", "password" => defined('SS_DATABASE_PASSWORD') ? SS_DATABASE_PASSWORD : "",
); "database" => isset($_SERVER['argv'][2]) ? $_SERVER['argv'][2] : "SS_mysite",
} );
}
if(isset($_REQUEST['admin'])) {
$adminConfig = $_REQUEST['admin']; if(isset($_REQUEST['admin'])) {
} else { $adminConfig = $_REQUEST['admin'];
$_REQUEST['admin'] = $adminConfig = array( } else {
'username' => 'admin', $_REQUEST['admin'] = $adminConfig = array(
'password' => 'password', 'username' => 'admin',
'firstname' => '', 'password' => 'password',
'surname' => '' 'firstname' => '',
); 'surname' => ''
} );
}
$alreadyInstalled = false;
if(file_exists('mysite/_config.php')) { $alreadyInstalled = false;
// Find the $database variable in the relevant config file without having to execute the config file if(file_exists('mysite/_config.php')) {
if(preg_match("/\\\$database\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) { // Find the $database variable in the relevant config file without having to execute the config file
eval($parts[0]); if(preg_match("/\\\$database\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) {
if($database) $alreadyInstalled = true; eval($parts[0]);
// Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has if($database) $alreadyInstalled = true;
// already gone ahead // Assume that if $databaseConfig is defined in mysite/_config.php, then a non-environment-based installation has
} else if(preg_match("/\\\$databaseConfig\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) { // already gone ahead
$alreadyInstalled = true; } else if(preg_match("/\\\$databaseConfig\s*=\s*[^\n\r]+[\n\r]/", file_get_contents("mysite/_config.php"), $parts)) {
} $alreadyInstalled = true;
}
}
}
if(file_exists('sapphire/silverstripe_version')) {
$sapphireVersionFile = file_get_contents('sapphire/silverstripe_version'); if(file_exists('sapphire/silverstripe_version')) {
if(strstr($sapphireVersionFile, "/sapphire/trunk")) { $sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
$silverstripe_version = "trunk"; if(strstr($sapphireVersionFile, "/sapphire/trunk")) {
} else { $silverstripe_version = "trunk";
preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches); } else {
$silverstripe_version = $matches[1]; preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches);
} $silverstripe_version = $matches[1];
} else { }
$silverstripe_version = "unknown"; } else {
} $silverstripe_version = "unknown";
}
// Check requirements
$req = new InstallRequirements(); // Check requirements
$req->check(); $req = new InstallRequirements();
$req->check();
if($req->hasErrors()) {
$hasErrorOtherThanDatabase = true; if($req->hasErrors()) {
} $hasErrorOtherThanDatabase = true;
}
if($databaseConfig) {
$dbReq = new InstallRequirements(); if($databaseConfig) {
$dbReq->checkdatabase($databaseConfig); $dbReq = new InstallRequirements();
} $dbReq->checkdatabase($databaseConfig);
}
// Actual processor
$installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install'); // Actual processor
$installFromCli = (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'install');
// CLI-install error message. exit(1) will halt any makefile.
if($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) { // CLI-install error message. exit(1) will halt any makefile.
echo "Cannot install due to errors:\n"; if($installFromCli && ($req->hasErrors() || $dbReq->hasErrors())) {
$req->listErrors(); echo "Cannot install due to errors:\n";
$dbReq->listErrors(); $req->listErrors();
exit(1); $dbReq->listErrors();
} exit(1);
}
if(isset($_REQUEST['go']) || $installFromCli && !$req->hasErrors() && !$dbReq->hasErrors()) {
// Confirm before reinstalling if(isset($_REQUEST['go']) || $installFromCli && !$req->hasErrors() && !$dbReq->hasErrors()) {
if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) { // Confirm before reinstalling
include('config-form.html'); if(!isset($_REQUEST['force_reinstall']) && !$installFromCli && $alreadyInstalled) {
include('config-form.html');
} else {
$inst = new Installer(); } else {
if($_REQUEST) $inst->install($_REQUEST); $inst = new Installer();
else $inst->install(array( if($_REQUEST) $inst->install($_REQUEST);
'database' => $databaseConfig['type'], else $inst->install(array(
'mysql' => $databaseConfig, 'database' => $databaseConfig['type'],
'admin' => $adminConfig, 'mysql' => $databaseConfig,
)); 'admin' => $adminConfig,
} ));
}
// Show the config form
} else { // Show the config form
include('config-form.html'); } else {
} include('config-form.html');
}
/**
* This class checks requirements /**
* Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array * This class checks requirements
* of 3 parts: * Each of the requireXXX functions takes an argument which gives a user description of the test. It's an array
* $description[0] - The test catetgory * of 3 parts:
* $description[1] - The test title * $description[0] - The test catetgory
* $description[2] - The test error to show, if it goes wrong * $description[1] - The test title
*/ * $description[2] - The test error to show, if it goes wrong
*/
class InstallRequirements {
var $errors, $warnings, $tests; class InstallRequirements {
var $errors, $warnings, $tests;
/**
* Just check that the database configuration is okay /**
*/ * Just check that the database configuration is okay
function checkdatabase($databaseConfig) { */
if($this->requireFunction('mysql_connect', array("PHP Configuration", "MySQL support", "MySQL support not included in PHP."))) { function checkdatabase($databaseConfig) {
$this->requireMySQLServer($databaseConfig['server'], array("MySQL Configuration", "Does the server exist", if($this->requireFunction('mysql_connect', array("PHP Configuration", "MySQL support", "MySQL support not included in PHP."))) {
"Can't find the a MySQL server on '$databaseConfig[server]'", $databaseConfig['server'])); $this->requireMySQLServer($databaseConfig['server'], array("MySQL Configuration", "Does the server exist",
if($this->requireMysqlConnection($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], "Can't find the a MySQL server on '$databaseConfig[server]'", $databaseConfig['server']));
array("MySQL Configuration", "Are the access credentials correct", "That username/password doesn't work"))) { if($this->requireMysqlConnection($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'],
@$this->requireMySQLVersion("4.1", array("MySQL Configuration", "MySQL version at least 4.1", "MySQL version 4.1 is required, you only have ", "MySQL " . mysql_get_server_info())); array("MySQL Configuration", "Are the access credentials correct", "That username/password doesn't work"))) {
} @$this->requireMySQLVersion("4.1", array("MySQL Configuration", "MySQL version at least 4.1", "MySQL version 4.1 is required, you only have ", "MySQL " . mysql_get_server_info()));
$this->requireDatabaseOrCreatePermissions($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'], }
array("MySQL Configuration", "Can I access/create the database", "I can't create new databases and the database '$databaseConfig[database]' doesn't exist")); $this->requireDatabaseOrCreatePermissions($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database'],
} array("MySQL Configuration", "Can I access/create the database", "I can't create new databases and the database '$databaseConfig[database]' doesn't exist"));
} }
}
/**
* Check everything except the database /**
*/ * Check everything except the database
function check() { */
$this->errors = null; function check() {
$this->errors = null;
$this->requirePHPVersion('5.2.0', '5.0.4', array("PHP Configuration", "PHP5 installed", null, "PHP version " . phpversion()));
$this->requirePHPVersion('5.2.0', '5.0.4', array("PHP Configuration", "PHP5 installed", null, "PHP version " . phpversion()));
// Check that we can identify the root folder successfully
$this->requireFile('config-form.html', array("File permissions", // Check that we can identify the root folder successfully
"Does the webserver know where files are stored?", $this->requireFile('config-form.html', array("File permissions",
"The webserver isn't letting me identify where files are stored.", "Does the webserver know where files are stored?",
$this->getBaseDir() "The webserver isn't letting me identify where files are stored.",
)); $this->getBaseDir()
$this->requireFile('mysite', array("File permissions", "mysite/ folder exists", "There's no mysite folder.")); ));
$this->requireFile('sapphire', array("File permissions", "sapphire/ folder exists", "There's no sapphire folder.")); $this->requireFile('mysite', array("File permissions", "mysite/ folder exists", "There's no mysite folder."));
$this->requireFile('cms', array("File permissions", "cms/ folder exists", "There's no cms folder.")); $this->requireFile('sapphire', array("File permissions", "sapphire/ folder exists", "There's no sapphire folder."));
$this->requireFile('jsparty', array("File permissions", "jsparty/ folder exists", "There's no jsparty folder.")); $this->requireFile('cms', array("File permissions", "cms/ folder exists", "There's no cms folder."));
$this->requireWriteable('.htaccess', array("File permissions", "Is the .htaccess file writeable?", null)); $this->requireFile('jsparty', array("File permissions", "jsparty/ folder exists", "There's no jsparty folder."));
$this->requireWriteable('mysite/_config.php', array("File permissions", "Is the mysite/_config.php file writeable?", null)); $this->requireWriteable('.htaccess', array("File permissions", "Is the .htaccess file writeable?", null));
$this->requireWriteable('assets', array("File permissions", "Is the assets/ folder writeable?", null)); $this->requireWriteable('mysite/_config.php', array("File permissions", "Is the mysite/_config.php file writeable?", null));
$this->requireWriteable('assets', array("File permissions", "Is the assets/ folder writeable?", null));
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null));
$this->requireTempFolder(array('File permissions', 'Is the temporary folder writeable?', null));
// Check for web server, unless we're calling the installer from the command-line
if(!isset($_SERVER['argv']) || !$_SERVER['argv']) { // Check for web server, unless we're calling the installer from the command-line
$webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE'])); if(!isset($_SERVER['argv']) || !$_SERVER['argv']) {
if($webserver == '') { $webserver = strip_tags(trim($_SERVER['SERVER_SIGNATURE']));
$webserver = "I can't tell what webserver you are running"; if($webserver == '') {
} $webserver = "I can't tell what webserver you are running";
}
$this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
if(function_exists('apache_get_modules')) { $this->isRunningApache(array("Webserver Configuration", "Server software", "$webserver. Without Apache I can't tell if mod_rewrite is enabled.", $webserver));
$this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled.")); if(function_exists('apache_get_modules')) {
} else { $this->requireApacheModule('mod_rewrite', array("Webserver Configuration", "mod_rewrite enabled", "You need mod_rewrite to run SilverStripe CMS, but it is not enabled."));
$this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself.")); } else {
} $this->warning(array("Webserver Configuration", "mod_rewrite enabled", "I can't tell whether mod_rewrite is running. You may need to configure a rewriting rule yourself."));
}
$this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
} $this->requireServerVariables(array('SCRIPT_NAME','HTTP_HOST','SCRIPT_FILENAME'), array("Webserver config", "Recognised webserver", "You seem to be using an unsupported webserver. The server variables SCRIPT_NAME, HTTP_HOST, SCRIPT_FILENAME need to be set."));
}
// Check for GD support
if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) { // Check for GD support
$this->requireFunction("imagecreate", array("PHP Configuration", "GD2 support", "GD support for PHP not included.")); if(!$this->requireFunction("imagecreatetruecolor", array("PHP Configuration", "GD2 support", "PHP must have GD version 2."))) {
} $this->requireFunction("imagecreate", array("PHP Configuration", "GD2 support", "GD support for PHP not included."));
}
// Check for XML support
$this->requireFunction('xml_set_object', array("PHP Configuration", "XML support", "XML support not included in PHP.")); // Check for XML support
$this->requireFunction('xml_set_object', array("PHP Configuration", "XML support", "XML support not included in PHP."));
// Check for MySQL support
$this->requireFunction('mysql_connect', array("PHP Configuration", "MySQL support", "MySQL support not included in PHP.")); // Check for MySQL support
$this->requireFunction('mysql_connect', array("PHP Configuration", "MySQL support", "MySQL support not included in PHP."));
// Check memory allocation
$this->requireMemory(32*1024*1024, 64*1024*1024, array("PHP Configuration", "Memory allocated (PHP config option 'memory_limit')", "SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.", ini_get("memory_limit"))); // Check memory allocation
$this->requireMemory(32*1024*1024, 64*1024*1024, array("PHP Configuration", "Memory allocated (PHP config option 'memory_limit')", "SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.", ini_get("memory_limit")));
// Check allow_call_time_pass_reference
$this->suggestPHPSetting('allow_call_time_pass_reference', array(1,'1','on','On'), array("PHP Configuration", "Check that the php.ini setting allow_call_time_pass_reference is on", // Check allow_call_time_pass_reference
"You can install with allow_call_time_pass_reference not set, but some warnings may get displayed. For best results, turn it on.")); $this->suggestPHPSetting('allow_call_time_pass_reference', array(1,'1','on','On'), array("PHP Configuration", "Check that the php.ini setting allow_call_time_pass_reference is on",
"You can install with allow_call_time_pass_reference not set, but some warnings may get displayed. For best results, turn it on."));
return $this->errors;
} return $this->errors;
}
function suggestPHPSetting($settingName, $settingValues, $testDetails) {
$this->testing($testDetails); function suggestPHPSetting($settingName, $settingValues, $testDetails) {
$this->testing($testDetails);
$val = ini_get($settingName);
if(!in_array($val, $settingValues) && $val != $settingValues) { $val = ini_get($settingName);
$testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]"; if(!in_array($val, $settingValues) && $val != $settingValues) {
$this->warning($testDetails); $testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]";
} $this->warning($testDetails);
} }
}
function requireMemory($min, $recommended, $testDetails) {
$_SESSION['forcemem'] = false; function requireMemory($min, $recommended, $testDetails) {
$_SESSION['forcemem'] = false;
$mem = $this->getPHPMemory();
if($mem < (64 * 1024 * 1024)) { $mem = $this->getPHPMemory();
ini_set('memory_limit', '64M'); if($mem < (64 * 1024 * 1024)) {
$mem = $this->getPHPMemory(); ini_set('memory_limit', '64M');
$testDetails[3] = ini_get("memory_limit"); $mem = $this->getPHPMemory();
} $testDetails[3] = ini_get("memory_limit");
}
$this->testing($testDetails);
$this->testing($testDetails);
if($mem < $min && $mem > 0) {
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated"; if($mem < $min && $mem > 0) {
$this->error($testDetails); $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
} else if($mem < $recommended && $mem > 0) { $this->error($testDetails);
$testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated"; } else if($mem < $recommended && $mem > 0) {
$this->warning($testDetails); $testDetails[2] .= " You only have " . ini_get("memory_limit") . " allocated";
} elseif($mem == 0) { $this->warning($testDetails);
$testDetails[2] .= " We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least 20 MB."; } elseif($mem == 0) {
$this->warning($testDetails); $testDetails[2] .= " We can't determine how much memory you have allocated. Install only if you're sure you've allocated at least 20 MB.";
} $this->warning($testDetails);
} }
}
function getPHPMemory() {
$memString = ini_get("memory_limit"); function getPHPMemory() {
$memString = ini_get("memory_limit");
switch(strtolower(substr($memString,-1))) {
case "k": switch(strtolower(substr($memString,-1))) {
return round(substr($memString,0,-1)*1024); case "k":
return round(substr($memString,0,-1)*1024);
case "m":
return round(substr($memString,0,-1)*1024*1024); case "m":
return round(substr($memString,0,-1)*1024*1024);
case "g":
return round(substr($memString,0,-1)*1024*1024*1024); case "g":
return round(substr($memString,0,-1)*1024*1024*1024);
default:
return round($memString); default:
} return round($memString);
} }
}
function listErrors() {
if($this->errors) { function listErrors() {
echo "<p>The following problems are preventing me from installing SilverStripe CMS:</p>\n\n"; if($this->errors) {
foreach($this->errors as $error) { echo "<p>The following problems are preventing me from installing SilverStripe CMS:</p>\n\n";
echo "<li>" . htmlentities(implode(", ", $error)) . "</li>\n"; foreach($this->errors as $error) {
} echo "<li>" . htmlentities(implode(", ", $error)) . "</li>\n";
} }
} }
}
function showTable($section = null) {
if($section) { function showTable($section = null) {
$tests = $this->tests[$section]; if($section) {
echo "<table class=\"testResults\" width=\"100%\">"; $tests = $this->tests[$section];
foreach($tests as $test => $result) { echo "<table class=\"testResults\" width=\"100%\">";
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>"; foreach($tests as $test => $result) {
} echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
echo "</table>"; }
echo "</table>";
} else {
foreach($this->tests as $section => $tests) { } else {
echo "<h5>$section</h5>"; foreach($this->tests as $section => $tests) {
echo "<table class=\"testResults\">"; echo "<h5>$section</h5>";
echo "<table class=\"testResults\">";
foreach($tests as $test => $result) {
echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>"; foreach($tests as $test => $result) {
} echo "<tr class=\"$result[0]\"><td>$test</td><td>" . nl2br(htmlentities($result[1])) . "</td></tr>";
echo "</table>"; }
} echo "</table>";
} }
} }
}
function showInstallStatus() {
if($this->warnings) { function showInstallStatus() {
echo "I have installed SilverStripe CMS, however, you should note the following:"; if($this->warnings) {
foreach($this->warnings as $warning) { echo "I have installed SilverStripe CMS, however, you should note the following:";
echo "<li>" . htmlentities($warning) . "</li>"; foreach($this->warnings as $warning) {
} echo "<li>" . htmlentities($warning) . "</li>";
} else { }
if(isset($_SERVER['HTTP_HOST'])) { } else {
?> if(isset($_SERVER['HTTP_HOST'])) {
<p>I have installed SilverStripe CMS successfully!</p> ?>
<p><a href="./admin/" target="_blank">Open the CMS tool</a><br /> <p>I have installed SilverStripe CMS successfully!</p>
<a href="./" target="_blank">Open the site</a></p> <p><a href="./admin/" target="_blank">Open the CMS tool</a><br />
<?php <a href="./" target="_blank">Open the site</a></p>
} else { <?php
echo "\nSilverStripe successfully installed\n"; } else {
} echo "\nSilverStripe successfully installed\n";
} }
} }
}
function requireFunction($funcName, $testDetails) {
$this->testing($testDetails); function requireFunction($funcName, $testDetails) {
if(!function_exists($funcName)) $this->error($testDetails); $this->testing($testDetails);
else return true; if(!function_exists($funcName)) $this->error($testDetails);
} else return true;
}
function requirePHPVersion($recommendedVersion, $requiredVersion, $testDetails) {
$this->testing($testDetails); function requirePHPVersion($recommendedVersion, $requiredVersion, $testDetails) {
$this->testing($testDetails);
list($recA, $recB, $recC) = explode('.', $recommendedVersion);
list($reqA, $reqB, $reqC) = explode('.', $requiredVersion); list($recA, $recB, $recC) = explode('.', $recommendedVersion);
list($a, $b, $c) = explode('.', phpversion()); list($reqA, $reqB, $reqC) = explode('.', $requiredVersion);
$c = ereg_replace('-.*$','',$c); list($a, $b, $c) = explode('.', phpversion());
$c = ereg_replace('-.*$','',$c);
if($a > $recA || ($a == $recA && $b > $recB) || ($a == $reqA && $b == $reqB && $c >= $reqC)) {
$testDetails[2] = "SilverStripe recommends PHP version $recommendedVersion or later, only $a.$b.$c is installed. While SilverStripe should run, you may run into issues, and future versions of SilverStripe may require a later version. Upgrading PHP is recommended."; if($a > $recA || ($a == $recA && $b > $recB) || ($a == $reqA && $b == $reqB && $c >= $reqC)) {
$this->warning($testDetails); $testDetails[2] = "SilverStripe recommends PHP version $recommendedVersion or later, only $a.$b.$c is installed. While SilverStripe should run, you may run into issues, and future versions of SilverStripe may require a later version. Upgrading PHP is recommended.";
return; $this->warning($testDetails);
} return;
}
if($a > $reqA) return true;
if($a == $reqA && $b > $reqB) return true; if($a > $reqA) return true;
if($a == $reqA && $b == $reqB && $c >= $reqC) return true; if($a == $reqA && $b > $reqB) return true;
if($a == $reqA && $b == $reqB && $c >= $reqC) return true;
if(!$testDetails[2]) {
if($a < $reqA) { if(!$testDetails[2]) {
$testDetails[2] = "You need PHP version $version or later, only $a.$b.$c is installed. Unfortunately PHP$a and PHP$reqA have some incompatabilities, so if you are on a your web-host may need to move you to a different server. Some software doesn't work with PHP5 and so upgrading a shared server could be problematic."; if($a < $reqA) {
} else { $testDetails[2] = "You need PHP version $version or later, only $a.$b.$c is installed. Unfortunately PHP$a and PHP$reqA have some incompatabilities, so if you are on a your web-host may need to move you to a different server. Some software doesn't work with PHP5 and so upgrading a shared server could be problematic.";
$testDetails[2] = "You need PHP version $requiredVersion or later, only $a.$b.$c is installed. Please upgrade your server, or ask your web-host to do so."; } else {
} $testDetails[2] = "You need PHP version $requiredVersion or later, only $a.$b.$c is installed. Please upgrade your server, or ask your web-host to do so.";
} }
}
$this->error($testDetails);
} $this->error($testDetails);
}
function requireFile($filename, $testDetails) {
$this->testing($testDetails); function requireFile($filename, $testDetails) {
$filename = $this->getBaseDir() . $filename; $this->testing($testDetails);
if(!file_exists($filename)) { $filename = $this->getBaseDir() . $filename;
$testDetails[2] .= " (file '$filename' not found)"; if(!file_exists($filename)) {
$this->error($testDetails); $testDetails[2] .= " (file '$filename' not found)";
} $this->error($testDetails);
} }
function requireNoFile($filename, $testDetails) { }
$this->testing($testDetails); function requireNoFile($filename, $testDetails) {
$filename = $this->getBaseDir() . $filename; $this->testing($testDetails);
if(file_exists($filename)) { $filename = $this->getBaseDir() . $filename;
$testDetails[2] .= " (file '$filename' found)"; if(file_exists($filename)) {
$this->error($testDetails); $testDetails[2] .= " (file '$filename' found)";
} $this->error($testDetails);
} }
function moveFileOutOfTheWay($filename, $testDetails) { }
$this->testing($testDetails); function moveFileOutOfTheWay($filename, $testDetails) {
$filename = $this->getBaseDir() . $filename; $this->testing($testDetails);
if(file_exists($filename)) { $filename = $this->getBaseDir() . $filename;
if(file_exists("$filename.bak")) rm("$filename.bak"); if(file_exists($filename)) {
rename($filename, "$filename.bak"); if(file_exists("$filename.bak")) rm("$filename.bak");
} rename($filename, "$filename.bak");
} }
}
function requireWriteable($filename, $testDetails) {
$this->testing($testDetails); function requireWriteable($filename, $testDetails) {
$filename = $this->getBaseDir() . $filename; $this->testing($testDetails);
$filename = $this->getBaseDir() . str_replace("/", DIRECTORY_SEPARATOR,$filename);
if(function_exists('posix_getgroups')) {
if(!is_writeable($filename)) { if(!is_writeable($filename)) {
$user = posix_getpwuid(posix_geteuid()); if(function_exists('posix_getgroups')) {
$groups = posix_getgroups(); $user = posix_getpwuid(posix_geteuid());
foreach($groups as $group) { $groups = posix_getgroups();
$groupInfo = posix_getgrgid($group); foreach($groups as $group) {
$groupList[] = $groupInfo['name']; $groupInfo = posix_getgrgid($group);
} $groupList[] = $groupInfo['name'];
$groupList = "'" . implode("', '", $groupList) . "'"; }
$groupList = "'" . implode("', '", $groupList) . "'"; }
$testDetails[2] .= "User '$user[name]' needs to be able to write to this file:\n$filename";
$this->error($testDetails); $testDetails[2] .= "User '$user[name]' needs to be able to write to this file:\n$filename";
} $this->error($testDetails);
} else { }
$testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable."; /*
$this->warning($testDetails); } else {
} $testDetails[2] .= "Unable to detect whether I can write to files. Please ensure $filename is writable.";
} $this->warning($testDetails);
}
function requireTempFolder($testDetails) { */
$this->testing($testDetails); }
if(function_exists('sys_get_temp_dir')) { function requireTempFolder($testDetails) {
$sysTmp = sys_get_temp_dir(); $this->testing($testDetails);
} elseif(isset($_ENV['TMP'])) {
$sysTmp = $_ENV['TMP']; if(function_exists('sys_get_temp_dir')) {
} else { $sysTmp = sys_get_temp_dir();
@$tmpFile = tempnam('adfadsfdas',''); } elseif(isset($_ENV['TMP'])) {
@unlink($tmpFile); $sysTmp = $_ENV['TMP'];
$sysTmp = dirname($tmpFile); } else {
} @$tmpFile = tempnam('adfadsfdas','');
@unlink($tmpFile);
$worked = true; $sysTmp = dirname($tmpFile);
$ssTmp = "$sysTmp/silverstripe-cache"; }
if(!@file_exists($ssTmp)) { $worked = true;
@$worked = mkdir($ssTmp); $ssTmp = "$sysTmp/silverstripe-cache";
if(!$worked) { if(!@file_exists($ssTmp)) {
$ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache"; @$worked = mkdir($ssTmp);
$worked = true;
if(!@file_exists($ssTmp)) { if(!$worked) {
@$worked = mkdir($ssTmp); $ssTmp = dirname($_SERVER['SCRIPT_FILENAME']) . "/silverstripe-cache";
} $worked = true;
if(!$worked) { if(!@file_exists($ssTmp)) {
$testDetails[2] = "Permission problem gaining access to a temp folder. " . @$worked = mkdir($ssTmp);
"Please create a folder named silverstripe-cache in the base folder " . }
"of the installation and ensure it has the adequate permissions"; if(!$worked) {
$this->error($testDetails); $testDetails[2] = "Permission problem gaining access to a temp folder. " .
} "Please create a folder named silverstripe-cache in the base folder " .
} "of the installation and ensure it has the adequate permissions";
} $this->error($testDetails);
} }
}
function requireApacheModule($moduleName, $testDetails) { }
$this->testing($testDetails); }
if(!in_array($moduleName, apache_get_modules())) $this->error($testDetails);
} function requireApacheModule($moduleName, $testDetails) {
$this->testing($testDetails);
function requireMysqlConnection($server, $username, $password, $testDetails) { if(!in_array($moduleName, apache_get_modules())) $this->error($testDetails);
$this->testing($testDetails); }
$conn = @mysql_connect($server, $username, $password);
function requireMysqlConnection($server, $username, $password, $testDetails) {
if($conn) { $this->testing($testDetails);
return true; $conn = @mysql_connect($server, $username, $password);
/*
if(mysql_query("CREATE DATABASE testing123")) { if($conn) {
mysql_query("DROP DATABASE testing123"); return true;
return true; /*
} else { if(mysql_query("CREATE DATABASE testing123")) {
$testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)"; mysql_query("DROP DATABASE testing123");
$this->error($testDetails); return true;
} } else {
*/ $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
} else { $this->error($testDetails);
$testDetails[2] .= ": " . mysql_error(); }
$this->error($testDetails); */
} } else {
} $testDetails[2] .= ": " . mysql_error();
$this->error($testDetails);
function requireMySQLServer($server, $testDetails) { }
$this->testing($testDetails); }
$conn = @mysql_connect($server, null, null);
function requireMySQLServer($server, $testDetails) {
if($conn || mysql_errno() < 2000) { $this->testing($testDetails);
return true; $conn = @mysql_connect($server, null, null);
} else {
$testDetails[2] .= ": " . mysql_error(); if($conn || mysql_errno() < 2000) {
$this->error($testDetails); return true;
} } else {
} $testDetails[2] .= ": " . mysql_error();
$this->error($testDetails);
function requireMySQLVersion($version, $testDetails) { }
$this->testing($testDetails); }
if(!mysql_get_server_info()) { function requireMySQLVersion($version, $testDetails) {
$testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.'; $this->testing($testDetails);
$this->warning($testDetails);
} else { if(!mysql_get_server_info()) {
list($majorRequested, $minorRequested) = explode('.', $version); $testDetails[2] = 'Cannot determine the version of MySQL installed. Please ensure at least version 4.1 is installed.';
$result = mysql_query('SELECT VERSION()'); $this->warning($testDetails);
$row=mysql_fetch_row($result); } else {
$version = ereg_replace("([A-Za-z-])", "", $row[0]); list($majorRequested, $minorRequested) = explode('.', $version);
list($majorHas, $minorHas) = explode('.', substr(trim($version), 0, 3)); $result = mysql_query('SELECT VERSION()');
$row=mysql_fetch_row($result);
if(($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) { $version = ereg_replace("([A-Za-z-])", "", $row[0]);
return true; list($majorHas, $minorHas) = explode('.', substr(trim($version), 0, 3));
} else {
$testDetails[2] .= "{$majorHas}.{$minorHas}."; if(($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) {
$this->error($testDetails); return true;
} } else {
} $testDetails[2] .= "{$majorHas}.{$minorHas}.";
} $this->error($testDetails);
}
}
function requireDatabaseOrCreatePermissions($server, $username, $password, $database, $testDetails) { }
$this->testing($testDetails);
$conn = @mysql_connect($server, $username, $password);
function requireDatabaseOrCreatePermissions($server, $username, $password, $database, $testDetails) {
if(@mysql_select_db($database)) { $this->testing($testDetails);
$okay = "Database '$database' exists"; $conn = @mysql_connect($server, $username, $password);
} else { if(@mysql_select_db($database)) {
if(@mysql_query("CREATE DATABASE testing123")) { $okay = "Database '$database' exists";
mysql_query("DROP DATABASE testing123");
$okay = "Able to create a new database"; } else {
if(@mysql_query("CREATE DATABASE testing123")) {
} else { mysql_query("DROP DATABASE testing123");
$testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)"; $okay = "Able to create a new database";
$this->error($testDetails);
return; } else {
} $testDetails[2] .= " (user '$username' doesn't have CREATE DATABASE permissions.)";
} $this->error($testDetails);
return;
if($okay) { }
$testDetails[3] = $okay; }
$this->testing($testDetails);
} if($okay) {
$testDetails[3] = $okay;
} $this->testing($testDetails);
}
function requireServerVariables($varNames, $errorMessage) {
//$this->testing($testDetails); }
foreach($varNames as $varName) {
if(!$_SERVER[$varName]) $missing[] = '$_SERVER[' . $varName . ']'; function requireServerVariables($varNames, $errorMessage) {
} //$this->testing($testDetails);
if(!isset($missing)) { foreach($varNames as $varName) {
return true; if(!$_SERVER[$varName]) $missing[] = '$_SERVER[' . $varName . ']';
} else { }
$testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")"; if(!isset($missing)) {
$this->error($testDetails); return true;
} } else {
} $testDetails[2] .= " (the following PHP variables are missing: " . implode(", ", $missing) . ")";
$this->error($testDetails);
function isRunningApache($testDetails) { }
$this->testing($testDetails); }
if(function_exists('apache_get_modules') || stristr($_SERVER['SERVER_SIGNATURE'], 'Apache'))
return true; function isRunningApache($testDetails) {
$this->testing($testDetails);
$this->warning($testDetails); if(function_exists('apache_get_modules') || stristr($_SERVER['SERVER_SIGNATURE'], 'Apache'))
return false; return true;
}
$this->warning($testDetails);
return false;
protected $baseDir; }
function getBaseDir() {
// Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method
// still returns the correct value. protected $baseDir;
if(!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . '/'; function getBaseDir() {
return $this->baseDir; // Cache the value so that when the installer mucks with SCRIPT_FILENAME half way through, this method
} // still returns the correct value.
if(!$this->baseDir) $this->baseDir = realpath(dirname($_SERVER['SCRIPT_FILENAME'])) . DIRECTORY_SEPARATOR;
function testing($testDetails) { return $this->baseDir;
if(!$testDetails) return; }
$section = $testDetails[0]; function testing($testDetails) {
$test = $testDetails[1]; if(!$testDetails) return;
$message = "OK"; $section = $testDetails[0];
if(isset($testDetails[3])) $message .= " ($testDetails[3])"; $test = $testDetails[1];
$this->tests[$section][$test] = array("good", $message); $message = "OK";
} if(isset($testDetails[3])) $message .= " ($testDetails[3])";
function error($testDetails) { $this->tests[$section][$test] = array("good", $message);
$section = $testDetails[0]; }
$test = $testDetails[1];
function error($testDetails) {
$this->tests[$section][$test] = array("error", $testDetails[2]); $section = $testDetails[0];
$this->errors[] = $testDetails; $test = $testDetails[1];
} $this->tests[$section][$test] = array("error", $testDetails[2]);
function warning($testDetails) { $this->errors[] = $testDetails;
$section = $testDetails[0];
$test = $testDetails[1]; }
function warning($testDetails) {
$section = $testDetails[0];
$this->tests[$section][$test] = array("warning", $testDetails[2]); $test = $testDetails[1];
$this->warnings[] = $testDetails;
}
$this->tests[$section][$test] = array("warning", $testDetails[2]);
function hasErrors() { $this->warnings[] = $testDetails;
return sizeof($this->errors); }
}
function hasWarnings() { function hasErrors() {
return sizeof($this->warnings); return sizeof($this->errors);
} }
function hasWarnings() {
} return sizeof($this->warnings);
}
class Installer extends InstallRequirements {
function __construct() { }
// Cache the baseDir value
$this->getBaseDir(); class Installer extends InstallRequirements {
} function __construct() {
// Cache the baseDir value
function install($config) { $this->getBaseDir();
if(isset($_SERVER['HTTP_HOST'])) { }
?>
<h1>Installing SilverStripe...</h1> function install($config) {
<p>I am now running through the installation steps (this should take about 30 seconds)</p> if(isset($_SERVER['HTTP_HOST'])) {
<p>If you receive a fatal error, refresh this page to continue the installation ?>
<?php <h1>Installing SilverStripe...</h1>
} else { <p>I am now running through the installation steps (this should take about 30 seconds)</p>
echo "SILVERSTRIPE COMMAND-LINE INSTALLATION\n\n"; <p>If you receive a fatal error, refresh this page to continue the installation
} <?php
} else {
flush(); echo "SILVERSTRIPE COMMAND-LINE INSTALLATION\n\n";
}
if(isset($_POST['stats'])) {
if(file_exists('sapphire/silverstripe_version')) { flush();
$sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
if(strstr($sapphireVersionFile, "/sapphire/trunk")) { if(isset($_POST['stats'])) {
$silverstripe_version = "trunk"; if(file_exists('sapphire/silverstripe_version')) {
} else { $sapphireVersionFile = file_get_contents('sapphire/silverstripe_version');
preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches); if(strstr($sapphireVersionFile, "/sapphire/trunk")) {
$silverstripe_version = $matches[1]; $silverstripe_version = "trunk";
} } else {
} else { preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches);
$silverstripe_version = "unknown"; $silverstripe_version = $matches[1];
} }
} else {
$phpVersion = urlencode(phpversion()); $silverstripe_version = "unknown";
$conn = @mysql_connect($config['mysql']['server'], null, null); }
$databaseVersion = urlencode('MySQL ' . mysql_get_server_info());
$webserver = urlencode($_SERVER['SERVER_SOFTWARE']); $phpVersion = urlencode(phpversion());
$conn = @mysql_connect($config['mysql']['server'], null, null);
$url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver"; $databaseVersion = urlencode('MySQL ' . mysql_get_server_info());
$webserver = urlencode($_SERVER['SERVER_SOFTWARE']);
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
$url .= '&ID=' . $_SESSION['StatsID']; $url = "http://ss2stat.silverstripe.com/Installation/add?SilverStripe=$silverstripe_version&PHP=$phpVersion&Database=$databaseVersion&WebServer=$webserver";
}
if(isset($_SESSION['StatsID']) && $_SESSION['StatsID']) {
@$_SESSION['StatsID'] = file_get_contents($url); $url .= '&ID=' . $_SESSION['StatsID'];
} }
if(file_exists('mysite/_config.php')) { @$_SESSION['StatsID'] = file_get_contents($url);
unlink('mysite/_config.php'); }
}
$theme = isset($_POST['template']) ? $_POST['template'] : 'blackcandy'; if(file_exists('mysite/_config.php')) {
// Write the config file unlink('mysite/_config.php');
global $usingEnv; }
if($usingEnv) { $theme = isset($_POST['template']) ? $_POST['template'] : 'blackcandy';
$this->statusMessage("Creating 'mysite/_config.php' for use with _ss_environment.php..."); // Write the config file
$this->createFile("mysite/_config.php", <<<PHP global $usingEnv;
<?php if($usingEnv) {
$this->statusMessage("Creating 'mysite/_config.php' for use with _ss_environment.php...");
global \$project; $this->createFile("mysite/_config.php", <<<PHP
\$project = 'mysite'; <?php
global \$database; global \$project;
\$database = "{$config['mysql']['database']}"; \$project = 'mysite';
require_once("conf/ConfigureFromEnv.php"); global \$database;
\$database = "{$config['mysql']['database']}";
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/themes/ require_once("conf/ConfigureFromEnv.php");
SSViewer::set_theme('$theme');
// This line set's the current theme. More themes can be
?> // downloaded from http://www.silverstripe.com/themes/
PHP SSViewer::set_theme('$theme');
);
?>
PHP
} else { );
$this->statusMessage("Creating 'mysite/_config.php'...");
$devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites'])); } else {
$this->statusMessage("Creating 'mysite/_config.php'...");
$escapedPassword = addslashes($config['mysql']['password']);
$this->createFile("mysite/_config.php", <<<PHP $devServers = $this->var_export_array_nokeys(explode("\n", $_POST['devsites']));
<?php
$escapedPassword = addslashes($config['mysql']['password']);
global \$project; $this->createFile("mysite/_config.php", <<<PHP
\$project = 'mysite'; <?php
global \$databaseConfig; global \$project;
\$databaseConfig = array( \$project = 'mysite';
"type" => "$config[database]",
"server" => "{$config['mysql']['server']}", global \$databaseConfig;
"username" => "{$config['mysql']['username']}", \$databaseConfig = array(
"password" => "{$escapedPassword}", "type" => "$config[database]",
"database" => "{$config['mysql']['database']}", "server" => "{$config['mysql']['server']}",
); "username" => "{$config['mysql']['username']}",
"password" => "{$escapedPassword}",
// Sites running on the following servers will be "database" => "{$config['mysql']['database']}",
// run in development mode. See );
// http://doc.silverstripe.com/doku.php?id=devmode
// for a description of what dev mode does. // Sites running on the following servers will be
Director::set_dev_servers($devServers); // run in development mode. See
// http://doc.silverstripe.com/doku.php?id=devmode
// This line set's the current theme. More themes can be // for a description of what dev mode does.
// downloaded from http://www.silverstripe.com/themes/ Director::set_dev_servers($devServers);
SSViewer::set_theme('$theme');
// This line set's the current theme. More themes can be
?> // downloaded from http://www.silverstripe.com/themes/
PHP SSViewer::set_theme('$theme');
);
} ?>
PHP
$this->statusMessage("Creating '.htaccess' file..."); );
}
$this->createHtaccess();
$this->statusMessage("Creating '.htaccess' file...");
// Load the sapphire runtime
$_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/sapphire/main.php'; $this->createHtaccess();
chdir('sapphire');
// Load the sapphire runtime
$_GET['flush'] = true; $_SERVER['SCRIPT_FILENAME'] = dirname(realpath($_SERVER['SCRIPT_FILENAME'])) . '/sapphire/main.php';
require_once('core/Core.php'); chdir('sapphire');
$this->statusMessage("Building database schema..."); $_GET['flush'] = true;
require_once('core/Core.php');
// Build database
$con = new Controller(); $this->statusMessage("Building database schema...");
$con->pushCurrent();
// Build database
global $databaseConfig; $con = new Controller();
DB::connect($databaseConfig); $con->pushCurrent();
$dbAdmin = new DatabaseAdmin(); global $databaseConfig;
$dbAdmin->init(); DB::connect($databaseConfig);
$_REQUEST['username'] = $config['admin']['username']; $dbAdmin = new DatabaseAdmin();
$_REQUEST['password'] = $config['admin']['password']; $dbAdmin->init();
$dbAdmin->doBuild(true);
$_REQUEST['username'] = $config['admin']['username'];
$adminmember = DataObject::get_one('Member',"`Email`= '".$_REQUEST['admin']['username']."'"); $_REQUEST['password'] = $config['admin']['password'];
if($adminmember) { $dbAdmin->doBuild(true);
$adminmember->FirstName = $_REQUEST['admin']['firstname'];
$adminmember->Surname = $_REQUEST['admin']['surname']; $adminmember = DataObject::get_one('Member',"`Email`= '".$_REQUEST['admin']['username']."'");
$adminmember->write(); if($adminmember) {
} $adminmember->FirstName = $_REQUEST['admin']['firstname'];
$adminmember->Surname = $_REQUEST['admin']['surname'];
// Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266) $adminmember->write();
FileSystem::sync(); }
if(isset($_SERVER['HTTP_HOST'])) { // Syncing filesystem (so /assets/Uploads is available instantly, see ticket #2266)
$this->statusMessage("Checking mod_rewrite works..."); FileSystem::sync();
$modRewriteWorks = $this->checkModRewrite();
} else { if(isset($_SERVER['HTTP_HOST'])) {
$modRewriteWorks = true; $this->statusMessage("Checking mod_rewrite works...");
} $modRewriteWorks = $this->checkModRewrite();
} else {
$_SESSION['username'] = $config['admin']['username']; $modRewriteWorks = true;
$_SESSION['password'] = $config['admin']['password']; }
if($modRewriteWorks && !$this->errors) { $_SESSION['username'] = $config['admin']['username'];
if(isset($_SERVER['HTTP_HOST'])) { $_SESSION['password'] = $config['admin']['password'];
echo "<p>Installed SilverStripe successfully. I will now try and direct you to
<a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a> to confirm that the installation was successful.</p> if($modRewriteWorks && !$this->errors) {
<script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script> if(isset($_SERVER['HTTP_HOST'])) {
"; echo "<p>Installed SilverStripe successfully. I will now try and direct you to
} else { <a href=\"home/successfullyinstalled?flush=1\">home/successfullyinstalled</a> to confirm that the installation was successful.</p>
echo "\nSilverStripe successfully installed\n"; <script>setTimeout(function() { window.location.href = 'home/successfullyinstalled?flush=1'; }, 1000);</script>
} ";
} } else {
echo "\nSilverStripe successfully installed\n";
return $this->errors; }
} }
function makeFolder($folder) { return $this->errors;
$base = $this->getBaseDir(); }
if(!file_exists($base . $folder)) {
if(!mkdir($base . $folder, 02775)) { function makeFolder($folder) {
$this->error("Couldn't create a folder called $base$folder"); $base = $this->getBaseDir();
} else { if(!file_exists($base . $folder)) {
chmod($base . $folder, 02775); if(!mkdir($base . $folder, 02775)) {
} $this->error("Couldn't create a folder called $base$folder");
} } else {
} chmod($base . $folder, 02775);
}
function renameFolder($oldName, $newName) { }
if($oldName == $newName) return true; }
$base = $this->getBaseDir(); function renameFolder($oldName, $newName) {
if(!rename($base . $oldName, $base . $newName)) { if($oldName == $newName) return true;
$this->error("Couldn't rename $base$oldName to $base$newName");
return false; $base = $this->getBaseDir();
} else { if(!rename($base . $oldName, $base . $newName)) {
return true; $this->error("Couldn't rename $base$oldName to $base$newName");
} return false;
} } else {
return true;
function copyFolder($oldName, $newName) { }
if($oldName == $newName) return true; }
$base = $this->getBaseDir(); function copyFolder($oldName, $newName) {
if(!copyr($base . $oldName, $base . $newName)) { if($oldName == $newName) return true;
$this->error("Couldn't rename $base$oldName to $base$newName");
return false; $base = $this->getBaseDir();
} else { if(!copyr($base . $oldName, $base . $newName)) {
return true; $this->error("Couldn't rename $base$oldName to $base$newName");
} return false;
} } else {
return true;
}
function createFile($filename, $content) { }
$base = $this->getBaseDir();
$this->statusMessage("Creating $base$filename");
function createFile($filename, $content) {
if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) { $base = $this->getBaseDir();
return true; $this->statusMessage("Creating $base$filename");
} else {
$this->error("Couldn't write to file $base$filename"); if((@$fh = fopen($base . $filename, 'w')) && fwrite($fh, $content) && fclose($fh)) {
} return true;
} } else {
$this->error("Couldn't write to file $base$filename");
function createHtaccess() { }
$start = "### SILVERSTRIPE START ###\n"; }
$end = "\n### SILVERSTRIPE END ###";
function createHtaccess() {
$base = dirname($_SERVER['SCRIPT_NAME']); $start = "### SILVERSTRIPE START ###\n";
if(defined('DIRECTORY_SEPARATOR')) $base = str_replace(DIRECTORY_SEPARATOR, '/', $base); $end = "\n### SILVERSTRIPE END ###";
else $base = str_replace("\\", '/', $base);
$base = dirname($_SERVER['SCRIPT_NAME']);
if($base != '.') $baseClause = "RewriteBase $base\n"; if(defined('DIRECTORY_SEPARATOR')) $base = str_replace(DIRECTORY_SEPARATOR, '/', $base);
else $baseClause = ""; else $base = str_replace("\\", '/', $base);
$rewrite = <<<TEXT if($base != '.') $baseClause = "RewriteBase $base\n";
<IfModule mod_dir.c> else $baseClause = "";
DirectorySlash Off
</IfModule> $rewrite = <<<TEXT
<IfModule mod_dir.c>
<Files *.ss> DirectorySlash Off
Order deny,allow </IfModule>
Deny from all
Allow from 127.0.0.1 <Files *.ss>
</Files> Order deny,allow
Deny from all
RewriteEngine On Allow from 127.0.0.1
$baseClause </Files>
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)$ $baseClause
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT RewriteCond %{REQUEST_URI} ^(.*)$
; RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]
if(file_exists('.htaccess')) { TEXT
$htaccess = file_get_contents('.htaccess'); ;
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) { if(file_exists('.htaccess')) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n"; $htaccess = file_get_contents('.htaccess');
}
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) { $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n"; }
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
} 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 ###'));
$this->createFile('.htaccess', $start . $rewrite . $end); }
} }
function createHtaccessAlternative() { $this->createFile('.htaccess', $start . $rewrite . $end);
$start = "### SILVERSTRIPE START ###\n"; }
$end= "\n### SILVERSTRIPE END ###";
function createHtaccessAlternative() {
$base = dirname($_SERVER['SCRIPT_NAME']); $start = "### SILVERSTRIPE START ###\n";
if($base != '.') $baseClause = "RewriteBase $base\n"; $end= "\n### SILVERSTRIPE END ###";
$rewrite = <<<TEXT $base = dirname($_SERVER['SCRIPT_NAME']);
<IfModule mod_dir.c> if($base != '.') $baseClause = "RewriteBase $base\n";
DirectorySlash Off
</IfModule> $rewrite = <<<TEXT
<IfModule mod_dir.c>
<Files *.ss> DirectorySlash Off
Order deny,allow </IfModule>
Deny from all
Allow from 127.0.0.1 <Files *.ss>
</Files> Order deny,allow
Deny from all
RewriteEngine On Allow from 127.0.0.1
$baseClause </Files>
RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)$ $baseClause
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$
RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
TEXT; RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
if(file_exists($this->getBaseDir() . '.htaccess')) { RewriteRule .* $_SERVER[DOCUMENT_ROOT]/sapphire/main.php?url=%1&%{QUERY_STRING} [L]
$htaccess = file_get_contents($this->getBaseDir() . '.htaccess'); TEXT;
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) { if(file_exists($this->getBaseDir() . '.htaccess')) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n"; $htaccess = file_get_contents($this->getBaseDir() . '.htaccess');
}
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) { $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n"; }
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
} 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 ###'));
echo "\n\nRewrite is $rewrite\n"; }
}
$this->createFile('.htaccess', $start . $rewrite . $end);
} echo "\n\nRewrite is $rewrite\n";
function restoreHtaccess() { $this->createFile('.htaccess', $start . $rewrite . $end);
$start = "### SILVERSTRIPE START ###\n"; }
$end= "\n### SILVERSTRIPE END ###";
function restoreHtaccess() {
if(file_exists('.htaccess')) { $start = "### SILVERSTRIPE START ###\n";
$htaccess = file_get_contents('.htaccess'); $end= "\n### SILVERSTRIPE END ###";
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) { if(file_exists('.htaccess')) {
$htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n"; $htaccess = file_get_contents('.htaccess');
}
if(strpos($htaccess, '### SILVERSTRIPE START ###') === false && strpos($htaccess, '### SILVERSTRIPE END ###') === false) {
if(strpos($htaccess, '### SILVERSTRIPE START ###') !== false && strpos($htaccess, '### SILVERSTRIPE END ###') !== false) { $htaccess .= "\n### SILVERSTRIPE START ###\n### SILVERSTRIPE END ###\n";
$start = substr($htaccess, 0, strpos($htaccess, '### SILVERSTRIPE START ###')) . "### SILVERSTRIPE START ###\n"; }
$end = "\n" . substr($htaccess, strpos($htaccess, '### SILVERSTRIPE END ###'));
} 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 ###'));
$this->createFile('.htaccess', $start . $end); }
} }
function checkModRewrite() { $this->createFile('.htaccess', $start . $end);
if($this->performModRewriteTest() == true) { }
return true;
} function checkModRewrite() {
if($this->performModRewriteTest() == true) {
$this->createHtaccessAlternative(); return true;
}
if($this->performModRewriteTest() == false) {
echo "<li>ERROR: mod_rewrite not working, redirecting to mod_rewrite test page</li>"; $this->createHtaccessAlternative();
$this->restoreHtaccess(); if($this->performModRewriteTest() == false) {
echo "<li>ERROR: mod_rewrite not working, redirecting to mod_rewrite test page</li>";
echo "I will now try and direct you to <a href=\"rewritetest.php\">rewritetest</a> to troubleshoot mod_rewrite</p>
<script>setTimeout(function() { window.location.href = 'rewritetest.php'; }, 1000);</script> $this->restoreHtaccess();
";
return false; echo "I will now try and direct you to <a href=\"rewritetest.php\">rewritetest</a> to troubleshoot mod_rewrite</p>
} <script>setTimeout(function() { window.location.href = 'rewritetest.php'; }, 1000);</script>
return true; ";
} return false;
}
function performModRewriteTest() { return true;
if(!isset($_SERVER['HTTP_HOST']) || !$_SERVER['HTTP_HOST']) { }
$this->statusMessage("Installer seems to be called from command-line, we're going to assume that rewriting is working.");
return true; function performModRewriteTest() {
} if(!isset($_SERVER['HTTP_HOST']) || !$_SERVER['HTTP_HOST']) {
$this->statusMessage("Installer seems to be called from command-line, we're going to assume that rewriting is working.");
$baseURL = dirname($_SERVER['SCRIPT_NAME']); return true;
if($baseURL == "/") { }
$baseURL = "";
} $baseURL = dirname($_SERVER['SCRIPT_NAME']);
if($baseURL == "/") {
// Check if mod_rewrite works properly $baseURL = "";
$location = 'http://' . (isset($_SERVER['PHP_AUTH_USER']) ? "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@" : '') . $_SERVER['HTTP_HOST'] . $baseURL . '/InstallerTest/testrewrite'; }
echo $location;
@$testrewriting = file_get_contents($location); // Check if mod_rewrite works properly
$location = 'http://' . (isset($_SERVER['PHP_AUTH_USER']) ? "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@" : '') . $_SERVER['HTTP_HOST'] . $baseURL . '/InstallerTest/testrewrite';
if($testrewriting == 'OK') { echo $location;
return true; @$testrewriting = file_get_contents($location);
}
if($testrewriting == 'OK') {
// Workaround for 'URL file-access is disabled in the server configuration' using curl return true;
if(function_exists('curl_init')) { }
$ch = curl_init($location);
$fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w"); // Workaround for 'URL file-access is disabled in the server configuration' using curl
if(function_exists('curl_init')) {
if($fp) { $ch = curl_init($location);
curl_setopt($ch, CURLOPT_FILE, $fp); $fp = @fopen(dirname(tempnam('adfadsfdas','')) . '/rewritetest', "w");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch); if($fp) {
curl_close($ch); curl_setopt($ch, CURLOPT_FILE, $fp);
fclose($fp); curl_setopt($ch, CURLOPT_HEADER, 0);
$testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest'); curl_exec($ch);
unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest'); curl_close($ch);
if($testrewriting == 'OK') { fclose($fp);
return true; $testrewriting = file_get_contents(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
} unlink(dirname(tempnam('adfadsfdas','')) . '/rewritetest');
} if($testrewriting == 'OK') {
} return true;
}
return false; }
} }
function var_export_array_nokeys($array) { return false;
$retval = "array(\n"; }
foreach($array as $item) {
$retval .= "\t'"; function var_export_array_nokeys($array) {
$retval .= trim($item); $retval = "array(\n";
$retval .= "',\n"; foreach($array as $item) {
} $retval .= "\t'";
$retval .= ")"; $retval .= trim($item);
return $retval; $retval .= "',\n";
} }
$retval .= ")";
/** return $retval;
* Show an installation status message. }
* The output differs depending on whether this is CLI or web based
*/ /**
function statusMessage($msg) { * Show an installation status message.
if(isset($_SERVER['HTTP_HOST'])) echo "<li>$msg</li>\n"; * The output differs depending on whether this is CLI or web based
else echo "$msg\n"; */
flush(); function statusMessage($msg) {
} if(isset($_SERVER['HTTP_HOST'])) echo "<li>$msg</li>\n";
} else echo "$msg\n";
flush();
/** }
* Copy a file, or recursively copy a folder and its contents }
*
* @author Aidan Lister <aidan@php.net> /**
* @version 1.0.1 * Copy a file, or recursively copy a folder and its contents
* @link http://aidanlister.com/repos/v/function.copyr.php *
* @param string $source Source path * @author Aidan Lister <aidan@php.net>
* @param string $dest Destination path * @version 1.0.1
* @return bool Returns TRUE on success, FALSE on failure * @link http://aidanlister.com/repos/v/function.copyr.php
*/ * @param string $source Source path
function copyr($source, $dest) * @param string $dest Destination path
{ * @return bool Returns TRUE on success, FALSE on failure
// Simple copy for a file */
if (is_file($source)) { function copyr($source, $dest)
return copy($source, $dest); {
} // Simple copy for a file
if (is_file($source)) {
// Make destination directory return copy($source, $dest);
if (!is_dir($dest)) { }
mkdir($dest);
} // Make destination directory
if (!is_dir($dest)) {
// Loop through the folder mkdir($dest);
$dir = dir($source); }
while (false !== $entry = $dir->read()) {
// Skip pointers // Loop through the folder
if ($entry == '.' || $entry == '..') { $dir = dir($source);
continue; while (false !== $entry = $dir->read()) {
} // Skip pointers
if ($entry == '.' || $entry == '..') {
// Deep copy directories continue;
if ($dest !== "$source/$entry") { }
copyr("$source/$entry", "$dest/$entry");
} // Deep copy directories
} if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
// Clean up }
$dir->close(); }
return true;
} // Clean up
$dir->close();
function rm($fileglob) return true;
{ }
if (is_string($fileglob)) {
if (is_file($fileglob)) { function rm($fileglob)
return unlink($fileglob); {
} else if (is_dir($fileglob)) { if (is_string($fileglob)) {
$ok = rm("$fileglob/*"); if (is_file($fileglob)) {
if (! $ok) { return unlink($fileglob);
return false; } else if (is_dir($fileglob)) {
} $ok = rm("$fileglob/*");
return rmdir($fileglob); if (! $ok) {
} else { return false;
$matching = glob($fileglob); }
if ($matching === false) { return rmdir($fileglob);
trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING); } else {
return false; $matching = glob($fileglob);
} if ($matching === false) {
$rcs = array_map('rm', $matching); trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING);
if (in_array(false, $rcs)) { return false;
return false; }
} $rcs = array_map('rm', $matching);
} if (in_array(false, $rcs)) {
} else if (is_array($fileglob)) { return false;
$rcs = array_map('rm', $fileglob); }
if (in_array(false, $rcs)) { }
return false; } else if (is_array($fileglob)) {
} $rcs = array_map('rm', $fileglob);
} else { if (in_array(false, $rcs)) {
trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR); return false;
return false; }
} } else {
trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR);
return true; return false;
} }
?> return true;
}
?>