My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
BanSearchPatch  
ban search patch for FluxBB
Updated Nov 10, 2009 by guillaum...@gmail.com

FluxBB ยป ban search patch


Ban search patch

This patch replace the ban list by a search form.

Patches

If you're running a non-modified installation of FluxBB (or, at least, if admin_bans.php was not modified), you can use one of those patches:

Patch can be applied by running:

patch -p0 < 01-better-bans.patch

while in the same directory than the admin_bans.php file you want to patch.

Manual modification

If you're running a modified installation or if you just hate the patch command, here's some instruction on how applying the change manually to your FluxBB install.

FluxBB 1.2

Open the admin_bans.php file

Find this block of code

// Remove a ban
else if (isset($_GET['del_ban']))
{
        ...
        redirect('admin_bans.php', 'Ban removed. Redirecting &hellip;');
}

Add this block just after:

// find a ban
else if (isset($_POST['find_ban']))
{
	$form = $_POST['form'];
	$form['username'] = $_POST['username'];

	// trim() all elements in $form
	$form = array_map('trim', $form);
	$conditions = array();

	$expire_after = trim($_POST['expire_after']);
	$expire_before = trim($_POST['expire_before']);
	$order_by = $_POST['order_by'];
	$direction = $_POST['direction'];

	// Try to convert date/time to timestamps
	if ($expire_after != '')
		$expire_after = strtotime($expire_after);
	if ($expire_before != '')
		$expire_before = strtotime($expire_before);

	if ($expire_after == -1 || $expire_before == -1)
		message('You entered an invalid date/time.');

	if ($expire_after != '')
		$conditions[] = 'expire>'.$expire_after;
	if ($expire_before != '')
		$conditions[] = 'expire<'.$expire_before;

	$like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
	while (list($key, $input) = @each($form))
	{
		if ($input != '' && in_array($key, array('username', 'email', 'ip', 'message')))
			$conditions[] = $db->escape($key).' '.$like_command.' \''.$db->escape(str_replace('*', '%', $input)).'\'';
	}

	if (empty($conditions))
		message('You didn\'t enter any search terms.');

	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
	require PUN_ROOT.'header.php';
?>
<div class="linkst">
	<div class="inbox">
		<div><a href="javascript:history.go(-1)">Go back</a></div>
	</div>
</div>

<div id="bans1" class="blocktable">
	<h2><span>Users</span></h2>
	<div class="box">
		<div class="inbox">
			<table cellspacing="0">
			<thead>
				<tr>
					<th class="tcl" scope="col">Username</th>
					<th class="tc2" scope="col">E-mail</th>
					<th class="tc3" scope="col">IP/IP-ranges</th>
					<th class="tc4" scope="col">Reason</th>
					<th class="tc5" scope="col">Expire</th>
					<th class="tcr" scope="col">Action</th>
				</tr>
			</thead>
			<tbody>
<?php

	$result = $db->query('SELECT id, username, email, ip, message, expire FROM '.$db->prefix.'bans WHERE '.implode(' AND ', $conditions).' ORDER BY '.$db->escape($order_by).' '.$db->escape($direction)) or error('Unable to fetch ban info', __FILE__, __LINE__, $db->error());
	if ($db->num_rows($result))
	{
		while ($ban_data = $db->fetch_assoc($result))
		{
			$actions = '<a href="admin_bans.php?edit_ban=' . $ban_data['id'] . '">Edit</a> - <a href="admin_bans.php?del_ban=' .  $ban_data['id'] . '">Remove</a>';
			$expire = format_time($ban_data['expire'], true);

?>
				<tr>
					<td class="tcl"><?php echo pun_htmlspecialchars($ban_data['username']) ?></td>
					<td class="tc2"><?php echo $ban_data['email']; ?></td>
					<td class="tc3"><?php echo $ban_data['ip']; ?></td>
					<td class="tc4"><?php echo pun_htmlspecialchars($ban_data['message']) ?></td>
					<td class="tc5"><?php echo $expire ?></td>
					<td class="tcr"><?php echo $actions ?></td>
				</tr>
<?php

		}
	}
	else
		echo "\t\t\t\t".'<tr><td class="tcl" colspan="6">No match.</td></tr>'."\n";

?>
			</tbody>
			</table>
		</div>
	</div>
</div>

<div class="linksb">
	<div class="inbox">
		<div><a href="javascript:history.go(-1)">Go back</a></div>
	</div>
</div>
<?php
	require PUN_ROOT.'footer.php';
	die();
}

Next, find this block:

		<h2 class="block2"><span>Existing bans</span></h2>
		<div class="box">
			<div class="fakeform">
                        ...
			</div>
		</div>

