示例#1
0
function scheduled_daily_maintenance()
{
    global $modSettings, $sourcedir, $db_type;
    // First clean out the cache.
    clean_cache();
    // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
    list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
    if ($modSettings['warning_decrement']) {
        // Find every member who has a warning level...
        $request = smf_db_query('
			SELECT id_member, warning
			FROM {db_prefix}members
			WHERE warning > {int:no_warning}', array('no_warning' => 0));
        $members = array();
        while ($row = mysql_fetch_assoc($request)) {
            $members[$row['id_member']] = $row['warning'];
        }
        mysql_free_result($request);
        // Have some members to check?
        if (!empty($members)) {
            // Find out when they were last warned.
            $request = smf_db_query('
				SELECT id_recipient, MAX(log_time) AS last_warning
				FROM {db_prefix}log_comments
				WHERE id_recipient IN ({array_int:member_list})
					AND comment_type = {string:warning}
				GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning'));
            $member_changes = array();
            while ($row = mysql_fetch_assoc($request)) {
                // More than 24 hours ago?
                if ($row['last_warning'] <= time() - 86400) {
                    $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0);
                }
            }
            mysql_free_result($request);
            // Have some members to change?
            if (!empty($member_changes)) {
                foreach ($member_changes as $change) {
                    smf_db_query('
						UPDATE {db_prefix}members
						SET warning = {int:warning}
						WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id']));
                }
            }
        }
    }
    // Do any spider stuff.
    if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) {
        require_once $sourcedir . '/ManageSearchEngines.php';
        consolidateSpiderStats();
    }
    // Check the database version - for some buggy MySQL version.
    $server_version = mysql_get_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'));
    } elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
        smf_db_query('
			DELETE FROM {db_prefix}settings
			WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix'));
    }
    // Regenerate the Diffie-Hellman keys if OpenID is enabled.
    if (!empty($modSettings['enableOpenID'])) {
        require_once $sourcedir . '/lib/Subs-OpenID.php';
        smf_openID_setup_DH(true);
    } elseif (!empty($modSettings['dh_keys'])) {
        smf_db_query('
			DELETE FROM {db_prefix}settings
			WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys'));
    }
    // clean out old cached posts
    if ($modSettings['post_cache_cutoff'] < 10) {
        $modSettings['post_cache_cutoff'] = 10;
    }
    smf_db_query('
		DELETE FROM {db_prefix}messages_cache WHERE updated < {int:cutoff}', array('cutoff' => time() - $modSettings['post_cache_cutoff'] * 86400));
    // auto-expire topicbans (expires == 0 means the ban is permanent until lifted manually, so do not expire them)
    smf_db_query('DELETE FROM {db_prefix}topicbans WHERE expires <> 0 AND expires <= UNIX_TIMESTAMP(NOW())');
    HookAPI::callHook('sys_daily_maint');
    // Log we've done it...
    return true;
}
示例#2
0
function SpiderStats()
{
    global $context, $txt, $sourcedir, $scripturl, $smcFunc;
    // Force an update of the stats every 60 seconds.
    if (!isset($_SESSION['spider_stat']) || $_SESSION['spider_stat'] < time() - 60) {
        consolidateSpiderStats();
        $_SESSION['spider_stat'] = time();
    }
    // Get the earliest and latest dates.
    $request = $smcFunc['db_query']('', '
		SELECT MIN(stat_date) AS first_date, MAX(stat_date) AS last_date
		FROM {db_prefix}log_spider_stats', array());
    list($min_date, $max_date) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    $min_year = (int) substr($min_date, 0, 4);
    $max_year = (int) substr($max_date, 0, 4);
    $min_month = (int) substr($min_date, 5, 2);
    $max_month = (int) substr($max_date, 5, 2);
    // Prepare the dates for the drop down.
    $date_choices = array();
    for ($y = $min_year; $y <= $max_year; $y++) {
        for ($m = 1; $m <= 12; $m++) {
            // This doesn't count?
            if ($y == $min_year && $m < $min_month) {
                continue;
            }
            if ($y == $max_year && $m > $max_month) {
                break;
            }
            $date_choices[$y . $m] = $txt['months_short'][$m] . ' ' . $y;
        }
    }
    // What are we currently viewing?
    $current_date = isset($_REQUEST['new_date']) && isset($date_choices[$_REQUEST['new_date']]) ? $_REQUEST['new_date'] : $max_date;
    // Prepare the HTML.
    $date_select = '
		' . $txt['spider_stats_select_month'] . ':
		<select name="new_date" onchange="document.spider_stat_list.submit();">';
    if (empty($date_choices)) {
        $date_select .= '
			<option></option>';
    } else {
        foreach ($date_choices as $id => $text) {
            $date_select .= '
			<option value="' . $id . '"' . ($current_date == $id ? ' selected="selected"' : '') . '>' . $text . '</option>';
        }
    }
    $date_select .= '
		</select>
		<noscript>
			<input type="submit" name="go" value="' . $txt['go'] . '" class="button_submit" />
		</noscript>';
    // If we manually jumped to a date work out the offset.
    if (isset($_REQUEST['new_date'])) {
        $date_query = sprintf('%04d-%02d-01', substr($current_date, 0, 4), substr($current_date, 4));
        $request = $smcFunc['db_query']('', '
			SELECT COUNT(*) AS offset
			FROM {db_prefix}log_spider_stats
			WHERE stat_date < {date:date_being_viewed}', array('date_being_viewed' => $date_query));
        list($_REQUEST['start']) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
    }
    $listOptions = array('id' => 'spider_stat_list', 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=sengines;sa=stats', 'default_sort_col' => 'stat_date', 'get_items' => array('function' => 'list_getSpiderStats'), 'get_count' => array('function' => 'list_getNumSpiderStats'), 'no_items_label' => $txt['spider_stats_no_entries'], 'columns' => array('stat_date' => array('header' => array('value' => $txt['date']), 'data' => array('db' => 'stat_date'), 'sort' => array('default' => 'stat_date', 'reverse' => 'stat_date DESC')), 'name' => array('header' => array('value' => $txt['spider_name']), 'data' => array('db' => 'spider_name'), 'sort' => array('default' => 's.spider_name', 'reverse' => 's.spider_name DESC')), 'page_hits' => array('header' => array('value' => $txt['spider_stats_page_hits']), 'data' => array('db' => 'page_hits'), 'sort' => array('default' => 'ss.page_hits', 'reverse' => 'ss.page_hits DESC'))), 'form' => array('href' => $scripturl . '?action=admin;area=sengines;sa=stats', 'name' => 'spider_stat_list'), 'additional_rows' => array(array('position' => 'below_table_data', 'value' => $date_select, 'style' => 'text-align: right;')));
    require_once $sourcedir . '/Subs-List.php';
    createList($listOptions);
    $context['sub_template'] = 'show_list';
    $context['default_list'] = 'spider_stat_list';
}
    /**
     * Show the spider statistics.
     */
    public function action_stats()
    {
        global $context, $txt, $scripturl;
        // We'll need to do hard work here.
        require_once SUBSDIR . '/SearchEngines.subs.php';
        // Force an update of the stats every 60 seconds.
        if (!isset($_SESSION['spider_stat']) || $_SESSION['spider_stat'] < time() - 60) {
            consolidateSpiderStats();
            $_SESSION['spider_stat'] = time();
        }
        // Are we cleaning up some old stats?
        if (!empty($_POST['delete_entries']) && isset($_POST['older'])) {
            checkSession();
            validateToken('admin-ss');
            $deleteTime = time() - (int) $_POST['older'] * 24 * 60 * 60;
            // Delete the entires.
            removeSpiderOldStats($deleteTime);
        }
        // Prepare the dates for the drop down.
        $date_choices = spidersStatsDates();
        end($date_choices);
        $max_date = key($date_choices);
        // What are we currently viewing?
        $current_date = isset($_REQUEST['new_date']) && isset($date_choices[$_REQUEST['new_date']]) ? $_REQUEST['new_date'] : $max_date;
        // Prepare the HTML.
        $date_select = '
			' . $txt['spider_stats_select_month'] . ':
			<select name="new_date" onchange="document.spider_stat_list.submit();">';
        if (empty($date_choices)) {
            $date_select .= '
				<option></option>';
        } else {
            foreach ($date_choices as $id => $text) {
                $date_select .= '
				<option value="' . $id . '"' . ($current_date == $id ? ' selected="selected"' : '') . '>' . $text . '</option>';
            }
        }
        $date_select .= '
			</select>
			<noscript>
				<input type="submit" name="go" value="' . $txt['go'] . '" class="right_submit" />
			</noscript>';
        // If we manually jumped to a date work out the offset.
        if (isset($_REQUEST['new_date'])) {
            $date_query = sprintf('%04d-%02d-01', substr($current_date, 0, 4), substr($current_date, 4));
            $_REQUEST['start'] = getNumSpiderStats($date_query);
        }
        $listOptions = array('id' => 'spider_stat_list', 'title' => $txt['spider'] . ' ' . $txt['spider_stats'], 'items_per_page' => 20, 'base_href' => $scripturl . '?action=admin;area=sengines;sa=stats', 'default_sort_col' => 'stat_date', 'get_items' => array('function' => 'getSpiderStats'), 'get_count' => array('function' => 'getNumSpiderStats', 'file' => SUBSDIR . '/SearchEngines.subs.php'), 'no_items_label' => $txt['spider_stats_no_entries'], 'columns' => array('stat_date' => array('header' => array('value' => $txt['date']), 'data' => array('db' => 'stat_date'), 'sort' => array('default' => 'stat_date', 'reverse' => 'stat_date DESC')), 'name' => array('header' => array('value' => $txt['spider_name']), 'data' => array('db' => 'spider_name'), 'sort' => array('default' => 's.spider_name', 'reverse' => 's.spider_name DESC')), 'page_hits' => array('header' => array('value' => $txt['spider_stats_page_hits']), 'data' => array('db' => 'page_hits'), 'sort' => array('default' => 'ss.page_hits', 'reverse' => 'ss.page_hits DESC'))), 'form' => array('href' => $scripturl . '?action=admin;area=sengines;sa=stats', 'name' => 'spider_stat_list'), 'additional_rows' => array(array('position' => 'below_table_data', 'value' => $date_select, 'style' => 'text-align: right;')));
        createToken('admin-ss');
        require_once SUBSDIR . '/GenericList.class.php';
        createList($listOptions);
        $context['sub_template'] = 'show_spider_stats';
    }
function scheduled_daily_maintenance()
{
    global $smcFunc, $modSettings, $sourcedir, $db_type;
    // First clean out the cache.
    clean_cache();
    // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
    list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
    if ($modSettings['warning_decrement']) {
        // Find every member who has a warning level...
        $request = $smcFunc['db_query']('', '
			SELECT id_member, warning
			FROM {db_prefix}members
			WHERE warning > {int:no_warning}', array('no_warning' => 0));
        $members = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $members[$row['id_member']] = $row['warning'];
        }
        $smcFunc['db_free_result']($request);
        // Have some members to check?
        if (!empty($members)) {
            // Find out when they were last warned.
            $request = $smcFunc['db_query']('', '
				SELECT id_recipient, MAX(log_time) AS last_warning
				FROM {db_prefix}log_comments
				WHERE id_recipient IN ({array_int:member_list})
					AND comment_type = {string:warning}
				GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning'));
            $member_changes = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                // More than 24 hours ago?
                if ($row['last_warning'] <= time() - 86400) {
                    $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0);
                }
            }
            $smcFunc['db_free_result']($request);
            // Have some members to change?
            if (!empty($member_changes)) {
                foreach ($member_changes as $change) {
                    $smcFunc['db_query']('', '
						UPDATE {db_prefix}members
						SET warning = {int:warning}
						WHERE id_member = {int:id_member}', array('warning' => $change['warning'], 'id_member' => $change['id']));
                }
            }
        }
    }
    // Do any spider stuff.
    if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) {
        require_once $sourcedir . '/ManageSearchEngines.php';
        consolidateSpiderStats();
    }
    // Check the database version - for some buggy MySQL version.
    $server_version = $smcFunc['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'));
    } elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}settings
			WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix'));
    }
    // Regenerate the Diffie-Hellman keys if OpenID is enabled.
    if (!empty($modSettings['enableOpenID'])) {
        require_once $sourcedir . '/Subs-OpenID.php';
        smf_openID_setup_DH(true);
    } elseif (!empty($modSettings['dh_keys'])) {
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}settings
			WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys'));
    }
    // Log we've done it...
    return true;
}
示例#5
0
    /**
     * This function does daily cleaning up:
     *
     * - decrements warning levels if it's enabled
     * - consolidate spider statistics
     * - fix MySQL version
     * - regenerate Diffie-Hellman keys for OpenID
     * - remove obsolete login history logs
     */
    public function daily_maintenance()
    {
        global $modSettings, $db_type;
        $db = database();
        // First clean out the cache.
        clean_cache('data');
        // If warning decrement is enabled and we have people who have not had a new warning in 24 hours, lower their warning level.
        list(, , $modSettings['warning_decrement']) = explode(',', $modSettings['warning_settings']);
        if ($modSettings['warning_decrement']) {
            // Find every member who has a warning level...
            $request = $db->query('', '
				SELECT id_member, warning
				FROM {db_prefix}members
				WHERE warning > {int:no_warning}', array('no_warning' => 0));
            $members = array();
            while ($row = $db->fetch_assoc($request)) {
                $members[$row['id_member']] = $row['warning'];
            }
            $db->free_result($request);
            // Have some members to check?
            if (!empty($members)) {
                // Find out when they were last warned.
                $request = $db->query('', '
					SELECT id_recipient, MAX(log_time) AS last_warning
					FROM {db_prefix}log_comments
					WHERE id_recipient IN ({array_int:member_list})
						AND comment_type = {string:warning}
					GROUP BY id_recipient', array('member_list' => array_keys($members), 'warning' => 'warning'));
                $member_changes = array();
                while ($row = $db->fetch_assoc($request)) {
                    // More than 24 hours ago?
                    if ($row['last_warning'] <= time() - 86400) {
                        $member_changes[] = array('id' => $row['id_recipient'], 'warning' => $members[$row['id_recipient']] >= $modSettings['warning_decrement'] ? $members[$row['id_recipient']] - $modSettings['warning_decrement'] : 0);
                    }
                }
                $db->free_result($request);
                // Have some members to change?
                if (!empty($member_changes)) {
                    foreach ($member_changes as $change) {
                        updateMemberData($change['id'], array('warning' => $change['warning']));
                    }
                }
            }
        }
        // Do any spider stuff.
        if (!empty($modSettings['spider_mode']) && $modSettings['spider_mode'] > 1) {
            // We'll need this.
            require_once SUBSDIR . '/SearchEngines.subs.php';
            consolidateSpiderStats();
        }
        // Check the database version - for some buggy MySQL 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'));
        } elseif (!empty($modSettings['db_mysql_group_by_fix'])) {
            $db->query('', '
				DELETE FROM {db_prefix}settings
				WHERE variable = {string:mysql_fix}', array('mysql_fix' => 'db_mysql_group_by_fix'));
        }
        // Regenerate the Diffie-Hellman keys if OpenID is enabled.
        if (!empty($modSettings['enableOpenID'])) {
            require_once SUBSDIR . '/OpenID.subs.php';
            $openID = new OpenID();
            $openID->setup_DH(true);
        } elseif (!empty($modSettings['dh_keys'])) {
            $db->query('', '
				DELETE FROM {db_prefix}settings
				WHERE variable = {string:dh_keys}', array('dh_keys' => 'dh_keys'));
        }
        // Clean up some old login history information.
        $db->query('', '
			DELETE FROM {db_prefix}member_logins
			WHERE time > {int:oldLogins}', array('oldLogins' => !empty($modSettings['loginHistoryDays']) ? 60 * 60 * $modSettings['loginHistoryDays'] : 108000));
        // Log we've done it...
        return true;
    }