author | Pascal Volk <user@localhost.localdomain.org> |
Sat, 15 Feb 2014 17:39:24 +0000 | |
branch | v0.7.x |
changeset 726 | 46b37d7c848a |
parent 711 | 2a75058fc064 |
child 727 | 695426b49de0 |
permissions | -rw-r--r-- |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
1 |
# -*- coding: UTF-8 -*- |
703
58815c004a61
Updated copyright notices to include the year 2014.
Pascal Volk <user@localhost.localdomain.org>
parents:
702
diff
changeset
|
2 |
# Copyright (c) 2007 - 2014, Pascal Volk |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
3 |
# See COPYING for distribution information. |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
4 |
""" |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
5 |
VirtualMailManager.handler |
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
6 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
8 |
A wrapper class. It wraps round all other classes and does some |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
9 |
dependencies checks. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
10 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
11 |
Additionally it communicates with the PostgreSQL database, creates |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
12 |
or deletes directories of domains or users. |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
13 |
""" |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
14 |
|
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
15 |
import os |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
16 |
import re |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
17 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
18 |
from shutil import rmtree |
648
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
19 |
from stat import S_IRGRP, S_IROTH, S_IWGRP, S_IWOTH |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
20 |
from subprocess import Popen, PIPE |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
21 |
|
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
22 |
import psycopg2 |
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
23 |
|
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
24 |
from VirtualMailManager.account import Account |
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
25 |
from VirtualMailManager.alias import Alias |
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
26 |
from VirtualMailManager.aliasdomain import AliasDomain |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
27 |
from VirtualMailManager.catchall import CatchallAlias |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
28 |
from VirtualMailManager.common import exec_ok, lisdir |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
29 |
from VirtualMailManager.config import Config as Cfg |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
30 |
from VirtualMailManager.constants import MIN_GID, MIN_UID, \ |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
31 |
ACCOUNT_EXISTS, ALIAS_EXISTS, CONF_NOFILE, CONF_NOPERM, CONF_WRONGPERM, \ |
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
32 |
DATABASE_ERROR, DOMAINDIR_GROUP_MISMATCH, DOMAIN_INVALID, \ |
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
33 |
FOUND_DOTS_IN_PATH, INVALID_ARGUMENT, MAILDIR_PERM_MISMATCH, \ |
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
34 |
NOT_EXECUTABLE, NO_SUCH_ACCOUNT, NO_SUCH_ALIAS, NO_SUCH_BINARY, \ |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
35 |
NO_SUCH_DIRECTORY, NO_SUCH_RELOCATED, RELOCATED_EXISTS, UNKNOWN_SERVICE, \ |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
36 |
VMM_ERROR, LOCALPART_INVALID, TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
37 |
from VirtualMailManager.domain import Domain |
371
3b2fd0b4e51b
VMM/handler: Handler.alias_add() and Handler.relocated_add() use
Pascal Volk <neverseen@users.sourceforge.net>
parents:
366
diff
changeset
|
38 |
from VirtualMailManager.emailaddress import DestinationEmailAddress, \ |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
39 |
EmailAddress, RE_LOCALPART |
285
d30a94f5aef5
VMM/Handler: import the errors before raising them.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
283
diff
changeset
|
40 |
from VirtualMailManager.errors import \ |
d30a94f5aef5
VMM/Handler: import the errors before raising them.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
283
diff
changeset
|
41 |
DomainError, NotRootError, PermissionError, VMMError |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
294
diff
changeset
|
42 |
from VirtualMailManager.mailbox import new as new_mailbox |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
43 |
from VirtualMailManager.quotalimit import QuotaLimit |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
44 |
from VirtualMailManager.relocated import Relocated |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
45 |
from VirtualMailManager.serviceset import ServiceSet, SERVICES |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
46 |
from VirtualMailManager.transport import Transport |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
47 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
48 |
|
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
49 |
_ = lambda msg: msg |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
50 |
|
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
51 |
CFG_FILE = 'vmm.cfg' |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
52 |
CFG_PATH = '/root:/usr/local/etc:/etc' |
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
53 |
RE_DOMAIN_SEARCH = """^[a-z0-9-\.]+$""" |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
54 |
OTHER_TYPES = { |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
55 |
TYPE_ACCOUNT: (_('an account'), ACCOUNT_EXISTS), |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
56 |
TYPE_ALIAS: (_('an alias'), ALIAS_EXISTS), |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
57 |
TYPE_RELOCATED: (_('a relocated user'), RELOCATED_EXISTS), |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
58 |
} |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
59 |
|
611
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
60 |
|
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
61 |
class Handler(object): |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
62 |
"""Wrapper class to simplify the access on all the stuff from |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
63 |
VirtualMailManager""" |
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
64 |
__slots__ = ('_cfg', '_cfg_fname', '_dbh', '_warnings') |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
65 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
66 |
def __init__(self, skip_some_checks=False): |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
67 |
"""Creates a new Handler instance. |
188
cf1b5f22dbd2
VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents:
187
diff
changeset
|
68 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
69 |
``skip_some_checks`` : bool |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
70 |
When a derived class knows how to handle all checks this |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
71 |
argument may be ``True``. By default it is ``False`` and |
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
72 |
all checks will be performed. |
188
cf1b5f22dbd2
VMM/Handler: __init__ accepts now a config_type ('default'||'cli').
Pascal Volk <neverseen@users.sourceforge.net>
parents:
187
diff
changeset
|
73 |
|
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
215
diff
changeset
|
74 |
Throws a NotRootError if your uid is greater 0. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
""" |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
76 |
self._cfg_fname = '' |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
77 |
self._warnings = [] |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
78 |
self._cfg = None |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
79 |
self._dbh = None |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
80 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
if os.geteuid(): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
82 |
raise NotRootError(_("You are not root.\n\tGood bye!\n"), |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
83 |
CONF_NOPERM) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
84 |
if self._check_cfg_file(): |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
85 |
self._cfg = Cfg(self._cfg_fname) |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
86 |
self._cfg.load() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
87 |
if not skip_some_checks: |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
88 |
self._cfg.check() |
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
89 |
self._chkenv() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
90 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
91 |
def _find_cfg_file(self): |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
92 |
"""Search the CFG_FILE in CFG_PATH. |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
93 |
Raise a VMMError when no vmm.cfg could be found. |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
94 |
""" |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
95 |
for path in CFG_PATH.split(':'): |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
96 |
tmp = os.path.join(path, CFG_FILE) |
119
014335f38962
Small code cleanups (replaced dir+'/'+file by os.path.join()).
Pascal Volk <neverseen@users.sourceforge.net>
parents:
115
diff
changeset
|
97 |
if os.path.isfile(tmp): |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
98 |
self._cfg_fname = tmp |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
99 |
break |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
100 |
if not self._cfg_fname: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
101 |
raise VMMError(_("Could not find '%(cfg_file)s' in: " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
102 |
"'%(cfg_path)s'") % {'cfg_file': CFG_FILE, |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
103 |
'cfg_path': CFG_PATH}, CONF_NOFILE) |
94
0d303d15549e
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
90
diff
changeset
|
104 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
105 |
def _check_cfg_file(self): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
106 |
"""Checks the configuration file, returns bool""" |
648
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
107 |
GRPRW = S_IRGRP | S_IWGRP |
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
108 |
OTHRW = S_IROTH | S_IWOTH |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
109 |
self._find_cfg_file() |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
110 |
fstat = os.stat(self._cfg_fname) |
648
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
111 |
if (fstat.st_uid == fstat.st_gid and fstat.st_mode & OTHRW) or \ |
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
112 |
(fstat.st_uid != fstat.st_gid and fstat.st_mode & (GRPRW | OTHRW)): |
470
807ad4df0774
VMM/handler: Added a comment for the Translation Project.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
458
diff
changeset
|
113 |
# TP: Please keep the backticks around the command. `chmod 0600 …` |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
114 |
raise PermissionError(_("wrong permissions for '%(file)s': " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
115 |
"%(perms)s\n`chmod 0600 %(file)s` would " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
116 |
"be great.") % {'file': self._cfg_fname, |
648
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
117 |
'perms': oct(fstat.st_mode)[-4:]}, |
9cf2cf762e26
VMM/handler: Reworked config file permission check.
Pascal Volk <user@localhost.localdomain.org>
parents:
643
diff
changeset
|
118 |
CONF_WRONGPERM) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
119 |
else: |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
120 |
return True |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
121 |
|
190
1903d4ce97d7
VMM/{,cli/}Handler: reverted most of cs cf1b5f22dbd2 added a cli handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
188
diff
changeset
|
122 |
def _chkenv(self): |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
123 |
"""Make sure our base_directory is a directory and that all |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
124 |
required executables exists and are executable. |
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
125 |
If not, a VMMError will be raised""" |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
126 |
dir_created = False |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
127 |
basedir = self._cfg.dget('misc.base_directory') |
168
fd496561acc6
vmm.cfg: a few re-renamed configuration options.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
166
diff
changeset
|
128 |
if not os.path.exists(basedir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
129 |
old_umask = os.umask(0o006) |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
130 |
os.makedirs(basedir, 0o771) |
270
d3389645a91d
configuration: Dropped setting misc.gid_mail.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
266
diff
changeset
|
131 |
os.chown(basedir, 0, 0) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
132 |
os.umask(old_umask) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
133 |
dir_created = True |
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
134 |
if not dir_created and not lisdir(basedir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
135 |
raise VMMError(_("'%(path)s' is not a directory.\n(%(cfg_file)s: " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
136 |
"section 'misc', option 'base_directory')") % |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
137 |
{'path': basedir, 'cfg_file': self._cfg_fname}, |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
138 |
NO_SUCH_DIRECTORY) |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
139 |
for opt, val in self._cfg.items('bin'): |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
140 |
try: |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
141 |
exec_ok(val) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
142 |
except VMMError as err: |
351
4bba5fb90b78
VMM/handler: Small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
341
diff
changeset
|
143 |
if err.code in (NO_SUCH_BINARY, NOT_EXECUTABLE): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
144 |
raise VMMError(err.msg + _("\n(%(cfg_file)s: section " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
145 |
"'bin', option '%(option)s')") % |
351
4bba5fb90b78
VMM/handler: Small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
341
diff
changeset
|
146 |
{'cfg_file': self._cfg_fname, |
4bba5fb90b78
VMM/handler: Small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
341
diff
changeset
|
147 |
'option': opt}, err.code) |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
148 |
else: |
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
184
diff
changeset
|
149 |
raise |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
150 |
|
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
151 |
def _db_connect(self): |
355
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
152 |
"""Return a new psycopg2 connection object.""" |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
153 |
if self._dbh is None or \ |
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
154 |
(isinstance(self._dbh, psycopg2.extensions.connection) and |
355
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
155 |
self._dbh.closed): |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
156 |
try: |
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
157 |
self._dbh = psycopg2.connect( |
355
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
158 |
host=self._cfg.dget('database.host'), |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
159 |
sslmode=self._cfg.dget('database.sslmode'), |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
160 |
port=self._cfg.dget('database.port'), |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
161 |
database=self._cfg.dget('database.name'), |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
162 |
user=self._cfg.pget('database.user'), |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
163 |
password=self._cfg.pget('database.pass')) |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
164 |
self._dbh.set_client_encoding('utf8') |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
165 |
dbc = self._dbh.cursor() |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
166 |
dbc.execute("SET NAMES 'UTF8'") |
48bf20b43f2e
VMM/handler: Added support for psycopg2.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
351
diff
changeset
|
167 |
dbc.close() |
694
b1bfd4d1d9c0
Dropped pyPgSQL support.
Pascal Volk <user@localhost.localdomain.org>
parents:
686
diff
changeset
|
168 |
except psycopg2.DatabaseError as err: |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
169 |
raise VMMError(str(err), DATABASE_ERROR) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
170 |
|
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
171 |
def _chk_other_address_types(self, address, exclude): |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
172 |
"""Checks if the EmailAddress *address* is known as `TYPE_ACCOUNT`, |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
173 |
`TYPE_ALIAS` or `TYPE_RELOCATED`, but not as the `TYPE_*` specified |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
174 |
by *exclude*. If the *address* is known as one of the `TYPE_*`s |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
175 |
the according `TYPE_*` constant will be returned. Otherwise 0 will |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
176 |
be returned.""" |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
177 |
assert exclude in (TYPE_ACCOUNT, TYPE_ALIAS, TYPE_RELOCATED) and \ |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
178 |
isinstance(address, EmailAddress) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
179 |
if exclude is not TYPE_ACCOUNT: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
180 |
account = Account(self._dbh, address) |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
181 |
if account: |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
182 |
return TYPE_ACCOUNT |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
183 |
if exclude is not TYPE_ALIAS: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
184 |
alias = Alias(self._dbh, address) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
185 |
if alias: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
186 |
return TYPE_ALIAS |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
187 |
if exclude is not TYPE_RELOCATED: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
188 |
relocated = Relocated(self._dbh, address) |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
189 |
if relocated: |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
190 |
return TYPE_RELOCATED |
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
191 |
return 0 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
192 |
|
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
193 |
def _is_other_address(self, address, exclude): |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
194 |
"""Checks if *address* is known for an Account (TYPE_ACCOUNT), |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
195 |
Alias (TYPE_ALIAS) or Relocated (TYPE_RELOCATED), except for |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
196 |
*exclude*. Returns `False` if the address is not known for other |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
197 |
types. |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
198 |
|
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
199 |
Raises a `VMMError` if the address is known. |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
200 |
""" |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
201 |
other = self._chk_other_address_types(address, exclude) |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
202 |
if not other: |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
203 |
return False |
341
6709d0faf2f5
VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
337
diff
changeset
|
204 |
# TP: %(a_type)s will be one of: 'an account', 'an alias' or |
6709d0faf2f5
VMM/…: Unified messages and removed non-ASCII quotes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
337
diff
changeset
|
205 |
# 'a relocated user' |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
206 |
msg = _("There is already %(a_type)s with the address '%(address)s'.") |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
207 |
raise VMMError(msg % {'a_type': OTHER_TYPES[other][0], |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
208 |
'address': address}, OTHER_TYPES[other][1]) |
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
209 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
210 |
def _get_account(self, address): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
211 |
"""Return an Account instances for the given address (str).""" |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
212 |
address = EmailAddress(address) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
213 |
self._db_connect() |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
214 |
return Account(self._dbh, address) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
215 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
216 |
def _get_alias(self, address): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
217 |
"""Return an Alias instances for the given address (str).""" |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
218 |
address = EmailAddress(address) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
219 |
self._db_connect() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
220 |
return Alias(self._dbh, address) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
221 |
|
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
222 |
def _get_catchall(self, domain): |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
223 |
"""Return a CatchallAlias instances for the given domain (str).""" |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
224 |
self._db_connect() |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
225 |
return CatchallAlias(self._dbh, domain) |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
226 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
227 |
def _get_relocated(self, address): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
228 |
"""Return a Relocated instances for the given address (str).""" |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
229 |
address = EmailAddress(address) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
230 |
self._db_connect() |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
231 |
return Relocated(self._dbh, address) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
232 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
233 |
def _get_domain(self, domainname): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
234 |
"""Return a Domain instances for the given domain name (str).""" |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
235 |
self._db_connect() |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
236 |
return Domain(self._dbh, domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
237 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
238 |
def _get_disk_usage(self, directory): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
239 |
"""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
|
240 |
|
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
241 |
Arguments: |
40 | 242 |
|
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
243 |
`directory` : basestring |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
244 |
The directory to summarize recursively disk usage for |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
245 |
""" |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
246 |
if lisdir(directory): |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
247 |
return Popen([self._cfg.dget('bin.du'), "-hs", directory], |
653
cf07e4468934
VMM: Post-2to3 fixes.
Pascal Volk <user@localhost.localdomain.org>
parents:
649
diff
changeset
|
248 |
stdout=PIPE).communicate()[0].decode().split('\t')[0] |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
249 |
else: |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
250 |
self._warnings.append(_('No such directory: %s') % directory) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
251 |
return 0 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
252 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
253 |
def _make_domain_dir(self, domain): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
254 |
"""Create a directory for the `domain` and its accounts.""" |
310
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
255 |
cwd = os.getcwd() |
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
256 |
hashdir, domdir = domain.directory.split(os.path.sep)[-2:] |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
257 |
dir_created = False |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
258 |
os.chdir(self._cfg.dget('misc.base_directory')) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
259 |
old_umask = os.umask(0o022) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
260 |
if not os.path.exists(hashdir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
261 |
os.mkdir(hashdir, 0o711) |
310
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
262 |
os.chown(hashdir, 0, 0) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
263 |
dir_created = True |
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
264 |
if not dir_created and not lisdir(hashdir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
265 |
raise VMMError(_("'%s' is not a directory.") % hashdir, |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
266 |
NO_SUCH_DIRECTORY) |
380
5aaf2dd6b146
VMM/handler: Handler._make_domain_dir(): Check if the domain
Pascal Volk <neverseen@users.sourceforge.net>
parents:
375
diff
changeset
|
267 |
if os.path.exists(domain.directory): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
268 |
raise VMMError(_("The file/directory '%s' already exists.") % |
381
98223e5c95e0
VMM:/handler: Fixed typo introduced with the previous commit.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
380
diff
changeset
|
269 |
domain.directory, VMM_ERROR) |
310
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
270 |
os.mkdir(os.path.join(hashdir, domdir), |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
271 |
self._cfg.dget('domain.directory_mode')) |
310
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
272 |
os.chown(domain.directory, 0, domain.gid) |
493
30365a87650d
VMM/handler: Create domain directory with umask 0022.
Pascal Volk <user@localhost.localdomain.org>
parents:
470
diff
changeset
|
273 |
os.umask(old_umask) |
310
644e2cc4a441
VMM/Handler: Reworked __domDirMake and reamed to __make_domain_dir.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
309
diff
changeset
|
274 |
os.chdir(cwd) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
275 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
276 |
def _make_home(self, account): |
309
d21423478803
VMM/mailbox: Added to the repository.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
294
diff
changeset
|
277 |
"""Create a home directory for the new Account *account*.""" |
329
41789df75339
VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
327
diff
changeset
|
278 |
domdir = account.domain.directory |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
279 |
if not lisdir(domdir): |
330
3fe8d6cdbe3a
VMM/handler: _make_home() Create the domain directory if it
Pascal Volk <neverseen@users.sourceforge.net>
parents:
329
diff
changeset
|
280 |
self._make_domain_dir(account.domain) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
281 |
os.umask(0o007) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
282 |
uid = account.uid |
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
283 |
os.chdir(domdir) |
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
284 |
os.mkdir('%s' % uid, self._cfg.dget('account.directory_mode')) |
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
285 |
os.chown('%s' % uid, uid, account.gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
286 |
|
337
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
287 |
def _make_account_dirs(self, account): |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
288 |
"""Create all necessary directories for the account.""" |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
289 |
oldpwd = os.getcwd() |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
290 |
self._make_home(account) |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
291 |
mailbox = new_mailbox(account) |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
292 |
mailbox.create() |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
293 |
folders = self._cfg.dget('mailbox.folders').split(':') |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
294 |
if any(folders): |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
295 |
bad = mailbox.add_boxes(folders, |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
296 |
self._cfg.dget('mailbox.subscribe')) |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
297 |
if bad: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
298 |
self._warnings.append(_("Skipped mailbox folders:") + |
337
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
299 |
'\n\t- ' + '\n\t- '.join(bad)) |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
300 |
os.chdir(oldpwd) |
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
301 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
302 |
def _delete_home(self, domdir, uid, gid): |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
303 |
"""Delete a user's home directory. |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
304 |
|
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
305 |
Arguments: |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
306 |
|
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
307 |
`domdir` : basestring |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
308 |
The directory of the domain the user belongs to |
329
41789df75339
VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
327
diff
changeset
|
309 |
(commonly AccountObj.domain.directory) |
670
f374ef062c94
VMM/*: Post-2to3 fix. Updated some error messages/comments.
Pascal Volk <user@localhost.localdomain.org>
parents:
653
diff
changeset
|
310 |
`uid` : int |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
311 |
The user's UID (commonly AccountObj.uid) |
670
f374ef062c94
VMM/*: Post-2to3 fix. Updated some error messages/comments.
Pascal Volk <user@localhost.localdomain.org>
parents:
653
diff
changeset
|
312 |
`gid` : int |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
313 |
The user's GID (commonly AccountObj.gid) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
314 |
""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
315 |
assert all(isinstance(xid, int) for xid in (uid, gid)) and \ |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
316 |
isinstance(domdir, str) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
317 |
if uid < MIN_UID or gid < MIN_GID: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
318 |
raise VMMError(_("UID '%(uid)u' and/or GID '%(gid)u' are less " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
319 |
"than %(min_uid)u/%(min_gid)u.") % {'uid': uid, |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
320 |
'gid': gid, 'min_gid': MIN_GID, 'min_uid': MIN_UID}, |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
321 |
MAILDIR_PERM_MISMATCH) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
322 |
if domdir.count('..'): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
323 |
raise VMMError(_('Found ".." in domain directory path: %s') % |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
324 |
domdir, FOUND_DOTS_IN_PATH) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
325 |
if not lisdir(domdir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
326 |
raise VMMError(_("No such directory: %s") % domdir, |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
327 |
NO_SUCH_DIRECTORY) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
328 |
os.chdir(domdir) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
329 |
userdir = '%s' % uid |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
330 |
if not lisdir(userdir): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
331 |
self._warnings.append(_("No such directory: %s") % |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
332 |
os.path.join(domdir, userdir)) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
333 |
return |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
334 |
mdstat = os.lstat(userdir) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
335 |
if (mdstat.st_uid, mdstat.st_gid) != (uid, gid): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
336 |
raise VMMError(_('Detected owner/group mismatch in home ' |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
337 |
'directory.'), MAILDIR_PERM_MISMATCH) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
338 |
rmtree(userdir, ignore_errors=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
339 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
340 |
def _delete_domain_dir(self, domdir, gid): |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
341 |
"""Delete a domain's directory. |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
342 |
|
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
343 |
Arguments: |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
344 |
|
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
345 |
`domdir` : basestring |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
346 |
The domain's directory (commonly DomainObj.directory) |
670
f374ef062c94
VMM/*: Post-2to3 fix. Updated some error messages/comments.
Pascal Volk <user@localhost.localdomain.org>
parents:
653
diff
changeset
|
347 |
`gid` : int |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
348 |
The domain's GID (commonly DomainObj.gid) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
349 |
""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
350 |
assert isinstance(domdir, str) and isinstance(gid, int) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
351 |
if gid < MIN_GID: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
352 |
raise VMMError(_("GID '%(gid)u' is less than '%(min_gid)u'.") % |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
353 |
{'gid': gid, 'min_gid': MIN_GID}, |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
354 |
DOMAINDIR_GROUP_MISMATCH) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
355 |
if domdir.count('..'): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
356 |
raise VMMError(_('Found ".." in domain directory path: %s') % |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
357 |
domdir, FOUND_DOTS_IN_PATH) |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
358 |
if not lisdir(domdir): |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
359 |
self._warnings.append(_('No such directory: %s') % domdir) |
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
360 |
return |
327
bb9ff81928f1
VMM/handler: Use more common.lisdir() in Handler's methods _chkenv,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
325
diff
changeset
|
361 |
dirst = os.lstat(domdir) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
362 |
if dirst.st_gid != gid: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
363 |
raise VMMError(_('Detected group mismatch in domain directory: ' |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
364 |
'%s') % domdir, DOMAINDIR_GROUP_MISMATCH) |
325
06c0457036a0
VMM/handler: Reworked methods _get_disk_usage, _delete_home and
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
365 |
rmtree(domdir, ignore_errors=True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
366 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
367 |
def has_warnings(self): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
368 |
"""Checks if warnings are present, returns bool.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
369 |
return bool(len(self._warnings)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
370 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
371 |
def get_warnings(self): |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
372 |
"""Returns a list with all available warnings and resets all |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
373 |
warnings. |
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
374 |
""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
375 |
ret_val = self._warnings[:] |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
376 |
del self._warnings[:] |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
377 |
return ret_val |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
378 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
379 |
def cfg_dget(self, option): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
380 |
"""Get the configured value of the *option* (section.option). |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
381 |
When the option was not configured its default value will be |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
382 |
returned.""" |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
383 |
return self._cfg.dget(option) |
40 | 384 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
385 |
def cfg_pget(self, option): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
386 |
"""Get the configured value of the *option* (section.option).""" |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
387 |
return self._cfg.pget(option) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
388 |
|
280
db35d2eec518
VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
278
diff
changeset
|
389 |
def cfg_install(self): |
db35d2eec518
VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
278
diff
changeset
|
390 |
"""Installs the cfg_dget method as ``cfg_dget`` into the built-in |
db35d2eec518
VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
278
diff
changeset
|
391 |
namespace.""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
392 |
import builtins |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
393 |
assert 'cfg_dget' not in builtins.__dict__ |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
394 |
builtins.__dict__['cfg_dget'] = self._cfg.dget |
280
db35d2eec518
VMM/{Config,Handler}: moved Config.install() to Handler.cfg_install().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
278
diff
changeset
|
395 |
|
686
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
396 |
def domain_add(self, domainname, transport=None, note=None): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
397 |
"""Wrapper around Domain's set_quotalimit, set_transport and save.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
398 |
dom = self._get_domain(domainname) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
399 |
if transport is None: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
400 |
dom.set_transport(Transport(self._dbh, |
458
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
401 |
transport=self._cfg.dget('domain.transport'))) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
402 |
else: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
403 |
dom.set_transport(Transport(self._dbh, transport=transport)) |
686
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
404 |
if note: |
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
405 |
dom.set_note(note) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
406 |
dom.set_quotalimit(QuotaLimit(self._dbh, |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
407 |
bytes=int(self._cfg.dget('domain.quota_bytes')), |
458
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
408 |
messages=self._cfg.dget('domain.quota_messages'))) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
409 |
dom.set_serviceset(ServiceSet(self._dbh, |
458
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
410 |
imap=self._cfg.dget('domain.imap'), |
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
411 |
pop3=self._cfg.dget('domain.pop3'), |
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
412 |
sieve=self._cfg.dget('domain.sieve'), |
4ff0fa3ba0fa
VMM/config: Moved some options to section `domain':
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
413 |
smtp=self._cfg.dget('domain.smtp'))) |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
414 |
dom.set_directory(self._cfg.dget('misc.base_directory')) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
415 |
dom.save() |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
416 |
self._make_domain_dir(dom) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
417 |
|
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
418 |
def domain_quotalimit(self, domainname, bytes_, messages=0, force=False): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
419 |
"""Wrapper around Domain.update_quotalimit().""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
420 |
if not all(isinstance(i, int) for i in (bytes_, messages)): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
421 |
raise TypeError("'bytes_' and 'messages' have to be " |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
422 |
"integers or longs.") |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
423 |
assert isinstance(force, bool) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
424 |
dom = self._get_domain(domainname) |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
425 |
quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages) |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
426 |
dom.update_quotalimit(quotalimit, force) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
427 |
|
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
428 |
def domain_services(self, domainname, force=False, *services): |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
429 |
"""Wrapper around Domain.update_serviceset().""" |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
430 |
assert isinstance(force, bool) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
431 |
kwargs = dict.fromkeys(SERVICES, False) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
432 |
for service in set(services): |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
433 |
if service not in SERVICES: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
434 |
raise DomainError(_("Unknown service: '%s'") % service, |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
435 |
UNKNOWN_SERVICE) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
436 |
kwargs[service] = True |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
437 |
|
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
438 |
dom = self._get_domain(domainname) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
439 |
serviceset = ServiceSet(self._dbh, **kwargs) |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
440 |
dom.update_serviceset(serviceset, force) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
426
diff
changeset
|
441 |
|
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
442 |
def domain_transport(self, domainname, transport, force=False): |
557
1498abbb6c91
VMM/handler: Restored method Handler.domain_transport().
Pascal Volk <user@localhost.localdomain.org>
parents:
555
diff
changeset
|
443 |
"""Wrapper around Domain.update_transport()""" |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
444 |
assert isinstance(force, bool) |
557
1498abbb6c91
VMM/handler: Restored method Handler.domain_transport().
Pascal Volk <user@localhost.localdomain.org>
parents:
555
diff
changeset
|
445 |
dom = self._get_domain(domainname) |
1498abbb6c91
VMM/handler: Restored method Handler.domain_transport().
Pascal Volk <user@localhost.localdomain.org>
parents:
555
diff
changeset
|
446 |
trsp = Transport(self._dbh, transport=transport) |
681
4cab983479db
VMM: Code cleanup.
Pascal Volk <user@localhost.localdomain.org>
parents:
676
diff
changeset
|
447 |
dom.update_transport(trsp, force) |
557
1498abbb6c91
VMM/handler: Restored method Handler.domain_transport().
Pascal Volk <user@localhost.localdomain.org>
parents:
555
diff
changeset
|
448 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
449 |
def domain_note(self, domainname, note): |
557
1498abbb6c91
VMM/handler: Restored method Handler.domain_transport().
Pascal Volk <user@localhost.localdomain.org>
parents:
555
diff
changeset
|
450 |
"""Wrapper around Domain.update_note()""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
451 |
dom = self._get_domain(domainname) |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
452 |
dom.update_note(note) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
453 |
|
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
454 |
def domain_delete(self, domainname, force=False): |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
455 |
"""Wrapper around Domain.delete()""" |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
456 |
if not isinstance(force, bool): |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
457 |
raise TypeError('force must be a bool') |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
458 |
dom = self._get_domain(domainname) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
459 |
gid = dom.gid |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
460 |
domdir = dom.directory |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
461 |
if self._cfg.dget('domain.force_deletion') or force: |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
462 |
dom.delete(True) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
463 |
else: |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
330
diff
changeset
|
464 |
dom.delete(False) |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
465 |
if self._cfg.dget('domain.delete_directory'): |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
466 |
self._delete_domain_dir(domdir, gid) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
467 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
468 |
def domain_info(self, domainname, details=None): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
469 |
"""Wrapper around Domain.get_info(), Domain.get_accounts(), |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
470 |
Domain.get_aliase_names(), Domain.get_aliases() and |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
471 |
Domain.get_relocated.""" |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
472 |
if details not in [None, 'accounts', 'aliasdomains', 'aliases', 'full', |
510
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
508
diff
changeset
|
473 |
'relocated', 'catchall']: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
474 |
raise VMMError(_("Invalid argument: '%s'") % details, |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
475 |
INVALID_ARGUMENT) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
476 |
dom = self._get_domain(domainname) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
477 |
dominfo = dom.get_info() |
702
01db2457bbed
VMM/handler: Improved domaininfo subcommand.
Pascal Volk <user@localhost.localdomain.org>
parents:
675
diff
changeset
|
478 |
if dominfo['domain name'].startswith('xn--') or \ |
01db2457bbed
VMM/handler: Improved domaininfo subcommand.
Pascal Volk <user@localhost.localdomain.org>
parents:
675
diff
changeset
|
479 |
dominfo['domain name'].count('.xn--'): |
447
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
444
diff
changeset
|
480 |
dominfo['domain name'] += ' (%s)' % \ |
653
cf07e4468934
VMM: Post-2to3 fixes.
Pascal Volk <user@localhost.localdomain.org>
parents:
649
diff
changeset
|
481 |
dominfo['domain name'].encode('utf-8').decode('idna') |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
482 |
if details is None: |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
483 |
return dominfo |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
484 |
elif details == 'accounts': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
485 |
return (dominfo, dom.get_accounts()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
486 |
elif details == 'aliasdomains': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
487 |
return (dominfo, dom.get_aliase_names()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
488 |
elif details == 'aliases': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
489 |
return (dominfo, dom.get_aliases()) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
490 |
elif details == 'relocated': |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
491 |
return(dominfo, dom.get_relocated()) |
510
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
508
diff
changeset
|
492 |
elif details == 'catchall': |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
508
diff
changeset
|
493 |
return(dominfo, dom.get_catchall()) |
62
869de537a020
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
55
diff
changeset
|
494 |
else: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
233
diff
changeset
|
495 |
return (dominfo, dom.get_aliase_names(), dom.get_accounts(), |
510
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
508
diff
changeset
|
496 |
dom.get_aliases(), dom.get_relocated(), dom.get_catchall()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
497 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
498 |
def aliasdomain_add(self, aliasname, domainname): |
55
15c873f94ba6
* 'VirtualMailManager/Exceptions.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
54
diff
changeset
|
499 |
"""Adds an alias domain to the domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
500 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
501 |
Arguments: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
502 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
503 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
504 |
The name of the alias domain |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
505 |
`domainname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
506 |
The name of the target domain |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
507 |
""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
508 |
dom = self._get_domain(domainname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
509 |
alias_dom = AliasDomain(self._dbh, aliasname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
510 |
alias_dom.set_destination(dom) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
511 |
alias_dom.save() |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
512 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
513 |
def aliasdomain_info(self, aliasname): |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
514 |
"""Returns a dict (keys: "alias" and "domain") with the names of |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
515 |
the alias domain and its primary domain.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
516 |
self._db_connect() |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
517 |
alias_dom = AliasDomain(self._dbh, aliasname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
518 |
return alias_dom.info() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
519 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
520 |
def aliasdomain_switch(self, aliasname, domainname): |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
521 |
"""Modifies the target domain of an existing alias domain. |
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
522 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
523 |
Arguments: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
524 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
525 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
526 |
The name of the alias domain |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
527 |
`domainname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
528 |
The name of the new target domain |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
529 |
""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
530 |
dom = self._get_domain(domainname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
531 |
alias_dom = AliasDomain(self._dbh, aliasname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
532 |
alias_dom.set_destination(dom) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
533 |
alias_dom.switch() |
78
8f1e501b1bb1
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
534 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
535 |
def aliasdomain_delete(self, aliasname): |
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
536 |
"""Deletes the given alias domain. |
53
5b50eb306d37
* 'VirtualMailManager/DomainAlias.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
52
diff
changeset
|
537 |
|
244
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
538 |
Argument: |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
539 |
|
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
540 |
`aliasname` : basestring |
698ba4208ddc
VMM/Handler: adjusted Handler.aliasDomain*() methods to changes
Pascal Volk <neverseen@users.sourceforge.net>
parents:
241
diff
changeset
|
541 |
The name of the alias domain |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
542 |
""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
543 |
self._db_connect() |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
544 |
alias_dom = AliasDomain(self._dbh, aliasname) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
545 |
alias_dom.delete() |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
546 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
547 |
def domain_list(self, pattern=None): |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
548 |
"""Wrapper around function search() from module Domain.""" |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
549 |
from VirtualMailManager.domain import search |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
550 |
like = False |
241
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
551 |
if pattern and (pattern.startswith('%') or pattern.endswith('%')): |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
552 |
like = True |
2493453f2c10
VMM/Handler: small code cleanups and an improved import statement.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
553 |
if not re.match(RE_DOMAIN_SEARCH, pattern.strip('%')): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
554 |
raise VMMError(_("The pattern '%s' contains invalid " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
555 |
"characters.") % pattern, DOMAIN_INVALID) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
556 |
self._db_connect() |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
557 |
return search(self._dbh, pattern=pattern, like=like) |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
558 |
|
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
559 |
def address_list(self, typelimit, pattern=None): |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
560 |
"""TODO""" |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
561 |
llike = dlike = False |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
562 |
lpattern = dpattern = None |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
563 |
if pattern: |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
564 |
parts = pattern.split('@', 2) |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
565 |
if len(parts) == 2: |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
566 |
# The pattern includes '@', so let's treat the |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
567 |
# parts separately to allow for pattern search like %@domain.% |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
568 |
lpattern = parts[0] |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
569 |
llike = lpattern.startswith('%') or lpattern.endswith('%') |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
570 |
dpattern = parts[1] |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
571 |
dlike = dpattern.startswith('%') or dpattern.endswith('%') |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
572 |
|
638
0de0b9e75c9f
VMM: Partial PEP-308-ification.
Pascal Volk <user@localhost.localdomain.org>
parents:
637
diff
changeset
|
573 |
checkp = lpattern.strip('%') if llike else lpattern |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
574 |
if len(checkp) > 0 and re.search(RE_LOCALPART, checkp): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
575 |
raise VMMError(_("The pattern '%s' contains invalid " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
576 |
"characters.") % pattern, |
611
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
577 |
LOCALPART_INVALID) |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
578 |
else: |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
579 |
# else just match on domains |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
580 |
# (or should that be local part, I don't know…) |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
581 |
dpattern = parts[0] |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
582 |
dlike = dpattern.startswith('%') or dpattern.endswith('%') |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
583 |
|
638
0de0b9e75c9f
VMM: Partial PEP-308-ification.
Pascal Volk <user@localhost.localdomain.org>
parents:
637
diff
changeset
|
584 |
checkp = dpattern.strip('%') if dlike else dpattern |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
585 |
if len(checkp) > 0 and not re.match(RE_DOMAIN_SEARCH, checkp): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
586 |
raise VMMError(_("The pattern '%s' contains invalid " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
587 |
"characters.") % pattern, DOMAIN_INVALID) |
555
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
588 |
self._db_connect() |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
589 |
from VirtualMailManager.common import search_addresses |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
590 |
return search_addresses(self._dbh, typelimit=typelimit, |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
591 |
lpattern=lpattern, llike=llike, |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
592 |
dpattern=dpattern, dlike=dlike) |
499c63f52462
Provide list{addresses,aliases,users,relocated} subcommands
martin f. krafft <madduck@madduck.net>
parents:
539
diff
changeset
|
593 |
|
686
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
594 |
def user_add(self, emailaddress, password, note=None): |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
595 |
"""Wrapper around Account.set_password() and Account.save().""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
596 |
acc = self._get_account(emailaddress) |
337
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
597 |
if acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
598 |
raise VMMError(_("The account '%s' already exists.") % |
337
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
599 |
acc.address, ACCOUNT_EXISTS) |
422
33a45e4c80c4
VMM: Deleted a few unused variables.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
600 |
self._is_other_address(acc.address, TYPE_ACCOUNT) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
601 |
acc.set_password(password) |
686
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
602 |
if note: |
5f4abdab738e
VMM: Added option `-n NOTE' to {domain,user}add.
Pascal Volk <user@localhost.localdomain.org>
parents:
681
diff
changeset
|
603 |
acc.set_note(note) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
604 |
acc.save() |
337
150ddcc8b315
VMM/{,cli/}handler: user_add: Check earlier if the account exists.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
335
diff
changeset
|
605 |
self._make_account_dirs(acc) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
606 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
607 |
def alias_add(self, aliasaddress, *targetaddresses): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
608 |
"""Creates a new `Alias` entry for the given *aliasaddress* with |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
609 |
the given *targetaddresses*.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
610 |
alias = self._get_alias(aliasaddress) |
375
4cbaf8d229f9
VMM/{,cli/}handler: Moved the 'address-in-use check' (introduced
Pascal Volk <neverseen@users.sourceforge.net>
parents:
373
diff
changeset
|
611 |
if not alias: |
4cbaf8d229f9
VMM/{,cli/}handler: Moved the 'address-in-use check' (introduced
Pascal Volk <neverseen@users.sourceforge.net>
parents:
373
diff
changeset
|
612 |
self._is_other_address(alias.address, TYPE_ALIAS) |
611
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
613 |
destinations = [DestinationEmailAddress(addr, self._dbh) |
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
614 |
for addr in targetaddresses] |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
615 |
warnings = [] |
281
59ff7c719697
VMM/Alias: moved the postconf stuff from the Handlers to Alias class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
280
diff
changeset
|
616 |
destinations = alias.add_destinations(destinations, warnings) |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
617 |
if warnings: |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
618 |
self._warnings.append(_('Ignored destination addresses:')) |
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
619 |
self._warnings.extend((' * %s' % w for w in warnings)) |
221
371ae0b4443d
VMM/Alias: renamed Alias.add_destination() to add_destinations().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
216
diff
changeset
|
620 |
for destination in destinations: |
371
3b2fd0b4e51b
VMM/handler: Handler.alias_add() and Handler.relocated_add() use
Pascal Volk <neverseen@users.sourceforge.net>
parents:
366
diff
changeset
|
621 |
if destination.gid and \ |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
285
diff
changeset
|
622 |
not self._chk_other_address_types(destination, TYPE_RELOCATED): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
623 |
self._warnings.append(_("The destination account/alias '%s' " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
624 |
"does not exist.") % destination) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
625 |
|
333
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
626 |
def user_delete(self, emailaddress, force=False): |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
627 |
"""Wrapper around Account.delete(...)""" |
333
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
628 |
if not isinstance(force, bool): |
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
629 |
raise TypeError('force must be a bool') |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
630 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
631 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
632 |
raise VMMError(_("The account '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
633 |
acc.address, NO_SUCH_ACCOUNT) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
634 |
uid = acc.uid |
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
635 |
gid = acc.gid |
329
41789df75339
VMM/account: Replaced property domain_directory by domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
327
diff
changeset
|
636 |
dom_dir = acc.domain.directory |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
637 |
acc_dir = acc.home |
333
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
638 |
acc.delete(force) |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
639 |
if self._cfg.dget('account.delete_directory'): |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
640 |
try: |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
641 |
self._delete_home(dom_dir, uid, gid) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
642 |
except VMMError as err: |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
643 |
if err.code in (FOUND_DOTS_IN_PATH, MAILDIR_PERM_MISMATCH, |
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
644 |
NO_SUCH_DIRECTORY): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
645 |
warning = _("""\ |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
646 |
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
|
647 |
But an error occurred while deleting the following directory: |
333
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
648 |
'%(directory)s' |
1ed85e696748
VMM/{account,handler}: Account delete, use the boolean keyword force too.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
331
diff
changeset
|
649 |
Reason: %(reason)s""") % {'directory': acc_dir, 'reason': err.msg} |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
650 |
self._warnings.append(warning) |
47
191d5a5adc4a
* Removed gettext import and setup in VirtualMailManager/:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
45
diff
changeset
|
651 |
else: |
191
db77501aeaed
VMM/Handler: __mailDirMake() add warning for skipped mailboxes.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
190
diff
changeset
|
652 |
raise |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
653 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
654 |
def alias_info(self, aliasaddress): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
655 |
"""Returns an iterator object for all destinations (`EmailAddress` |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
656 |
instances) for the `Alias` with the given *aliasaddress*.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
657 |
alias = self._get_alias(aliasaddress) |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
658 |
if alias: |
215
33f727efa7c4
PEP-8-ified the work of the last days.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
208
diff
changeset
|
659 |
return alias.get_destinations() |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
660 |
if not self._is_other_address(alias.address, TYPE_ALIAS): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
661 |
raise VMMError(_("The alias '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
662 |
alias.address, NO_SUCH_ALIAS) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
663 |
|
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
664 |
def alias_delete(self, aliasaddress, targetaddresses=None): |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
665 |
"""Deletes the `Alias` *aliasaddress* with all its destinations from |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
666 |
the database. If *targetaddresses* is not ``None``, only the given |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
667 |
destinations will be removed from the alias.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
668 |
alias = self._get_alias(aliasaddress) |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
669 |
error = None |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
670 |
if targetaddresses is None: |
196
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
671 |
alias.delete() |
65a3163bd113
VMM/{Alias,Handler}: reworked Alias class, adjusted Handler class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
192
diff
changeset
|
672 |
else: |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
673 |
destinations = [DestinationEmailAddress(addr, self._dbh) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
674 |
for addr in targetaddresses] |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
675 |
warnings = [] |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
676 |
try: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
677 |
alias.del_destinations(destinations, warnings) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
678 |
except VMMError as err: |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
679 |
error = err |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
680 |
if warnings: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
681 |
self._warnings.append(_('Ignored destination addresses:')) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
682 |
self._warnings.extend((' * %s' % w for w in warnings)) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
683 |
if error: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
684 |
raise error |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
685 |
|
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
686 |
def catchall_add(self, domain, *targetaddresses): |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
687 |
"""Creates a new `CatchallAlias` entry for the given *domain* with |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
688 |
the given *targetaddresses*.""" |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
689 |
catchall = self._get_catchall(domain) |
611
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
690 |
destinations = [DestinationEmailAddress(addr, self._dbh) |
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
605
diff
changeset
|
691 |
for addr in targetaddresses] |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
692 |
warnings = [] |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
693 |
destinations = catchall.add_destinations(destinations, warnings) |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
694 |
if warnings: |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
695 |
self._warnings.append(_('Ignored destination addresses:')) |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
696 |
self._warnings.extend((' * %s' % w for w in warnings)) |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
697 |
for destination in destinations: |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
698 |
if destination.gid and \ |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
699 |
not self._chk_other_address_types(destination, TYPE_RELOCATED): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
700 |
self._warnings.append(_("The destination account/alias '%s' " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
701 |
"does not exist.") % destination) |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
702 |
|
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
703 |
def catchall_info(self, domain): |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
704 |
"""Returns an iterator object for all destinations (`EmailAddress` |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
705 |
instances) for the `CatchallAlias` with the given *domain*.""" |
508
18870919ec48
Fixup catchall_info to return iterator, not self
martin f. krafft <madduck@madduck.net>
parents:
505
diff
changeset
|
706 |
return self._get_catchall(domain).get_destinations() |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
707 |
|
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
708 |
def catchall_delete(self, domain, targetaddresses=None): |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
709 |
"""Deletes the `CatchallAlias` for domain *domain* with all its |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
710 |
destinations from the database. If *targetaddresses* is not |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
711 |
``None``, only those destinations will be removed from the alias.""" |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
712 |
catchall = self._get_catchall(domain) |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
713 |
error = None |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
714 |
if targetaddresses is None: |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
715 |
catchall.delete() |
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
716 |
else: |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
717 |
destinations = [DestinationEmailAddress(addr, self._dbh) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
718 |
for addr in targetaddresses] |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
719 |
warnings = [] |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
720 |
try: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
721 |
catchall.del_destinations(destinations, warnings) |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
722 |
except VMMError as err: |
618
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
723 |
error = err |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
724 |
if warnings: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
725 |
self._warnings.append(_('Ignored destination addresses:')) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
726 |
self._warnings.extend((' * %s' % w for w in warnings)) |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
727 |
if error: |
d8736bb80bdc
VMM: {alias,catchall}delete: Accept multiple destinations.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
728 |
raise error |
505
3da8c919584f
Provide catchall_* methods to the Handler class
martin f. krafft <madduck@madduck.net>
parents:
493
diff
changeset
|
729 |
|
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
730 |
def user_info(self, emailaddress, details=None): |
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
731 |
"""Wrapper around Account.get_info(...)""" |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
732 |
if details not in (None, 'du', 'aliases', 'full'): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
733 |
raise VMMError(_("Invalid argument: '%s'") % details, |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
734 |
INVALID_ARGUMENT) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
735 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
736 |
if not acc: |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
737 |
if not self._is_other_address(acc.address, TYPE_ACCOUNT): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
738 |
raise VMMError(_("The account '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
739 |
acc.address, NO_SUCH_ACCOUNT) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
740 |
info = acc.get_info() |
318
4dc2edf02d11
VMM//{,cli/}Handler: Reworked configuration related parts.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
741 |
if self._cfg.dget('account.disk_usage') or details in ('du', 'full'): |
293
a77b67673aa6
VMM/Account: replaced attribute _mid : int by _mail : MailLocation.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
290
diff
changeset
|
742 |
path = os.path.join(acc.home, acc.mail_location.directory) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
743 |
info['disk usage'] = self._get_disk_usage(path) |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
744 |
if details in (None, 'du'): |
90
1734eb5101c6
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
88
diff
changeset
|
745 |
return info |
174
974bafa59330
VMM/Config: reworked configuration handling.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
168
diff
changeset
|
746 |
if details in ('aliases', 'full'): |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
747 |
return (info, acc.get_aliases()) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
748 |
return info |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
749 |
|
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
750 |
def user_by_uid(self, uid): |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
751 |
"""Search for an Account by its *uid*. |
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
752 |
Returns a dict (address, uid and gid) if a user could be found.""" |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
319
diff
changeset
|
753 |
from VirtualMailManager.account import get_account_by_uid |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
754 |
self._db_connect() |
255
d2ddd4a6528d
VMM/Handler: renamed some methods and added their missing docstrings:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
755 |
return get_account_by_uid(uid, self._dbh) |
19
bf9a03c476fc
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
18
diff
changeset
|
756 |
|
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
757 |
def user_password(self, emailaddress, password): |
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
758 |
"""Wrapper for Account.modify('password' ...).""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
759 |
if not isinstance(password, str) or not password: |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
760 |
raise VMMError(_("Could not accept password: '%s'") % password, |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
761 |
INVALID_ARGUMENT) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
762 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
763 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
764 |
raise VMMError(_("The account '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
765 |
acc.address, NO_SUCH_ACCOUNT) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
766 |
acc.modify('password', password) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
767 |
|
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
768 |
def user_name(self, emailaddress, name): |
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
769 |
"""Wrapper for Account.modify('name', ...).""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
770 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
771 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
772 |
raise VMMError(_("The account '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
773 |
acc.address, NO_SUCH_ACCOUNT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
774 |
acc.modify('name', name) |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
775 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
776 |
def user_note(self, emailaddress, note): |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
777 |
"""Wrapper for Account.modify('note', ...).""" |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
778 |
acc = self._get_account(emailaddress) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
779 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
780 |
raise VMMError(_("The account '%s' does not exist.") % |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
781 |
acc.address, NO_SUCH_ACCOUNT) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
782 |
acc.modify('note', note) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
536
diff
changeset
|
783 |
|
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
784 |
def user_quotalimit(self, emailaddress, bytes_, messages=0): |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
785 |
"""Wrapper for Account.update_quotalimit(QuotaLimit).""" |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
786 |
acc = self._get_account(emailaddress) |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
787 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
788 |
raise VMMError(_("The account '%s' does not exist.") % |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
789 |
acc.address, NO_SUCH_ACCOUNT) |
605
b994444f7dee
VMM/handler: Fixed user{quota,services,transport} subcommands.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
790 |
if bytes_ == 'domain': |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
791 |
quotalimit = None |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
792 |
else: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
793 |
if not all(isinstance(i, int) for i in (bytes_, messages)): |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
794 |
raise TypeError("'bytes_' and 'messages' have to be " |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
795 |
"integers or longs.") |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
796 |
quotalimit = QuotaLimit(self._dbh, bytes=bytes_, |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
797 |
messages=messages) |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
798 |
acc.update_quotalimit(quotalimit) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
799 |
|
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
800 |
def user_transport(self, emailaddress, transport): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
381
diff
changeset
|
801 |
"""Wrapper for Account.update_transport(Transport).""" |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
802 |
if not isinstance(transport, str) or not transport: |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
803 |
raise VMMError(_("Could not accept transport: '%s'") % transport, |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
804 |
INVALID_ARGUMENT) |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
805 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
806 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
807 |
raise VMMError(_("The account '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
808 |
acc.address, NO_SUCH_ACCOUNT) |
638
0de0b9e75c9f
VMM: Partial PEP-308-ification.
Pascal Volk <user@localhost.localdomain.org>
parents:
637
diff
changeset
|
809 |
transport = None if transport == 'domain' \ |
0de0b9e75c9f
VMM: Partial PEP-308-ification.
Pascal Volk <user@localhost.localdomain.org>
parents:
637
diff
changeset
|
810 |
else Transport(self._dbh, transport=transport) |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
811 |
acc.update_transport(transport) |
17
fe9be0081e5f
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
16
diff
changeset
|
812 |
|
444
95275b61ff8a
VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
813 |
def user_services(self, emailaddress, *services): |
95275b61ff8a
VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
814 |
"""Wrapper around Account.update_serviceset().""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
815 |
acc = self._get_account(emailaddress) |
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
816 |
if not acc: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
817 |
raise VMMError(_("The account '%s' does not exist.") % |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
818 |
acc.address, NO_SUCH_ACCOUNT) |
605
b994444f7dee
VMM/handler: Fixed user{quota,services,transport} subcommands.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
819 |
if len(services) == 1 and services[0] == 'domain': |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
820 |
serviceset = None |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
821 |
else: |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
822 |
kwargs = dict.fromkeys(SERVICES, False) |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
823 |
for service in set(services): |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
824 |
if service not in SERVICES: |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
825 |
raise VMMError(_("Unknown service: '%s'") % service, |
533
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
826 |
UNKNOWN_SERVICE) |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
827 |
kwargs[service] = True |
2676dbf43e1c
Change UI to accept 'default' to restore inherited values
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
828 |
serviceset = ServiceSet(self._dbh, **kwargs) |
444
95275b61ff8a
VMM/account: Integrated class ServiceSet in class Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
829 |
acc.update_serviceset(serviceset) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
830 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
831 |
def relocated_add(self, emailaddress, targetaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
832 |
"""Creates a new `Relocated` entry in the database. If there is |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
833 |
already a relocated user with the given *emailaddress*, only the |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
834 |
*targetaddress* for the relocated user will be updated.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
835 |
relocated = self._get_relocated(emailaddress) |
375
4cbaf8d229f9
VMM/{,cli/}handler: Moved the 'address-in-use check' (introduced
Pascal Volk <neverseen@users.sourceforge.net>
parents:
373
diff
changeset
|
836 |
if not relocated: |
4cbaf8d229f9
VMM/{,cli/}handler: Moved the 'address-in-use check' (introduced
Pascal Volk <neverseen@users.sourceforge.net>
parents:
373
diff
changeset
|
837 |
self._is_other_address(relocated.address, TYPE_RELOCATED) |
373
1016a17684c1
VMM/handler: Handler.relocated_add() check if the target address'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
372
diff
changeset
|
838 |
destination = DestinationEmailAddress(targetaddress, self._dbh) |
1016a17684c1
VMM/handler: Handler.relocated_add() check if the target address'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
372
diff
changeset
|
839 |
relocated.set_destination(destination) |
1016a17684c1
VMM/handler: Handler.relocated_add() check if the target address'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
372
diff
changeset
|
840 |
if destination.gid and \ |
1016a17684c1
VMM/handler: Handler.relocated_add() check if the target address'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
372
diff
changeset
|
841 |
not self._chk_other_address_types(destination, TYPE_RELOCATED): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
842 |
self._warnings.append(_("The destination account/alias '%s' " |
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
843 |
"does not exist.") % destination) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
844 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
845 |
def relocated_info(self, emailaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
846 |
"""Returns the target address of the relocated user with the given |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
847 |
*emailaddress*.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
848 |
relocated = self._get_relocated(emailaddress) |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
849 |
if relocated: |
251
0963ad2f5fe2
VMM/Handler: Implemented Handler._chk_other_address_types().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
244
diff
changeset
|
850 |
return relocated.get_info() |
283
ea6d052de24a
VMM/Handler: code cleanups in the user/alias/relocated info methods.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
282
diff
changeset
|
851 |
if not self._is_other_address(relocated.address, TYPE_RELOCATED): |
643
df1e3b67882a
Ran 2to3 from Python 3.2.3.
Pascal Volk <user@localhost.localdomain.org>
parents:
638
diff
changeset
|
852 |
raise VMMError(_("The relocated user '%s' does not exist.") % |
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
310
diff
changeset
|
853 |
relocated.address, NO_SUCH_RELOCATED) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
854 |
|
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
855 |
def relocated_delete(self, emailaddress): |
197
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
856 |
"""Deletes the relocated user with the given *emailaddress* from |
d2712e8c724e
VMM/{Relocated,Handler}: reworked Relocated class, adjusted Handler.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
196
diff
changeset
|
857 |
the database.""" |
319
f4956b4ceba1
VMM//{,cli/}Handler: PEP-8-ified the Handler classes:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
318
diff
changeset
|
858 |
relocated = self._get_relocated(emailaddress) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
859 |
relocated.delete() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
78
diff
changeset
|
860 |
|
277
e50ffc0b8468
VMM{,/cli}/Handler: adjusted user* methods to the changes in Account.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
272
diff
changeset
|
861 |
del _ |