From e0b488868a061e25f023faf8bac8b5a71ee85973 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Fri, 4 Jan 2013 17:22:00 +0100 Subject: [PATCH] Add custom offenses list to determine if safe or not --- lib/project_honeypot.rb | 2 +- lib/project_honeypot/url.rb | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/project_honeypot.rb b/lib/project_honeypot.rb index aa862a1..5d5ac47 100644 --- a/lib/project_honeypot.rb +++ b/lib/project_honeypot.rb @@ -6,7 +6,7 @@ require "project_honeypot/rack/forbidden" module ProjectHoneypot class << self - attr_accessor :api_key, :score, :last_activity + attr_accessor :api_key, :score, :last_activity, :offenses def api_key raise "ProjectHoneypot really needs its api_key set to work" unless @api_key diff --git a/lib/project_honeypot/url.rb b/lib/project_honeypot/url.rb index da16d96..396c71b 100644 --- a/lib/project_honeypot/url.rb +++ b/lib/project_honeypot/url.rb @@ -27,11 +27,18 @@ module ProjectHoneypot score = hash[:score] || ProjectHoneypot.score last_activity = hash[:last_activity] || ProjectHoneypot.last_activity + forbidden_offenses = hash[:offenses] || + ProjectHoneypot.offenses || + [:comment_spammer, :harvester, :suspicious] + + detected_offenses = forbidden_offenses & @offenses + @safe || + detected_offenses.length == 0 || !( last_activity.nil? && score.nil? || - !score.nil? && self.score > score || - !last_activity.nil? && self.last_activity > last_activity + !score.nil? && self.score >= score || + !last_activity.nil? && self.last_activity >= last_activity ) end