line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
WGmeta::Validator - A place for all input validation functions |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=cut |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
package Wireguard::WGmeta::Validator; |
8
|
5
|
|
|
5
|
|
33
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
151
|
|
9
|
5
|
|
|
5
|
|
39
|
use warnings FATAL => 'all'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
171
|
|
10
|
5
|
|
|
5
|
|
25
|
use experimental 'signatures'; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
22
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
517
|
use Scalar::Util qw(looks_like_number); |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
270
|
|
13
|
|
|
|
|
|
|
|
14
|
5
|
|
|
5
|
|
29
|
use base 'Exporter'; |
|
5
|
|
|
|
|
41
|
|
|
5
|
|
|
|
|
609
|
|
15
|
|
|
|
|
|
|
our @EXPORT = qw(accept_any is_number looks_like_comma_sep_ips); |
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
34
|
use constant FALSE => 0; |
|
5
|
|
|
|
|
45
|
|
|
5
|
|
|
|
|
314
|
|
18
|
5
|
|
|
5
|
|
29
|
use constant TRUE => 1; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1647
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
25
|
|
|
25
|
0
|
34
|
sub accept_any($input) { |
|
25
|
|
|
|
|
46
|
|
|
25
|
|
|
|
|
32
|
|
22
|
25
|
|
|
|
|
71
|
return TRUE; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
2
|
|
|
2
|
0
|
2
|
sub is_number($input) { |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3
|
|
26
|
2
|
|
|
|
|
27
|
return looks_like_number($input); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
0
|
|
sub looks_like_comma_sep_ips($input) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my @ips = split /\,/, $input; |
31
|
0
|
|
|
|
|
|
chomp(@ips); |
32
|
0
|
|
|
|
|
|
for my $possible_ip (@ips) { |
33
|
0
|
|
|
|
|
|
my @v4 = $possible_ip =~ /(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/(\d{1,2})/g; |
34
|
0
|
|
|
|
|
|
my @v6 = $possible_ip =~ /([a-f0-9:]+:+[a-f0-9]+)\/(\d{1,3})/g; |
35
|
0
|
0
|
0
|
|
|
|
return FALSE if (!@v4 && !@v6); |
36
|
|
|
|
|
|
|
} |
37
|
0
|
|
|
|
|
|
return TRUE; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |