示例#1
0
 /**
  * The standard upgrader
  * This parses the requested sql file for database upgrade
  * Most upgrades will use this function
  */
 function standard_upgrader()
 {
     global $roster;
     $ver = str_replace('.', '', $this->versions[$this->index]);
     $db_structure_file = ROSTER_LIB . 'dbal' . DIR_SEP . 'structure' . DIR_SEP . 'upgrade_' . $ver . '.sql';
     if (file_exists($db_structure_file)) {
         // Parse structure file and create database tables
         $sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file));
         $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $roster->db->prefix . '\\1\\2', $sql);
         $sql = remove_remarks($sql);
         $sql = parse_sql($sql, ';');
         $sql_count = count($sql);
         for ($i = 0; $i < $sql_count; $i++) {
             $roster->db->query($sql[$i]);
         }
         unset($sql);
     } else {
         roster_die('Could not obtain SQL structure/data', $roster->locale->act['upgrade_wowroster']);
     }
     $roster->db->query("UPDATE `" . $roster->db->table('config') . "` SET `config_value` = '" . ROSTER_VERSION . "' WHERE `id` = '4' LIMIT 1;");
     $roster->db->query("ALTER TABLE `" . $roster->db->table('config') . "` ORDER BY `id`;");
     return;
 }
示例#2
0
/**
 * Step 2: Everything.
 */
function action_databaseChanges()
{
    global $db_prefix, $modSettings, $command_line, $upcontext, $support_js, $db_type;
    $db = database();
    // Have we just completed this?
    if (!empty($_POST['database_done'])) {
        return true;
    }
    $upcontext['sub_template'] = isset($_GET['xml']) ? 'database_xml' : 'database_changes';
    $upcontext['page_title'] = 'Database Changes';
    // All possible files.
    // Name, less than version, insert_on_complete.
    $files = array(array('upgrade_1-0.sql', '1.1', '1.1 RC0'), array('upgrade_1-1.sql', '2.0', '2.0 a'), array('upgrade_2-0_' . $db_type . '.sql', '2.1', '2.1 dev0'), array('upgrade_elk_1-0_' . $db_type . '.sql', '1.1', CURRENT_VERSION));
    // How many files are there in total?
    if (isset($_GET['filecount'])) {
        $upcontext['file_count'] = (int) $_GET['filecount'];
    } else {
        $upcontext['file_count'] = 0;
        foreach ($files as $file) {
            if (!isset($modSettings['elkVersion']) && isset($modSettings['smfVersion']) && strpos($file[0], '_elk_') === false && version_compare($modSettings['smfVersion'], $file[1]) < 0) {
                $upcontext['file_count']++;
            } elseif (!isset($modSettings['elkVersion']) && strpos($file[0], '_elk_') !== false || strpos($file[0], '_elk_') !== false && version_compare($modSettings['elkVersion'], $file[1]) < 0) {
                $upcontext['file_count']++;
            }
        }
    }
    // Do each file!
    $did_not_do = count($files) - $upcontext['file_count'];
    $upcontext['step_progress'] = 0;
    $upcontext['cur_file_num'] = 0;
    foreach ($files as $file) {
        if ($did_not_do) {
            $did_not_do--;
        } else {
            $upcontext['cur_file_num']++;
            $upcontext['cur_file_name'] = $file[0];
            // @todo Do we actually need to do this still?
            if (!isset($modSettings['elkVersion']) || $modSettings['elkVersion'] < $file[1] || $modSettings['elkVersion'] == '2.1 dev0' && $file[0] == 'upgrade_elk_1-0_' . $db_type . '.sql') {
                $nextFile = parse_sql(dirname(__FILE__) . '/' . $file[0]);
                if ($nextFile) {
                    // Only update the version of this if complete.
                    $db->insert('replace', $db_prefix . 'settings', array('variable' => 'string', 'value' => 'string'), array('elkVersion', $file[2]), array('variable'));
                    $modSettings['elkVersion'] = $file[2];
                }
                // If this is XML we only do this stuff once.
                if (isset($_GET['xml'])) {
                    // Flag to move on to the next.
                    $upcontext['completed_step'] = true;
                    // Did we complete the whole file?
                    if ($nextFile) {
                        $upcontext['current_debug_item_num'] = -1;
                    }
                    return upgradeExit();
                } elseif ($support_js) {
                    break;
                }
            }
            // Set the progress bar to be right as if we had - even if we hadn't...
            $upcontext['step_progress'] = $upcontext['cur_file_num'] / $upcontext['file_count'] * 100;
        }
    }
    $_GET['substep'] = 0;
    // So the template knows we're done.
    if (!$support_js) {
        $upcontext['changes_complete'] = true;
        // If this is the command line we can't do any more.
        if ($command_line) {
            return action_deleteUpgrade();
        }
        return true;
    }
    return false;
}
 function do_install($data = '')
 {
     if (!$data) {
         $data = $this->data['query'];
     }
     foreach ($data as $value) {
         $sql_array = parse_sql($value);
         foreach ($sql_array as $query) {
             if (cip_db_query($query) === false) {
                 $this->error('SQL error :<b>' . mysql_errno() . ' - ' . mysql_error() . '<br>' . $query);
                 return $this->error;
             }
         }
     }
     return $this->error;
 }
