mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Domain functions with arguments in a namespace
This commit is contained in:
parent
2ae505b69d
commit
4f3cf88623
3 changed files with 21 additions and 20 deletions
|
@ -171,7 +171,7 @@ domain:
|
||||||
add:
|
add:
|
||||||
action_help: Create a custom domain
|
action_help: Create a custom domain
|
||||||
arguments:
|
arguments:
|
||||||
domain:
|
domains:
|
||||||
help: Domain name to add
|
help: Domain name to add
|
||||||
nargs: '*'
|
nargs: '*'
|
||||||
ask: "New domain"
|
ask: "New domain"
|
||||||
|
@ -181,7 +181,7 @@ domain:
|
||||||
remove:
|
remove:
|
||||||
action_help: Delete domains
|
action_help: Delete domains
|
||||||
arguments:
|
arguments:
|
||||||
domain:
|
domains:
|
||||||
help: Domain(s) to delete
|
help: Domain(s) to delete
|
||||||
nargs: "*"
|
nargs: "*"
|
||||||
ask: "Domain to remove"
|
ask: "Domain to remove"
|
||||||
|
|
|
@ -7,24 +7,25 @@ import re
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args
|
||||||
|
|
||||||
def domain_list(args):
|
def domain_list(filter=None, limit=None, offset=None):
|
||||||
"""
|
"""
|
||||||
List YunoHost domains
|
List YunoHost domains
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
args -- Dictionnary of values (can be empty)
|
filter -- LDAP filter to search with
|
||||||
|
limit
|
||||||
|
offset
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict
|
Dict
|
||||||
"""
|
"""
|
||||||
with YunoHostLDAP() as yldap:
|
with YunoHostLDAP() as yldap:
|
||||||
result_dict = {}
|
result_dict = {}
|
||||||
if args['offset']: offset = int(args['offset'])
|
if offset: offset = int(offset)
|
||||||
else: offset = 0
|
else: offset = 0
|
||||||
if args['limit']: limit = int(args['limit'])
|
if limit: limit = int(limit)
|
||||||
else: limit = 1000
|
else: limit = 1000
|
||||||
if args['filter']: filter = args['filter']
|
if not filter: filter = 'virtualdomain=*'
|
||||||
else: filter = 'virtualdomain=*'
|
|
||||||
|
|
||||||
result = yldap.search('ou=domains,dc=yunohost,dc=org', filter, attrs=['virtualdomain'])
|
result = yldap.search('ou=domains,dc=yunohost,dc=org', filter, attrs=['virtualdomain'])
|
||||||
|
|
||||||
|
@ -40,12 +41,12 @@ def domain_list(args):
|
||||||
return result_dict
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def domain_add(args):
|
def domain_add(domains):
|
||||||
"""
|
"""
|
||||||
Add one or more domains
|
Add one or more domains
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
args -- Dictionnary of values (can be empty)
|
domains -- List of domains to add
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict
|
Dict
|
||||||
|
@ -57,10 +58,10 @@ def domain_add(args):
|
||||||
timestamp = str(now.year) + str(now.month) + str(now.day)
|
timestamp = str(now.year) + str(now.month) + str(now.day)
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if not isinstance(args['domain'], list):
|
if not isinstance(domains, list):
|
||||||
args['domain'] = [ args['domain'] ]
|
domains = [ domains ]
|
||||||
|
|
||||||
for domain in args['domain']:
|
for domain in domains:
|
||||||
yldap.validate_uniqueness({ 'virtualdomain' : domain })
|
yldap.validate_uniqueness({ 'virtualdomain' : domain })
|
||||||
attr_dict['virtualdomain'] = domain
|
attr_dict['virtualdomain'] = domain
|
||||||
|
|
||||||
|
@ -109,12 +110,12 @@ def domain_add(args):
|
||||||
return { 'Domains' : result }
|
return { 'Domains' : result }
|
||||||
|
|
||||||
|
|
||||||
def domain_remove(args):
|
def domain_remove(domains):
|
||||||
"""
|
"""
|
||||||
Remove domain from LDAP
|
Remove domain from LDAP
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
args -- Dictionnary of values
|
domains -- List of domains to remove
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict
|
Dict
|
||||||
|
@ -122,10 +123,10 @@ def domain_remove(args):
|
||||||
with YunoHostLDAP() as yldap:
|
with YunoHostLDAP() as yldap:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
if not isinstance(args['domain'], list):
|
if not isinstance(domains, list):
|
||||||
args['domain'] = [ args['domain'] ]
|
domains = [ domains ]
|
||||||
|
|
||||||
for domain in args['domain']:
|
for domain in domains:
|
||||||
if yldap.remove('virtualdomain=' + domain + ',ou=domains'):
|
if yldap.remove('virtualdomain=' + domain + ',ou=domains'):
|
||||||
try:
|
try:
|
||||||
os.remove('/var/lib/bind/'+ domain +'.zone')
|
os.remove('/var/lib/bind/'+ domain +'.zone')
|
||||||
|
|
|
@ -65,7 +65,7 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
|
||||||
return result_dict
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def user_create(username=None, firstname=None, lastname=None, mail=None, password=None):
|
def user_create(username, firstname, lastname, mail, password):
|
||||||
"""
|
"""
|
||||||
Add user to LDAP
|
Add user to LDAP
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ def user_create(username=None, firstname=None, lastname=None, mail=None, passwor
|
||||||
raise YunoHostError(169, _("An error occured during user creation"))
|
raise YunoHostError(169, _("An error occured during user creation"))
|
||||||
|
|
||||||
|
|
||||||
def user_delete(users=None, purge=None):
|
def user_delete(users, purge=None):
|
||||||
"""
|
"""
|
||||||
Remove user from LDAP
|
Remove user from LDAP
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue