author | Pascal Volk <neverseen@users.sourceforge.net> |
Wed, 07 May 2008 19:09:55 +0000 | |
changeset 30 | 24d8baf0cd6b |
parent 28 | 87da30d30fde |
child 32 | ceb700bc4a80 |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
2 |
# -*- coding: UTF-8 -*- |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
4
diff
changeset
|
3 |
# Copyright 2007-2008 VEB IT |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
# See COPYING for distribution information. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
# $Id$ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
6 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
"""The main class for vmm.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
|
4 | 9 |
from constants.VERSION import VERSION |
10 |
||
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
11 |
__author__ = 'Pascal Volk <p.volk@veb-it.de>' |
4 | 12 |
__version__ = VERSION |
13 |
__revision__ = 'rev '+'$Rev$'.split()[1] |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
__date__ = '$Date$'.split()[1] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
15 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
16 |
import os |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
import re |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
import sys |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
19 |
from encodings.idna import ToASCII, ToUnicode |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
from shutil import rmtree |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
21 |
from subprocess import Popen, PIPE |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
22 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
23 |
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
24 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
25 |
from Exceptions import * |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
import constants.ERROR as ERR |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
from Config import VMMConfig as Cfg |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
28 |
from Account import Account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
29 |
from Alias import Alias |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
from Domain import Domain |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
31 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
32 |
SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
RE_ASCII_CHARS = """^[\x20-\x7E]*$""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
RE_DOMAIN = """^(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}$""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
35 |
RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]""" |
8
7e3ce56f49e6
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
4
diff
changeset
|
36 |
RE_MAILLOCATION = """^[\w]{1,20}$""" |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
re.compile(RE_ASCII_CHARS) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
re.compile(RE_DOMAIN) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
39 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
ENCODING_IN = sys.getfilesystemencoding() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
ENCODING_OUT = sys.stdout.encoding or sys.getfilesystemencoding() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
class VirtualMailManager: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
"""The main class for vmm""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
def __init__(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
"""Creates a new VirtualMailManager instance. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
47 |
Throws a VMMNotRootException if your uid is greater 0. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
48 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
self.__cfgFileName = '/usr/local/etc/vmm.cfg' |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
50 |
self.__permWarnMsg = "fix permissions for '%s'\n`chmod 0600 %s` would\ |
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
51 |
be great." % (self.__cfgFileName, self.__cfgFileName) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
52 |
self.__warnings = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
self.__Cfg = None |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
54 |
self.__dbh = None |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
55 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
if os.geteuid(): |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
57 |
raise VMMNotRootException(("You are not root.\n\tGood bye!\n", |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
58 |
ERR.CONF_NOPERM)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
if self.__chkCfgFile(): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
60 |
self.__Cfg = Cfg(self.__cfgFileName) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
61 |
self.__Cfg.load() |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
62 |
self.__Cfg.check() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
63 |
self.__cfgSections = self.__Cfg.getsections() |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
64 |
self.__scheme = self.__Cfg.get('misc', 'passwdscheme') |
14
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
65 |
if not sys.argv[1] in ['cf', 'configure']: |
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
66 |
self.__chkenv() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
68 |
def __chkCfgFile(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
69 |
"""Checks the configuration file, returns bool""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
if not os.path.isfile(self.__cfgFileName): |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
71 |
raise VMMException(("The file »%s« does not exists." % |
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
72 |
self.__cfgFileName, ERR.CONF_NOFILE)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
fstat = os.stat(self.__cfgFileName) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
fmode = self.__getFileMode() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
76 |
except: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
77 |
raise |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
78 |
if fmode % 100 and fstat.st_uid != fstat.st_gid \ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
79 |
or fmode % 10 and fstat.st_uid == fstat.st_gid: |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
80 |
raise VMMPermException((self.__permWarnMsg, ERR.CONF_ERROR)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
82 |
return True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
83 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
84 |
def __chkenv(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
85 |
"""""" |
24 | 86 |
if not os.path.exists(self.__Cfg.get('domdir', 'base')): |
28
87da30d30fde
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
87 |
old_umask = os.umask(0006) |
87da30d30fde
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
88 |
os.makedirs(self.__Cfg.get('domdir', 'base'), 0771) |
87da30d30fde
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
89 |
os.chown(self.__Cfg.get('domdir', 'base'), 0, |
87da30d30fde
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
24
diff
changeset
|
90 |
self.__Cfg.getint('misc', 'gid_mail')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
91 |
os.umask(old_umask) |
24 | 92 |
elif not os.path.isdir(self.__Cfg.get('domdir', 'base')): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
93 |
raise VMMException(('%s is not a directory' % |
24 | 94 |
self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
95 |
for opt, val in self.__Cfg.items('bin'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
96 |
if not os.path.exists(val): |
14
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
97 |
raise VMMException(("%s doesn't exists." % val, |
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
98 |
ERR.NO_SUCH_BINARY)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
99 |
elif not os.access(val, os.X_OK): |
14
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
100 |
raise VMMException(("%s is not executable." % val, |
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
101 |
ERR.NOT_EXECUTABLE)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
102 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
103 |
def __getFileMode(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
104 |
"""Determines the file access mode from file __cfgFileName, |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
returns int. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
107 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
108 |
return int(oct(os.stat(self.__cfgFileName).st_mode & 0777)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
109 |
except: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
110 |
raise |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
111 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
112 |
def __dbConnect(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
113 |
"""Creates a pyPgSQL.PgSQL.connection instance.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
114 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
self.__dbh = PgSQL.connect( |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
116 |
database=self.__Cfg.get('database', 'name'), |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
117 |
user=self.__Cfg.get('database', 'user'), |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
118 |
host=self.__Cfg.get('database', 'host'), |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
password=self.__Cfg.get('database', 'pass'), |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
client_encoding='utf8', unicode_results=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
dbc = self.__dbh.cursor() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
122 |
dbc.execute("SET NAMES 'UTF8'") |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
124 |
except PgSQL.libpq.DatabaseError, e: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
125 |
raise VMMException((str(e), ERR.DATABASE_ERROR)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
126 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
def __chkLocalpart(self, localpart): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
128 |
"""Validates the local part of an e-mail address. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
129 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
130 |
Keyword arguments: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
131 |
localpart -- the e-mail address that should be validated (str) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
132 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
133 |
if len(localpart) > 64: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
134 |
raise VMMException(('The local part is too long', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
135 |
ERR.LOCALPART_TOO_LONG)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
136 |
if re.compile(RE_LOCALPART).search(localpart): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
137 |
raise VMMException(( |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
138 |
'The local part »%s« contains invalid characters.' % localpart, |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
139 |
ERR.LOCALPART_INVALID)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
140 |
return localpart |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
141 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
142 |
def __idn2ascii(self, domainname): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
"""Converts an idn domainname in punycode. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
145 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
domainname -- the domainname to convert (str) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
148 |
tmp = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
149 |
for label in domainname.split('.'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
150 |
if len(label) == 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
151 |
continue |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
152 |
tmp.append(ToASCII(unicode(label, ENCODING_IN))) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
153 |
return '.'.join(tmp) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
154 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
155 |
def __ace2idna(self, domainname): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
156 |
"""Convertis a domainname from ACE according to IDNA |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
157 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
158 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
159 |
domainname -- the domainname to convert (str) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
160 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
161 |
tmp = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
162 |
for label in domainname.split('.'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
163 |
if len(label) == 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
164 |
continue |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
165 |
tmp.append(ToUnicode(label)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
return '.'.join(tmp) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
167 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
168 |
def __chkDomainname(self, domainname): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
169 |
"""Validates the domain name of an e-mail address. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
170 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
171 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
172 |
domainname -- the domain name that should be validated |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
173 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
174 |
if not re.match(RE_ASCII_CHARS, domainname): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
175 |
domainname = self.__idn2ascii(domainname) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
176 |
if len(domainname) > 255: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
177 |
raise VMMException(('The domain name is too long.', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
178 |
ERR.DOMAIN_TOO_LONG)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
179 |
if not re.match(RE_DOMAIN, domainname): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
180 |
raise VMMException(('The domain name is invalid.', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
181 |
ERR.DOMAIN_INVALID)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
182 |
return domainname |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
183 |
|
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
184 |
def __chkEmailAddress(self, address): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
185 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
186 |
localpart, domain = address.split('@') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
187 |
except ValueError: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
188 |
raise VMMException(("Missing '@' sign in e-mail address »%s«." % |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
189 |
address, ERR.INVALID_ADDRESS)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
190 |
except AttributeError: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
191 |
raise VMMException(("»%s« looks not like an e-mail address." % |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
192 |
address, ERR.INVALID_ADDRESS)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
193 |
domain = self.__chkDomainname(domain) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
194 |
localpart = self.__chkLocalpart(localpart) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
195 |
return '%s@%s' % (localpart, domain) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
196 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
197 |
def __getAccount(self, address, password=None): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
198 |
address = self.__chkEmailAddress(address) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
199 |
self.__dbConnect() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
200 |
if not password is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
201 |
password = self.__pwhash(password) |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
202 |
return Account(self.__dbh, address, password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
203 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
204 |
def __getAlias(self, address, destination=None): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
205 |
address = self.__chkEmailAddress(address) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
206 |
if not destination is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
207 |
if destination.count('@'): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
208 |
destination = self.__chkEmailAddress(destination) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
209 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
210 |
destination = self.__chkLocalpart(destination) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
211 |
self.__dbConnect() |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
212 |
return Alias(self.__dbh, address, destination) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
213 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
214 |
def __getDomain(self, domainname, transport=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
215 |
domainname = self.__chkDomainname(domainname) |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
216 |
if transport is None: |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
217 |
transport = self.__Cfg.get('misc', 'transport') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
218 |
self.__dbConnect() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
219 |
return Domain(self.__dbh, domainname, |
24 | 220 |
self.__Cfg.get('domdir', 'base'), transport) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
221 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
222 |
def __getDiskUsage(self, directory): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
223 |
"""Estimate file space usage for the given directory. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
224 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
225 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
226 |
directory -- the directory to summarize recursively disk usage for |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
227 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
228 |
return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory], |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
229 |
stdout=PIPE).communicate()[0].split('\t')[0] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
230 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
231 |
def __makedir(self, directory, mode=None, uid=None, gid=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
232 |
if mode is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
233 |
mode = self.__Cfg.getint('maildir', 'mode') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
234 |
if uid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
235 |
uid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
236 |
if gid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
237 |
gid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
238 |
os.makedirs(directory, mode) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
239 |
os.chown(directory, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
240 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
241 |
def __domdirmake(self, domdir, gid): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
242 |
os.umask(0006) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
243 |
oldpwd = os.getcwd() |
24 | 244 |
basedir = self.__Cfg.get('domdir', 'base') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
245 |
domdirdirs = domdir.replace(basedir+'/', '').split('/') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
246 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
247 |
os.chdir(basedir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
248 |
if not os.path.isdir(domdirdirs[0]): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
249 |
self.__makedir(domdirdirs[0], 489, 0, |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
250 |
self.__Cfg.getint('misc', 'gid_mail')) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
251 |
os.chdir(domdirdirs[0]) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
252 |
os.umask(0007) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
253 |
self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
254 |
gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
255 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
256 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
257 |
def __maildirmake(self, domdir, uid, gid): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
258 |
"""Creates maildirs and maildir subfolders. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
259 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
260 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
261 |
uid -- user id from the account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
262 |
gid -- group id from the account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
263 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
264 |
os.umask(0007) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
265 |
oldpwd = os.getcwd() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
266 |
os.chdir(domdir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
267 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
268 |
maildir = '%s' % self.__Cfg.get('maildir', 'folder') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
269 |
folders = [maildir , maildir+'/.Drafts', maildir+'/.Sent', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
270 |
maildir+'/.Templates', maildir+'/.Trash'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
271 |
subdirs = ['cur', 'new', 'tmp'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
272 |
mode = self.__Cfg.getint('maildir', 'mode') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
273 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
274 |
self.__makedir('%s' % uid, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
275 |
os.chdir('%s' % uid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
276 |
for folder in folders: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
277 |
self.__makedir(folder, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
278 |
for subdir in subdirs: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
279 |
self.__makedir(folder+'/'+subdir, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
280 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
281 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
282 |
def __maildirdelete(self, domdir, uid, gid): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
283 |
if uid > 0 and gid > 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
284 |
maildir = '%s' % uid |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
285 |
if maildir.count('..') or domdir.count('..'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
286 |
raise VMMException(('FATAL: ".." in maildir path detected.', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
287 |
ERR.FOUND_DOTS_IN_PATH)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
288 |
if os.path.isdir(domdir): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
289 |
os.chdir(domdir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
290 |
if os.path.isdir(maildir): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
291 |
mdstat = os.stat(maildir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
292 |
if (mdstat.st_uid, mdstat.st_gid) != (uid, gid): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
293 |
raise VMMException( |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
294 |
('FATAL: owner/group mismatch in maildir detected', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
295 |
ERR.MAILDIR_PERM_MISMATCH)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
296 |
rmtree(maildir, ignore_errors=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
297 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
298 |
def __domdirdelete(self, domdir, gid): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
299 |
if gid > 0: |
24 | 300 |
basedir = '%s' % self.__Cfg.get('domdir', 'base') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
301 |
domdirdirs = domdir.replace(basedir+'/', '').split('/') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
302 |
if basedir.count('..') or domdir.count('..'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
303 |
raise VMMException( |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
304 |
('FATAL: ".." in domain directory path detected.', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
305 |
ERR.FOUND_DOTS_IN_PATH)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
306 |
if os.path.isdir('%s/%s' % (basedir, domdirdirs[0])): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
307 |
os.chdir('%s/%s' % (basedir, domdirdirs[0])) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
308 |
if os.lstat(domdirdirs[1]).st_gid != gid: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
309 |
raise VMMException( |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
310 |
('FATAL: group mismatch in domain directory detected', |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
311 |
ERR.DOMAINDIR_GROUP_MISMATCH)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
312 |
rmtree(domdirdirs[1], ignore_errors=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
313 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
314 |
def __getSalt(self): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
315 |
from random import choice |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
316 |
salt = None |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
317 |
if self.__scheme == 'CRYPT': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
318 |
salt = '%s%s' % (choice(SALTCHARS), choice(SALTCHARS)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
319 |
elif self.__scheme in ['MD5', 'MD5-CRYPT']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
320 |
salt = '$1$' |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
321 |
for i in range(8): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
322 |
salt += choice(SALTCHARS) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
323 |
salt += '$' |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
324 |
return salt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
325 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
326 |
def __pwCrypt(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
327 |
# for: CRYPT, MD5 and MD5-CRYPT |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
328 |
from crypt import crypt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
329 |
return crypt(password, self.__getSalt()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
330 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
331 |
def __pwSHA1(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
332 |
# for: SHA/SHA1 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
333 |
import sha |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
334 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
335 |
sha1 = sha.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
336 |
return standard_b64encode(sha1.digest()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
337 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
338 |
def __pwMD5(self, password, emailaddress=None): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
339 |
import md5 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
340 |
_md5 = md5.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
341 |
if self.__scheme == 'LDAP-MD5': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
342 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
343 |
return standard_b64encode(_md5.digest()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
344 |
elif self.__scheme == 'PLAIN-MD5': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
345 |
return _md5.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
346 |
elif self.__scheme == 'DIGEST-MD5' and emailaddress is not None: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
347 |
_md5 = md5.new('%s:%s:' % tuple(emailaddress.split('@'))) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
348 |
_md5.update(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
349 |
return _md5.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
350 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
351 |
def __pwMD4(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
352 |
# for: PLAIN-MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
353 |
from Crypto.Hash import MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
354 |
_md4 = MD4.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
355 |
return _md4.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
356 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
357 |
def __pwhash(self, password, scheme=None, user=None): |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
358 |
if scheme is not None: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
359 |
self.__scheme = scheme |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
360 |
if self.__scheme in ['CRYPT', 'MD5', 'MD5-CRYPT']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
361 |
return '{%s}%s' % (self.__scheme, self.__pwCrypt(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
362 |
elif self.__scheme in ['SHA', 'SHA1']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
363 |
return '{%s}%s' % (self.__scheme, self.__pwSHA1(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
364 |
elif self.__scheme in ['PLAIN-MD5', 'LDAP-MD5', 'DIGEST-MD5']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
365 |
return '{%s}%s' % (self.__scheme, self.__pwMD5(password, user)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
366 |
elif self.__scheme == 'MD4': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
367 |
return '{%s}%s' % (self.__scheme, self.__pwMD4(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
368 |
elif self.__scheme in ['SMD5', 'SSHA', 'CRAM-MD5', 'HMAC-MD5', |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
369 |
'LANMAN', 'NTLM', 'RPA']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
370 |
return Popen([self.__Cfg.get('bin', 'dovecotpw'), '-s', |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
371 |
self.__scheme,'-p',password],stdout=PIPE).communicate()[0][:-1] |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
372 |
else: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
373 |
return '{%s}%s' % (self.__scheme, password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
374 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
375 |
def hasWarnings(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
376 |
"""Checks if warnings are present, returns bool.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
377 |
return bool(len(self.__warnings)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
378 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
379 |
def getWarnings(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
380 |
"""Returns a list with all available warnings.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
381 |
return self.__warnings |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
382 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
383 |
def setupIsDone(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
384 |
"""Checks if vmm is configured, returns bool""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
385 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
386 |
return self.__Cfg.getboolean('config', 'done') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
387 |
except ValueError, e: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
388 |
raise VMMConfigException('Configurtion error: "'+str(e) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
389 |
+'"\n(in section "Connfig", option "done")' |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
390 |
+'\nsee also: vmm.cfg(5)\n') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
391 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
392 |
def configure(self, section=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
393 |
"""Starts interactive configuration. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
394 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
395 |
Configures in interactive mode options in the given section. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
396 |
If no section is given (default) all options from all sections |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
397 |
will be prompted. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
398 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
399 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
400 |
section -- the section to configure (default None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
401 |
'database', 'maildir', 'bin' or 'misc' |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
402 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
403 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
404 |
if not section: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
405 |
self.__Cfg.configure(self.__cfgSections) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
406 |
elif section not in self.__cfgSections: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
407 |
raise VMMException(("Invalid section: »%s«" % section, |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
408 |
ERR.INVALID_SECTION)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
409 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
410 |
self.__Cfg.configure([section]) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
411 |
except: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
412 |
raise |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
413 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
414 |
def domain_add(self, domainname, transport=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
415 |
dom = self.__getDomain(domainname, transport) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
416 |
dom.save() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
417 |
self.__domdirmake(dom.getDir(), dom.getID()) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
418 |
|
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
419 |
def domain_transport(self, domainname, transport, force=None): |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
420 |
if force is not None and force != 'force': |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
421 |
raise VMMDomainException(('Invalid argument: »%s«' % force, |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
422 |
ERR.INVALID_OPTION)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
423 |
dom = self.__getDomain(domainname, None) |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
424 |
if force is None: |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
425 |
dom.updateTransport(transport) |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
426 |
else: |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
427 |
dom.updateTransport(transport, force=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
428 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
429 |
def domain_delete(self, domainname, force=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
430 |
if not force is None and force not in ['deluser','delalias','delall']: |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
431 |
raise VMMDomainException(('Invalid argument: »%s«' % force, |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
432 |
ERR.INVALID_OPTION)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
433 |
dom = self.__getDomain(domainname) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
434 |
gid = dom.getID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
435 |
domdir = dom.getDir() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
436 |
if self.__Cfg.getboolean('misc', 'forcedel') or force == 'delall': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
437 |
dom.delete(True, True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
438 |
elif force == 'deluser': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
439 |
dom.delete(delUser=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
440 |
elif force == 'delalias': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
441 |
dom.delete(delAlias=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
442 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
443 |
dom.delete() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
444 |
if self.__Cfg.getboolean('domdir', 'delete'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
445 |
self.__domdirdelete(domdir, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
446 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
447 |
def domain_info(self, domainname, detailed=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
448 |
dom = self.__getDomain(domainname) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
449 |
dominfo = dom.getInfo() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
450 |
if dominfo['domainname'].startswith('xn--'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
451 |
dominfo['domainname'] += ' (%s)'\ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
452 |
% self.__ace2idna(dominfo['domainname']) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
453 |
if dominfo['aliases'] is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
454 |
dominfo['aliases'] = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
455 |
if detailed is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
456 |
return dominfo |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
457 |
elif detailed == 'detailed': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
458 |
return dominfo, dom.getAccounts(), dom.getAliases() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
459 |
else: |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
460 |
raise VMMDomainException(('Invalid argument: »%s«' % detailed, |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
461 |
ERR.INVALID_OPTION)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
462 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
463 |
def user_add(self, emailaddress, password): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
464 |
acc = self.__getAccount(emailaddress, password) |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
465 |
acc.save(self.__Cfg.get('maildir', 'folder'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
466 |
self.__Cfg.getboolean('services', 'smtp'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
467 |
self.__Cfg.getboolean('services', 'pop3'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
468 |
self.__Cfg.getboolean('services', 'imap'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
469 |
self.__Cfg.getboolean('services', 'managesieve')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
470 |
self.__maildirmake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
471 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
472 |
def alias_add(self, aliasaddress, targetaddress): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
473 |
alias = self.__getAlias(aliasaddress, targetaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
474 |
alias.save() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
475 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
476 |
def user_delete(self, emailaddress): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
477 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
478 |
uid = acc.getUID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
479 |
gid = acc.getGID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
480 |
acc.delete() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
481 |
if self.__Cfg.getboolean('maildir', 'delete'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
482 |
self.__maildirdelete(acc.getDir('domain'), uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
483 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
484 |
def alias_info(self, aliasaddress): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
485 |
alias = self.__getAlias(aliasaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
486 |
return alias.getInfo() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
487 |
|
12
44161dbb1518
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
488 |
def alias_delete(self, aliasaddress, targetaddress=None): |
44161dbb1518
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
489 |
alias = self.__getAlias(aliasaddress, targetaddress) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
490 |
alias.delete() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
491 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
492 |
def user_info(self, emailaddress, diskusage=False): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
493 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
494 |
info = acc.getInfo() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
495 |
if self.__Cfg.getboolean('maildir', 'diskusage') or diskusage: |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
496 |
info['disk usage'] = self.__getDiskUsage('%(maildir)s' % info) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
497 |
return info |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
498 |
|
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
499 |
def user_byID(self, uid): |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
500 |
from Account import getAccountByID |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
501 |
self.__dbConnect() |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
502 |
return getAccountByID(uid, self.__dbh) |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
503 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
504 |
def user_password(self, emailaddress, password): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
505 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
506 |
acc.modify('password', self.__pwhash(password)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
507 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
508 |
def user_name(self, emailaddress, name): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
509 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
510 |
acc.modify('name', name) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
511 |
|
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
512 |
def user_transport(self, emailaddress, transport): |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
513 |
acc = self.__getAccount(emailaddress) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
514 |
acc.modify('transport', transport) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
515 |
|
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
516 |
def user_disable(self, emailaddress, service=None): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
517 |
acc = self.__getAccount(emailaddress) |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
518 |
acc.disable(service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
519 |
|
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
520 |
def user_enable(self, emailaddress, service=None): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
521 |
acc = self.__getAccount(emailaddress) |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
522 |
acc.enable(service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
523 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
524 |
def __del__(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
525 |
if not self.__dbh is None and self.__dbh._isOpen: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
526 |
self.__dbh.close() |