Block any address with more than one suspended user
[rails.git] / script / update-spam-blocks
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + '/../config/environment'
4 require 'generator'
5
6 addresses = User.count(
7   :conditions => {
8     :status => ["suspended", "deleted"],
9     :creation_time => Time.now - 28.days .. Time.now
10   },
11   :group => :creation_ip
12 )
13
14 addresses.each do |address,count|
15   if count > 1
16     acl = Acl.find(:first, :conditions => {
17       :address => address,
18     })
19
20     unless acl
21       Acl.create(
22         :address => address,
23         :netmask => "255.255.255.255",
24         :k => "no_account_creation",
25         :v => "auto_spam_block"
26       )
27
28       puts "Blocked #{address}"
29     end
30   end
31 end
32
33 acls = Acl.find(:all, :conditions => {
34   :k => "no_account_creation",
35   :v => "auto_spam_block"
36 })
37
38 acls.each do |acl|
39   unless addresses[acl.address]
40     acl.delete
41
42     puts "Unblocked #{acl.address}"
43   end
44 end
45
46 exit 0