author | Pascal Volk <user@localhost.localdomain.org> |
Sun, 23 Mar 2014 16:27:31 +0000 | |
changeset 741 | 5ffba47a137d |
parent 704 | ad15e89a93ec |
child 711 | 2a75058fc064 |
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:
701
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. |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
4 |
""" |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
5 |
VirtualMailManager.domain |
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
6 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
7 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
8 |
Virtual Mail Manager's Domain class to manage e-mail domains. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
9 |
""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
10 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
11 |
import os |
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
12 |
import re |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
13 |
from random import choice |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
14 |
|
316
31d8931dc535
VMM/constants: Replaced the constants subpackage by a module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
294
diff
changeset
|
15 |
from VirtualMailManager.constants import \ |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
16 |
ACCOUNT_AND_ALIAS_PRESENT, DOMAIN_ALIAS_EXISTS, DOMAIN_EXISTS, \ |
404
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
17 |
DOMAIN_INVALID, DOMAIN_TOO_LONG, NO_SUCH_DOMAIN, VMM_ERROR |
615
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
18 |
from VirtualMailManager.common import validate_transport |
404
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
19 |
from VirtualMailManager.errors import VMMError, DomainError as DomErr |
615
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
20 |
from VirtualMailManager.maillocation import MailLocation |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
21 |
from VirtualMailManager.pycompat import all, any |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
22 |
from VirtualMailManager.quotalimit import QuotaLimit |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
23 |
from VirtualMailManager.serviceset import ServiceSet |
320
011066435e6f
VMM/*: Made all modules names lowercase, adjusted imports.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
316
diff
changeset
|
24 |
from VirtualMailManager.transport import Transport |
185
6e1ef32fbd82
VMM/*: Moved some methods from classes to modules __init__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
25 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
26 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
27 |
MAILDIR_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz' |
704
ad15e89a93ec
VMM/domain: RE_DOMAIN: Check Punycode TLDs more precise.
Pascal Volk <user@localhost.localdomain.org>
parents:
703
diff
changeset
|
28 |
RE_DOMAIN = re.compile(r"""^(?:[a-z0-9-]{1,63}\.){1,} # one or more labels |
ad15e89a93ec
VMM/domain: RE_DOMAIN: Check Punycode TLDs more precise.
Pascal Volk <user@localhost.localdomain.org>
parents:
703
diff
changeset
|
29 |
(?:[a-z]{2,} # a ASCII TLD |
ad15e89a93ec
VMM/domain: RE_DOMAIN: Check Punycode TLDs more precise.
Pascal Volk <user@localhost.localdomain.org>
parents:
703
diff
changeset
|
30 |
|xn--[a-z0-9]{4,})$ # or a ACE TLD""", re.X) |
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
31 |
_ = lambda msg: msg |
404
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
32 |
cfg_dget = lambda option: None |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
33 |
|
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
34 |
|
122
30abf0abf8f8
Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
110
diff
changeset
|
35 |
class Domain(object): |
3
a9b44e04bf01
* VirtualMailManager/Account.py:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
0
diff
changeset
|
36 |
"""Class to manage e-mail domains.""" |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
37 |
__slots__ = ('_directory', '_gid', '_name', '_qlimit', '_services', |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
38 |
'_transport', '_note', '_dbh', '_new') |
225
a51809f7940b
VMM/Transport: reworked Transport class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
222
diff
changeset
|
39 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
40 |
def __init__(self, dbh, domainname): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
41 |
"""Creates a new Domain instance. |
122
30abf0abf8f8
Converted to new-style class, added __slots__.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
110
diff
changeset
|
42 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
43 |
Loads all relevant data from the database, if the domain could be |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
44 |
found. To create a new domain call the methods set_directory() and |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
45 |
set_transport() before save(). |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
46 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
47 |
A DomainError will be thrown when the *domainname* is the name of |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
48 |
an alias domain. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
49 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
50 |
Arguments: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
51 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
52 |
`dbh` : pyPgSQL.PgSQL.Connection |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
53 |
a database connection for the database access |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
54 |
`domainname` : basestring |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
55 |
The name of the domain |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
56 |
""" |
199
0684790fff7c
VMM: renamed function chk_domainname() -> check_domainname().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
198
diff
changeset
|
57 |
self._name = check_domainname(domainname) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
58 |
self._dbh = dbh |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
59 |
self._gid = 0 |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
60 |
self._qlimit = None |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
61 |
self._services = None |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
62 |
self._transport = None |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
63 |
self._directory = None |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
64 |
self._note = None |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
65 |
self._new = True |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
66 |
self._load() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
67 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
68 |
def _load(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
69 |
"""Load information from the database and checks if the domain name |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
70 |
is the primary one. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
71 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
72 |
Raises a DomainError if Domain._name isn't the primary name of the |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
73 |
domain. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
74 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
75 |
dbc = self._dbh.cursor() |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
76 |
dbc.execute('SELECT dd.gid, qid, ssid, tid, domaindir, is_primary, ' |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
77 |
'note ' |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
78 |
'FROM domain_data dd, domain_name dn WHERE domainname = ' |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
79 |
'%s AND dn.gid = dd.gid', (self._name,)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
80 |
result = dbc.fetchone() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
81 |
dbc.close() |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
82 |
if result: |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
83 |
if not result[5]: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
84 |
raise DomErr(_(u"The domain '%s' is an alias domain.") % |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
85 |
self._name, DOMAIN_ALIAS_EXISTS) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
86 |
self._gid, self._directory = result[0], result[4] |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
87 |
self._qlimit = QuotaLimit(self._dbh, qid=result[1]) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
88 |
self._services = ServiceSet(self._dbh, ssid=result[2]) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
89 |
self._transport = Transport(self._dbh, tid=result[3]) |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
90 |
self._note = result[6] |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
91 |
self._new = False |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
92 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
93 |
def _set_gid(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
94 |
"""Sets the ID of the domain - if not set yet.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
95 |
assert self._gid == 0 |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
96 |
dbc = self._dbh.cursor() |
43
92a6132940f5
* 'VirtualMailManager/Account.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
35
diff
changeset
|
97 |
dbc.execute("SELECT nextval('domain_gid')") |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
98 |
self._gid = dbc.fetchone()[0] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
99 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
100 |
|
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
101 |
def _check_for_addresses(self): |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
102 |
"""Checks dependencies for deletion. Raises a DomainError if there |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
103 |
are accounts, aliases and/or relocated users. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
104 |
""" |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
105 |
dbc = self._dbh.cursor() |
492
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
106 |
dbc.execute('SELECT ' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
107 |
'(SELECT count(gid) FROM users WHERE gid = %(gid)u)' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
108 |
' as account_count, ' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
109 |
'(SELECT count(gid) FROM alias WHERE gid = %(gid)u)' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
110 |
' as alias_count, ' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
111 |
'(SELECT count(gid) FROM relocated WHERE gid = %(gid)u)' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
112 |
' as relocated_count' |
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
113 |
% {'gid': self._gid}) |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
114 |
result = dbc.fetchall() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
115 |
dbc.close() |
492
e5c2b3647971
Modify address check query to obtain well-defined result
martin f. krafft <madduck@madduck.net>
parents:
453
diff
changeset
|
116 |
result = result[0] |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
117 |
if any(result): |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
118 |
keys = ('account_count', 'alias_count', 'relocated_count') |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
119 |
raise DomErr(_(u'There are %(account_count)u accounts, ' |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
120 |
u'%(alias_count)u aliases and %(relocated_count)u ' |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
121 |
u'relocated users.') % dict(zip(keys, result)), |
216
0c8c053b451c
Moved VirtualMailManager/Exceptions to VirtualMailManager/errors.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
199
diff
changeset
|
122 |
ACCOUNT_AND_ALIAS_PRESENT) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
123 |
|
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
124 |
def _chk_state(self, must_exist=True): |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
125 |
"""Checks the state of the Domain instance and will raise a |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
126 |
VirtualMailManager.errors.DomainError: |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
127 |
- if *must_exist* is `True` and the domain doesn't exist |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
128 |
- or *must_exist* is `False` and the domain exists |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
129 |
""" |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
130 |
if must_exist and self._new: |
417
8209da83e256
VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
404
diff
changeset
|
131 |
raise DomErr(_(u"The domain '%s' does not exist.") % self._name, |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
132 |
NO_SUCH_DOMAIN) |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
133 |
elif not must_exist and not self._new: |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
134 |
raise DomErr(_(u"The domain '%s' already exists.") % self._name, |
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
135 |
DOMAIN_EXISTS) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
136 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
137 |
def _update_tables(self, column, value): |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
138 |
"""Update table columns in the domain_data table.""" |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
139 |
dbc = self._dbh.cursor() |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
140 |
dbc.execute('UPDATE domain_data SET %s = %%s WHERE gid = %%s' % column, |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
141 |
(value, self._gid)) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
142 |
if dbc.rowcount > 0: |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
143 |
self._dbh.commit() |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
144 |
dbc.close() |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
145 |
|
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
146 |
def _update_tables_ref(self, column, value, force=False): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
147 |
"""Update various columns in the domain_data table. When *force* is |
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
148 |
`True`, the corresponding column in the users table will be reset to |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
149 |
NULL. |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
150 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
151 |
Arguments: |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
152 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
153 |
`column` : basestring |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
154 |
Name of the table column. Currently: qid, ssid and tid |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
155 |
`value` : long |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
156 |
The referenced key |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
157 |
`force` : bool |
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
158 |
reset existing users. Default: `False` |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
159 |
""" |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
160 |
if column not in ('qid', 'ssid', 'tid'): |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
161 |
raise ValueError('Unknown column: %r' % column) |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
162 |
self._update_tables(column, value) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
163 |
if force: |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
164 |
dbc = self._dbh.cursor() |
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
165 |
dbc.execute('UPDATE users SET %s = NULL WHERE gid = %%s' % column, |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
166 |
(self._gid,)) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
167 |
if dbc.rowcount > 0: |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
168 |
self._dbh.commit() |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
169 |
dbc.close() |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
170 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
171 |
@property |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
172 |
def gid(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
173 |
"""The GID of the Domain.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
174 |
return self._gid |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
175 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
176 |
@property |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
177 |
def name(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
178 |
"""The Domain's name.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
179 |
return self._name |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
180 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
181 |
@property |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
182 |
def directory(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
183 |
"""The Domain's directory.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
184 |
return self._directory |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
185 |
|
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
186 |
@property |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
187 |
def quotalimit(self): |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
188 |
"""The Domain's quota limit.""" |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
189 |
return self._qlimit |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
190 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
191 |
@property |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
192 |
def serviceset(self): |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
193 |
"""The Domain's serviceset.""" |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
194 |
return self._services |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
195 |
|
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
196 |
@property |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
197 |
def transport(self): |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
198 |
"""The Domain's transport.""" |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
199 |
return self._transport |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
200 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
201 |
@property |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
202 |
def note(self): |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
203 |
"""The Domain's note.""" |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
204 |
return self._note |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
205 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
206 |
def set_directory(self, basedir): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
207 |
"""Set the path value of the Domain's directory, inside *basedir*. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
208 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
209 |
Argument: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
210 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
211 |
`basedir` : basestring |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
212 |
The base directory of all domains |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
213 |
""" |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
214 |
self._chk_state(False) |
363
502d59f4bb34
VMM/domain: set_{directory,transport} make sure the domain is new.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
352
diff
changeset
|
215 |
assert self._directory is None |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
216 |
self._set_gid() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
217 |
self._directory = os.path.join(basedir, choice(MAILDIR_CHARS), |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
218 |
str(self._gid)) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
219 |
|
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
220 |
def set_quotalimit(self, quotalimit): |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
221 |
"""Set the quota limit for the new Domain. |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
222 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
223 |
Argument: |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
224 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
225 |
`quotalimit` : VirtualMailManager.quotalimit.QuotaLimit |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
226 |
The quota limit of the new Domain. |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
227 |
""" |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
228 |
self._chk_state(False) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
229 |
assert isinstance(quotalimit, QuotaLimit) |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
230 |
self._qlimit = quotalimit |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
231 |
|
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
232 |
def set_serviceset(self, serviceset): |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
233 |
"""Set the services for the new Domain. |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
234 |
|
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
235 |
Argument: |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
236 |
|
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
237 |
`serviceset` : VirtualMailManager.serviceset.ServiceSet |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
238 |
The service set for the new Domain. |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
239 |
""" |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
240 |
self._chk_state(False) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
241 |
assert isinstance(serviceset, ServiceSet) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
242 |
self._services = serviceset |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
243 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
244 |
def set_transport(self, transport): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
245 |
"""Set the transport for the new Domain. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
246 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
247 |
Argument: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
248 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
249 |
`transport` : VirtualMailManager.Transport |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
250 |
The transport of the new Domain |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
251 |
""" |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
252 |
self._chk_state(False) |
363
502d59f4bb34
VMM/domain: set_{directory,transport} make sure the domain is new.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
352
diff
changeset
|
253 |
assert isinstance(transport, Transport) |
615
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
254 |
validate_transport(transport, |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
255 |
MailLocation(self._dbh, |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
256 |
mbfmt=cfg_dget('mailbox.format'), |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
257 |
directory=cfg_dget('mailbox.root'))) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
258 |
self._transport = transport |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
259 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
260 |
def set_note(self, note): |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
261 |
"""Set the domain's (optional) note. |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
262 |
|
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
263 |
Argument: |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
264 |
|
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
265 |
`note` : basestring or None |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
266 |
The note, or None to remove |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
267 |
""" |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
268 |
self._chk_state(False) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
269 |
assert note is None or isinstance(note, basestring) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
270 |
self._note = note |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
271 |
|
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
272 |
def save(self): |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
273 |
"""Stores the new domain in the database.""" |
453
f2934105181b
VMM/domain: Extended Domain._chk_state() to support both states.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
447
diff
changeset
|
274 |
self._chk_state(False) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
275 |
assert all((self._directory, self._qlimit, self._services, |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
276 |
self._transport)) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
277 |
dbc = self._dbh.cursor() |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
278 |
dbc.execute('INSERT INTO domain_data (gid, qid, ssid, tid, domaindir, ' |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
279 |
'note) ' |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
280 |
'VALUES (%s, %s, %s, %s, %s, %s)', (self._gid, |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
281 |
self._qlimit.qid, self._services.ssid, self._transport.tid, |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
282 |
self._directory, self._note)) |
379
7518d927d443
VMM/*: Use target column names in all INSERT statements.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
366
diff
changeset
|
283 |
dbc.execute('INSERT INTO domain_name (domainname, gid, is_primary) ' |
7518d927d443
VMM/*: Use target column names in all INSERT statements.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
366
diff
changeset
|
284 |
'VALUES (%s, %s, TRUE)', (self._name, self._gid)) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
285 |
self._dbh.commit() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
286 |
dbc.close() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
287 |
self._new = False |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
288 |
|
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
289 |
def delete(self, force=False): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
290 |
"""Deletes the domain. |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
291 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
292 |
Arguments: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
293 |
|
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
294 |
`force` : bool |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
295 |
force the deletion of all available accounts, aliases and |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
296 |
relocated users. When *force* is `False` and there are accounts, |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
297 |
aliases and/or relocated users a DomainError will be raised. |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
298 |
Default `False` |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
299 |
""" |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
300 |
if not isinstance(force, bool): |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
301 |
raise TypeError('force must be a bool') |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
302 |
self._chk_state() |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
303 |
if not force: |
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
304 |
self._check_for_addresses() |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
305 |
dbc = self._dbh.cursor() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
306 |
for tbl in ('alias', 'users', 'relocated', 'domain_name', |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
307 |
'domain_data'): |
331
270b57af85de
VMM/domain: Simplified Domain.delete() related methods and their arguments,
Pascal Volk <neverseen@users.sourceforge.net>
parents:
320
diff
changeset
|
308 |
dbc.execute("DELETE FROM %s WHERE gid = %u" % (tbl, self._gid)) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
309 |
self._dbh.commit() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
310 |
dbc.close() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
311 |
self._gid = 0 |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
312 |
self._directory = self._qlimit = self._transport = None |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
313 |
self._services = None |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
314 |
self._new = True |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
315 |
|
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
316 |
def update_quotalimit(self, quotalimit, force=False): |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
317 |
"""Update the quota limit of the Domain. |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
318 |
|
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
319 |
If *force* is `True`, accounts-specific overrides will be reset |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
320 |
for all existing accounts of the domain. Otherwise, the limit |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
321 |
will only affect accounts that use the default. |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
322 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
323 |
Arguments: |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
324 |
|
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
325 |
`quotalimit` : VirtualMailManager.quotalimit.QuotaLimit |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
326 |
the new quota limit of the domain. |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
327 |
`force` : bool |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
328 |
enforce new quota limit for all accounts, default `False` |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
329 |
""" |
404
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
330 |
if cfg_dget('misc.dovecot_version') < 0x10102f00: |
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
331 |
raise VMMError(_(u'PostgreSQL-based dictionary quota requires ' |
417
8209da83e256
VMM: Updated some messages. (doesn't, isn't) -> (does not, is not)
Pascal Volk <neverseen@users.sourceforge.net>
parents:
404
diff
changeset
|
332 |
u'Dovecot >= v1.1.2.'), VMM_ERROR) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
333 |
self._chk_state() |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
334 |
assert isinstance(quotalimit, QuotaLimit) |
402
8984b1f4e6e3
VMM/domain: Execute the database updates of
Pascal Volk <neverseen@users.sourceforge.net>
parents:
392
diff
changeset
|
335 |
if not force and quotalimit == self._qlimit: |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
336 |
return |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
337 |
self._update_tables_ref('qid', quotalimit.qid, force) |
390
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
338 |
self._qlimit = quotalimit |
660b42391c8e
VMM/{account,domain,handler}: Added quota limit support. A few
Pascal Volk <neverseen@users.sourceforge.net>
parents:
379
diff
changeset
|
339 |
|
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
340 |
def update_serviceset(self, serviceset, force=False): |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
341 |
"""Assign a different set of services to the Domain, |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
342 |
|
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
343 |
If *force* is `True`, accounts-specific overrides will be reset |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
344 |
for all existing accounts of the domain. Otherwise, the service |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
345 |
set will only affect accounts that use the default. |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
346 |
|
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
347 |
Arguments: |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
348 |
`serviceset` : VirtualMailManager.serviceset.ServiceSet |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
349 |
the new set of services |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
350 |
`force` |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
351 |
enforce the serviceset for all accounts, default `False` |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
352 |
""" |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
353 |
self._chk_state() |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
354 |
assert isinstance(serviceset, ServiceSet) |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
355 |
if not force and serviceset == self._services: |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
356 |
return |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
357 |
self._update_tables_ref('ssid', serviceset.ssid, force) |
441
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
358 |
self._services = serviceset |
1af5fe0683ce
VMM/domain: Integrated class ServiceSet in class Domain.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
417
diff
changeset
|
359 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
360 |
def update_transport(self, transport, force=False): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
361 |
"""Sets a new transport for the Domain. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
362 |
|
534
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
363 |
If *force* is `True`, accounts-specific overrides will be reset |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
364 |
for all existing accounts of the domain. Otherwise, the transport |
6a27c7529cd7
Change 'force' argument to reset user records for tid/ssid/qid
martin f. krafft <madduck@madduck.net>
parents:
515
diff
changeset
|
365 |
setting will only affect accounts that use the default. |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
366 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
367 |
Arguments: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
368 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
369 |
`transport` : VirtualMailManager.Transport |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
370 |
the new transport |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
371 |
`force` : bool |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
372 |
enforce new transport setting for all accounts, default `False` |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
373 |
""" |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
374 |
self._chk_state() |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
375 |
assert isinstance(transport, Transport) |
402
8984b1f4e6e3
VMM/domain: Execute the database updates of
Pascal Volk <neverseen@users.sourceforge.net>
parents:
392
diff
changeset
|
376 |
if not force and transport == self._transport: |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
377 |
return |
615
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
378 |
validate_transport(transport, |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
379 |
MailLocation(self._dbh, |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
380 |
mbfmt=cfg_dget('mailbox.format'), |
5882bfdf83e8
VMM/domain: Enabled transport-validation.
Pascal Volk <user@localhost.localdomain.org>
parents:
611
diff
changeset
|
381 |
directory=cfg_dget('mailbox.root'))) |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
382 |
self._update_tables_ref('tid', transport.tid, force) |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
383 |
self._transport = transport |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
384 |
|
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
385 |
def update_note(self, note): |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
386 |
"""Sets a new note for the Domain. |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
387 |
|
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
388 |
Arguments: |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
389 |
|
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
390 |
`transport` : basestring or None |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
391 |
the new note |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
392 |
""" |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
393 |
self._chk_state() |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
394 |
assert note is None or isinstance(note, basestring) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
395 |
if note == self._note: |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
396 |
return |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
397 |
self._update_tables('note', note) |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
398 |
self._note = note |
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
399 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
400 |
def get_info(self): |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
401 |
"""Returns a dictionary with information about the domain.""" |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
402 |
self._chk_state() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
403 |
dbc = self._dbh.cursor() |
447
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
404 |
dbc.execute('SELECT aliasdomains "alias domains", accounts, aliases, ' |
515
09fa019bb330
Include catch-all count in domaininfo output
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
405 |
'relocated, catchall "catch-all dests" ' |
09fa019bb330
Include catch-all count in domaininfo output
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
406 |
'FROM vmm_domain_info WHERE gid = %s', (self._gid,)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
407 |
info = dbc.fetchone() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
408 |
dbc.close() |
515
09fa019bb330
Include catch-all count in domaininfo output
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
409 |
keys = ('alias domains', 'accounts', 'aliases', 'relocated', |
09fa019bb330
Include catch-all count in domaininfo output
martin f. krafft <madduck@madduck.net>
parents:
510
diff
changeset
|
410 |
'catch-all dests') |
392
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
411 |
info = dict(zip(keys, info)) |
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
412 |
info['gid'] = self._gid |
447
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
413 |
info['domain name'] = self._name |
392
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
414 |
info['transport'] = self._transport.transport |
447
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
415 |
info['domain directory'] = self._directory |
392
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
416 |
info['bytes'] = self._qlimit.bytes |
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
417 |
info['messages'] = self._qlimit.messages |
447
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
418 |
services = self._services.services |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
419 |
services = [s.upper() for s in services if services[s]] |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
420 |
if services: |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
421 |
services.sort() |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
422 |
else: |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
423 |
services.append('None') |
c31d604e26d3
VMM/domain: Extended/updated Domain.get_info() in order to:
Pascal Volk <neverseen@users.sourceforge.net>
parents:
441
diff
changeset
|
424 |
info['active services'] = ' '.join(services) |
539
5806fb74130b
Add note field to Account/Domain and CLI
martin f. krafft <madduck@madduck.net>
parents:
534
diff
changeset
|
425 |
info['note'] = self._note |
392
ffce67e3c6eb
VMM/domain: Adjusted Domain.get_info() to the updated vmm_domain_info view.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
390
diff
changeset
|
426 |
return info |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
427 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
428 |
def get_accounts(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
429 |
"""Returns a list with all accounts of the domain.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
430 |
self._chk_state() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
431 |
dbc = self._dbh.cursor() |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
432 |
dbc.execute('SELECT local_part from users where gid = %s ORDER BY ' |
352
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
433 |
'local_part', (self._gid,)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
434 |
users = dbc.fetchall() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
435 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
436 |
accounts = [] |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
437 |
if users: |
142
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
438 |
addr = u'@'.join |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
439 |
_dom = self._name |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
440 |
accounts = [addr((account[0], _dom)) for account in users] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
441 |
return accounts |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
442 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
443 |
def get_aliases(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
444 |
"""Returns a list with all aliases e-mail addresses of the domain.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
445 |
self._chk_state() |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
446 |
dbc = self._dbh.cursor() |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
447 |
dbc.execute('SELECT DISTINCT address FROM alias WHERE gid = %s ORDER ' |
352
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
448 |
'BY address', (self._gid,)) |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
449 |
addresses = dbc.fetchall() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
450 |
dbc.close() |
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
451 |
aliases = [] |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
452 |
if addresses: |
142
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
453 |
addr = u'@'.join |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
454 |
_dom = self._name |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
455 |
aliases = [addr((alias[0], _dom)) for alias in addresses] |
0
bb0aa2102206
Initial import @sf.net
Pascal Volk <neverseen@users.sourceforge.net>
parents:
diff
changeset
|
456 |
return aliases |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
457 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
458 |
def get_relocated(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
459 |
"""Returns a list with all addresses of relocated users.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
460 |
self._chk_state() |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
461 |
dbc = self._dbh.cursor() |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
462 |
dbc.execute('SELECT address FROM relocated WHERE gid = %s ORDER BY ' |
352
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
463 |
'address', (self._gid,)) |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
464 |
addresses = dbc.fetchall() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
465 |
dbc.close() |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
466 |
relocated = [] |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
467 |
if addresses: |
142
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
468 |
addr = u'@'.join |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
469 |
_dom = self._name |
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
470 |
relocated = [addr((address[0], _dom)) for address in addresses] |
80
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
471 |
return relocated |
5dedc673524e
* 'create_tables.pgsql'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
76
diff
changeset
|
472 |
|
510
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
473 |
def get_catchall(self): |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
474 |
"""Returns a list with all catchall e-mail addresses of the domain.""" |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
475 |
self._chk_state() |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
476 |
dbc = self._dbh.cursor() |
611
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
477 |
dbc.execute('SELECT DISTINCT destination FROM catchall WHERE gid = %s ' |
8e9b0046bc8f
PEP8: Fixed all PEP8 related issues.
Pascal Volk <user@localhost.localdomain.org>
parents:
568
diff
changeset
|
478 |
'ORDER BY destination', (self._gid,)) |
510
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
479 |
addresses = dbc.fetchall() |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
480 |
dbc.close() |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
481 |
return addresses |
1fa354bbdb90
Add catchall info to domain_info output
martin f. krafft <madduck@madduck.net>
parents:
492
diff
changeset
|
482 |
|
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
483 |
def get_aliase_names(self): |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
484 |
"""Returns a list with all alias domain names of the domain.""" |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
485 |
self._chk_state() |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
486 |
dbc = self._dbh.cursor() |
290
e2785e04f92e
VMM/…: re-indented long queries and error messages.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
254
diff
changeset
|
487 |
dbc.execute('SELECT domainname FROM domain_name WHERE gid = %s AND ' |
352
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
488 |
'NOT is_primary ORDER BY domainname', (self._gid,)) |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
489 |
anames = dbc.fetchall() |
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
490 |
dbc.close() |
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
491 |
aliasdomains = [] |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
492 |
if anames: |
142
28f26f7f3d8f
Reduced the mixing/concatenating of str and unicode objects.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
138
diff
changeset
|
493 |
aliasdomains = [aname[0] for aname in anames] |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
494 |
return aliasdomains |
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
495 |
|
198
02d467e4fbab
VMM/Domain: added function get_gid() to the Domain module.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
185
diff
changeset
|
496 |
|
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
497 |
def check_domainname(domainname): |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
498 |
"""Returns the validated domain name `domainname`. |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
499 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
500 |
Throws an `DomainError`, if the domain name is too long or doesn't |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
501 |
look like a valid domain name (label.label.label). |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
502 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
503 |
""" |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
504 |
if not RE_DOMAIN.match(domainname): |
294
7d1bafc6fa30
VMM/Domain: removed functions ace2idna() and idn2ascii().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
290
diff
changeset
|
505 |
domainname = domainname.encode('idna') |
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
506 |
if len(domainname) > 255: |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
507 |
raise DomErr(_(u'The domain name is too long'), DOMAIN_TOO_LONG) |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
508 |
if not RE_DOMAIN.match(domainname): |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
509 |
raise DomErr(_(u"The domain name '%s' is invalid") % domainname, |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
510 |
DOMAIN_INVALID) |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
511 |
return domainname |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
512 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
513 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
514 |
def get_gid(dbh, domainname): |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
515 |
"""Returns the group id of the domain *domainname*. |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
516 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
517 |
If the domain couldn't be found in the database 0 will be returned. |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
518 |
""" |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
519 |
domainname = check_domainname(domainname) |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
520 |
dbc = dbh.cursor() |
352
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
521 |
dbc.execute('SELECT gid FROM domain_name WHERE domainname = %s', |
22d115376e4d
VMM/…: Provide parameters as tuple to cursor.execute().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
336
diff
changeset
|
522 |
(domainname,)) |
254
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
523 |
gid = dbc.fetchone() |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
524 |
dbc.close() |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
525 |
if gid: |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
526 |
return gid[0] |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
527 |
return 0 |
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
528 |
|
8aecc83a0d32
VMM: moved functions ace2idna(), check_domainname(), idn2ascii()
Pascal Volk <neverseen@users.sourceforge.net>
parents:
242
diff
changeset
|
529 |
|
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
530 |
def search(dbh, pattern=None, like=False): |
236
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
531 |
"""'Search' for domains by *pattern* in the database. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
532 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
533 |
*pattern* may be a domain name or a partial domain name - starting |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
534 |
and/or ending with a '%' sign. When the *pattern* starts or ends with |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
535 |
a '%' sign *like* has to be `True` to perform a wildcard search. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
536 |
To retrieve all available domains use the arguments' default values. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
537 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
538 |
This function returns a tuple with a list and a dict: (order, domains). |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
539 |
The order list contains the domains' gid, alphabetical sorted by the |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
540 |
primary domain name. The domains dict's keys are the gids of the |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
541 |
domains. The value of item is a list. The first list element contains |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
542 |
the primary domain name or `None`. The elements [1:] contains the |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
543 |
names of alias domains. |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
544 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
545 |
Arguments: |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
546 |
|
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
547 |
`pattern` : basestring |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
548 |
a (partial) domain name (starting and/or ending with a "%" sign) |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
549 |
`like` : bool |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
550 |
should be `True` when *pattern* starts/ends with a "%" sign |
084331dd1e4c
VMM/Domain: reworked Domain class.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
225
diff
changeset
|
551 |
""" |
242
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
552 |
if pattern and not like: |
199
0684790fff7c
VMM: renamed function chk_domainname() -> check_domainname().
Pascal Volk <neverseen@users.sourceforge.net>
parents:
198
diff
changeset
|
553 |
pattern = check_domainname(pattern) |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
554 |
sql = 'SELECT gid, domainname, is_primary FROM domain_name' |
242
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
555 |
if pattern: |
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
556 |
if like: |
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
557 |
sql += " WHERE domainname LIKE '%s'" % pattern |
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
558 |
else: |
496099847480
VMM/Domain: search() small code cleanups.
Pascal Volk <neverseen@users.sourceforge.net>
parents:
240
diff
changeset
|
559 |
sql += " WHERE domainname = '%s'" % pattern |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
560 |
sql += ' ORDER BY is_primary DESC, domainname' |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
561 |
dbc = dbh.cursor() |
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
562 |
dbc.execute(sql) |
239
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
563 |
result = dbc.fetchall() |
35
22cc616aef61
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
34
diff
changeset
|
564 |
dbc.close() |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
565 |
|
239
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
566 |
gids = [domain[0] for domain in result if domain[2]] |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
567 |
domains = {} |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
568 |
for gid, domain, is_primary in result: |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
569 |
if is_primary: |
239
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
570 |
if not gid in domains: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
571 |
domains[gid] = [domain] |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
572 |
else: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
573 |
domains[gid].insert(0, domain) |
44
c9ab6900ede9
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
43
diff
changeset
|
574 |
else: |
239
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
575 |
if gid in gids: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
576 |
if gid in domains: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
577 |
domains[gid].append(domain) |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
578 |
else: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
579 |
domains[gid] = [domain] |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
580 |
else: |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
581 |
gids.append(gid) |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
582 |
domains[gid] = [None, domain] |
184970fd7486
VMM/Domain: search() lists now all matching domains, also when
Pascal Volk <neverseen@users.sourceforge.net>
parents:
162
diff
changeset
|
583 |
return gids, domains |
45
9e66138aad0b
* 'VirtualMailManager/VirtualMailManager.py'
Pascal Volk <neverseen@users.sourceforge.net>
parents:
44
diff
changeset
|
584 |
|
404
0c52094447b0
VMM/{account,domain}: Added a versions check to the update_quotalimit
Pascal Volk <neverseen@users.sourceforge.net>
parents:
402
diff
changeset
|
585 |
del _, cfg_dget |