bpalmen-httpbl 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/httpbl.rb +7 -13
  2. metadata +1 -1
@@ -8,12 +8,9 @@ class HttpBL
8
8
  @options = {:blocked_search_engines => [],
9
9
  :age_threshold => 10,
10
10
  :threat_level_threshold => 2,
11
- # 8..128 aren't used as of 3/2009, but might be used in the future
12
- :deny_types => [1, 2, 4, 8, 16, 32, 64, 128],
13
- # DONT set this to 0
11
+ :deny_types => [1, 2, 4, 8, 16, 32, 64, 128], # 8..128 aren't used as of 3/2009, but might be used in the future
14
12
  :dns_timeout => 0.5,
15
- :memcached_server => nil,
16
- :memcached_options => {}
13
+ :memcached_server => nil
17
14
  }.merge(options)
18
15
  raise "Missing :api_key for Http:BL middleware" unless @options[:api_key]
19
16
  if @options[:memcached_server]
@@ -45,7 +42,7 @@ class HttpBL
45
42
  cache = @cache.clone if @cache
46
43
  unless response = cache.get("httpbl_#{ip}")
47
44
  response = resolve(ip)
48
- cache.set("httpbl_#{ip}", response, 1.hour)
45
+ cache.set("httpbl_#{ip}", (response || "0.0.0.0"), 1.hour)
49
46
  end
50
47
  return response
51
48
  end
@@ -63,14 +60,11 @@ class HttpBL
63
60
  response = response.split('.').collect!(&:to_i)
64
61
  if response[0] == 127
65
62
  if response[3] == 0
66
- @blocked = true if @options[:blocked_search_engines].include? response[2]
63
+ @blocked = @options[:blocked_search_engines].include?(response[2])
67
64
  else
68
- @age = true if response[1] < @options[:age_threshold]
69
- @threat = true if response[2] > @options[:threat_level_threshold]
70
- @options[:deny_types].each do |key|
71
- @deny = true if response[3] & key == key
72
- end
73
- @blocked = true if @deny and @threat and @age
65
+ @blocked = @options[:deny_types].collect{|key| response[3] & key == key }.any?
66
+ @blocked = @blocked and response[2] > @options[:threat_level_threshold]
67
+ @blocked = @blocked and response[1] < @options[:age_threshold]
74
68
  end
75
69
  end
76
70
  return @blocked
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bpalmen-httpbl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Palmen