Logo
You
Code

Postfix, Courier, Saslauthd, MySQL, phpMyAdmin (Parte 3)

Autor YouCode - http://www.youcode.com.ar/postfix/postfix-courier-saslauthd-mysql-phpmyadmin-parte-3-95

Continuamos con la Parte 3

Instalamos amavisd-new, SpamAssassin y ClamAV

apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax
Ahora activaremos ClamAV y SpanAssassin
vi /etc/amavis/conf.d/15-content_filter_mode
el archivo debera quedar asi
use strict;

# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.

#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);


#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);

1;  # ensure a defined return
Hechenle una mirada al archivo vi /etc/amavis/conf.d/20-debian_defaults para que se familiaricen, este archivo no hace falta que lo cambiemos

Finalmente, editaremos el archivo 50-user para agregar la linea $pax='pax'; tal cual figura aqui
vi /etc/amavis/conf.d/50-user
use strict;

#
# Place your configuration directives here.  They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#

$pax='pax';
#------------ Do not modify anything below this line -------------
1;  # ensure a defined return
Agregamos el usuario clamav y amavis, luego reiniciamos
adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-daemon restart
/etc/init.d/clamav-freshclam restart
Configuraremos postfix para que reciba los emails atrvez de amavisd-new
postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'
agregamos las siguientes lineas al archivo de configuracion
vi /etc/postfix/master.cf
[...]
amavis unix - - - - 2 smtp
        -o smtp_data_done_timeout=1200
        -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - - - - smtpd
        -o content_filter=
        -o local_recipient_maps=
        -o relay_recipient_maps=
        -o smtpd_restriction_classes=
        -o smtpd_client_restrictions=
        -o smtpd_helo_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks=127.0.0.0/8
        -o strict_rfc821_envelopes=yes
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
        -o smtpd_bind_address=127.0.0.1
reiniciamos postfix
/etc/init.d/postfix restart
Hechemos un vistazo para ver que todo este en funcionamiento
netstat -tap
y deberiamos tener algo asi