and replace it by this one:

		<h2 class="block2"><span>Ban search</span></h2>
		<div class="box">
			<form id="find_ban" method="post" action="admin_bans2.php?action=find_ban">
				<p class="submittop"><input type="submit" name="find_ban" value="Submit search" tabindex="1" /></p>
				<div class="inform">
					<fieldset>
						<legend>Enter search criteria</legend>
						<div class="infldset">
							<p>Search for bans in the database. You can enter one or more terms to search for. Wildcards in the form of asterisks (*) are accepted.</p>
							<table  class="aligntop" cellspacing="0">
								<tr>
									<th scope="row">Username</th>
									<td><input type="text" name="username" size="25" maxlength="25" tabindex="2" /></td>
								</tr>
								<tr>
									<th scope="row">E-mail</th>
									<td><input type="text" name="form[email]" size="25" maxlength="25" tabindex="3" /></td>
								</tr>
								<tr>
									<th scope="row">IP/IP-ranges</th>
									<td><input type="text" name="form[ip]" size="25" maxlength="25" tabindex="4" /></td>
								</tr>
								<tr>
									<th scope="row">Reason</th>
									<td><input type="text" name="form[message]" size="25" maxlength="25" tabindex="5" /></td>
								</tr>
								<tr>
									<th scope="row">Expire after</th>
									<td><input type="text" name="expire_after" size="24" maxlength="19" tabindex="6" />
									<span>(yyyy-mm-dd hh:mm:ss)</span></td>
								</tr>
								<tr>
									<th scope="row">Expire before</th>
									<td><input type="text" name="expire_before" size="24" maxlength="19" tabindex="7" />
									<span>(yyyy-mm-dd hh:mm:ss)</span></td>
								</tr>
								<tr>
									<th scope="row">Order by</th>
									<td>
										<select name="order_by" tabindex="8">
											<option value="username" selected="selected">username</option>
											<option value="email">e-mail</option>
											<option value="ip">ip</option>
											<option value="expire">expire</option>
										</select>&nbsp;&nbsp;&nbsp;<select name="direction" tabindex="9">
											<option value="ASC" selected="selected">ascending</option>
											<option value="DESC">descending</option>
										</select>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</div>
				<p class="submitend"><input type="submit" name="find_ban" value="Submit search" tabindex="10" /></p>
			</form>
		</div>

You're done :)

FluxBB 1.4

Open the admin_bans.php file

Find this block of code

// Remove a ban
else if (isset($_GET['del_ban']))
{
        ...
        redirect('admin_bans.php', 'Ban removed. Redirecting &hellip;');
}

Add this block just after:

// find a ban
else if (isset($_POST['find_ban']))
{
	$form = $_POST['form'];
	$form['username'] = $_POST['username'];

	// trim() all elements in $form
	$form = array_map('trim', $form);
	$conditions = array();

	$expire_after = trim($_POST['expire_after']);
	$expire_before = trim($_POST['expire_before']);
	$order_by = $_POST['order_by'];
	$direction = $_POST['direction'];

	// Try to convert date/time to timestamps
	if ($expire_after != '')
		$expire_after = strtotime($expire_after);
	if ($expire_before != '')
		$expire_before = strtotime($expire_before);

	if ($expire_after == -1 || $expire_before == -1)
		message('You entered an invalid date/time.');

	if ($expire_after != '')
		$conditions[] = 'expire>'.$expire_after;
	if ($expire_before != '')
		$conditions[] = 'expire<'.$expire_before;

	$like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE';
	while (list($key, $input) = @each($form))
	{
		if ($input != '' && in_array($key, array('username', 'email', 'ip', 'message')))
			$conditions[] = 'b.'.$db->escape($key).' '.$like_command.' \''.$db->escape(str_replace('*', '%', $input)).'\'';
	}

	if (empty($conditions))
		message('You didn\'t enter any search terms.');

	$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Bans';
	require PUN_ROOT.'header.php';
?>
<div class="linkst">
	<div class="inbox">
		<div><a href="javascript:history.go(-1)">Go back</a></div>
	</div>
</div>

<div id="bans1" class="blocktable">
	<h2><span>Users</span></h2>
	<div class="box">
		<div class="inbox">
			<table cellspacing="0">
			<thead>
				<tr>
					<th class="tcl" scope="col">Username</th>
					<th class="tc2" scope="col">E-mail</th>
					<th class="tc3" scope="col">IP/IP-ranges</th>
					<th class="tc4" scope="col">Reason</th>
					<th class="tc5" scope="col">Banned by</th>
					<th class="tc6" scope="col">Expire</th>
					<th class="tcr" scope="col">Action</th>
				</tr>
			</thead>
			<tbody>
<?php

	$result = $db->query('SELECT b.id, b.username, b.email, b.ip, b.message, b.expire, b.ban_creator, u.username AS ban_creator_username FROM '.$db->prefix.'bans AS b LEFT JOIN '.$db->prefix.'users AS u ON b.ban_creator=u.id WHERE '.implode(' AND ', $conditions).' ORDER BY '.$db->escape($order_by).' '.$db->escape($direction)) or error('Unable to fetch ban info', __FILE__, __LINE__, $db->error());
	if ($db->num_rows($result))
	{
		while ($ban_data = $db->fetch_assoc($result))
		{
			$actions = '<a href="admin_bans.php?edit_ban=' . $ban_data['id'] . '">Edit</a> - <a href="admin_bans.php?del_ban=' .  $ban_data['id'] . '">Remove</a>';
			$expire = format_time($ban_data['expire'], true);

?>
				<tr>
					<td class="tcl"><?php echo pun_htmlspecialchars($ban_data['username']) ?></td>
					<td class="tc2"><?php echo $ban_data['email']; ?></td>
					<td class="tc3"><?php echo $ban_data['ip']; ?></td>
					<td class="tc4"><?php echo pun_htmlspecialchars($ban_data['message']) ?></td>
					<td class="tc5"><a href="profile.php?id=<?php echo $ban_data['ban_creator'] ?>"><?php echo pun_htmlspecialchars($ban_data['ban_creator_username']) ?></a></td>
					<td class="tc6"><?php echo $expire ?></td>
					<td class="tcr"><?php echo $actions ?></td>
				</tr>
<?php

		}
	}
	else
		echo "\t\t\t\t".'<tr><td class="tcl" colspan="6">No match.</td></tr>'."\n";

?>
			</tbody>
			</table>
		</div>
	</div>
</div>

<div class="linksb">
	<div class="inbox">
		<div><a href="javascript:history.go(-1)">Go back</a></div>
	</div>
</div>
<?php
	require PUN_ROOT.'footer.php';
	die();
}