示例#4
0
function process_step3()
{
    global $DEFAULTS, $DBALS, $LOCALES, $REQUIRE;
    $tpl = new Template_Wrap();
    $tpl->set_handle('body', 'install_step3.html');
    /**
     * Get our posted data
     */
    $db_config['dbtype'] = post_or_db('dbtype');
    $db_config['host'] = post_or_db('dbhost');
    $db_config['database'] = post_or_db('dbname');
    $db_config['username'] = post_or_db('dbuser');
    $db_config['password'] = post_or_db('dbpass');
    $db_config['table_prefix'] = post_or_db('table_prefix', $DEFAULTS);
    $default_locale = post_or_db('default_lang', $DEFAULTS);
    $server_name = post_or_db('server_name');
    $create['username'] = post_or_db('dbuser_c');
    $create['password'] = post_or_db('dbpass_c');
    define('ROSTER_DB_DIR', ROSTER_LIB . 'dbal' . DIR_SEP);
    $dbal_file = ROSTER_DB_DIR . $db_config['dbtype'] . '.php';
    if (!file_exists($dbal_file)) {
        $tpl->message_die('Unable to find the database abstraction layer for <strong>' . $db_config['dbtype'] . '</strong>, check to make sure ' . $dbal_file . ' exists.');
    }
    /**
     * Database population
     */
    include_once $dbal_file;
    // Hey, looks like we are making the database, YAY!
    if ($create['username'] != '' && $create['password'] != '') {
        include_once $dbal_file;
        $db = new roster_db($db_config['host'], '', $create['username'], $create['password']);
        $db->query("CREATE DATABASE IF NOT EXISTS `" . $db_config['database'] . "`;");
        unset($db, $create);
    }
    // Try to connect
    $db = new roster_db($db_config['host'], $db_config['database'], $db_config['username'], $db_config['password'], $db_config['table_prefix']);
    $db->log_level();
    $db->error_die();
    // Check to make sure a connection was made
    if (!is_resource($db->link_id)) {
        // Attempt to
        $tpl->message_die('Failed to connect to database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
    }
    $db_structure_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_structure.sql';
    $db_data_file = ROSTER_DB_DIR . 'structure' . DIR_SEP . $db_config['dbtype'] . '_data.sql';
    $remove_remarks_function = $DBALS[$db_config['dbtype']]['comments'];
    // I require MySQL version 4.1.0 minimum.
    $server_version = $db->server_info();
    $client_version = $db->client_info();
    if (isset($server_version) && isset($client_version)) {
        $tpl->message_append('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
			<strong>You are running:</strong>
			<ul>
				<li><strong>Your server version: ' . $server_version . '</strong></li>
				<li><strong>Your client version: ' . $client_version . '</strong></li>
			</ul>
			Your server meets the MySQL requirements for WoWRoster.');
        if (version_compare($server_version, $REQUIRE['mysql_version'], '<')) {
            $tpl->message_die('MySQL server version ' . $REQUIRE['mysql_version'] . ' or higher is required for WoWRoster.<br /><br />
				<strong>You are running:</strong>
				<ul>
					<li><strong>Your server version: ' . $server_version . '</strong></li>
					<li><strong>Your client version: ' . $client_version . '</strong></li>
				</ul>
				We are sorry, your MySQL server version is not high enough to install WoWRoster, please upgrade MySQL.');
        }
    } else {
        $tpl->message_die('Failed to get version information for database <strong>' . $db_config['database'] . '</strong> as <strong>' . $db_config['username'] . '@' . $db_config['host'] . '</strong><br />' . $db->connect_error() . '<br /><br />' . '<form method="post" action="index.php" name="post"><input type="hidden" name="install_step" value="2" /><div align="center"><input type="submit" name="submit" value="Try Again" /></div></form>');
    }
    // Parse structure file and create database tables
    $sql = @fread(@fopen($db_structure_file, 'r'), @filesize($db_structure_file));
    $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
    $sql = $remove_remarks_function($sql);
    $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
    $sql_count = count($sql);
    $i = 0;
    while ($i < $sql_count) {
        if (isset($sql[$i]) && $sql[$i] != '') {
            if (!$db->query($sql[$i])) {
                $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>');
            }
        }
        $i++;
    }
    unset($sql);
    // Parse the data file and populate the database tables
    $sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file));
    $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $db_config['table_prefix'] . '\\1\\2', $sql);
    $sql = $remove_remarks_function($sql);
    $sql = parse_sql($sql, $DBALS[$db_config['dbtype']]['delim']);
    $sql_count = count($sql);
    $i = 0;
    while ($i < $sql_count) {
        if (isset($sql[$i]) && $sql[$i] != '') {
            if (!$db->query($sql[$i])) {
                $tpl->message_die('Error in SQL query<br />' . $sql[$i] . '<br />' . 'Error: ' . $db->error() . '<br />' . '<a href="index.php">Restart Installation</a>');
            }
        }
        $i++;
    }
    unset($sql);
    /**
     * Update some config settings
     */
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$default_locale}' WHERE `config_name` = 'locale';");
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '" . ROSTER_VERSION . "' WHERE `config_name` = 'version';");
    $db->query("UPDATE `" . $db->table('config') . "` SET `config_value` = '{$server_name}' WHERE `config_name` = 'website_address';");
    /**
     * Write the config file
     */
    $config_file = "<?php\n";
    $config_file .= "/**\n * AUTO-GENERATED CONF FILE\n * DO NOT EDIT !!!\n */\n\n";
    $config_file .= "\$db_config['host']         = " . var_export($db_config['host'], true) . ";\n";
    $config_file .= "\$db_config['username']     = "******";\n";
    $config_file .= "\$db_config['password']     = "******";\n";
    $config_file .= "\$db_config['database']     = " . var_export($db_config['database'], true) . ";\n";
    $config_file .= "\$db_config['table_prefix'] = " . var_export($db_config['table_prefix'], true) . ";\n";
    $config_file .= "\$db_config['dbtype']       = " . var_export($db_config['dbtype'], true) . ";\n";
    // Set our permissions to execute-only
    @umask(0111);
    if (!($fp = @fopen('conf.php', 'w'))) {
        $error_message = 'The <strong>conf.php</strong> file couldn\'t be opened for writing.  Paste the following in to conf.php and save the file to continue:<br /><pre>' . htmlspecialchars($config_file) . '</pre>';
        $tpl->error_append($error_message);
    } else {
        @fputs($fp, $config_file);
        @fclose($fp);
        $tpl->message_append('Your configuration file has been written with the initial values<br />But installation will not be complete until you create an administrator account in this step');
    }
    /**
     * Output the page
     */
    $tpl->sql_output($db);
    $tpl->page_header();
    $tpl->page_tail();
}
 function sql_restore()
 {
     vam_set_time_limit(0);
     $backup_file = DIR_FS_ADMIN_BACKUP . $this->cip_name . '.sql';
     $zip_file = $backup_file . '.gz';
     $restore_query = '';
     if (!file_exists($backup_file)) {
         if (file_exists($zip_file)) {
             $zd = gzopen($zip_file, "r");
             while (!feof($zd)) {
                 $restore_query .= gzread($zd, 10000);
             }
             gzclose($zd);
         }
     } else {
         $restore_query = file_get_contents($backup_file);
     }
     if ($restore_query != '') {
         //Delete all tables from database:
         $tables_query = cip_db_query('show tables');
         while ($tables = mysql_fetch_array($tables_query, MYSQL_ASSOC)) {
             list(, $table) = each($tables);
             mysql_query('DROP TABLE IF EXISTS ' . $table);
         }
         if ($restore_query) {
             $sql_array = parse_sql($restore_query);
             foreach ($sql_array as $query) {
                 cip_db_query($query);
             }
         }
     }
     ci_remove($zip_file);
     ci_remove($backup_file);
 }
