How to read email with login user@domain in ISPConfig
ISPConfig is one of the most powerful control panel for hosting on Linux. It offers lots of useful features. However, the default user name for obtaining email is in form web1_user
where as 1 is the web identifier and user is the user name in that domain. Actually, we don't know its domain. The preferable user for reading email should be , however, ISPConfig created the user
web1_user
which is not meaningful for end-users. Fortunately, it is possible to configure to add support this scheme.
My idea is inspired by a thread talking about solution for this requirement. It is exactly what I want. However, the code provided in that thread did not work on my ISPConfig 2.2.7 and Ubuntu Dapper Drake due to incorrect format of userdb. So below are my codes.
/usr/local/bin/pw2userdb
#! /usr/bin/perl
#
# Convert /etc/passwd and /etc/shadow to userdb format.
#
# $Id: pw2userdb.in,v 1.5 2000/07/19 11:55:15 mrsam Exp $
#
# Copyright 1998 - 1999 Double Precision, Inc. See COPYING for
# distribution information.
use Getopt::Long;
#
# Some undocumented options here (for vchkpw2userdb)
#
die "Invalid options.\n" unless
GetOptions("passwd=s" => \$passwd, "shadow=s" => \$shadow,
"noshadow" => \$noshadow, "nouid" => \$nouid,
"domain=s" => \$domain, "vpopuid" => \$vpopuid );
($dummy, $dummy, $fixed_uid, $fixed_gid)=getpwnam("vpopmail")
if $vpopuid;
$passwd="/etc/passwd" unless $passwd =~ /./;
$shadow="/etc/shadow" unless $shadow =~ /./;
$domain="" unless $domain =~ /./;
$domain="\@$domain" if $domain =~ /./;
open(PASSWD, $passwd) || die "$!\n";
while ()
{
chop if /\n$/;
next if /^#/;
($acct,$passwd,$uid,$gid,$name,$home,$shell)=split ( /:/ );
($uid,$gid)=($fixed_uid,$fixed_gid) if $vpopuid;
$PASSWORD{$acct}=$passwd if $passwd ne "x";
$UID{$acct}=$uid;
$GID{$acct}=$gid;
$HOME{$acct}=$home;
$SHELL{$acct}=$shell;
$name =~ s/\|/./g; # Just in case
$GECOS{$acct}=$name;
}
close (PASSWD);
if ( -f $shadow && ! $noshadow)
{
open (SHADOW, $shadow) || die "$!\n";
while ()
{
next if /^#/;
($acct,$passwd,$dummy)=split(/:/);
$PASSWORD{$acct}=$passwd;
}
close (SHADOW);
}
while ( defined ($key=each %UID))
{
print "$key$domain\tuid=$UID{$key}|gid=$GID{$key}|home=$HOME{$key}" .
( $SHELL{$key} =~ /./ ? "|shell=$SHELL{$key}":"") .
( $PASSWORD{$key} =~ /./ ? "|systempw=$PASSWORD{$key}":"") .
( $GECOS{$key} =~ /./ ? "|gecos=$GECOS{$key}":"") .
"\n";
print "$UID{$key}=\t$key\n" unless $nouid;
}
/usr/local/bin/userdb2ispconfig
#!/bin/bash
BASE_PATH=`dirname $0`
delim="|"
OIFS=$IFS
IFS="
"
rm -rf /etc/courier/userdb
touch /etc/courier/userdb
chmod 600 /etc/courier/userdb
for line in `$BASE_PATH/pw2userdb | grep -ir /var/www/web`
do
eval `echo -n $line | awk 'BEGIN {RS="\t|\||\n";FS="_"} !/=/ {printf("domain=\"%s\";username=\"%s\";",$1,$2); FS="="} /=/ {printf("%s=\"%s\";",$1,$2)}'`
password=$systempw
echo "$username@$domain uid=$uid|gid=$gid|home=$home|shell=$shell|systempw=$password|mail=/var/www/www.$domain/user/${domain}_$username/Maildir" >> /etc/courier/userdb
/usr/lib/courier/makeuserdb
done
IFS=$OIFS
/etc/cron.d/userdb
*/5 * * * * root /usr/local/bin/userdb2ispconfig
Don't forget to enable authuserdb
in authdaemon by modifying /etc/courier/authdaemonrc
.
Find:
authmodulelist="authpam"
Change to:
authmodulelist="authuserdb authpam"
Then restart authdaemon.
/etc/init.d/courier-authdaemon restart
Now it is time to customize ISPConfig by changing user prefix to [DOMAIN]_
. The option is in System Management -> System Config -> Settings. Note that you have to remove all existing users and create new ones to conform to the new prefix.
- sugree's blog
- 2875 reads
Post new comment