diff options
-rw-r--r-- | engine/lib/elgglib.php | 25 | ||||
-rw-r--r-- | engine/lib/input.php | 9 | ||||
-rw-r--r-- | engine/lib/install.php | 23 | ||||
-rw-r--r-- | engine/settings.example.php | 10 | ||||
-rw-r--r-- | engine/start.php | 51 | ||||
-rw-r--r-- | htaccess_dist | 7 | ||||
-rw-r--r-- | languages/en.php | 34 | ||||
-rw-r--r-- | views/default/messages/sanitisation/htaccess.php | 18 | ||||
-rw-r--r-- | views/default/messages/sanitisation/settings.php | 20 | ||||
-rw-r--r-- | views/failsafe/messages/errors/error.php | 20 | ||||
-rw-r--r-- | views/failsafe/messages/errors/list.php | 37 | ||||
-rw-r--r-- | views/failsafe/messages/exceptions/exception.php | 39 | ||||
-rw-r--r-- | views/failsafe/messages/list.php | 25 | ||||
-rw-r--r-- | views/failsafe/messages/sanitisation/htaccess.php | 17 | ||||
-rw-r--r-- | views/failsafe/messages/sanitisation/settings.php | 43 | ||||
-rw-r--r-- | views/failsafe/pageshells/pageshell.php | 36 |
16 files changed, 346 insertions, 68 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 1c4d02138..af48a2200 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -514,14 +514,29 @@ $sanitised = true;
- if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) {
- register_error(elgg_view("messages/sanitisation/settings"));
- $sanitised = false;
+ if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) { + // See if we are being asked to save the file + $save_vars = get_input('db_install_vars'); + $result = ""; + if ($save_vars) + { + $result = create_settings($save_vars, dirname(dirname(__FILE__)) . "/settings.example.php"); + + if (file_put_contents(dirname(dirname(__FILE__)) . "/settings.php", $result)) + $result = ""; // blank result to stop it being displayed in textarea + + } + + // Recheck to see if the file is still missing + if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) {
+ register_error(elgg_view("messages/sanitisation/settings", array('settings.php' => $result)));
+ $sanitised = false; + }
}
if (!file_exists(dirname(dirname(dirname(__FILE__))) . "/.htaccess")) {
if (!@copy(dirname(dirname(dirname(__FILE__))) . "/htaccess_dist", dirname(dirname(dirname(__FILE__))) . "/.htaccess")) {
- register_error(elgg_view("messages/sanitisation/htaccess"));
+ register_error(elgg_view("messages/sanitisation/htaccess", array('.htaccess' => file_get_contents(dirname(dirname(dirname(__FILE__))) . "/htaccess_dist"))));
$sanitised = false;
}
}
@@ -899,7 +914,7 @@ error_log("*** FATAL EXCEPTION *** : " . $exception);
$body = elgg_view("messages/exceptions/exception",array('object' => $exception));
- echo page_draw("We've encountered a problem.", $body);
+ echo page_draw(elgg_echo('exception:title'), $body);
}
diff --git a/engine/lib/input.php b/engine/lib/input.php index 9244c16f3..f42aa7a25 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -20,9 +20,12 @@ function get_input($variable, $default = "")
{
- if (isset($_REQUEST[$variable])) {
- $value = $_REQUEST[$variable];
- return trim($_REQUEST[$variable]);
+ if (isset($_REQUEST[$variable])) { + + if (is_array($_REQUEST[$variable])) + return $_REQUEST[$variable]; + else + return trim($_REQUEST[$variable]);
}
global $CONFIG;
diff --git a/engine/lib/install.php b/engine/lib/install.php index 16f000ee7..b348ab9b2 100644 --- a/engine/lib/install.php +++ b/engine/lib/install.php @@ -38,6 +38,29 @@ return datalist_get('installed');
}
+ + /** + * Copy and create a new settings.php from settings.example.php, substituting the variables in + * $vars where appropriate. + * + * $vars is an associate array of $key => $value, where $key is the variable text you wish to substitute (eg + * CONFIG_DBNAME will replace {{CONFIG_DBNAME}} in the settings file. + * + * @param array $vars The array of vars + * @param string $in_file Optional input file (if not settings.example.php) + * @return string The file containing substitutions. + */ + function create_settings(array $vars, $in_file="engine/settings.example.php") + { + $file = file_get_contents($in_file); + + if (!$file) return false; + + foreach ($vars as $k => $v) + $file = str_replace("{{".$k."}}", $v, $file); + + return $file; + } /**
* Initialisation for installation functions
diff --git a/engine/settings.example.php b/engine/settings.example.php index 6d947a8ba..94b6d5f37 100644 --- a/engine/settings.example.php +++ b/engine/settings.example.php @@ -24,22 +24,22 @@ */
// Database username
- $CONFIG->dbuser = "";
+ $CONFIG->dbuser = "{{CONFIG_DBUSER}}";
// Database password
- $CONFIG->dbpass = "";
+ $CONFIG->dbpass = "{{CONFIG_DBPASS}}";
// Database name
- $CONFIG->dbname = "";
+ $CONFIG->dbname = "{{CONFIG_DBNAME}}";
// Database server
// (For most configurations, you can leave this as 'localhost')
- $CONFIG->dbhost = "localhost";
+ $CONFIG->dbhost = "{{CONFIG_DBHOST}}";
// Database table prefix
// If you're sharing a database with other applications, you will want to use this
// to differentiate Elgg's tables.
- $CONFIG->dbprefix = "elgg";
+ $CONFIG->dbprefix = "{{CONFIG_DBPREFIX}}";
/*
* Multiple database connections
diff --git a/engine/start.php b/engine/start.php index 4682e35b2..ac8d186de 100644 --- a/engine/start.php +++ b/engine/start.php @@ -11,6 +11,8 @@ * @copyright Curverider Ltd 2008
* @link http://elgg.org/
*/
+ + /**
* Load important prerequisites
@@ -22,20 +24,38 @@ } if (!@include_once(dirname(__FILE__) . "/lib/elgglib.php")) { // Main Elgg library
- throw new InstallationException("Elgg could not load its main library.");
+ echo "Elgg could not load its main library."; + exit;
} if (!@include_once(dirname(__FILE__) . "/lib/system_log.php")) { // Logging library - throw new InstallationException("Error in installation: could not load the System Log library."); + echo "Error in installation: could not load the System Log library."; + exit; } if (!@include_once(dirname(__FILE__) . "/lib/export.php")) { // Export library
- throw new InstallationException("Error in installation: could not load the Export library.");
+ echo "Error in installation: could not load the Export library."; + exit;
}
- if (!@include_once(dirname(__FILE__) . "/lib/languages.php")) { // Main Elgg library
- throw new InstallationException("Error in installation: could not load the languages library.");
- }
+ if (!@include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library
+ echo "Error in installation: could not load the languages library."; + exit;
+ } + + if (!@include_once(dirname(__FILE__) . "/lib/input.php")) { // Input library + echo "Error in installation: could not load the input library."; + exit; + } + + if (!@include_once(dirname(__FILE__) . "/lib/install.php")) { // Installation library + echo "Error in installation: could not load the installation library."; + exit; + } + + // Use fallback view until sanitised + $oldview = get_input('view'); + set_input('view', 'failsafe');
/**
* Set light mode default
@@ -118,21 +138,23 @@ load_plugins();
} else { // End portion for sanitised installs only
-
- throw new InstallationException("Once you've corrected any configuration issues, press reload to try again.");
+ + throw new InstallationException(elgg_echo('installation:error:configuration'));
}
// Autodetect some default configuration settings
- set_default_config();
+ set_default_config(); +
// Trigger events
- trigger_elgg_event('boot', 'system');
+ trigger_elgg_event('boot', 'system'); +
// Forward if we haven't been installed
if ((!is_installed() || !is_db_installed()) && !substr_count($_SERVER["PHP_SELF"],"install.php") && !substr_count($_SERVER["PHP_SELF"],"action_handler.php")) {
header("Location: install.php");
exit;
- }
-
+ } +
// Trigger events
if (!substr_count($_SERVER["PHP_SELF"],"install.php") &&
!substr_count($_SERVER["PHP_SELF"],"setup.php") &&
@@ -143,5 +165,8 @@ //forward("setup.php");
}
}
-
+ + + // System booted, return to normal view + set_input('view', $oldview);
?>
\ No newline at end of file diff --git a/htaccess_dist b/htaccess_dist index 720a9b4b3..3e83fc5c2 100644 --- a/htaccess_dist +++ b/htaccess_dist @@ -7,6 +7,13 @@ php_flag magic_quotes_gpc off RewriteEngine on
+#
+# If you are installing Elgg to an unusual location (for example your personal public_html directory)
+# then you may need to uncomment this line and modify accordingly:
+#
+# RewriteBase /web/path/to/elgg/root/
+#
+
RewriteRule ^action\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1
RewriteRule ^actions\/([A-Za-z\_\-\/]+)$ engine/handlers/action_handler.php?action=$1
diff --git a/languages/en.php b/languages/en.php index fb6ca8734..49900e86a 100644 --- a/languages/en.php +++ b/languages/en.php @@ -16,7 +16,8 @@ /**
* Errors
- */
+ */ + 'exception:title' => "We've encountered a problem.",
'InstallationException:CantCreateSite' => "Unable to create a default ElggSite with credentials Name:%s, Url: %s",
@@ -27,7 +28,7 @@ 'SecurityException:Codeblock' => "Denied access to execute privileged code block",
'DatabaseException:WrongCredentials' => "Elgg couldn't connect to the database using the given credentials %s@%s (pw: %s).",
- 'DatabaseException:NoConnect' => "Elgg couldn't select the database %s.",
+ 'DatabaseException:NoConnect' => "Elgg couldn't select the database '%s', please check that the database is created and you have access to it.",
'SecurityException:FunctionDenied' => "Access to privileged function '%s' is denied.",
'DatabaseException:DBSetupIssues' => "There were a number of issues: ",
'DatabaseException:ScriptNotFound' => "Elgg couldn't find the requested database script at %s.",
@@ -299,14 +300,39 @@ /**
* Installation and system settings
- */
+ */ + + 'installation:error:htaccess' => "Elgg requires a file called .htaccess to be set in the root directory of its installation. We tried to create it for you, but Elgg doesn't have permission to write to that directory. + +Creating this is easy. Copy the contents of the textbox below into a text editor and save it as .htaccess + +", + 'installation:error:settings' => "Elgg couldn't find its settings file. Most of Elgg's settings will be handled for you, but we need you to supply your database details. To do this: + +1. Rename engine/settings.example.php to settings.php in your Elgg installation. + +2. Open it with a text editor and enter your MySQL database details. If you don't know these, ask your system administrator or technical support for help. + +Alternatively, you can enter your database settings below and we will try and do this for you...", + + 'installation:error:configuration' => "Once you've corrected any configuration issues, press reload to try again.",
'installation' => "Installation",
'installation:success' => "Elgg's database was installed successfully.",
'installation:configuration:success' => "Your initial configuration settings have been saved. Now register your initial user; this will be your first system administrator.",
'installation:settings' => "System settings",
- 'installation:settings:description' => "Now that the Elgg database has been successfully installed, you need to enter a couple of pieces of information to get your site fully up and running. We've tried to guess where we could, but you may find that you need to tweak these details.",
+ 'installation:settings:description' => "Now that the Elgg database has been successfully installed, you need to enter a couple of pieces of information to get your site fully up and running. We've tried to guess where we could, but you may find that you need to tweak these details.", + + 'installation:settings:dbwizard:prompt' => "Enter your database settings below and hit save:", + 'installation:settings:dbwizard:label:user' => "Database user", + 'installation:settings:dbwizard:label:pass' => "Database password", + 'installation:settings:dbwizard:label:dbname' => "Elgg database", + 'installation:settings:dbwizard:label:host' => "Database hostname (usually 'localhost')", + 'installation:settings:dbwizard:label:prefix' => "Database table prefix (usually 'elgg')", + + 'installation:settings:dbwizard:savefail' => "We were unable to save the new settings.php. Please save the following file as engine/settings.php using a text editor.", +
'sitename' => "The name of your site (eg \"My social networking site\"):",
'wwwroot' => "The site URL, followed by a trailing slash:",
'path' => "The full path to your site root on your disk, followed by a trailing slash:",
diff --git a/views/default/messages/sanitisation/htaccess.php b/views/default/messages/sanitisation/htaccess.php deleted file mode 100644 index 31423e3b3..000000000 --- a/views/default/messages/sanitisation/htaccess.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php
-
- /**
- * Elgg .htaccess not found message
- * Is saved to the errors register when the main .htaccess cannot be found
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
-?>
-Elgg requires a file called .htaccess to be set in the root directory of its installation. We tried to create it for you, but Elgg doesn't have permission to write to that directory.
-
-Creating this is easy. Just take the htaccess_dist file in the root directory and rename it to .htaccess. (On Windows systems, you will need to open htaccess_dist in Notepad and save it as .htaccess from there.)
\ No newline at end of file diff --git a/views/default/messages/sanitisation/settings.php b/views/default/messages/sanitisation/settings.php deleted file mode 100644 index 539598320..000000000 --- a/views/default/messages/sanitisation/settings.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php
-
- /**
- * Elgg settings not found message
- * Is saved to the errors register when settings.php cannot be found
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008
- * @link http://elgg.org/
- */
-
-?>
-Elgg couldn't find its settings file. Most of Elgg's settings will be handled for you, but we need you to supply your database details. To do this:
-
-1. Rename engine/settings.example.php to settings.php in your Elgg installation.
-
-2. Open it with a text editor and enter your MySQL database details. If you don't know these, ask your system administrator or technical support for help.
\ No newline at end of file diff --git a/views/failsafe/messages/errors/error.php b/views/failsafe/messages/errors/error.php new file mode 100644 index 000000000..8e7dbb84a --- /dev/null +++ b/views/failsafe/messages/errors/error.php @@ -0,0 +1,20 @@ +<?php
+
+ /**
+ * Elgg error message
+ * Displays a single error message
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ * @uses $vars['object'] An error message (string)
+ */
+?>
+
+ <p>
+ <?php echo $vars['object']; ?>
+ </p>
\ No newline at end of file diff --git a/views/failsafe/messages/errors/list.php b/views/failsafe/messages/errors/list.php new file mode 100644 index 000000000..ff43f1d00 --- /dev/null +++ b/views/failsafe/messages/errors/list.php @@ -0,0 +1,37 @@ +<?php
+
+ /**
+ * Elgg list errors
+ * Lists error messages
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ * @uses $vars['object'] An array of error messages
+ */
+
+ if (!empty($vars['object']) && is_array($vars['object'])) {
+
+?>
+
+ <div class="messages">
+ <div class="messages-errors">
+
+<?php
+ foreach($vars['object'] as $error) {
+ echo elgg_view('messages/errors/error',array('object' => $error)); + echo "<hr />";
+ }
+?>
+ </div>
+ </div>
+<?php
+ }
+
+
+
+?>
\ No newline at end of file diff --git a/views/failsafe/messages/exceptions/exception.php b/views/failsafe/messages/exceptions/exception.php new file mode 100644 index 000000000..c8c630f3b --- /dev/null +++ b/views/failsafe/messages/exceptions/exception.php @@ -0,0 +1,39 @@ +<?php + + /** + * Elgg exception (fallback mode) + * Displays a single exception + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Curverider Ltd + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + * + * @uses $vars['object'] An exception + */ + + global $CONFIG; +?> + + <p class="messages-exception"> + <span title="<?php echo get_class($vars['object']); ?>"> + <?php + + echo nl2br($vars['object']->getMessage()); + + ?> + </span> + </p> + + <?php if ($CONFIG->debug) { ?> + <hr /> + <p class="messages-exception-detail"> + <?php + + echo nl2br(htmlentities(print_r($vars['object'], true))); + + ?> + </p> + <?php } ?>
\ No newline at end of file diff --git a/views/failsafe/messages/list.php b/views/failsafe/messages/list.php new file mode 100644 index 000000000..10fda8f90 --- /dev/null +++ b/views/failsafe/messages/list.php @@ -0,0 +1,25 @@ +<?php
+
+ /**
+ * Elgg global system message list
+ * Lists all system messages
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ *
+ * @uses $vars['object'] The array of message registers
+ */
+
+ if (!empty($vars['object']) && is_array($vars['object']) && sizeof($vars['object']) > 0) {
+
+ foreach($vars['object'] as $register => $list ) {
+ echo elgg_view("messages/{$register}/list", array('object' => $list));
+ }
+
+ }
+
+?>
\ No newline at end of file diff --git a/views/failsafe/messages/sanitisation/htaccess.php b/views/failsafe/messages/sanitisation/htaccess.php new file mode 100644 index 000000000..99bfe4159 --- /dev/null +++ b/views/failsafe/messages/sanitisation/htaccess.php @@ -0,0 +1,17 @@ +<?php
+
+ /**
+ * Elgg .htaccess not found message
+ * Is saved to the errors register when the main .htaccess cannot be found
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */ + + echo nl2br(elgg_echo('installation:error:htaccess'));
+?> +<textarea cols="120" rows="30"><?php echo $vars['.htaccess']; ?></textarea>
\ No newline at end of file diff --git a/views/failsafe/messages/sanitisation/settings.php b/views/failsafe/messages/sanitisation/settings.php new file mode 100644 index 000000000..798bfbd91 --- /dev/null +++ b/views/failsafe/messages/sanitisation/settings.php @@ -0,0 +1,43 @@ +<?php
+
+ /**
+ * Elgg settings not found message
+ * Is saved to the errors register when settings.php cannot be found
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008
+ * @link http://elgg.org/
+ */
+ + if ($vars['settings.php']) + { + echo elgg_echo('installation:settings:dbwizard:savefail'); +?> +<div> + <textarea rows="50" cols="120"><?php echo $vars['settings.php']; ?></textarea> +</div> +<?php + } + else + { + + echo nl2br(elgg_echo('installation:error:settings'));
+?> +<div> + <h2><?php echo elgg_echo('installation:settings:dbwizard:prompt'); ?></h2> + <form method="POST"> + <table> + <tr><td width="200" valign="top"><?php echo elgg_echo('installation:settings:dbwizard:label:user'); ?></td><td valign="top"> <input type="text" name="db_install_vars[CONFIG_DBUSER]" /></td></tr> + <tr><td width="200" valign="top"><?php echo elgg_echo('installation:settings:dbwizard:label:pass'); ?></td><td valign="top"> <input type="password" name="db_install_vars[CONFIG_DBPASS]" /></td></tr> + <tr><td width="200" valign="top"><?php echo elgg_echo('installation:settings:dbwizard:label:dbname'); ?></td><td valign="top"> <input type="text" name="db_install_vars[CONFIG_DBNAME]" /></td></tr> + <tr><td width="200" valign="top"><?php echo elgg_echo('installation:settings:dbwizard:label:host'); ?></td><td valign="top"> <input type="text" name="db_install_vars[CONFIG_DBHOST]" value="localhost" /></td></tr> + <tr><td width="200" valign="top"><?php echo elgg_echo('installation:settings:dbwizard:label:prefix'); ?></td><td valign="top"> <input type="text" name="db_install_vars[CONFIG_DBPREFIX]" value="elgg" /></td></tr> + </table> + + <input type="submit" name="<?php echo elgg_echo('save'); ?>" value="<?php echo elgg_echo('save'); ?>" /> + </form> +</div> +<?php } ?>
\ No newline at end of file diff --git a/views/failsafe/pageshells/pageshell.php b/views/failsafe/pageshells/pageshell.php new file mode 100644 index 000000000..7e1de7c10 --- /dev/null +++ b/views/failsafe/pageshells/pageshell.php @@ -0,0 +1,36 @@ +<?php + /** + * Elgg fallback pageshell + * Render a few things (like the installation process) in a fallback mode, text only with minimal use + * of functions. + * + * @package Elgg + * @subpackage Core + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @author Marcus Povey + * @copyright Curverider Ltd 2008 + * @link http://elgg.org/ + * + * @uses $vars['config'] The site configuration settings, imported + * @uses $vars['title'] The page title + * @uses $vars['body'] The main content of the page + * @uses $vars['messages'] A 2d array of various message registers, passed from system_messages() + */ + + +?> +<html> + <head> + <title><?php echo $vars['title']; ?></title> + </head> + <body> + <h1><?php echo $vars['title']; ?></h1> + + <!-- display any system messages --> + <?php echo elgg_view('messages/list', array('object' => $vars['sysmessages'])); ?> + + <p> + <?php echo $vars['body']; ?> + </p> + </body> +</html>
\ No newline at end of file |