| 1 | package Net::DNS::Check::HostsList; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::DNS::Check::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::DNS::Check::Host; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 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 | ▶ | $self->{config} = $param{config} || new Net::DNS::Check::Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$param{'config'} || 'Net::DNS::Check::Config'->new
MC/DC0%0/2
$param{'config'} || 'Net::DNS::Check::Config'->new
$param{'config'}
'Net::DNS::Check::Config'->new
Truth table0%0/3
A || B
A= $param{'config'}B= 'Net::DNS::Check::Config'->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $self->{debug} = $param{debug} || $self->{config}->debug_default(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$param{'debug'} || $self->{'config'}->debug_default
MC/DC0%0/2
$param{'debug'} || $self->{'config'}->debug_default
$param{'debug'}
$self->{'config'}->debug_default
Truth table0%0/3
A || B
A= $param{'debug'}B= $self->{'config'}->debug_default
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | $self->{list} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | bless $self, $pkg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ($param{load_predefined}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | $self->load_predefined_host(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub load_predefined_host() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_predefined_host: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Precaricamento dei predefined_hosts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | foreach my $prehost ( keys %{$self->{config}->{predefined_hosts} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | my $host_obj = new Net::DNS::Check::Host( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | init_only => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | host => $prehost, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | config => $self->{config}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | 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 | 0 | ▶ | sub add_host { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_host: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my %param = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $hostname = lc $param{hostname}; # nome del dns | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my $ip = $param{ip} || []; # ip array pointer (facoltativo) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$param{'ip'} || []
MC/DC0%0/1
$param{'ip'} || []
$param{'ip'}
Truth table0%0/2
A
A= $param{'ip'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $ip_orig = $param{ip_orig} || []; # ip array pointer (facoltativo) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$param{'ip_orig'} || []
MC/DC0%0/1
$param{'ip_orig'} || []
$param{'ip_orig'}
Truth table0%0/2
A
A= $param{'ip_orig'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | return undef if (!$hostname); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( exists $self->{list}->{$hostname} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( ($self->{domain} eq $hostname) || $self->{domain} && $hostname =~ /.*$self->{qdomain}$/ && $domcount == $hostcount ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$self->{"domain"} eq $hostname or $self->{"domain"} and $hostname =~ /.*$self->{"qdomain"}$/ and $domcount == $hostcount
$self->{"domain"} and $hostname =~ /.*$self->{"qdomain"}$/ and $domcount == $hostcount
$self->{"domain"} and $hostname =~ /.*$self->{"qdomain"}$/
MC/DC0%0/4
$self->{"domain"} eq $hostname or $self->{"domain"} and $hostname =~ /.*$self->{"qdomain"}$/ and $domcount == $hostcount
$self->{"domain"} eq $hostname
$self->{"domain"}
$hostname =~ /.*$self->{"qdomain"}$/
$domcount == $hostcount
Truth table0%0/5
A or B and C and D
A= $self->{"domain"} eq $hostnameB= $self->{"domain"}C= $hostname =~ /.*$self->{"qdomain"}$/D= $domcount == $hostcount
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # print "$hostname inside query /$self->{domain}, $domcount, $hostcount\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | $host = new Net::DNS::Check::Host( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | host => $hostname, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | config => $self->{config}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ip => $ip, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ip_orig => $ip_orig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # print "$hostname outside query /$self->{domain}, $domcount, $hostcount\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | $host = new Net::DNS::Check::Host( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | debug => $self->{debug}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | config => $self->{config}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | 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 | 0 | ▶ | sub rm_host() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rm_host: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $hostname = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if (exists $self->{list}->{$hostname} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub get_list() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_list: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return keys %{$self->{list}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Riporta l'oggetto host specifico corrispondente all'hostname passato come | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # parametro | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub get_host() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_host: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $hostname = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (exists $self->{list}->{$hostname} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | return $self->{list}->{$hostname}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||