backend functions for mail account
- creating aliases works git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@29 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
5a401f31b2
commit
9cea2ab6b4
1 changed files with 78 additions and 0 deletions
78
backend/mailtools.py
Executable file
78
backend/mailtools.py
Executable file
|
@ -0,0 +1,78 @@
|
|||
#! /usr/bin/env python
|
||||
|
||||
import os, string
|
||||
|
||||
USERPREFIX="usr"
|
||||
EXIMCONFDIR="etc/exim/"
|
||||
VIRTUALDOMDIR=EXIMCONFDIR+"virtual/"
|
||||
|
||||
# if [ -n $USERPREFIX ]; then
|
||||
# USERPREFIX="usr"
|
||||
# fi
|
||||
|
||||
# if [ $1 == "" ]; then
|
||||
# echo "give <UserNumber>p<pop3Account> as parameter"
|
||||
# exit
|
||||
# fi
|
||||
|
||||
# NEWUSER="$USERPREFIX$1"
|
||||
# NEWHOME="/home/mail/$NEWUSER"
|
||||
# NEWPASS=$(apg -n 1 -a 1 -CL -m 8 -x 12)
|
||||
# echo $NEWHOME
|
||||
|
||||
# adduser --home "$NEWHOME" --shell /bin/true --no-create-home --firstuid 20000 --ingroup poponly --disabled-password --disabled-login --gecos "Popuser $NEWUSER" $NEWUSER
|
||||
|
||||
# mkdir -p "$NEWHOME"
|
||||
# chown -Rc $NEWUSER.poponly "$NEWHOME"
|
||||
# echo "${NEWUSER}:${NEWPASS}" | chpasswd
|
||||
|
||||
# echo "Herzlich willkommen auf dem GNU-Viech" | mail -s "Willkommen auf dem GNU-Viech" ${NEWUSER}
|
||||
# echo added new pop3 user $NEWUSER with password $NEWPASS
|
||||
|
||||
def readaliasfile(domainname):
|
||||
"""reads the aliasfile for the given domain and returns a dictionary
|
||||
object with the aliases
|
||||
"""
|
||||
aliases={}
|
||||
if (os.access(VIRTUALDOMDIR, os.R_OK)):
|
||||
try:
|
||||
aliasfile=open(VIRTUALDOMDIR+domainname, 'r')
|
||||
for line in aliasfile.readlines():
|
||||
keyvals = string.split(line,":",1)
|
||||
aliases[keyvals[0]]=keyvals[1].strip()
|
||||
aliasfile.close()
|
||||
except IOError:
|
||||
print "couldn't read the aliasfile for "+domainname+"."
|
||||
else:
|
||||
print "couldn't read from "+VIRTUALDOMDIR+"."
|
||||
return aliases
|
||||
|
||||
def writealiasfile(domainname, aliases):
|
||||
"""writes the aliasfile for the given domain with the aliases defined
|
||||
in the dictionary object aliases
|
||||
"""
|
||||
if (os.access(VIRTUALDOMDIR, os.W_OK)):
|
||||
try:
|
||||
aliasfile=open(VIRTUALDOMDIR+domainname, 'w')
|
||||
for key in aliases.keys():
|
||||
aliasfile.write(key+":"+aliases[key]+"\n")
|
||||
aliasfile.close()
|
||||
except IOError:
|
||||
print "writing to aliasfile failed."
|
||||
else:
|
||||
print "no write access to directory "+VIRTUALDOMDIR+"."
|
||||
|
||||
def createpopaccount(domainname, sysuser):
|
||||
"""Creates a pop3/imap account for given domain and system user"""
|
||||
"addpopuser sysusrp<num>"
|
||||
|
||||
def setmailalias(domainname, alias, target):
|
||||
"""sets a mail alias for given domain which directs the MTA to the
|
||||
given target
|
||||
"""
|
||||
aliases=readaliasfile(domainname)
|
||||
aliases[alias]=target
|
||||
writealiasfile(domainname, aliases)
|
||||
|
||||
createpopaccount("test.de", "usr03")
|
||||
setmailalias("test.de", "doedel", "horst@dittberner.info")
|
Loading…
Reference in a new issue