root@server1:/etc/courier# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:sunrpc                *:*                     LISTEN      605/portmap
tcp        0      0 *:ssh                   *:*                     LISTEN      1110/sshd
tcp        0      0 *:55384                 *:*                     LISTEN      617/rpc.statd
tcp        0      0 *:smtp                  *:*                     LISTEN      23615/master
tcp        0      0 localhost.localdo:10024 *:*                     LISTEN      22454/amavisd (mast
tcp        0      0 localhost.localdo:10025 *:*                     LISTEN      23615/master
tcp        0      0 localhost.localdo:mysql *:*                     LISTEN      3838/mysqld
tcp        0     52 server1.example.com:ssh 192.168.0.199:3809      ESTABLISHED 1136/0
tcp6       0      0 [::]:pop3               [::]:*                  LISTEN      19519/couriertcpd
tcp6       0      0 [::]:imap2              [::]:*                  LISTEN      19476/couriertcpd
tcp6       0      0 [::]:www                [::]:*                  LISTEN      4429/apache2
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      1110/sshd
tcp6       0      0 [::]:imaps              [::]:*                  LISTEN      19503/couriertcpd
tcp6       0      0 [::]:pop3s              [::]:*                  LISTEN      19536/couriertcpd
root@server1:/etc/courier#


Instalando las notificaciones de las quotas

Lo que esto ara es de enviarle un mail a los usuario notificandoles que su casilla esta n% de su capacidad

cd /usr/local/sbin/
vi quota_notify
#!/usr/bin/perl -w

# Author <jps@tntmax.com>
#
# This script assumes that virtual_mailbox_base in defined
# in postfix's main.cf file. This directory is assumed to contain
# directories which themselves contain your virtual user's maildirs.
# For example:
#
# -----------/
#            |
#            |
#    home/vmail/domains/
#        |          |
#        |          |
#  example.com/  foo.com/
#                   |
#                   |
#           -----------------
#           |       |       |
#           |       |       |
#         user1/   user2/  user3/
#                           |
#                           |
#                        maildirsize
#

use strict;

my $POSTFIX_CF = "/etc/postfix/main.cf";
my $MAILPROG = "/usr/sbin/sendmail -t";
my $WARNPERCENT = 80;
my @POSTMASTERS = ('postmaster@domain.tld');
my $CONAME = 'My Company';
my $COADDR = 'postmaster@domain.tld';
my $SUADDR = 'postmaster@domain.tld';
my $MAIL_REPORT = 1;
my $MAIL_WARNING = 1;

#get virtual mailbox base from postfix config
open(PCF, "< $POSTFIX_CF") or die $!;
my $mboxBase;
while (<PCF>) {
   next unless /virtual_mailbox_base\s*=\s*(.*)\s*/;
   $mboxBase = $1;
}
close(PCF);

#assume one level of subdirectories for domain names
my @domains;
opendir(DIR, $mboxBase) or die $!;
while (defined(my $name = readdir(DIR))) {
   next if $name =~ /^\.\.?$/;        #skip '.' and '..'
   next unless (-d "$mboxBase/$name");
   push(@domains, $name);
}
closedir(DIR);
#iterate through domains for username/maildirsize files
my @users;
chdir($mboxBase);
foreach my $domain (@domains) {
        opendir(DIR, $domain) or die $!;
        while (defined(my $name = readdir(DIR))) {
           next if $name =~ /^\.\.?$/;        #skip '.' and '..'
           next unless (-d "$domain/$name");
      push(@users, {"$name\@$domain" => "$mboxBase/$domain/$name"});
        }
}
closedir(DIR);

#get user quotas and percent used
my (%lusers, $report);
foreach my $href (@users) {
   foreach my $user (keys %$href) {
      my $quotafile = "$href->{$user}/maildirsize";
      next unless (-f $quotafile);
      open(QF, "< $quotafile") or die $!;
      my ($firstln, $quota, $used);
      while (<QF>) {
         my $line = $_;
              if (! $firstln) {
                 $firstln = 1;
                 die "Error: corrupt quotafile $quotafile"
                    unless ($line =~ /^(\d+)S/);
                 $quota = $1;
            last if (! $quota);
            next;
         }
         die "Error: corrupt quotafile $quotafile"
            unless ($line =~ /\s*(-?\d+)/);
         $used += $1;
      }
      close(QF);
      next if (! $used);
      my $percent = int($used / $quota * 100);
      $lusers{$user} = $percent unless not $percent;
   }
}

#send a report to the postmasters
if ($MAIL_REPORT) {
   open(MAIL, "| $MAILPROG");
   select(MAIL);
   map {print "To: $_\n"} @POSTMASTERS;
   print "From: $COADDR\n";
   print "Subject: Daily Quota Report.\n";
   print "DAILY QUOTA REPORT:\n\n";
   print "----------------------------------------------\n";
   print "| % USAGE |            ACCOUNT NAME          |\n";
   print "----------------------------------------------\n";
   foreach my $luser ( sort { $lusers{$b} <=> $lusers{$a} } keys %lusers ) {
      printf("|   %3d   | %32s |\n", $lusers{$luser}, $luser);
      print "---------------------------------------------\n";
   }
        print "\n--\n";
        print "$CONAME\n";
        close(MAIL);
}

#email a warning to people over quota
if ($MAIL_WARNING) {
        foreach my $luser (keys (%lusers)) {
           next unless $lusers{$luser} >= $WARNPERCENT;       # skip those under quota
           open(MAIL, "| $MAILPROG");
           select(MAIL);
           print "To: $luser\n";
      map {print "BCC: $_\n"} @POSTMASTERS;
           print "From: $SUADDR\n";
           print "Subject: WARNING: Your mailbox is $lusers{$luser}% full.\n";
           print "Reply-to: $SUADDR\n";
           print "Your mailbox: $luser is $lusers{$luser}% full.\n\n";
           print "Once your e-mail box has exceeded your monthly storage quota\n";
      print "your monthly billing will be automatically adjusted.\n";
      print "Please consider deleting e-mail and emptying your trash folder to clear some space.\n\n";
           print "Contact <$SUADDR> for further assistance.\n\n";
           print "Thank You.\n\n";
           print "--\n";
           print "$CONAME\n";
           close(MAIL);
        }
}
ajustamos los permisos
chmod 755 quota_notify
Vamos al cron del linux y agregamos el codigo para que se ejecute la quota
crontab -e
se ejecutara todos los dias a las 0 horas 0 minutos
0 0 * * * /usr/local/sbin/quota_notify &> /dev/null
Continuamos en la parte 4
http://www.youcode.com.ar/postfix/postfix-courier-saslauthd-mysql-phpmyadmin-parte-4-96
http://www.youcode.com.ar/postfix/postfix-courier-saslauthd-mysql-phpmyadmin-parte-3-95