1package Net::DNS::Check::Config; 2 3use vars qw($VERSION $AUTOLOAD); 4 5use strict; 6use Carp; 7 8sub new { 9 my ($pkg, %param) = @_; 10 11 my $self = {}; 12 13 bless $self, $pkg; 14 15 # Definizione rootnameservers 16 $self->{rootservers} = [ qw( 17 198.41.0.4 18 128.9.0.107 19 192.33.4.12 20 128.8.10.90 21 192.203.230.10 22 192.5.5.241 23 192.112.36.4 24 128.63.2.53 25 192.36.148.17 26 192.58.128.30 27 193.0.14.129 28 198.32.64.12 29 202.12.27.33 ) 30 ]; 31 32 33 $self->{debug_default} = 0; 34 35 36 # Intervallo di tempo per la ritrasmissione delle query 37 $self->{query_retrans} = 5; 38 39 # Numero di tentativi nelle fare le query 40 $self->{query_retry} = 2; 41 42 # Time out delle connessioni di tipo TCP (default a 120) 43 $self->{query_tcp_timeout} = 30; 44 45 # Time out delle connessioni di tipo UDP (default undef) 46 $self->{query_udp_timeout} = undef; 47 48 # Abilita disabilita le query per i RR::AAAA 49 $self->{query_AAAA} = undef; 50 51 # $self->{predefined_hosts}->{'dns.nic.it'} = ['193.205.245.5']; 52 # $self->{predefined_hosts}->{'dns2.nic.it'} = ['193.205.245.8']; 53 # $self->{predefined_hosts}->{'dns3.nic.it'} = ['193.205.245.66']; 54 55 # list of all available Check (test) 56 # if you add a new Check you should add it to this list 57 $self->{test_list} = [ qw( 58 mx_compare 59 mx_present 60 ns_compare 61 ns_vs_delegated 62 ns_count 63 soa_expire_compare 64 soa_expire_range 65 soa_refresh_compare 66 soa_refresh_range 67 soa_retry_compare 68 soa_retry_range 69 soa_serial_compare 70 soa_serial_syntax 71 soa_master_compare 72 soa_master_in_ns 73 host_syntax 74 host_not_cname 75 host_ip_vs_ip_orig 76 host_ip_private 77 ) ]; 78 79 80 81 $self->{test_level}->{OK} = 'OK'; 82 $self->{test_level}->{E} = 'Error'; 83 $self->{test_level}->{W} = 'Warning'; 84 $self->{test_level}->{I} = 'Ignore'; 85 $self->{test_level}->{F} = 'Fatal'; 86 87 $self->{ok_status} = 'OK'; 88 $self->{error_status} = [qw{E F}]; 89 $self->{default_status} = 'E'; 90 91 # List of all configured test. This is an hash ref containg 92 # all test used. Default use all available tests. 93 # Default level E (Error) 94 $self->{test_configured} = { map { $_ => 'E' } @{ $self->{test_list} } }; 95 96 # $self->{test_configured}->{soa_serial_syntax} = 'W'; 97 # $self->{test_configured}->{soa_serial_compare} = 'W'; 98 # $self->{test_configured}->{soa_refresh_range} = 'W'; 99 # $self->{test_configured}->{soa_refresh_compare} = 'W'; 100 # $self->{test_configured}->{soa_retry_range} = 'W'; 101 # $self->{test_configured}->{soa_retry_compare} = 'W'; 102 103 104 # If value is '0' 105 $self->{ns_min_count} = 2; 106 $self->{ns_max_count} = 0; # no max limit 107 108 $self->{soa_min_retry} = 1800; 109 $self->{soa_max_retry} = 28800; 110 111 $self->{soa_min_refresh} = 1800; 112 $self->{soa_max_refresh} = 86400; 113 114 $self->{soa_min_expire} = 86400; 115 $self->{soa_max_expire} = 0; # no max limit 116 117 $self->{ip_private} = [ qw( 118 10 119 127 120 172.16 121 172.17 122 172.18 123 172.19 124 172.20 125 172.21 126 172.22 127 172.23 128 172.24 129 172.25 130 172.26 131 172.27 132 172.28 133 172.29 134 172.30 135 172.31 136 192.168 ) 137 ]; 138 139 return $self; 140} 141 142sub test_level { 143 my ($self) = shift; 144 my ($level) = shift;; 145 146 if ( $level ) { 147 return $self->{test_level}->{$level}; 148 } else { 149 return $self->{test_level}; 150 } 151} 152 153 154sub test_conf { 155 my ($self) = shift; 156 my (%param) = @_; 157 158 return unless $param{test}; 159 160 # We should verify if test exists and if level is one of that supported 161 if ($param{level}) { 162 $self->{test_configured}->{$param{test}} = uc $param{level}; 163 } 164 165 if (defined $self->{test_configured}->{$param{test}} ) { 166 return $self->{test_configured}->{$param{test}}; 167 } 168} 169 170 171sub AUTOLOAD { 172 my ($self) = @_; 173 174 my ($name) = $AUTOLOAD =~ m/^.*::(.*)$/; 175 176 unless (exists $self->{$name}) { 177 Carp::carp(<<"AMEN"); 178 179*** 180*** WARNING!!! Param Doesn't exist 181*** $AUTOLOAD 182*** 183 184AMEN 185 return; 186 } 187 188 no strict q/refs/; 189 190 # Build a method in the class. 191 *{$AUTOLOAD} = sub { 192 my ($self, $new_val) = @_; 193 194 if (defined $new_val) { 195 $self->{$name} = $new_val; 196 } 197 198 return $self->{$name}; 199 }; 200 201 # And jump over to it. 202 goto &{$AUTOLOAD}; 203} 204 205 206sub DESTROY {}; 2071; 208 209__END__ 210 211=head1 NAME 212 213Net::DNS::Check::Config - 214 215=head1 SYNOPSIS 216 217 use Net::DNS::Check::Config; 218 219 my $config = new Net::DNS::Check::Config(); 220 $config->test_conf( test => 'soa_refresh_range', level => 'I'); 221 $config->debug(0); 222 223 224=head1 DESCRIPTION 225 226A Config object is an instance of the Net::DNS::Check::Config class. 227With this object you can configure how Net::DNS::Check operates. You can set, for example, which tests will be executed during the check phase, set the debug level and several other options. 228 229One of the main configurations that you can do with Net::DNS::Check::Config are about which tests will be executed and how to consider "succeeded" or "failed" anwsers from them. For this purpose is important to explain what it means when we talk about "status" or "status level". Every executed tests returns always an answer that can be "true" or "false" or if you prefer "succeeded" or "failed". 230The Net::DNS::Check::Config class define at present 4 different status level that can be associated to "succeeded" or "failed" answer returned from executed tests: OK, E (Error), W (Warning), I (Ignore). 231 232Usually a "succeeded" answer from a test is associated to "OK" status level (you can change this association with "ok_status" function) and the association is made for all tests and is not possibile to set it test by test. 233The status associated to a "failed" answer can be set test by test using "test_conf" function (if don't use "test_conf" function all test inside "test_list" are set to "default_status" status value). 234 235 236=head1 METHODS 237 238=head2 new 239 240This method create a new Net::DNS::Check object and returns a reference to it. Arguments are not available. 241 242 use Net::DNS::Check::Config; 243 244 my $config = new Net::DNS::Check::Config(); 245 246 247=head2 rootservers 248 249With this method you can get or set the ip addresses of the root nameservers used by L<Net::DNS::Resolver::Recurse>. The root nameservers list is stored or returned as an array reference. 250 251 # Get 252 print join(' ', @{ $config->rootservers() } ); 253 254 # Set 255 $config->rootservers([qw( 198.41.0.4 128.9.0.107) ]); 256 257 258=head2 debug_default 259 260With this method you can get or set the default debug level. You can set the debug level with debug argument of the method "new" of L<Net::DNS::Check> object and if the debug level is not specified the "debug_default" value, of L<Ne::DNS::Check::Config> object, will be used. 261 262At present 4 debug levels are supported: 263 264=over 2 265 266=item 267 268Level 0: no debug information 269 270=item 271 272Level 1: print to STDOUT information about executed actions 273 274=item 275 276Level 2: as for level 1, but information about query answers are also displayed 277 278=item 279 280Level 3: as for previous levels, but debug option of Net::DNS module is also activated. 281 282=back 283 284The default value of "debug_default" is 0 (debug disabled). 285 286 # Set 287 $config->debug_default(2); 288 289=head2 query_retrans 290 291Get or set the retransmission interval used in the L<Net::DNS::Resolver> object. The default value is 5. 292 293=head2 query_retry 294 295Get or set the number of times to try the query in the L<Net::DNS::Resolver>. The default value is 2. 296 297=head2 query_tcp_timeout 298 299Get or set the default timeout in seconds for TCP queries (L<Net::DNS::Resolver> 300tcp_timeout argument). 301 302=head2 query_udp_timeout 303 304Not yet implemented. 305 306=head2 predefined_hosts 307 308Working in progress. 309 310=head2 test_conf (funzione) 311 312This method is used to set the association for a "failed" answer from a test. This function support two arguments passed as hash: "test" and "level". 313The "test" argument is mandatory and contains the name of the test for which you want set or get the status level information. 314If you omit the "level" argument, this method return the status information about the test specified with the "test" argument. 315 316 # Set the Warning status level for test "soa_expire_range" 317 $config->test_conf( test => 'soa_expire_range', level => 'W' ); 318 319 # Get the status information about the test "soa_refresh_range" 320 $config->test_conf( test => 'soa_refresh_range' ); 321 322=head2 ok_status 323 324Get or set the "good" status. The default "good" status is "OK". 325 326=head2 error_status 327 328Get or set the list of status considered as "not good" or error status. The list is stored or returned as an array reference. The default "not good" status is: "E" (Error). 329 330=head2 default_status 331 332Get or Set the default status for a test. If a status is not specified for a test, the default status is used. The default value is "E" (Error). 333 334=head2 test_list 335 336Get or set the list of all the available tests (sublcass of Net::DNS::Check::Test). The list is stored or returned as an array reference. For additional information about available tests please see L<Net::DNS::Check::Test> class. 337 338 my @list = @{ $config->test_list() }; 339 push (@list, 'new_test'); 340 $config->test_list(\@list); 341 342Every test inside the "test_list" are initialized to the "default_status" value. If you want to change the status level of a specific test you must use "test_conf" function: 343 344 $config->test_list([qw( mx_compare mx_present ns_compare ns_vs_delegated ns_count]); 345 # For all this tests a default_status is set. 346 # If you want change the status of a specific test use test_conf function. 347 # For example this set for "mx_present" test a "warning" (W) level. 348 $config->test_conf( test => 'mx_present', level => 'W' ); 349 350 351=head2 test_level 352 353This method is used to query Net::DNS::Check::Conf for supported status levels. It can be used to know either the list of all supported status levels (returned as an hash) or to translate from short status name to long status name (example from "W" to "Warning"). o 354 355 $config->test_level(); 356 # Return an hash containing the list of all supported status level: 357 # 'W' => 'Warning', 'OK' => 'OK', 'E' => 'Error', 'I' => 'Ignore' 358 359 $config->test_level('W'); 360 # Return 'Warning' 361 362 363=head2 ns_min_count 364 365Get or set the minimun number of NS RR for the domain you want to check. This number is used in the L<Net::DNS::Check::Test::ns_count> test. The default value is 2. 366 367 $config->ns_min_coung(3); 368 369 370=head2 ns_max_count 371 372Get or set the maximum number of NS RR for the domain you want to check. This number is used in the L<Net::DNS::Check::Test::ns_count> test. The default value is 0, so there is no maximum limit. 373 374 $config->ns_max_count(7); 375 376 377=head2 soa_min_retry 378 379Get or set the minimum value required for the retry time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_retry_range> test. The default value is 1800. 380 381=head2 soa_max_retry 382 383Get or set the maximum value required for the retry time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_retry_range> test. The default value is 28800. A value of 0 disable the maximum limit for the retry time. 384 385=head2 soa_min_refresh 386 387Get or set the minimum value required for the refresh time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_refresh_range> test. The default value is 1800. 388 389=head2 soa_max_refresh 390 391Get or set the minimum value required for the refresh time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_refresh_range> test. The default value is 1800. A value of 0 disable the maximum limit for the refresh time. 392 393=head2 soa_min_expire 394 395Get or set the minimum value required for the expire time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_expire_range> test. The default value is 86400. 396 397=head2 soa_max_expire 398 399Get or set the maximum value required for the expire time in the SOA record. This number is used in the L<Net::DNS::Check::Test::soa_expire_range> test. The default value is 0 so there is not maximum limit for the expire time. 400 401=head2 ip_private 402 403Get or set the list of the private IP addresses (see RFC1597 ). The list is stored or returned as an array reference. This list is used in the L<Net::DNS::Check::Test::host_ip_private> test. The default values are: 404 405=over 4 406 40710 127 172.16 172.17 172.18 172.19 172.20 172.21 172.22 172.23 172.24 172.25 172.26 172.27 172.28 172.29 172.30 172.31 192.168 408 409=back 410 411=head1 COPYRIGHT 412 413Copyright (c) 2005 Lorenzo Luconi Trombacchi - IIT-CNR 414 415All rights reserved. This program is free software; you may redistribute 416it and/or modify it under the same terms as Perl itself. 417 418=head1 SEE ALSO 419 420L<perl(1)> 421 422=cut 423 424