Created
February 27, 2011 19:10
-
-
Save samt/846437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* @package Spammer Prunner for phpBB3 | |
* @license http://www.opensource.org/licenses/mit-license.php The MIT License | |
* @copyright Copyright (c) 2011 Sam Thompson <[email protected]> | |
*/ | |
set_time_limit(0); | |
define('IN_PHPBB', true); | |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; | |
$phpEx = substr(strrchr(__FILE__, '.'), 1); | |
include($phpbb_root_path . 'common.' . $phpEx); | |
include($phpbb_root_path . 'includes/functions_display.' . $phpEx); | |
if(!function_exists('user_delete')) | |
{ | |
include($phpbb_root_path . 'includes/functions_user.' . $phpEx); | |
} | |
// Start session management | |
$user->session_begin(); | |
$auth->acl($user->data); | |
$user->setup(); | |
// We've reached the edge of the map: here there be monsters. | |
if($user->data['user_type'] != USER_FOUNDER) | |
{ | |
exit; | |
} | |
// Select all the users who are inactive and have their timezone as Spammer | |
// Island Timezone | |
$sql = 'SELECT user_id, username, user_email, user_ip, user_posts | |
FROM ' . USERS_TABLE . ' | |
WHERE user_timezone = -12.00 | |
AND user_inactive_reason = ' . INACTIVE_REGISTER; | |
$result = $db->sql_query($sql); | |
$users = $db->sql_fetchrowset($result); | |
$db->sql_freeresult($result); | |
echo "<html><head>"; | |
echo "<title>Spam Bot Removal</title>"; | |
echo '<style type="text/css">'; | |
echo "table,th,td{border:1px solid black;}"; | |
echo "table{border-collapse:collapse;}"; | |
echo "td,th{padding: 5px;}"; | |
echo "th{color: #FFF}"; | |
echo ".h{background-color:#333}"; | |
echo ".e{background-color:#DDD}"; | |
echo ".o{background-color:#EEE}"; | |
echo "tr.e:hover, tr.o:hover{background-color:#FFF;}"; | |
echo "</style>"; | |
echo "</head><body>"; | |
if(!isset($_POST['confirm'])) | |
{ | |
echo "<h1>Spam Bot Removal Tool</h1>"; | |
echo "<p style='color: red; font-weight: bold;'>WARNING: The following users will be DELETED from your forum.</p>"; | |
echo '<table border="1">'; | |
echo "<tr class='h'>"; | |
echo "<th>User ID</th>"; | |
echo "<th>Username</th>"; | |
echo "<th>User Email</th>"; | |
echo "<th>User IP</th>"; | |
echo "</tr>"; | |
$i = 0; | |
foreach($users as $u) | |
{ | |
$i++; | |
echo ($i % 2) ? "<tr class='o'>" : "<tr class='e'>"; | |
echo "<td>{$u['user_id']}</td>"; | |
echo "<td>{$u['username']}</td>"; | |
echo "<td>{$u['user_email']}</td>"; | |
echo "<td>{$u['user_ip']}</td>"; | |
echo "</tr>"; | |
} | |
echo "</table>"; | |
echo '<br />'; | |
echo $i . ' Records Total<br />'; | |
echo '<form action="" method="post">'; | |
echo 'Stop Forum Spam API Key: <input type="text" name="sfsapi" /><br />'; | |
echo '<input type="submit" value="Hammer Time" name="submit" onclick="this.disabled=true" />'; | |
echo '<input type="hidden" value="1" name="confirm" />'; | |
echo '</form>'; | |
echo "<p style='color: red; font-weight: bold;'>Clicking the button above will DELETE and REPORT all of the users listed above from your forum. <br />Depending on the ammount of spammers to delete and report, this process can take a long time.</p>"; | |
} | |
else | |
{ | |
if(!sizeof($users)) | |
{ | |
echo "<p style='color: red; font-weight: bold;'>Error: No spammers were found.</p></body></html>"; | |
exit; | |
} | |
$sfs_key = request_var('sfsapi', ''); | |
if(empty($sfs_key)) | |
{ | |
echo "<p style='color: red; font-weight: bold;'>Error: An API key is required to report spammers.</p></body></html>"; | |
exit; | |
} | |
foreach($users as $u) | |
{ | |
// Build POST request context | |
$data = http_build_query(array( | |
'username' => $u['username'], | |
'ip_addr' => $u['user_ip'], | |
'email' => $u['user_email'], | |
'api_key' => $sfs_key, | |
)); | |
$context = stream_context_create(array( | |
'http' => array( | |
'method' => 'POST', | |
'header' => | |
"Accept-language: en\r\n". | |
"Content-type: application/x-www-form-urlencoded\r\n" . | |
"Content-Length: " . strlen($data) . "\r\n", | |
'content' => $data, | |
), | |
)); | |
// Send request | |
file_get_contents('http://www.stopforumspam.com/add.php', false, $context); | |
// Delete | |
user_delete('remove', $u['user_id']); | |
} | |
echo "<p style='color: green; font-weight: bold;'>Success: All spammers have been deleted and reported to Stop Forum Spam</p>"; | |
echo "<ul>"; | |
foreach($users as $u) | |
{ | |
echo "<li>{$u['username']}</li>"; | |
} | |
echo "</ul>"; | |
} | |
echo '<br /><br />Spammer Pruner by <a href="http://ichimonai.com">Sam Thompson</a></body></html>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment