diff options
-rw-r--r-- | actions/systemsettings/install.php | 128 | ||||
-rw-r--r-- | engine/lib/actions.php | 3 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 67 | ||||
-rw-r--r-- | engine/lib/install.php | 97 | ||||
-rw-r--r-- | engine/start.php | 20 | ||||
-rw-r--r-- | install/languages/en.php | 5 | ||||
-rw-r--r-- | languages/en.php | 3 | ||||
-rw-r--r-- | views/default/settings/install.php | 14 |
8 files changed, 19 insertions, 318 deletions
diff --git a/actions/systemsettings/install.php b/actions/systemsettings/install.php deleted file mode 100644 index 6f3b75a3d..000000000 --- a/actions/systemsettings/install.php +++ /dev/null @@ -1,128 +0,0 @@ -<?php -/** - * Elgg install site action - * - * Creates a new site and sets it as the default - * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ - */ - -global $CONFIG; -define('INSTALLING', TRUE); - -// Set failsafe again in case we get an exception thrown -elgg_set_viewtype('failsafe'); - -if (is_installed()) { - forward(); -} - -if (get_input('settings') == 'go') { - if (!datalist_get('default_site')) { - // Sanitise - $path = sanitise_filepath(get_input('path')); - $dataroot = sanitise_filepath(get_input('dataroot')); - $url = sanitise_filepath(get_input('wwwroot')); - - // Blank? - if ($dataroot == "/") { - throw new InstallationException(elgg_echo('InstallationException:DatarootBlank')); - } - - // That it's valid - if (stripos($dataroot, $path)!==false) { - throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootUnderPath'), $dataroot)); - } - - // Check data root is writable - if (!is_writable($dataroot)) { - throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootNotWritable'), $dataroot)); - } - - $site = new ElggSite(); - $site->name = get_input('sitename'); - $site->url = $url; - $site->description = get_input('sitedescription'); - $site->access_id = ACCESS_PUBLIC; - $guid = $site->save(); - - if (!$guid) { - throw new InstallationException(sprintf(elgg_echo('InstallationException:CantCreateSite'), get_input('sitename'), get_input('wwwroot'))); - } - - $site->email = get_input('siteemail'); - - // this is needed to grab plugins - $CONFIG->site_guid = $guid; - $CONFIG->site = $site; - - datalist_set('installed',time()); - datalist_set('path', $path); - datalist_set('dataroot', $dataroot); - datalist_set('default_site', $site->getGUID()); - datalist_set('version', get_version()); - - set_config('view', get_input('view'), $site->getGUID()); - set_config('language', get_input('language'), $site->getGUID()); - set_config('default_access', get_input('default_access'), $site->getGUID()); - set_config('allow_registration', TRUE, $site->getGUID()); - set_config('walled_garden', FALSE, $site->getGUID()); - - $debug = get_input('debug'); - if ($debug) { - set_config('debug', $debug, $site->getGUID()); - } else { - unset_config('debug', $site->getGUID()); - } - - $api = get_input('api'); - if ($api) { - unset_config('disable_api', $site->getGUID()); - } else { - set_config('disable_api', 'disabled', $site->getGUID()); - } - - $https_login = get_input('https_login'); - if ($https_login) { - set_config('https_login', 1, $site->getGUID()); - } else { - unset_config('https_login', $site->getGUID()); - } - - // activate some plugins by default - if (isset($CONFIG->default_plugins)) { - if (!is_array($CONFIG->default_plugins)) { - $plugins = explode(',', $CONFIG->default_plugins); - } else { - $CONFIG->default_plugins = $CONFIG->default_plugins; - } - - foreach ($plugins as $plugin){ - enable_plugin(trim($plugin), $site->getGUID()); - } - } else { - // activate plugins with manifest.xml: elgg_install_state = enabled - $plugins = get_plugin_list(); - foreach ($plugins as $plugin) { - if ($manifest = load_plugin_manifest($plugin)) { - if (isset($manifest['elgg_install_state']) && $manifest['elgg_install_state'] == 'enabled') { - enable_plugin($plugin); - } - } - } - } - - // reset the views path in case of installing over an old data dir. - $dataroot = datalist_get('dataroot'); - $cache = new ElggFileCache($dataroot); - $cache->delete('view_paths'); - - system_message(elgg_echo("installation:configuration:success")); - - header("Location: ../../pg/register"); - exit; - } -} diff --git a/engine/lib/actions.php b/engine/lib/actions.php index 6b2967964..d164b14d6 100644 --- a/engine/lib/actions.php +++ b/engine/lib/actions.php @@ -60,12 +60,9 @@ function action($action, $forwarder = "") { // @todo REMOVE THESE ONCE #1509 IS IN PLACE. // Allow users to disable plugins without a token in order to // remove plugins that are incompatible. - // Installation cannot use tokens because it requires site secret to be - // working. (#1462) // Login and logout are for convenience. // file/download (see #2010) $exceptions = array( - 'systemsettings/install', 'admin/plugins/disable', 'logout', 'login', diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index c00a88e84..16e20ef7c 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -584,73 +584,6 @@ function elgg_get_file_list($directory, $exceptions = array(), $list = array(), } /** - * Checks that Elgg has been installed and attempts to complete installation if not. - * - * This is called by {@link engine/start.php} immediately after Elgg libraries are loaded - * to check the installation state. - * - * Elgg's installation state is determined by (1) the existence of the engine/settings.php - * file, (2) a .htaccess file, and (3) a populated database. This function checks - * for 1 and 2, while 3 is checked by {@link is_installed()} and {@link is_db_installed()}. - * - * If settings.php doesn't exist and $_REQUEST['db_install_vars'] is present, - * this function attempts to write the values from 'db_install_vars' to settings.php. - * - * If .htaccess doens't exist this function attempts to copy htaccess_dist to .htaccess. - * - * If there are any problems, this function calls {@link register_error()} and returns FALSE. - * Since this function is called during bootstrapping, the viewtype is failsafe. - * Returning FALSE results in an InstallationException, which halts execution. - * - * @return bool - */ -function sanitised() { - $sanitised = true; - - 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) { - $rtn = db_check_settings($save_vars['CONFIG_DBUSER'], - $save_vars['CONFIG_DBPASS'], - $save_vars['CONFIG_DBNAME'], - $save_vars['CONFIG_DBHOST'] ); - if ($rtn == FALSE) { - register_error(elgg_view("messages/sanitisation/dbsettings_error")); - register_error(elgg_view("messages/sanitisation/settings", - array( 'settings.php' => $result, - 'sticky' => $save_vars))); - return FALSE; - } - - $result = create_settings($save_vars, dirname(dirname(__FILE__)) . "/settings.example.php"); - - - if (file_put_contents(dirname(dirname(__FILE__)) . "/settings.php", $result)) { - // blank result to stop it being displayed in textarea - $result = ""; - } - } - - // 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", array('.htaccess' => file_get_contents(dirname(dirname(dirname(__FILE__))) . "/htaccess_dist")))); - $sanitised = false; - } - } - - return $sanitised; -} - -/** * Adds an entry in $CONFIG[$register_name][$subregister_name]. * * This is only used for the site-wide menu. See {@link add_menu()}. diff --git a/engine/lib/install.php b/engine/lib/install.php index f1ad74b23..9deec9e26 100644 --- a/engine/lib/install.php +++ b/engine/lib/install.php @@ -11,63 +11,6 @@ */ /** - * Check that the installed version of PHP meets the minimum requirements (currently 5.2 or greater). - * - * @return bool - */ -function php_check_version() { - if (version_compare(phpversion(), '5.1.2', '>=')) { - return true; - } - - return false; -} - -/** - * Validate the platform Elgg is being installed on. - * - * @throws ConfigurationException if the validation fails. - * @return bool - */ -function validate_platform() { - // Get database version - if (!db_check_version()) { - throw new ConfigurationException(elgg_echo('ConfigurationException:BadDatabaseVersion')); - } - - // Now check PHP - if (!php_check_version()) { - throw new ConfigurationException(elgg_echo('ConfigurationException:BadPHPVersion')); - } - - // @todo Consider checking for installed modules etc - return true; -} - -/** - * Confirm the settings for the database - * - * @param string $user - * @param string $password - * @param string $dbname - * @param string $host - * @return bool - * @since 1.7.1 - */ -function db_check_settings($user, $password, $dbname, $host) { - $mysql_dblink = mysql_connect($host, $user, $password, true); - if ($mysql_dblink == FALSE) { - return $FALSE; - } - - $result = mysql_select_db($dbname, $mysql_dblink); - - mysql_close($mysql_dblink); - - return $result; -} - -/** * Returns whether or not the database has been installed * * @return true|false Whether the database has been installed @@ -104,37 +47,13 @@ function is_installed() { 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); +function verify_installation() { + $installed = FALSE; + try { + $installed = is_installed(); + } catch (DatabaseException $e) {} + if (!$installed) { + header("Location: install.php"); + exit; } - - return $file; -} - -/** - * Initialisation for installation functions - * - */ -function install_init() { - register_action("systemsettings/install",true); } - -register_elgg_event_handler("boot","system","install_init");
\ No newline at end of file diff --git a/engine/start.php b/engine/start.php index ce011f5c4..a84a19e0d 100644 --- a/engine/start.php +++ b/engine/start.php @@ -82,7 +82,8 @@ set_exception_handler('__elgg_php_exception_handler'); * Load the system settings */ if (!include_once(dirname(__FILE__) . "/settings.php")) { - throw new InstallationException("Elgg could not load the settings file."); + $msg = elgg_echo('InstallationException:CannotLoadSettings'); + throw new InstallationException($msg); } @@ -94,7 +95,7 @@ $lib_files = array( 'admin.php', 'annotations.php', 'api.php', 'cache.php', 'calendar.php', 'configuration.php', 'cron.php', 'entities.php', 'export.php', 'extender.php', 'filestore.php', 'group.php', - 'input.php', 'install.php', 'location.php', 'mb_wrapper.php', + 'input.php', 'location.php', 'mb_wrapper.php', 'memcache.php', 'metadata.php', 'metastrings.php', 'notification.php', 'objects.php', 'opendd.php', 'pagehandler.php', 'pageowner.php', 'pam.php', 'plugins.php', 'query.php', @@ -107,20 +108,13 @@ foreach($lib_files as $file) { $file = $lib_dir . $file; elgg_log("Loading $file..."); if (!include_once($file)) { - throw new InstallationException("Could not load {$file}"); + $msg = sprint(elgg_echo('InstallationException:MissingLibrary'), $file); + throw new InstallationException($msg); } } -// check if the install was completed -// @todo move into function -$installed = FALSE; -try { - $installed = is_installed(); -} catch (DatabaseException $e) {} -if (!$installed) { - header("Location: install.php"); - exit; -} +// confirm that the installation completed successfully +verify_installation(); // Autodetect some default configuration settings set_default_config(); diff --git a/install/languages/en.php b/install/languages/en.php index aadb89f0d..93bd9e190 100644 --- a/install/languages/en.php +++ b/install/languages/en.php @@ -112,10 +112,7 @@ If you are ready to proceed, click the Next button.", 'install:complete:instructions' => 'Your Elgg site is now ready to be used. Click the button below to be taken to your site.', - 'InstallationException:UnknownStep' => '%s is an unknown installation step.', - 'InstallationException:MissingLibrary' => 'Could not load %s', - 'InstallationException:CannotLoadSettings' => 'Elgg could not load the settings file. It does not exist or there is a file permissions issue.', - + 'InstallationException:UnknownStep' => '%s is an unknown installation step.', ); diff --git a/languages/en.php b/languages/en.php index 77ff00a7d..5dd1874d7 100644 --- a/languages/en.php +++ b/languages/en.php @@ -42,6 +42,9 @@ $english = array( 'actionloggedout' => "Sorry, you cannot perform this action while logged out.", 'actionunauthorized' => 'You are unauthorized to perform this action', + 'InstallationException:MissingLibrary' => 'Could not load %s', + 'InstallationException:CannotLoadSettings' => 'Elgg could not load the settings file. It does not exist or there is a file permissions issue.', + 'SecurityException:Codeblock' => "Denied access to execute privileged code block", 'DatabaseException:WrongCredentials' => "Elgg couldn't connect to the database using the given credentials.", 'DatabaseException:NoConnect' => "Elgg couldn't select the database '%s', please check that the database is created and you have access to it.", diff --git a/views/default/settings/install.php b/views/default/settings/install.php deleted file mode 100644 index 6fccfb06f..000000000 --- a/views/default/settings/install.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -/** - * Elgg system settings on initial installation - * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ - * - */ - -echo "<p>" . autop(elgg_echo("installation:settings:description")) . "</p>"; - -echo elgg_view("settings/system",array("action" => "action/systemsettings/install"));
\ No newline at end of file |