bpalmen-httpbl 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/httpbl.rb +7 -13
- metadata +1 -1
data/lib/httpbl.rb
CHANGED
@@ -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 =
|
63
|
+
@blocked = @options[:blocked_search_engines].include?(response[2])
|
67
64
|
else
|
68
|
-
@
|
69
|
-
@
|
70
|
-
@options[:
|
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
|