/** * Handles get requests for the system information page. */ public function get_sysinfo() { $sysinfo = array(); $siteinfo = array(); // Assemble Site Info $siteinfo[_t('Habari Version')] = Version::get_habariversion(); if (Version::is_devel()) { $siteinfo[_t('Habari Version')] .= " " . Version::get_git_short_hash(); } $siteinfo[_t('Habari API Version')] = Version::get_apiversion(); $siteinfo[_t('Habari DB Version')] = Version::get_dbversion(); $siteinfo[_t('Active Theme')] = Options::get('theme_name'); $siteinfo[_t('System Locale')] = HabariLocale::get(); $siteinfo[_t('Cache Class')] = Cache::get_class(); $this->theme->siteinfo = $siteinfo; // Assemble System Info $sysinfo[_t('PHP Version')] = phpversion(); $sysinfo[_t('Server Software')] = $_SERVER['SERVER_SOFTWARE']; $sysinfo[_t('Database')] = DB::get_driver_name() . ' - ' . DB::get_driver_version(); $sysinfo[_t('PHP Extensions')] = implode(', ', get_loaded_extensions()); $sysinfo[_t('PHP Configuration Settings')] = implode("<br>", Utils::get_ini_settings()); if (defined('PCRE_VERSION')) { $sysinfo[_t('PCRE Version')] = PCRE_VERSION; } else { // probably PHP < 5.2.4 ob_start(); phpinfo(8); $phpinfo = ob_get_contents(); ob_end_clean(); preg_match('/PCRE Library Version.*class="v">(.*)$/mi', $phpinfo, $matches); $sysinfo[_t('PCRE Version')] = $matches[1]; } $sysinfo[_t('Browser')] = $_SERVER['HTTP_USER_AGENT']; $this->theme->sysinfo = $sysinfo; // Assemble Class Info $classinfo = Utils::glob(HABARI_PATH . "/user/classes/*.php"); if (count($classinfo)) { $classinfo = array_map('realpath', $classinfo); } $this->theme->classinfo = $classinfo; // Assemble Plugin Info $raw_plugins = Plugins::get_active(); $plugins = array('system' => array(), 'user' => array(), '3rdparty' => array(), 'other' => array()); foreach ($raw_plugins as $plugin) { $file = $plugin->get_file(); // Catch plugins that are symlinked from other locations as ReflectionClass->getFileName() only returns the ultimate file path, not the symlink path, and we really want the symlink path $all_plugins = Plugins::list_all(); $filename = basename($file); if (array_key_exists($filename, $all_plugins) && $all_plugins[$filename] != $file) { $file = $all_plugins[$filename]; } if (preg_match('%[\\\\/](system|3rdparty|user)[\\\\/]plugins[\\\\/]%i', $file, $matches)) { // A plugin's info is XML, cast the element to a string. See #1026. $plugins[strtolower($matches[1])][(string) $plugin->info->name] = $file; } else { // A plugin's info is XML, cast the element to a string. $plugins['other'][(string) $plugin->info->name] = $file; } } $this->theme->plugins = $plugins; $this->theme->admin_page = _t('System Information'); $this->display('sysinfo'); }
/** * Entry point for installation. The reason there is a begin_install * method to handle is that conceivably, the user can stop installation * mid-install and need an alternate entry point action at a later time. */ public function act_begin_install() { // Create a new theme to handle the display of the installer $this->theme = Themes::create('installer', 'RawPHPEngine', HABARI_PATH . '/system/installer/'); /** * Set user selected Locale or default */ $this->theme->locales = HabariLocale::list_all(); if (isset($_POST['locale']) && $_POST['locale'] != null) { HabariLocale::set($_POST['locale']); } else { HabariLocale::set(Config::get('locale', 'en-us')); } $this->theme->locale = HabariLocale::get(); $this->handler_vars['locale'] = HabariLocale::get(); /** * Check .htaccess first because ajax doesn't work without it. */ if (!$this->check_htaccess()) { $this->handler_vars['file_contents'] = htmlentities(implode("\n", $this->htaccess())); $this->display('htaccess'); } // Dispatch AJAX requests. if (isset($_POST['ajax_action'])) { switch ($_POST['ajax_action']) { case 'check_mysql_credentials': self::ajax_check_mysql_credentials(); exit; break; case 'check_pgsql_credentials': self::ajax_check_pgsql_credentials(); exit; break; case 'check_sqlite_credentials': self::ajax_check_sqlite_credentials(); exit; break; } } // set the default values now, which will be overriden as we go $this->form_defaults(); if (!$this->meets_all_requirements()) { $this->display('requirements'); } /** * Add the AJAX hooks */ Plugins::register(array('InstallHandler', 'ajax_check_mysql_credentials'), 'ajax_', 'check_mysql_credentials'); Plugins::register(array('InstallHandler', 'ajax_check_pgsql_credentials'), 'ajax_', 'check_pgsql_credentials'); /** * Let's check the config.php file if no POST data was submitted */ if (!file_exists(Site::get_dir('config_file')) && !isset($_POST['admin_username'])) { // no config file, and no HTTP POST $this->display('db_setup'); } // try to load any values that might be defined in config.php if (file_exists(Site::get_dir('config_file'))) { include Site::get_dir('config_file'); // check for old style config (global variable, pre-dates registry based config if (!Config::exists('db_connection') && isset($db_connection)) { // found old style config... // set up registry: Config::set('db_connection', $db_connection); // assign handler vars (for config file write) $this->set_handler_vars_from_db_connection(); // write new config file if ($this->write_config_file(true)) { // successful, so redirect: Utils::redirect(Site::get_url('habari')); } } if (Config::exists('db_connection')) { $this->set_handler_vars_from_db_connection(); } // if a $blog_data array exists in config.php, use it // to pre-load values for the installer // ** this is completely optional ** if (Config::exists('blog_data')) { $blog_data = Config::get('blog_data'); foreach ($blog_data as $blog_datum => $value) { $this->handler_vars[$blog_datum] = $value; } } } // now merge in any HTTP POST values that might have been sent // these will override the defaults and the config.php values $this->handler_vars = $this->handler_vars->merge($_POST); // we need details for the admin user to install if ('' == $this->handler_vars['admin_username'] || '' == $this->handler_vars['admin_pass1'] || '' == $this->handler_vars['admin_pass2'] || '' == $this->handler_vars['admin_email']) { // if none of the above are set, display the form $this->display('db_setup'); } $db_type = $this->handler_vars['db_type']; if ((!Config::exists('db_connection') || Config::get('db_connection')->connection_string == '') && ($db_type == 'mysql' || $db_type == 'pgsql')) { $this->handler_vars['db_host'] = $_POST["{$db_type}_db_host"]; $this->handler_vars['db_user'] = $_POST["{$db_type}_db_user"]; $this->handler_vars['db_pass'] = $_POST->raw("{$db_type}_db_pass"); $this->handler_vars['db_schema'] = $_POST["{$db_type}_db_schema"]; } // we got here, so we have all the info we need to install // make sure the admin password is correct if ($this->handler_vars['admin_pass1'] !== $this->handler_vars['admin_pass2']) { $this->theme->assign('form_errors', array('password_mismatch' => _t('Password mis-match.'))); $this->display('db_setup'); } // don't accept emails with control characters if (!ctype_print($this->handler_vars['admin_email'])) { $this->theme->assign('form_errors', array('admin_email' => _t('Only printable characters are allowed.'))); $this->display('db_setup'); } // check whether prefix is valid if (isset($this->handler_vars['table_prefix']) && preg_replace('/[^a-zA-Z_]/', '', $this->handler_vars['table_prefix']) !== $this->handler_vars['table_prefix']) { $this->theme->assign('form_errors', array('table_prefix' => _t('Allowed characters are A-Z, a-z and "_".'))); $this->display('db_setup'); } // Make sure we still have a valid connection if (!call_user_func(array($this, "check_{$db_type}"))) { $this->display('db_setup'); } // try to write the config file if (!$this->write_config_file()) { $this->theme->assign('form_errors', array('write_file' => _t('Could not write config.php file…'))); $this->display('db_setup'); } // try to install the database if (!$this->install_db()) { // the installation failed for some reason. // re-display the form $this->display('db_setup'); } // activate plugins on POST if (count($_POST) > 0) { $this->activate_plugins(); $this->activate_theme(); } // Installation complete. Secure sqlite if it was chosen as the database type to use if ($db_type == 'sqlite') { if (!$this->secure_sqlite()) { $this->theme->sqlite_contents = implode("\n", $this->sqlite_contents()); $this->display('sqlite'); } } EventLog::log(_t('Habari successfully installed.'), 'info', 'default', 'habari'); Utils::redirect(Site::get_url('habari')); }