| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | *
|
|---|
| 4 | * @package acp
|
|---|
| 5 | * @version $Id$
|
|---|
| 6 | * @copyright (c) 2005 phpBB Group
|
|---|
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * @ignore
|
|---|
| 13 | */
|
|---|
| 14 | if (!defined('IN_PHPBB'))
|
|---|
| 15 | {
|
|---|
| 16 | exit;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * @package acp
|
|---|
| 21 | */
|
|---|
| 22 | class acp_ban
|
|---|
| 23 | {
|
|---|
| 24 | var $u_action;
|
|---|
| 25 |
|
|---|
| 26 | function main($id, $mode)
|
|---|
| 27 | {
|
|---|
| 28 | global $config, $db, $user, $auth, $template, $cache;
|
|---|
| 29 | global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
|
|---|
| 30 |
|
|---|
| 31 | include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
|---|
| 32 |
|
|---|
| 33 | $bansubmit = (isset($_POST['bansubmit'])) ? true : false;
|
|---|
| 34 | $unbansubmit = (isset($_POST['unbansubmit'])) ? true : false;
|
|---|
| 35 | $current_time = time();
|
|---|
| 36 |
|
|---|
| 37 | $user->add_lang(array('acp/ban', 'acp/users'));
|
|---|
| 38 | $this->tpl_name = 'acp_ban';
|
|---|
| 39 | $form_key = 'acp_ban';
|
|---|
| 40 | add_form_key($form_key);
|
|---|
| 41 |
|
|---|
| 42 | if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
|
|---|
| 43 | {
|
|---|
| 44 | trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | // Ban submitted?
|
|---|
| 48 | if ($bansubmit)
|
|---|
| 49 | {
|
|---|
| 50 | // Grab the list of entries
|
|---|
| 51 | $ban = utf8_normalize_nfc(request_var('ban', '', true));
|
|---|
| 52 | $ban_len = request_var('banlength', 0);
|
|---|
| 53 | $ban_len_other = request_var('banlengthother', '');
|
|---|
| 54 | $ban_exclude = request_var('banexclude', 0);
|
|---|
| 55 | $ban_reason = utf8_normalize_nfc(request_var('banreason', '', true));
|
|---|
| 56 | $ban_give_reason = utf8_normalize_nfc(request_var('bangivereason', '', true));
|
|---|
| 57 |
|
|---|
| 58 | if ($ban)
|
|---|
| 59 | {
|
|---|
| 60 | user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
|
|---|
| 61 |
|
|---|
| 62 | trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 | else if ($unbansubmit)
|
|---|
| 66 | {
|
|---|
| 67 | $ban = request_var('unban', array(''));
|
|---|
| 68 |
|
|---|
| 69 | if ($ban)
|
|---|
| 70 | {
|
|---|
| 71 | user_unban($mode, $ban);
|
|---|
| 72 |
|
|---|
| 73 | trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // Define language vars
|
|---|
| 78 | $this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
|
|---|
| 79 |
|
|---|
| 80 | $l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
|
|---|
| 81 | $l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
|
|---|
| 82 | $l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
|
|---|
| 83 | $l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
|
|---|
| 84 | $l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
|
|---|
| 85 |
|
|---|
| 86 | switch ($mode)
|
|---|
| 87 | {
|
|---|
| 88 | case 'user':
|
|---|
| 89 | $l_ban_cell = $user->lang['USERNAME'];
|
|---|
| 90 | break;
|
|---|
| 91 |
|
|---|
| 92 | case 'ip':
|
|---|
| 93 | $l_ban_cell = $user->lang['IP_HOSTNAME'];
|
|---|
| 94 | break;
|
|---|
| 95 |
|
|---|
| 96 | case 'email':
|
|---|
| 97 | $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
|
|---|
| 98 | break;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | $this->display_ban_options($mode);
|
|---|
| 102 |
|
|---|
| 103 | $template->assign_vars(array(
|
|---|
| 104 | 'L_TITLE' => $this->page_title,
|
|---|
| 105 | 'L_EXPLAIN' => $l_ban_explain,
|
|---|
| 106 | 'L_UNBAN_TITLE' => $l_unban_title,
|
|---|
| 107 | 'L_UNBAN_EXPLAIN' => $l_unban_explain,
|
|---|
| 108 | 'L_BAN_CELL' => $l_ban_cell,
|
|---|
| 109 | 'L_BAN_EXCLUDE_EXPLAIN' => $l_ban_exclude_explain,
|
|---|
| 110 | 'L_NO_BAN_CELL' => $l_no_ban_cell,
|
|---|
| 111 |
|
|---|
| 112 | 'S_USERNAME_BAN' => ($mode == 'user') ? true : false,
|
|---|
| 113 |
|
|---|
| 114 | 'U_ACTION' => $this->u_action,
|
|---|
| 115 | 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=acp_ban&field=ban'),
|
|---|
| 116 | ));
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Display ban options
|
|---|
| 121 | */
|
|---|
| 122 | function display_ban_options($mode)
|
|---|
| 123 | {
|
|---|
| 124 | global $user, $db, $template;
|
|---|
| 125 |
|
|---|
| 126 | // Ban length options
|
|---|
| 127 | $ban_end_text = array(0 => $user->lang['PERMANENT'], 30 => $user->lang['30_MINS'], 60 => $user->lang['1_HOUR'], 360 => $user->lang['6_HOURS'], 1440 => $user->lang['1_DAY'], 10080 => $user->lang['7_DAYS'], 20160 => $user->lang['2_WEEKS'], 40320 => $user->lang['1_MONTH'], -1 => $user->lang['UNTIL'] . ' -> ');
|
|---|
| 128 |
|
|---|
| 129 | $ban_end_options = '';
|
|---|
| 130 | foreach ($ban_end_text as $length => $text)
|
|---|
| 131 | {
|
|---|
| 132 | $ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | switch ($mode)
|
|---|
| 136 | {
|
|---|
| 137 | case 'user':
|
|---|
| 138 |
|
|---|
| 139 | $field = 'username';
|
|---|
| 140 | $l_ban_cell = $user->lang['USERNAME'];
|
|---|
| 141 |
|
|---|
| 142 | $sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
|
|---|
| 143 | FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
|
|---|
| 144 | WHERE (b.ban_end >= ' . time() . '
|
|---|
| 145 | OR b.ban_end = 0)
|
|---|
| 146 | AND u.user_id = b.ban_userid
|
|---|
| 147 | ORDER BY u.username_clean ASC';
|
|---|
| 148 | break;
|
|---|
| 149 |
|
|---|
| 150 | case 'ip':
|
|---|
| 151 |
|
|---|
| 152 | $field = 'ban_ip';
|
|---|
| 153 | $l_ban_cell = $user->lang['IP_HOSTNAME'];
|
|---|
| 154 |
|
|---|
| 155 | $sql = 'SELECT *
|
|---|
| 156 | FROM ' . BANLIST_TABLE . '
|
|---|
| 157 | WHERE (ban_end >= ' . time() . "
|
|---|
| 158 | OR ban_end = 0)
|
|---|
| 159 | AND ban_ip <> ''
|
|---|
| 160 | ORDER BY ban_ip";
|
|---|
| 161 | break;
|
|---|
| 162 |
|
|---|
| 163 | case 'email':
|
|---|
| 164 |
|
|---|
| 165 | $field = 'ban_email';
|
|---|
| 166 | $l_ban_cell = $user->lang['EMAIL_ADDRESS'];
|
|---|
| 167 |
|
|---|
| 168 | $sql = 'SELECT *
|
|---|
| 169 | FROM ' . BANLIST_TABLE . '
|
|---|
| 170 | WHERE (ban_end >= ' . time() . "
|
|---|
| 171 | OR ban_end = 0)
|
|---|
| 172 | AND ban_email <> ''
|
|---|
| 173 | ORDER BY ban_email";
|
|---|
| 174 | break;
|
|---|
| 175 | }
|
|---|
| 176 | $result = $db->sql_query($sql);
|
|---|
| 177 |
|
|---|
| 178 | $banned_options = '';
|
|---|
| 179 | $ban_length = $ban_reasons = $ban_give_reasons = array();
|
|---|
| 180 |
|
|---|
| 181 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 182 | {
|
|---|
| 183 | $banned_options .= '<option' . (($row['ban_exclude']) ? ' class="sep"' : '') . ' value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
|
|---|
| 184 |
|
|---|
| 185 | $time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
|
|---|
| 186 |
|
|---|
| 187 | if ($time_length == 0)
|
|---|
| 188 | {
|
|---|
| 189 | // Banned permanently
|
|---|
| 190 | $ban_length[$row['ban_id']] = $user->lang['PERMANENT'];
|
|---|
| 191 | }
|
|---|
| 192 | else if (isset($ban_end_text[$time_length]))
|
|---|
| 193 | {
|
|---|
| 194 | // Banned for a given duration
|
|---|
| 195 | $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DURATION'], $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
|
|---|
| 196 | }
|
|---|
| 197 | else
|
|---|
| 198 | {
|
|---|
| 199 | // Banned until given date
|
|---|
| 200 | $ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DATE'], $user->format_date($row['ban_end'], false, true));
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | $ban_reasons[$row['ban_id']] = $row['ban_reason'];
|
|---|
| 204 | $ban_give_reasons[$row['ban_id']] = $row['ban_give_reason'];
|
|---|
| 205 | }
|
|---|
| 206 | $db->sql_freeresult($result);
|
|---|
| 207 |
|
|---|
| 208 | if (sizeof($ban_length))
|
|---|
| 209 | {
|
|---|
| 210 | foreach ($ban_length as $ban_id => $length)
|
|---|
| 211 | {
|
|---|
| 212 | $template->assign_block_vars('ban_length', array(
|
|---|
| 213 | 'BAN_ID' => (int) $ban_id,
|
|---|
| 214 | 'LENGTH' => $length,
|
|---|
| 215 | 'A_LENGTH' => addslashes($length),
|
|---|
| 216 | ));
|
|---|
| 217 | }
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | if (sizeof($ban_reasons))
|
|---|
| 221 | {
|
|---|
| 222 | foreach ($ban_reasons as $ban_id => $reason)
|
|---|
| 223 | {
|
|---|
| 224 | $template->assign_block_vars('ban_reason', array(
|
|---|
| 225 | 'BAN_ID' => $ban_id,
|
|---|
| 226 | 'REASON' => $reason,
|
|---|
| 227 | 'A_REASON' => addslashes(htmlspecialchars_decode($reason)),
|
|---|
| 228 | ));
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | if (sizeof($ban_give_reasons))
|
|---|
| 233 | {
|
|---|
| 234 | foreach ($ban_give_reasons as $ban_id => $reason)
|
|---|
| 235 | {
|
|---|
| 236 | $template->assign_block_vars('ban_give_reason', array(
|
|---|
| 237 | 'BAN_ID' => $ban_id,
|
|---|
| 238 | 'REASON' => $reason,
|
|---|
| 239 | 'A_REASON' => addslashes(htmlspecialchars_decode($reason)),
|
|---|
| 240 | ));
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | $template->assign_vars(array(
|
|---|
| 245 | 'S_BAN_END_OPTIONS' => $ban_end_options,
|
|---|
| 246 | 'S_BANNED_OPTIONS' => ($banned_options) ? true : false,
|
|---|
| 247 | 'BANNED_OPTIONS' => $banned_options)
|
|---|
| 248 | );
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | ?>
|
|---|