Class: Sqreen::Actions::IpRangesIndex
- Inherits:
-
ActionsIndex
- Object
- ActionsIndex
- Sqreen::Actions::IpRangesIndex
- Defined in:
- lib/sqreen/actions/ip_ranges_index.rb
Instance Method Summary collapse
- #actions_matching(client_ip) ⇒ Object
- #index(params, action) ⇒ Object
-
#initialize ⇒ IpRangesIndex
constructor
A new instance of IpRangesIndex.
Constructor Details
#initialize ⇒ IpRangesIndex
Returns a new instance of IpRangesIndex.
14 15 16 17 |
# File 'lib/sqreen/actions/ip_ranges_index.rb', line 14 def initialize @trie_v4 = Sqreen::Trie.new @trie_v6 = Sqreen::Trie.new(nil, nil, Socket::AF_INET6) end |
Instance Method Details
#actions_matching(client_ip) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sqreen/actions/ip_ranges_index.rb', line 27 def actions_matching(client_ip) parsed_ip = IPAddr.new(client_ip.gsub(/%[^%\/]+/, '')) trie = parsed_ip.family == Socket::AF_INET6 ? @trie_v6 : @trie_v4 return [] unless trie found = trie.search_matching(parsed_ip.to_i, parsed_ip.family) return [] unless found.size > 0 Sqreen.log.debug("Client ip #{client_ip} matches #{found.inspect}") found.map(&:data) end |
#index(params, action) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/sqreen/actions/ip_ranges_index.rb', line 19 def index(params, action) ranges = parse_ip_ranges params ranges.each do |r| add_prefix r, action end end |