mechanism to report spam ips to stopforumspam

This commit is contained in:
Kyle Drake 2017-01-11 17:16:40 -06:00
parent 7be37ce595
commit bedc08cb58
10 changed files with 38 additions and 25 deletions

View file

@ -296,19 +296,15 @@ class Site < Sequel::Model
end
def ip_create_limit?(ip)
hashed_ip = hash_ip ip
Site.where('created_at > ?', Date.today.to_time).where(ip: hashed_ip).count > IP_CREATE_LIMIT ||
Site.where(ip: hashed_ip).count > TOTAL_IP_CREATE_LIMIT
end
def hash_ip(ip)
SCrypt::Engine.hash_secret ip, $config['ip_hash_salt']
Site.where('created_at > ?', Date.today.to_time).where(ip: ip).count > IP_CREATE_LIMIT ||
Site.where(ip: ip).count > TOTAL_IP_CREATE_LIMIT
end
def banned_ip?(ip)
return false if ENV['RACK_ENV'] == 'production' && ip == '127.0.0.1'
return false if ip.blank?
return true if Site.where(is_banned: true).
where(ip: hash_ip(ip)).
where(Sequel.or(ip: ip, ip: hash_ip(ip))).
where(['updated_at > ?', Time.now-BANNED_TIME]).
first
@ -317,6 +313,10 @@ class Site < Sequel::Model
false
end
def hash_ip(ip)
SCrypt::Engine.hash_secret ip, $config['ip_hash_salt']
end
def ssl_sites
select(:id, :username, :domain, :ssl_key, :ssl_cert).
exclude(domain: nil).
@ -326,10 +326,6 @@ class Site < Sequel::Model
end
end
def ip=(ip)
super self.class.hash_ip(ip)
end
def is_following?(site)
followings_dataset.select(:follows__id).filter(site_id: site.id).first ? true : false
end