示例#6
0
function db_populate($install_filename, $display_sql)
{
    global $show_all_errors, $str_parsed_sql;
    if ($install_filename == '') {
        return;
    }
    $current_pointer = false;
    $full_sql = '';
    $magic = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    $fd = @fopen('sql/' . $install_filename, 'r', true);
    // Discard everything up to the required point in the upgrade file.
    while (!feof($fd) && empty($current_pointer)) {
        $data = trim(fgets($fd, 4096), "\r\n ");
        if (strpos(strtoupper($data), strtoupper($_SESSION['install_file'])) || substr($_SESSION['install_file'], 0, 6) == 'tables') {
            $current_pointer = true;
        }
    }
    // We already have a $data item from above.
    if (substr($data, 0, 2) == "/*" && substr($_SESSION['install_file'], 0, 6) != 'tables') {
        // Do nothing...We skip over comments in upgrade files.
    } else {
        $full_sql .= $data;
    }
    // We need to strip out the comments from upgrade files.
    while (!feof($fd)) {
        $data = trim(fgets($fd, 4096), "\r\n ");
        if (substr($data, 0, 2) == '/*' && substr($_SESSION['install_file'], 0, 6) != 'tables') {
            // Do nothing...We skip over comments in upgrade files.
        } else {
            $full_sql .= $data;
        }
    }
    @set_magic_quotes_runtime($magic);
    fclose($fd);
    $parsed_sql = parse_sql($full_sql);
    // String version of parsed_sql that is used if displaying SQL only.
    $str_parsed_sql = '';
    for ($i = 0, $sqlCntStr = count($parsed_sql); $i < $sqlCntStr; $i++) {
        if (empty($display_sql)) {
            if ($show_all_errors == true) {
                echo $parsed_sql[$i] . '<br />';
            }
            dbi_execute($parsed_sql[$i], array(), false, $show_all_errors);
        } else {
            $str_parsed_sql .= $parsed_sql[$i] . "\n\n";
        }
    }
    // Enable warnings.
    show_errors(true);
}
 * @subpackage RosterCP
