diff --git a/app/models/post.rb b/app/models/post.rb index 5276cbea2..6f92b08fe 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -158,8 +158,29 @@ class Post < ActiveRecord::Base @acting_user = pu end + def whitelisted_spam_hosts + + hosts = SiteSetting + .white_listed_spam_host_domains + .split(",") + .map{|h| h.strip} + .reject{|h| !h.include?(".")} + + hosts << GlobalSetting.hostname + + end + def total_hosts_usage hosts = linked_hosts.clone + whitelisted = whitelisted_spam_hosts + + hosts.reject! do |h| + whitelisted.any? do |w| + h.end_with?(w) + end + end + + return hosts if hosts.length == 0 TopicLink.where(domain: hosts.keys, user_id: acting_user.id) .group(:domain, :post_id) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9be95d195..84e9d9cd1 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -774,6 +774,8 @@ en: privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here." newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_posts` posts before being considered spam." + + white_listed_spam_host_domains: "A comma delimited list of domains excluded from spam host testing, new users will be able to create an unrestricted count of posts with links to this domain" staff_like_weight: "Extra weighting factor given to likes when performed by staff." reply_by_email_enabled: "Enable replying to topics via email" diff --git a/config/site_settings.yml b/config/site_settings.yml index 24101afcc..e33b80574 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -333,6 +333,7 @@ spam: notify_mods_when_user_blocked: false flag_sockpuppets: true newuser_spam_host_threshold: 3 + white_listed_spam_host_domains: "" rate_limits: unique_posts_mins: diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index a329bf6b0..9f011f4da 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -795,4 +795,24 @@ describe Post do end end + + describe "has_host_spam" do + it "correctly detects host spam" do + post = Fabricate(:post, raw: "hello from my site http://www.somesite.com + http://#{GlobalSetting.hostname} ") + + post.total_hosts_usage.should == {"www.somesite.com" => 1} + post.acting_user.trust_level = 0 + + post.has_host_spam?.should == false + + SiteSetting.stubs(:newuser_spam_host_threshold).returns(1) + + post.has_host_spam?.should == true + + SiteSetting.stubs(:white_listed_spam_host_domains).returns("bla.com,boo.com , somesite.com ") + post.has_host_spam?.should == false + end + end + end