View Single Post
  #1  
Old 2nd November 2006, 21:53
desmondk desmondk is offline
Junior Member
 
Join Date: Nov 2006
Posts: 5
Thanks: 0
Thanked 4 Times in 2 Posts
Default ispconfig email login with user@domain How to

For those that want to log into your email with user@domain here it is.
In ispconfig control panel , log in as admin and go to Management -> system config -> settings -> ISP manager ; and change "User Prefix" to [DOMAIN]_

We wil be using couriers userdb for authentication purposes.
Users wil now be added to the system as domain_user using the ispconfig frontend.

Edit authdaemonrc located at /etc/courier/ (on my ubuntu system) and change the line reading authmodulelist so it look like this

Code:
authmodulelist="authuserdb authpam"
Save and restart courier authdaemon.

Here is the code for the script that wil convert the text to user@domain that you would be able to login in with
Code:
#!/bin/bash

delim="_"

OIFS=$IFS
IFS="
"
rm -rf /etc/courier/userdb
touch /etc/courier/userdb
chmod 600 /etc/courier/userdb
for line in `pw2userdb2 | grep -ir user`
do
        domain=$( echo $line | cut -d"$delim" -f1 )
        useruid=$( echo $line | cut -d"$delim" -f2 )
        username=$( echo $useruid | cut -d'     ' -f1 )
        uid=$( echo $useruid | cut -d'  ' -f2 )
        gid=$( echo $line | cut -d"$delim" -f3 )
        home=$( echo $line | cut -d"$delim" -f4 )
        shell=$( echo $line | cut -d"$delim" -f6 )
        password=$( echo $line | cut -d"$delim" -f7)
        echo "$username@$domain $uid|$gid|${home}_$username|$shell|$password|/var/www/www.$domain/user/${domain}_$username/Maildir" >> /etc/courier/userdb
        /usr/lib/courier/makeuserdb
done

IFS=$OIFS
Also replace pw2userdb that is located in /usr/sbin on my system , it may be at a dif location to mine, in that case just use the following command to see where the file is located "which pw2userdb" and replace the code inside with this:
Code:
#! /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 (<PASSWD>)
{
        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 (<SHADOW>)
        {
                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;
}


Put he first script in a crontab to remake the userdb file. like this: run the command "crontab -e"
Add into the file:
Code:
*/5 * * * * /location_of_the_script/script_name
And Save.



I am busy changing the script so that it would check to see if there has been any changes made before rebuilding the userdb file and if there wasn't any changes it won't do anything.
Hope this helps some people in the mean time. Still busy improving it.
Reply With Quote
Sponsored Links