| 1 |
|
| package Mail::Toaster::Setup::Simscan; |
| 2 |
|
| use strict; |
| 3 |
|
| use warnings; |
| 4 |
|
| |
| 5 |
|
| our $VERSION = '5.50'; |
| 6 |
|
| |
| 7 |
|
| use Carp; |
| 8 |
|
| #use Config; |
| 9 |
|
| #use Cwd; |
| 10 |
|
| #use Data::Dumper; |
| 11 |
|
| #use File::Copy; |
| 12 |
|
| #use File::Path; |
| 13 |
|
| use English '-no_match_vars'; |
| 14 |
|
| use Params::Validate ':all'; |
| 15 |
|
| use Sys::Hostname; |
| 16 |
|
| |
| 17 |
|
| use lib 'lib'; |
| 18 |
|
| use parent 'Mail::Toaster::Base'; |
| 19 |
|
| |
| 20 |
|
| sub install { |
| 21 |
|
| my $self = shift; |
| 22 |
|
| my %p = validate( @_, { $self->get_std_opts },); |
| 23 |
|
| |
| 24 |
|
| return $p{test_ok} if defined $p{test_ok}; # for testing |
| 25 |
|
| |
| 26 |
|
| my $ver = $self->conf->{'install_simscan'} or do { |
| 27 |
|
| $self->audit( "simscan install, skipping (disabled)" ); |
| 28 |
|
| return; |
| 29 |
|
| }; |
| 30 |
|
| |
| 31 |
|
| if ( $OSNAME eq 'freebsd' ) { |
| 32 |
|
| my $r = $self->install_freebsd_port; |
| 33 |
|
| return $r if $ver eq 'port'; |
| 34 |
|
| }; |
| 35 |
|
| |
| 36 |
|
| my $user = $self->conf->{'simscan_user'} || "clamav"; |
| 37 |
|
| my $reje = $self->conf->{'simscan_spam_hits_reject'}; |
| 38 |
|
| my $qdir = $self->conf->{'qmail_dir'}; |
| 39 |
|
| my $custom = $self->conf->{'simscan_custom_smtp_reject'}; |
| 40 |
|
| |
| 41 |
|
| if ( -x "$qdir/bin/simscan" ) { |
| 42 |
|
| return 0 |
| 43 |
|
| if ! $self->util->yes_or_no( |
| 44 |
|
| "simscan is already installed, do you want to reinstall?", |
| 45 |
|
| timeout => 60, |
| 46 |
|
| ); |
| 47 |
|
| } |
| 48 |
|
| |
| 49 |
|
| my $bin; |
| 50 |
|
| my $confcmd = "./configure "; |
| 51 |
|
| $confcmd .= "--enable-user=$user "; |
| 52 |
|
| $confcmd .= $self->simscan_ripmime( $ver ); |
| 53 |
|
| $confcmd .= $self->simscan_clamav; |
| 54 |
|
| $confcmd .= $self->simscan_spamassassin; |
| 55 |
|
| $confcmd .= $self->simscan_regex; |
| 56 |
|
| $confcmd .= "--enable-received=y " if $self->conf->{'simscan_received'}; |
| 57 |
|
| $confcmd .= "--enable-spam-hits=$reje " if ($reje); |
| 58 |
|
| $confcmd .= "--enable-attach=y " if $self->conf->{'simscan_block_attachments'}; |
| 59 |
|
| $confcmd .= "--enable-qmaildir=$qdir " if $qdir; |
| 60 |
|
| $confcmd .= "--enable-qmail-queue=$qdir/bin/qmail-queue " if $qdir; |
| 61 |
|
| $confcmd .= "--enable-per-domain=y " if $self->conf->{'simscan_per_domain'}; |
| 62 |
|
| $confcmd .= "--enable-custom-smtp-reject=y " if $custom; |
| 63 |
|
| $confcmd .= "--enable-spam-passthru=y " if $self->conf->{'simscan_spam_passthru'}; |
| 64 |
|
| |
| 65 |
|
| if ( $self->conf->{'simscan_quarantine'} && -d $self->conf->{'simscan_quarantine'} ) { |
| 66 |
|
| $confcmd .= "--enable-quarantinedir=$self->conf->{'simscan_quarantine'}"; |
| 67 |
|
| } |
| 68 |
|
| |
| 69 |
|
| print "configure: $confcmd\n"; |
| 70 |
|
| my $patches = []; |
| 71 |
|
| push @$patches, 'simscan-1.4.0-clamav.3.patch' if $confcmd =~ /clamavdb/; |
| 72 |
|
| |
| 73 |
|
| $self->util->install_from_source( |
| 74 |
|
| 'package' => "simscan-$ver", |
| 75 |
|
| # site => 'http://www.inter7.com', |
| 76 |
|
| site => "http://downloads.sourceforge.net", |
| 77 |
|
| url => '/simscan', |
| 78 |
|
| targets => [ $confcmd, 'make', 'make install-strip' ], |
| 79 |
|
| bintest => "$qdir/bin/simscan", |
| 80 |
|
| source_sub_dir => 'mail', |
| 81 |
|
| patches => $patches, |
| 82 |
|
| patch_url => $self->conf->{'toaster_dl_site'}.$self->conf->{'toaster_dl_url'}.'/patches', |
| 83 |
|
| ); |
| 84 |
|
| |
| 85 |
|
| $self->config; |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| sub simscan_clamav { |
| 89 |
|
| my ( $self ) = @_; |
| 90 |
|
| |
| 91 |
|
| return '' if ! $self->conf->{'simscan_clamav'}; |
| 92 |
|
| |
| 93 |
|
| my $bin = $self->util->find_bin( "clamdscan", fatal => 0 ); |
| 94 |
|
| croak "couldn't find $bin, install ClamAV!\n" if !-x $bin; |
| 95 |
|
| |
| 96 |
|
| my $cmd .= "--enable-clamdscan=$bin "; |
| 97 |
|
| $cmd .= "--enable-clamavdb-path="; |
| 98 |
|
| $cmd .= -d "/var/db/clamav" ? "/var/db/clamav " |
| 99 |
|
| : -d "/usr/local/share/clamav" ? "/usr/local/share/clamav " |
| 100 |
|
| : -d "/opt/local/share/clamav" ? "/opt/local/share/clamav " |
| 101 |
|
| : croak "can't find the ClamAV db path!"; |
| 102 |
|
| |
| 103 |
|
| $bin = $self->util->find_bin( "sigtool", fatal => 0 ); |
| 104 |
|
| croak "couldn't find $bin, install ClamAV!" if ! -x $bin; |
| 105 |
|
| $cmd .= "--enable-sigtool-path=$bin "; |
| 106 |
|
| return $cmd; |
| 107 |
|
| }; |
| 108 |
|
| |
| 109 |
|
| sub config { |
| 110 |
|
| my $self = shift; |
| 111 |
|
| my %p = validate( @_, { $self->get_std_opts },); |
| 112 |
|
| |
| 113 |
|
| my ( $file, @lines ); |
| 114 |
|
| |
| 115 |
|
| my $reje = $self->conf->{'simscan_spam_hits_reject'}; |
| 116 |
|
| |
| 117 |
|
| my @attach; |
| 118 |
|
| if ( $self->conf->{'simscan_block_attachments'} ) { |
| 119 |
|
| |
| 120 |
|
| $file = "/var/qmail/control/ssattach"; |
| 121 |
|
| foreach ( split( /,/, $self->conf->{'simscan_block_types'} ) ) { |
| 122 |
|
| push @attach, ".$_"; |
| 123 |
|
| } |
| 124 |
|
| $self->util->file_write( $file, lines => \@attach ); |
| 125 |
|
| } |
| 126 |
|
| |
| 127 |
|
| $file = "/var/qmail/control/simcontrol"; |
| 128 |
|
| if ( !-e $file ) { |
| 129 |
|
| my @opts; |
| 130 |
|
| $self->conf->{'simscan_clamav'} |
| 131 |
|
| ? push @opts, "clam=yes" |
| 132 |
|
| : push @opts, "clam=no"; |
| 133 |
|
| |
| 134 |
|
| $self->conf->{'simscan_spamassassin'} |
| 135 |
|
| ? push @opts, "spam=yes" |
| 136 |
|
| : push @opts, "spam=no"; |
| 137 |
|
| |
| 138 |
|
| $self->conf->{'simscan_trophie'} |
| 139 |
|
| ? push @opts, "trophie=yes" |
| 140 |
|
| : push @opts, "trophie=no"; |
| 141 |
|
| |
| 142 |
|
| $reje |
| 143 |
|
| ? push @opts, "spam_hits=$reje" |
| 144 |
|
| : print "no reject.\n"; |
| 145 |
|
| |
| 146 |
|
| if ( @attach > 0 ) { |
| 147 |
|
| my $line = "attach="; |
| 148 |
|
| my $first = shift @attach; |
| 149 |
|
| $line .= "$first"; |
| 150 |
|
| foreach (@attach) { $line .= ":$_"; } |
| 151 |
|
| push @opts, $line; |
| 152 |
|
| } |
| 153 |
|
| |
| 154 |
|
| @lines = "#postmaster\@example.com:" . join( ",", @opts ); |
| 155 |
|
| push @lines, "#example.com:" . join( ",", @opts ); |
| 156 |
|
| push @lines, "#"; |
| 157 |
|
| push @lines, ":" . join( ",", @opts ); |
| 158 |
|
| |
| 159 |
|
| if ( -e $file ) { |
| 160 |
|
| $self->util->file_write( "$file.new", lines => \@lines ); |
| 161 |
|
| print |
| 162 |
|
| "\nNOTICE: simcontrol written to $file.new. You need to review and install it!\n"; |
| 163 |
|
| } |
| 164 |
|
| else { |
| 165 |
|
| $self->util->file_write( $file, lines => \@lines ); |
| 166 |
|
| } |
| 167 |
|
| } |
| 168 |
|
| |
| 169 |
|
| my $user = $self->conf->{'simscan_user'} || 'simscan'; |
| 170 |
|
| my $group = $self->conf->{'smtpd_run_as_group'} || 'qmail'; |
| 171 |
|
| |
| 172 |
|
| $self->util->syscmd( "pw user mod simscan -G qmail,clamav" ); |
| 173 |
|
| $self->util->chown( '/var/qmail/simscan', uid => $user, gid => $group ); |
| 174 |
|
| $self->util->chown( '/var/qmail/bin/simscan', uid => $user, gid=>$group ); |
| 175 |
|
| $self->util->chmod( dir => '/var/qmail/simscan', mode => '0770' ); |
| 176 |
|
| |
| 177 |
|
| if ( -x "/var/qmail/bin/simscanmk" ) { |
| 178 |
|
| $self->util->syscmd( "/var/qmail/bin/simscanmk" ); |
| 179 |
|
| system "/var/qmail/bin/simscanmk"; |
| 180 |
|
| } |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
|
| sub install_freebsd_port { |
| 184 |
|
| my $self = shift; |
| 185 |
|
| |
| 186 |
|
| my @args; |
| 187 |
|
| push @args, "SPAMC_ARGS=" . $self->conf->{simscan_spamc_args} if $self->conf->{simscan_spamc_args}; |
| 188 |
|
| push @args, 'SPAM_HITS=' . $self->conf->{simscan_spam_hits_reject} if $self->conf->{simscan_spam_hits_reject}; |
| 189 |
|
| push @args, 'SIMSCAN_USER=' . $self->conf->{simscan_user} if $self->conf->{simscan_user}; |
| 190 |
|
| push @args, 'QUARANTINE_DIR=' . $self->conf->{simscan_quarantine} if $self->conf->{'simscan_quarantine'}; |
| 191 |
|
| push @args, 'QMAIL_PREFIX=' . $self->conf->{qmail_dir} || '/var/qmail'; |
| 192 |
|
| |
| 193 |
|
| $self->freebsd->install_port( "simscan", |
| 194 |
|
| category => 'mail', |
| 195 |
|
| flags => join( ",", @args ), |
| 196 |
|
| options => "# Options for simscan-1.4.0_6 |
| 197 |
|
| _OPTIONS_READ=simscan-1.4.0_6 |
| 198 |
|
| _FILE_COMPLETE_OPTIONS_LIST=ATTACH CLAMAV DOMAIN DROPMSG DSPAM HEADERS PASSTHRU RIPMIME SPAMD USER |
| 199 |
|
| OPTIONS_FILE_SET+=ATTACH |
| 200 |
|
| OPTIONS_FILE_SET+=CLAMAV |
| 201 |
|
| OPTIONS_FILE_SET+=DOMAIN |
| 202 |
|
| OPTIONS_FILE_UNSET+=DROPMSG |
| 203 |
|
| OPTIONS_FILE_UNSET+=DSPAM |
| 204 |
|
| OPTIONS_FILE_SET+=HEADERS |
| 205 |
|
| OPTIONS_FILE_UNSET+=PASSTHRU |
| 206 |
|
| OPTIONS_FILE_SET+=RIPMIME |
| 207 |
|
| OPTIONS_FILE_SET+=SPAMD |
| 208 |
|
| OPTIONS_FILE_SET+=USER |
| 209 |
|
| ", |
| 210 |
|
| ); |
| 211 |
|
| |
| 212 |
|
| return $self->config; |
| 213 |
|
| }; |
| 214 |
|
| |
| 215 |
|
| sub simscan_regex { |
| 216 |
|
| my ($self) = @_; |
| 217 |
|
| return '' if ! $self->conf->{'simscan_regex_scanner'}; |
| 218 |
|
| |
| 219 |
|
| my $config = "--enable-regex=y "; |
| 220 |
|
| |
| 221 |
|
| if ( $OSNAME eq "freebsd" ) { |
| 222 |
|
| $self->freebsd->install_port( 'pcre' ); |
| 223 |
|
| $config .= "--with-pcre-include=/usr/local/include "; |
| 224 |
|
| } |
| 225 |
|
| else { |
| 226 |
|
| print "\n\nWARNING: is pcre installed?\n\n"; |
| 227 |
|
| } |
| 228 |
|
| return $config; |
| 229 |
|
| }; |
| 230 |
|
| |
| 231 |
|
| sub simscan_ripmime { |
| 232 |
|
| my ($self, $ver ) = @_; |
| 233 |
|
| |
| 234 |
|
| if ( ! $self->setup->is_newer( min => "1.0.8", cur => $ver ) ) { |
| 235 |
|
| print "ripmime doesn't work with simcan < 1.0.8\n"; |
| 236 |
|
| return ''; |
| 237 |
|
| }; |
| 238 |
|
| |
| 239 |
|
| return "--disable-ripmime " if ! $self->conf->{'simscan_ripmime'}; |
| 240 |
|
| |
| 241 |
|
| my $bin = $self->util->find_bin( "ripmime", fatal => 0, verbose=>0); |
| 242 |
|
| unless ( -x $bin ) { |
| 243 |
|
| croak "couldn't find $bin, install ripmime!\n"; |
| 244 |
|
| } |
| 245 |
|
| $self->setup->ripmime or return ''; |
| 246 |
|
| return "--enable-ripmime=$bin "; |
| 247 |
|
| }; |
| 248 |
|
| |
| 249 |
|
| sub simscan_spamassassin { |
| 250 |
|
| my ($self) = @_; |
| 251 |
|
| |
| 252 |
|
| return '' if ! $self->conf->{'simscan_spamassassin'}; |
| 253 |
|
| |
| 254 |
|
| my $spamc = $self->util->find_bin( "spamc", fatal => 0 ); |
| 255 |
|
| my $cmd = "--enable-spam=y --enable-spamc-user=y --enable-spamc=$spamc "; |
| 256 |
|
| |
| 257 |
|
| my $spamc_args = $self->conf->{'simscan_spamc_args'}; |
| 258 |
|
| $cmd .= "--enable-spamc-args=$spamc_args " if $spamc_args; |
| 259 |
|
| |
| 260 |
|
| if ( $self->conf->{'simscan_received'} ) { |
| 261 |
|
| my $bin = $self->util->find_bin( "spamassassin", fatal => 0 ); |
| 262 |
|
| croak "couldn't find $bin, install SpamAssassin!\n" if !-x $bin; |
| 263 |
|
| $cmd .= "--enable-spamassassin-path=$bin "; |
| 264 |
|
| } |
| 265 |
|
| return $cmd; |
| 266 |
|
| }; |
| 267 |
|
| |
| 268 |
|
| sub test { |
| 269 |
|
| my $self = shift; |
| 270 |
|
| my %p = validate( @_, { $self->get_std_opts },); |
| 271 |
|
| |
| 272 |
|
| my $qdir = $self->conf->{qmail_dir}; |
| 273 |
|
| |
| 274 |
|
| if ( ! $self->conf->{install_simscan} ) { |
| 275 |
|
| print "simscan installation disabled, skipping test!\n"; |
| 276 |
|
| return; |
| 277 |
|
| } |
| 278 |
|
| |
| 279 |
|
| print "testing simscan..."; |
| 280 |
|
| my $scan = "$qdir/bin/simscan"; |
| 281 |
|
| if ( ! -x $scan ) { |
| 282 |
|
| print "FAILURE: Simscan could not be found at $scan!\n"; |
| 283 |
|
| return; |
| 284 |
|
| } |
| 285 |
|
| |
| 286 |
|
| $ENV{"QMAILQUEUE"} = $scan; |
| 287 |
|
| $self->setup->test->email_send; |
| 288 |
|
| } |
| 289 |
|
| |
| 290 |
|
| 1; |