blib/lib/Mail/Toaster/Setup/Test.pm untested

filter: Statementstmt 0.0% 0 / 370 Branchbran 0.0% 0 / 76 Conditioncond 0.0% 0 / 91 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 34 Podpod 0.0% 0 / 26 totaltotal 0.0% 0 / 597 SCAR 73.5
CC
39
Cov
0%
test_network
56.0
auth_setup
30.0
imap_auth_nossl
20.0
CRAP 1560.0
1 package Mail::Toaster::Setup::Test;
2 use strict;
3 use warnings;
4  
5 our $VERSION = '5.50';
6  
7 use Carp;
8 use English '-no_match_vars';
9 use Params::Validate qw( :all );
10  
11 use lib 'lib';
12 use parent 'Mail::Toaster::Base';
13  
14 sub daemontools {
15 my $self = shift;
16  
17 print "checking daemontools binaries...\n";
18 my @bins = qw/ multilog softlimit setuidgid supervise svok svscan tai64nlocal /;
19 foreach my $test ( @bins ) {
20 my $bin = $self->util->find_bin( $test, fatal => 0, verbose=>0);
21 $self->pretty(" $test", -x $bin );
22 };
23  
24 return 1;
25 }
26  
27 sub email_send {
28 my $self = shift;
29 my $email = $self->conf->{toaster_admin_email} || 'root';
30 my $qdir = $self->conf->{qmail_dir} || '/var/qmail';
31 my $ibin = "$qdir/bin/qmail-inject";
32 if ( ! -x $ibin ) {
33 return $self->error("qmail-inject ($ibin) not found!");
34 };
35  
36 foreach ( qw/ clean spam eicar attach clam / ) {
37 open(my $INJECT, "|", "$ibin -a -f \"\" $email" ) or
38 return $self->error( "couldn't send using qmail-inject!");
39 my $method = 'email_send_' . $_;
40 $self->$method( $INJECT, $email );
41 close $INJECT;
42 };
43  
44 return 1;
45 }
46  
47 sub email_send_attach {
48 my ( $self, $INJECT, $email ) = @_;
49  
50 print "\n\t\tSending .com test attachment - should fail.\n";
51 print $INJECT <<"EOATTACH";
52 From: Mail Toaster Testing <$email>
53 To: Email Administrator <$email>
54 Subject: Email test (blocked attachment message)
55 Mime-Version: 1.0
56 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg"
57 Content-Disposition: inline
58  
59 --gKMricLos+KVdGMg
60 Content-Type: text/plain; charset=us-ascii
61 Content-Disposition: inline
62  
63 This is an example of an Email message containing a virus. It should
64 trigger the virus scanner, and not be delivered.
65  
66 If you are using qmail-scanner, the server admin should get a notification.
67  
68 --gKMricLos+KVdGMg
69 Content-Type: text/plain; charset=us-ascii
70 Content-Disposition: attachment; filename="Eicar.com"
71  
72 00000000000000000000000000000000000000000000000000000000000000000000
73  
74 --gKMricLos+KVdGMg--
75  
76 EOATTACH
77  
78 }
79  
80 sub email_send_clam {
81 my ( $self, $INJECT, $email ) = @_;
82  
83 print "\n\t\tSending ClamAV test virus - should fail.\n";
84 print $INJECT <<EOCLAM;
85 From: Mail Toaster testing <$email>
86 To: Email Administrator <$email>
87 Subject: Email test (virus message)
88  
89 This is a viral message containing the clam.zip test virus pattern. It should be blocked by any scanning software using ClamAV.
90  
91  
92 --Apple-Mail-7-468588064
93 Content-Transfer-Encoding: base64
94 Content-Type: application/zip;
95 x-unix-mode=0644;
96 name="clam.zip"
97 Content-Disposition: attachment;
98 filename=clam.zip
99  
100 UEsDBBQAAAAIALwMJjH9PAfvAAEAACACAAAIABUAY2xhbS5leGVVVAkAA1SjO0El6E1BVXgEAOgD
101 6APzjQpgYGJgYGBh4Gf4/5+BYQeQrQjEDgxSDAQBIwPD7kIBBwbjAwEB3Z+DgwM2aDoYsKStqfy5
102 y5ChgndtwP+0Aj75fYYML5/+38J5VnGLz1nFJB4uRqaCMnEmOT8eFv1bZwRQjTwA5Degid0C8r+g
103 icGAt2uQn6uPsZGei48PA4NrRWZJQFF+cmpxMUNosGsQVNzZx9EXKJSYnuqUX+HI8Axqlj0QBLgy
104 MPgwMjIkOic6wcx8wNDXyM3IJAkMFAYGNoiYA0iPAChcwDwwGxRwjFA9zAxcEIYCODDBgAlMCkDE
105 QDTUXmSvtID8izeQaQOiQWHiGBbLAPUXsl+QwAEAUEsBAhcDFAAAAAgAvAwmMf08B+8AAQAAIAIA
106 AAgADQAAAAAAAAAAAKSBAAAAAGNsYW0uZXhlVVQFAANUoztBVXgAAFBLBQYAAAAAAQABAEMAAAA7
107 AQAAAAA=
108  
109 --Apple-Mail-7-468588064
110  
111  
112 EOCLAM
113  
114 }
115  
116 sub email_send_clean {
117 my ( $self, $INJECT, $email ) = @_;
118  
119 print "\n\t\tsending a clean message - should arrive unaltered\n";
120 print $INJECT <<EOCLEAN;
121 From: Mail Toaster testing <$email>
122 To: Email Administrator <$email>
123 Subject: Email test (clean message)
124  
125 This is a clean test message. It should arrive unaltered and should also pass any virus or spam checks.
126  
127 EOCLEAN
128  
129 }
130  
131 sub email_send_eicar {
132 my ( $self, $INJECT, $email ) = @_;
133  
134 # http://eicar.org/anti_virus_test_file.htm
135 # X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
136  
137 print "\n\t\tSending the EICAR test virus - should fail.\n";
138 print $INJECT <<EOVIRUS;
139 From: Mail Toaster testing <$email'>
140 To: Email Administrator <$email>
141 Subject: Email test (eicar virus test message)
142 Mime-Version: 1.0
143 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg"
144 Content-Disposition: inline
145  
146 --gKMricLos+KVdGMg
147 Content-Type: text/plain; charset=us-ascii
148 Content-Disposition: inline
149  
150 This is an example email containing a virus. It should trigger any good virus
151 scanner.
152  
153 If it is caught by AV software, it will not be delivered to its intended
154 recipient (the email admin). The Qmail-Scanner administrator should receive
155 an Email alerting him/her to the presence of the test virus. All other
156 software should block the message.
157  
158 --gKMricLos+KVdGMg
159 Content-Type: text/plain; charset=us-ascii
160 Content-Disposition: attachment; filename="sneaky.txt"
161  
162 X5O!P%\@AP[4\\PZX54(P^)7CC)7}\$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!\$H+H*
163  
164 --gKMricLos+KVdGMg--
165  
166 EOVIRUS
167 ;
168  
169 }
170  
171 sub email_send_spam {
172 my ( $self, $INJECT, $email ) = @_;
173  
174 print "\n\t\tSending a sample spam message - should fail\n";
175  
176 print $INJECT 'Return-Path: sb55sb55@yahoo.com
177 Delivery-Date: Mon, 19 Feb 2001 13:57:29 +0000
178 Return-Path: <sb55sb55@yahoo.com>
179 Delivered-To: jm@netnoteinc.com
180 Received: from webnote.net (mail.webnote.net [193.120.211.219])
181 by mail.netnoteinc.com (Postfix) with ESMTP id 09C18114095
182 for <jm7@netnoteinc.com>; Mon, 19 Feb 2001 13:57:29 +0000 (GMT)
183 Received: from netsvr.Internet (USR-157-050.dr.cgocable.ca [24.226.157.50] (may be forged))
184 by webnote.net (8.9.3/8.9.3) with ESMTP id IAA29903
185 for <jm7@netnoteinc.com>; Sun, 18 Feb 2001 08:28:16 GMT
186 From: sb55sb55@yahoo.com
187 Received: from R00UqS18S (max1-45.losangeles.corecomm.net [216.214.106.173]) by netsvr.Internet with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13)
188 id 1429NTL5; Sun, 18 Feb 2001 03:26:12 -0500
189 DATE: 18 Feb 01 12:29:13 AM
190 Message-ID: <9PS291LhupY>
191 Subject: anti-spam test: checking SpamAssassin [if present] (There yours for FREE!)
192 To: undisclosed-recipients:;
193  
194 Congratulations! You have been selected to receive 2 FREE 2 Day VIP Passes to Universal Studios!
195  
196 Click here http://209.61.190.180
197  
198 As an added bonus you will also be registered to receive vacations discounted 25%-75%!
199  
200  
201 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
202 This mailing is done by an independent marketing co.
203 We apologize if this message has reached you in error.
204 Save the Planet, Save the Trees! Advertise via E mail.
205 No wasted paper! Delete with one simple keystroke!
206 Less refuse in our Dumps! This is the new way of the new millennium
207 To be removed please reply back with the word "remove" in the subject line.
208 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
209  
210 ';
211 }
212  
213 sub imap_auth {
214 my $self = shift;
215 my %p = validate( @_, { $self->get_std_opts },);
216  
217 return $p{test_ok} if defined $p{test_ok}; # for testing only
218  
219 $self->imap_auth_nossl;
220 $self->imap_auth_ssl;
221 };
222  
223 sub imap_auth_nossl {
224 my $self = shift;
225  
226 my $r = $self->util->install_module("Mail::IMAPClient", verbose => 0);
227 $self->pretty("checking Mail::IMAPClient", $r );
228 if ( ! $r ) {
229 print "skipping imap test authentications\n";
230 return;
231 };
232  
233 eval "use Mail::IMAPClient"; ## no critic ( ProhibitStringyEval )
234 if ( $EVAL_ERROR ) {
235 $self->audit("unable to load Mail::IMAPClient");
236 return;
237 };
238  
239 # an authentication that should succeed
240 my $imap = Mail::IMAPClient->new(
241 User => $self->conf->{'toaster_test_email'} || 'test2@example.com',
242 Password => $self->conf->{'toaster_test_email_pass'} || 'cHanGeMe',
243 Server => 'localhost',
244 );
245 if ( !defined $imap ) {
246 $self->pretty( "imap connection", $imap );
247 return;
248 };
249  
250 $self->pretty( "authenticate IMAP user with plain passwords",
251 $imap->IsAuthenticated );
252  
253 my @features = $imap->capability
254 or warn "Couldn't determine capability: $@\n";
255 $self->audit( "Your IMAP server supports: " . join( ',', @features ) );
256 $imap->logout;
257  
258 print "an authentication that should fail\n";
259 $imap = Mail::IMAPClient->new(
260 Server => 'localhost',
261 User => 'no_such_user',
262 Pass => 'hi_there_log_watcher'
263 )
264 or do {
265 $self->pretty( "imap connection that should fail", 0);
266 return 1;
267 };
268 $self->pretty( " imap connection", $imap->IsConnected );
269 $self->pretty( " test auth that should fail", !$imap->IsAuthenticated );
270 $imap->logout;
271 return;
272 };
273  
274 sub imap_auth_ssl {
275 my $self = shift;
276  
277 my $user = $self->conf->{'toaster_test_email'} || 'test2@example.com';
278 my $pass = $self->conf->{'toaster_test_email_pass'} || 'cHanGeMe';
279  
280 my $r = $self->util->install_module( "IO::Socket::SSL", verbose => 0,);
281 $self->pretty( "checking IO::Socket::SSL ", $r);
282 if ( ! $r ) {
283 print "skipping IMAP SSL tests due to missing SSL support\n";
284 return;
285 };
286  
287 require IO::Socket::SSL;
288 my $socket = IO::Socket::SSL->new(
289 PeerAddr => 'localhost',
290 PeerPort => 993,
291 Proto => 'tcp',
292 SSL_verify_mode => 'SSL_VERIFY_NONE',
293 );
294 $self->pretty( " imap SSL connection", $socket);
295 return if ! $socket;
296  
297 print " connected with " . $socket->get_cipher . "\n";
298 print $socket ". login $user $pass\n";
299 ($r) = $socket->peek =~ /OK/i;
300 $self->pretty( " auth IMAP SSL with plain password", $r ? 0 : 1);
301 print $socket ". logout\n";
302 close $socket;
303  
304 # no idea why this doesn't work, so I just forge an authentication by printing directly to the socket
305 # my $imapssl = Mail::IMAPClient->new( Socket=>$socket, User=>$user, Password=>$pass) or warn "new IMAP failed: ($@)\n";
306 # $imapssl->IsAuthenticated ? print "ok\n" : print "FAILED.\n";
307  
308 # doesn't work yet because courier doesn't support CRAM-MD5 via the vchkpw auth module
309 # print "authenticating IMAP user with CRAM-MD5...";
310 # $imap->connect;
311 # $imap->authenticate;
312 # $imap->IsAuthenticated ? print "ok\n" : print "FAILED.\n";
313 #
314 # print "logging out...";
315 # $imap->logout;
316 # $imap->IsAuthenticated ? print "FAILED.\n" : print "ok.\n";
317 # $imap->IsConnected ? print "connection open.\n" : print "connection closed.\n";
318  
319 }
320  
321 sub pop3_auth {
322 my $self = shift;
323 my %p = validate( @_, { $self->get_std_opts },);
324  
325 $OUTPUT_AUTOFLUSH = 1;
326  
327 my $r = $self->util->install_module( "Mail::POP3Client", verbose => 0,);
328 $self->pretty("checking Mail::POP3Client", $r );
329 eval "use Mail::POP3Client"; ## no critic ( ProhibitStringyEval )
330 if ( $EVAL_ERROR ) {
331 print "unable to load Mail::POP3Client, skipping POP3 tests\n";
332 return;
333 };
334  
335 my %auths = (
336 'POP3' => { type => 'PASS', descr => 'plain text' },
337 'POP3-APOP' => { type => 'APOP', descr => 'APOP' },
338 'POP3-CRAM-MD5' => { type => 'CRAM-MD5', descr => 'CRAM-MD5' },
339 'POP3-SSL' => { type => 'PASS', descr => 'plain text', ssl => 1 },
340 'POP3-SSL-APOP' => { type => 'APOP', descr => 'APOP', ssl => 1 },
341 'POP3-SSL-CRAM-MD5' => { type => 'CRAM-MD5', descr => 'CRAM-MD5', ssl => 1 },
342 );
343  
344 foreach ( sort keys %auths ) {
345 $self->pop3_auth_prot( $_, $auths{$_} );
346 }
347  
348 return 1;
349 }
350  
351 sub pop3_auth_prot {
352 my $self = shift;
353 my ( $name, $v ) = @_;
354  
355 my $type = $v->{'type'};
356 my $descr = $v->{'descr'};
357  
358 my $user = $self->conf->{'toaster_test_email'} || 'test2@example.com';
359 my $pass = $self->conf->{'toaster_test_email_pass'} || 'cHanGeMe';
360 my $host = $self->conf->{'pop3_ip_address_listen_on'} || 'localhost';
361 $host = "localhost" if ( $host =~ /system|qmail|all/i );
362  
363 my $pop = Mail::POP3Client->new(
364 HOST => $host,
365 AUTH_MODE => $type,
366 $v->{ssl} ? ( USESSL => 1 ) : (),
367 );
368  
369 if ( $v->{ssl} ) {
370 my $socket = IO::Socket::SSL->new( PeerAddr => $host,
371 PeerPort => 995,
372 SSL_verify_mode => 'SSL_VERIFY_NONE',
373 Proto => 'tcp',
374 )
375 or do { warn "No socket!"; return };
376  
377 $pop->Socket($socket);
378 }
379  
380 $pop->User($user);
381 $pop->Pass($pass);
382 $pop->Connect >= 0 || warn $pop->Message;
383 $self->pretty( " $name authentication", ($pop->State eq 'TRANSACTION'));
384  
385 # if ( my @features = $pop->Capa ) {
386 # print " POP3 server supports: " . join( ",", @features ) . "\n";
387 # }
388 $pop->Close;
389 }
390  
391 sub smtp_auth {
392 my $self = shift;
393 my %p = validate( @_, { $self->get_std_opts } );
394  
395 my @modules = ('IO::Socket::INET', 'IO::Socket::SSL', 'Net::SSLeay', 'Socket qw(:DEFAULT :crlf)','Net::SMTP_auth');
396 foreach ( @modules ) {
397 eval "use $_"; ## no critic ( ProhibitStringyEval )
398 die $@ if $@;
399 $self->pretty( "loading $_", 'ok' );
400 };
401  
402 Net::SSLeay::load_error_strings();
403 Net::SSLeay::SSLeay_add_ssl_algorithms();
404 Net::SSLeay::randomize();
405  
406 my $host = $self->conf->{'smtpd_listen_on_address'} || 'localhost';
407 $host = 'localhost' if ( $host =~ /system|qmail|all/i );
408  
409 my $smtp = Net::SMTP_auth->new($host);
410 $self->pretty( "connect to smtp port on $host", $smtp );
411 return 0 if ! defined $smtp;
412  
413 my @auths = $smtp->auth_types;
414 $self->pretty( " get list of SMTP AUTH methods", scalar @auths);
415 $smtp->quit;
416  
417 $self->smtp_auth_pass($host, \@auths);
418 $self->smtp_auth_fail($host, \@auths);
419 };
420  
421 sub smtp_auth_pass {
422 my $self = shift;
423 my $host = shift;
424 my $auths = shift or die "invalid params\n";
425  
426 my $user = $self->conf->{'toaster_test_email'} || 'test2@example.com';
427 my $pass = $self->conf->{'toaster_test_email_pass'} || 'cHanGeMe';
428  
429 # test each authentication method the server advertises
430 foreach (@$auths) {
431  
432 my $smtp = Net::SMTP_auth->new($host);
433 my $r = $smtp->auth( $_, $user, $pass );
434 $self->pretty( " authentication with $_", $r );
435 next if ! $r;
436  
437 $smtp->mail( $self->conf->{'toaster_admin_email'} );
438 $smtp->to('postmaster');
439 $smtp->data;
440 $smtp->datasend("To: postmaster\n");
441 $smtp->datasend("\n");
442 $smtp->datasend("A simple test message\n");
443 $smtp->dataend;
444  
445 $smtp->quit;
446 $self->pretty(" sending after auth $_", 1 );
447 }
448 }
449  
450 sub smtp_auth_fail {
451 my $self = shift;
452 my $host = shift;
453 my $auths = shift or die "invalid params\n";
454  
455 my $user = 'non-exist@example.com';
456 my $pass = 'non-password';
457  
458 foreach (@$auths) {
459 my $smtp = Net::SMTP_auth->new($host);
460 my $r = $smtp->auth( $_, $user, $pass );
461 $self->pretty( " failed authentication with $_", ! $r );
462 $smtp->quit;
463 }
464 }
465  
466 sub run_all {
467 my $self = shift;
468 my %p = validate( @_, { $self->get_std_opts } );
469  
470 print "testing...\n";
471  
472 $self->test_qmail;
473 sleep 1;
474 $self->daemontools;
475 sleep 1;
476 $self->ucspi;
477 sleep 1;
478  
479 $self->dump_audit(quiet=>1); # clear audit history
480  
481 $self->supervised_procs;
482 sleep 1;
483 $self->test_logging;
484 sleep 1;
485 $self->setup->vpopmail->test;
486 sleep 1;
487  
488 $self->toaster->check_running_processes;
489 sleep 1;
490 $self->test_network;
491 sleep 1;
492 $self->crons;
493 sleep 1;
494  
495 $self->qmail->check_rcpthosts;
496 sleep 1;
497  
498 if ( ! $self->util->yes_or_no( "skip the mail scanner tests?", timeout => 10 ) ) {
499 $self->setup->simscan->test;
500 print "\n\nFor more ways to test your Virus scanner, go here:
501 \n\t http://www.testvirus.org/\n\n";
502 };
503 sleep 1;
504  
505 if ( ! $self->util->yes_or_no( "skip the authentication tests?", timeout => 10) ) {
506 $self->auth;
507 };
508  
509 # there's plenty more room here for more tests.
510  
511 # test DNS!
512 # make sure primary IP is not reserved IP space
513 # test reverse address for this machines IP
514 # test resulting hostname and make sure it matches
515 # make sure server's domain name has NS records
516 # test MX records for server name
517 # test for SPF records for server name
518  
519 # test for low disk space on /, qmail, and vpopmail partitions
520  
521 print "\ntesting complete.\n";
522 }
523  
524 sub auth {
525 my $self = shift;
526 my %p = validate( @_, { $self->get_std_opts } );
527  
528 $self->auth_setup or return;
529  
530 $self->imap_auth;
531 $self->pop3_auth;
532 $self->smtp_auth;
533  
534 print
535 "\n\nNOTICE: It is normal for some of the tests to fail. This test suite is useful for any mail server, not just a Mail::Toaster. \n\n";
536  
537 # webmail auth
538 # other ?
539 }
540  
541 sub auth_setup {
542 my $self = shift;
543  
544 my $qmail_dir = $self->conf->{qmail_dir};
545 my $assign = "$qmail_dir/users/assign";
546 my $email = $self->conf->{toaster_test_email};
547 my $pass = $self->conf->{toaster_test_email_pass};
548  
549 my $domain = ( split( '@', $email ) )[1];
550 print "test_auth: testing domain is: $domain.\n";
551  
552 if ( ! -e $assign || ! grep {/:$domain:/} `cat $assign` ) {
553 print "domain $domain is not set up.\n";
554 return if ! $self->util->yes_or_no( "may I add it for you?", timeout => 30 );
555  
556 my $vpdir = $self->conf->{vpopmail_home_dir};
557 system "$vpdir/bin/vadddomain $domain $pass";
558 system "$vpdir/bin/vadduser $email $pass";
559 }
560  
561 open( my $ASSIGN, '<', $assign) or return;
562 return if ! grep {/:$domain:/} <$ASSIGN>;
563 close $ASSIGN;
564  
565 if ( $OSNAME eq "freebsd" ) {
566 $self->freebsd->install_port( "p5-Mail-POP3Client" ) or return;
567 $self->freebsd->install_port( "p5-Mail-IMAPClient" ) or return;
568 $self->freebsd->install_port( "p5-Net-SMTP_auth" ) or return;
569 $self->freebsd->install_port( "p5-IO-Socket-SSL" ) or return;
570 }
571 return 1;
572 };
573  
574 sub crons {
575 my $self = shift;
576 my %p = validate( @_, { $self->get_std_opts },);
577  
578 my $tw = $self->util->find_bin( 'toaster-watcher.pl', verbose => 0);
579 my $vpopdir = $self->conf->{'vpopmail_home_dir'} || "/usr/local/vpopmail";
580  
581 my @crons = ( "$vpopdir/bin/clearopensmtp", $tw);
582  
583 my $sqcache = "/usr/local/share/sqwebmail/cleancache.pl";
584 push @crons, $sqcache if ( $self->conf->{'install_sqwebmail'} && -x $sqcache);
585  
586 print "checking cron processes\n";
587  
588 foreach (@crons) {
589 $self->pretty(" $_", system( $_ ) ? 0 : 1 );
590 }
591 }
592  
593 sub pretty {
594 my $self = shift;
595 my $mess = shift or croak "test with no args?!";
596 my $result = shift;
597  
598 my %p = validate(@_, { $self->get_std_opts } );
599 return $p{test_ok} if defined $p{test_ok};
600  
601 print $mess;
602 defined $result or do { print "\n"; return; };
603 for ( my $i = length($mess); $i <= 65; $i++ ) { print '.' };
604 print $result ? 'ok' : 'FAILED';
605 print "\n";
606 };
607  
608 sub test_dns {
609  
610 print <<'EODNS'
611 People forget to even have DNS setup on their Toaster, as Matt has said before. If someone forgot to configure DNS, chances are, little or nothing will work -- from port fetching to timely mail delivery.
612  
613 How about adding a simple DNS check to the Toaster Setup test suite? And in the meantime, you could give some sort of crude benchmark, depending on the circumstances of the test data. I am not looking for something too hefty, but something small and sturdy to make sure there is a good DNS server around answering queries reasonably fast.
614  
615 Here is a sample of some DNS lookups you could perform. What I would envision is that there were around 20 to 100 forward and reverse lookups, and that the lookups were timed. I guess you could look them up in parallel, and wait a maximum of around 15 seconds for all of the replies. The interesting thing about a lot of reverse lookups is that they often fail because no one has published them.
616  
617 Iteration 1: lookup A records.
618 Iteration 2: lookup NS records.
619 Iteration 3: lookup MX records.
620 Iteration 4: lookup TXT records.
621 Iteration 5: Repeat step 1, observe the faster response time due to caching.
622  
623 Here's a sample output! Wow.
624  
625 #toaster_setup.pl -s dnstest
626 Would you like to enter a local domain so I can test it in detail?
627 testmydomain-local.net
628 Would you like to test domains with underscores in them? (y/n)n
629 Testing /etc/rc.conf for a hostname= line...
630 This box is known as smtp.testmydomain-local.net
631 Verifying /etc/hosts exists ... Okay
632 Verifying /etc/host.conf exists ... Okay
633 Verifying /etc/nsswitch.conf exists ... Okay
634 Doing reverse lookups in in-addr.arpa using default name service....
635 Doing forward A lookups using default name service....
636 Doing forward NS lookups using default name service....
637 Doing forward MX lookups using default name service....
638 Doing forward TXT lookups using default name service....
639 Results:
640 [Any errors, like...]
641 Listing Reverses Not found:
642 10.120.187.45 (normal)
643 169.254.89.123 (normal)
644 Listing A Records Not found:
645 example.impossible.nonexistent.bogus.co.nl (normal)
646 Listing TXT Records Not found:
647 Attempting to lookup the same A records again.... Hmmm. much faster!
648 Your DNS Server (or its forwarder) seems to be caching responses. (Good)
649  
650 Checking local domain known as testmydomain-local.net
651 Checking to see if I can query the testmydomain-local.net NS servers and retrieve the entire DNS record...
652 ns1.testmydomain-local.net....yes.
653 ns256.backup-dns.com....yes.
654 ns13.ns-ns-ns.net...no.
655 Do DNS records agree on all DNS servers? Yes. identical.
656 Skipping SOA match.
657  
658 I have discovered that testmydomain-local.net has no MX records. Shame on you, this is a mail server! Please fix this issue and try again.
659  
660 I have discovered that testmydomain-local.net has no TXT records. You may need to consider an SPF v1 TXT record.
661  
662 Here is a dump of your domain records I dug up for you:
663 xoxoxoxox
664  
665 Does hostname agree with DNS? Yes. (good).
666  
667 Is this machine a CNAME for something else in DNS? No.
668  
669 Does this machine have any A records in DNS? Yes.
670 smtp.testmydomain-local.net is 192.168.41.19. This is a private IP.
671  
672 Round-Robin A Records in DNS pointing to another machine/interface?
673 No.
674  
675 Does this machine have any CNAME records in DNS? Yes. aka
676 box1.testmydomain-local.net
677 pop.testmydomain-local.net
678 webmail.testmydomain-local.net
679  
680 ***************DNS Test Output complete
681  
682 Sample Forwards:
683 The first few may be cached, and the last one should fail. Some will have no MX server, some will have many. (The second to last entry has an interesting mail exchanger and priority.) Many of these will (hopefully) not be found in even a good sized DNS cache.
684  
685 I have purposely listed a few more obscure entries to try to get the DNS server to do a full lookup.
686 localhost
687 <vpopmail_default_domain if set>
688 www.google.com
689 yahoo.com
690 nasa.gov
691 sony.co.jp
692 ctr.columbia.edu
693 time.nrc.ca
694 distancelearning.org
695 www.vatican.va
696 klipsch.com
697 simerson.net
698 warhammer.mcc.virginia.edu
699 example.net
700 foo.com
701 example.impossible.nonexistent.bogus.co.nl
702  
703 [need some obscure ones that are probably always around, plus some non-US sample domains.]
704  
705 Sample Reverses:
706 Most of these should be pretty much static. Border routers, nics and such. I was looking for a good range of IP's from different continents and providers. Help needed in some networks. I didn't try to include many that don't have a published reverse name, but many examples exist in case you want to purposely have some.
707 127.0.0.1
708 224.0.0.1
709 198.32.200.50 (the big daddy?!)
710 209.197.64.1
711 4.2.49.2
712 38.117.144.45
713 64.8.194.3
714 72.9.240.9
715 128.143.3.7
716 192.228.79.201
717 192.43.244.18
718 193.0.0.193
719 194.85.119.131
720 195.250.64.90
721 198.32.187.73
722 198.41.3.54
723 198.32.200.157
724 198.41.0.4
725 198.32.187.58
726 198.32.200.148
727 200.23.179.1
728 202.11.16.169
729 202.12.27.33
730 204.70.25.234
731 207.132.116.7
732 212.26.18.3
733 10.120.187.45
734 169.254.89.123
735  
736 [Looking to fill in some of the 12s, 50s and 209s better. Remove some 198s]
737  
738 Just a little project. I'm not sure how I could code it, but it is a little snippet I have been thinking about. I figure that if you write the code once, it would be quite a handy little feature to try on a server you are new to.
739  
740 Billy
741  
742 EODNS
743 ;
744 }
745  
746 sub test_logging {
747 my $self = shift;
748 my %p = validate( @_, { $self->get_std_opts },);
749  
750 print "do the logging directories exist?\n";
751 my $q_log = $self->conf->{'qmail_log_base'};
752 foreach ( '', "pop3", "send", "smtp", "submit" ) {
753 $self->pretty(" $q_log/$_", -d "$q_log/$_" );
754 }
755  
756 print "checking log files?\n";
757 my @active_log_files = ( "clean.log", "maildrop.log", "watcher.log",
758 "send/current", "smtp/current", "submit/current" );
759  
760 push @active_log_files, "pop3/current" if $self->conf->{'pop3_daemon'} eq 'qpop3d';
761  
762 foreach ( @active_log_files ) {
763 $self->pretty(" $_", -f "$q_log/$_" );
764 }
765 }
766  
767 sub test_network {
768 my $self = shift;
769 return if $self->util->yes_or_no( "skip the network listener tests?",
770 timeout => 10,
771 );
772  
773 my $netstat = $self->util->find_bin( 'netstat', fatal => 0, verbose=>0 );
774 return unless $netstat && -x $netstat;
775  
776 if ( $OSNAME eq "freebsd" ) { $netstat .= " -alS" }
777 if ( $OSNAME eq "darwin" ) { $netstat .= " -al" }
778 if ( $OSNAME eq "linux" ) { $netstat .= " -a --numeric-hosts" }
779 else { $netstat .= " -a" }; # should be pretty safe
780  
781 print "checking for listening tcp ports\n";
782 my @listeners = `$netstat | grep -i listen`;
783 foreach (qw( smtp http pop3 imap https submission pop3s imaps )) {
784 $self->pretty(" $_", scalar grep {/$_/} @listeners );
785 }
786  
787 print "checking for udp listeners\n";
788 my @udps;
789 push @udps, "snmp" if $self->conf->{install_snmp};
790  
791 foreach ( @udps ) {
792 $self->pretty(" $_", `$netstat | grep $_` );
793 }
794 }
795  
796 sub test_qmail {
797 my $self = shift;
798 my %p = validate( @_, { $self->get_std_opts } );
799  
800 my $qdir = $self->conf->{'qmail_dir'};
801 print "does qmail's home directory exist?\n";
802 $self->pretty(" $qdir", -d $qdir );
803  
804 print "checking qmail directory contents\n";
805 my @tests = qw(alias boot control man users bin doc queue);
806 push @tests, "configure" if ( $OSNAME eq "freebsd" ); # added by the port
807 foreach (@tests) {
808 $self->pretty(" $qdir/$_", -d "$qdir/$_" );
809 }
810  
811 print "is the qmail rc file executable?\n";
812 $self->pretty( " $qdir/rc", -x "$qdir/rc" );
813  
814 print "do the qmail users exist?\n";
815 foreach (
816 $self->conf->{'qmail_user_alias'} || 'alias',
817 $self->conf->{'qmail_user_daemon'} || 'qmaild',
818 $self->conf->{'qmail_user_passwd'} || 'qmailp',
819 $self->conf->{'qmail_user_queue'} || 'qmailq',
820 $self->conf->{'qmail_user_remote'} || 'qmailr',
821 $self->conf->{'qmail_user_send'} || 'qmails',
822 $self->conf->{'qmail_log_user'} || 'qmaill',
823 )
824 {
825 $self->pretty(" $_", $self->setup->user_exists($_) );
826 }
827  
828 print "do the qmail groups exist?\n";
829 foreach ( $self->conf->{'qmail_group'} || 'qmail',
830 $self->conf->{'qmail_log_group'} || 'qnofiles',
831 ) {
832 $self->pretty(" $_", scalar getgrnam($_) );
833 }
834  
835 print "do the qmail alias files have contents?\n";
836 my $q_alias = "$qdir/alias/.qmail";
837 foreach ( qw/ postmaster root mailer-daemon / ) {
838 $self->pretty( " $q_alias-$_", -s "$q_alias-$_" );
839 }
840 }
841  
842 sub supervised_procs {
843 my $self = shift;
844  
845 print "do supervise directories exist?\n";
846 my $q_sup = $self->conf->{'qmail_supervise'} || "/var/qmail/supervise";
847 $self->pretty(" $q_sup", -d $q_sup);
848  
849 # check supervised directories
850 foreach ( qw/ smtp send pop3 submit / ) {
851 $self->pretty( " $q_sup/$_",
852 $self->toaster->supervised_dir_test( $_, verbose=>1 ) );
853 }
854  
855 print "do service directories exist?\n";
856 my $q_ser = $self->conf->{'qmail_service'};
857  
858 my @active_service_dirs;
859 foreach ( qw/ smtp send / ) {
860 push @active_service_dirs, $self->toaster->service_dir_get( $_ );
861 }
862  
863 push @active_service_dirs, $self->toaster->service_dir_get( 'pop3' )
864 if $self->conf->{'pop3_daemon'} eq 'qpop3d';
865  
866 push @active_service_dirs, $self->toaster->service_dir_get( "submit" )
867 if $self->conf->{'submit_enable'};
868  
869 foreach ( $q_ser, @active_service_dirs ) {
870 $self->pretty( " $_", -d $_ );
871 }
872  
873 print "are the supervised services running?\n";
874 my $svok = $self->util->find_bin( 'svok', fatal => 0 );
875 foreach ( @active_service_dirs ) {
876 $self->pretty( " $_", system("$svok $_") ? 0 : 1 );
877 }
878 };
879  
880 sub ucspi {
881 my $self = shift;
882  
883 print "checking ucspi-tcp binaries...\n";
884 foreach (qw( tcprules tcpserver rblsmtpd tcpclient recordio )) {
885 $self->pretty(" $_", $self->util->find_bin( $_, fatal => 0, verbose=>0 ) );
886 }
887  
888 if ( $self->conf->{install_mysql} && $self->conf->{'vpopmail_mysql'} ) {
889 my $tcpserver = $self->util->find_bin( "tcpserver", fatal => 0, verbose=>0 );
890 $self->pretty( " tcpserver mysql support",
891 scalar `strings $tcpserver | grep sql`
892 );
893 }
894  
895 return 1;
896 }
897  
898 1;
899 __END__;
900  
901  
902 =over 4
903  
904 =item email_send
905  
906  
907 ############ email_send ####################
908 # Usage : $toaster->email_send("clean" );
909 # : $toaster->email_send("spam" );
910 # : $toaster->email_send("attach");
911 # : $toaster->email_send("virus" );
912 # : $toaster->email_send("clam" );
913 #
914 # Purpose : send test emails to test the content scanner
915 # Returns : 1 on success
916 # Parameters : type (clean, spam, attach, virus, clam)
917 # See Also : email_send_[clean|spam|...]
918  
919  
920 Email test routines for testing a mail toaster installation.
921  
922 This sends a test email of a specified type to the postmaster email address configured in toaster-watcher.conf.
923  
924  
925 =item email_send_attach
926  
927  
928 ######### email_send_attach ###############
929 # Usage : internal only
930 # Purpose : send an email with a .com attachment
931 # Parameters : an email address
932 # See Also : email_send
933  
934 Sends a sample test email to the provided address with a .com file extension. If attachment scanning is enabled, this should trigger the content scanner (simscan/qmailscanner/etc) to reject the message.
935  
936  
937 =item email_send_clam
938  
939 Sends a test clam.zip test virus pattern, testing to verify that the AV engine catches it.
940  
941  
942 =item email_send_clean
943  
944 Sends a test clean email that the email filters should not block.
945  
946  
947 =item email_send_eicar
948  
949 Sends an email message with the Eicar virus inline. It should trigger the AV engine and block the message.
950  
951  
952 =item email_send_spam
953  
954 Sends a sample spam message that SpamAssassin should block.
955  
956 =back
957  
958 =cut