| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::ElasticSearch::Utilities::QueryString::IP; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Expand IP CIDR Notation to ES ranges |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
826
|
use v5.16; |
|
|
1
|
|
|
|
|
4
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
60
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '8.7'; # VERSION |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
528
|
use Net::CIDR::Lite; |
|
|
1
|
|
|
|
|
4298
|
|
|
|
1
|
|
|
|
|
33
|
|
|
10
|
1
|
|
|
1
|
|
8
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
8
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
64
|
use Moo; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
13
|
|
|
|
|
|
|
with 'App::ElasticSearch::Utilities::QueryString::Plugin'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
45
|
sub _build_priority { 25 } |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub handle_token { |
|
19
|
|
|
|
|
|
|
my ($self,$token) = @_; |
|
20
|
|
|
|
|
|
|
if( my ($term,$match) = split /\:/, $token, 2 ) { |
|
21
|
|
|
|
|
|
|
# These are not 100% accurate IP matchers, but they are fast |
|
22
|
|
|
|
|
|
|
if( $match =~ m|^\d{1,3}(?:\.\d{1,3}){1,3}(?:/\d+)$| |
|
23
|
|
|
|
|
|
|
or $match =~ m|^[0-9a-fA-F:]+(?:/\d+)$| |
|
24
|
|
|
|
|
|
|
) { |
|
25
|
|
|
|
|
|
|
my $cidr = Net::CIDR::Lite->new(); |
|
26
|
|
|
|
|
|
|
$cidr->add($match); |
|
27
|
|
|
|
|
|
|
my @range = split /-/, ($cidr->list_range)[0]; |
|
28
|
|
|
|
|
|
|
return { condition => { range => { $term => { gte => $range[0], lte => $range[1] } } } }; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
return; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
App::ElasticSearch::Utilities::QueryString::IP - Expand IP CIDR Notation to ES ranges |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 VERSION |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
version 8.7 |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 App::ElasticSearch::Utilities::QueryString::IP |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
If a field is an IP address uses CIDR Notation, it's expanded to a range query. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
src_ip:10.0/8 => src_ip:[10.0.0.0 TO 10.255.255.255] |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=for Pod::Coverage handle_token |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 AUTHOR |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Brad Lhotsky <brad@divisionbyzero.net> |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Brad Lhotsky. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This is free software, licensed under: |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
The (three-clause) BSD License |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |