#============================================================================# # vHost - one-step solution for all virtual hosting needs # # V25pop3d - pop3d virtualization module # # # # Copyright(c) Chaogic Systems, LLC. http://chaogic.com # # Author: Jake Fan # # # # This is Free Software; permission to use, copy, modify, and distribute # # this software and its documentation for any purpose - with or without fee # # - is hereby granted, provided that the above copyright information and # # this permission notice appear in all copies and documentations. This # # software is provided "as is" without express or implied warranty. For # # more details, see GNU General Public License as published by the Free # # Software Foundation. # # # #============================================================================# $X eq "configuration" && do { ################################################ ### EDITABLE CONFIGURATIONS ################################################## ### pop3 daemon as specified (and not disabled) in $inetdCf (see $inetdCf in # "./V00hostconf"). when left blank, vhost will make $vpop3d (see below) a # separate inetd/xinetd service, in which case there must not be any other # pop3 daemon running either stand-alone or as an inetd/xinetd service. # $pop3d = "/usr/sbin/ipop3d"; $pop3d = "/usr/sbin/ipop3d"; ### command "vpop3d". # $vpop3d = "/usr/local/vhost/bin/vpop3d"; $vpop3d = "/usr/local/vhost/bin/vpop3d"; ### 1 = enable pop clients to use virtual hosts to relay mails ("pop before # smtp"). clients' ip addresses will be listed in "/etc/poprelay", which # is dynamically generated by command "vhost --poprelay" called by vpop3d # when clients request pop connections. each entry on the list is in the # form of "ip_address time_stamp". 0 = disable the feature. # $popRelay = "1"; $popRelay = "1"; ### the period of time in seconds during which an entry is allowed to stay on # the poprelay list. # $popTimer = "86400"; $popTimer = "86400"; ### DO NOT TOUCH ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING!! ### SanityChecking ########################################################### $ERR = 1, Error "$MOD: \$vpop3d = '$vpop3d'" if $vpop3d !~ /\A\/.*\/vpop3d\z/ || !-x $vpop3d; $ERR = 1, Error "$MOD: \$popRelay = '$popRelay'" if $popRelay !~ /\A[10]\z/; $ERR = 1, Error "$MOD: \$popTimer = '$popTimer'" if $popTimer !~ /\A\d+\z/; }; $X eq "initialization" && do { ############################################### my $ok; if ($ONCFG) { my $i = getgrnam "mail"; `touch /etc/poprelax $NERR` if !-e "/etc/poprelax"; `touch /etc/poprelay $NERR` if !-e "/etc/poprelay"; `chown 0:$i $mailDir $NERR` if $i && (stat $mailDir)[5] != $i; `chown 0:$GHID /etc/poprelax $NERR` if !-o "/etc/poprelax"; `chown 0:$GHID /etc/poprelay $NERR` if !-o "/etc/poprelay"; `chmod 0775 $mailDir $NERR` if $i && ((stat $mailDir)[2] & 07777) != 0775; `chmod 0600 /etc/poprelax $NERR` if ((stat "/etc/poprelax")[2] & 07777) != 0600; `chmod 0600 /etc/poprelay $NERR` if ((stat "/etc/poprelay")[2] & 07777) != 0600; $pop3d && grep (/^[^#]*(=|\s)\Q$pop3d\E(\s|$)/, Cat $_) && (-f $inetdCf || !grep /^\s*disable\s*=\s*yes(\s|$)/i, Cat $_) && ($pop3dCf = $_) && last for -f $inetdCf && $inetdCf || <$inetdCf/*>; $ERR = 1, Error ("$MOD: \$pop3d = '$pop3d'"), $ERR = 1, Error ("please adjust system configuration(s)", 1) if $pop3d && !$pop3dCf; $ERR && exit 1; $pop3dCf = $pop3dCf || -f $inetdCf && $inetdCf || "$inetdCf/vpop3d"; `touch $pop3dCf $NERR` if !-f $pop3dCf; } if (-f $inetdCf && $ONCFG) { Flock $pop3dCf, "+<", 0 if !grep /^[^#]*\/vpop3d(\s|$)/, Cat $pop3dCf; BackupCf $pop3dCf; $pop3d && s/^([^#]*\s)(\Q$pop3d\E(\s|$))/$1$vpop3d vpop3d $2/ && ($ok = 1) for @FILE; !$pop3d && -f FILE && ($ok = 1) && ($FILE[$#FILE+1] = <<"#"); pop3 stream tcp nowait root $vpop3d vpop3d # print FILE @FILE if $ok; Flock 0; } if (-d $inetdCf && $ONCFG) { Flock $pop3dCf, "+<", 0 if !grep /^[^#]*\/vpop3d(\s|$)/, Cat $pop3dCf; # BackupCf $pop3dCf; $pop3d && s/^\s*server\s*=\s*(\Q$pop3d\E(\s|$))/\tserver\t\t\t= $vpop3d\n\tserver_args\t\t= $1/i && ($ok = 1) for @FILE; !$pop3d && -f FILE && ($ok = 1) && (@FILE = (), $FILE[0] = <<"#"); service pop3 { disable = no socket_type = stream wait = no user = root server = $vpop3d log_on_success += HOST DURATION log_on_failure += HOST } # print FILE @FILE if $ok; Flock 0; } ReloadRc 0 if $ok; }; $X eq "reload" && do { ####################################################### ReloadRc $inetdRc if !$_f || $USER ne "root"; }; $X eq "poprelay" && do { ##################################################### my ($ok, @file0, @file1); my $i = CheckI ($ARGV[1]) && $ARGV[1]; my $s = $i && !$HOST && $USER eq "root" && $ARGV[2] + 0; my $t = $i && grep ((chomp, inm $i, $_), Cat "/etc/poprelax") || $s || time; Flock "/etc/poprelay", "+<", 0; @file0 = sort map {(split /\s+/)[0]} @FILE; @FILE = @FILE? ("") : (), $ok = 1 if !$popRelay; /^\s*(\S+)\s+(\d+)\s*$/ || s/.*//s, $i eq $1 && ($ok = 1), ($i eq $1 && $t || $2) + $popTimer < time && ($_ = ""), $i eq $1 && ($s || $2 < $t) && $_ && ($_ = "$i\t$t\n") for @FILE; $i && !$ok && $t + $popTimer > time && ($FILE[$#FILE+1] = "$i\t$t\n"); @FILE = sort {(split /\s+/, $a)[1] <=> (split /\s+/, $b)[1]} @FILE; @file1 = sort map {(split /\s+/)[0]} @FILE; print FILE @FILE; Flock 0; $popReload = !$i || "@file0" ne "@file1"; }; $X eq "finalization" && do { ################################################# ReloadRc $inetdRc if !$_q && $ARGV[0] =~ /^(addhost)$/; }; 1;