* 'VirtualMailManager/ext/Postconf.py'
- Added to repository to read some Postfix settings
* 'VirtualMailManager/Config.py'
* 'VirtualMailManager/VirtualMailManager.py'
* 'man/de/man5/vmm.cfg.5'
* 'man/man5/vmm.cfg.5'
* 'setup.py'
* 'update_config_0.4.x-0.5.py'
* 'upgrade.sh'
* 'vmm.cfg'
- Added postconf stuff
--- a/VirtualMailManager/Config.py Fri Sep 12 21:24:10 2008 +0000
+++ b/VirtualMailManager/Config.py Tue Sep 16 05:55:54 2008 +0000
@@ -32,7 +32,6 @@
You can specify settings for the database connection
and maildirectories.
-
"""
def __init__(self, filename):
@@ -74,7 +73,8 @@
]
self.__binopts = [
['dovecotpw', '/usr/sbin/dovecotpw'],
- ['du', '/usr/bin/du']
+ ['du', '/usr/bin/du'],
+ ['postconf', '/usr/sbin/postconf']
]
self.__miscopts = [
['passwdscheme', 'PLAIN'],
--- a/VirtualMailManager/VirtualMailManager.py Fri Sep 12 21:24:10 2008 +0000
+++ b/VirtualMailManager/VirtualMailManager.py Tue Sep 16 05:55:54 2008 +0000
@@ -23,6 +23,7 @@
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net
import constants.ERROR as ERR
+from ext.Postconf import Postconf
from Account import Account
from Alias import Alias
from AliasDomain import AliasDomain
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/VirtualMailManager/ext/Postconf.py Tue Sep 16 05:55:54 2008 +0000
@@ -0,0 +1,92 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2007-2008 VEB IT
+# See COPYING for distribution information.
+# $Id$
+
+"""A small - r/o - wrapper class for Postfix' postconf."""
+
+from VirtualMailManager.constants.VERSION import VERSION
+
+__author__ = 'Pascal Volk <p.volk@veb-it.de>'
+__version__ = VERSION
+__revision__ = 'rev '+'$Rev$'.split()[1]
+__date__ = '$Date$'.split()[1]
+
+import re
+from subprocess import Popen, PIPE
+
+import VirtualMailManager.constants.ERROR as ERR
+from VirtualMailManager.Exceptions import VMMException
+
+RE_PC_PARAMS = """^\w+$"""
+RE_PC_VARIABLES = r"""\$\b\w+\b"""
+
+class Postconf:
+ def __init__(self, postconf_bin):
+ """Creates a new Postconf instance.
+
+ Keyword arguments:
+ postconf_bin -- absolute path to Postfix' postconf binary (str)
+ """
+ self.__bin = postconf_bin
+ self.__val = ''
+ re.compile(RE_PC_PARAMS)
+ re.compile(RE_PC_VARIABLES)
+
+ def read(self, parameter, expand_vars=True):
+ """Returns the parameters value.
+
+ If expand_vars is True (default), all variables in the value will be
+ expanded:
+ e.g. mydestination -> mail.example.com, localhost.example.com, localhost
+ Otherwise the value may contain one or more variables.
+ e.g. mydestination -> $myhostname, localhost.$mydomain, localhost
+
+ Keyword arguments:
+ parameter -- the name of a Postfix configuration parameter (str)
+ expand_vars -- default True (bool)
+ """
+ if not re.match(RE_PC_PARAMS, parameter):
+ raise VMMException(_(u'The value »%s« looks not like a valid\
+ postfix configuration parameter name.'), ERR.INVALID_AGUMENT)
+ self.__val = self.__read(parameter)
+ if expand_vars:
+ self.__expandVars()
+ return self.__val
+
+ def __expandVars(self):
+ while True:
+ pvars = set(re.findall(RE_PC_VARIABLES, self.__val))
+ pvars_len = len(pvars)
+ if pvars_len < 1:
+ break
+ if pvars_len > 1:
+ self.__expandMultiVars(self.__readMulti(pvars))
+ continue
+ for var in pvars:
+ self.__val = self.__val.replace(var, self.__read(var[1:]))
+
+ def __expandMultiVars(self, old_new):
+ for old, new in old_new.items():
+ self.__val = self.__val.replace('$'+old, new)
+
+ def __read(self, parameter):
+ out, err = Popen([self.__bin, '-h', parameter], stdout=PIPE,
+ stderr=PIPE).communicate()
+ if len(err):
+ raise Exception, err.strip()
+ return out.strip()
+
+ def __readMulti(self, parameters):
+ cmd = [self.__bin]
+ for parameter in parameters:
+ cmd.append(parameter[1:])
+ out, err = Popen(cmd, stdout=PIPE, stderr=PIPE).communicate()
+ if len(err):
+ raise Exception, err.strip()
+ par_val = {}
+ for line in out.splitlines():
+ par, val = line.split(' = ')
+ par_val[par] = val
+ return par_val
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/VirtualMailManager/ext/__init__.py Tue Sep 16 05:55:54 2008 +0000
@@ -0,0 +1,7 @@
+# -*- coding: UTF-8 -*-
+# Copyright 2008 VEB IT
+# See COPYING for distribution information.
+# $Id$
+# package placeholder
+#
+# EOF
--- a/man/de/man5/vmm.cfg.5 Fri Sep 12 21:24:10 2008 +0000
+++ b/man/de/man5/vmm.cfg.5 Tue Sep 16 05:55:54 2008 +0000
@@ -1,5 +1,5 @@
.\" $Id$
-.TH vmm.cfg 5 "27. Aug 2008" "Pascal Volk"
+.TH vmm.cfg 5 "15 Sep 2008" "Pascal Volk"
.SH NAME
vmm.cfg \- Konfigurationsdatei für vmm
.SH SYNOPSIS
@@ -173,12 +173,20 @@
Der absolute Pfad zu \fBdu\fR(1). Dieses Binary wird verwendet, wenn die
Festplattenbelegung eines Kontos ermittelt wird.
.TP
+\fBpostconf\fP (\fIString\fP)
+Der absolute Pfad zu Postfix' \fBpostconf\fR(1).
+.br
+Dieses Binary wird verwendet, wenn \fBvmm\fR(1) diverse Postfix-Einstellungen
+prüft, zum Beispiel virtual_alias_expansion_limit.
+.TP
\fBBeispiel\fP:
[bin]
.br
dovecotpw = /usr/sbin/dovecotpw
.br
du = /usr/bin/du
+.br
+postconf = /usr/sbin/postconf
.\" -----
.SH MISC ABSCHNITT
Im \fBmisc\fP-Abschnitt werden verschiedene Einstellungen festgelegt.
--- a/man/man5/vmm.cfg.5 Fri Sep 12 21:24:10 2008 +0000
+++ b/man/man5/vmm.cfg.5 Tue Sep 16 05:55:54 2008 +0000
@@ -1,5 +1,5 @@
.\" $Id$
-.TH vmm.cfg 5 "27. Aug 2008" "Pascal Volk"
+.TH vmm.cfg 5 "15 Sep 2008" "Pascal Volk"
.SH NAME
vmm.cfg \- configuration file for vmm
.SH SYNOPSIS
@@ -161,12 +161,20 @@
The absolute path to \fBdu\fR(1). This binary is used to summarize the disk
usage of a maildir.
.TP
+\fBpostconf\fP (\fIString\fP)
+The absolute path to Postfix' \fBpostconf\fR(1).
+.br
+This binary is required if \fBvmm\fR(1) has to check for some Postfix settings,
+e.g. virtual_alias_expansion_limit.
+.TP
\fBExample\fP:
[bin]
.br
dovecotpw = /usr/sbin/dovecotpw
.br
du = /usr/bin/du
+.br
+postconf = /usr/sbin/postconf
.\" -----
.SH MISC SECTION
The \fBmisc\fP section is used to define miscellaneous settings.
--- a/setup.py Fri Sep 12 21:24:10 2008 +0000
+++ b/setup.py Tue Sep 16 05:55:54 2008 +0000
@@ -24,7 +24,8 @@
version=VERSION,
description='Tool to manage mail domains/accounts/aliases for Dovecot and Postfix',
long_description=long_description,
- packages=['VirtualMailManager', 'VirtualMailManager.constants'],
+ packages=['VirtualMailManager', 'VirtualMailManager.ext',
+ 'VirtualMailManager.constants'],
author='Pascal Volk',
author_email='p.volk@veb-it.de',
license='BSD License',
--- a/update_config_0.4.x-0.5.py Fri Sep 12 21:24:10 2008 +0000
+++ b/update_config_0.4.x-0.5.py Tue Sep 16 05:55:54 2008 +0000
@@ -4,6 +4,7 @@
# See COPYING for distribution information.
# $Id$
+import sys
from ConfigParser import ConfigParser
from shutil import copy2
@@ -29,3 +30,21 @@
cp.remove_option('maildir', 'folder')
cp.write(fh)
fh.close()
+
+if not cp.has_option('bin', 'postconf'):
+ fh = file(cf, 'w')
+ try:
+ postconf = sys.argv[1].strip()
+ if len(postconf):
+ cp.set('bin', 'postconf', postconf)
+ else: # possible?
+ cp.set('bin', 'postconf', '/usr/sbin/postconf')
+ except IndexError:
+ cp.set('bin', 'postconf', '/usr/sbin/postconf')
+ cp.write(fh)
+ fh.close()
+ print
+ print "Please have a look at your %s" %cf
+ print "and verify the value from option 'postconf' in section 'bin'."
+ print
+
--- a/upgrade.sh Fri Sep 12 21:24:10 2008 +0000
+++ b/upgrade.sh Tue Sep 16 05:55:54 2008 +0000
@@ -10,6 +10,7 @@
PF_CONFDIR=$(postconf -h config_directory)
PF_GID=$(id -g $(postconf -h mail_owner))
+POSTCONF=$(which postconf)
LOCALE_DIR=${PREFIX}/share/locale
DOC_DIR=${PREFIX}/share/doc/vmm
if [ ${PREFIX} == "/usr" ]; then
@@ -82,5 +83,5 @@
install -m 0644 ${INSTALL_OPTS} vmm.cfg ${DOC_DIR}/examples
# update config file
-./update_config_0.4.x-0.5.py
+./update_config_0.4.x-0.5.py $POSTCONF
--- a/vmm.cfg Fri Sep 12 21:24:10 2008 +0000
+++ b/vmm.cfg Tue Sep 16 05:55:54 2008 +0000
@@ -66,6 +66,8 @@
dovecotpw = /usr/sbin/dovecotpw
; location of disk usage (String)
du = /usr/bin/du
+; location of postconf
+postconf = '/usr/sbin/postconf'
#
# misc settings