function fs_get_database_status_message($db_status_array = null) { if (!$db_status_array) { $fsdb =& fs_get_db_conn(); $db_status_array = fs_get_db_status($fsdb); } $db_status = $db_status_array['status']; $msg = ''; switch ($db_status) { case FS_DB_VALID: $msg = fs_r('FireStats is properly installed in the database'); break; case FS_DB_NOT_CONFIGURED: $msg = fs_r('FireStats is not configured'); break; case FS_DB_GENERAL_ERROR: $msg = fs_r('Database error, check your configuration'); break; case FS_DB_NOT_INSTALLED: $msg = fs_r('FireStats is not installed in the database'); break; case FS_DB_NEED_UPGRADE: $msg = fs_r('FireStats database need to be upgraded'); break; case FS_DB_IS_NEWER_THAN_CODE: $msg = fs_r('The FireStats database version is newer than this code version, you need to upgrade FireStats'); break; case FS_DB_CONNECTION_ERROR: $msg = fs_r('Error connecting to database'); break; default: $msg = fs_r('Unknown database status code'); } return $msg; }
function fs_install_impl(&$fsdb, $upgrade_if_needed = false) { $db_status_arr = fs_get_db_status($fsdb); $db_status = $db_status_arr['status']; $db_version = $db_status_arr['ver']; $msg = fs_get_database_status_message($db_status_arr); if ($db_status == FS_DB_VALID) { return true; } else { if ($db_status == FS_DB_NOT_CONFIGURED || $db_status == FS_DB_IS_NEWER_THAN_CODE) { echo $msg; return false; } else { if ($db_status == FS_DB_GENERAL_ERROR || $db_status == FS_DB_CONNECTION_ERROR) { echo $msg . " : " . $fsdb->debug(); return false; } else { if ($db_status == FS_DB_NOT_INSTALLED) { if (!fs_db_install($fsdb)) { return false; } } else { if ($db_status == FS_DB_NEED_UPGRADE && $upgrade_if_needed) { if (!fs_db_upgrade($fsdb, $db_version)) { return false; } fs_do_action("db_upgraded"); // after a db upgrade (major releases only) reset donation status for users that didn't donate $donation = fs_get_option('donation_status'); if ($donation != 'donated') { fs_update_option('donation_status', ''); fs_update_option('last_nag_time', time()); } } } } } } return true; }
This file is the standalone entry point for FireStats Its not called when FireStats is installed inside WordPress or other systems */ require_once dirname(__FILE__) . '/php/init.php'; require_once dirname(__FILE__) . '/php/utils.php'; require_once dirname(__FILE__) . '/php/html-utils.php'; if (fs_in_wordpress()) { // security check. // prevent uncontroled access to FireStats installed inside another system $msg = "<h3>" . fs_r('Error') . "</h3>" . fs_r('Access denied'); fs_show_page($msg, false, false); return; } require_once FS_ABS_PATH . '/php/auth.php'; require_once FS_ABS_PATH . '/php/db-common.php'; $db = fs_get_db_status(); if ($db['status'] != FS_DB_VALID) { $show_db = false; switch ($db['status']) { case FS_DB_NOT_INSTALLED: case FS_DB_NOT_CONFIGURED: $show_db = true; break; case FS_DB_NEED_UPGRADE: if ($db['status'] == FS_DB_NEED_UPGRADE && $db['ver'] < 11) { $show_db = true; } break; } if ($show_db) { fs_dummy_auth();
function fs_systest_database_test() { require_once FS_ABS_PATH . '/php/db-common.php'; $db = fs_get_db_status(); $errors = array(); if ($db['status'] == FS_DB_NOT_CONFIGURED) { $errors[] = fs_systest_error("fatal", "Database is not configured"); } else { // database is configured, we can do some serious tests. $mysql_version = fs_mysql_version(); if (!fs_mysql_newer_than("4.0.17")) { $errors[] = fs_systest_error("fatal", "Your MySQL database version is <b>{$mysql_version}</b>, FireStats requires <b>4.0.17</b> or newer"); } else { if (!fs_mysql_newer_than("4.1.14")) { $errors[] = fs_systest_error("warning", "Your MySQL database version is <b>{$mysql_version}</b>, Some features of FireStats reqruires <b>4.1.14</b> or newer"); } } if ($db['status'] != FS_DB_VALID && $db['status'] != FS_DB_NOT_CONFIGURED) { $errors[] = fs_systest_error("fatal", fs_get_database_status_message($db)); } else { $fsdb =& fs_get_db_conn(); $tables = fs_get_tables_list(); $except = array(fs_pending_date_table()); // don't check this one for InnoDB. $res = $fsdb->get_results("SHOW TABLE STATUS"); if ($res === false) { $errors[] = fs_systest_error("fatal", "Error querying database"); } else { $bad_tables = ""; $found = array(); foreach ($res as $t) { if (in_array($t->Name, $tables) === true) { $found[$t->Name] = true; if (in_array($t->Name, $except) === false) { if (isset($t->Engine) && $t->Engine != "InnoDB" || isset($t->Type) && $t->Type != "InnoDB") { if ($bad_tables == "") { $bad_tables .= $t->Name; } else { $bad_tables .= ", " . $t->Name; } } } } } foreach ($tables as $t) { if (!(isset($found[$t]) && $found[$t])) { $errors[] = fs_systest_error("fatal", "missing table <b>{$t}</b>"); } } if ($bad_tables != "") { $errors[] = fs_systest_error("fatal", "Some of your tables are not using the InnoDB engine, which is required by FireStats. wierd things may happen <b>({$bad_tables})</b>"); } } } } return $errors; }
function fs_output_database_table() { ?> <table> <?php if (!fs_db_valid()) { ?> <tr> <td colspan='2'> <div class="fwrap"> <?php echo fs_r('Database status') . " : <b style='color:red'>" . fs_get_database_status_message() . "</b>"; ?> <br/> <?php $st = fs_get_db_status(); if ($st['status'] == FS_DB_NEED_UPGRADE) { ?> <div id="database_upgrade_div"> <span class="notice"><?php fs_e('Click to upgrade'); ?> </span> <button id="upgrade_db" class="button" onclick="upgradeDatabase()"><?php fs_e('Upgrade'); ?> </button> </div> <?php } ?> </div> </td> </tr> <?php } ?> </table> <div id="database_table_config_div"> <table> <tr> <td colspan="2"> <div class="fwrap"> <?php $cfg_source = fs_get_config_source_desc(); $cfg_source_div = "<div id='config_source'><b>{$cfg_source}</b></div>"; echo sprintf(fs_r('Configuration source : %s'), $cfg_source_div); echo '<div id="switch_to_external_system">'; if (fs_should_show_use_wp_button()) { ?> <br/> <?php fs_e('To use wordpress database, click this button.'); ?> <br/> <?php echo '<div class="notice">' . fs_r('FireStats database configuration will be lost.') . '</div>'; ?> <br/> <button class="button" onclick="useWordpressDB()"><?php fs_e('Use Wordpress database'); ?> </button> <?php } echo '</div>'; ?> </div> <!-- fwrap --> </td> </tr> <tr> <td colspan="2"> <div class="fwrap"> <?php fs_e('To perform one of the following actions:'); ?> <ul> <li><?php fs_e('Attach to an existing FireStats installation'); ?> </li> <li><?php fs_e('Install FireStats into an existing database'); ?> </li> <li><?php fs_e('Create a new database and install FireStats there'); ?> </li> </ul> <?php fs_e('Follow instructions in the help'); ?> </div> </td> </tr> <tr> <?php global $fs_config; ?> <td><?php fs_e('Database host'); ?> </td> <td id="holder_database_host"> <input type="text" size="30" name="text_database_host" id="text_database_host" onkeypress="return trapEnter(event,'testDBConnection()')" value="<?php print $fs_config['DB_HOST']; ?> "/> </td> </tr> <tr> <td><?php fs_e('Database name'); ?> </td> <td id="holder_database_name"> <input type="text" size="30" name="text_database_name" id="text_database_name" onkeypress="return trapEnter(event,'testDBConnection()')" value="<?php print $fs_config['DB_NAME']; ?> "/> </td> </tr> <tr> <td><?php fs_e('Database user name'); ?> </td> <td id="holder_database_user"> <input type="text" size="30" name="text_database_user" id="text_database_user" onkeypress="return trapEnter(event,'testDBConnection()')" value="<?php print $fs_config['DB_USER']; ?> "/> </td> </tr> <tr> <td><?php fs_e('Database password'); ?> </td> <td id="holder_database_pass"> <input type="password" size="30" name="text_database_pass" onkeypress="return trapEnter(event,'testDBConnection()')" id="text_database_pass" value="<?php // don't send password, too risky ?> "/> </td> </tr> <tr> <td><?php fs_e('Tables prefix'); ?> </td> <td id="holder_database_prefix"> <input type="text" size="30" name="text_database_prefix" id="text_database_prefix" value="<?php print $fs_config['DB_PREFIX']; ?> "/> </td> </tr> </table> <table> <tr> <td><button class="button" onclick="testDBConnection()"><?php fs_e('Test connection'); ?> </button></td> <td><div id="advanced_feedback"></div></td> </tr> </table> </div> <div style="display:none" id="install_tables_id" class="fwrap"> <table> <tr> <td><?php fs_e('Click to install and switch to new FireStats tables'); ?> </td> </tr> <tr> <td><button class="button" onclick="installDBTables()"><?php fs_e('Install tables'); ?> </button></td> </tr> </table> </div> <div id="use_database_id" style="display:none" class="fwrap"> <table> <tr> <td><?php fs_e('Click to use this FireStats database'); ?> </td> </tr> <tr> <td> <button class="button" onclick="attachToDatabase()"><?php fs_e('Use this database'); ?> </button> </td> </tr> </table> </div> <div id="create_db_id" style="display:none" class="fwrap"> <table> <tr> <td colspan="2"> <?php echo fs_r('To create a new database, an administrator user should be used in the above fields.') . '<br/>'; echo fs_r('However, For security reason, it is recommended not to use a database administrator user for day to day operations.') . '<br/>'; echo fs_r('Enter new user name and password for FireStats, this user will only have access to the FireStats database') . '<br/>'; echo fs_r('If you will not specify user and password the Admin user and password will be used.') . '<br/>'; ?> </td> </tr> </table> <table> <tr> <td><?php fs_e('FireStats User name'); ?> </td> <td><input type="text" size="30" id="text_database_firestats_user" value=""/></td> </tr> <tr> <td><?php fs_e('FireStats password'); ?> </td> <td><input type="password" size="30" id="text_database_firestats_pass" value=""/></td> </tr> </table> <table> <tr> <td><button class="button" onclick="createNewDatabase()"><?php fs_e('Create database'); ?> </button></td> <td><div id="new_db_feedback"></div></td> </tr> </table> </div> <?php }