netik / mod_memcache_block

mod_memcache_block is an apache module that allows you to block access to your servers using a block list stored in memcache. It also offers distributed rate limiting based on HTTP response code.

This URL has Read+Write access

mod_memcache_block / setblocks.rb
100755 37 lines (29 sloc) 0.799 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/ruby
#
# construct the blocklist in memcache for testing
#
 
# for use with memcache-client 1.5.x
 
require 'rubygems'
require 'memcache'
 
@servers = [ 'localhost:11211' ]
 
@options = {
      :prefix_key => '',
      :hash => :default,
      :distribution => :modula
}
 
@cache = MemCache.new(@servers,@options)
#
# per robey: marshall must be set to false otherwise we'll feed marshalled data to apache
# and apache doesn't work with marshalled data.
#
@cache.set("mb:b:1",'127.0.0.0-127.0.0.99',0,true)
@cache.set("mb:b:2",'127.0.0.0/24',0,true)
@cache.set("mb:b:3",'127.0.0.1',0,true)
# ipv6
@cache.set("mb:b:4",'::1',0,true)
 
# whitelisting - takes precendence
# @cache.set("mb:w:4",'::1',0,true)
 
puts "blocks set:"
for x in 1..4
    puts "#{x} = " + @cache.get("mb:b:#{x}",true)
end