Advertisement
jvvg

Spam Reporting Script

Apr 26th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.91 KB | None | 0 0
  1. <?php
  2. define('PUN_ROOT', dirname(__FILE__) . '/');
  3. define('PUN_DEBUG', 1);
  4. include PUN_ROOT . 'include/common.php';
  5. header('Content-type: application/xml');
  6. $result = $db->query('SELECT COUNT(id) FROM ' . $db->prefix . 'users') or error('Failed to get user count', __FILE__, __LINE__, $db->error());
  7. list($count) = $db->fetch_row($result);
  8. if ($count > 22) {
  9.     $limit = 10;
  10. } else if ($count > 12) {
  11.     $limit = $count - 12;
  12. } else {
  13.     $limit = 0;
  14. }
  15. echo '<?xml version="1.0" ?>' . "\n" . '<recordset>';
  16. $result = $db->query('SELECT u.id,u.username,u.email,u.registration_ip,u.registered,u.signature,u.url,u.last_visit,u.num_posts,p.posted AS post_time,p.message AS post_msg FROM ' . $db->prefix . 'users AS u LEFT JOIN ' . $db->prefix . 'posts AS p ON p.poster=u.id WHERE u.id>2 ORDER BY u.registered ASC,p.posted DESC LIMIT ' . $limit) or error('Failed to get users', __FILE__, __LINE__, $db->error());
  17. while ($user = $db->fetch_assoc($result)) {
  18.     $id = $user['id'];
  19.     $evidence = 'FST HONEYPOT CAPTURE REPORT' . "\n";
  20.     $evidence .= 'Reason: Registered on a honeypot forum' . "\n";
  21.     $evidence .= 'Registered: ' . gmdate('d M Y H:i:s', $user['registered']) . ' (UTC)' . "\n";
  22.     $evidence .= 'Last visit: ' . gmdate('d M Y H:i:s', $user['last_visit']) . ' (UTC)' . "\n";
  23.     $evidence .= 'Posts: ' . $user['num_posts'] . "\n";
  24.     if ($user['url'] != '') {
  25.         $evidence .= 'Profile website: ' . $user['url'] . "\n";
  26.     }
  27.     if ($user['signature'] != '') {
  28.         $evidence .= 'Signature: ' . "\n" . $user['signature'] . "\n\n";
  29.     }
  30.     if ($user['post_time'] != '') {
  31.         $evidence .= 'Most recent post: ' . date('d M Y H:i:s', $user['post_time']) . ' (UTC), with content as follows (first 400 chars):' . "\n";
  32.         $evidence .= substr($user['post_msg'], 0, 400);
  33.     }
  34.     echo "\t" . '<user><username>' . htmlspecialchars($user['username']) . '</username><email>' . htmlspecialchars($user['email']) . '</email><ip>' . htmlspecialchars($user['registration_ip']) . '</ip><evidence>' . htmlspecialchars($evidence) . '</evidence></user>' . "\n";
  35.    
  36.     //delete the user and guest all of the posts (keep them to attract more spammers)
  37.     $db->query('UPDATE '.$db->prefix.'posts SET poster_id=1 WHERE poster_id='.$id) or error('Unable to update posts', __FILE__, __LINE__, $db->error());
  38.     $db->query('DELETE FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to delete user', __FILE__, __LINE__, $db->error());
  39. }
  40. echo '</recordset>';
  41.  
  42. if (file_exists(PUN_ROOT . 'cache/cache_users_info.php')) {
  43.     unlink(PUN_ROOT . 'cache/cache_users_info.php');
  44. }
  45.  
  46. //prune old stuff
  47. $prune_date = time() - (7 * 86400);
  48. $result = $db->query('SELECT id FROM '.$db->prefix.'forums') or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
  49. $num_forums = $db->num_rows($result);
  50.  
  51. for ($i = 0; $i < $num_forums; ++$i) {
  52.     $fid = $db->result($result, $i);
  53.  
  54.     prune($fid, $prune_sticky, $prune_date);
  55.     update_forum($fid);
  56. }
  57.  
  58. // Locate any "orphaned redirect topics" and delete them
  59. $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
  60. $num_orphans = $db->num_rows($result);
  61.  
  62. if ($num_orphans)
  63. {
  64.     for ($i = 0; $i < $num_orphans; ++$i)
  65.         $orphans[] = $db->result($result, $i);
  66.  
  67.     $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
  68. }
  69.  
  70. //clear search index
  71. $db->query('TRUNCATE TABLE ' . $db->prefix . 'search_cache') or error('Failed to truncate searches', __FILE__, __LINE__, $db->error());
  72. $db->query('TRUNCATE TABLE ' . $db->prefix . 'search_matches') or error('Failed to truncate searches', __FILE__, __LINE__, $db->error());
  73. $db->query('TRUNCATE TABLE ' . $db->prefix . 'search_words') or error('Failed to truncate searches', __FILE__, __LINE__, $db->error());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement