/** * View a summary. * @param int $memID id_member */ 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_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') && $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']; $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']); // Do we have a hostname already? if (!empty($context['member']['hostname'])) { $ban_query[] = '({string:hostname} LIKE hostname)'; $ban_query_vars['hostname'] = $context['member']['hostname']; } // 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); }
/** * Used to see if a user is banned * * - Checks banning by ip, hostname, email or member id * * @package Bans * @param int $memID * @param string $hostname * @param string $email */ function BanCheckUser($memID, $hostname = '', $email = '') { global $memberContext, $scripturl, $txt; $db = database(); $bans = array(); // This is a valid member id, we at least need that if (loadMemberContext($memID) && isset($memberContext[$memID])) { $ban_query = array(); $ban_query_vars = array('time' => time()); // Member id and ip $ban_query[] = 'id_member = ' . $memID; require_once SOURCEDIR . '/Security.php'; $ban_query[] = constructBanQueryIP($memberContext[$memID]['ip']); // Do we have a hostname? if (!empty($hostname)) { $ban_query[] = '({string:hostname} LIKE hostname)'; $ban_query_vars['hostname'] = $hostname; } // Check their email as well... if (strlen($email) != 0) { $ban_query[] = '({string:email} LIKE bi.email_address)'; $ban_query_vars['email'] = $email; } // So... are they banned? Dying to know! $request = $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); $bans = array(); while ($row = $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>'); $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); } $db->free_result($request); } return $bans; }
/** * Do banning related stuff. (ie. disallow access....) * Checks if the user is banned, and if so dies with an error. * Caches this information for optimization purposes. * Forces a recheck if force_check is true. * @param bool $forceCheck = false */ function is_not_banned($forceCheck = false) { global $txt, $modSettings, $context, $user_info, $backend_subdir; 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'] != $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) { if ($ip_number == 'ip2' && $user_info['ip2'] == $user_info['ip']) { continue; } $ban_query[] = constructBanQueryIP($user_info[$ip_number]); // IP was valid, maybe there's also a hostname... if (empty($modSettings['disableHostnameLookup']) && $user_info[$ip_number] != 'unknown') { $hostname = host_from_ip($user_info[$ip_number]); if (strlen($hostname) > 0) { $ban_query[] = '({string:hostname} LIKE bi.hostname)'; $ban_query_vars['hostname'] = $hostname; } } } // 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 = smf_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 = 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 (!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; } } } } 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']) || 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 . '/' . $backend_subdir . '/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 = smf_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 = 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 . '/lib/Subs-Auth.php'; $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); smf_setcookie($cookiename . '_', '', time() - 3600, $cookie_url[1], $cookie_url[0], false, false); } } // 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']) { smf_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 . '/lib/Subs-Auth.php'; $cookie_url = url_parts(!empty($modSettings['localCookies']), !empty($modSettings['globalCookies'])); smf_setcookie($cookiename . '_', implode(',', $_SESSION['ban']['cannot_access']['ids']), time() + 3153600, $cookie_url[1], $cookie_url[0], false, false); // 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! smf_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(); } }