]> git.openstreetmap.org Git - rails.git/blob - script/update-spam-blocks
Update Potlatch 2 to r25217 build
[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 > 2
16     acl = Acl.find(:first, :conditions => {
17       :address => address,
18       :netmask => "255.255.255.255"
19     })
20
21     unless acl
22       Acl.create(
23         :address => address,
24         :netmask => "255.255.255.255",
25         :k => "no_account_creation",
26         :v => "auto_spam_block"
27       )
28
29       puts "Blocked #{address}"
30     end
31   end
32 end
33
34 acls = Acl.find(:all, :conditions => {
35   :netmask => "255.255.255.255",
36   :k => "no_account_creation",
37   :v => "auto_spam_block"
38 })
39
40 acls.each do |acl|
41   unless addresses[acl.address]
42     acl.delete
43
44     puts "Unblocked #{acl.address}"
45   end
46 end
47
48 exit 0