Example #1
0
/**
 * Retrieves all the ban items belonging to a certain ban group
 *
 * @package Bans
 * @param int $start
 * @param int $items_per_page
 * @param int $sort
 * @param int $ban_group_id
 * @return array
 */
function list_getBanItems($start = 0, $items_per_page = 0, $sort = 0, $ban_group_id = 0)
{
    global $context, $scripturl;
    $db = database();
    $ban_items = array();
    $request = $db->query('', '
		SELECT
			bi.id_ban, bi.hostname, bi.email_address, bi.id_member, bi.hits,
			bi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4,
			bi.ip_low5, bi.ip_high5, bi.ip_low6, bi.ip_high6, bi.ip_low7, bi.ip_high7, bi.ip_low8, bi.ip_high8,
			bg.id_ban_group, bg.name, bg.ban_time, bg.expire_time, bg.reason, bg.notes, bg.cannot_access, bg.cannot_register, bg.cannot_login, bg.cannot_post,
			IFNULL(mem.id_member, 0) AS id_member, mem.member_name, mem.real_name
		FROM {db_prefix}ban_groups AS bg
			LEFT JOIN {db_prefix}ban_items AS bi ON (bi.id_ban_group = bg.id_ban_group)
			LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = bi.id_member)
		WHERE bg.id_ban_group = {int:current_ban}
		LIMIT {int:start}, {int:items_per_page}', array('current_ban' => $ban_group_id, 'start' => $start, 'items_per_page' => $items_per_page));
    if ($db->num_rows($request) == 0) {
        fatal_lang_error('ban_not_found', false);
    }
    while ($row = $db->fetch_assoc($request)) {
        if (!isset($context['ban'])) {
            $context['ban'] = array('id' => $row['id_ban_group'], 'name' => $row['name'], 'expiration' => array('status' => $row['expire_time'] === null ? 'never' : ($row['expire_time'] < time() ? 'expired' : 'one_day'), 'days' => $row['expire_time'] > time() ? floor(($row['expire_time'] - time()) / 86400) : 0), 'reason' => $row['reason'], 'notes' => $row['notes'], 'cannot' => array('access' => !empty($row['cannot_access']), 'post' => !empty($row['cannot_post']), 'register' => !empty($row['cannot_register']), 'login' => !empty($row['cannot_login'])), 'is_new' => false, 'hostname' => '', 'email' => '');
        }
        if (!empty($row['id_ban'])) {
            $ban_items[$row['id_ban']] = array('id' => $row['id_ban'], 'hits' => $row['hits']);
            if (!empty($row['ip_high1'])) {
                $ban_items[$row['id_ban']]['type'] = 'ip';
                $ban_items[$row['id_ban']]['ip'] = range2ip(array($row['ip_low1'], $row['ip_low2'], $row['ip_low3'], $row['ip_low4'], $row['ip_low5'], $row['ip_low6'], $row['ip_low7'], $row['ip_low8']), array($row['ip_high1'], $row['ip_high2'], $row['ip_high3'], $row['ip_high4'], $row['ip_high5'], $row['ip_high6'], $row['ip_high7'], $row['ip_high8']));
            } elseif (!empty($row['hostname'])) {
                $ban_items[$row['id_ban']]['type'] = 'hostname';
                $ban_items[$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
            } elseif (!empty($row['email_address'])) {
                $ban_items[$row['id_ban']]['type'] = 'email';
                $ban_items[$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
            } elseif (!empty($row['id_member'])) {
                $ban_items[$row['id_ban']]['type'] = 'user';
                $ban_items[$row['id_ban']]['user'] = array('id' => $row['id_member'], 'name' => $row['real_name'], 'href' => $scripturl . '?action=profile;u=' . $row['id_member'], 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>');
            } else {
                unset($ban_items[$row['id_ban']]);
                removeBanTriggers($row['id_ban']);
            }
        }
    }
    $db->free_result($request);
    return $ban_items;
}
Example #2
0
    /**
     * This handles the screen for showing the banned entities
     *
     * What it does:
     * - It is accessed by ?action=admin;area=ban;sa=browse
     * - It uses sub-tabs for browsing by IP, hostname, email or username.
     *
     * @uses ManageBans template, browse_triggers sub template.
     */
    public function action_browse()
    {
        global $modSettings, $context, $scripturl, $txt;
        require_once SUBSDIR . '/Bans.subs.php';
        if (!empty($_POST['remove_triggers']) && !empty($_POST['remove']) && is_array($_POST['remove'])) {
            checkSession();
            // Make sure every entry is a proper integer.
            $to_remove = array_map('intval', $_POST['remove']);
            removeBanTriggers($to_remove);
            // Rehabilitate some members.
            if ($_REQUEST['entity'] == 'member') {
                updateBanMembers();
            }
            // Make sure the ban cache is refreshed.
            updateSettings(array('banLastUpdated' => time()));
        }
        $context['selected_entity'] = isset($_REQUEST['entity']) && in_array($_REQUEST['entity'], array('ip', 'hostname', 'email', 'member')) ? $_REQUEST['entity'] : 'ip';
        $listOptions = array('id' => 'ban_trigger_list', 'title' => $txt['ban_trigger_browse'], 'items_per_page' => $modSettings['defaultMaxMessages'], 'base_href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=' . $context['selected_entity'], 'default_sort_col' => 'banned_entity', 'no_items_label' => $txt['ban_no_triggers'], 'get_items' => array('function' => 'list_getBanTriggers', 'params' => array($context['selected_entity'])), 'get_count' => array('function' => 'list_getNumBanTriggers', 'params' => array($context['selected_entity'])), 'columns' => array('banned_entity' => array('header' => array('value' => $txt['ban_banned_entity'])), 'ban_name' => array('header' => array('value' => $txt['ban_name']), 'data' => array('sprintf' => array('format' => '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=%1$d">%2$s</a>', 'params' => array('id_ban_group' => false, 'name' => false))), 'sort' => array('default' => 'bg.name', 'reverse' => 'bg.name DESC')), 'hits' => array('header' => array('value' => $txt['ban_hits']), 'data' => array('db' => 'hits'), 'sort' => array('default' => 'bi.hits DESC', 'reverse' => 'bi.hits')), 'check' => array('header' => array('value' => '<input type="checkbox" onclick="invertAll(this, this.form);" class="input_check" />', 'class' => 'centertext'), 'data' => array('sprintf' => array('format' => '<input type="checkbox" name="remove[]" value="%1$d" class="input_check" />', 'params' => array('id_ban' => false)), 'class' => 'centertext'))), 'form' => array('href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=' . $context['selected_entity'], 'include_start' => true, 'include_sort' => true), 'additional_rows' => array(array('position' => 'bottom_of_list', 'value' => '<input type="submit" name="remove_triggers" value="' . $txt['ban_remove_selected_triggers'] . '" onclick="return confirm(\'' . $txt['ban_remove_selected_triggers_confirm'] . '\');" class="right_submit" />')), 'list_menu' => array('show_on' => 'top', 'links' => array(array('href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=ip', 'is_selected' => $context['selected_entity'] == 'ip', 'label' => $txt['ip']), array('href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=hostname', 'is_selected' => $context['selected_entity'] == 'hostname', 'label' => $txt['hostname']), array('href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=email', 'is_selected' => $context['selected_entity'] == 'email', 'label' => $txt['email']), array('href' => $scripturl . '?action=admin;area=ban;sa=browse;entity=member', 'is_selected' => $context['selected_entity'] == 'member', 'label' => $txt['username']))));
        // Specific data for the first column depending on the selected entity.
        if ($context['selected_entity'] === 'ip') {
            $listOptions['columns']['banned_entity']['data'] = array('function' => create_function('$rowData', '
					return range2ip(array(
						$rowData[\'ip_low1\'],
						$rowData[\'ip_low2\'],
						$rowData[\'ip_low3\'],
						$rowData[\'ip_low4\'],
						$rowData[\'ip_low5\'],
						$rowData[\'ip_low6\'],
						$rowData[\'ip_low7\'],
						$rowData[\'ip_low8\']
					), array(
						$rowData[\'ip_high1\'],
						$rowData[\'ip_high2\'],
						$rowData[\'ip_high3\'],
						$rowData[\'ip_high4\'],
						$rowData[\'ip_high5\'],
						$rowData[\'ip_high6\'],
						$rowData[\'ip_high7\'],
						$rowData[\'ip_high8\']
					));
				'));
            $listOptions['columns']['banned_entity']['sort'] = array('default' => 'bi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4, bi.ip_low5, bi.ip_high5, bi.ip_low6, bi.ip_high6, bi.ip_low7, bi.ip_high7, bi.ip_low8, bi.ip_high8', 'reverse' => 'bi.ip_low1 DESC, bi.ip_high1 DESC, bi.ip_low2 DESC, bi.ip_high2 DESC, bi.ip_low3 DESC, bi.ip_high3 DESC, bi.ip_low4 DESC, bi.ip_high4 DESC, bi.ip_low5 DESC, bi.ip_high5 DESC, bi.ip_low6 DESC, bi.ip_high6 DESC, bi.ip_low7 DESC, bi.ip_high7 DESC, bi.ip_low8 DESC, bi.ip_high8 DESC');
        } elseif ($context['selected_entity'] === 'hostname') {
            $listOptions['columns']['banned_entity']['data'] = array('function' => create_function('$rowData', '
					return strtr(Util::htmlspecialchars($rowData[\'hostname\']), array(\'%\' => \'*\'));
				'));
            $listOptions['columns']['banned_entity']['sort'] = array('default' => 'bi.hostname', 'reverse' => 'bi.hostname DESC');
        } elseif ($context['selected_entity'] === 'email') {
            $listOptions['columns']['banned_entity']['data'] = array('function' => create_function('$rowData', '
					return strtr(Util::htmlspecialchars($rowData[\'email_address\']), array(\'%\' => \'*\'));
				'));
            $listOptions['columns']['banned_entity']['sort'] = array('default' => 'bi.email_address', 'reverse' => 'bi.email_address DESC');
        } elseif ($context['selected_entity'] === 'member') {
            $listOptions['columns']['banned_entity']['data'] = array('sprintf' => array('format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>', 'params' => array('id_member' => false, 'real_name' => false)));
            $listOptions['columns']['banned_entity']['sort'] = array('default' => 'mem.real_name', 'reverse' => 'mem.real_name DESC');
        }
        // Create the list.
        require_once SUBSDIR . '/GenericList.class.php';
        createList($listOptions);
    }