initial commit of file from CVS for smeserver-fetchmail on Sat Sep 7 19:53:47 AEST 2024
This commit is contained in:
137
root/etc/e-smith/templates/etc/crontab/FetchMails
Normal file
137
root/etc/e-smith/templates/etc/crontab/FetchMails
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
{
|
||||
use esmith::config;
|
||||
use esmith::db;
|
||||
|
||||
$OUT = '';
|
||||
|
||||
local %services;
|
||||
$services{'fetchmail'} = $fetchmail;
|
||||
|
||||
if ( ( $FetchMails{ status } || "disabled" ) eq "enabled" ) {
|
||||
|
||||
if ( ( $fetchmail{ status } || "disabled" ) eq "enabled" &&
|
||||
( $fetchmail{ Method } || "standard" ) ne "standard" ) {
|
||||
} else {
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# fetchmail times during office hours\n";
|
||||
$OUT .= "\n";
|
||||
|
||||
my $FetchmailFreqOffice =
|
||||
db_get_prop(\%services, "fetchmail", 'FreqOffice');
|
||||
if ($FetchmailFreqOffice)
|
||||
{
|
||||
if ($FetchmailFreqOffice eq 'every5min')
|
||||
{
|
||||
$OUT .= "*/5\t8-17\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOffice eq 'every15min')
|
||||
{
|
||||
$OUT .= "*/15\t8-17\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOffice eq 'every30min')
|
||||
{
|
||||
$OUT .= "*/30\t8-17\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOffice eq 'everyhour')
|
||||
{
|
||||
$OUT .= "0\t8-17\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOffice eq 'every2hrs')
|
||||
{
|
||||
$OUT .= "0\t8-17/2\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqOffice - never\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqOffice - not defined\n";
|
||||
}
|
||||
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# fetchmail times outside office hours\n";
|
||||
$OUT .= "\n";
|
||||
|
||||
my $FetchmailFreqOutside =
|
||||
db_get_prop(\%services, "fetchmail", 'FreqOutside');
|
||||
if ($FetchmailFreqOutside)
|
||||
{
|
||||
if ($FetchmailFreqOutside eq 'every5min')
|
||||
{
|
||||
$OUT .= "*/5\t0-7\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
$OUT .= "*/5\t18-23\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOutside eq 'every15min')
|
||||
{
|
||||
$OUT .= "*/15\t0-7\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
$OUT .= "*/15\t18-23\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOutside eq 'every30min')
|
||||
{
|
||||
$OUT .= "*/30\t0-7\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
$OUT .= "*/30\t18-23\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOutside eq 'everyhour')
|
||||
{
|
||||
$OUT .= "0\t0-7\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
$OUT .= "0\t18-23\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqOutside eq 'every2hrs')
|
||||
{
|
||||
$OUT .= "0\t0-7/2\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
$OUT .= "0\t18-23/2\t*\t*\t1-5\troot\t/etc/startmail\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqOutside - never\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqOutside - not defined\n";
|
||||
}
|
||||
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# fetchmail times during the weekend\n";
|
||||
$OUT .= "\n";
|
||||
|
||||
my $FetchmailFreqWeekend =
|
||||
db_get_prop(\%services, "fetchmail", 'FreqWeekend');
|
||||
if ($FetchmailFreqWeekend)
|
||||
{
|
||||
if ($FetchmailFreqWeekend eq 'every5min')
|
||||
{
|
||||
$OUT .= "*/5\t*\t*\t*\t6-7\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqWeekend eq 'every15min')
|
||||
{
|
||||
$OUT .= "*/15\t*\t*\t*\t6-7\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqWeekend eq 'every30min')
|
||||
{
|
||||
$OUT .= "*/30\t*\t*\t*\t6-7\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqWeekend eq 'everyhour')
|
||||
{
|
||||
$OUT .= "0\t*\t*\t*\t6-7\troot\t/etc/startmail\n";
|
||||
}
|
||||
elsif ($FetchmailFreqWeekend eq 'every2hrs')
|
||||
{
|
||||
$OUT .= "0\t*/2\t*\t*\t6-7\troot\t/etc/startmail\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqWeekend - never\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "# FetchmailFreqWeekend - not defined\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
363
root/etc/e-smith/templates/etc/fetchmail/90fetchmail
Normal file
363
root/etc/e-smith/templates/etc/fetchmail/90fetchmail
Normal file
@@ -0,0 +1,363 @@
|
||||
{
|
||||
# vim: ft=perl ts=4 sw=4 et:
|
||||
package esmith;
|
||||
use strict;
|
||||
use Errno;
|
||||
use esmith::util;
|
||||
# ADDs by PS :
|
||||
use esmith::ConfigDB ;
|
||||
use esmith::AccountsDB ;
|
||||
|
||||
use constant FS => "," ;
|
||||
use constant RS => ";" ;
|
||||
$OUT ='';
|
||||
|
||||
# Access to databases 'New Look' ! (PS)
|
||||
my $db = esmith::ConfigDB->open
|
||||
or die "Can't open the Config database : $!\n" ;
|
||||
my $accountdb = esmith::AccountsDB->open
|
||||
or die "Can't open the Account database : $!\n" ;
|
||||
|
||||
my @users = $accountdb->get('admin');
|
||||
push @users, $accountdb->users();
|
||||
unless (scalar @users)
|
||||
{
|
||||
$OUT .="#\n#\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
# In some cases, it's not adviseable to have the
|
||||
# local SMTP server set as mail.$domain
|
||||
# my $dom = "mail.".$db->get_value('DomainName') ;
|
||||
my $dom = $db->get_value('DomainName') ;
|
||||
#
|
||||
# convert the old configuration with this
|
||||
#
|
||||
# here, we need maybe to do a doble conversion :
|
||||
# old form to 1.0.2 form
|
||||
# 1.0.2 to 1.3 form
|
||||
my $maxmbox=20;
|
||||
my $mdrop=$db->get_value('MDrop');
|
||||
my $FM=$db->get('FetchMails');
|
||||
if ( not defined $FM ) {
|
||||
$FM = $db->new_record('FetchMails', { type => '' } ) ;
|
||||
}
|
||||
my $UsersDatasToConvert = 0 ;
|
||||
|
||||
if( not defined $mdrop)
|
||||
# form is not 'before 1.0.2' like
|
||||
{
|
||||
my $type=$FM->prop('type') ;
|
||||
if( (not defined $type) || ($type eq '') )
|
||||
# FetchMails record is not defined at all
|
||||
{
|
||||
$FM->set_prop( 'type', 'service' ) ;
|
||||
$FM->set_prop( 'status', 'disabled' ) ;
|
||||
$FM->set_prop( 'Routing', 'YES' ) ;
|
||||
} elsif ( $type eq 'custom_service' ) { # 1.0.2 like database
|
||||
$UsersDatasToConvert = 1 ;
|
||||
$FM->set_prop( 'type', 'service' ) ;
|
||||
$FM->set_prop( 'status', 'enabled' ) ;
|
||||
$FM->delete_prop('Lang') ;
|
||||
$FM->delete_prop('MDrop');
|
||||
$FM->delete_prop('MDropServ');
|
||||
$FM->delete_prop('MDropName');
|
||||
$FM->delete_prop('MDropPass');
|
||||
$FM->delete_prop('MDropEnv');
|
||||
$FM->delete_prop('MDropDebug');
|
||||
$FM->delete_prop('MDropDomain1');
|
||||
$FM->delete_prop('MDropDomain2');
|
||||
$FM->delete_prop('MDropDomain3');
|
||||
$FM->delete_prop('MaxMailBox');
|
||||
$FM->delete_prop('OrigMDrop');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
# Data base is in 'before 1.0.2' format
|
||||
$UsersDatasToConvert = 1 ;
|
||||
$FM->set_prop( 'type', 'service' ) ;
|
||||
$FM->set_prop( 'status', 'enabled' ) ;
|
||||
$db->delete('MDropServ');
|
||||
$db->delete('MDropName');
|
||||
$db->delete('MDropPass');
|
||||
$db->delete('MDropEnv');
|
||||
$db->delete('MDrop');
|
||||
$db->delete('MDropDebug');
|
||||
}
|
||||
|
||||
# starting with version 1.3.4, there is a 'version' field in the
|
||||
# configuration database.
|
||||
# so, if the version in database is below the version of
|
||||
# smeserver-fetchmail, User accounts need to be converted.
|
||||
my $version = $FM->prop('version') || 0 ;
|
||||
$version =~s/[-\.]/0/g ;
|
||||
|
||||
my $packversion = 0 ;
|
||||
if ( open VER, "/etc/e-smith/db/configuration/defaults/FetchMails/version" ) {
|
||||
$packversion = <VER> ;
|
||||
chomp $packversion ;
|
||||
}
|
||||
close VER ;
|
||||
my $packver = $packversion ;
|
||||
$packversion =~s/[-\.]/0/g ;
|
||||
if ( $packversion gt $version ) {
|
||||
$UsersDatasToConvert = 1 ;
|
||||
$FM->set_prop('version', $packver ) ;
|
||||
}
|
||||
|
||||
# Do we need to convert account Datas in user DataBases ?
|
||||
if ( $UsersDatasToConvert ) {
|
||||
my %ToConvert=( 'NumBox' => 'FM-NumBox',
|
||||
'FetchMailAccounts' => 'FM-Accounts',
|
||||
'MailCopyTo' => 'FM-MailCopyTo',
|
||||
'ghost' => 'FM-Ghost',
|
||||
'DebugOption' => 'FM-DebugOption',
|
||||
'KeepOption' => 'FM-KeepOption',
|
||||
'TransName' => 'FM-TransName' ) ;
|
||||
|
||||
foreach my $u ( @users ) {
|
||||
# starting with version 1.3.1 : var names change in
|
||||
# users database
|
||||
foreach my $convert ( keys %ToConvert ) {
|
||||
if ( defined ( $u->prop($convert) ) ) {
|
||||
$u->set_prop($ToConvert{$convert}, $u->prop($convert) ) ;
|
||||
$u->delete_prop($convert) ;
|
||||
}
|
||||
}
|
||||
# special case : SpyOption is converted to MailCopyTo admin
|
||||
if ( defined ( $u->prop( 'SpyOption' ) ) ) {
|
||||
if ( $u->prop( 'SpyOption' ) eq 'YES' ) {
|
||||
my $MailCopyTo = ( $u->prop( 'FM-MailCopyTo') || '' ) ;
|
||||
if ( $MailCopyTo eq '' ) { $MailCopyTo = 'admin' }
|
||||
else { $MailCopyTo = 'admin,' . $MailCopyTo }
|
||||
$u->set_prop( 'FM-MailCopyTo', $MailCopyTo );
|
||||
}
|
||||
$u->delete_prop( 'SpyOption' ) ;
|
||||
}
|
||||
# starting with version 1.3.3, TransOption (who can conflict with
|
||||
# Ghost is removed. If a transName is set, we use it. If not, we don't ;-)
|
||||
# but, before removing, there a try to find a good mode for 'FM-Ghost'
|
||||
# that is :
|
||||
# if TransOption != 'FORWARD' no change to 'FM-Ghost'
|
||||
# if 'FM-Ghost' == 'YES', no change
|
||||
# if there no 'mail-copy-to' --> 'FM-Ghost' set to 'YES'
|
||||
if ( defined $u->prop( 'TransOption' ) ) {
|
||||
if ( $u->prop( 'TransOption' ) eq 'FORWARD' ) {
|
||||
my $ghost = $u->prop( 'FM-Ghost' ) || 'NO' ;
|
||||
if ( $ghost eq 'NO' ) {
|
||||
my $mailCopyTo = $u->prop( 'FM-MAilCopyTo' ) || '' ;
|
||||
if ( $mailCopyTo eq '' ) {
|
||||
$u->set_prop( 'FM-Ghost', 'YES' ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
$u->delete_prop( 'TransOption' ) ;
|
||||
}
|
||||
|
||||
my @MailData ; my @MailRemove ;
|
||||
my $i = 0 ;
|
||||
for ( $i = 1 ; $i <= 20 ; $i++ ) {
|
||||
my $MS='MailServ' . $i ;
|
||||
my $MT='MailType' . $i ;
|
||||
my $MN='MailName' . $i ;
|
||||
my $MP='MailPass' . $i ;
|
||||
if ( defined ( $u->prop($MS) ) && defined ( $u->prop($MT) ) &&
|
||||
defined ( $u->prop($MN) ) && defined ( $u->prop($MP) ) ) {
|
||||
push @MailRemove, $i ;
|
||||
my $Rec = $u->prop($MS) . FS . $u->prop($MT) . FS ;
|
||||
$Rec .= unpack( "H*", $u->prop($MN) ) . FS ;
|
||||
$Rec .= unpack( "H*", $u->prop($MP) ) ;
|
||||
push @MailData, $Rec ;
|
||||
}
|
||||
}
|
||||
$u->set_prop('FM-Accounts', join( RS, @MailData ) ) if scalar ( @MailData ) ;
|
||||
# Old data are removed only after writing the new look datas.
|
||||
foreach my $remove ( @MailRemove ) {
|
||||
my $MS='MailServ' . $remove ;
|
||||
my $MT='MailType' . $remove ;
|
||||
my $MN='MailName' . $remove ;
|
||||
my $MP='MailPass' . $remove ;
|
||||
$u->delete_prop($MS) ;
|
||||
$u->delete_prop($MT) ;
|
||||
$u->delete_prop($MN) ;
|
||||
$u->delete_prop($MP) ;
|
||||
}
|
||||
|
||||
# Specials tests. Only needed for sanity check in case of
|
||||
# some versions between 1.0.2 and 1.3.4 are in the wild
|
||||
# should normaly not be the case...
|
||||
if (defined $u->prop('FM-Accounts') ) {
|
||||
my $FMAccounts = $u->prop('FM-Accounts') ;
|
||||
# News fields and records separators
|
||||
$FMAccounts =~ s/\037/;/g ;
|
||||
$FMAccounts =~ s/\036/,/g ;
|
||||
# shall we convert to hex ???
|
||||
my @Recs = split ( RS, $FMAccounts ) ;
|
||||
my $toconv = 0 ;
|
||||
foreach my $rec ( @Recs ) {
|
||||
my @R = split( FS, $rec ) ;
|
||||
if ( "$R[2]$R[3]" =~ /[A-Zg-z\W]/ ) {
|
||||
$toconv = 1 ;
|
||||
}
|
||||
}
|
||||
if ( $toconv ) {
|
||||
my @Recs2 ;
|
||||
foreach my $rec ( @Recs ) {
|
||||
my @R = split ( FS, $rec ) ;
|
||||
$R[2] = unpack( "H*", $R[2] ) ;
|
||||
$R[3] = unpack( "H*", $R[3] ) ;
|
||||
push @Recs2, join( FS, @R ) ;
|
||||
}
|
||||
$FMAccounts = join( RS, @Recs2) ;
|
||||
}
|
||||
$u->set_prop('FM-Accounts', $FMAccounts) ;
|
||||
}
|
||||
}
|
||||
# Here, the mails groups need to be generated...
|
||||
# But we don't need to put that in this file :
|
||||
# in a normal way, the database conversion is done at install time
|
||||
# and at install time, the group are build after the conversion
|
||||
}
|
||||
|
||||
#
|
||||
# End of Data conversion...
|
||||
#
|
||||
|
||||
# New test : if FetchMails status is 'disabled', we don't want that
|
||||
# this part of /etc/fetchmail be generated.
|
||||
|
||||
if ( $FM->prop('status') eq 'enabled' ) {
|
||||
foreach my $account ( @users ) {
|
||||
my $FetchN=0;
|
||||
my $Debug = $account->prop( 'FM-DebugOption' ) || '' ;
|
||||
my $spy = $account->prop( 'FM-SpyOption' ) || '' ;
|
||||
my $keepopt = $account->prop( 'FM-KeepOption' ) || '' ;
|
||||
my $transname = $account->prop( 'FM-TransName') || '' ;
|
||||
my $usergt = $account->prop( 'FM-MailCopyTo') || '' ;
|
||||
my $ghost = $account->prop( 'FM-Ghost') || 'NO' ;
|
||||
|
||||
my $name = $account->key ;
|
||||
my $comment = $name ;
|
||||
my $maxcpy = 0;
|
||||
|
||||
if ( $transname ne '' ) {
|
||||
$transname =~ s/:/,/g ;
|
||||
if ( $usergt eq '' ) { $usergt = $transname }
|
||||
else { $usergt = $usergt . "," . $transname }
|
||||
}
|
||||
|
||||
if($usergt ne '') {
|
||||
$name = "fm_fm-" . $name ;
|
||||
my $comment2 = '' ;
|
||||
$comment2 = $comment . "," if ( $ghost ne 'YES' ) ;
|
||||
$comment = "$comment delivered to : $name = $comment2 $usergt";
|
||||
}
|
||||
|
||||
# PS 2005/08/02 -> 1.3.4-05
|
||||
# tristate combination for the delivering host :
|
||||
# 1) if 'FetchMails->fetchhost' is set then this is the delivery host
|
||||
# This should normally never be the case...
|
||||
# 2) If the (systemWide) 'SMTPSmartHost is set, then this is the delivey host for fetchmail
|
||||
# 3) If none of these are set, then the delivery host is set to the domain name of the computer
|
||||
# BTW, correcting a bug preventing previous version to use the SMTPSmartHost value...
|
||||
# PS 2005/08/19 ->1.3.4-06
|
||||
# considerable mistake ! I had an automagical configuration whistle, but not the good one.
|
||||
# I Said that if a smartHost is set, fetchmail must send incoming mails to the SmartHost.
|
||||
# But SmartHosts are for Outgoing mails !
|
||||
# Now, fetchmail automagically send mail to a DelegateMailServer, if set-up.
|
||||
my $DestSMTPServer = $FM->prop( 'fetchhost' ) || '' ;
|
||||
# my $SMTPSmartHost = $db->get( 'SMTPSmartHost' );
|
||||
# $smarthost = $SMTPSmartHost->value || '' if ( $smarthost eq '' ) ;
|
||||
# DelegateMailServer not ever exists...
|
||||
if ( my $DelegateMailServer = $db->get( 'DelegateMailServer' ) ) {
|
||||
$DestSMTPServer = $DelegateMailServer->value || '' if ( $DestSMTPServer eq '' ) ;
|
||||
}
|
||||
|
||||
if( $DestSMTPServer ne '')
|
||||
{ $DestSMTPServer = "smtpaddress $DestSMTPServer" ; }
|
||||
else
|
||||
{ $DestSMTPServer = "smtpaddress $dom" ; }
|
||||
|
||||
my $keep='fetchall';
|
||||
|
||||
if($keepopt eq "YES") { $keep='keep'; }
|
||||
elsif($keepopt eq "NEW") { $keep='no fetchall'; }
|
||||
|
||||
# Change by PS
|
||||
my $FetchMailsAcc = '' ;
|
||||
if ( defined $account->prop( 'FM-Accounts' ) ) {
|
||||
$FetchMailsAcc = $account->prop( 'FM-Accounts' ) ;
|
||||
}
|
||||
my @FetchMailAccounts = split RS, $FetchMailsAcc ;
|
||||
|
||||
foreach my $FetchMailAcount ( @FetchMailAccounts ) {
|
||||
$FetchN++ ;
|
||||
my ( $mserv, $mtype, $mname, $mpass, $moptions ) = split FS, $FetchMailAcount ;
|
||||
if(not defined $mserv ) { $mserv='';}
|
||||
if(not defined $mname ) { $mname='';}
|
||||
if(not defined $mpass ) { $mpass='';}
|
||||
if(not defined $mtype ) { $mtype='';}
|
||||
if(not defined $moptions ) { $moptions='';}
|
||||
|
||||
# we need to convert the name, the password and the options from HEX to text
|
||||
$mname = pack( "H*", $mname );
|
||||
$mpass = pack( "H*", $mpass );
|
||||
$moptions = pack( "H*", $moptions );
|
||||
|
||||
if ($mserv ne '') {
|
||||
my $ServOpt = ' and options uidl no dns';
|
||||
|
||||
if($mtype =~ /IMAP/ ) { $ServOpt = ' and options no dns'; }
|
||||
|
||||
# ver 1.3.5-01 : add a timeout option
|
||||
# this option is equal to the value timeout in the
|
||||
# FetchMails service configuration
|
||||
$ServOpt = ' timeout ' . ( $FM->prop('timeout') || 60 ) . $ServOpt;
|
||||
|
||||
if ( $mtype =~ s/^S// ) { $moptions = "ssl $moptions" }
|
||||
|
||||
#We retrieve the $qmail{MaxMessageSize} to fix
|
||||
#the max limit where emails won't be downloaded
|
||||
my $size = $db->get_prop('qmail','MaxMessageSize') || '0';
|
||||
my $mdbg='-l' . $size . ' -d0 --silent --syslog';
|
||||
if($Debug eq "YES") { $mdbg='-l' . $size . ' -d0 --verbose --syslog'; }
|
||||
$mdbg .= " -i /var/lib/fetchmail/.fetchids "; # fix SME: 11979
|
||||
|
||||
my $staticvalue = "/usr/bin/fetchmail $mdbg --fetchmailrc - <<EOF\n" ;
|
||||
$staticvalue .= "set postmaster \"postmaster\@$dom\"\n" ;
|
||||
$staticvalue .= "set bouncemail\nset no softbounce\nset properties \"\"\n" ;
|
||||
|
||||
# special case : the \ must be changed to \x5c !
|
||||
$mname =~ s/[\\]/\\x5c/g ;
|
||||
$mpass =~ s/[\\]/\\x5c/g ;
|
||||
# escape some odd characters by \ (just add them between the [] if needed
|
||||
$mname =~ s/([\^\$\@\'\"\`])/\\$1/g ;
|
||||
$mpass =~ s/([\^\$\@\'\"\`])/\\$1/g ;
|
||||
# special case : the ' must be quoted another way
|
||||
$mname =~ s/[\']/\\x27/g ;
|
||||
$mpass =~ s/[\']/\\x27/g ;
|
||||
|
||||
#find the tcp port of smtpd
|
||||
my $tcpport = $db->get_prop('smtpd','TCPPort')||'25';
|
||||
|
||||
$OUT .= "#\n";
|
||||
$OUT .= "# Mail N$FetchN Account for : $comment\n";
|
||||
$OUT .= $staticvalue;
|
||||
$OUT .= "poll $mserv with proto $mtype$ServOpt\n";
|
||||
$OUT .= " user '$mname' $DestSMTPServer with password '";
|
||||
$OUT .= "$mpass' is $name here $keep\n";
|
||||
if ( $moptions ne '' ) {
|
||||
$OUT .= " options $moptions\n";
|
||||
}
|
||||
$OUT .= " smtphost 127.0.0.200/$tcpport" . "\n";
|
||||
$OUT .= " antispam 550\n";
|
||||
$OUT .="EOF\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$OUT .="#\n#\n";
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
$OUT .= <<HERE;
|
||||
|
||||
LOCALIP=\$\(/sbin/e-smith/db configuration get LocalIP\)
|
||||
if [ -z "\$LOCALIP" ]
|
||||
then
|
||||
# Set LOCALIP to internal loopback
|
||||
OUTERNET=127.0.0.1
|
||||
fi
|
||||
|
||||
HERE
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
{
|
||||
$OUT = '';
|
||||
|
||||
my $routing = $FetchMails{ "Routing" } || "YES" ;
|
||||
if ( $routing eq "NO" ) {
|
||||
|
||||
# Users on LAN are not allowed to access to POP3 or IMAP4
|
||||
# servers on Internet.
|
||||
|
||||
# Block any outgoing connections to POP3 servers
|
||||
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 110\\\n";
|
||||
$OUT .= "\t--jump LOG --log-prefix \"denylogfetchmail: \"\n";
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 110 --jump DROP\n";
|
||||
|
||||
# Block any outgoing connections to IMAP4 servers
|
||||
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 143\\\n";
|
||||
$OUT .= "\t--jump LOG --log-prefix \"denylogfetchmail: \"\n";
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 143 --jump DROP\n";
|
||||
|
||||
}
|
||||
my $routingNNTP = $FetchMails{ "RoutingNNTP" } || "YES" ;
|
||||
if ( $routingNNTP eq "NO" ) {
|
||||
|
||||
# Users on LAN are not allowed to access to news
|
||||
# servers on Internet.
|
||||
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 119\\\n";
|
||||
$OUT .= "\t--jump LOG --log-prefix \"denylogfetchmail: \"\n";
|
||||
$OUT .= " /sbin/iptables --append FORWARD\\\n";
|
||||
$OUT .= "\t-i \$INTERNALIF -p tcp ! --dst \$LOCALIP --dport 119 --jump DROP\n";
|
||||
|
||||
}
|
||||
}
|
50
root/etc/e-smith/templates/etc/startmail/90FetchMails
Normal file
50
root/etc/e-smith/templates/etc/startmail/90FetchMails
Normal file
@@ -0,0 +1,50 @@
|
||||
{
|
||||
my $status = $FetchMails{status};
|
||||
my $fetchmailstatus = "disabled" ;
|
||||
$fetchmailstatus = $fetchmail{ status } if ( defined $fetchmail{ status } );
|
||||
if (defined $status)
|
||||
{
|
||||
if ($status eq "enabled" && $fetchmailstatus ne "enabled" )
|
||||
{
|
||||
$command = "/bin/su - qmailr -s /bin/bash -c \\\n";
|
||||
$command .= "\t\"FETCHMAILHOME=/var/lock/fetchmail";
|
||||
$command .= " /etc/fetchmail\"";
|
||||
|
||||
if ($AccessType eq 'dialup')
|
||||
{
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# FetchMail dialup connection; if we're already connected, ";
|
||||
$OUT .= "call fetchmail.\n";
|
||||
$OUT .= "# otherwise, bring up the line (which will invoke ";
|
||||
$OUT .= "fetchmail in\n";
|
||||
$OUT .= "# the ip-up script).\n";
|
||||
$OUT .= "\n";
|
||||
$OUT .= "if /sbin/ifconfig | /bin/grep -q 'ppp'\n";
|
||||
$OUT .= "then\n";
|
||||
$OUT .= " ${command}\n";
|
||||
$OUT .= "else\n";
|
||||
$OUT .= " /usr/bin/killall -USR1 diald\n";
|
||||
$OUT .= "fi\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# FetchMails dedicated connection; just call fetchmail to get ";
|
||||
$OUT .= "things started\n";
|
||||
$OUT .= "${command}\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# This service FetchMail has been flagged as 'disabled'\n";
|
||||
$OUT .= "# in the e-smith services database.\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$OUT .= "\n";
|
||||
$OUT .= "# This service FetchMail does not exist in the e-smith services";
|
||||
$OUT .= " database.\n";
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
{
|
||||
# vim: ft=perl ts=4 sw=4 et:
|
||||
use esmith::ConfigDB ;
|
||||
use esmith::AccountsDB ;
|
||||
|
||||
$OUT = '';
|
||||
|
||||
# Generate qmail user assignments for groups. These will be handled
|
||||
# by ~alias/.qmail-groupname and ~alias/.qmail-groupname-ext.
|
||||
|
||||
my $db = esmith::ConfigDB->open_ro
|
||||
or die "Can't open the Config database : $!\n" ;
|
||||
my $accountdb = esmith::AccountsDB->open_ro
|
||||
or die "Can't open the Account database : $!\n" ;
|
||||
|
||||
my (undef, undef, $uid, $gid, undef, undef, undef, $dir, undef)
|
||||
= getpwnam("alias");
|
||||
|
||||
# It is almost impossible to get Text::Template to output nothing
|
||||
# on failure. It can be done by removing the newline at the end of
|
||||
# this file but that is messy. Therefore, we'll simply return an
|
||||
# error message that will make qmail-newu fail. Also send a
|
||||
# warning message that will be captured in the logs.
|
||||
|
||||
unless (defined $uid && defined $gid && defined $dir)
|
||||
{
|
||||
my $msg =
|
||||
"Failed to obtain user details for \'alias\' "
|
||||
. "while processing group assignments.";
|
||||
|
||||
warn "$msg\n";
|
||||
$OUT = $msg;
|
||||
return;
|
||||
}
|
||||
|
||||
my $alias_assign = "alias:${uid}:${gid}:${dir}";
|
||||
|
||||
my @users ;
|
||||
my $fetchmail = $db->get('FetchMails') ;
|
||||
my $FMStatus = 'disabled' ;
|
||||
if ( defined $fetchmail ) {
|
||||
$FMStatus = $fetchmail->prop('status') || 'disabled' ;
|
||||
}
|
||||
|
||||
if ( $FMStatus eq 'enabled' ) {
|
||||
my @users = $accountdb->get('admin');
|
||||
push @users, $accountdb->users();
|
||||
foreach my $u ( @users ) {
|
||||
# print $u->key ;
|
||||
my $MailCopyTo = '' ;
|
||||
$MailCopyTo = $u->prop( 'FM-MailCopyTo' ) if ( defined $u->prop( 'FM-MailCopyTo' ) ) ;
|
||||
my $TransName = '' ;
|
||||
$TransName = $u->prop( 'FM-TransName' ) if ( defined $u->prop( 'FM-TransName' ) ) ;
|
||||
# print "$MailCopyTo\n" ;
|
||||
if ( $MailCopyTo ne '' || $TransName ne '' ) {
|
||||
my $FMGroup = "fm_fm-" . $u->key ;
|
||||
|
||||
# Assign mail for group@
|
||||
$OUT .= "=${FMGroup}:${alias_assign}:-:${FMGroup}:\n";
|
||||
|
||||
# Assign mail for group-ext@
|
||||
$OUT .= "+${FMGroup}-:${alias_assign}:-${FMGroup}-::\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Need to remove the final newline character. Blank lines in
|
||||
# /var/qmail/users/assign are prohibited.
|
||||
|
||||
chomp($OUT);
|
||||
|
||||
# Failsafe: /var/qmail/users/assign cannot have blank lines.
|
||||
# Therefore, if $OUT is empty, simply set up an assign for the
|
||||
# alias user.
|
||||
|
||||
$OUT = "=alias:${alias_assign}:::" unless $OUT;
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
# vim: ft=perl ts=4 sw=4 et:
|
||||
if ( ( $FetchMails{ status } || "disabled" ) eq "enabled" ) {
|
||||
$OUT = "\n127.0.0.200\n" ;
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
{
|
||||
# vim: ft=perl ts=4 sw=4 et:
|
||||
if ( ( $FetchMails{ status } || "disabled" ) eq "enabled" ) {
|
||||
$OUT = "\n# fetchmail groups entries start\n" ;
|
||||
$OUT .= "# If smeserver-fetchmail creates mailgroup for incoming fetched mails\n" ;
|
||||
$OUT .= "# we need to accept these groups from outside.\n" ;
|
||||
|
||||
my $fetchgroup = 0 ;
|
||||
my $dom = $DomainName ;
|
||||
|
||||
opendir ( DIR, "/var/qmail/alias" ) ;
|
||||
foreach my $fic ( grep( /^\.qmail-fm_fm-/, readdir DIR) ) {
|
||||
$fic =~ s/^\.qmail-//;
|
||||
$fic =~ s/:/./g;
|
||||
$OUT .= "$fic\@$dom\n";
|
||||
$fetchgroup = 1;
|
||||
}
|
||||
closedir (DIR);
|
||||
|
||||
$OUT .= "### No smeserver-fetchmail groups set Now ...\n" if ( ! $fetchgroup ) ;
|
||||
$OUT .= "# fetchmail groups entries end\n" ;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user