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"
EXIMCONFDIR="etc/exim/"
VIRTUALDOMDIR=EXIMCONFDIR+"virtual/"
POPHOMEDIR="home/mail/"
USERPREFIX = "usr"
BASEPREFIX = "../tmp"
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

@ -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
import os, string
import GVAdm
from UserDict import UserDict
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 added new pop3 user $NEWUSER with password $NEWPASS
def createpopaccount(domainname, sysuser):
"""Creates a pop3/imap account for given domain and system user"""
"addpopuser sysusrp<num>"
class MailAccount(UserDict):
def __init__(self, domain):
"Initialize a MailAccount instance for a given domain"
UserDict.__init__(self)
self["domainname"] = domain
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
class MailAlias(MailAccount):
"""This represents a mail alias"""
def __init__(self, domain):
"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)):
try:
aliasfile = open(VIRTUALDOMDIR+self["domainname"], 'r')
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+"."
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 writeAll(self):
"""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 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)
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()
createpopaccount("test.de", "usr03")
setmailalias("test.de", "doedel", "horst@dittberner.info")
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