line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNS::Check::HostsList; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use Net::DNS::Check::Config; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
5
|
1
|
|
|
1
|
|
530
|
use Net::DNS::Check::Host; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
729
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
0
|
|
|
0
|
0
|
|
my ($pkg, %param) = @_; |
10
|
0
|
|
|
|
|
|
my $self; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
$self->{domain} = $param{domain}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Quotiamo i '.' |
15
|
0
|
|
|
|
|
|
$self->{qdomain} = $param{domain}; |
16
|
0
|
|
|
|
|
|
$self->{qdomain} =~ s/\./\\./g; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
0
|
|
0
|
|
|
|
$self->{config} = $param{config} || new Net::DNS::Check::Config; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
0
|
|
|
|
$self->{debug} = $param{debug} || $self->{config}->debug_default(); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->{list} = {}; |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
bless $self, $pkg; |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if ($param{load_predefined}) { |
28
|
0
|
|
|
|
|
|
$self->load_predefined_host(); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub load_predefined_host() { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Precaricamento dei predefined_hosts |
39
|
0
|
|
|
|
|
|
foreach my $prehost ( keys %{$self->{config}->{predefined_hosts} } ) { |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $host_obj = new Net::DNS::Check::Host( |
41
|
|
|
|
|
|
|
init_only => 1, |
42
|
|
|
|
|
|
|
debug => $self->{debug}, |
43
|
|
|
|
|
|
|
host => $prehost, |
44
|
|
|
|
|
|
|
config => $self->{config}, |
45
|
|
|
|
|
|
|
ip => $self->{config}->{predefined_hosts}->{$prehost} |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
$self->{list}->{$prehost} = $host_obj; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub add_host { |
56
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my %param = @_; |
58
|
0
|
|
|
|
|
|
my $hostname = lc $param{hostname}; # nome del dns |
59
|
0
|
|
0
|
|
|
|
my $ip = $param{ip} || []; # ip array pointer (facoltativo) |
60
|
0
|
|
0
|
|
|
|
my $ip_orig = $param{ip_orig} || []; # ip array pointer (facoltativo) |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
return undef if (!$hostname); |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
if ( exists $self->{list}->{$hostname} ) { |
65
|
|
|
|
|
|
|
# print "$hostname: already present\n"; |
66
|
|
|
|
|
|
|
# Se c'e' gia' riportiamo il record gia' presente |
67
|
0
|
|
|
|
|
|
return $self->{list}->{$hostname}; |
68
|
|
|
|
|
|
|
} else { |
69
|
|
|
|
|
|
|
# Passiamo l'IP (query non ricorsiva) solo se l'host |
70
|
|
|
|
|
|
|
# fa parte del dominio che stiamo analizzando |
71
|
|
|
|
|
|
|
# print "$hostname: not present found: "; |
72
|
0
|
|
|
|
|
|
my $host; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my @temp; |
75
|
0
|
|
|
|
|
|
@temp = split('\.', $self->{domain}); |
76
|
0
|
|
|
|
|
|
my $domcount = scalar @temp; |
77
|
0
|
|
|
|
|
|
@temp = split('\.', $hostname); |
78
|
0
|
|
|
|
|
|
my $hostcount = (scalar @temp)-1; |
79
|
|
|
|
|
|
|
|
80
|
0
|
0
|
0
|
|
|
|
if ( ($self->{domain} eq $hostname) || $self->{domain} && $hostname =~ /.*$self->{qdomain}$/ && $domcount == $hostcount ) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
81
|
|
|
|
|
|
|
# print "$hostname inside query /$self->{domain}, $domcount, $hostcount\n"; |
82
|
0
|
|
|
|
|
|
$host = new Net::DNS::Check::Host( |
83
|
|
|
|
|
|
|
debug => $self->{debug}, |
84
|
|
|
|
|
|
|
host => $hostname, |
85
|
|
|
|
|
|
|
config => $self->{config}, |
86
|
|
|
|
|
|
|
ip => $ip, |
87
|
|
|
|
|
|
|
ip_orig => $ip_orig |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} else { |
90
|
|
|
|
|
|
|
# print "$hostname outside query /$self->{domain}, $domcount, $hostcount\n"; |
91
|
0
|
|
|
|
|
|
$host = new Net::DNS::Check::Host( |
92
|
|
|
|
|
|
|
debug => $self->{debug}, |
93
|
|
|
|
|
|
|
config => $self->{config}, |
94
|
|
|
|
|
|
|
host => $hostname, |
95
|
|
|
|
|
|
|
ip_orig => $ip_orig |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->{list}->{$hostname} = $host; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $host; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Rimuove un host dalla HostsList. Servira'? Boh? |
107
|
|
|
|
|
|
|
sub rm_host() { |
108
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $hostname = shift; |
110
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
if (exists $self->{list}->{$hostname} ) { |
112
|
0
|
|
|
|
|
|
delete $self->{list}->{$hostname}; |
113
|
0
|
|
|
|
|
|
return 1; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return undef; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# Riporta la lista degli oggetti Host contenuti nella HostsList (che giro |
122
|
|
|
|
|
|
|
# di parole!!) |
123
|
|
|
|
|
|
|
sub get_list() { |
124
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return keys %{$self->{list}}; |
|
0
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Riporta l'oggetto host specifico corrispondente all'hostname passato come |
131
|
|
|
|
|
|
|
# parametro |
132
|
|
|
|
|
|
|
sub get_host() { |
133
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
134
|
0
|
|
|
|
|
|
my $hostname = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if (exists $self->{list}->{$hostname} ) { |
137
|
0
|
|
|
|
|
|
return $self->{list}->{$hostname}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return undef; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |