From 15c60cb6a8709dac34b69857f6674fa956e5a4c4 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Wed, 22 Oct 2014 22:32:02 -0700 Subject: [PATCH] limit ip site creation --- app.rb | 2 +- models/site.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app.rb b/app.rb index 7ce31199..9d88ad2f 100644 --- a/app.rb +++ b/app.rb @@ -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 diff --git a/models/site.rb b/models/site.rb index a9ad1a31..a20eca15 100644 --- a/models/site.rb +++ b/models/site.rb @@ -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)