punbb/admin_bans.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
// Tell header.php to use the admin template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
define('PUN_ADMIN_CONSOLE', 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    29
//define('PUN_ROOT', './');
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    30
//require PUN_ROOT.'include/common.php';
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    31
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    32
global $pun_db, $pun_user, $pun_config, $lang_common;
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    33
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    34
require PUN_ROOT.'include/common_admin.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    35
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    36
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    37
if ($pun_user['g_id'] < PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    38
	message($lang_common['No permission']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    39
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    40
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    41
// Add/edit a ban (stage 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    42
if (isset($_REQUEST['add_ban']) || isset($_GET['edit_ban']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    43
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    44
	if (isset($_GET['add_ban']) || isset($_POST['add_ban']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    45
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    46
		// If the id of the user to ban was provided through GET (a link from profile.php)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    47
		if (isset($_GET['add_ban']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    48
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    49
			$add_ban = intval($_GET['add_ban']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    50
			if ($add_ban < 2)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    51
				message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    52
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    53
			$user_id = $add_ban;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    54
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    55
			$result = $pun_db->query('SELECT group_id, username, email FROM '.$pun_db->prefix.'users WHERE id='.$user_id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    56
			if ($pun_db->num_rows($result))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    57
				list($group_id, $ban_user, $ban_email) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
			else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
				message('No user by that ID registered.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    60
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    61
		else	// Otherwise the username is in POST
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
			$ban_user = trim($_POST['new_ban_user']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
			if ($ban_user != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
			{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    67
				$result = $pun_db->query('SELECT id, group_id, username, email FROM '.$pun_db->prefix.'users WHERE username=\''.$pun_db->escape($ban_user).'\' AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    68
				if ($pun_db->num_rows($result))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    69
					list($user_id, $group_id, $ban_user, $ban_email) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
				else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
					message('No user by that username registered. If you want to add a ban not tied to a specific username just leave the username blank.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
		// Make sure we're not banning an admin
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    76
		if (isset($group_id) && $group_id == PUN_ADMIN)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
			message('The user '.pun_htmlspecialchars($ban_user).' is an administrator and can\'t be banned. If you want to ban an administrator, you must first demote him/her to moderator or user.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
		// If we have a $user_id, we can try to find the last known IP of that user
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
		if (isset($user_id))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
		{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    82
			$result = $pun_db->query('SELECT poster_ip FROM '.$pun_db->prefix.'posts WHERE poster_id='.$user_id.' ORDER BY posted DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    83
			$ban_ip = ($pun_db->num_rows($result)) ? $pun_db->result($result) : '';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
		$mode = 'add';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    87
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
	else	// We are editing a ban
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
		$ban_id = intval($_GET['edit_ban']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
		if ($ban_id < 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    92
			message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    93
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    94
		$result = $pun_db->query('SELECT username, ip, email, message, expire FROM '.$pun_db->prefix.'bans WHERE id='.$ban_id) or error('Unable to fetch ban info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    95
		if ($pun_db->num_rows($result))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    96
			list($ban_user, $ban_ip, $ban_email, $ban_message, $ban_expire) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
			message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
		$ban_expire = ($ban_expire != '') ? date('Y-m-d', $ban_expire) : '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
		$mode = 'edit';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   105
	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
	$focus_element = array('bans2', 'ban_user');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
	generate_admin_menu('bans');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   110
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   111
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   112
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
	<div class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   114
		<h2><span>Ban advanced settings</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
			<form id="bans2" method="post" action="admin_bans.php">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   118
				<input type="hidden" name="mode" value="<?php echo $mode ?>" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
<?php if ($mode == 'edit'): ?>				<input type="hidden" name="ban_id" value="<?php echo $ban_id ?>" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   120
<?php endif; ?>				<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
						<legend>Supplement ban with IP and e-mail</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
							<table class="aligntop" cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
									<th scope="row">Username</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
										<input type="text" name="ban_user" size="25" maxlength="25" value="<?php if (isset($ban_user)) echo pun_htmlspecialchars($ban_user); ?>" tabindex="1" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
										<span>The username to ban.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
									<th scope="row">IP-adresses</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
										<input type="text" name="ban_ip" size="45" maxlength="255" value="<?php if (isset($ban_ip)) echo $ban_ip; ?>" tabindex="2" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
										<span>The IP or IP-ranges you wish to ban (e.g. 150.11.110.1 or 150.11.110). Separate addresses with spaces. If an IP is entered already it is the last known IP of this user in the database.<?php if ($ban_user != '' && isset($user_id)) echo ' Click <a href="admin_users.php?ip_stats='.$user_id.'">here</a> to see IP statistics for this user.' ?></span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
									<th scope="row">E-mail/domain</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
										<input type="text" name="ban_email" size="40" maxlength="50" value="<?php if (isset($ban_email)) echo strtolower($ban_email); ?>" tabindex="3" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
										<span>The e-mail or e-mail domain you wish to ban (e.g. someone@somewhere.com or somewhere.com). See "Allow banned e-mail addresses" in Options for more info.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
							<p class="topspace"><strong class="warntext">You should be very careful when banning an IP-range because of the possibility of multiple users matching the same partial IP.</strong></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   148
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   150
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   151
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   152
						<legend>Ban message and expiry</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   153
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   154
							<table class="aligntop" cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   155
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   156
									<th scope="row">Ban message</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   157
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   158
										<input type="text" name="ban_message" size="50" maxlength="255" value="<?php if (isset($ban_message)) echo pun_htmlspecialchars($ban_message); ?>" tabindex="4" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   159
										<span>A message that will be displayed to the banned user when he/she visits the forums.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   160
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   161
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   162
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   163
									<th scope="row">Expire date</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   164
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   165
										<input type="text" name="ban_expire" size="17" maxlength="10" value="<?php if (isset($ban_expire)) echo $ban_expire; ?>" tabindex="5" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   166
										<span>The date when this ban should be automatically removed (format: YYYY-MM-DD). Leave blank to remove manually.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   167
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   168
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   169
							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   170
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   171
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   172
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   173
				<p class="submitend"><input type="submit" name="add_edit_ban" value=" Save " tabindex="6" /></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   174
			</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   175
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   176
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   177
	<div class="clearer"></div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   178
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   179
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   180
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   181
	require PUN_ROOT.'footer.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   182
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   183
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   184
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   185
// Add/edit a ban (stage 2)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   186
else if (isset($_POST['add_edit_ban']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   187
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   188
	confirm_referrer('admin_bans.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   189
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   190
	$ban_user = trim($_POST['ban_user']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   191
	$ban_ip = trim($_POST['ban_ip']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   192
	$ban_email = strtolower(trim($_POST['ban_email']));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   193
	$ban_message = trim($_POST['ban_message']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   194
	$ban_expire = trim($_POST['ban_expire']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   195
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   196
	if ($ban_user == '' && $ban_ip == '' && $ban_email == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   197
		message('You must enter either a username, an IP address or an e-mail address (at least).');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   198
	else if (strtolower($ban_user) == 'guest')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   199
		message('The guest user cannot be banned.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   200
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   201
	// Validate IP/IP range (it's overkill, I know)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   202
	if ($ban_ip != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   203
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   204
		$ban_ip = preg_replace('/[\s]{2,}/', ' ', $ban_ip);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   205
		$addresses = explode(' ', $ban_ip);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   206
		$addresses = array_map('trim', $addresses);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   207
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   208
		for ($i = 0; $i < count($addresses); ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   209
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   210
			$octets = explode('.', $addresses[$i]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   211
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   212
			for ($c = 0; $c < count($octets); ++$c)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   213
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   214
				$octets[$c] = (strlen($octets[$c]) > 1) ? ltrim($octets[$c], "0") : $octets[$c];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   215
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   216
				if ($c > 3 || preg_match('/[^0-9]/', $octets[$c]) || intval($octets[$c]) > 255)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   217
					message('You entered an invalid IP/IP-range.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   218
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   219
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   220
			$cur_address = implode('.', $octets);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   221
			$addresses[$i] = $cur_address;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   222
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   223
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   224
		$ban_ip = implode(' ', $addresses);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   225
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   226
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   227
	require PUN_ROOT.'include/email.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   228
	if ($ban_email != '' && !is_valid_email($ban_email))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   229
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   230
		if (!preg_match('/^[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/', $ban_email))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   231
			message('The e-mail address (e.g. user@domain.com) or partial e-mail address domain (e.g. domain.com) you entered is invalid.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   232
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   233
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   234
	if ($ban_expire != '' && $ban_expire != 'Never')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   235
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   236
		$ban_expire = strtotime($ban_expire);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   237
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   238
		if ($ban_expire == -1 || $ban_expire <= time())
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   239
			message('You entered an invalid expire date. The format should be YYYY-MM-DD and the date must be at least one day in the future.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   240
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   241
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   242
		$ban_expire = 'NULL';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   243
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   244
	$ban_user = ($ban_user != '') ? '\''.$pun_db->escape($ban_user).'\'' : 'NULL';
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   245
	$ban_ip = ($ban_ip != '') ? '\''.$pun_db->escape($ban_ip).'\'' : 'NULL';
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   246
	$ban_email = ($ban_email != '') ? '\''.$pun_db->escape($ban_email).'\'' : 'NULL';
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   247
	$ban_message = ($ban_message != '') ? '\''.$pun_db->escape($ban_message).'\'' : 'NULL';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   248
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   249
	if ($_POST['mode'] == 'add')
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   250
		$pun_db->query('INSERT INTO '.$pun_db->prefix.'bans (username, ip, email, message, expire) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.')') or error('Unable to add ban', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   251
	else
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   252
		$pun_db->query('UPDATE '.$pun_db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($_POST['ban_id'])) or error('Unable to update ban', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   253
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   254
	// Regenerate the bans cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   255
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   256
	generate_bans_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   257
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   258
	pun_redirect('admin_bans.php', 'Ban '.(($_POST['mode'] == 'edit') ? 'edited' : 'added').'. Redirecting &hellip;');
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   259
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   260
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   261
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   262
// Remove a ban
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   263
else if (isset($_GET['del_ban']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   264
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   265
	confirm_referrer('admin_bans.php');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   266
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   267
	$ban_id = intval($_GET['del_ban']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   268
	if ($ban_id < 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   269
		message($lang_common['Bad request']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   270
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   271
	$pun_db->query('DELETE FROM '.$pun_db->prefix.'bans WHERE id='.$ban_id) or error('Unable to delete ban', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   272
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   273
	// Regenerate the bans cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   274
	require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   275
	generate_bans_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   276
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   277
	pun_redirect('admin_bans.php', 'Ban removed. Redirecting &hellip;');
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   278
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   279
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   280
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   281
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   282
$focus_element = array('bans', 'new_ban_user');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   283
require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   284
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   285
generate_admin_menu('bans');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   286
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   287
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   288
	<div class="blockform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   289
		<h2><span>New ban</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   290
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   291
			<form id="bans" method="post" action="admin_bans.php?action=more">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   292
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   293
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   294
						<legend>Add ban</legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   295
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   296
							<table class="aligntop" cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   297
								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   298
									<th scope="row">Username<div><input type="submit" name="add_ban" value=" Add " tabindex="2" /></div></th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   299
									<td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   300
										<input type="text" name="new_ban_user" size="25" maxlength="25" tabindex="1" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   301
										<span>The username to ban (case insensitive). The next page will let you enter a custom IP and e-mail. If you just want to ban a specific IP/IP-range or e-mail just leave it blank.</span>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   302
									</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   303
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   304
							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   305
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   306
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   307
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   308
			</form>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   309
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   310
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   311
		<h2 class="block2"><span>Existing bans</span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   312
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   313
			<div class="fakeform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   314
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   315
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   316
$result = $pun_db->query('SELECT id, username, ip, email, message, expire FROM '.$pun_db->prefix.'bans ORDER BY id') or error('Unable to fetch ban list', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   317
if ($pun_db->num_rows($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   318
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   319
	while ($cur_ban = $pun_db->fetch_assoc($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   320
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   321
		$expire = format_time($cur_ban['expire'], true);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   322
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   323
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   324
				<div class="inform">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   325
					<fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   326
						<legend>Ban expires: <?php echo $expire ?></legend>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   327
						<div class="infldset">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   328
							<table cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   329
<?php if ($cur_ban['username'] != ''): ?>								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   330
									<th>Username</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   331
									<td><?php echo pun_htmlspecialchars($cur_ban['username']) ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   332
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   333
<?php endif; ?><?php if ($cur_ban['email'] != ''): ?>								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   334
									<th>E-mail</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   335
									<td><?php echo $cur_ban['email'] ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   336
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   337
<?php endif; ?><?php if ($cur_ban['ip'] != ''): ?>								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   338
									<th>IP/IP-ranges</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   339
									<td><?php echo $cur_ban['ip'] ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   340
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   341
<?php endif; ?><?php if ($cur_ban['message'] != ''): ?>								<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   342
									<th>Reason</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   343
									<td><?php echo pun_htmlspecialchars($cur_ban['message']) ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   344
								</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   345
<?php endif; ?>							</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   346
							<p class="linkactions"><a href="admin_bans.php?edit_ban=<?php echo $cur_ban['id'] ?>">Edit</a> - <a href="admin_bans.php?del_ban=<?php echo $cur_ban['id'] ?>">Remove</a></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   347
						</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   348
					</fieldset>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   349
				</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   350
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   351
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   352
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   353
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   354
else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   355
	echo "\t\t\t\t".'<p>No bans in list.</p>'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   356
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   357
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   358
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   359
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   360
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   361
	<div class="clearer"></div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   362
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   363
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   364
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   365
require PUN_ROOT.'footer.php';