From 1a3eeaf4cf06a259971969d322b2fc4f6bb5c0f9 Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Fri, 4 Jan 2013 17:20:05 +0100 Subject: [PATCH] Add search engines support --- lib/project_honeypot/url.rb | 39 +++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/project_honeypot/url.rb b/lib/project_honeypot/url.rb index ce45d34..da16d96 100644 --- a/lib/project_honeypot/url.rb +++ b/lib/project_honeypot/url.rb @@ -1,6 +1,22 @@ module ProjectHoneypot class Url - attr_reader :ip_address, :last_activity, :score, :offenses + SEARCH_ENGINES = %w( + Undocumented + AltaVista + Ask + Baidu + Excite + Google + Looksmart + Lycos + MSN + Yahoo + Cuil + InfoSeek + Miscellaneous + ) + + attr_reader :ip_address, :last_activity, :score, :offenses, :search_engine def initialize(ip_address, honeypot_response) @ip_address = ip_address @safe = honeypot_response.nil? @@ -19,6 +35,10 @@ module ProjectHoneypot ) end + def search_engine? + @offenses.include?(:search_engine) + end + def comment_spammer? @offenses.include?(:comment_spammer) end @@ -40,9 +60,20 @@ module ProjectHoneypot @offenses = [] else hp_array = honeypot_response.split(".") - @last_activity = hp_array[1].to_i - @score = hp_array[2].to_i - @offenses = set_offenses(hp_array[3]) + + if hp_array[3].to_i == 0 + # search engine + @last_activity = nil + @score = 0 + @offenses = [:search_engine] + @search_engine = (hp_array[2].to_i < SEARCH_ENGINES.length ? + SEARCH_ENGINES[hp_array[2].to_i] : + SEARCH_ENGINES[0]) + else + @last_activity = hp_array[1].to_i + @score = hp_array[2].to_i + @offenses = set_offenses(hp_array[3]) + end end end