author | Pascal Volk <neverseen@users.sourceforge.net> |
Fri, 04 Sep 2009 20:27:39 +0000 | |
changeset 142 | 28f26f7f3d8f |
parent 140 | ffac064bd728 |
child 143 | 16542519a5a8 |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
102
485d3f7d6981
Removed svn keywords, more POSIX compliant shell scripts
Pascal Volk <neverseen@users.sourceforge.net>
parents:
96
diff
changeset
|
2 |
# Copyright (c) 2007 - 2009, VEB IT |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
5 |
"""The main class for vmm.""" |
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 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
8 |
from encodings.idna import ToASCII, ToUnicode |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
9 |
from getpass import getpass |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
from shutil import rmtree |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
11 |
from subprocess import Popen, PIPE |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
12 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
from pyPgSQL import PgSQL # python-pgsql - http://pypgsql.sourceforge.net |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
|
138
617f27715b01
Reorganized module import.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
136
diff
changeset
|
15 |
from __main__ import os, re, ENCODING, ERR, w_std |
86
e43e4e7e9ec0
* 'VirtualMailManager/ext/Postconf.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
84
diff
changeset
|
16 |
from ext.Postconf import Postconf |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
17 |
from Account import Account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
from Alias import Alias |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
19 |
from AliasDomain import AliasDomain |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
20 |
from Config import Config as Cfg |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
21 |
from Domain import Domain |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
22 |
from EmailAddress import EmailAddress |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
23 |
from Exceptions import * |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
24 |
from Relocated import Relocated |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
25 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
26 |
SALTCHARS = './0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
RE_ASCII_CHARS = """^[\x20-\x7E]*$""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
28 |
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
|
29 |
RE_DOMAIN_SRCH = """^[a-z0-9-\.]+$""" |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
30 |
RE_LOCALPART = """[^\w!#$%&'\*\+-\.\/=?^_`{\|}~]""" |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
31 |
RE_MBOX_NAMES = """^[\x20-\x25\x27-\x7E]*$""" |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
32 |
|
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
33 |
class VirtualMailManager(object): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
"""The main class for vmm""" |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
35 |
__slots__ = ('__Cfg', '__cfgFileName', '__cfgSections', '__dbh', '__scheme', |
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
36 |
'__warnings', '_postconf') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
37 |
def __init__(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
38 |
"""Creates a new VirtualMailManager instance. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
39 |
Throws a VMMNotRootException if your uid is greater 0. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
40 |
""" |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
41 |
self.__cfgFileName = '' |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
42 |
self.__warnings = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
43 |
self.__Cfg = None |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
44 |
self.__dbh = None |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
45 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
46 |
if os.geteuid(): |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
47 |
raise VMMNotRootException(_(u"You are not root.\n\tGood bye!\n"), |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
48 |
ERR.CONF_NOPERM) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
49 |
if self.__chkCfgFile(): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
50 |
self.__Cfg = Cfg(self.__cfgFileName) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
51 |
self.__Cfg.load() |
2
9b39f828aa8a
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
52 |
self.__Cfg.check() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
53 |
self.__cfgSections = self.__Cfg.getsections() |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
54 |
self.__scheme = self.__Cfg.get('misc', 'passwdscheme') |
88
b3debcfea7bc
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
87
diff
changeset
|
55 |
self._postconf = Postconf(self.__Cfg.get('bin', 'postconf')) |
136
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
56 |
if not os.sys.argv[1] in ['cf', 'configure']: |
14
ebc9b864bc9a
* 'update_config_0.3.x-0.4.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
12
diff
changeset
|
57 |
self.__chkenv() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
|
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
59 |
def __findCfgFile(self): |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
60 |
for path in ['/root', '/usr/local/etc', '/etc']: |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
61 |
tmp = os.path.join(path, 'vmm.cfg') |
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
62 |
if os.path.isfile(tmp): |
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
63 |
self.__cfgFileName = tmp |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
64 |
break |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
65 |
if not len(self.__cfgFileName): |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
66 |
raise VMMException( |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
67 |
_(u"No “vmm.cfg” found in: /root:/usr/local/etc:/etc"), |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
68 |
ERR.CONF_NOFILE) |
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
69 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
70 |
def __chkCfgFile(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
"""Checks the configuration file, returns bool""" |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
72 |
self.__findCfgFile() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
73 |
fstat = os.stat(self.__cfgFileName) |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
74 |
fmode = int(oct(fstat.st_mode & 0777)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
if fmode % 100 and fstat.st_uid != fstat.st_gid \ |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
76 |
or fmode % 10 and fstat.st_uid == fstat.st_gid: |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
77 |
raise VMMPermException(_( |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
78 |
u'fix permissions (%(perms)s) for “%(file)s”\n\ |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
79 |
`chmod 0600 %(file)s` would be great.') % {'file': |
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
80 |
self.__cfgFileName, 'perms': fmode}, ERR.CONF_WRONGPERM) |
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')): |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
93 |
raise VMMException(_(u'“%s” is not a directory.\n\ |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
94 |
(vmm.cfg: section "domdir", option "base")') % |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
95 |
self.__Cfg.get('domdir', 'base'), ERR.NO_SUCH_DIRECTORY) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
96 |
for opt, val in self.__Cfg.items('bin'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
97 |
if not os.path.exists(val): |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
98 |
raise VMMException(_(u'“%(binary)s” doesn\'t exists.\n\ |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
99 |
(vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt}, |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
100 |
ERR.NO_SUCH_BINARY) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
101 |
elif not os.access(val, os.X_OK): |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
102 |
raise VMMException(_(u'“%(binary)s” is not executable.\n\ |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
103 |
(vmm.cfg: section "bin", option "%(option)s")') %{'binary': val,'option': opt}, |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
104 |
ERR.NOT_EXECUTABLE) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
def __dbConnect(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
107 |
"""Creates a pyPgSQL.PgSQL.connection instance.""" |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
108 |
if self.__dbh is None or not self.__dbh._isOpen: |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
109 |
try: |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
110 |
self.__dbh = PgSQL.connect( |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
111 |
database=self.__Cfg.get('database', 'name'), |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
112 |
user=self.__Cfg.get('database', 'user'), |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
113 |
host=self.__Cfg.get('database', 'host'), |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
114 |
password=self.__Cfg.get('database', 'pass'), |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
115 |
client_encoding='utf8', unicode_results=True) |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
116 |
dbc = self.__dbh.cursor() |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
117 |
dbc.execute("SET NAMES 'UTF8'") |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
118 |
dbc.close() |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
119 |
except PgSQL.libpq.DatabaseError, e: |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
120 |
raise VMMException(str(e), ERR.DATABASE_ERROR) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
|
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
122 |
def idn2ascii(domainname): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
"""Converts an idn domainname in punycode. |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
124 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
125 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
126 |
domainname -- the domainname to convert (str) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
127 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
128 |
tmp = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
129 |
for label in domainname.split('.'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
130 |
if len(label) == 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
131 |
continue |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
132 |
tmp.append(ToASCII(label)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
133 |
return '.'.join(tmp) |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
134 |
idn2ascii = staticmethod(idn2ascii) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
135 |
|
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
136 |
def ace2idna(domainname): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
137 |
"""Convertis a domainname from ACE according to IDNA |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
138 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
139 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
140 |
domainname -- the domainname to convert (str) |
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 |
tmp = [] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
143 |
for label in domainname.split('.'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
144 |
if len(label) == 0: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
145 |
continue |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
146 |
tmp.append(ToUnicode(label)) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
147 |
return '.'.join(tmp) |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
148 |
ace2idna = staticmethod(ace2idna) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
149 |
|
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
150 |
def chkDomainname(domainname): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
2
diff
changeset
|
151 |
"""Validates the domain name of an e-mail address. |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
152 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
153 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
154 |
domainname -- the domain name that should be validated |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
155 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
156 |
if not re.match(RE_ASCII_CHARS, domainname): |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
157 |
domainname = VirtualMailManager.idn2ascii(domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
158 |
if len(domainname) > 255: |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
159 |
raise VMMException(_(u'The domain name is too long.'), |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
160 |
ERR.DOMAIN_TOO_LONG) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
161 |
if not re.match(RE_DOMAIN, domainname): |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
162 |
raise VMMException(_(u'The domain name “%s” is invalid.') %\ |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
163 |
domainname, ERR.DOMAIN_INVALID) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
164 |
return domainname |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
165 |
chkDomainname = staticmethod(chkDomainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
166 |
|
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
167 |
def _exists(dbh, query): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
168 |
dbc = dbh.cursor() |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
169 |
dbc.execute(query) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
170 |
gid = dbc.fetchone() |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
171 |
dbc.close() |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
172 |
if gid is None: |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
173 |
return False |
52
c152d7714802
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
51
diff
changeset
|
174 |
else: |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
175 |
return True |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
176 |
_exists = staticmethod(_exists) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
177 |
|
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
178 |
def accountExists(dbh, address): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
179 |
sql = "SELECT gid FROM users WHERE gid = (SELECT gid FROM domain_name\ |
109
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
180 |
WHERE domainname = '%s') AND local_part = '%s'" % (address._domainname, |
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
181 |
address._localpart) |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
182 |
return VirtualMailManager._exists(dbh, sql) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
183 |
accountExists = staticmethod(accountExists) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
184 |
|
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
185 |
def aliasExists(dbh, address): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
186 |
sql = "SELECT DISTINCT gid FROM alias WHERE gid = (SELECT gid FROM\ |
109
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
187 |
domain_name WHERE domainname = '%s') AND address = '%s'" %\ |
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
188 |
(address._domainname, address._localpart) |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
189 |
return VirtualMailManager._exists(dbh, sql) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
190 |
aliasExists = staticmethod(aliasExists) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
191 |
|
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
192 |
def relocatedExists(dbh, address): |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
193 |
sql = "SELECT gid FROM relocated WHERE gid = (SELECT gid FROM\ |
109
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
194 |
domain_name WHERE domainname = '%s') AND address = '%s'" %\ |
766299a8639d
VMM: Fixed an AttributeError, caused by the last commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
102
diff
changeset
|
195 |
(address._domainname, address._localpart) |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
196 |
return VirtualMailManager._exists(dbh, sql) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
197 |
relocatedExists = staticmethod(relocatedExists) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
198 |
|
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
199 |
def _readpass(self): |
136
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
200 |
readp_msg0 = _(u'Enter new password: ').encode(ENCODING, 'replace') |
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
201 |
readp_msg1 = _(u'Retype new password: ').encode(ENCODING, 'replace') |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
202 |
mismatched = True |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
203 |
while mismatched: |
136
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
204 |
clear0 = getpass(prompt=readp_msg0) |
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
205 |
clear1 = getpass(prompt=readp_msg1) |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
206 |
if clear0 != clear1: |
136
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
207 |
w_std(_(u'Sorry, passwords do not match')) |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
208 |
continue |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
209 |
if len(clear0) < 1 or len(clear1) < 1: |
136
fb61f64e6351
Reorganized imports, eliminated a potential UnicodeEncodeError.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
133
diff
changeset
|
210 |
w_std(_(u'Sorry, empty passwords are not permitted')) |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
211 |
continue |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
212 |
mismatched = False |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
213 |
return clear0 |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
214 |
|
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
215 |
def __getAccount(self, address, password=None): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
216 |
self.__dbConnect() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
217 |
address = EmailAddress(address) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
218 |
if not password is None: |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
219 |
password = self.__pwhash(password) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
220 |
return Account(self.__dbh, address, password) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
221 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
222 |
def __getAlias(self, address, destination=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
223 |
self.__dbConnect() |
76
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
224 |
address = EmailAddress(address) |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
225 |
if destination is not None: |
14c0a092d7d2
* 'VirtualMailManager/EmailAddress.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
70
diff
changeset
|
226 |
destination = EmailAddress(destination) |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
227 |
return Alias(self.__dbh, address, destination) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
228 |
|
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
229 |
def __getRelocated(self,address, destination=None): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
230 |
self.__dbConnect() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
231 |
address = EmailAddress(address) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
232 |
if destination is not None: |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
233 |
destination = EmailAddress(destination) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
234 |
return Relocated(self.__dbh, address, destination) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
235 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
236 |
def __getDomain(self, domainname, transport=None): |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
237 |
if transport is None: |
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
238 |
transport = self.__Cfg.get('misc', 'transport') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
239 |
self.__dbConnect() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
240 |
return Domain(self.__dbh, domainname, |
24 | 241 |
self.__Cfg.get('domdir', 'base'), transport) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
242 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
243 |
def __getDiskUsage(self, directory): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
244 |
"""Estimate file space usage for the given directory. |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
245 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
246 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
247 |
directory -- the directory to summarize recursively disk usage for |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
248 |
""" |
40 | 249 |
if self.__isdir(directory): |
250 |
return Popen([self.__Cfg.get('bin', 'du'), "-hs", directory], |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
251 |
stdout=PIPE).communicate()[0].split('\t')[0] |
40 | 252 |
else: |
253 |
return 0 |
|
254 |
||
255 |
def __isdir(self, directory): |
|
256 |
isdir = os.path.isdir(directory) |
|
257 |
if not isdir: |
|
258 |
self.__warnings.append(_('No such directory: %s') % directory) |
|
259 |
return isdir |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
260 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
261 |
def __makedir(self, directory, mode=None, uid=None, gid=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
262 |
if mode is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
263 |
mode = self.__Cfg.getint('maildir', 'mode') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
264 |
if uid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
265 |
uid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
266 |
if gid is None: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
267 |
gid = 0 |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
268 |
os.makedirs(directory, mode) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
269 |
os.chown(directory, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
270 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
271 |
def __domDirMake(self, domdir, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
272 |
os.umask(0006) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
273 |
oldpwd = os.getcwd() |
24 | 274 |
basedir = self.__Cfg.get('domdir', 'base') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
275 |
domdirdirs = domdir.replace(basedir+'/', '').split('/') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
276 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
277 |
os.chdir(basedir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
278 |
if not os.path.isdir(domdirdirs[0]): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
279 |
self.__makedir(domdirdirs[0], 489, 0, |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
280 |
self.__Cfg.getint('misc', 'gid_mail')) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
281 |
os.chdir(domdirdirs[0]) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
282 |
os.umask(0007) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
283 |
self.__makedir(domdirdirs[1], self.__Cfg.getint('domdir', 'mode'), 0, |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
284 |
gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
285 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
286 |
|
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
287 |
def __subscribeFL(self, folderlist, uid, gid): |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
288 |
fname = os.path.join(self.__Cfg.get('maildir','name'), 'subscriptions') |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
289 |
sf = file(fname, 'w') |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
290 |
for f in folderlist: |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
291 |
sf.write(f+'\n') |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
292 |
sf.flush() |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
293 |
sf.close() |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
294 |
os.chown(fname, uid, gid) |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
295 |
os.chmod(fname, 384) |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
296 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
297 |
def __mailDirMake(self, domdir, uid, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
298 |
"""Creates maildirs and maildir subfolders. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
299 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
300 |
Keyword arguments: |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
301 |
domdir -- the path to the domain directory |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
302 |
uid -- user id from the account |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
303 |
gid -- group id from the account |
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 |
os.umask(0007) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
306 |
oldpwd = os.getcwd() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
307 |
os.chdir(domdir) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
308 |
|
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
309 |
maildir = self.__Cfg.get('maildir', 'name') |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
310 |
folders = [maildir] |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
311 |
for folder in self.__Cfg.get('maildir', 'folders').split(':'): |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
312 |
folder = folder.strip() |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
313 |
if len(folder) and not folder.count('..')\ |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
314 |
and re.match(RE_MBOX_NAMES, folder): |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
315 |
folders.append('%s/.%s' % (maildir, folder)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
316 |
subdirs = ['cur', 'new', 'tmp'] |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
317 |
mode = self.__Cfg.getint('maildir', 'mode') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
318 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
319 |
self.__makedir('%s' % uid, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
320 |
os.chdir('%s' % uid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
321 |
for folder in folders: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
322 |
self.__makedir(folder, mode, uid, gid) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
323 |
for subdir in subdirs: |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
324 |
self.__makedir(os.path.join(folder, subdir), mode, uid, gid) |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
325 |
self.__subscribeFL([f.replace(maildir+'/.', '') for f in folders[1:]], |
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
326 |
uid, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
327 |
os.chdir(oldpwd) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
328 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
329 |
def __userDirDelete(self, domdir, uid, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
330 |
if uid > 0 and gid > 0: |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
331 |
userdir = '%s' % uid |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
332 |
if userdir.count('..') or domdir.count('..'): |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
333 |
raise VMMException(_(u'Found ".." in home directory path.'), |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
334 |
ERR.FOUND_DOTS_IN_PATH) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
335 |
if os.path.isdir(domdir): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
336 |
os.chdir(domdir) |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
337 |
if os.path.isdir(userdir): |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
338 |
mdstat = os.stat(userdir) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
339 |
if (mdstat.st_uid, mdstat.st_gid) != (uid, gid): |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
340 |
raise VMMException( |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
341 |
_(u'Owner/group mismatch in home directory detected.'), |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
342 |
ERR.MAILDIR_PERM_MISMATCH) |
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
343 |
rmtree(userdir, ignore_errors=True) |
40 | 344 |
else: |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
345 |
raise VMMException(_(u"No such directory: %s") % |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
346 |
os.path.join(domdir, userdir), ERR.NO_SUCH_DIRECTORY) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
347 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
348 |
def __domDirDelete(self, domdir, gid): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
349 |
if gid > 0: |
40 | 350 |
if not self.__isdir(domdir): |
351 |
return |
|
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
352 |
basedir = self.__Cfg.get('domdir', 'base') |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
353 |
domdirdirs = domdir.replace(basedir+'/', '').split('/') |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
354 |
domdirparent = os.path.join(basedir, domdirdirs[0]) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
355 |
if basedir.count('..') or domdir.count('..'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
356 |
raise VMMException( |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
357 |
_(u'FATAL: ".." in domain directory path detected.'), |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
358 |
ERR.FOUND_DOTS_IN_PATH) |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
359 |
if os.path.isdir(domdirparent): |
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
360 |
os.chdir(domdirparent) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
361 |
if os.lstat(domdirdirs[1]).st_gid != gid: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
362 |
raise VMMException( |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
363 |
_(u'FATAL: group mismatch in domain directory detected'), |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
364 |
ERR.DOMAINDIR_GROUP_MISMATCH) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
365 |
rmtree(domdirdirs[1], ignore_errors=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
366 |
|
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
367 |
def __getSalt(self): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
368 |
from random import choice |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
369 |
salt = None |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
370 |
if self.__scheme == 'CRYPT': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
371 |
salt = '%s%s' % (choice(SALTCHARS), choice(SALTCHARS)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
372 |
elif self.__scheme in ['MD5', 'MD5-CRYPT']: |
140
ffac064bd728
Code cleanup/optimization in VirtualMailManager's __getSalt().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
373 |
salt = '$1$%s$' % ''.join([choice(SALTCHARS) for x in xrange(8)]) |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
374 |
return salt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
375 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
376 |
def __pwCrypt(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
377 |
# for: CRYPT, MD5 and MD5-CRYPT |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
378 |
from crypt import crypt |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
379 |
return crypt(password, self.__getSalt()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
380 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
381 |
def __pwSHA1(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
382 |
# for: SHA/SHA1 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
383 |
import sha |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
384 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
385 |
sha1 = sha.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
386 |
return standard_b64encode(sha1.digest()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
387 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
388 |
def __pwMD5(self, password, emailaddress=None): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
389 |
import md5 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
390 |
_md5 = md5.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
391 |
if self.__scheme == 'LDAP-MD5': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
392 |
from base64 import standard_b64encode |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
393 |
return standard_b64encode(_md5.digest()) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
394 |
elif self.__scheme == 'PLAIN-MD5': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
395 |
return _md5.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
396 |
elif self.__scheme == 'DIGEST-MD5' and emailaddress is not None: |
70
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
397 |
# use an empty realm - works better with usenames like user@dom |
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
398 |
_md5 = md5.new('%s::%s' % (emailaddress, password)) |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
399 |
return _md5.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
400 |
|
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
401 |
def __pwMD4(self, password): |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
402 |
# for: PLAIN-MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
403 |
from Crypto.Hash import MD4 |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
404 |
_md4 = MD4.new(password) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
405 |
return _md4.hexdigest() |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
406 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
407 |
def __pwhash(self, password, scheme=None, user=None): |
16
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
408 |
if scheme is not None: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
409 |
self.__scheme = scheme |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
410 |
if self.__scheme in ['CRYPT', 'MD5', 'MD5-CRYPT']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
411 |
return '{%s}%s' % (self.__scheme, self.__pwCrypt(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
412 |
elif self.__scheme in ['SHA', 'SHA1']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
413 |
return '{%s}%s' % (self.__scheme, self.__pwSHA1(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
414 |
elif self.__scheme in ['PLAIN-MD5', 'LDAP-MD5', 'DIGEST-MD5']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
415 |
return '{%s}%s' % (self.__scheme, self.__pwMD5(password, user)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
416 |
elif self.__scheme == 'MD4': |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
417 |
return '{%s}%s' % (self.__scheme, self.__pwMD4(password)) |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
418 |
elif self.__scheme in ['SMD5', 'SSHA', 'CRAM-MD5', 'HMAC-MD5', |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
419 |
'LANMAN', 'NTLM', 'RPA']: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
420 |
return Popen([self.__Cfg.get('bin', 'dovecotpw'), '-s', |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
421 |
self.__scheme,'-p',password],stdout=PIPE).communicate()[0][:-1] |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
422 |
else: |
3388b96fd3ed
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
14
diff
changeset
|
423 |
return '{%s}%s' % (self.__scheme, password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
424 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
425 |
def hasWarnings(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
426 |
"""Checks if warnings are present, returns bool.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
427 |
return bool(len(self.__warnings)) |
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 getWarnings(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
430 |
"""Returns a list with all available warnings.""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
431 |
return self.__warnings |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
432 |
|
40 | 433 |
def cfgGetBoolean(self, section, option): |
434 |
return self.__Cfg.getboolean(section, option) |
|
435 |
||
436 |
def cfgGetInt(self, section, option): |
|
437 |
return self.__Cfg.getint(section, option) |
|
438 |
||
439 |
def cfgGetString(self, section, option): |
|
440 |
return self.__Cfg.get(section, option) |
|
441 |
||
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
442 |
def setupIsDone(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
443 |
"""Checks if vmm is configured, returns bool""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
444 |
try: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
445 |
return self.__Cfg.getboolean('config', 'done') |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
446 |
except ValueError, e: |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
447 |
raise VMMConfigException(_(u"""Configurtion error: "%s" |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
448 |
(in section "connfig", option "done") see also: vmm.cfg(5)\n""") % str(e), |
50
927b0705d31a
* 'VirtualMailManager/Domain.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
49
diff
changeset
|
449 |
ERR.CONF_ERROR) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
450 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
451 |
def configure(self, section=None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
452 |
"""Starts interactive configuration. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
453 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
454 |
Configures in interactive mode options in the given section. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
455 |
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
|
456 |
will be prompted. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
457 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
458 |
Keyword arguments: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
459 |
section -- the section to configure (default None): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
460 |
'database', 'maildir', 'bin' or 'misc' |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
461 |
""" |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
462 |
if section is None: |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
463 |
self.__Cfg.configure(self.__cfgSections) |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
464 |
elif section in self.__cfgSections: |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
465 |
self.__Cfg.configure([section]) |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
466 |
else: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
467 |
raise VMMException(_(u"Invalid section: “%s”") % section, |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
468 |
ERR.INVALID_SECTION) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
469 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
470 |
def domainAdd(self, domainname, transport=None): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
471 |
dom = self.__getDomain(domainname, transport) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
472 |
dom.save() |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
473 |
self.__domDirMake(dom.getDir(), dom.getID()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
474 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
475 |
def domainTransport(self, domainname, transport, force=None): |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
476 |
if force is not None and force != 'force': |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
477 |
raise VMMDomainException(_(u"Invalid argument: “%s”") % force, |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
478 |
ERR.INVALID_OPTION) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
479 |
dom = self.__getDomain(domainname, None) |
18
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
480 |
if force is None: |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
481 |
dom.updateTransport(transport) |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
482 |
else: |
c98e08791ee8
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
17
diff
changeset
|
483 |
dom.updateTransport(transport, force=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
484 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
485 |
def domainDelete(self, domainname, force=None): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
486 |
if not force is None and force not in ['deluser','delalias','delall']: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
487 |
raise VMMDomainException(_(u"Invalid argument: “%s”") % force, |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
488 |
ERR.INVALID_OPTION) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
489 |
dom = self.__getDomain(domainname) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
490 |
gid = dom.getID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
491 |
domdir = dom.getDir() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
492 |
if self.__Cfg.getboolean('misc', 'forcedel') or force == 'delall': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
493 |
dom.delete(True, True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
494 |
elif force == 'deluser': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
495 |
dom.delete(delUser=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
496 |
elif force == 'delalias': |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
497 |
dom.delete(delAlias=True) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
498 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
499 |
dom.delete() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
500 |
if self.__Cfg.getboolean('domdir', 'delete'): |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
501 |
self.__domDirDelete(domdir, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
502 |
|
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
503 |
def domainInfo(self, domainname, details=None): |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
504 |
if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full', |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
505 |
'relocated', 'detailed']: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
506 |
raise VMMException(_(u'Invalid argument: “%s”') % details, |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
507 |
ERR.INVALID_AGUMENT) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
508 |
if details == 'detailed': |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
509 |
details = 'full' |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
510 |
self.__warnings.append(_(u'\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
511 |
The keyword “detailed” is deprecated and will be removed in a future release.\n\ |
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
512 |
Please use the keyword “full” to get full details.')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
513 |
dom = self.__getDomain(domainname) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
514 |
dominfo = dom.getInfo() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
515 |
if dominfo['domainname'].startswith('xn--'): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
516 |
dominfo['domainname'] += ' (%s)'\ |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
517 |
% VirtualMailManager.ace2idna(dominfo['domainname']) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
518 |
if details is None: |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
519 |
return dominfo |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
520 |
elif details == 'accounts': |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
521 |
return (dominfo, dom.getAccounts()) |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
522 |
elif details == 'aliasdomains': |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
523 |
return (dominfo, dom.getAliaseNames()) |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
524 |
elif details == 'aliases': |
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
525 |
return (dominfo, dom.getAliases()) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
526 |
elif details == 'relocated': |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
527 |
return(dominfo, dom.getRelocated()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
528 |
else: |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
40
diff
changeset
|
529 |
return (dominfo, dom.getAliaseNames(), dom.getAccounts(), |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
530 |
dom.getAliases(), dom.getRelocated()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
531 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
532 |
def aliasDomainAdd(self, aliasname, domainname): |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
533 |
"""Adds an alias domain to the domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
534 |
|
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
535 |
Keyword arguments: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
536 |
aliasname -- the name of the alias domain (str) |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
537 |
domainname -- name of the target domain (str) |
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
538 |
""" |
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
539 |
dom = self.__getDomain(domainname) |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
540 |
aliasDom = AliasDomain(self.__dbh, aliasname, dom) |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
541 |
aliasDom.save() |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
542 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
543 |
def aliasDomainInfo(self, aliasname): |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
544 |
self.__dbConnect() |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
545 |
aliasDom = AliasDomain(self.__dbh, aliasname, None) |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
546 |
return aliasDom.info() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
547 |
|
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
548 |
def aliasDomainSwitch(self, aliasname, domainname): |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
549 |
"""Modifies the target domain of an existing alias domain. |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
550 |
|
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
551 |
Keyword arguments: |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
552 |
aliasname -- the name of the alias domain (str) |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
553 |
domainname -- name of the new target domain (str) |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
554 |
""" |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
555 |
dom = self.__getDomain(domainname) |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
556 |
aliasDom = AliasDomain(self.__dbh, aliasname, dom) |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
557 |
aliasDom.switch() |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
558 |
|
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
559 |
def aliasDomainDelete(self, aliasname): |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
560 |
"""Deletes the specified alias domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
561 |
|
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
562 |
Keyword arguments: |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
563 |
aliasname -- the name of the alias domain (str) |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
564 |
""" |
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
565 |
self.__dbConnect() |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
566 |
aliasDom = AliasDomain(self.__dbh, aliasname, None) |
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
567 |
aliasDom.delete() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
568 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
569 |
def domainList(self, pattern=None): |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
570 |
from Domain import search |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
571 |
like = False |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
572 |
if pattern is not None: |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
573 |
if pattern.startswith('%') or pattern.endswith('%'): |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
574 |
like = True |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
575 |
if pattern.startswith('%') and pattern.endswith('%'): |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
576 |
domain = pattern[1:-1] |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
577 |
elif pattern.startswith('%'): |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
578 |
domain = pattern[1:] |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
579 |
elif pattern.endswith('%'): |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
580 |
domain = pattern[:-1] |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
581 |
if not re.match(RE_DOMAIN_SRCH, domain): |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
582 |
raise VMMException( |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
583 |
_(u"The pattern “%s” contains invalid characters.") % |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
584 |
pattern, ERR.DOMAIN_INVALID) |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
585 |
self.__dbConnect() |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
586 |
return search(self.__dbh, pattern=pattern, like=like) |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
587 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
588 |
def userAdd(self, emailaddress, password): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
589 |
acc = self.__getAccount(emailaddress, password) |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
590 |
if password is None: |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
591 |
password = self._readpass() |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
592 |
acc.setPassword(self.__pwhash(password)) |
68
7ae95b9938c4
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
66
diff
changeset
|
593 |
acc.save(self.__Cfg.get('maildir', 'name'), |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
113
diff
changeset
|
594 |
self.__Cfg.getint('misc', 'dovecotvers'), |
20
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
595 |
self.__Cfg.getboolean('services', 'smtp'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
596 |
self.__Cfg.getboolean('services', 'pop3'), |
55146c78b3fb
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
19
diff
changeset
|
597 |
self.__Cfg.getboolean('services', 'imap'), |
113
e35755191ff3
Config: renamed services.managesieve to services.sieve,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
109
diff
changeset
|
598 |
self.__Cfg.getboolean('services', 'sieve')) |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
599 |
self.__mailDirMake(acc.getDir('domain'), acc.getUID(), acc.getGID()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
600 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
601 |
def aliasAdd(self, aliasaddress, targetaddress): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
602 |
alias = self.__getAlias(aliasaddress, targetaddress) |
88
b3debcfea7bc
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
87
diff
changeset
|
603 |
alias.save(long(self._postconf.read('virtual_alias_expansion_limit'))) |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
604 |
gid = self.__getDomain(alias._dest._domainname).getID() |
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
605 |
if gid > 0 and not VirtualMailManager.accountExists(self.__dbh, |
128
cf8116625866
Converted VirtualMailManager and Postconf to new-style classes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
119
diff
changeset
|
606 |
alias._dest) and not VirtualMailManager.aliasExists(self.__dbh, |
84
c1363b84a24b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
83
diff
changeset
|
607 |
alias._dest): |
83
cc195af37de0
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
80
diff
changeset
|
608 |
self.__warnings.append( |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
609 |
_(u"The destination account/alias “%s” doesn't exists yet.")%\ |
84
c1363b84a24b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
83
diff
changeset
|
610 |
alias._dest) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
611 |
|
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
612 |
def userDelete(self, emailaddress, force=None): |
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
613 |
if force not in [None, 'delalias']: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
614 |
raise VMMException(_(u"Invalid argument: “%s”") % force, |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
615 |
ERR.INVALID_AGUMENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
616 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
617 |
uid = acc.getUID() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
618 |
gid = acc.getGID() |
66
995d538a6eb5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
62
diff
changeset
|
619 |
acc.delete(force) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
620 |
if self.__Cfg.getboolean('maildir', 'delete'): |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
621 |
try: |
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
622 |
self.__userDirDelete(acc.getDir('domain'), uid, gid) |
48
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
623 |
except VMMException, e: |
0d5f58f8b8f5
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
47
diff
changeset
|
624 |
if e.code() in [ERR.FOUND_DOTS_IN_PATH, |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
625 |
ERR.MAILDIR_PERM_MISMATCH, ERR.NO_SUCH_DIRECTORY]: |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
626 |
warning = _(u"""\ |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
627 |
The account has been successfully deleted from the database. |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
628 |
But an error occurred while deleting the following directory: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
629 |
“%(directory)s” |
51
f5ca21303871
* Switched from pygettext to xgettext -> small adjustments to these files:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
50
diff
changeset
|
630 |
Reason: %(raeson)s""") % {'directory': acc.getDir('home'),'raeson': e.msg()} |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
631 |
self.__warnings.append(warning) |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
632 |
else: |
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
633 |
raise e |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
634 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
635 |
def aliasInfo(self, aliasaddress): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
636 |
alias = self.__getAlias(aliasaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
637 |
return alias.getInfo() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
638 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
639 |
def aliasDelete(self, aliasaddress, targetaddress=None): |
12
44161dbb1518
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
9
diff
changeset
|
640 |
alias = self.__getAlias(aliasaddress, targetaddress) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
641 |
alias.delete() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
642 |
|
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
643 |
def userInfo(self, emailaddress, details=None): |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
644 |
if details not in [None, 'du', 'aliases', 'full']: |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
645 |
raise VMMException(_(u'Invalid argument: “%s”') % details, |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
646 |
ERR.INVALID_AGUMENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
647 |
acc = self.__getAccount(emailaddress) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
113
diff
changeset
|
648 |
info = acc.getInfo(self.__Cfg.getint('misc', 'dovecotvers')) |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
649 |
if self.__Cfg.getboolean('maildir', 'diskusage')\ |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
650 |
or details in ['du', 'full']: |
9
e3d3dbeb5b84
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
8
diff
changeset
|
651 |
info['disk usage'] = self.__getDiskUsage('%(maildir)s' % info) |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
652 |
if details in [None, 'du']: |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
653 |
return info |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
654 |
if details in ['aliases', 'full']: |
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
655 |
return (info, acc.getAliases()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
656 |
return info |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
657 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
658 |
def userByID(self, uid): |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
659 |
from Account import getAccountByID |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
660 |
self.__dbConnect() |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
661 |
return getAccountByID(uid, self.__dbh) |
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
662 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
663 |
def userPassword(self, emailaddress, password): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
664 |
acc = self.__getAccount(emailaddress) |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
665 |
if acc.getUID() == 0: |
70
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
666 |
raise VMMException(_(u"Account doesn't exists"), ERR.NO_SUCH_ACCOUNT) |
38
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
667 |
if password is None: |
c44ea4526546
* 'VirtualMailManager/Alias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
668 |
password = self._readpass() |
70
a3663ad491bf
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
69
diff
changeset
|
669 |
acc.modify('password', self.__pwhash(password, user=emailaddress)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
670 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
671 |
def userName(self, emailaddress, name): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
672 |
acc = self.__getAccount(emailaddress) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
673 |
acc.modify('name', name) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
674 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
675 |
def userTransport(self, emailaddress, transport): |
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
676 |
acc = self.__getAccount(emailaddress) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
677 |
acc.modify('transport', transport) |
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
678 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
679 |
def userDisable(self, emailaddress, service=None): |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
680 |
if service == 'managesieve': |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
681 |
service = 'sieve' |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
682 |
self.__warnings.append(_(u'\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
683 |
The service name “managesieve” is deprecated and will be removed\n\ |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
684 |
in a future release.\n\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
685 |
Please use the service name “sieve” instead.')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
686 |
acc = self.__getAccount(emailaddress) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
113
diff
changeset
|
687 |
acc.disable(self.__Cfg.getint('misc', 'dovecotvers'), service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
688 |
|
54
1fc1f82c662f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
53
diff
changeset
|
689 |
def userEnable(self, emailaddress, service=None): |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
690 |
if service == 'managesieve': |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
691 |
service = 'sieve' |
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
692 |
self.__warnings.append(_(u'\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
693 |
The service name “managesieve” is deprecated and will be removed\n\ |
132
fa22bd13b4d1
Added a deprecated warning for managesieve. Updated translation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
128
diff
changeset
|
694 |
in a future release.\n\ |
133
2d5c4745efec
Replaced angle quotes by quotation marks.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
132
diff
changeset
|
695 |
Please use the service name “sieve” instead.')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
696 |
acc = self.__getAccount(emailaddress) |
115
21f264a88ab2
Added sieve/managesieve switching stuff,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
113
diff
changeset
|
697 |
acc.enable(self.__Cfg.getint('misc', 'dovecotvers'), service) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
698 |
|
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
699 |
def relocatedAdd(self, emailaddress, targetaddress): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
700 |
relocated = self.__getRelocated(emailaddress, targetaddress) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
701 |
relocated.save() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
702 |
|
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
703 |
def relocatedInfo(self, emailaddress): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
704 |
relocated = self.__getRelocated(emailaddress) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
705 |
return relocated.getInfo() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
706 |
|
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
707 |
def relocatedDelete(self, emailaddress): |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
708 |
relocated = self.__getRelocated(emailaddress) |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
709 |
relocated.delete() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
710 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
711 |
def __del__(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
712 |
if not self.__dbh is None and self.__dbh._isOpen: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
713 |
self.__dbh.close() |