1
0
Fork 0

- start for object oriented infrastructure

- default preferencs file
- ignore development files


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@81 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
Jan Dittberner 2004-12-21 19:01:59 +00:00
parent f6ca9aa8a1
commit e18a12269f
4 changed files with 129 additions and 47 deletions

37
backend/GVAdm.py Normal file
View file

@ -0,0 +1,37 @@
"""Package for GNUViech Admin main types and functions
(c) Copyright 2004 Jan Dittberner, IT-Consulting & Solutions
Germany
"""
import os
execfile('gvadm.preferences')
class GNVDomain:
"""Represents a domain in the GNUViech admin tool"""
def __init__(self, domain):
"""Initializes the domain object"""
self.domainname = domain
self.findUser()
def __repr__(self):
return "Domain "+self.domainname+", User "+self.username
def findUser(self):
"""Finds the user for the domain or creates a new one."""
if (os.access(GVADMDIR, os.R_OK)):
try:
domainsfile = open(GVADMDIR+"domains", "r")
self.username = "<from file>"
except IOError:
print "domain file not accessible"
self.username = "<unknown>"
else:
print "The directory "+GVADMDIR+" is not accessible!"
self.username = "<unknown>"
if __name__ == "__main__":
dom = GNVDomain("test.de")
print dom

View file

@ -1,4 +1,10 @@
USERPREFIX="usr" USERPREFIX = "usr"
EXIMCONFDIR="etc/exim/" BASEPREFIX = "../tmp"
VIRTUALDOMDIR=EXIMCONFDIR+"virtual/" GVADMDIR = BASEPREFIX+"/etc/gvadm/"
POPHOMEDIR="home/mail/" EXIMCONFDIR = BASEPREFIX+"/etc/exim/"
VIRTUALDOMDIR = EXIMCONFDIR+"virtual/"
HOMEDIR = BASEPREFIX+"/home"
POPHOMEDIR = HOMEDIR+"/mail/"
WEBHOMEDIR = HOMEDIR+"/www/"
WEBLOGDIR = WEBHOMEDIR+"logs/"
WEBSTATSDIR = WEBHOMEDIR+"stats/"

View file

@ -0,0 +1,10 @@
USERPREFIX = "usr"
BASEPREFIX = ""
GVADMDIR = BASEPREFIX+"/etc/gvadm/"
EXIMCONFDIR = BASEPREFIX+"/etc/exim/"
VIRTUALDOMDIR = EXIMCONFDIR+"virtual/"
HOMEDIR = BASEPREFIX+"/home"
POPHOMEDIR = HOMEDIR+"/mail/"
WEBHOMEDIR = HOMEDIR+"/www/"
WEBLOGDIR = WEBHOMEDIR+"logs/"
WEBSTATSDIR = WEBHOMEDIR+"stats/"

View file

@ -1,6 +1,8 @@
#! /usr/bin/env python #! /usr/bin/env python
import os, string import os, string
import GVAdm
from UserDict import UserDict
execfile('gvadm.preferences') execfile('gvadm.preferences')
@ -27,50 +29,77 @@ execfile('gvadm.preferences')
# echo "Herzlich willkommen auf dem GNU-Viech" | mail -s "Willkommen auf dem GNU-Viech" ${NEWUSER} # echo "Herzlich willkommen auf dem GNU-Viech" | mail -s "Willkommen auf dem GNU-Viech" ${NEWUSER}
# echo added new pop3 user $NEWUSER with password $NEWPASS # echo added new pop3 user $NEWUSER with password $NEWPASS
def createpopaccount(domainname, sysuser): class MailAccount(UserDict):
"""Creates a pop3/imap account for given domain and system user""" def __init__(self, domain):
"addpopuser sysusrp<num>" "Initialize a MailAccount instance for a given domain"
UserDict.__init__(self)
self["domainname"] = domain
def readaliasfile(domainname): class MailAlias(MailAccount):
"""reads the aliasfile for the given domain and returns a dictionary """This represents a mail alias"""
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): def __init__(self, domain):
"""writes the aliasfile for the given domain with the aliases defined "Initialize the POPAccount class for a given domain"
in the dictionary object aliases MailAccount.__init__(self, domain)
""" self["aliases"] = {}
if (os.access(VIRTUALDOMDIR, os.W_OK)): self.readAll()
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 setmailalias(domainname, alias, target): def readAll(self):
"""sets a mail alias for given domain which directs the MTA to the """reads the aliasfile for the given domain"""
given target self["aliases"] = {}
""" if (os.access(VIRTUALDOMDIR, os.R_OK)):
aliases=readaliasfile(domainname) try:
aliases[alias]=target aliasfile = open(VIRTUALDOMDIR+self["domainname"], 'r')
writealiasfile(domainname, aliases) for line in aliasfile.readlines():
keyvals = string.split(line,":",1)
self["aliases"][keyvals[0]] = keyvals[1].strip()
aliasfile.close()
except IOError:
print "couldn't read the aliasfile for "+self["domainname"]+"."
else:
print "couldn't read from "+VIRTUALDOMDIR+"."
createpopaccount("test.de", "usr03") def writeAll(self):
setmailalias("test.de", "doedel", "horst@dittberner.info") """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+self["domainname"], 'w')
keys = self["aliases"].keys();
keys.sort();
for key in keys:
aliasfile.write(key+":"+self["aliases"][key]+"\n")
aliasfile.close()
except IOError:
print "writing to aliasfile failed."
else:
print "no write access to directory "+VIRTUALDOMDIR+"."
def setAlias(self, alias, target):
"""sets a mail alias for given domain which directs the MTA to the
given target
"""
self.readAll()
self["aliases"][alias]=target
self.writeAll()
class POP3Account(MailAccount):
"""This represents a pop 3 account"""
def create(self, address):
"""Creates a pop3/imap account for the domain"""
print self
print "adding address "+address
alias = MailAlias(self["domainname"])
alias.setAlias(address, "usr03")
print alias
if __name__ == "__main__":
popacc = POP3Account("test.de")
print popacc
popacc.create("webmaster")
alias = MailAlias("test.de")
print alias
alias.setAlias("klaus", "klaus@dittberner.info")
print alias