diff options
author | Richard Jones <richard@mechanicalcat.net> | 2012-12-05 20:11:46 +1100 |
---|---|---|
committer | Richard Jones <richard@mechanicalcat.net> | 2012-12-05 20:11:46 +1100 |
commit | fdb45019aa70a69652670f6e4ade6e367955ce20 (patch) | |
tree | 066b4857c5f2c8efa2f49449bc8912eb49893221 | |
parent | 3ff73559450320e841f3e1e2786ab3fe79554a68 (diff) | |
download | decorator-fdb45019aa70a69652670f6e4ade6e367955ce20.tar.gz |
add spam removal admin command "rmspam" which takes an SQL LIKE expression for package names to match; without "confirm" on the command line you see info; if "confirm" is also added to the command line then packages are removed and user acccounts are disabled. Also displays the IP addresses for additional killage if possible.
-rw-r--r-- | admin.py | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -14,6 +14,48 @@ def set_password(store, name, pw): store.store_user(user['name'], pw.strip(), user['email'], None) print 'done' +def remove_spam(store, namepat, confirm=False): + '''Remove packages that match namepat (SQL wildcards). + + The packages will be removed. Additionally the user that created them will + have their password set to 'spammer'. + + Pass the additional command-line argument "confirm" to perform the + deletions and modifications. + + This will additionally display the IP address(es) of the spam submissions. + ''' + assert confirm in (False, 'confirm') + cursor = st.get_cursor() + cursor.execute(""" + select packages.name, submitted_date, submitted_by, submitted_from + from packages, journals + where packages.name LIKE %s + and packages.name = journals.name + and action = 'create' + """, (namepat,)) + + if not confirm: + print 'NOT taking any action; add "confirm" to the command line to act' + + users = set() + ips = set() + for name, date, by, ip in cursor.fetchall(): + ips.add(ip) + users.add(by) + print 'delete', name, 'submitted on', date + if confirm: + store.remove_package(name) + + print 'IP addresses of spammers to possibly block:' + for ip in ips: + print ' ', ip + + for user in users: + print 'disable user', user + if confirm: + cursor.execute("update users set password='spammer' where name=%s", + (user,)) def remove_package(store, name): ''' Remove a package from the database @@ -190,6 +232,8 @@ if __name__ == '__main__': set_password(*args) elif command == 'rmpackage': remove_package(*args) + elif command == 'rmspam': + remove_spam(*args) elif command == 'addclass': add_classifier(*args) print 'done' |