*/
if (!defined('IN_ROSTER') || !defined('IN_ROSTER_ADMIN')) {
    exit('Detected invalid access to this file!');
}
$roster->output['title'] .= $roster->locale->act['pagebar_configreset'];
$roster->output['body_onload'] .= "initARC('conf_change_pass','radioOn','radioOff','checkboxOn','checkboxOff');";
$roster->tpl->assign_vars(array('L_CONFIG_RESET' => $roster->locale->act['pagebar_configreset'], 'L_RESET_CONFIRM' => $roster->locale->act['config_reset_confirm'], 'L_RESET_HELP' => $roster->locale->act['config_reset_help'], 'L_PROCEED' => $roster->locale->act['proceed'], 'MESSAGE' => ''));
if (isset($_POST['doit']) && $_POST['doit'] == 'doit') {
    $query = 'TRUNCATE `' . $roster->db->table('config') . '`;';
    $roster->db->query($query);
    $db_data_file = ROSTER_LIB . 'dbal' . DIR_SEP . 'structure' . DIR_SEP . 'mysql_data.sql';
    // Parse the data file and populate the database tables
    $sql = @fread(@fopen($db_data_file, 'r'), @filesize($db_data_file));
    $sql = preg_replace('#renprefix\\_(\\S+?)([\\s\\.,]|$)#', $roster->db->prefix . '\\1\\2', $sql);
    $sql = parse_sql($sql, ';');
    $sql_count = count($sql);
    for ($i = 0; $i < $sql_count; $i++) {
        $roster->db->query($sql[$i]);
    }
    unset($sql);
    $roster->tpl->assign_var('MESSAGE', messagebox($roster->locale->act['config_is_reset'], $roster->locale->act['roster_cp']));
}
$roster->tpl->set_filenames(array('body' => 'admin/config_reset.html'));
$body = $roster->tpl->fetch('body');
/**
* Parse multi-line SQL statements into a single line
*
* @param    string  $sql    SQL file contents
* @param    char    $delim  End-of-statement SQL delimiter
* @return   array
示例#8
0
文件: upgrade.php 项目: alencarmo/OCF
function doStep2()
{
    global $db_prefix, $modSettings, $command_line;
    global $language, $boardurl, $sourcedir, $boarddir;
    $_GET['step'] = '2';
    $endl = $command_line ? "\n" : '<br />' . "\n";
    // Okay, so we want to upgrade to 1.0 if not at 1.0 or higher.
    if (@$modSettings['smfVersion'] < '1.1' && empty($_GET['s'])) {
        parse_sql(dirname(__FILE__) . '/upgrade_1-0.sql');
        // Don't wanna do this part again, though we're not ready yet.
        upgrade_query("\n\t\t\tREPLACE INTO {$db_prefix}settings\n\t\t\t\t(variable, value)\n\t\t\tVALUES\n\t\t\t\t('smfVersion', '1.1 RC0')");
    }
    $_GET['s'] = 1;
    parse_sql(dirname(__FILE__) . '/upgrade_1-1.sql');
    if (!empty($_GET['debug'])) {
        echo $command_line ? ' +++ ' : '&nbsp;&nbsp;&nbsp;', 'Updating version number...';
    }
    upgrade_query("\n\t\tREPLACE INTO {$db_prefix}settings\n\t\t\t(variable, value)\n\t\tVALUES\n\t\t\t('smfVersion', '" . SMF_VERSION . "')");
    if (!empty($_GET['debug'])) {
        echo ' done.', $endl;
    }
    // Almost done... convert the template.php or template.html file?
    if (isset($_GET['conv']) && !file_exists($boarddir . '/Themes/converted')) {
        if (!empty($_GET['debug'])) {
            echo $command_line ? ' +++ ' : '&nbsp;&nbsp;&nbsp;', 'Converting the template...';
        }
        require_once $sourcedir . '/Themes.php';
        mkdir($boarddir . '/Themes/converted', 0777);
        convert_template($boarddir . '/Themes/converted');
        // Copy over the default index.php file.
        copy($boarddir . '/Themes/classic/index.php', $boarddir . '/Themes/converted/index.php');
        @chmod($boarddir . '/Themes/converted/index.php', 0777);
        // Now set up the "converted" theme.
        $values = array('name' => 'Converted Theme from YaBB SE', 'theme_url' => $boardurl . '/Themes/classic', 'images_url' => $boardurl . '/Themes/classic/images', 'theme_dir' => strtr($boarddir, array('\\' => '/')) . '/Themes/converted', 'base_theme_dir' => strtr($boarddir, array('\\' => '/')) . '/Themes/classic');
        // Get an available ID_THEME first...
        $request = upgrade_query("\n\t\t\tSELECT MAX(ID_THEME) + 1\n\t\t\tFROM {$db_prefix}themes");
        list($ID_THEME) = mysql_fetch_row($request);
        mysql_free_result($request);
        $setString = '';
        foreach ($values as $variable => $value) {
            $setString .= "\n\t\t\t\t\t(0, " . $ID_THEME . ", '" . $variable . "', '" . $value . "'),";
        }
        if (!empty($setString)) {
            upgrade_query("\n\t\t\t\tINSERT IGNORE INTO {$db_prefix}themes\n\t\t\t\tVALUES " . substr($setString, 0, -1));
        }
        upgrade_query("\n\t\t\tUPDATE {$db_prefix}settings\n\t\t\tSET value = CONCAT(value, ',{$ID_THEME}')\n\t\t\tWHERE variable = 'knownThemes'\n\t\t\tLIMIT 1");
        upgrade_query("\n\t\t\tREPLACE INTO {$db_prefix}settings\n\t\t\t\t(variable, value)\n\t\t\tVALUES ('theme_guests', {$ID_THEME}),\n\t\t\t\t('smiley_sets_default', 'classic')");
        if (!empty($_GET['debug'])) {
            echo ' done.', $endl;
        }
    }
    $changes = array('language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'', 'db_error_send' => '1');
    if (!empty($_GET['maint'])) {
        echo $command_line ? ' * ' : '', 'Taking the forum out of maintenance mode...';
        $changes['maintenance'] = '0';
    }
    // Make a backup of Settings.php first as otherwise earlier changes are lost.
    copy($boarddir . '/Settings.php', $boarddir . '/Settings_bak.php');
    changeSettings($changes);
    if (!empty($_GET['maint'])) {
        echo ' Successful.', $endl;
    }
    if ($command_line) {
        echo $endl;
        echo 'Upgrade Complete!', $endl;
        echo 'Please delete this file as soon as possible for security reasons.', $endl;
        return true;
    }
    echo '
			<h2 style="margin-top: 2ex;">Upgrade Complete</h2>
			<h3>That wasn\'t so hard, was it?  Now you are ready to use <a href="', $boardurl, '/index.php">your installation of SMF</a>.  Hope you like it!</h3>';
    if (is_writable(dirname(__FILE__)) || is_writable(__FILE__)) {
        echo '
			<label for="delete_self"><input type="checkbox" id="delete_self" onclick="doTheDelete(this);" /> Delete this upgrade.php and its data files now.</label> <i>(doesn\'t work on all servers.)</i>
			<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
				function doTheDelete(theCheck)
				{
					var theImage = document.getElementById ? document.getElementById("delete_upgrader") : document.all.delete_upgrader;

					theImage.src = "', $_SERVER['PHP_SELF'], '?delete=1&ts=" + (new Date().getTime());
					theCheck.disabled = true;
				}
			// ]]></script>
			<img src="', $boardurl, '/Themes/default/images/blank.gif" alt="" id="delete_upgrader" /><br />';
    }
    echo '<br />
			If you had any problems with this upgrade, or have any problems using SMF, please don\'t hesitate to <a href="http://www.simplemachines.org/community/index.php">look to us for assistance</a>.<br />
			<br />
			Best of luck,<br />
			Simple Machines';
    return true;
}