Sha256: fa8d47fc5904a904d001bbe804eca379a6c6a7b5738a27c6a7915b3459632cf2
Contents?: true
Size: 1.11 KB
Versions: 9
Compression:
Stored size: 1.11 KB
Contents
# Copyright (c) 2015 Sqreen. All Rights Reserved. # Please refer to our terms for more information: https://www.sqreen.com/terms.html require 'ipaddr' require 'sqreen/trie' require 'sqreen/prefix' module Sqreen module Actions module IpRangesIndex def add_prefix(prefix_str, data) @trie_v4 ||= Sqreen::Trie.new @trie_v6 ||= Sqreen::Trie.new(nil, nil, Socket::AF_INET6) prefix = Sqreen::Prefix.from_str(prefix_str, data) trie = prefix.family == Socket::AF_INET6 ? @trie_v6 : @trie_v4 trie.insert prefix end def matching_actions(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 def clear @trie_v4 = Sqreen::Trie.new @trie_v6 = Sqreen::Trie.new(nil, nil, Socket::AF_INET6) end end end end
Version data entries
9 entries across 9 versions & 1 rubygems