bpalmen-httpbl 0.1.3 → 0.1.4

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 (4) hide show
  1. data/CHANGELOG +1 -0
  2. data/lib/httpbl.rb +23 -3
  3. metadata +9 -9
  4. data/Changelog +0 -4
@@ -0,0 +1 @@
1
+ v0.1.3. First public test release, not ready for production
@@ -11,9 +11,15 @@ class HttpBL
11
11
  # 8..128 aren't used as of 3/2009, but might be used in the future
12
12
  :deny_types => [1, 2, 4, 8, 16, 32, 64, 128],
13
13
  # DONT set this to 0
14
- :dns_timeout => 0.5
14
+ :dns_timeout => 0.5,
15
+ :memcached_server => nil,
16
+ :memcached_options => {}
15
17
  }.merge(options)
16
18
  raise "Missing :api_key for Http:BL middleware" unless @options[:api_key]
19
+ if @options[:memcached_server]
20
+ require 'memcache'
21
+ @cache = MemCache.new(@options[:memcached_server], @options[:memcached_options])
22
+ end
17
23
  end
18
24
 
19
25
  def call(env)
@@ -22,7 +28,7 @@ class HttpBL
22
28
 
23
29
  def _call(env)
24
30
  request = Rack::Request.new(env)
25
- bl_status = resolve(request.ip)
31
+ bl_status = check(request.ip)
26
32
  if bl_status and blocked?(bl_status)
27
33
  [403, {"Content-Type" => "text/html"}, "<h1>403 Forbidden</h1> Request IP is listed as suspicious by <a href='http://projecthoneypot.org/ip_#{request.ip}'>Project Honeypot</a>"]
28
34
  else
@@ -31,10 +37,24 @@ class HttpBL
31
37
 
32
38
  end
33
39
 
40
+ def check(ip)
41
+ @cache ? cache_check(ip) : resolve(ip)
42
+ end
43
+
44
+ def cache_check(ip)
45
+ cache = @cache.clone if @cache
46
+ unless response = cache.get("httpbl_#{ip}")
47
+ response = resolve(ip)
48
+ cache.set("httpbl_#{ip}", response, 1.hour)
49
+ end
50
+ return response
51
+ end
52
+
34
53
  def resolve(ip)
35
54
  query = @options[:api_key] + '.' + ip.split('.').reverse.join('.') + '.dnsbl.httpbl.org'
36
55
  Timeout::timeout(@options[:dns_timeout]) do
37
- Resolv::DNS.new.getaddress(query).to_s rescue nil
56
+ Resolv::DNS.new.getaddress(query).to_s rescue false
57
+ puts "resolving"
38
58
  end
39
59
  rescue Timeout::Error, Errno::ECONNREFUSED
40
60
  end
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.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Palmen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-20 00:00:00 -07:00
12
+ date: 2009-05-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -18,11 +18,11 @@ dependencies:
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
- - - ~>
21
+ - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: "0.4"
23
+ version: 0.9.0
24
24
  version:
25
- description: HttpBL is a Rack/Rails middleware filter that blocks requests from suspicious IP addresses.
25
+ description: HttpBL is a Rack middleware filter that blocks requests from suspicious IP addresses.
26
26
  email: brandon.palmen@gmail.com
27
27
  executables: []
28
28
 
@@ -32,11 +32,11 @@ extra_rdoc_files:
32
32
  - README
33
33
  files:
34
34
  - README
35
- - Changelog
35
+ - CHANGELOG
36
36
  - LICENSE
37
37
  - lib/httpbl.rb
38
38
  has_rdoc: false
39
- homepage:
39
+ homepage: http://bpalmen.github.com/httpbl/
40
40
  post_install_message:
41
41
  rdoc_options: []
42
42
 
@@ -56,10 +56,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  version:
57
57
  requirements: []
58
58
 
59
- rubyforge_project:
59
+ rubyforge_project: httpbl
60
60
  rubygems_version: 1.2.0
61
61
  signing_key:
62
62
  specification_version: 2
63
- summary: HttpBL is a Rack/Rails middleware filter that blocks requests from suspicious IP addresses.
63
+ summary: HttpBL is a Rack middleware filter that blocks requests from suspicious IP addresses.
64
64
  test_files: []
65
65
 
data/Changelog DELETED
@@ -1,4 +0,0 @@
1
- -------------------------
2
- 2009-03-21 - 04:28 EST
3
-
4
- I think this might be ready to go live. Why am I up so late?