Beispiel #1
0
function BanEditTrigger()
{
    global $context, $smcFunc;
    $context['sub_template'] = 'ban_edit_trigger';
    if (empty($_REQUEST['bg'])) {
        fatal_lang_error('ban_not_found', false);
    }
    if (empty($_REQUEST['bi'])) {
        $context['ban_trigger'] = array('id' => 0, 'group' => (int) $_REQUEST['bg'], 'ip' => array('value' => '', 'selected' => true), 'hostname' => array('selected' => false, 'value' => ''), 'email' => array('value' => '', 'selected' => false), 'banneduser' => array('value' => '', 'selected' => false), 'is_new' => true);
    } else {
        $request = $smcFunc['db_query']('', '
			SELECT
				bi.id_ban, bi.id_ban_group, bi.hostname, bi.email_address, bi.id_member,
				bi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4,
				mem.member_name, mem.real_name
			FROM {db_prefix}ban_items AS bi
				LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = bi.id_member)
			WHERE bi.id_ban = {int:ban_item}
				AND bi.id_ban_group = {int:ban_group}
			LIMIT 1', array('ban_item' => (int) $_REQUEST['bi'], 'ban_group' => (int) $_REQUEST['bg']));
        if ($smcFunc['db_num_rows']($request) == 0) {
            fatal_lang_error('ban_not_found', false);
        }
        $row = $smcFunc['db_fetch_assoc']($request);
        $smcFunc['db_free_result']($request);
        $context['ban_trigger'] = array('id' => $row['id_ban'], 'group' => $row['id_ban_group'], 'ip' => array('value' => empty($row['ip_low1']) ? '' : range2ip(array($row['ip_low1'], $row['ip_low2'], $row['ip_low3'], $row['ip_low4']), array($row['ip_high1'], $row['ip_high2'], $row['ip_high3'], $row['ip_high4'])), 'selected' => !empty($row['ip_low1'])), 'hostname' => array('value' => str_replace('%', '*', $row['hostname']), 'selected' => !empty($row['hostname'])), 'email' => array('value' => str_replace('%', '*', $row['email_address']), 'selected' => !empty($row['email_address'])), 'banneduser' => array('value' => $row['member_name'], 'selected' => !empty($row['member_name'])), 'is_new' => false);
    }
}
Beispiel #2
0
function BanBrowseTriggers()
{
    global $db_prefix, $modSettings, $context, $scripturl;
    if (!empty($_POST['remove_triggers']) && !empty($_POST['remove']) && is_array($_POST['remove'])) {
        checkSession();
        // Clean the integers.
        foreach ($_POST['remove'] as $key => $value) {
            $_POST['remove'][$key] = $value;
        }
        db_query("\n\t\t\tDELETE FROM {$db_prefix}ban_items\n\t\t\tWHERE ID_BAN IN (" . implode(', ', $_POST['remove']) . ")\n\t\t\tLIMIT " . count($_POST['remove']), __FILE__, __LINE__);
        // Rehabilitate some members.
        if ($_REQUEST['entity'] == 'member') {
            updateBanMembers();
        }
        // Make sure the ban cache is refreshed.
        updateSettings(array('banLastUpdated' => time()));
    }
    $query = array('ip' => array('select' => 'bi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4', 'where' => 'bi.ip_low1 > 0', 'orderby' => 'bi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4'), 'hostname' => array('select' => 'bi.hostname', 'where' => "bi.hostname != ''", 'orderby' => 'bi.hostname'), 'email' => array('select' => 'bi.email_address', 'where' => "bi.email_address != ''", 'orderby' => 'bi.email_address'), 'member' => array('select' => 'mem.ID_MEMBER, mem.realName', 'where' => 'mem.ID_MEMBER = bi.ID_MEMBER', 'orderby' => 'mem.realName'));
    $context['selected_entity'] = isset($_REQUEST['entity']) && isset($query[$_REQUEST['entity']]) ? $_REQUEST['entity'] : 'ip';
    $request = db_query("\n\t\tSELECT COUNT(*)\n\t\tFROM ({$db_prefix}ban_items AS bi" . ($context['selected_entity'] == 'member' ? ", {$db_prefix}members AS mem" : '') . ")\n\t\tWHERE " . $query[$context['selected_entity']]['where'], __FILE__, __LINE__);
    list($num_items) = mysql_fetch_row($request);
    mysql_free_result($request);
    $context['page_index'] = constructPageIndex($scripturl . '?action=ban;sa=browse;entity=' . $context['selected_entity'], $_REQUEST['start'], $num_items, $modSettings['defaultMaxMessages']);
    $context['start'] = $_REQUEST['start'];
    $context['ban_items'] = array();
    if (!empty($num_items)) {
        $request = db_query("\n\t\t\tSELECT bi.ID_BAN, " . $query[$context['selected_entity']]['select'] . ", bi.hits, bg.ID_BAN_GROUP, bg.name\n\t\t\tFROM ({$db_prefix}ban_items AS bi, {$db_prefix}ban_groups AS bg" . ($context['selected_entity'] == 'member' ? ", {$db_prefix}members AS mem" : '') . ")\n\t\t\tWHERE " . $query[$context['selected_entity']]['where'] . "\n\t\t\t\tAND bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\tORDER BY " . $query[$context['selected_entity']]['orderby'] . "\n\t\t\tLIMIT {$context['start']}, {$modSettings['defaultMaxMessages']}", __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            $context['ban_items'][$row['ID_BAN']] = array('id' => $row['ID_BAN'], 'hits' => $row['hits'], 'group' => array('id' => $row['ID_BAN_GROUP'], 'name' => $row['name'], 'href' => $scripturl . '?action=ban;sa=edit;bg=' . $row['ID_BAN_GROUP'], 'link' => '<a href="' . $scripturl . '?action=ban;sa=edit;bg=' . $row['ID_BAN_GROUP'] . '">' . $row['name'] . '</a>'));
            if ($context['selected_entity'] == 'ip') {
                $context['ban_items'][$row['ID_BAN']]['entity'] = range2ip(array($row['ip_low1'], $row['ip_low2'], $row['ip_low3'], $row['ip_low4']), array($row['ip_high1'], $row['ip_high2'], $row['ip_high3'], $row['ip_high4']));
            } elseif ($context['selected_entity'] == 'hostname') {
                $context['ban_items'][$row['ID_BAN']]['entity'] = str_replace('%', '*', $row['hostname']);
            } elseif ($context['selected_entity'] == 'email') {
                $context['ban_items'][$row['ID_BAN']]['entity'] = str_replace('%', '*', $row['email_address']);
            } else {
                $context['ban_items'][$row['ID_BAN']]['member'] = array('id' => $row['ID_MEMBER'], 'name' => $row['realName'], 'href' => $scripturl . '?action=profile;u=' . $row['ID_MEMBER'], 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['realName'] . '</a>');
                $context['ban_items'][$row['ID_BAN']]['entity'] = $context['ban_items'][$row['ID_BAN']]['member']['link'];
            }
        }
        mysql_free_result($request);
    }
    $context['sub_template'] = 'browse_triggers';
}
Beispiel #3
0
/**
 * When removing a ban trigger, this will return the specifics of whats being
 * removed so it can be logged
 *
 * @package Bans
 * @param mixed[] $ban_details
 */
