mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Check domain at user mail creation/changing
This commit is contained in:
parent
f278b3b6a0
commit
a8572559ac
2 changed files with 9 additions and 4 deletions
|
@ -104,11 +104,9 @@ def domain_add(domains, web=False):
|
||||||
domain +'. IN SOA ns.'+ domain +'. root.'+ domain +'. '+ timestamp +' 10800 3600 604800 38400',
|
domain +'. IN SOA ns.'+ domain +'. root.'+ domain +'. '+ timestamp +' 10800 3600 604800 38400',
|
||||||
domain +'. IN NS ns.'+ domain +'.',
|
domain +'. IN NS ns.'+ domain +'.',
|
||||||
domain +'. IN A '+ ip,
|
domain +'. IN A '+ ip,
|
||||||
domain +'. IN MX 5 mail.'+ domain +'.',
|
domain +'. IN MX 5 '+ domain +'.',
|
||||||
domain +'. IN TXT "v=spf1 a mx a:'+ domain +' ?all"',
|
domain +'. IN TXT "v=spf1 a mx a:'+ domain +' ?all"',
|
||||||
'mail.'+ domain +'. IN A '+ ip,
|
|
||||||
'ns.'+ domain +'. IN A '+ ip,
|
'ns.'+ domain +'. IN A '+ ip,
|
||||||
'root.'+ domain +'. IN A '+ ip
|
|
||||||
]
|
]
|
||||||
with open('/var/lib/bind/' + domain + '.zone', 'w') as zone:
|
with open('/var/lib/bind/' + domain + '.zone', 'w') as zone:
|
||||||
for line in zone_lines:
|
for line in zone_lines:
|
||||||
|
|
|
@ -8,6 +8,7 @@ import random
|
||||||
import string
|
import string
|
||||||
import getpass
|
import getpass
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
||||||
|
from yunohost_domain import domain_list
|
||||||
|
|
||||||
def user_list(fields=None, filter=None, limit=None, offset=None):
|
def user_list(fields=None, filter=None, limit=None, offset=None):
|
||||||
"""
|
"""
|
||||||
|
@ -92,7 +93,8 @@ def user_create(username, firstname, lastname, mail, password):
|
||||||
#if not os.system("getent passwd " + username):
|
#if not os.system("getent passwd " + username):
|
||||||
# raise YunoHostError(17, _("Username not available"))
|
# raise YunoHostError(17, _("Username not available"))
|
||||||
|
|
||||||
#TODO: check if mail belongs to a domain
|
if mail[mail.find('@')+1:] not in domain_list()['Domains']:
|
||||||
|
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
|
||||||
|
|
||||||
# Get random UID/GID
|
# Get random UID/GID
|
||||||
uid_check = gid_check = 0
|
uid_check = gid_check = 0
|
||||||
|
@ -187,6 +189,7 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
|
||||||
with YunoHostLDAP() as yldap:
|
with YunoHostLDAP() as yldap:
|
||||||
attrs_to_fetch = ['givenName', 'sn', 'mail', 'maildrop']
|
attrs_to_fetch = ['givenName', 'sn', 'mail', 'maildrop']
|
||||||
new_attr_dict = {}
|
new_attr_dict = {}
|
||||||
|
domains = domain_list()['Domains']
|
||||||
|
|
||||||
# Populate user informations
|
# Populate user informations
|
||||||
result = yldap.search(base='ou=users,dc=yunohost,dc=org', filter='uid=' + username, attrs=attrs_to_fetch)
|
result = yldap.search(base='ou=users,dc=yunohost,dc=org', filter='uid=' + username, attrs=attrs_to_fetch)
|
||||||
|
@ -214,6 +217,8 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
|
||||||
|
|
||||||
if mail:
|
if mail:
|
||||||
yldap.validate_uniqueness({ 'mail': mail })
|
yldap.validate_uniqueness({ 'mail': mail })
|
||||||
|
if mail[mail.find('@')+1:] not in domains:
|
||||||
|
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
|
||||||
del user['mail'][0]
|
del user['mail'][0]
|
||||||
new_attr_dict['mail'] = [mail] + user['mail']
|
new_attr_dict['mail'] = [mail] + user['mail']
|
||||||
|
|
||||||
|
@ -222,6 +227,8 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
|
||||||
add_mailalias = [ add_mailalias ]
|
add_mailalias = [ add_mailalias ]
|
||||||
for mail in add_mailalias:
|
for mail in add_mailalias:
|
||||||
yldap.validate_uniqueness({ 'mail': mail })
|
yldap.validate_uniqueness({ 'mail': mail })
|
||||||
|
if mail[mail.find('@')+1:] not in domains:
|
||||||
|
raise YunoHostError(22, _("Domain not found : ")+ mail[mail.find('@')+1:])
|
||||||
user['mail'].append(mail)
|
user['mail'].append(mail)
|
||||||
new_attr_dict['mail'] = user['mail']
|
new_attr_dict['mail'] = user['mail']
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue