Class: ProjectHoneypot::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/project_honeypot/url.rb

Constant Summary collapse

SEARCH_ENGINES =
%w(
  Undocumented
  AltaVista
  Ask
  Baidu
  Excite
  Google
  Looksmart
  Lycos
  MSN
  Yahoo
  Cuil
  InfoSeek
  Miscellaneous
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_address, honeypot_response) ⇒ Url

Returns a new instance of Url.



20
21
22
23
24
# File 'lib/project_honeypot/url.rb', line 20

def initialize(ip_address, honeypot_response)
  @ip_address = ip_address
  @safe = honeypot_response.nil?
  process_score(honeypot_response)
end

Instance Attribute Details

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



19
20
21
# File 'lib/project_honeypot/url.rb', line 19

def ip_address
  @ip_address
end

#last_activityObject (readonly)

Returns the value of attribute last_activity.



19
20
21
# File 'lib/project_honeypot/url.rb', line 19

def last_activity
  @last_activity
end

#offensesObject (readonly)

Returns the value of attribute offenses.



19
20
21
# File 'lib/project_honeypot/url.rb', line 19

def offenses
  @offenses
end

#scoreObject (readonly)

Returns the value of attribute score.



19
20
21
# File 'lib/project_honeypot/url.rb', line 19

def score
  @score
end

#search_engineObject (readonly)

Returns the value of attribute search_engine.



19
20
21
# File 'lib/project_honeypot/url.rb', line 19

def search_engine
  @search_engine
end

Instance Method Details

#comment_spammer?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/project_honeypot/url.rb', line 49

def comment_spammer?
  @offenses.include?(:comment_spammer)
end

#harvester?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/project_honeypot/url.rb', line 53

def harvester?
  @offenses.include?(:harvester)
end

#safe?(hash = {}) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/project_honeypot/url.rb', line 26

def safe?(hash = {})
  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
    )
end

#search_engine?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/project_honeypot/url.rb', line 45

def search_engine?
  @offenses.include?(:search_engine)
end

#suspicious?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/project_honeypot/url.rb', line 57

def suspicious?
  @offenses.include?(:suspicious)
end