function banLogItems($ban_details)
{
    $log_info = array();
    // For each ban, get the details for logging
    foreach ($ban_details as $row) {
        // An ip ban
        if (!empty($row['ip_high1'])) {
            $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']));
            $is_range = strpos($ip, '-') !== false || strpos($ip, '*') !== false;
            $log_info[] = array('bantype' => $is_range ? 'ip_range' : 'main_ip', 'value' => $ip);
        } elseif (!empty($row['hostname'])) {
            $log_info[] = array('bantype' => 'hostname', 'value' => $row['hostname']);
        } elseif (!empty($row['email_address'])) {
            $log_info[] = array('bantype' => 'email', 'value' => str_replace('%', '*', $row['email_address']));
        } elseif (!empty($row['id_member'])) {
            $log_info[] = array('bantype' => 'user', 'value' => $row['id_member']);
        }
    }
    return $log_info;
}
 /**
  * This function handles the ins and outs of the screen for adding new ban
  * triggers or modifying existing ones.
  *
  * - Adding new ban triggers:
  *   - is accessed by ?action=admin;area=ban;sa=edittrigger;bg=x
  *   - uses the ban_edit_trigger sub template of ManageBans.
  *
  * - Editing existing ban triggers:
  *   - is accessed by ?action=admin;area=ban;sa=edittrigger;bg=x;bi=y
  *   - uses the ban_edit_trigger sub template of ManageBans.
  *
  * @uses sub template ban_edit_trigger
  */
 public function action_edittrigger()
 {
     global $context, $scripturl;
     require_once SUBSDIR . '/Bans.subs.php';
     $ban_group = isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0;
     $ban_id = isset($_REQUEST['bi']) ? (int) $_REQUEST['bi'] : 0;
     if (empty($ban_group)) {
         fatal_lang_error('ban_not_found', false);
     }
     // Adding a new trigger
     if (isset($_POST['add_new_trigger']) && !empty($_POST['ban_suggestions'])) {
         saveTriggers($_POST['ban_suggestions'], $ban_group, 0, $ban_id);
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     } elseif (isset($_POST['edit_trigger']) && !empty($_POST['ban_suggestions'])) {
         // The first replaces the old one, the others are added new
         // (simplification, otherwise it would require another query and some work...)
         saveTriggers(array_shift($_POST['ban_suggestions']), $ban_group, 0, $ban_id);
         if (!empty($_POST['ban_suggestions'])) {
             saveTriggers($_POST['ban_suggestions'], $ban_group);
         }
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     } elseif (isset($_POST['edit_trigger'])) {
         removeBanTriggers($ban_id);
         redirectexit('action=admin;area=ban;sa=edit' . (!empty($ban_group) ? ';bg=' . $ban_group : ''));
     }
     // No id supplied, this must be a new trigger being added
     if (empty($ban_id)) {
         $context['ban_trigger'] = array('id' => 0, 'group' => $ban_group, 'ip' => array('value' => '', 'selected' => true), 'hostname' => array('selected' => false, 'value' => ''), 'email' => array('value' => '', 'selected' => false), 'banneduser' => array('value' => '', 'selected' => false), 'is_new' => true);
     } else {
         $ban_row = banDetails($ban_id, $ban_group);
         if (empty($ban_row)) {
             fatal_lang_error('ban_not_found', false);
         }
         $row = $ban_row[$ban_id];
         // Load it up for the template
         $context['ban_trigger'] = array('id' => $row['id_ban'], 'group' => $row['id_ban_group'], 'ip' => array('value' => empty($row['ip_low1']) ? '' : 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'])), 'selected' => !empty($row['ip_low1'])), 'hostname' => array('value' => str_replace('%', '*', $row['hostname']), 'selected' => !empty($row['hostname'])), 'email' => array('value' => str_replace('%', '*', $row['email_address']), 'selected' => !empty($row['email_address'])), 'banneduser' => array('value' => $row['member_name'], 'selected' => !empty($row['member_name'])), 'is_new' => false);
     }
     // The template uses the autosuggest functions
     loadJavascriptFile('suggest.js');
     // Template we will use
     $context['sub_template'] = 'ban_edit_trigger';
     $context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edittrigger';
     createToken('admin-bet');
 }