示例#1
0
function is_not_banned($forceCheck = false)
{
    global $txt, $modSettings, $context, $user_info;
    global $sourcedir, $cookiename, $user_settings, $smcFunc;
    // You cannot be banned if you are an admin - doesn't help if you log out.
    if ($user_info['is_admin']) {
        return;
    }
    // Only check the ban every so often. (to reduce load.)
    if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || $_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated'] || $_SESSION['ban']['id_member'] != $user_info['id'] || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']) {
        // Innocent until proven guilty.  (but we know you are! :P)
        $_SESSION['ban'] = array('last_checked' => time(), 'id_member' => $user_info['id'], 'ip' => $user_info['ip'], 'ip2' => $user_info['ip2'], 'email' => $user_info['email']);
        $ban_query = array();
        $ban_query_vars = array('current_time' => time());
        $flag_is_activated = false;
        // Check both IP addresses.
        foreach (array('ip', 'ip2') as $ip_number) {
            // Check if we have a valid IP address.
            if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $user_info[$ip_number], $ip_parts) == 1) {
                $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
							AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
							AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
							AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))';
                // IP was valid, maybe there's also a hostname...
                if (empty($modSettings['disableHostnameLookup'])) {
                    $hostname = host_from_ip($user_info[$ip_number]);
                    if (strlen($hostname) > 0) {
                        $ban_query[] = '({string:hostname} LIKE bi.hostname)';
                        $ban_query_vars['hostname'] = $hostname;
                    }
                }
            } elseif ($user_info['ip'] == 'unknown') {
                $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255
							AND bi.ip_low2 = 255 AND bi.ip_high2 = 255
							AND bi.ip_low3 = 255 AND bi.ip_high3 = 255
							AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)';
            }
        }
        // Is their email address banned?
        if (strlen($user_info['email']) != 0) {
            $ban_query[] = '({string:email} LIKE bi.email_address)';
            $ban_query_vars['email'] = $user_info['email'];
        }
        // How about this user?
        if (!$user_info['is_guest'] && !empty($user_info['id'])) {
            $ban_query[] = 'bi.id_member = {int:id_member}';
            $ban_query_vars['id_member'] = $user_info['id'];
        }
        // Check the ban, if there's information.
        if (!empty($ban_query)) {
            $restrictions = array('cannot_access', 'cannot_login', 'cannot_post', 'cannot_register');
            $request = $smcFunc['db_query']('', '
				SELECT bi.id_ban, bi.email_address, bi.id_member, bg.cannot_access, bg.cannot_register,
					bg.cannot_post, bg.cannot_login, bg.reason, IFNULL(bg.expire_time, 0) AS expire_time
				FROM {db_prefix}ban_items AS bi
					INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time}))
				WHERE
					(' . implode(' OR ', $ban_query) . ')', $ban_query_vars);
            // Store every type of ban that applies to you in your session.
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                foreach ($restrictions as $restriction) {
                    if (!empty($row[$restriction])) {
                        $_SESSION['ban'][$restriction]['reason'] = $row['reason'];
                        $_SESSION['ban'][$restriction]['ids'][] = $row['id_ban'];
                        if (!isset($_SESSION['ban']['expire_time']) || $_SESSION['ban']['expire_time'] != 0 && ($row['expire_time'] == 0 || $row['expire_time'] > $_SESSION['ban']['expire_time'])) {
                            $_SESSION['ban']['expire_time'] = $row['expire_time'];
                        }
                        if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['id_member'] == $user_info['id'] || $row['email_address'] == $user_info['email'])) {
                            $flag_is_activated = true;
                        }
                    }
                }
            }
            $smcFunc['db_free_result']($request);
        }
        // Mark the cannot_access and cannot_post bans as being 'hit'.
        if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post']) || isset($_SESSION['ban']['cannot_login'])) {
            log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array(), isset($_SESSION['ban']['cannot_login']) ? $_SESSION['ban']['cannot_login']['ids'] : array()));
        }
        // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
        if ($user_info['id'] && ($user_settings['is_activated'] >= 10 && !$flag_is_activated || $user_settings['is_activated'] < 10 && $flag_is_activated)) {
            require_once $sourcedir . '/ManageBans.php';
            updateBanMembers();
        }
    }
    // Hey, I know you! You're ehm...
    if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) {
        $bans = explode(',', $_COOKIE[$cookiename . '_']);
        foreach ($bans as $key => $value) {
            $bans[$key] = (int) $value;
        }
        $request = $smcFunc['db_query']('', '
			SELECT bi.id_ban, bg.reason
			FROM {db_prefix}ban_items AS bi
				INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group)
			WHERE bi.id_ban IN ({array_int:ban_list})
				AND (bg.expire_time IS NULL OR bg.expire_time > {int:current_time})
				AND bg.cannot_access = {int:cannot_access}
			LIMIT ' . count($bans), array('cannot_access' => 1, 'ban_list' => $bans, 'current_time' => time()));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $_SESSION['ban']['cannot_access']['ids'][] = $row['id_ban'];
            $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
        }
        $smcFunc['db_free_result']($request);
        // My mistake. Next time better.
        if (!isset($_SESSION['ban']['cannot_access'])) {
            require_once $sourcedir . '/Subs-Auth.php';
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            setcookie($cookiename . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], 0);
        }
    }
    // If you're fully banned, it's end of the story for you.
    if (isset($_SESSION['ban']['cannot_access'])) {
        // We don't wanna see you!
        if (!$user_info['is_guest']) {
            $smcFunc['db_query']('', '
				DELETE FROM {db_prefix}log_online
				WHERE id_member = {int:current_member}', array('current_member' => $user_info['id']));
        }
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $user_info['id'] = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt['guest_title'], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'can_mod' => false, 'language' => $user_info['language']);
        // A goodbye present.
        require_once $sourcedir . '/Subs-Auth.php';
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
        setcookie($cookiename . '_', implode(',', $_SESSION['ban']['cannot_access']['ids']), time() + 3153600, $cookie_url[1], $cookie_url[0], 0);
        // Don't scare anyone, now.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        // You banned, sucka!
        fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_access']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_access']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']), 'user');
        // If we get here, something's gone wrong.... but let's try anyway.
        trigger_error('Hacking attempt...', E_USER_ERROR);
    } elseif (isset($_SESSION['ban']['cannot_login']) && !$user_info['is_guest']) {
        // We don't wanna see you!
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}log_online
			WHERE id_member = {int:current_member}', array('current_member' => $user_info['id']));
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt['guest_title'];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $user_info['id'] = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt['guest_title'], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'can_mod' => false, 'language' => $user_info['language']);
        // SMF's Wipe 'n Clean(r) erases all traces.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        require_once $sourcedir . '/LogInOut.php';
        Logout(true, false);
        fatal_error(sprintf($txt['your_ban'], $old_name) . (empty($_SESSION['ban']['cannot_login']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_login']['reason']) . '<br />' . (!empty($_SESSION['ban']['expire_time']) ? sprintf($txt['your_ban_expires'], timeformat($_SESSION['ban']['expire_time'], false)) : $txt['your_ban_expires_never']) . '<br />' . $txt['ban_continue_browse'], 'user');
    }
    // Fix up the banning permissions.
    if (isset($user_info['permissions'])) {
        banPermissions();
    }
}
示例#2
0
function summary($memID)
{
    global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
    // Attempt to load the member's profile data.
    if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
        fatal_lang_error('not_a_user', false);
    }
    // Set up the stuff and load the user.
    $context += array('page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), 'can_send_pm' => allowedTo('pm_send'), 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && $modSettings['warning_settings'][0] == 1);
    $context['member'] =& $memberContext[$memID];
    $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']);
    // Set a canonical URL for this page.
    $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
    // Are there things we don't show?
    $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
    // See if they have broken any warning levels...
    list($modSettings['warning_enable'], $modSettings['user_limit']) = explode(',', $modSettings['warning_settings']);
    if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
        $context['warning_status'] = $txt['profile_warning_is_muted'];
    } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
        $context['warning_status'] = $txt['profile_warning_is_moderation'];
    } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
        $context['warning_status'] = $txt['profile_warning_is_watch'];
    }
    // They haven't even been registered for a full day!?
    $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
    if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
        $context['member']['posts_per_day'] = $txt['not_applicable'];
    } else {
        $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
    }
    // Set the age...
    if (empty($context['member']['birth_date'])) {
        $context['member'] += array('age' => $txt['not_applicable'], 'today_is_birthday' => false);
    } else {
        list($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
        $datearray = getdate(forum_time());
        $context['member'] += array('age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1), 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day);
    }
    if (allowedTo('moderate_forum')) {
        // Make sure it's a valid ip address; otherwise, don't bother...
        if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
            $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
        } else {
            $context['member']['hostname'] = '';
        }
        $context['can_see_ip'] = true;
    } else {
        $context['can_see_ip'] = false;
    }
    if (!empty($modSettings['who_enabled'])) {
        include_once $sourcedir . '/Who.php';
        $action = determineActions($user_profile[$memID]['url']);
        if ($action !== false) {
            $context['member']['action'] = $action;
        }
    }
    // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
    if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) {
        $context['activate_type'] = $context['member']['is_activated'];
        // What should the link text be?
        $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
        // Should we show a custom message?
        $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
    }
    // Is the signature even enabled on this forum?
    $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
    // How about, are they banned?
    $context['member']['bans'] = array();
    if (allowedTo('moderate_forum')) {
        // Can they edit the ban?
        $context['can_edit_ban'] = allowedTo('manage_bans');
        $ban_query = array();
        $ban_query_vars = array('time' => time());
        $ban_query[] = 'id_member = ' . $context['member']['id'];
        // Valid IP?
        if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $memberContext[$memID]['ip'], $ip_parts) == 1) {
            $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
						AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
						AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
						AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))';
            // Do we have a hostname already?
            if (!empty($context['member']['hostname'])) {
                $ban_query[] = '({string:hostname} LIKE hostname)';
                $ban_query_vars['hostname'] = $context['member']['hostname'];
            }
        } elseif ($memberContext[$memID]['ip'] == 'unknown') {
            $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255
						AND bi.ip_low2 = 255 AND bi.ip_high2 = 255
						AND bi.ip_low3 = 255 AND bi.ip_high3 = 255
						AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)';
        }
        // Check their email as well...
        if (strlen($context['member']['email']) != 0) {
            $ban_query[] = '({string:email} LIKE bi.email_address)';
            $ban_query_vars['email'] = $context['member']['email'];
        }
        // So... are they banned?  Dying to know!
        $request = $smcFunc['db_query']('', '
			SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
				bg.cannot_login, bg.reason
			FROM {db_prefix}ban_items AS bi
				INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
			WHERE (' . implode(' OR ', $ban_query) . ')', $ban_query_vars);
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // Work out what restrictions we actually have.
            $ban_restrictions = array();
            foreach (array('access', 'register', 'login', 'post') as $type) {
                if ($row['cannot_' . $type]) {
                    $ban_restrictions[] = $txt['ban_type_' . $type];
                }
            }
            // No actual ban in place?
            if (empty($ban_restrictions)) {
                continue;
            }
            // Prepare the link for context.
            $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
            $context['member']['bans'][$row['id_ban_group']] = array('reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'], 'cannot' => array('access' => !empty($row['cannot_access']), 'register' => !empty($row['cannot_register']), 'post' => !empty($row['cannot_post']), 'login' => !empty($row['cannot_login'])), 'explanation' => $ban_explanation);
        }
        $smcFunc['db_free_result']($request);
    }
    loadCustomFields($memID);
}
示例#3
0
function BanEdit()
{
    global $txt, $modSettings, $context, $ban_request, $scripturl, $smcFunc;
    $_REQUEST['bg'] = empty($_REQUEST['bg']) ? 0 : (int) $_REQUEST['bg'];
    // Adding or editing a ban trigger?
    if (!empty($_POST['add_new_trigger']) || !empty($_POST['edit_trigger'])) {
        checkSession();
        $newBan = !empty($_POST['add_new_trigger']);
        $values = array('id_ban_group' => $_REQUEST['bg'], 'hostname' => '', 'email_address' => '', 'id_member' => 0, 'ip_low1' => 0, 'ip_high1' => 0, 'ip_low2' => 0, 'ip_high2' => 0, 'ip_low3' => 0, 'ip_high3' => 0, 'ip_low4' => 0, 'ip_high4' => 0);
        // Preset all values that are required.
        if ($newBan) {
            $insertKeys = array('id_ban_group' => 'int', 'hostname' => 'string', 'email_address' => 'string', 'id_member' => 'int', 'ip_low1' => 'int', 'ip_high1' => 'int', 'ip_low2' => 'int', 'ip_high2' => 'int', 'ip_low3' => 'int', 'ip_high3' => 'int', 'ip_low4' => 'int', 'ip_high4' => 'int');
        } else {
            $updateString = '
				hostname = {string:hostname}, email_address = {string:email_address}, id_member = {int:id_member},
				ip_low1 = {int:ip_low1}, ip_high1 = {int:ip_high1},
				ip_low2 = {int:ip_low2}, ip_high2 = {int:ip_high2},
				ip_low3 = {int:ip_low3}, ip_high3 = {int:ip_high3},
				ip_low4 = {int:ip_low4}, ip_high4 = {int:ip_high4}';
        }
        if ($_POST['bantype'] == 'ip_ban') {
            $ip = trim($_POST['ip']);
            $ip_parts = ip2range($ip);
            $ip_check = checkExistingTriggerIP($ip_parts, $ip);
            if (!$ip_check) {
                fatal_lang_error('invalid_ip', false);
            }
            $values = array_merge($values, $ip_check);
            $modlogInfo['ip_range'] = $_POST['ip'];
        } elseif ($_POST['bantype'] == 'hostname_ban') {
            if (preg_match('/[^\\w.\\-*]/', $_POST['hostname']) == 1) {
                fatal_lang_error('invalid_hostname', false);
            }
            // Replace the * wildcard by a MySQL compatible wildcard %.
            $_POST['hostname'] = str_replace('*', '%', $_POST['hostname']);
            $values['hostname'] = $_POST['hostname'];
            $modlogInfo['hostname'] = $_POST['hostname'];
        } elseif ($_POST['bantype'] == 'email_ban') {
            if (preg_match('/[^\\w.\\-\\+*@]/', $_POST['email']) == 1) {
                fatal_lang_error('invalid_email', false);
            }
            $_POST['email'] = strtolower(str_replace('*', '%', $_POST['email']));
            // Check the user is not banning an admin.
            $request = $smcFunc['db_query']('', '
				SELECT id_member
				FROM {db_prefix}members
				WHERE (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0)
					AND email_address LIKE {string:email}
				LIMIT 1', array('admin_group' => 1, 'email' => $_POST['email']));
            if ($smcFunc['db_num_rows']($request) != 0) {
                fatal_lang_error('no_ban_admin', 'critical');
            }
            $smcFunc['db_free_result']($request);
            $values['email_address'] = $_POST['email'];
            $modlogInfo['email'] = $_POST['email'];
        } elseif ($_POST['bantype'] == 'user_ban') {
            $_POST['user'] = preg_replace('~&amp;#(\\d{4,5}|[2-9]\\d{2,4}|1[2-9]\\d);~', '&#$1;', $smcFunc['htmlspecialchars']($_POST['user'], ENT_QUOTES));
            $request = $smcFunc['db_query']('', '
				SELECT id_member, (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0) AS isAdmin
				FROM {db_prefix}members
				WHERE member_name = {string:user_name} OR real_name = {string:user_name}
				LIMIT 1', array('admin_group' => 1, 'user_name' => $_POST['user']));
            if ($smcFunc['db_num_rows']($request) == 0) {
                fatal_lang_error('invalid_username', false);
            }
            list($memberid, $isAdmin) = $smcFunc['db_fetch_row']($request);
            $smcFunc['db_free_result']($request);
            if ($isAdmin && $isAdmin != 'f') {
                fatal_lang_error('no_ban_admin', 'critical');
            }
            $values['id_member'] = $memberid;
            $modlogInfo['member'] = $memberid;
        } else {
            fatal_lang_error('no_bantype_selected', false);
        }
        if ($newBan) {
            $smcFunc['db_insert']('', '{db_prefix}ban_items', $insertKeys, $values, array('id_ban'));
        } else {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}ban_items
				SET ' . $updateString . '
				WHERE id_ban = {int:ban_item}
					AND id_ban_group = {int:id_ban_group}', array_merge($values, array('ban_item' => (int) $_REQUEST['bi'])));
        }
        // Log the addion of the ban entry into the moderation log.
        logAction('ban', $modlogInfo + array('new' => $newBan, 'type' => $_POST['bantype']));
        // Register the last modified date.
        updateSettings(array('banLastUpdated' => time()));
        // Update the member table to represent the new ban situation.
        updateBanMembers();
    } elseif (!empty($_POST['remove_selection']) && !empty($_POST['ban_items']) && is_array($_POST['ban_items'])) {
        checkSession();
        // Making sure every deleted ban item is an integer.
        foreach ($_POST['ban_items'] as $key => $value) {
            $_POST['ban_items'][$key] = (int) $value;
        }
        $smcFunc['db_query']('', '
			DELETE FROM {db_prefix}ban_items
			WHERE id_ban IN ({array_int:ban_list})
				AND id_ban_group = {int:ban_group}', array('ban_list' => $_POST['ban_items'], 'ban_group' => $_REQUEST['bg']));
        // It changed, let the settings and the member table know.
        updateSettings(array('banLastUpdated' => time()));
        updateBanMembers();
    } elseif (!empty($_POST['modify_ban']) || !empty($_POST['add_ban'])) {
        checkSession();
        $addBan = !empty($_POST['add_ban']);
        if (empty($_POST['ban_name'])) {
            fatal_lang_error('ban_name_empty', false);
        }
        // Let's not allow HTML in ban names, it's more evil than beneficial.
        $_POST['ban_name'] = $smcFunc['htmlspecialchars']($_POST['ban_name'], ENT_QUOTES);
        // Check whether a ban with this name already exists.
        $request = $smcFunc['db_query']('', '
			SELECT id_ban_group
			FROM {db_prefix}ban_groups
			WHERE name = {string:new_ban_name}' . ($addBan ? '' : '
				AND id_ban_group != {int:ban_group}') . '
			LIMIT 1', array('ban_group' => $_REQUEST['bg'], 'new_ban_name' => $_POST['ban_name']));
        if ($smcFunc['db_num_rows']($request) == 1) {
            fatal_lang_error('ban_name_exists', false, array($_POST['ban_name']));
        }
        $smcFunc['db_free_result']($request);
        $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
        $_POST['notes'] = $smcFunc['htmlspecialchars']($_POST['notes'], ENT_QUOTES);
        $_POST['notes'] = str_replace(array("\r", "\n", '  '), array('', '<br />', '&nbsp; '), $_POST['notes']);
        $_POST['expiration'] = $_POST['expiration'] == 'never' ? 'NULL' : ($_POST['expiration'] == 'expired' ? '0' : ($_POST['expire_date'] != $_POST['old_expire'] ? time() + 24 * 60 * 60 * (int) $_POST['expire_date'] : 'expire_time'));
        $_POST['full_ban'] = empty($_POST['full_ban']) ? '0' : '1';
        $_POST['cannot_post'] = !empty($_POST['full_ban']) || empty($_POST['cannot_post']) ? '0' : '1';
        $_POST['cannot_register'] = !empty($_POST['full_ban']) || empty($_POST['cannot_register']) ? '0' : '1';
        $_POST['cannot_login'] = !empty($_POST['full_ban']) || empty($_POST['cannot_login']) ? '0' : '1';
        if ($addBan) {
            // Adding some ban triggers?
            if ($addBan && !empty($_POST['ban_suggestion']) && is_array($_POST['ban_suggestion'])) {
                $ban_triggers = array();
                $ban_logs = array();
                if (in_array('main_ip', $_POST['ban_suggestion']) && !empty($_POST['main_ip'])) {
                    $ip = trim($_POST['main_ip']);
                    $ip_parts = ip2range($ip);
                    if (!checkExistingTriggerIP($ip_parts, $ip)) {
                        fatal_lang_error('invalid_ip', false);
                    }
                    $ban_triggers[] = array($ip_parts[0]['low'], $ip_parts[0]['high'], $ip_parts[1]['low'], $ip_parts[1]['high'], $ip_parts[2]['low'], $ip_parts[2]['high'], $ip_parts[3]['low'], $ip_parts[3]['high'], '', '', 0);
                    $ban_logs[] = array('ip_range' => $_POST['main_ip']);
                }
                if (in_array('hostname', $_POST['ban_suggestion']) && !empty($_POST['hostname'])) {
                    if (preg_match('/[^\\w.\\-*]/', $_POST['hostname']) == 1) {
                        fatal_lang_error('invalid_hostname', false);
                    }
                    // Replace the * wildcard by a MySQL wildcard %.
                    $_POST['hostname'] = str_replace('*', '%', $_POST['hostname']);
                    $ban_triggers[] = array(0, 0, 0, 0, 0, 0, 0, 0, substr($_POST['hostname'], 0, 255), '', 0);
                    $ban_logs[] = array('hostname' => $_POST['hostname']);
                }
                if (in_array('email', $_POST['ban_suggestion']) && !empty($_POST['email'])) {
                    if (preg_match('/[^\\w.\\-\\+*@]/', $_POST['email']) == 1) {
                        fatal_lang_error('invalid_email', false);
                    }
                    $_POST['email'] = strtolower(str_replace('*', '%', $_POST['email']));
                    $ban_triggers[] = array(0, 0, 0, 0, 0, 0, 0, 0, '', substr($_POST['email'], 0, 255), 0);
                    $ban_logs[] = array('email' => $_POST['email']);
                }
                if (in_array('user', $_POST['ban_suggestion']) && (!empty($_POST['bannedUser']) || !empty($_POST['user']))) {
                    // We got a username, let's find its ID.
                    if (empty($_POST['bannedUser'])) {
                        $_POST['user'] = preg_replace('~&amp;#(\\d{4,5}|[2-9]\\d{2,4}|1[2-9]\\d);~', '&#$1;', $smcFunc['htmlspecialchars']($_POST['user'], ENT_QUOTES));
                        $request = $smcFunc['db_query']('', '
							SELECT id_member, (id_group = {int:admin_group} OR FIND_IN_SET({int:admin_group}, additional_groups) != 0) AS isAdmin
							FROM {db_prefix}members
							WHERE member_name = {string:username} OR real_name = {string:username}
							LIMIT 1', array('admin_group' => 1, 'username' => $_POST['user']));
                        if ($smcFunc['db_num_rows']($request) == 0) {
                            fatal_lang_error('invalid_username', false);
                        }
                        list($_POST['bannedUser'], $isAdmin) = $smcFunc['db_fetch_row']($request);
                        $smcFunc['db_free_result']($request);
                        if ($isAdmin && $isAdmin != 'f') {
                            fatal_lang_error('no_ban_admin', 'critical');
                        }
                    }
                    $ban_triggers[] = array(0, 0, 0, 0, 0, 0, 0, 0, '', '', (int) $_POST['bannedUser']);
                    $ban_logs[] = array('member' => $_POST['bannedUser']);
                }
                if (!empty($_POST['ban_suggestion']['ips']) && is_array($_POST['ban_suggestion']['ips'])) {
                    $_POST['ban_suggestion']['ips'] = array_unique($_POST['ban_suggestion']['ips']);
                    // Don't add the main IP again.
                    if (in_array('main_ip', $_POST['ban_suggestion'])) {
                        $_POST['ban_suggestion']['ips'] = array_diff($_POST['ban_suggestion']['ips'], array($_POST['main_ip']));
                    }
                    foreach ($_POST['ban_suggestion']['ips'] as $ip) {
                        $ip_parts = ip2range($ip);
                        // They should be alright, but just to be sure...
                        if (count($ip_parts) != 4) {
                            fatal_lang_error('invalid_ip', false);
                        }
                        $ban_triggers[] = array($ip_parts[0]['low'], $ip_parts[0]['high'], $ip_parts[1]['low'], $ip_parts[1]['high'], $ip_parts[2]['low'], $ip_parts[2]['high'], $ip_parts[3]['low'], $ip_parts[3]['high'], '', '', 0);
                        $ban_logs[] = array('ip_range' => $ip);
                    }
                }
            }
            // Yes yes, we're ready to add now.
            $smcFunc['db_insert']('', '{db_prefix}ban_groups', array('name' => 'string-20', 'ban_time' => 'int', 'expire_time' => 'raw', 'cannot_access' => 'int', 'cannot_register' => 'int', 'cannot_post' => 'int', 'cannot_login' => 'int', 'reason' => 'string-255', 'notes' => 'string-65534'), array($_POST['ban_name'], time(), $_POST['expiration'], $_POST['full_ban'], $_POST['cannot_register'], $_POST['cannot_post'], $_POST['cannot_login'], $_POST['reason'], $_POST['notes']), array('id_ban_group'));
            $_REQUEST['bg'] = $smcFunc['db_insert_id']('{db_prefix}ban_groups', 'id_ban_group');
            // Now that the ban group is added, add some triggers as well.
            if (!empty($ban_triggers) && !empty($_REQUEST['bg'])) {
                // Put in the ban group ID.
                foreach ($ban_triggers as $k => $trigger) {
                    array_unshift($ban_triggers[$k], $_REQUEST['bg']);
                }
                // Log what we are doing!
                foreach ($ban_logs as $log_details) {
                    logAction('ban', $log_details + array('new' => 1));
                }
                $smcFunc['db_insert']('', '{db_prefix}ban_items', array('id_ban_group' => 'int', 'ip_low1' => 'int', 'ip_high1' => 'int', 'ip_low2' => 'int', 'ip_high2' => 'int', 'ip_low3' => 'int', 'ip_high3' => 'int', 'ip_low4' => 'int', 'ip_high4' => 'int', 'hostname' => 'string-255', 'email_address' => 'string-255', 'id_member' => 'int'), $ban_triggers, array('id_ban'));
            }
        } else {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}ban_groups
				SET
					name = {string:ban_name},
					reason = {string:reason},
					notes = {string:notes},
					expire_time = {raw:expiration},
					cannot_access = {int:cannot_access},
					cannot_post = {int:cannot_post},
					cannot_register = {int:cannot_register},
					cannot_login = {int:cannot_login}
				WHERE id_ban_group = {int:id_ban_group}', array('expiration' => $_POST['expiration'], 'cannot_access' => $_POST['full_ban'], 'cannot_post' => $_POST['cannot_post'], 'cannot_register' => $_POST['cannot_register'], 'cannot_login' => $_POST['cannot_login'], 'id_ban_group' => $_REQUEST['bg'], 'ban_name' => $_POST['ban_name'], 'reason' => $_POST['reason'], 'notes' => $_POST['notes']));
        }
        // No more caching, we have something new here.
        updateSettings(array('banLastUpdated' => time()));
        updateBanMembers();
    }
    // If we're editing an existing ban, get it from the database.
    if (!empty($_REQUEST['bg'])) {
        $context['ban_items'] = array();
        $request = $smcFunc['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,
				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}', array('current_ban' => $_REQUEST['bg']));
        if ($smcFunc['db_num_rows']($request) == 0) {
            fatal_lang_error('ban_not_found', false);
        }
        while ($row = $smcFunc['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' : 'still_active_but_we_re_counting_the_days'), '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);
            }
            if (!empty($row['id_ban'])) {
                $context['ban_items'][$row['id_ban']] = array('id' => $row['id_ban'], 'hits' => $row['hits']);
                if (!empty($row['ip_high1'])) {
                    $context['ban_items'][$row['id_ban']]['type'] = 'ip';
                    $context['ban_items'][$row['id_ban']]['ip'] = 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 (!empty($row['hostname'])) {
                    $context['ban_items'][$row['id_ban']]['type'] = 'hostname';
                    $context['ban_items'][$row['id_ban']]['hostname'] = str_replace('%', '*', $row['hostname']);
                } elseif (!empty($row['email_address'])) {
                    $context['ban_items'][$row['id_ban']]['type'] = 'email';
                    $context['ban_items'][$row['id_ban']]['email'] = str_replace('%', '*', $row['email_address']);
                } elseif (!empty($row['id_member'])) {
                    $context['ban_items'][$row['id_ban']]['type'] = 'user';
                    $context['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($context['ban_items'][$row['id_ban']]);
                    $smcFunc['db_query']('', '
						DELETE FROM {db_prefix}ban_items
						WHERE id_ban = {int:current_ban}', array('current_ban' => $row['id_ban']));
                }
            }
        }
        $smcFunc['db_free_result']($request);
    } else {
        $context['ban'] = array('id' => 0, 'name' => '', 'expiration' => array('status' => 'never', 'days' => 0), 'reason' => '', 'notes' => '', 'ban_days' => 0, 'cannot' => array('access' => true, 'post' => false, 'register' => false, 'login' => false), 'is_new' => true);
        $context['ban_suggestions'] = array('main_ip' => '', 'hostname' => '', 'email' => '', 'member' => array('id' => 0));
        // Overwrite some of the default form values if a user ID was given.
        if (!empty($_REQUEST['u'])) {
            $request = $smcFunc['db_query']('', '
				SELECT id_member, real_name, member_ip, email_address
				FROM {db_prefix}members
				WHERE id_member = {int:current_user}
				LIMIT 1', array('current_user' => (int) $_REQUEST['u']));
            if ($smcFunc['db_num_rows']($request) > 0) {
                list($context['ban_suggestions']['member']['id'], $context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = $smcFunc['db_fetch_row']($request);
            }
            $smcFunc['db_free_result']($request);
            if (!empty($context['ban_suggestions']['member']['id'])) {
                $context['ban_suggestions']['href'] = $scripturl . '?action=profile;u=' . $context['ban_suggestions']['member']['id'];
                $context['ban_suggestions']['member']['link'] = '<a href="' . $context['ban_suggestions']['href'] . '">' . $context['ban_suggestions']['member']['name'] . '</a>';
                // Default the ban name to the name of the banned member.
                $context['ban']['name'] = $context['ban_suggestions']['member']['name'];
                // Would be nice if we could also ban the hostname.
                if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
                    $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
                }
                // Find some additional IP's used by this member.
                $context['ban_suggestions']['message_ips'] = array();
                $request = $smcFunc['db_query']('ban_suggest_message_ips', '
					SELECT DISTINCT poster_ip
					FROM {db_prefix}messages
					WHERE id_member = {int:current_user}
						AND poster_ip RLIKE {string:poster_ip_regex}
					ORDER BY poster_ip', array('current_user' => (int) $_REQUEST['u'], 'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'));
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $context['ban_suggestions']['message_ips'][] = $row['poster_ip'];
                }
                $smcFunc['db_free_result']($request);
                $context['ban_suggestions']['error_ips'] = array();
                $request = $smcFunc['db_query']('ban_suggest_error_ips', '
					SELECT DISTINCT ip
					FROM {db_prefix}log_errors
					WHERE id_member = {int:current_user}
						AND ip RLIKE {string:poster_ip_regex}
					ORDER BY ip', array('current_user' => (int) $_REQUEST['u'], 'poster_ip_regex' => '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'));
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    $context['ban_suggestions']['error_ips'][] = $row['ip'];
                }
                $smcFunc['db_free_result']($request);
                // Borrowing a few language strings from profile.
                loadLanguage('Profile');
            }
        }
    }
    // Template needs this to show errors using javascript
    loadLanguage('Errors');
    // If we're in wireless mode remove the admin template layer and use a special template.
    if (WIRELESS && WIRELESS_PROTOCOL != 'wap') {
        $context['sub_template'] = WIRELESS_PROTOCOL . '_ban_edit';
        foreach ($context['template_layers'] as $k => $v) {
            if (strpos($v, 'generic_menu') === 0) {
                unset($context['template_layers'][$k]);
            }
        }
    } else {
        $context['sub_template'] = 'ban_edit';
    }
}
示例#4
0
function BanEdit()
{
    global $txt, $db_prefix, $modSettings, $context, $ban_request, $scripturl;
    global $func;
    $_REQUEST['bg'] = empty($_REQUEST['bg']) ? 0 : (int) $_REQUEST['bg'];
    // Adding or editing a ban trigger?
    if (!empty($_POST['add_new_trigger']) || !empty($_POST['edit_trigger'])) {
        checkSession();
        $newBan = !empty($_POST['add_new_trigger']);
        // Preset all values that are required.
        if ($newBan) {
            $inserts = array('ID_BAN_GROUP' => $_REQUEST['bg'], 'hostname' => "''", 'email_address' => "''");
        }
        if ($_POST['bantype'] == 'ip_ban') {
            $ip_parts = ip2range($_POST['ip']);
            if (count($ip_parts) != 4) {
                fatal_lang_error('invalid_ip', false);
            }
            if ($newBan) {
                $inserts += array('ip_low1' => $ip_parts[0]['low'], 'ip_high1' => $ip_parts[0]['high'], 'ip_low2' => $ip_parts[1]['low'], 'ip_high2' => $ip_parts[1]['high'], 'ip_low3' => $ip_parts[2]['low'], 'ip_high3' => $ip_parts[2]['high'], 'ip_low4' => $ip_parts[3]['low'], 'ip_high4' => $ip_parts[3]['high']);
            } else {
                $update = '
					ip_low1 = ' . $ip_parts[0]['low'] . ', ip_high1 = ' . $ip_parts[0]['high'] . ',
					ip_low2 = ' . $ip_parts[1]['low'] . ', ip_high2 = ' . $ip_parts[1]['high'] . ',
					ip_low3 = ' . $ip_parts[2]['low'] . ', ip_high3 = ' . $ip_parts[2]['high'] . ',
					ip_low4 = ' . $ip_parts[3]['low'] . ', ip_high4 = ' . $ip_parts[3]['high'] . ',
					hostname = \'\', email_address = \'\', ID_MEMBER = 0';
            }
            $modlogInfo['ip_range'] = $_POST['ip'];
        } elseif ($_POST['bantype'] == 'hostname_ban') {
            if (preg_match("/[^\\w.\\-*]/", $_POST['hostname']) == 1) {
                fatal_lang_error('invalid_hostname', false);
            }
            // Replace the * wildcard by a MySQL compatible wildcard %.
            $_POST['hostname'] = str_replace('*', '%', $_POST['hostname']);
            if ($newBan) {
                $inserts['hostname'] = "'{$_POST['hostname']}'";
            } else {
                $update = "\n\t\t\t\t\tip_low1 = 0, ip_high1 = 0,\n\t\t\t\t\tip_low2 = 0, ip_high2 = 0,\n\t\t\t\t\tip_low3 = 0, ip_high3 = 0,\n\t\t\t\t\tip_low4 = 0, ip_high4 = 0,\n\t\t\t\t\thostname = '{$_POST['hostname']}', email_address = '', ID_MEMBER = 0";
            }
            $modlogInfo['hostname'] = stripslashes($_POST['hostname']);
        } elseif ($_POST['bantype'] == 'email_ban') {
            if (preg_match("/[^\\w.\\-*@]/", $_POST['email']) == 1) {
                fatal_lang_error('invalid_email', false);
            }
            $_POST['email'] = strtolower(str_replace('*', '%', $_POST['email']));
            // Check the user is not banning an admin.
            $request = db_query("\n\t\t\t\tSELECT ID_MEMBER\n\t\t\t\tFROM {$db_prefix}members\n\t\t\t\tWHERE (ID_GROUP = 1 OR FIND_IN_SET(1, additionalGroups))\n\t\t\t\t\tAND emailAddress LIKE '{$_POST['email']}'\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            if (mysql_num_rows($request) != 0) {
                fatal_lang_error('no_ban_admin');
            }
            mysql_free_result($request);
            if ($newBan) {
                $inserts['email_address'] = "'{$_POST['email']}'";
            } else {
                $update = "\n\t\t\t\t\tip_low1 = 0, ip_high1 = 0,\n\t\t\t\t\tip_low2 = 0, ip_high2 = 0,\n\t\t\t\t\tip_low3 = 0, ip_high3 = 0,\n\t\t\t\t\tip_low4 = 0, ip_high4 = 0,\n\t\t\t\t\thostname = '', email_address = '{$_POST['email']}', ID_MEMBER = 0";
            }
            $modlogInfo['email'] = stripslashes($_POST['email']);
        } elseif ($_POST['bantype'] == 'user_ban') {
            $_POST['user'] = $func['htmlspecialchars']($_POST['user'], ENT_QUOTES);
            $request = db_query("\n\t\t\t\tSELECT ID_MEMBER, (ID_GROUP = 1 OR FIND_IN_SET(1, additionalGroups)) AS isAdmin\n\t\t\t\tFROM {$db_prefix}members\n\t\t\t\tWHERE memberName = '{$_POST['user']}' OR realName = '{$_POST['user']}'\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            if (mysql_num_rows($request) == 0) {
                fatal_lang_error('invalid_username', false);
            }
            list($memberid, $isAdmin) = mysql_fetch_row($request);
            mysql_free_result($request);
            if ($isAdmin) {
                fatal_lang_error('no_ban_admin');
            }
            if ($newBan) {
                $inserts['ID_MEMBER'] = $memberid;
            } else {
                $update = "\n\t\t\t\t\tip_low1 = 0, ip_high1 = 0,\n\t\t\t\t\tip_low2 = 0, ip_high2 = 0,\n\t\t\t\t\tip_low3 = 0, ip_high3 = 0,\n\t\t\t\t\tip_low4 = 0, ip_high4 = 0,\n\t\t\t\t\thostname = '', email_address = '', ID_MEMBER = {$memberid}";
            }
            $modlogInfo['member'] = $memberid;
        } else {
            fatal_lang_error('no_bantype_selected', false);
        }
        if ($newBan) {
            db_query("\n\t\t\t\tINSERT INTO {$db_prefix}ban_items\n\t\t\t\t\t(" . implode(', ', array_keys($inserts)) . ")\n\t\t\t\tVALUES (" . implode(', ', $inserts) . ")", __FILE__, __LINE__);
        } else {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}ban_items\n\t\t\t\tSET {$update}\n\t\t\t\tWHERE ID_BAN = " . (int) $_REQUEST['bi'] . "\n\t\t\t\t\tAND ID_BAN_GROUP = {$_REQUEST['bg']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
        // Log the addion of the ban entry into the moderation log.
        logAction('ban', $modlogInfo + array('new' => $newBan, 'type' => $_POST['bantype']));
        // Register the last modified date.
        updateSettings(array('banLastUpdated' => time()));
        // Update the member table to represent the new ban situation.
        updateBanMembers();
    } elseif (!empty($_POST['remove_selection']) && !empty($_POST['ban_items']) && is_array($_POST['ban_items'])) {
        checkSession();
        // Making sure every deleted ban item is an integer.
        foreach ($_POST['ban_items'] as $key => $value) {
            $_POST['ban_items'][$key] = (int) $value;
        }
        db_query("\n\t\t\tDELETE FROM {$db_prefix}ban_items\n\t\t\tWHERE ID_BAN IN (" . implode(', ', $_POST['ban_items']) . ")\n\t\t\t\tAND ID_BAN_GROUP = {$_REQUEST['bg']}\n\t\t\tLIMIT " . count($_POST['ban_items']), __FILE__, __LINE__);
        // It changed, let the settings and the member table know.
        updateSettings(array('banLastUpdated' => time()));
        updateBanMembers();
    } elseif (!empty($_POST['modify_ban']) || !empty($_POST['add_ban'])) {
        checkSession();
        $addBan = !empty($_POST['add_ban']);
        if (empty($_POST['ban_name'])) {
            fatal_error($txt['ban_name_empty'], false);
        }
        // Check whether a ban with this name already exists.
        $request = db_query("\n\t\t\tSELECT ID_BAN_GROUP\n\t\t\tFROM {$db_prefix}ban_groups\n\t\t\tWHERE name = '{$_POST['ban_name']}'" . ($addBan ? '' : "\n\t\t\t\tAND ID_BAN_GROUP != {$_REQUEST['bg']}") . "\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        // !!! Separate the sprintf?
        if (mysql_num_rows($request) == 1) {
            fatal_error(sprintf($txt['ban_name_exists'], $_POST['ban_name']), false);
        }
        mysql_free_result($request);
        $_POST['reason'] = htmlspecialchars($_POST['reason'], ENT_QUOTES);
        $_POST['notes'] = htmlspecialchars($_POST['notes'], ENT_QUOTES);
        $_POST['notes'] = str_replace(array("\r", "\n", '  '), array('', '<br />', '&nbsp; '), $_POST['notes']);
        $_POST['expiration'] = $_POST['expiration'] == 'never' ? 'NULL' : ($_POST['expiration'] == 'expired' ? '0' : ($_POST['expire_date'] != $_POST['old_expire'] ? time() + 24 * 60 * 60 * (int) $_POST['expire_date'] : 'expire_time'));
        $_POST['full_ban'] = empty($_POST['full_ban']) ? '0' : '1';
        $_POST['cannot_post'] = !empty($_POST['full_ban']) || empty($_POST['cannot_post']) ? '0' : '1';
        $_POST['cannot_register'] = !empty($_POST['full_ban']) || empty($_POST['cannot_register']) ? '0' : '1';
        $_POST['cannot_login'] = !empty($_POST['full_ban']) || empty($_POST['cannot_login']) ? '0' : '1';
        if ($addBan) {
            // Adding some ban triggers?
            if ($addBan && !empty($_POST['ban_suggestion']) && is_array($_POST['ban_suggestion'])) {
                $ban_triggers = array();
                if (in_array('main_ip', $_POST['ban_suggestion']) && !empty($_POST['main_ip'])) {
                    $ip_parts = ip2range($_POST['main_ip']);
                    if (count($ip_parts) != 4) {
                        fatal_lang_error('invalid_ip', false);
                    }
                    $ban_triggers[] = $ip_parts[0]['low'] . ', ' . $ip_parts[0]['high'] . ', ' . $ip_parts[1]['low'] . ', ' . $ip_parts[1]['high'] . ', ' . $ip_parts[2]['low'] . ', ' . $ip_parts[2]['high'] . ', ' . $ip_parts[3]['low'] . ', ' . $ip_parts[3]['high'] . ", '', '', 0";
                }
                if (in_array('hostname', $_POST['ban_suggestion']) && !empty($_POST['hostname'])) {
                    if (preg_match("/[^\\w.\\-*]/", $_POST['hostname']) == 1) {
                        fatal_lang_error('invalid_hostname', false);
                    }
                    // Replace the * wildcard by a MySQL wildcard %.
                    $_POST['hostname'] = str_replace('*', '%', $_POST['hostname']);
                    $ban_triggers[] = "0, 0, 0, 0, 0, 0, 0, 0, '" . substr($_POST['hostname'], 0, 255) . "', '', 0";
                }
                if (in_array('email', $_POST['ban_suggestion']) && !empty($_POST['email'])) {
                    if (preg_match("/[^\\w.\\-*@]/", $_POST['email']) == 1) {
                        fatal_lang_error('invalid_email', false);
                    }
                    $_POST['email'] = strtolower(str_replace('*', '%', $_POST['email']));
                    $ban_triggers[] = "0, 0, 0, 0, 0, 0, 0, 0, '', '" . substr($_POST['email'], 0, 255) . "', 0";
                }
                if (in_array('user', $_POST['ban_suggestion']) && (!empty($_POST['bannedUser']) || !empty($_POST['user']))) {
                    // We got a username, let's find its ID.
                    if (empty($_POST['bannedUser'])) {
                        $_POST['user'] = $func['htmlspecialchars']($_POST['user'], ENT_QUOTES);
                        $request = db_query("\n\t\t\t\t\t\t\tSELECT ID_MEMBER, (ID_GROUP = 1 OR FIND_IN_SET(1, additionalGroups)) AS isAdmin\n\t\t\t\t\t\t\tFROM {$db_prefix}members\n\t\t\t\t\t\t\tWHERE memberName = '{$_POST['user']}' OR realName = '{$_POST['user']}'\n\t\t\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
                        if (mysql_num_rows($request) == 0) {
                            fatal_lang_error('invalid_username', false);
                        }
                        list($_POST['bannedUser'], $isAdmin) = mysql_fetch_row($request);
                        mysql_free_result($request);
                        if ($isAdmin) {
                            fatal_lang_error('no_ban_admin');
                        }
                    }
                    $ban_triggers[] = "0, 0, 0, 0, 0, 0, 0, 0, '', '', " . (int) $_POST['bannedUser'];
                }
                if (!empty($_POST['ban_suggestion']['ips']) && is_array($_POST['ban_suggestion']['ips'])) {
                    $_POST['ban_suggestion']['ips'] = array_unique($_POST['ban_suggestion']['ips']);
                    // Don't add the main IP again.
                    if (in_array('main_ip', $_POST['ban_suggestion'])) {
                        $_POST['ban_suggestion']['ips'] = array_diff($_POST['ban_suggestion']['ips'], array($_POST['main_ip']));
                    }
                    foreach ($_POST['ban_suggestion']['ips'] as $ip) {
                        $ip_parts = ip2range($ip);
                        // They should be alright, but just to be sure...
                        if (count($ip_parts) != 4) {
                            fatal_lang_error('invalid_ip', false);
                        }
                        $ban_triggers[] = $ip_parts[0]['low'] . ', ' . $ip_parts[0]['high'] . ', ' . $ip_parts[1]['low'] . ', ' . $ip_parts[1]['high'] . ', ' . $ip_parts[2]['low'] . ', ' . $ip_parts[2]['high'] . ', ' . $ip_parts[3]['low'] . ', ' . $ip_parts[3]['high'] . ", '', '', 0";
                    }
                }
            }
            // Yes yes, we're ready to add now.
            db_query("\n\t\t\t\tINSERT INTO {$db_prefix}ban_groups\n\t\t\t\t\t(name, ban_time, expire_time, cannot_access, cannot_register, cannot_post, cannot_login, reason, notes)\n\t\t\t\tVALUES\n\t\t\t\t\t(SUBSTRING('{$_POST['ban_name']}', 1, 20), " . time() . ", {$_POST['expiration']}, {$_POST['full_ban']}, {$_POST['cannot_register']}, {$_POST['cannot_post']}, {$_POST['cannot_login']}, SUBSTRING('{$_POST['reason']}', 1, 255), SUBSTRING('{$_POST['notes']}', 1, 65534))", __FILE__, __LINE__);
            $_REQUEST['bg'] = db_insert_id();
            // Now that the ban group is added, add some triggers as well.
            if (!empty($ban_triggers) && !empty($_REQUEST['bg'])) {
                db_query("\n\t\t\t\t\tINSERT INTO {$db_prefix}ban_items\n\t\t\t\t\t\t(ID_BAN_GROUP, ip_low1, ip_high1, ip_low2, ip_high2, ip_low3, ip_high3, ip_low4, ip_high4, hostname, email_address, ID_MEMBER)\n\t\t\t\t\tVALUES ({$_REQUEST['bg']}, " . implode("), ({$_REQUEST['bg']}, ", $ban_triggers) . ')', __FILE__, __LINE__);
            }
        } else {
            db_query("\n\t\t\t\tUPDATE {$db_prefix}ban_groups\n\t\t\t\tSET\n\t\t\t\t\tname = '{$_POST['ban_name']}',\n\t\t\t\t\treason = '{$_POST['reason']}',\n\t\t\t\t\tnotes = '{$_POST['notes']}',\n\t\t\t\t\texpire_time = {$_POST['expiration']},\n\t\t\t\t\tcannot_access = {$_POST['full_ban']},\n\t\t\t\t\tcannot_post = {$_POST['cannot_post']},\n\t\t\t\t\tcannot_register = {$_POST['cannot_register']},\n\t\t\t\t\tcannot_login = {$_POST['cannot_login']}\n\t\t\t\tWHERE ID_BAN_GROUP = {$_REQUEST['bg']}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
        // No more caching, we have something new here.
        updateSettings(array('banLastUpdated' => time()));
        updateBanMembers();
    }
    // If we're editing an existing ban, get it from the database.
    if (!empty($_REQUEST['bg'])) {
        $context['ban_items'] = array();
        $request = db_query("\n\t\t\tSELECT\n\t\t\t\tbi.ID_BAN, bi.hostname, bi.email_address, bi.ID_MEMBER, bi.hits,\n\t\t\t\tbi.ip_low1, bi.ip_high1, bi.ip_low2, bi.ip_high2, bi.ip_low3, bi.ip_high3, bi.ip_low4, bi.ip_high4,\n\t\t\t\tbg.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,\n\t\t\t\tIFNULL(mem.ID_MEMBER, 0) AS ID_MEMBER, mem.memberName, mem.realName\n\t\t\tFROM {$db_prefix}ban_groups AS bg\n\t\t\t\tLEFT JOIN {$db_prefix}ban_items AS bi ON (bi.ID_BAN_GROUP = bg.ID_BAN_GROUP)\n\t\t\t\tLEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = bi.ID_MEMBER)\n\t\t\tWHERE bg.ID_BAN_GROUP = {$_REQUEST['bg']}", __FILE__, __LINE__);
        if (mysql_num_rows($request) == 0) {
            fatal_lang_error('ban_not_found', false);
        }
        while ($row = mysql_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' : 'still_active_but_we_re_counting_the_days'), '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);
            }
            if (!empty($row['ID_BAN'])) {
                $context['ban_items'][$row['ID_BAN']] = array('id' => $row['ID_BAN'], 'hits' => $row['hits']);
                if (!empty($row['ip_high1'])) {
                    $context['ban_items'][$row['ID_BAN']]['type'] = 'ip';
                    $context['ban_items'][$row['ID_BAN']]['ip'] = 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 (!empty($row['hostname'])) {
                    $context['ban_items'][$row['ID_BAN']]['type'] = 'hostname';
                    $context['ban_items'][$row['ID_BAN']]['hostname'] = str_replace('%', '*', $row['hostname']);
                } elseif (!empty($row['email_address'])) {
                    $context['ban_items'][$row['ID_BAN']]['type'] = 'email';
                    $context['ban_items'][$row['ID_BAN']]['email'] = str_replace('%', '*', $row['email_address']);
                } elseif (!empty($row['ID_MEMBER'])) {
                    $context['ban_items'][$row['ID_BAN']]['type'] = 'user';
                    $context['ban_items'][$row['ID_BAN']]['user'] = 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>');
                } else {
                    unset($context['ban_items'][$row['ID_BAN']]);
                    db_query("\n\t\t\t\t\t\tDELETE FROM {$db_prefix}ban_items\n\t\t\t\t\t\tWHERE ID_BAN = {$row['ID_BAN']}\n\t\t\t\t\t\tLIMIT 1", __FILE__, __LINE__);
                }
            }
        }
        mysql_free_result($request);
    } else {
        $context['ban'] = array('id' => 0, 'name' => '', 'expiration' => array('status' => 'never', 'days' => 0), 'reason' => '', 'notes' => '', 'ban_days' => 0, 'cannot' => array('access' => true, 'post' => false, 'register' => false, 'login' => false), 'is_new' => true);
        $context['ban_suggestions'] = array('main_ip' => '', 'hostname' => '', 'email' => '', 'member' => array('id' => 0));
        // Overwrite some of the default form values if a user ID was given.
        if (!empty($_REQUEST['u'])) {
            $request = db_query("\n\t\t\t\tSELECT ID_MEMBER, realName, memberIP, emailAddress\n\t\t\t\tFROM {$db_prefix}members\n\t\t\t\tWHERE ID_MEMBER = " . (int) $_REQUEST['u'] . "\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
            if (mysql_num_rows($request) > 0) {
                list($context['ban_suggestions']['member']['id'], $context['ban_suggestions']['member']['name'], $context['ban_suggestions']['main_ip'], $context['ban_suggestions']['email']) = mysql_fetch_row($request);
            }
            mysql_free_result($request);
            if (!empty($context['ban_suggestions']['member']['id'])) {
                $context['ban_suggestions']['href'] = $scripturl . '?action=profile;u=' . $context['ban_suggestions']['member']['id'];
                $context['ban_suggestions']['member']['link'] = '<a href="' . $context['ban_suggestions']['href'] . '">' . $context['ban_suggestions']['member']['name'] . '</a>';
                // Default the ban name to the name of the banned member.
                $context['ban']['name'] = $context['ban_suggestions']['member']['name'];
                // Would be nice if we could also ban the hostname.
                if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
                    $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
                }
                // Find some additional IP's used by this member.
                $context['ban_suggestions']['message_ips'] = array();
                $request = db_query("\n\t\t\t\t\tSELECT DISTINCT posterIP\n\t\t\t\t\tFROM {$db_prefix}messages\n\t\t\t\t\tWHERE ID_MEMBER = " . (int) $_REQUEST['u'] . "\n\t\t\t\t\t\tAND posterIP RLIKE '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\$'\n\t\t\t\t\tORDER BY posterIP", __FILE__, __LINE__);
                while ($row = mysql_fetch_assoc($request)) {
                    $context['ban_suggestions']['message_ips'][] = $row['posterIP'];
                }
                mysql_free_result($request);
                $context['ban_suggestions']['error_ips'] = array();
                $request = db_query("\n\t\t\t\t\tSELECT DISTINCT ip\n\t\t\t\t\tFROM {$db_prefix}log_errors\n\t\t\t\t\tWHERE ID_MEMBER = " . (int) $_REQUEST['u'] . "\n\t\t\t\t\t\tAND ip RLIKE '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\$'\n\t\t\t\t\tORDER BY ip", __FILE__, __LINE__);
                while ($row = mysql_fetch_assoc($request)) {
                    $context['ban_suggestions']['error_ips'][] = $row['ip'];
                }
                mysql_free_result($request);
                // Borrowing a few language strings from profile.
                loadLanguage('Profile');
            }
        }
    }
    $context['sub_template'] = 'ban_edit';
}
function shd_profile_frontpage($memID)
{
    global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;
    // Attempt to load the member's profile data.
    if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
        fatal_lang_error('not_a_user', false);
    }
    $context['page_title'] = $txt['shd_profile_area'] . ' - ' . $txt['shd_profile_main'];
    $context['sub_template'] = 'shd_profile_main';
    $query = shd_db_query('', '
		SELECT COUNT(id_ticket) AS count, status
		FROM {db_prefix}helpdesk_tickets AS hdt
		WHERE id_member_started = {int:member}
		GROUP BY status', array('member' => $memID));
    $context['shd_numtickets'] = 0;
    $context['shd_numopentickets'] = 0;
    while ($row = $smcFunc['db_fetch_assoc']($query)) {
        $context['shd_numtickets'] += $row['count'];
        if ($row['status'] != TICKET_STATUS_CLOSED && $row['status'] != TICKET_STATUS_DELETED) {
            $context['shd_numopentickets'] += $row['count'];
        }
    }
    $context['shd_numtickets'] = comma_format($context['shd_numtickets']);
    $context['shd_numopentickets'] = comma_format($context['shd_numopentickets']);
    $smcFunc['db_free_result']($query);
    $query = shd_db_query('', '
		SELECT COUNT(id_ticket)
		FROM {db_prefix}helpdesk_tickets
		WHERE id_member_assigned = {int:member}', array('member' => $memID));
    list($context['shd_numassigned']) = $smcFunc['db_fetch_row']($query);
    $smcFunc['db_free_result']($query);
    $context['shd_numassigned'] = comma_format($context['shd_numassigned']);
    $context['can_post_ticket'] = shd_allowed_to('shd_new_ticket', 0) && $memID == $context['user']['id'];
    $context['can_post_proxy'] = shd_allowed_to('shd_new_ticket', 0) && shd_allowed_to('shd_post_proxy', 0) && $memID != $context['user']['id'];
    // since it's YOUR permissions, whether you can post on behalf of this user and this user isn't you!
    // Everything hereafter is HD only stuff.
    if (empty($modSettings['shd_helpdesk_only'])) {
        return;
    }
    $context['can_send_pm'] = allowedTo('pm_send') && (empty($modSettings['shd_helpdesk_only']) || empty($modSettings['shd_disable_pm']));
    $context['member'] =& $memberContext[$memID];
    if (allowedTo('moderate_forum')) {
        // Make sure it's a valid ip address; otherwise, don't bother...
        if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
            $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
        } else {
            $context['member']['hostname'] = '';
        }
        $context['can_see_ip'] = true;
    } else {
        $context['can_see_ip'] = false;
    }
    // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
    if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) {
        $context['activate_type'] = $context['member']['is_activated'];
        // What should the link text be?
        $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
        // Should we show a custom message?
        $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
    }
    // How about, are they banned?
    $context['member']['bans'] = array();
    if (allowedTo('moderate_forum')) {
        // Can they edit the ban?
        $context['can_edit_ban'] = allowedTo('manage_bans');
        $ban_query = array();
        $ban_query_vars = array('time' => time());
        $ban_query[] = 'id_member = ' . $context['member']['id'];
        // Valid IP?
        if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $memberContext[$memID]['ip'], $ip_parts) == 1) {
            $ban_query[] = '((' . $ip_parts[1] . ' BETWEEN bi.ip_low1 AND bi.ip_high1)
						AND (' . $ip_parts[2] . ' BETWEEN bi.ip_low2 AND bi.ip_high2)
						AND (' . $ip_parts[3] . ' BETWEEN bi.ip_low3 AND bi.ip_high3)
						AND (' . $ip_parts[4] . ' BETWEEN bi.ip_low4 AND bi.ip_high4))';
            // Do we have a hostname already?
            if (!empty($context['member']['hostname'])) {
                $ban_query[] = '({string:hostname} LIKE hostname)';
                $ban_query_vars['hostname'] = $context['member']['hostname'];
            }
        } elseif ($memberContext[$memID]['ip'] == 'unknown') {
            $ban_query[] = '(bi.ip_low1 = 255 AND bi.ip_high1 = 255
						AND bi.ip_low2 = 255 AND bi.ip_high2 = 255
						AND bi.ip_low3 = 255 AND bi.ip_high3 = 255
						AND bi.ip_low4 = 255 AND bi.ip_high4 = 255)';
        }
        // Check their email as well...
        if (strlen($context['member']['email']) != 0) {
            $ban_query[] = '({string:email} LIKE bi.email_address)';
            $ban_query_vars['email'] = $context['member']['email'];
        }
        // So... are they banned?  Dying to know!
        $request = $smcFunc['db_query']('', '
			SELECT bg.id_ban_group, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,
				bg.cannot_login, bg.reason
			FROM {db_prefix}ban_items AS bi
				INNER JOIN {db_prefix}ban_groups AS bg ON (bg.id_ban_group = bi.id_ban_group AND (bg.expire_time IS NULL OR bg.expire_time > {int:time}))
			WHERE (' . implode(' OR ', $ban_query) . ')', $ban_query_vars);
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // Work out what restrictions we actually have.
            $ban_restrictions = array();
            foreach (array('access', 'register', 'login', 'post') as $type) {
                if ($row['cannot_' . $type]) {
                    $ban_restrictions[] = $txt['ban_type_' . $type];
                }
            }
            // No actual ban in place?
            if (empty($ban_restrictions)) {
                continue;
            }
            // Prepare the link for context.
            $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $row['id_ban_group'] . '">' . $row['name'] . '</a>');
            $context['member']['bans'][$row['id_ban_group']] = array('reason' => empty($row['reason']) ? '' : '<br /><br /><strong>' . $txt['ban_reason'] . ':</strong> ' . $row['reason'], 'cannot' => array('access' => !empty($row['cannot_access']), 'register' => !empty($row['cannot_register']), 'post' => !empty($row['cannot_post']), 'login' => !empty($row['cannot_login'])), 'explanation' => $ban_explanation);
        }
        $smcFunc['db_free_result']($request);
    }
}
示例#6
0
文件: Profile.php 项目: alencarmo/OCF
function summary($memID)
{
    global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $db_prefix, $scripturl;
    // Attempt to load the member's profile data.
    if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
        fatal_error($txt[453] . ' - ' . $memID, false);
    }
    // Set up the stuff and load the user.
    $context += array('allow_hide_email' => !empty($modSettings['allow_hideEmail']), 'page_title' => $txt[92] . ' ' . $memberContext[$memID]['name'], 'can_send_pm' => allowedTo('pm_send'), 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']));
    $context['member'] =& $memberContext[$memID];
    // They haven't even been registered for a full day!?
    $days_registered = (int) ((time() - $user_profile[$memID]['dateRegistered']) / (3600 * 24));
    if (empty($user_profile[$memID]['dateRegistered']) || $days_registered < 1) {
        $context['member']['posts_per_day'] = $txt[470];
    } else {
        $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
    }
    // Set the age...
    if (empty($context['member']['birth_date'])) {
        $context['member'] += array('age' => &$txt[470], 'today_is_birthday' => false);
    } else {
        list($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
        $datearray = getdate(forum_time());
        $context['member'] += array('age' => $birth_year <= 4 ? $txt[470] : $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1), 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day);
    }
    if (allowedTo('moderate_forum')) {
        // Make sure it's a valid ip address; otherwise, don't bother...
        if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
            $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
        } else {
            $context['member']['hostname'] = '';
        }
        $context['can_see_ip'] = true;
    } else {
        $context['can_see_ip'] = false;
    }
    if (!empty($modSettings['who_enabled'])) {
        include_once $sourcedir . '/Who.php';
        $action = determineActions($user_profile[$memID]['url']);
        if ($action !== false) {
            $context['member']['action'] = $action;
        }
    }
    // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
    if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) {
        $context['activate_type'] = $context['member']['is_activated'];
        // What should the link text be?
        $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
        // Should we show a custom message?
        $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
    }
    // How about, are they banned?
    $context['member']['bans'] = array();
    if (allowedTo('moderate_forum')) {
        // Can they edit the ban?
        $context['can_edit_ban'] = allowedTo('manage_bans');
        $ban_query = array();
        $ban_query[] = "ID_MEMBER = " . $context['member']['id'];
        // Valid IP?
        if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $memberContext[$memID]['ip'], $ip_parts) == 1) {
            $ban_query[] = "(({$ip_parts['1']} BETWEEN bi.ip_low1 AND bi.ip_high1)\n\t\t\t\t\t\tAND ({$ip_parts['2']} BETWEEN bi.ip_low2 AND bi.ip_high2)\n\t\t\t\t\t\tAND ({$ip_parts['3']} BETWEEN bi.ip_low3 AND bi.ip_high3)\n\t\t\t\t\t\tAND ({$ip_parts['4']} BETWEEN bi.ip_low4 AND bi.ip_high4))";
            // Do we have a hostname already?
            if (!empty($context['member']['hostname'])) {
                $ban_query[] = "('" . addslashes($context['member']['hostname']) . "' LIKE hostname)";
            }
        } elseif ($memberContext[$memID]['ip'] == 'unknown') {
            $ban_query[] = "(bi.ip_low1 = 255 AND bi.ip_high1 = 255\n\t\t\t\t\t\tAND bi.ip_low2 = 255 AND bi.ip_high2 = 255\n\t\t\t\t\t\tAND bi.ip_low3 = 255 AND bi.ip_high3 = 255\n\t\t\t\t\t\tAND bi.ip_low4 = 255 AND bi.ip_high4 = 255)";
        }
        // Check their email as well...
        if (strlen($context['member']['email']) != 0) {
            $ban_query[] = "('" . addslashes($context['member']['email']) . "' LIKE bi.email_address)";
        }
        // So... are they banned?  Dying to know!
        $request = db_query("\n\t\t\tSELECT bg.ID_BAN_GROUP, bg.name, bg.cannot_access, bg.cannot_post, bg.cannot_register,\n\t\t\t\tbg.cannot_login, bg.reason\n\t\t\tFROM ({$db_prefix}ban_items AS bi, {$db_prefix}ban_groups AS bg)\n\t\t\tWHERE bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\t\tAND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")\n\t\t\t\tAND (" . implode(' OR ', $ban_query) . ')
			GROUP BY bg.ID_BAN_GROUP', __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            // Work out what restrictions we actually have.
            $ban_restrictions = array();
            foreach (array('access', 'register', 'login', 'post') as $type) {
                if ($row['cannot_' . $type]) {
                    $ban_restrictions[] = $txt['ban_type_' . $type];
                }
            }
            // No actual ban in place?
            if (empty($ban_restrictions)) {
                continue;
            }
            // Prepare the link for context.
            $ban_explanation = sprintf($txt['user_cannot_due_to'], implode(', ', $ban_restrictions), '<a href="' . $scripturl . '?action=ban;sa=edit;bg=' . $row['ID_BAN_GROUP'] . '">' . $row['name'] . '</a>');
            $context['member']['bans'][] = array('reason' => empty($row['reason']) ? '' : '<br /><br /><b>' . $txt['ban_reason'] . ':</b> ' . $row['reason'], 'cannot' => array('access' => !empty($row['cannot_access']), 'register' => !empty($row['cannot_register']), 'post' => !empty($row['cannot_post']), 'login' => !empty($row['cannot_login'])), 'explanation' => $ban_explanation);
        }
        mysql_free_result($request);
    }
}
示例#7
0
function is_not_banned($forceCheck = false)
{
    global $txt, $db_prefix, $ID_MEMBER, $modSettings, $context, $user_info;
    global $sourcedir, $cookiename, $user_settings;
    // You cannot be banned if you are an admin - doesn't help if you log out.
    if ($user_info['is_admin']) {
        return;
    }
    // Only check the ban every so often. (to reduce load.)
    if ($forceCheck || !isset($_SESSION['ban']) || empty($modSettings['banLastUpdated']) || $_SESSION['ban']['last_checked'] < $modSettings['banLastUpdated'] || $_SESSION['ban']['ID_MEMBER'] != $ID_MEMBER || $_SESSION['ban']['ip'] != $user_info['ip'] || $_SESSION['ban']['ip2'] != $user_info['ip2'] || isset($user_info['email'], $_SESSION['ban']['email']) && $_SESSION['ban']['email'] != $user_info['email']) {
        // Innocent until proven guilty.  (but we know you are! :P)
        $_SESSION['ban'] = array('last_checked' => time(), 'ID_MEMBER' => $ID_MEMBER, 'ip' => $user_info['ip'], 'ip2' => $user_info['ip2'], 'email' => $user_info['email']);
        $ban_query = array();
        $flag_is_activated = false;
        // Check both IP addresses.
        foreach (array('ip', 'ip2') as $ip_number) {
            // Check if we have a valid IP address.
            if (preg_match('/^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$/', $user_info[$ip_number], $ip_parts) == 1) {
                $ban_query[] = "(({$ip_parts['1']} BETWEEN bi.ip_low1 AND bi.ip_high1)\n\t\t\t\t\t\t\tAND ({$ip_parts['2']} BETWEEN bi.ip_low2 AND bi.ip_high2)\n\t\t\t\t\t\t\tAND ({$ip_parts['3']} BETWEEN bi.ip_low3 AND bi.ip_high3)\n\t\t\t\t\t\t\tAND ({$ip_parts['4']} BETWEEN bi.ip_low4 AND bi.ip_high4))";
                // IP was valid, maybe there's also a hostname...
                if (empty($modSettings['disableHostnameLookup'])) {
                    $hostname = host_from_ip($user_info[$ip_number]);
                    if (strlen($hostname) > 0) {
                        $ban_query[] = "('" . addslashes($hostname) . "' LIKE bi.hostname)";
                    }
                }
            } elseif ($user_info[$ip_number] == 'unknown') {
                $ban_query[] = "(bi.ip_low1 = 255 AND bi.ip_high1 = 255\n\t\t\t\t\t\t\tAND bi.ip_low2 = 255 AND bi.ip_high2 = 255\n\t\t\t\t\t\t\tAND bi.ip_low3 = 255 AND bi.ip_high3 = 255\n\t\t\t\t\t\t\tAND bi.ip_low4 = 255 AND bi.ip_high4 = 255)";
            }
        }
        // Is their email address banned?
        if (strlen($user_info['email']) != 0) {
            $ban_query[] = "('" . addslashes($user_info['email']) . "' LIKE bi.email_address)";
        }
        // How about this user?
        if (!$user_info['is_guest'] && !empty($ID_MEMBER)) {
            $ban_query[] = "bi.ID_MEMBER = {$ID_MEMBER}";
        }
        // Check the ban, if there's information.
        if (!empty($ban_query)) {
            $restrictions = array('cannot_access', 'cannot_login', 'cannot_post', 'cannot_register');
            $request = db_query("\n\t\t\t\tSELECT bi.ID_BAN, bi.email_address, bi.ID_MEMBER, bg.cannot_access, bg.cannot_register,\n\t\t\t\t\tbg.cannot_post, bg.cannot_login, bg.reason\n\t\t\t\tFROM ({$db_prefix}ban_groups AS bg, {$db_prefix}ban_items AS bi)\n\t\t\t\tWHERE bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\t\t\tAND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")\n\t\t\t\t\tAND (" . implode(' OR ', $ban_query) . ')', __FILE__, __LINE__);
            // Store every type of ban that applies to you in your session.
            while ($row = mysql_fetch_assoc($request)) {
                foreach ($restrictions as $restriction) {
                    if (!empty($row[$restriction])) {
                        $_SESSION['ban'][$restriction]['reason'] = $row['reason'];
                        $_SESSION['ban'][$restriction]['ids'][] = $row['ID_BAN'];
                        if (!$user_info['is_guest'] && $restriction == 'cannot_access' && ($row['ID_MEMBER'] == $ID_MEMBER || $row['email_address'] == $user_info['email'])) {
                            $flag_is_activated = true;
                        }
                    }
                }
            }
            mysql_free_result($request);
        }
        // Mark the cannot_access and cannot_post bans as being 'hit'.
        if (isset($_SESSION['ban']['cannot_access']) || isset($_SESSION['ban']['cannot_post'])) {
            log_ban(array_merge(isset($_SESSION['ban']['cannot_access']) ? $_SESSION['ban']['cannot_access']['ids'] : array(), isset($_SESSION['ban']['cannot_post']) ? $_SESSION['ban']['cannot_post']['ids'] : array()));
        }
        // If for whatever reason the is_activated flag seems wrong, do a little work to clear it up.
        if ($ID_MEMBER && ($user_settings['is_activated'] >= 10 && !$flag_is_activated || $user_settings['is_activated'] < 10 && $flag_is_activated)) {
            require_once $sourcedir . '/ManageBans.php';
            updateBanMembers();
        }
    }
    // Hey, I know you! You're ehm...
    if (!isset($_SESSION['ban']['cannot_access']) && !empty($_COOKIE[$cookiename . '_'])) {
        $bans = explode(',', $_COOKIE[$cookiename . '_']);
        foreach ($bans as $key => $value) {
            $bans[$key] = (int) $value;
        }
        $request = db_query("\n\t\t\tSELECT bi.ID_BAN, bg.reason\n\t\t\tFROM ({$db_prefix}ban_items AS bi, {$db_prefix}ban_groups AS bg)\n\t\t\tWHERE bg.ID_BAN_GROUP = bi.ID_BAN_GROUP\n\t\t\t\tAND (bg.expire_time IS NULL OR bg.expire_time > " . time() . ")\n\t\t\t\tAND bg.cannot_access = 1\n\t\t\t\tAND bi.ID_BAN IN (" . implode(', ', $bans) . ")\n\t\t\tLIMIT " . count($bans), __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            $_SESSION['ban']['cannot_access']['ids'][] = $row['ID_BAN'];
            $_SESSION['ban']['cannot_access']['reason'] = $row['reason'];
        }
        mysql_free_result($request);
        // My mistake. Next time better.
        if (!isset($_SESSION['ban']['cannot_access'])) {
            require_once $sourcedir . '/Subs-Auth.php';
            $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
            setcookie($cookiename . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], 0);
        }
    }
    // If you're fully banned, it's end of the story for you.
    if (isset($_SESSION['ban']['cannot_access'])) {
        // We don't wanna see you!
        if (!$user_info['is_guest']) {
            db_query("\n\t\t\t\tDELETE FROM {$db_prefix}log_online\n\t\t\t\tWHERE ID_MEMBER = {$ID_MEMBER}\n\t\t\t\tLIMIT 1", __FILE__, __LINE__);
        }
        // 'Log' the user out.  Can't have any funny business... (save the name!)
        $old_name = isset($user_info['name']) && $user_info['name'] != '' ? $user_info['name'] : $txt[28];
        $user_info['name'] = '';
        $user_info['username'] = '';
        $user_info['is_guest'] = true;
        $user_info['is_admin'] = false;
        $user_info['permissions'] = array();
        $ID_MEMBER = 0;
        $context['user'] = array('id' => 0, 'username' => '', 'name' => $txt[28], 'is_guest' => true, 'is_logged' => false, 'is_admin' => false, 'is_mod' => false, 'language' => $user_info['language']);
        // A goodbye present.
        require_once $sourcedir . '/Subs-Auth.php';
        $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies']));
        setcookie($cookiename . '_', implode(',', $_SESSION['ban']['cannot_access']['ids']), time() + 3153600, $cookie_url[1], $cookie_url[0], 0);
        // Don't scare anyone, now.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        // You banned, sucka!
        fatal_error(sprintf($txt[430], $old_name) . (empty($_SESSION['ban']['cannot_access']['reason']) ? '' : '<br />' . $_SESSION['ban']['cannot_access']['reason']));
        // If we get here, something's gone wrong.... but let's try anyway.
        trigger_error('Hacking attempt...', E_USER_ERROR);
    } elseif (isset($_SESSION['ban']['cannot_login']) && !$user_info['is_guest']) {
        // !!! Why doesn't this use the function made for logging bans?
        db_query("\n\t\t\tUPDATE {$db_prefix}ban_items\n\t\t\tSET hits = hits + 1\n\t\t\tWHERE ID_BAN IN (" . implode(', ', $_SESSION['ban']['cannot_login']['ids']) . ')', __FILE__, __LINE__);
        // Log this ban.
        db_query("\n\t\t\tINSERT INTO {$db_prefix}log_banned\n\t\t\t\t(ID_MEMBER, ip, email, logTime)\n\t\t\tVALUES ({$ID_MEMBER}, SUBSTRING('{$user_info['ip']}', 1, 16), SUBSTRING('{$user_info['email']}', 1, 255), " . time() . ')', __FILE__, __LINE__);
        // SMF's Wipe 'n Clean(r) erases all traces.
        $_GET['action'] = '';
        $_GET['board'] = '';
        $_GET['topic'] = '';
        writeLog(true);
        // Logged in, but not for long...
        require_once $sourcedir . '/LogInOut.php';
        Logout(true);
    }
    // Fix up the banning permissions.
    if (isset($user_info['permissions'])) {
        banPermissions();
    }
}
    /**
     * View the user profile summary.
     *
     * @uses ProfileInfo template
     */
    public function action_summary()
    {
        global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $scripturl, $settings;
        $memID = currentMemberID();
        // Attempt to load the member's profile data.
        if (!loadMemberContext($memID) || !isset($memberContext[$memID])) {
            fatal_lang_error('not_a_user', false);
        }
        loadTemplate('ProfileInfo');
        // Set up the stuff and load the user.
        $context += array('page_title' => sprintf($txt['profile_of_username'], $memberContext[$memID]['name']), 'can_send_pm' => allowedTo('pm_send'), 'can_send_email' => allowedTo('send_email_to_members'), 'can_have_buddy' => allowedTo('profile_identity_own') && !empty($modSettings['enable_buddylist']), 'can_issue_warning' => in_array('w', $context['admin_features']) && allowedTo('issue_warning') && !empty($modSettings['warning_enable']));
        $context['member'] =& $memberContext[$memID];
        $context['can_view_warning'] = in_array('w', $context['admin_features']) && (allowedTo('issue_warning') && !$context['user']['is_owner']) || !empty($modSettings['warning_show']) && ($modSettings['warning_show'] > 1 || $context['user']['is_owner']);
        // Set a canonical URL for this page.
        $context['canonical_url'] = $scripturl . '?action=profile;u=' . $memID;
        // Are there things we don't show?
        $context['disabled_fields'] = isset($modSettings['disabled_profile_fields']) ? array_flip(explode(',', $modSettings['disabled_profile_fields'])) : array();
        // Menu tab
        $context[$context['profile_menu_name']]['tab_data'] = array();
        // Tab information for use in the summary page
        // Each tab template defines a div, the value of which are the template(s) to load in that div
        // Templates are named template_profile_block_YOURNAME
        $context['summarytabs'] = array('summary' => array('name' => $txt['summary'], 'templates' => array(array('summary', 'user_info'), array('contact', 'other_info'), array('user_customprofileinfo', 'moderation')), 'active' => true), 'recent' => array('name' => $txt['profile_recent_activity'], 'templates' => array('posts', 'topics', 'attachments'), 'active' => true), 'buddies' => array('name' => $txt['buddies'], 'templates' => array('buddies'), 'active' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner']));
        // Let addons add or remove to the tabs array
        call_integration_hook('integrate_profile_summary', array($memID));
        // Go forward with whats left
        $summary_areas = '';
        foreach ($context['summarytabs'] as $id => $tab) {
            // If the tab is active we add it
            if ($tab['active'] !== true) {
                unset($context['summarytabs'][$id]);
            } else {
                // All the active templates, used to prevent processing data we don't need
                foreach ($tab['templates'] as $template) {
                    $summary_areas .= is_array($template) ? implode(',', $template) : ',' . $template;
                }
            }
        }
        $summary_areas = explode(',', $summary_areas);
        // See if they have broken any warning levels...
        if (!empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $context['member']['warning']) {
            $context['warning_status'] = $txt['profile_warning_is_muted'];
        } elseif (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $context['member']['warning']) {
            $context['warning_status'] = $txt['profile_warning_is_moderation'];
        } elseif (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $context['member']['warning']) {
            $context['warning_status'] = $txt['profile_warning_is_watch'];
        }
        // They haven't even been registered for a full day!?
        $days_registered = (int) ((time() - $user_profile[$memID]['date_registered']) / (3600 * 24));
        if (empty($user_profile[$memID]['date_registered']) || $days_registered < 1) {
            $context['member']['posts_per_day'] = $txt['not_applicable'];
        } else {
            $context['member']['posts_per_day'] = comma_format($context['member']['real_posts'] / $days_registered, 3);
        }
        // Set the age...
        if (empty($context['member']['birth_date'])) {
            $context['member'] += array('age' => $txt['not_applicable'], 'today_is_birthday' => false);
        } else {
            list($birth_year, $birth_month, $birth_day) = sscanf($context['member']['birth_date'], '%d-%d-%d');
            $datearray = getdate(forum_time());
            $context['member'] += array('age' => $birth_year <= 4 ? $txt['not_applicable'] : $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1), 'today_is_birthday' => $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day);
        }
        if (allowedTo('moderate_forum')) {
            // Make sure it's a valid ip address; otherwise, don't bother...
            if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $memberContext[$memID]['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
                $context['member']['hostname'] = host_from_ip($memberContext[$memID]['ip']);
            } else {
                $context['member']['hostname'] = '';
            }
            $context['can_see_ip'] = true;
        } else {
            $context['can_see_ip'] = false;
        }
        if (!empty($modSettings['who_enabled']) && $context['member']['online']['is_online']) {
            include_once SUBSDIR . '/Who.subs.php';
            $action = determineActions($user_profile[$memID]['url']);
            loadLanguage('index');
            if ($action !== false) {
                $context['member']['action'] = $action;
            }
        }
        // If the user is awaiting activation, and the viewer has permission - setup some activation context messages.
        if ($context['member']['is_activated'] % 10 != 1 && allowedTo('moderate_forum')) {
            $context['activate_type'] = $context['member']['is_activated'];
            // What should the link text be?
            $context['activate_link_text'] = in_array($context['member']['is_activated'], array(3, 4, 5, 13, 14, 15)) ? $txt['account_approve'] : $txt['account_activate'];
            // Should we show a custom message?
            $context['activate_message'] = isset($txt['account_activate_method_' . $context['member']['is_activated'] % 10]) ? $txt['account_activate_method_' . $context['member']['is_activated'] % 10] : $txt['account_not_activated'];
            $context['activate_url'] = $scripturl . '?action=profile;save;area=activateaccount;u=' . $memID . ';' . $context['session_var'] . '=' . $context['session_id'] . ';' . $context['profile-aa' . $memID . '_token_var'] . '=' . $context['profile-aa' . $memID . '_token'];
        }
        // Is the signature even enabled on this forum?
        $context['signature_enabled'] = substr($modSettings['signature_settings'], 0, 1) == 1;
        // How about, are they banned?
        if (allowedTo('moderate_forum')) {
            require_once SUBSDIR . '/Bans.subs.php';
            $hostname = !empty($context['member']['hostname']) ? $context['member']['hostname'] : '';
            $email = !empty($context['member']['email']) ? $context['member']['email'] : '';
            $context['member']['bans'] = BanCheckUser($memID, $hostname, $email);
            // Can they edit the ban?
            $context['can_edit_ban'] = allowedTo('manage_bans');
        }
        // Load up the most recent attachments for this user for use in profile views etc.
        $context['thumbs'] = array();
        if (!empty($modSettings['attachmentEnable']) && !empty($settings['attachments_on_summary']) && in_array('attachments', $summary_areas)) {
            $boardsAllowed = boardsAllowedTo('view_attachments');
            if (empty($boardsAllowed)) {
                $boardsAllowed = array(-1);
            }
            $attachments = $this->list_getAttachments(0, $settings['attachments_on_summary'], 'm.poster_time DESC', $boardsAllowed, $memID);
            // Some generic images for mime types
            $mime_images_url = $settings['default_images_url'] . '/mime_images/';
            $mime_path = $settings['default_theme_dir'] . '/images/mime_images/';
            // Load them in to $context for use in the template
            for ($i = 0, $count = count($attachments); $i < $count; $i++) {
                $context['thumbs'][$i] = array('url' => $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'], 'img' => '', 'filename' => $attachments[$i]['filename'], 'downloads' => $attachments[$i]['downloads'], 'subject' => $attachments[$i]['subject'], 'id' => $attachments[$i]['id']);
                // Show a thumbnail image as well?
                if ($attachments[$i]['is_image'] && !empty($modSettings['attachmentShowImages']) && !empty($modSettings['attachmentThumbnails'])) {
                    if (!empty($attachments[$i]['id_thumb'])) {
                        $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id_thumb'] . ';image" title="" alt="" />';
                    } else {
                        // No thumbnail available ... use html instead
                        if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight'])) {
                            if ($attachments[$i]['width'] > $modSettings['attachmentThumbWidth'] || $attachments[$i]['height'] > $modSettings['attachmentThumbHeight']) {
                                $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'] . '" title="" alt="" width="' . $modSettings['attachmentThumbWidth'] . '" height="' . $modSettings['attachmentThumbHeight'] . '" />';
                            } else {
                                $context['thumbs'][$i]['img'] = '<img id="thumb_' . $attachments[$i]['id'] . '" src="' . $scripturl . '?action=dlattach;topic=' . $attachments[$i]['topic'] . '.0;attach=' . $attachments[$i]['id'] . '" title="" alt="" width="' . $attachments[$i]['width'] . '" height="' . $attachments[$i]['height'] . '" />';
                            }
                        }
                    }
                } else {
                    if (!empty($modSettings['attachmentThumbWidth']) && !empty($modSettings['attachmentThumbHeight']) && (128 > $modSettings['attachmentThumbWidth'] || 128 > $modSettings['attachmentThumbHeight'])) {
                        $context['thumbs'][$i]['img'] = '<img src="' . $mime_images_url . (!file_exists($mime_path . $attachments[$i]['fileext'] . '.png') ? 'default' : $attachments[$i]['fileext']) . '.png" title="" alt="" width="' . $modSettings['attachmentThumbWidth'] . '" height="' . $modSettings['attachmentThumbHeight'] . '" />';
                    } else {
                        $context['thumbs'][$i]['img'] = '<img src="' . $mime_images_url . (!file_exists($mime_path . $attachments[$i]['fileext'] . '.png') ? 'default' : $attachments[$i]['fileext']) . '.png" title="" alt="" />';
                    }
                }
            }
        }
        // Would you be mine? Could you be mine? Be my buddy :D
        if (!empty($modSettings['enable_buddylist']) && $context['user']['is_owner'] && !empty($user_info['buddies']) && in_array('buddies', $summary_areas)) {
            $context['buddies'] = array();
            loadMemberData($user_info['buddies'], false, 'profile');
            // Get the info for this buddy
            foreach ($user_info['buddies'] as $buddy) {
                loadMemberContext($buddy, true);
                $context['buddies'][$buddy] = $memberContext[$buddy];
            }
        }
        // How about thier most recent posts?
        if (in_array('posts', $summary_areas)) {
            // Is the load average too high just now, then let them know
            if (!empty($modSettings['loadavg_show_posts']) && $modSettings['current_load'] >= $modSettings['loadavg_show_posts']) {
                $context['loadaverage'] = true;
            } else {
                // Set up to get the last 10 psots of this member
                $msgCount = count_user_posts($memID);
                $range_limit = '';
                $maxIndex = 10;
                $start = (int) $_REQUEST['start'];
                // If they are a frequent poster, we guess the range to help minimize what the query work
                if ($msgCount > 1000) {
                    list($min_msg_member, $max_msg_member) = findMinMaxUserMessage($memID);
                    $margin = floor(($max_msg_member - $min_msg_member) * (($start + $modSettings['defaultMaxMessages']) / $msgCount) + 0.1 * ($max_msg_member - $min_msg_member));
                    $range_limit = 'm.id_msg > ' . ($max_msg_member - $margin);
                }
                // Find this user's most recent posts
                $rows = load_user_posts($memID, 0, $maxIndex, $range_limit);
                $context['posts'] = array();
                foreach ($rows as $row) {
                    // Censor....
                    censorText($row['body']);
                    censorText($row['subject']);
                    // Do the code.
                    $row['body'] = parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']);
                    $preview = strip_tags(strtr($row['body'], array('<br />' => '&#10;')));
                    $preview = Util::shorten_text($preview, !empty($modSettings['ssi_preview_length']) ? $modSettings['ssi_preview_length'] : 128);
                    $short_subject = Util::shorten_text($row['subject'], !empty($modSettings['ssi_subject_length']) ? $modSettings['ssi_subject_length'] : 24);
                    // And the array...
                    $context['posts'][] = array('body' => $preview, 'board' => array('name' => $row['bname'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'subject' => $row['subject'], 'short_subject' => $short_subject, 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $short_subject . '</a>');
                }
            }
        }
        // How about the most recent topics that they started?
        if (in_array('topics', $summary_areas)) {
            // Is the load average still too high?
            if (!empty($modSettings['loadavg_show_posts']) && $modSettings['current_load'] >= $modSettings['loadavg_show_posts']) {
                $context['loadaverage'] = true;
            } else {
                // Set up to get the last 10 topics of this member
                $topicCount = count_user_topics($memID);
                $range_limit = '';
                $maxIndex = 10;
                // If they are a frequent topic starter we guess the range to help the query
                if ($topicCount > 1000) {
                    list($min_topic_member, $max_topic_member) = findMinMaxUserTopic($memID);
                    $margin = floor(($max_topic_member - $min_topic_member) * (($start + $modSettings['defaultMaxMessages']) / $topicCount) + 0.1 * ($max_topic_member - $min_topic_member));
                    $margin *= 5;
                    $range_limit = 't.id_first_msg > ' . ($max_topic_member - $margin);
                }
                // Find this user's most recent topics
                $rows = load_user_topics($memID, 0, $maxIndex, $range_limit);
                $context['topics'] = array();
                foreach ($rows as $row) {
                    // Censor....
                    censorText($row['body']);
                    censorText($row['subject']);
                    // Do the code.
                    $short_subject = Util::shorten_text($row['subject'], !empty($modSettings['ssi_subject_length']) ? $modSettings['ssi_subject_length'] : 24);
                    // And the array...
                    $context['topics'][] = array('board' => array('name' => $row['bname'], 'link' => '<a href="' . $scripturl . '?board=' . $row['id_board'] . '.0">' . $row['bname'] . '</a>'), 'subject' => $row['subject'], 'short_subject' => $short_subject, 'time' => standardTime($row['poster_time']), 'html_time' => htmlTime($row['poster_time']), 'timestamp' => forum_time(true, $row['poster_time']), 'link' => '<a href="' . $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'] . '" rel="nofollow">' . $short_subject . '</a>');
                }
            }
        }
        // To finish this off, custom profile fields.
        require_once SUBSDIR . '/Profile.subs.php';
        loadCustomFields($memID);
        // To make tabs work, we need jQueryUI
        $modSettings['jquery_include_ui'] = true;
        addInlineJavascript('
		$(function() {$( "#tabs" ).tabs();});', true);
    }
示例#9
0
function method_get_user_info()
{
    global $context, $mobdb, $mobsettings, $modSettings, $scripturl, $func, $smcFunc, $memberContext, $txt;
    // Invalid username? Non-existant username?
    if (!isset($context['mob_request']['params'][0])) {
        createErrorResponse(7);
    }
    $username = base64_decode($context['mob_request']['params'][0][0]);
    ######## Added by Sean##############
    $username = htmltrim__recursive($username);
    $username = stripslashes__recursive($username);
    $username = htmlspecialchars__recursive($username);
    $username = addslashes__recursive($username);
    ####################################
    list($member_id) = loadMemberData($username, true);
    if (!loadMemberContext($member_id) || !isset($memberContext[$member_id])) {
        fatal_error($txt[453] . ' - ' . $member_id, false);
    }
    $user_data = $memberContext[$member_id];
    loadLanguage('Profile');
    if (!empty($modSettings['titlesEnable']) && $user_data['title'] != '') {
        $user_data['custom_fields_list'][$txt['title1']] = $user_data['title'];
    }
    $user_data['custom_fields_list'][$txt[87]] = !empty($user_data['group']) ? $user_data['group'] : $user_data['post_group'];
    if (allowedTo('moderate_forum') && $user_data['ip']) {
        $user_data['custom_fields_list'][$txt[512]] = $user_data['ip'];
        if (preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $user_data['ip']) == 1 && empty($modSettings['disableHostnameLookup'])) {
            $user_data['custom_fields_list'][$txt['hostname']] = host_from_ip($user_data['ip']);
        }
    }
    // If karma enabled show the members karma.
    if ($modSettings['karmaMode'] == '1') {
        $user_data['custom_fields_list'][$modSettings['karmaLabel']] = $user_data['karma']['good'] - $user_data['karma']['bad'];
    } elseif ($modSettings['karmaMode'] == '2') {
        $user_data['custom_fields_list'][$modSettings['karmaLabel']] = '+' . $user_data['karma']['good'] . '/-' . $user_data['karma']['bad'];
    }
    if ($user_data['icq']['name']) {
        $user_data['custom_fields_list'][$txt[513]] = $user_data['icq']['name'];
    }
    if ($user_data['aim']['name']) {
        $user_data['custom_fields_list'][$txt[603]] = $user_data['aim']['name'];
    }
    if ($user_data['msn']['name']) {
        $user_data['custom_fields_list'][$txt['MSN']] = $user_data['msn']['name'];
    }
    if ($user_data['yim']['name']) {
        $user_data['custom_fields_list'][$txt[604]] = $user_data['yim']['name'];
    }
    $user_data['custom_fields_list'][$txt[69]] = $user_data['email_public'] || !$user_data['hide_email'] ? $user_data['email'] : $txt[722];
    if ($user_data['website']['title'] != '' || $user_data['website']['url'] != '') {
        $user_data['custom_fields_list'][$txt[96]] = $user_data['website']['title'] . ($user_data['website']['url'] ? '(' . $user_data['website']['url'] . ')' : '');
    }
    if ($user_data['gender']['name']) {
        $user_data['custom_fields_list'][$txt[231]] = $user_data['gender']['name'];
    }
    if (!empty($user_data['birth_date'])) {
        list($birth_year, $birth_month, $birth_day) = sscanf($user_data['birth_date'], '%d-%d-%d');
        $datearray = getdate(forum_time());
        if ($birth_year > 4) {
            $user_data['custom_fields_list'][$txt[420]] = $datearray['year'] - $birth_year - ($datearray['mon'] > $birth_month || $datearray['mon'] == $birth_month && $datearray['mday'] >= $birth_day ? 0 : 1);
            $user_data['custom_fields_list'][$txt[420]] .= $datearray['mon'] == $birth_month && $datearray['mday'] == $birth_day ? ' (' . substr($txt['calendar3'], 0, -1) . ')' : '';
        }
    }
    if ($user_data['location']) {
        $user_data['custom_fields_list'][$txt[227]] = $user_data['location'];
    }
    if ($user_data['local_time']) {
        $user_data['custom_fields_list'][$txt['local_time']] = $user_data['local_time'];
    }
    if (!empty($modSettings['userLanguage']) && $user_data['language']) {
        $user_data['custom_fields_list'][$txt['smf225']] = $user_data['language'];
    }
    if ($user_data['signature']) {
        $user_data['custom_fields_list'][$txt[85]] = $user_data['signature'];
    }
    // Return the output
    outputRPCUserInfo($user_data);
}
示例#10
0
    /**
     * This function is behind the screen for adding new bans and modifying existing ones.
     *
     * Adding new bans:
     *  - is accesssed by ?action=admin;area=ban;sa=add.
     *  - uses the ban_edit sub template of the ManageBans template.
     *
     * Modifying existing bans:
     *  - is accesssed by ?action=admin;area=ban;sa=edit;bg=x
     *  - uses the ban_edit sub template of the ManageBans template.
     *  - shows a list of ban triggers for the specified ban.
     */
    public function action_edit()
    {
        global $txt, $modSettings, $context, $scripturl;
        require_once SUBSDIR . '/Bans.subs.php';
        $ban_errors = Error_Context::context('ban', 1);
        // Saving a new or edited ban?
        if ((isset($_POST['add_ban']) || isset($_POST['modify_ban']) || isset($_POST['remove_selection'])) && !$ban_errors->hasErrors()) {
            $this->action_edit2();
        }
        $ban_group_id = isset($context['ban']['id']) ? $context['ban']['id'] : (isset($_REQUEST['bg']) ? (int) $_REQUEST['bg'] : 0);
        // Template needs this to show errors using javascript
        loadLanguage('Errors');
        createToken('admin-bet');
        $context['form_url'] = $scripturl . '?action=admin;area=ban;sa=edit';
        // Prepare any errors found to the template to show
        $context['ban_errors'] = array('errors' => $ban_errors->prepareErrors(), 'type' => $ban_errors->getErrorType() == 0 ? 'minor' : 'serious', 'title' => $txt['ban_errors_detected']);
        if (!$ban_errors->hasErrors()) {
            // If we're editing an existing ban, get it from the database.
            if (!empty($ban_group_id)) {
                $context['ban_group_id'] = $ban_group_id;
                // We're going to want this for making our list.
                require_once SUBSDIR . '/GenericList.class.php';
                // Setup for a createlist
                $listOptions = array('id' => 'ban_items', 'base_href' => $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $ban_group_id, 'no_items_label' => $txt['ban_no_triggers'], 'items_per_page' => $modSettings['defaultMaxMessages'], 'get_items' => array('function' => 'list_getBanItems', 'params' => array('ban_group_id' => $ban_group_id)), 'get_count' => array('function' => 'list_getNumBanItems', 'params' => array('ban_group_id' => $ban_group_id)), 'columns' => array('type' => array('header' => array('value' => $txt['ban_banned_entity'], 'style' => 'width: 60%;'), 'data' => array('function' => create_function('$ban_item', '
									global $txt;

									if (in_array($ban_item[\'type\'], array(\'ip\', \'hostname\', \'email\')))
										return \'<strong>\' . $txt[$ban_item[\'type\']] . \':</strong>&nbsp;\' . $ban_item[$ban_item[\'type\']];
									elseif ($ban_item[\'type\'] == \'user\')
										return \'<strong>\' . $txt[\'username\'] . \':</strong>&nbsp;\' . $ban_item[\'user\'][\'link\'];
									else
										return \'<strong>\' . $txt[\'unknown\'] . \':</strong>&nbsp;\' . $ban_item[\'no_bantype_selected\'];
								'))), 'hits' => array('header' => array('value' => $txt['ban_hits'], 'style' => 'width: 15%;text-align: center'), 'data' => array('db' => 'hits', 'class' => 'centertext')), 'id' => array('header' => array('value' => $txt['ban_actions'], 'style' => 'width: 15%;'), 'data' => array('function' => create_function('$ban_item', '
									global $txt, $context, $scripturl;

									return \'<a href="\' . $scripturl . \'?action=admin;area=ban;sa=edittrigger;bg=\' . $context[\'ban\'][\'id\'] . \';bi=\' . $ban_item[\'id\'] . \'">\' . $txt[\'ban_edit_trigger\'] . \'</a>\';
								'))), 'checkboxes' => array('header' => array('value' => '<input type="checkbox" onclick="invertAll(this, this.form, \'ban_items\');" class="input_check" />', 'style' => 'width: 5%;'), 'data' => array('sprintf' => array('format' => '<input type="checkbox" name="ban_items[]" value="%1$d" class="input_check" />', 'params' => array('id' => false))))), 'form' => array('href' => $scripturl . '?action=admin;area=ban;sa=edit;bg=' . $ban_group_id), 'additional_rows' => array(array('position' => 'below_table_data', 'class' => 'submitbutton', 'value' => '
								<input type="submit" name="remove_selection" value="' . $txt['ban_remove_selected_triggers'] . '" class="right_submit" />
								<a class="linkbutton" href="' . $scripturl . '?action=admin;area=ban;sa=edittrigger;bg=' . $ban_group_id . '">' . $txt['ban_add_trigger'] . '</a>
								<input type="hidden" name="bg" value="' . $ban_group_id . '" />
								<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
								<input type="hidden" name="' . $context['admin-bet_token_var'] . '" value="' . $context['admin-bet_token'] . '" />')));
                createList($listOptions);
            } else {
                $context['ban'] = array('id' => 0, 'name' => '', 'expiration' => array('status' => 'never', 'days' => 0), 'reason' => '', 'notes' => '', 'ban_days' => 0, 'cannot' => array('access' => true, 'post' => false, 'register' => false, 'login' => false), 'is_new' => true);
                $context['ban_suggestions'] = array('main_ip' => '', 'hostname' => '', 'email' => '', 'member' => array('id' => 0));
                // Overwrite some of the default form values if a user ID was given.
                if (!empty($_REQUEST['u'])) {
                    $context['ban_suggestions'] = array_merge($context['ban_suggestions'], getMemberData((int) $_REQUEST['u']));
                    if (!empty($context['ban_suggestions']['member']['id'])) {
                        $context['ban_suggestions']['href'] = $scripturl . '?action=profile;u=' . $context['ban_suggestions']['member']['id'];
                        $context['ban_suggestions']['member']['link'] = '<a href="' . $context['ban_suggestions']['href'] . '">' . $context['ban_suggestions']['member']['name'] . '</a>';
                        // Default the ban name to the name of the banned member.
                        $context['ban']['name'] = $context['ban_suggestions']['member']['name'];
                        // @todo: there should be a better solution...
                        // used to lock the "Ban on Username" input when banning from profile
                        $context['ban']['from_user'] = true;
                        // Would be nice if we could also ban the hostname.
                        if ((preg_match('/^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$/', $context['ban_suggestions']['main_ip']) == 1 || isValidIPv6($context['ban_suggestions']['main_ip'])) && empty($modSettings['disableHostnameLookup'])) {
                            $context['ban_suggestions']['hostname'] = host_from_ip($context['ban_suggestions']['main_ip']);
                        }
                        $context['ban_suggestions']['other_ips'] = banLoadAdditionalIPs($context['ban_suggestions']['member']['id']);
                    }
                } else {
                    $context['use_autosuggest'] = true;
                    loadJavascriptFile('suggest.js');
                }
            }
        }
        // Set the right template
        $context['sub_template'] = 'ban_edit';
        // A couple of text strings we *may* need
        addJavascriptVar(array('txt_ban_name_empty' => $txt['ban_name_empty'], 'txt_ban_restriction_empty' => $txt['ban_restriction_empty']), true);
        // And a bit of javascript to enable/disable some fields
        addInlineJavascript('addLoadEvent(fUpdateStatus);', true);
    }