blib/script/toaster-watcher.pl untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod n/a totaltotal 0.0% 0 / 77 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2 use strict;
3 use warnings;
4  
5 #use Data::Dumper;
6 use English '-no_match_vars';
7 use Getopt::Std;
8  
9 use lib 'lib';
10 use Mail::Toaster 5.41;
11  
12 die "Sorry, you are not root!\n" if $UID != 0;
13  
14 use vars qw/ $opt_d $opt_v /;
15 $|++;
16  
17 getopts('dv');
18 $opt_v = $opt_v ? 1 : 0;
19  
20 my $toaster = Mail::Toaster->new;
21 my $verbose = $toaster->conf->{'toaster_verbose'} || $opt_v || 0;
22 $toaster->verbose($verbose);
23  
24 my $pidfile = "/var/run/toaster-watcher.pid";
25 if ( ! $toaster->util->check_pidfile( $pidfile, fatal=>0 ) ) {
26 $toaster->error( "another toaster-watcher is running, I refuse to!",fatal=>0);
27 $toaster->dump_errors;
28 exit 500;
29 };
30  
31 # suppress test output when not running in verbose mode
32 my %args = ( fatal=>0, verbose => $verbose );
33  
34 print "$0 v$Mail::Toaster::VERSION\n" if $verbose;
35  
36 $toaster->log( "Starting up" );
37 $toaster->qmail->config( %args );
38 $toaster->supervise_dirs_create( %args );
39  
40 foreach my $prot ( $toaster->get_daemons(1) ) {
41 $toaster->log( "Building $prot/run" );
42 $prot =~ s/\-/_/g;
43 my $method = 'build_' . $prot . '_run';
44 $toaster->qmail->$method( %args );
45 };
46  
47 #$toaster->setup->startup_script();
48 $toaster->check( %args );
49 $toaster->service_symlinks( %args );
50 $toaster->clear_open_smtp( %args );
51 $toaster->sqwebmail_clean_cache( %args );
52 $toaster->run_isoqlog( %args );
53 $toaster->run_qmailscanner( %args );
54 $toaster->clean_mailboxes( %args );
55 $toaster->learn_mailboxes( %args );
56 $toaster->process_logfiles( %args );
57  
58 $toaster->qmail->rebuild_ssl_temp_keys( %args );
59 $toaster->qmail->rebuild_simscan_control( %args );
60  
61 unlink $pidfile;
62 $toaster->log( "Exiting" );
63  
64 exit 0;
65  
66 __END__
67  
68  
69 =head1 NAME
70  
71 toaster-watcher.pl - monitors and configure various aspects of a qmail toaster
72  
73 =head1 SYNOPSIS
74  
75 toaster-watcher does several unique and important things. First, it includes a configuration file that stores settings about your mail system. You configure it to suit your needs and it goes about making sure all the settings on your system are as you selected. Various other scripts (like toaster_setup.pl) and programs use this configuration file to determine how to configure themselves and other parts of the mail toaster solution.
76  
77 The really cool part about toaster-watcher.pl is that it dynamically builds the run files for your qmail daemons (qmail-smtpd, qmail-send, and qmail-pop3). You choose all your settings in toaster-watcher.conf and toaster-watcher.pl builds your run files for you, on the fly. It tests the RBL's you've selected to use, and builds a control file based on your settings and dynamic information such as the availability of the RBLs you want to use.
78  
79  
80 =head1 DESCRIPTION
81  
82 =head1 SUBROUTINES
83  
84 =over
85  
86 =item build_send_run
87  
88 We first build a new $service/send/run file based on your settings in
89 toaster-watcher.conf. There are a ton of configuration options, be sure
90 to check out the docs for toaster-watcher.conf.
91  
92 If the new generated file is different than the installed version, we
93 install the updated run file and restart the daemon.
94  
95  
96 =item build_pop3_run
97  
98 We first build a new $service/pop3/run file based on your settings in
99 toaster-watcher.conf. There are a ton of configuration options, be sure
100 to check out the docs for toaster-watcher.conf.
101  
102 If the new generated file is different than the installed version, we
103 install the updated run file and restart the daemon.
104  
105  
106 =item build_smtp_run
107  
108 We first build a new $service/smtp/run file based on your settings in
109 toaster-watcher.conf. There are a ton of configuration options, be sure
110 to check out the docs for toaster-watcher.conf.
111  
112 If the new generated file is different than the installed version, we
113 install the updated run file and restart the daemon.
114  
115  
116 =item build_submit_run
117  
118 We first build a new $service/submit/run file based on your settings in
119 toaster-watcher.conf. There are a ton of configuration options, be sure
120 to check out the docs for toaster-watcher.conf.
121  
122 If the new generated file is different than the installed version, we
123 install the updated run file and restart the daemon.
124  
125  
126 =item Clear Open SMTP
127  
128 This script runs the clearopensmtp program which expires old ip addresses from the vpopmail smtp relay table. It will only run if you have vpopmail_roaming_users enabled in toaster-watcher.conf.
129  
130  
131 =item Isoqlog
132  
133 If you have isoqlog installed, you'll want to have it running frequently. I suggest running it from here, or from cron directly.
134  
135  
136 =item Qmail-Scanner Quarantine Processing
137  
138 Qmail-Scanner quarantines any files that fail certain tests, such as banned attachments, Virus laden messages, etc. The messages get left laying around in the quarantine until someone does something about it. If you enable this feature, toaster-watcher.pl will go through the quarantine and deal with messages as you see fit.
139  
140 I have mine configured to block the IP (for 24 hours) of anyone that's sent me a virus and delete the quarantined message. I run toaster-watcher.pl from cron every 5 minutes so this usually keeps virus infected hosts from sending me another virus laden message for at least 24 hours, after which we hope the owner of the system has cleaned up his computer.
141  
142  
143 =item Maildir Processing
144  
145 Many times its useful to have a script that cleans up old mail messages on your mail system and enforces policy. Now toaster-watcher.pl does that. You tell it how often to run (I use every 7 days), what mail folders to clean (Inbox, Read, Unread, Sent, Trash, Spam), and then how old the messaged need to be before you remove them.
146  
147 I have my system set to remove messages in Sent folders more than 180 days old and messages in Trash and Spam folders that are over 14 days old. I have also instructed toaster-watcher to feed any messages in my Spam and Read folders that are more than 1 day old through sa-learn. That way I train SpamAssassin by merely moving my messages into appropriate folders.
148  
149  
150 =back
151  
152 =head1 TODO
153  
154 Feature request by David Chaplin-Leobell: check for low disk space on the queue and
155 mail delivery partitions. If low disk is detected, it could either just
156 notify the administrator, or it could do some cleanup of things like the
157 qmail-scanner quarantine folder.
158  
159  
160 =head1 AUTHOR
161  
162 Matt Simerson <matt@tnpi.net>
163  
164  
165 =head1 DEPENDENCIES
166  
167 This module requires these other modules and libraries:
168  
169 Net::DNS
170  
171  
172 =head1 SEE ALSO
173  
174 http://mail-toaster.org/
175  
176 =head1 ACKNOWLEDGEMENTS
177  
178 Thanks to Randy Ricker, Anton Zavrin, Randy Jordan, Arie Gerszt, Joe Kletch, and Marius Kirschner for contributing to the development of this program.
179  
180  
181 =head1 COPYRIGHT AND LICENSE
182  
183 Copyright (c) 2004-2013, The Network People, Inc. All rights reserved.
184  
185 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
186  
187 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
188  
189 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
190  
191 Neither the name of the The Network People, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
192  
193 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
194  
195 =cut