Example #1
0
/**
 * Delete the damn thing!
 * Finalizes the upgrade
 * Updates maintenance mode to what it was before the upgrade started
 * Updates settings.php, sometimes even correctly
 * Flushes the cache so there is a clean start
 * Runs a scheduled fetch files so the install can be checked in the admin panel
 */
function action_deleteUpgrade()
{
    global $command_line, $language, $upcontext, $forum_version, $user_info, $maintenance, $db_type;
    // Now it's nice to have some of the basic source files.
    if (!isset($_GET['ssi']) && !$command_line) {
        redirectLocation('&ssi=1');
    }
    $upcontext['sub_template'] = 'upgrade_complete';
    $upcontext['page_title'] = 'Upgrade Complete';
    $endl = $command_line ? "\n" : '<br />' . "\n";
    $changes = array('language' => '\'' . (substr($language, -4) == '.lng' ? substr($language, 0, -4) : $language) . '\'', 'db_error_send' => '1');
    // Are we in maintenance mode?
    if (isset($upcontext['user']['main'])) {
        if ($command_line) {
            echo ' * ';
        }
        $upcontext['removed_maintenance'] = true;
        $changes['maintenance'] = $upcontext['user']['main'];
    } elseif (!empty($maintenance) && $maintenance == 2) {
        $changes['maintenance'] = 1;
    }
    // Wipe this out...
    $upcontext['user'] = array();
    // @todo this is mad and needs to be looked at
    // Make a backup of Settings.php first as otherwise earlier changes are lost.
    copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php');
    changeSettings($changes);
    // Now remove our marker
    $changes = array('upgradeData' => '#remove#');
    changeSettings($changes);
    copy(BOARDDIR . '/Settings.php', BOARDDIR . '/Settings_bak.php');
    // Clean any old cache files away.
    clean_cache();
    // Can we delete the file?
    $upcontext['can_delete_script'] = is_writable(dirname(__FILE__)) || is_writable(__FILE__);
    // Now is the perfect time to fetch the ELK files.
    if ($command_line) {
        cli_scheduled_fetchFiles();
    } else {
        // The variable is usually defined in index.php so lets just use the constant to do it for us.
        $forum_version = CURRENT_VERSION;
        // Now go get those files!
        require_once SUBSDIR . '/ScheduledTask.class.php';
        $task = new Scheduled_Task();
        $task->fetchFiles();
    }
    // Log what we've done.
    if (empty($user_info['id'])) {
        $user_info['id'] = !empty($upcontext['user']['id']) ? $upcontext['user']['id'] : 0;
    }
    // We need to log in the database
    $db = database();
    // Log the action manually, so CLI still works.
    $db->insert('', '{db_prefix}log_actions', array('log_time' => 'int', 'id_log' => 'int', 'id_member' => 'int', 'ip' => 'string-16', 'action' => 'string', 'id_board' => 'int', 'id_topic' => 'int', 'id_msg' => 'int', 'extra' => 'string-65534'), array(time(), 3, $user_info['id'], $command_line ? '127.0.0.1' : $user_info['ip'], 'upgrade', 0, 0, 0, serialize(array('version' => $forum_version, 'member' => $user_info['id']))), array('id_action'));
    $user_info['id'] = 0;
    // Save the current database version.
    $server_version = $db->db_server_info();
    if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
        updateSettings(array('db_mysql_group_by_fix' => '1'));
    }
    // Set jquery to auto if its not already set
    if (!isset($modSettings['jquery_source'])) {
        updateSettings(array('jquery_source' => 'auto'));
    }
    if ($command_line) {
        echo $endl;
        echo 'Upgrade Complete!', $endl;
        echo 'Please delete this file as soon as possible for security reasons.', $endl;
        exit;
    }
    // Make sure it says we're done.
    $upcontext['overall_percent'] = 100;
    if (isset($upcontext['step_progress'])) {
        unset($upcontext['step_progress']);
    }
    $_GET['substep'] = 0;
    return false;
}
Example #2
0
/**
 * Final step, clean up and a complete message!
 */
