mirror of
https://github.com/neocities/neocities.git
synced 2025-08-05 17:18:02 +02:00
mechanism to report spam ips to stopforumspam
This commit is contained in:
parent
7be37ce595
commit
bedc08cb58
10 changed files with 38 additions and 25 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue