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