function action_deleteInstall()
{
    global $txt, $incontext, $db_character_set;
    global $current_version, $databases, $forum_version, $modSettings, $user_info, $db_type;
    // A few items we will load in from settings and make avaialble.
    global $boardurl, $db_prefix, $cookiename, $mbname, $language;
    $incontext['page_title'] = $txt['congratulations'];
    $incontext['sub_template'] = 'delete_install';
    $incontext['continue'] = 0;
    require dirname(__FILE__) . '/Settings.php';
    if (!defined('ELK')) {
        define('ELK', 1);
    }
    definePaths();
    $db = load_database();
    if (!defined('SUBSDIR')) {
        define('SUBSDIR', dirname(__FILE__) . '/sources/subs');
    }
    chdir(dirname(__FILE__));
    require_once SOURCEDIR . '/Errors.php';
    require_once SOURCEDIR . '/Logging.php';
    require_once SOURCEDIR . '/Subs.php';
    require_once SOURCEDIR . '/Load.php';
    require_once SUBSDIR . '/Cache.subs.php';
    require_once SOURCEDIR . '/Security.php';
    require_once SUBSDIR . '/Auth.subs.php';
    require_once SUBSDIR . '/Util.class.php';
    // Bring a warning over.
    if (!empty($incontext['account_existed'])) {
        $incontext['warning'] = $incontext['account_existed'];
    }
    if (!empty($db_character_set) && !empty($databases[$db_type]['utf8_support'])) {
        $db->query('', '
			SET NAMES {raw:db_character_set}', array('db_character_set' => $db_character_set, 'db_error_skip' => true));
    }
    // As track stats is by default enabled let's add some activity.
    $db->insert('ignore', '{db_prefix}log_activity', array('date' => 'date', 'topics' => 'int', 'posts' => 'int', 'registers' => 'int'), array(strftime('%Y-%m-%d', time()), 1, 1, !empty($incontext['member_id']) ? 1 : 0), array('date'));
    // We're going to want our lovely $modSettings now.
    $request = $db->query('', '
		SELECT variable, value
		FROM {db_prefix}settings', array('db_error_skip' => true));
    // Only proceed if we can load the data.
    if ($request) {
        while ($row = $db->fetch_row($request)) {
            $modSettings[$row[0]] = $row[1];
        }
        $db->free_result($request);
    }
    // Automatically log them in ;)
    if (isset($incontext['member_id']) && isset($incontext['member_salt'])) {
        setLoginCookie(3153600 * 60, $incontext['member_id'], hash('sha256', $incontext['passwd'] . $incontext['member_salt']));
    }
    $result = $db->query('', '
		SELECT value
		FROM {db_prefix}settings
		WHERE variable = {string:db_sessions}', array('db_sessions' => 'databaseSession_enable', 'db_error_skip' => true));
    if ($db->num_rows($result) != 0) {
        list($db_sessions) = $db->fetch_row($result);
    }
    $db->free_result($result);
    if (empty($db_sessions)) {
        $_SESSION['admin_time'] = time();
    } else {
        $_SERVER['HTTP_USER_AGENT'] = substr($_SERVER['HTTP_USER_AGENT'], 0, 211);
        $db->insert('replace', '{db_prefix}sessions', array('session_id' => 'string', 'last_update' => 'int', 'data' => 'string'), array(session_id(), time(), 'USER_AGENT|s:' . strlen($_SERVER['HTTP_USER_AGENT']) . ':"' . $_SERVER['HTTP_USER_AGENT'] . '";admin_time|i:' . time() . ';'), array('session_id'));
    }
    updateStats('member');
    updateStats('message');
    updateStats('topic');
    $request = $db->query('', '
		SELECT id_msg
		FROM {db_prefix}messages
		WHERE id_msg = 1
			AND modified_time = 0
		LIMIT 1', array('db_error_skip' => true));
    if ($db->num_rows($request) > 0) {
        updateStats('subject', 1, htmlspecialchars($txt['default_topic_subject']));
    }
    $db->free_result($request);
    // Now is the perfect time to fetch remote files.
    require_once SUBSDIR . '/ScheduledTask.class.php';
    // Sanity check that they loaded earlier!
    if (isset($modSettings['recycle_board'])) {
        // The variable is usually defined in index.php so lets just use our variable to do it for us.
        $forum_version = $current_version;
        // Now go get those files!
        $task = new Scheduled_Task();
        $task->fetchFiles();
        // We've just installed!
        $user_info['ip'] = $_SERVER['REMOTE_ADDR'];
        $user_info['id'] = isset($incontext['member_id']) ? $incontext['member_id'] : 0;
        logAction('install', array('version' => $forum_version), 'admin');
    }
    // Check if we need some stupid MySQL fix.
    $server_version = $db->db_server_info();
    if ($db_type == 'mysql' && in_array(substr($server_version, 0, 6), array('5.0.50', '5.0.51'))) {
        updateSettings(array('db_mysql_group_by_fix' => '1'));
    }
    // Some final context for the template.
    $incontext['dir_still_writable'] = is_writable(dirname(__FILE__)) && substr(__FILE__, 1, 2) != ':\\';
    $incontext['probably_delete_install'] = isset($_SESSION['installer_temp_ftp']) || is_writable(dirname(__FILE__)) || is_writable(__FILE__);
    return false;
}