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"
GVADMDIR = BASEPREFIX+"/etc/gvadm/"
EXIMCONFDIR = BASEPREFIX+"/etc/exim/"
VIRTUALDOMDIR = EXIMCONFDIR+"virtual/" VIRTUALDOMDIR = EXIMCONFDIR+"virtual/"
POPHOMEDIR="home/mail/" 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
""" def __init__(self, domain):
aliases={} "Initialize the POPAccount class for a given domain"
MailAccount.__init__(self, domain)
self["aliases"] = {}
self.readAll()
def readAll(self):
"""reads the aliasfile for the given domain"""
self["aliases"] = {}
if (os.access(VIRTUALDOMDIR, os.R_OK)): if (os.access(VIRTUALDOMDIR, os.R_OK)):
try: try:
aliasfile=open(VIRTUALDOMDIR+domainname, 'r') aliasfile = open(VIRTUALDOMDIR+self["domainname"], 'r')
for line in aliasfile.readlines(): for line in aliasfile.readlines():
keyvals = string.split(line,":",1) keyvals = string.split(line,":",1)
aliases[keyvals[0]]=keyvals[1].strip() self["aliases"][keyvals[0]] = keyvals[1].strip()
aliasfile.close() aliasfile.close()
except IOError: except IOError:
print "couldn't read the aliasfile for "+domainname+"." print "couldn't read the aliasfile for "+self["domainname"]+"."
else: else:
print "couldn't read from "+VIRTUALDOMDIR+"." print "couldn't read from "+VIRTUALDOMDIR+"."
return aliases
def writealiasfile(domainname, aliases): def writeAll(self):
"""writes the aliasfile for the given domain with the aliases defined """writes the aliasfile for the given domain with the aliases defined
in the dictionary object aliases in the dictionary object aliases"""
"""
if (os.access(VIRTUALDOMDIR, os.W_OK)): if (os.access(VIRTUALDOMDIR, os.W_OK)):
try: try:
aliasfile=open(VIRTUALDOMDIR+domainname, 'w') aliasfile = open(VIRTUALDOMDIR+self["domainname"], 'w')
for key in aliases.keys(): keys = self["aliases"].keys();
aliasfile.write(key+":"+aliases[key]+"\n") keys.sort();
for key in keys:
aliasfile.write(key+":"+self["aliases"][key]+"\n")
aliasfile.close() aliasfile.close()
except IOError: except IOError:
print "writing to aliasfile failed." print "writing to aliasfile failed."
else: else:
print "no write access to directory "+VIRTUALDOMDIR+"." print "no write access to directory "+VIRTUALDOMDIR+"."
def setmailalias(domainname, alias, target): def setAlias(self, alias, target):
"""sets a mail alias for given domain which directs the MTA to the """sets a mail alias for given domain which directs the MTA to the
given target given target
""" """
aliases=readaliasfile(domainname) self.readAll()
aliases[alias]=target self["aliases"][alias]=target
writealiasfile(domainname, aliases) self.writeAll()
createpopaccount("test.de", "usr03") class POP3Account(MailAccount):
setmailalias("test.de", "doedel", "horst@dittberner.info") """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