Next, find this block:

		<h2 class="block2"><span>Existing bans</span></h2>
		<div class="box">
			<div class="fakeform">
                        ...
			</div>
		</div>

and replace it by this one:

		<h2 class="block2"><span>Ban search</span></h2>
		<div class="box">
			<form id="find_ban" method="post" action="admin_bans.php?action=find_ban">
				<p class="submittop"><input type="submit" name="find_ban" value="Submit search" tabindex="1" /></p>
				<div class="inform">
					<fieldset>
						<legend>Enter search criteria</legend>
						<div class="infldset">
							<p>Search for bans in the database. You can enter one or more terms to search for. Wildcards in the form of asterisks (*) are accepted.</p>
							<table  class="aligntop" cellspacing="0">
								<tr>
									<th scope="row">Username</th>
									<td><input type="text" name="username" size="25" maxlength="25" tabindex="2" /></td>
								</tr>
								<tr>
									<th scope="row">E-mail</th>
									<td><input type="text" name="form[email]" size="25" maxlength="25" tabindex="3" /></td>
								</tr>
								<tr>
									<th scope="row">IP/IP-ranges</th>
									<td><input type="text" name="form[ip]" size="25" maxlength="25" tabindex="4" /></td>
								</tr>
								<tr>
									<th scope="row">Reason</th>
									<td><input type="text" name="form[message]" size="25" maxlength="25" tabindex="5" /></td>
								</tr>
								<tr>
									<th scope="row">Expire after</th>
									<td><input type="text" name="expire_after" size="24" maxlength="19" tabindex="6" />
									<span>(yyyy-mm-dd hh:mm:ss)</span></td>
								</tr>
								<tr>
									<th scope="row">Expire before</th>
									<td><input type="text" name="expire_before" size="24" maxlength="19" tabindex="7" />
									<span>(yyyy-mm-dd hh:mm:ss)</span></td>
								</tr>
								<tr>
									<th scope="row">Order by</th>
									<td>
										<select name="order_by" tabindex="8">
											<option value="username" selected="selected">username</option>
											<option value="email">e-mail</option>
											<option value="ip">ip</option>
											<option value="expire">expire</option>
										</select>&nbsp;&nbsp;&nbsp;<select name="direction" tabindex="9">
											<option value="ASC" selected="selected">ascending</option>
											<option value="DESC">descending</option>
										</select>
									</td>
								</tr>
							</table>
						</div>
					</fieldset>
				</div>
				<p class="submitend"><input type="submit" name="find_ban" value="Submit search" tabindex="10" /></p>
			</form>
		</div>

You're done :)


Sign in to add a comment
Powered by Google Project Hosting