Domain/mailbox creation control when importing from LDAP.

see #591
This commit is contained in:
Antoine Nguyen
2014-08-24 12:27:19 +02:00
parent d1b0b6a5b4
commit d40d162ffa
5 changed files with 66 additions and 18 deletions
+8
View File
@@ -274,6 +274,14 @@ Modoboa should connect to your LDAP server. They are described just below:
| | | |
| | | |
+--------------------+---------------------------------+--------------------+
|Domain/mailbox |Automatically create a domain and|yes |
|creation |a mailbox when a new user is | |
| |created just after the first | |
| |successful authentication. You | |
| |will generally want to disable | |
| |this feature when the relay | |
| |domains extension is in use | |
+--------------------+---------------------------------+--------------------+
If you need additional parameters, you will find a detailled
+42 -10
View File
@@ -31,6 +31,9 @@ def enabled_applications():
class GeneralParametersForm(parameters.AdminParametersForm):
"""General parameters."""
app = "core"
sep1 = SeparatorField(label=ugettext_lazy("Authentication"))
@@ -78,7 +81,8 @@ class GeneralParametersForm(parameters.AdminParametersForm):
ldap_server_address = forms.CharField(
label=ugettext_lazy("Server address"),
initial="localhost",
help_text=ugettext_lazy("The IP address of the DNS name of the LDAP server")
help_text=ugettext_lazy(
"The IP address of the DNS name of the LDAP server")
)
ldap_server_port = forms.IntegerField(
@@ -90,7 +94,8 @@ class GeneralParametersForm(parameters.AdminParametersForm):
ldap_secured = YesNoField(
label=ugettext_lazy("Use a secured connection"),
initial="no",
help_text=ugettext_lazy("Use an SSL/TLS connection to access the LDAP server")
help_text=ugettext_lazy(
"Use an SSL/TLS connection to access the LDAP server")
)
ldap_auth_method = forms.ChoiceField(
@@ -105,14 +110,20 @@ class GeneralParametersForm(parameters.AdminParametersForm):
ldap_bind_dn = forms.CharField(
label=ugettext_lazy("Bind DN"),
initial='',
help_text=ugettext_lazy("The distinguished name to use when binding to the LDAP server. Leave empty for an anonymous bind"),
help_text=ugettext_lazy(
"The distinguished name to use when binding to the LDAP server. "
"Leave empty for an anonymous bind"
),
required=False
)
ldap_bind_password = forms.CharField(
label=ugettext_lazy("Bind password"),
initial='',
help_text=ugettext_lazy("The password to use when binding to the LDAP server (with 'Bind DN')"),
help_text=ugettext_lazy(
"The password to use when binding to the LDAP server "
"(with 'Bind DN')"
),
widget=forms.PasswordInput(render_value=True),
required=False
)
@@ -120,21 +131,29 @@ class GeneralParametersForm(parameters.AdminParametersForm):
ldap_search_base = forms.CharField(
label=ugettext_lazy("Users search base"),
initial="",
help_text=ugettext_lazy("The distinguished name of the search base used to find users"),
help_text=ugettext_lazy(
"The distinguished name of the search base used to find users"
),
required=False
)
ldap_search_filter = forms.CharField(
label=ugettext_lazy("Search filter"),
initial="(mail=%(user)s)",
help_text=ugettext_lazy("An optional filter string (e.g. '(objectClass=person)'). In order to be valid, it must be enclosed in parentheses."),
help_text=ugettext_lazy(
"An optional filter string (e.g. '(objectClass=person)'). "
"In order to be valid, it must be enclosed in parentheses."
),
required=False
)
ldap_user_dn_template = forms.CharField(
label=ugettext_lazy("User DN template"),
initial="",
help_text=ugettext_lazy("The template used to construct a user's DN. It should contain one placeholder (ie. %(user)s)"),
help_text=ugettext_lazy(
"The template used to construct a user's DN. It should contain "
"one placeholder (ie. %(user)s)"
),
required=False
)
@@ -147,7 +166,8 @@ class GeneralParametersForm(parameters.AdminParametersForm):
ldap_is_active_directory = YesNoField(
label=ugettext_lazy("Active Directory"),
initial="no",
help_text=ugettext_lazy("Tell if the LDAP server is an Active Directory one")
help_text=ugettext_lazy(
"Tell if the LDAP server is an Active Directory one")
)
ldap_admin_groups = forms.CharField(
@@ -169,6 +189,15 @@ class GeneralParametersForm(parameters.AdminParametersForm):
required=False
)
ldap_create_domain_mailbox = YesNoField(
label=ugettext_lazy("Domain/mailbox creation"),
initial="yes",
help_text=ugettext_lazy(
"Automatically create a domain and a mailbox when a new user "
"is created just after the first successful authentication."
)
)
sep3 = SeparatorField(label=ugettext_lazy("Miscellaneous"))
log_maximum_age = forms.IntegerField(
@@ -187,7 +216,9 @@ class GeneralParametersForm(parameters.AdminParametersForm):
label=ugettext_lazy("Default top redirection"),
choices=[],
initial="user",
help_text=ugettext_lazy("The default redirection used when no application is specified")
help_text=ugettext_lazy(
"The default redirection used when no application is specified"
)
)
# Visibility rules
@@ -279,7 +310,8 @@ class GeneralParametersForm(parameters.AdminParametersForm):
"last_name": "sn"
})
ldap_uri = 'ldaps://' if values["ldap_secured"] == "yes" else "ldap://"
ldap_uri += "%s:%s" % (values["ldap_server_address"], values["ldap_server_port"])
ldap_uri += "%s:%s" % (
values["ldap_server_address"], values["ldap_server_port"])
setattr(settings, "AUTH_LDAP_SERVER_URI", ldap_uri)
setattr(settings, "AUTH_LDAP_GROUP_TYPE", PosixGroupType())
setattr(settings, "AUTH_LDAP_GROUP_SEARCH", LDAPSearch(
+2
View File
@@ -198,6 +198,8 @@ def account_auto_created(user):
from modoboa.core.models import User
from modoboa.lib.permissions import grant_access_to_object
if parameters.get_admin("LDAP_CREATE_DOMAIN_MAILBOX", app="core") == "no":
return
localpart, domname = split_mailbox(user.username)
if user.group != 'SimpleUsers' and domname is None:
return
+11 -7
View File
@@ -61,13 +61,15 @@ class SQLconnector(object):
"""
if self.user.group == 'SimpleUsers':
rcpts = [self.user.email] \
+ self.user.mailbox_set.all()[0].alias_addresses
flt &= Q(rid__email__in=rcpts)
rcpts = [self.user.email]
if self.user.mailbox_set.count():
rcpts += self.user.mailbox_set.all()[0].alias_addresses
return flt & Q(rid__email__in=rcpts)
elif not self.user.is_superuser:
doms = Domain.objects.get_for_admin(self.user)
regexp = "(%s)" % '|'.join([dom.name for dom in doms])
flt &= Q(rid__email__regex=regexp)
return flt & Q(rid__email__regex=regexp)
return flt
def _apply_extra_search_filter(self, crit, pattern):
"""Apply search filters using additional criterias.
@@ -90,7 +92,7 @@ class SQLconnector(object):
"""
flt = Q(rs__in=[' ', 'V', 'R', 'p']) \
if self.navparams.get('viewrequests', '0') != '1' else Q(rs='p')
self._apply_msgrcpt_filters(flt)
flt = self._apply_msgrcpt_filters(flt)
pattern = self.navparams.get("pattern", "")
if pattern:
criteria = self.navparams.get('criteria')
@@ -226,8 +228,9 @@ class PgSQLconnector(SQLconnector):
"""
self._where = []
if self.user.group == 'SimpleUsers':
rcpts = [self.user.email] \
+ self.user.mailbox_set.all()[0].alias_addresses
rcpts = [self.user.email]
if self.user.mailbox_set.count():
rcpts += self.user.mailbox_set.all()[0].alias_addresses
self._where.append(
"convert_from(maddr.email, 'UTF8') IN (%s)" \
% (','.join(["'%s'" % rcpt for rcpt in rcpts])))
@@ -236,6 +239,7 @@ class PgSQLconnector(SQLconnector):
regexp = "(%s)" % '|'.join([dom.name for dom in doms])
self._where.append(
"convert_from(maddr.email, 'UTF8') ~ '%s'" % regexp)
return flt
def _apply_extra_search_filter(self, crit, pattern):
"""Apply search filters using additional criterias.
+3 -1
View File
@@ -102,7 +102,9 @@ def viewmail_selfservice(request, mail_id,
@selfservice(viewmail_selfservice)
def viewmail(request, mail_id):
rcpt = request.GET["rcpt"]
if request.user.mailbox_set.count():
if request.user.email == rcpt:
get_connector().set_msgrcpt_status(rcpt, mail_id, 'V')
elif request.user.mailbox_set.count():
mb = Mailbox.objects.get(user=request.user)
if rcpt == mb.full_address or rcpt in mb.alias_addresses:
get_connector().set_msgrcpt_status(rcpt, mail_id, 'V')