diff --git a/html/inc/boinc_db.inc b/html/inc/boinc_db.inc index fbea97890e..2b4abb1dca 100644 --- a/html/inc/boinc_db.inc +++ b/html/inc/boinc_db.inc @@ -387,7 +387,7 @@ class BoincProfile { $db = BoincDb::get(); return $db->insert('profile', $clause); } - static function enum($clause, $clause2=null) { + static function enum($clause=null, $clause2=null) { $db = BoincDb::get(); return $db->enum('profile', 'BoincProfile', $clause, $clause2); } diff --git a/html/ops/delete_spammers.php b/html/ops/delete_spammers.php new file mode 100755 index 0000000000..8c4406e75d --- /dev/null +++ b/html/ops/delete_spammers.php @@ -0,0 +1,100 @@ +#!/usr/bin/env php +. + +// script to delete spammer accounts and profiles. +// +// delete_spammers.php --list filename +// "filename" contains a list of user IDs, one per line. +// +// delete_spammers.php --auto +// delete accounts that +// - have no hosts +// - have no message-board posts +// - have a profile containing a link. +// NOTE: use this with caution. See delete_auto() below. +// Run it in test mode first. + +require_once("../inc/db.inc"); +db_init(); + +function del($id) { + echo "deleting user $id\n"; + $q = "delete from profile where userid=$id"; + mysql_query($q); + $q = "delete from user where id=$id"; + mysql_query($q); +} + +function delete_list($fname) { + $f = fopen($fname, "r"); + if (!$f) die("no such file $fname\n"); + while ($s = fgets($f)) { + $s = trim($s); + if (!is_numeric($s)) die("bad ID $s\n"); + del($s); + } +} + +function has_link($x) { + if (strstr($x, "[url")) return true; + if (strstr($x, "http://")) return true; + if (strstr($x, "https://")) return true; + return false; +} + +function delete_auto() { + $profiles = BoincProfile::enum(""); + foreach ($profiles as $p) { + if (has_link($p->response1) || has_link($p->response2)) { + $user = BoincUser::lookup_id($p->userid); + if (!$user) { + echo "profile has missing user: %p->userid\n"; + continue; + } + + // uncomment the following to delete only recent accounts + // + //if ($user->create_time < time() - 60*86400) continue; + + $n = BoincHost::count("userid=$p->userid"); + if ($n) continue; + $n = BoincPost::count("user=$p->userid"); + if ($n) continue; + + // By default, show profile but don't delete anything + // Change 0 to 1 if you want to actually delete + // + if (0) { + del($user->id); + } else { + echo "------------\n$p->userid\n$p->response1\n$p->response2\n"; + } + } + } +} + +for ($i=1; $i<$argc; $i++) { + if ($argv[$i] == "--list") { + delete_list($argv[++$i]); + } else if ($argv[$i] == "--auto") { + delete_auto(); + } +} + +?> diff --git a/html/ops/index.php b/html/ops/index.php index 7528ba8d05..73d10653b5 100644 --- a/html/ops/index.php +++ b/html/ops/index.php @@ -33,24 +33,33 @@ admin_page_head($title); echo "