limit ip site creation

This commit is contained in:
Kyle Drake 2014-10-22 22:32:02 -07:00
parent 9140f3b929
commit 15c60cb6a8
2 changed files with 9 additions and 1 deletions

2
app.rb
View file

@ -550,7 +550,7 @@ post '/create' do
}.to_json
end
if !black_box_answered || !@site.valid?
if !black_box_answered || !@site.valid? || Site.ip_create_limit?(request.ip)
flash[:error] = 'There was an unknown error, please try again.'
return {result: 'error'}.to_json
end

View file

@ -95,6 +95,9 @@ class Site < Sequel::Model
SUGGESTIONS_VIEWS_MIN = 500
CHILD_SITES_MAX = 100
IP_CREATE_LIMIT = 50
TOTAL_IP_CREATE_LIMIT = 300
PLAN_FEATURES[:catbus] = PLAN_FEATURES[:fatcat].merge(
name: 'Cat Bus',
space: Filesize.from('10GB').to_i,
@ -206,6 +209,11 @@ class Site < Sequel::Model
return nil if site.nil? || site.is_banned || site.owner.is_banned
site
end
def ip_create_limit?(ip)
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
end
def self.banned_ip?(ip)