diff --git a/yunohost.py b/yunohost.py index c42d0ec4..7bf1ece5 100644 --- a/yunohost.py +++ b/yunohost.py @@ -17,6 +17,8 @@ import string if not __debug__: import traceback +lemon_tmp_conf = '/tmp/tmplemonconf' + def random_password(length=8): char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase return ''.join(random.sample(char_set,length)) @@ -186,6 +188,30 @@ def display_error(error): print(json.dumps({ 'error' : error.message })) +def lemon_configuration(conf_dict): + conf_lines = [] + for key, value in conf_dict.items(): + if value is None: line = "delete $tmp" + else: line = "$tmp" + + if not isinstance(key, tuple): key = (key,) + for level in key: + line = line +"->{'"+ level +"'}" + + if value is None: conf_lines.append(line +';') + else: conf_lines.append(line +' = \''+ value +'\';') + + + with open(lemon_tmp_conf,'w') as lemon_conf: + for conf_line in conf_lines: + lemon_conf.write(conf_line + '\n') + + if os.system('/usr/share/lemonldap-ng/bin/lmYnhMoulinette') == 0: + win_msg(_("LemonLDAP configured")) + else: + raise YunoHostError(1, _("An error occured during LemonLDAP configuration")) + + class YunoHostError(Exception): """ Custom exception diff --git a/yunohost_app.py b/yunohost_app.py index 3cfefca7..39995076 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -7,7 +7,7 @@ import shutil import stat import yaml import time -from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, lvl, is_true +from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, lvl, is_true, lemon_configuration from yunohost_domain import domain_list, domain_add repo_path = '/var/cache/yunohost/repo' @@ -298,19 +298,9 @@ def app_install(app, domain, path='/', label=None, mode='private'): else: raise YunoHostError(22, _("Invalid privacy mode")) - lemon_conf_lines = [ - "$tmp->{'locationRules'}->{'"+ domain +"'}->{'(?#"+ unique_app_id +"Z)^"+ path +"'} = '"+ lemon_mode +"';" - ] - - with open(lemon_tmp_conf,'w') as lemon_conf: - for line in lemon_conf_lines: - lemon_conf.write(line + '\n') - - if os.system('/usr/share/lemonldap-ng/bin/lmYnhMoulinette') == 0: - win_msg(_("LemonLDAP configured")) - else: - raise YunoHostError(1, _("An error occured during LemonLDAP configuration")) - + lemon_configuration({ + ('locationRules', domain, '(?#'+ unique_app_id +'Z)^'+ path ): lemon_mode + }) ########## # Apache # diff --git a/yunohost_domain.py b/yunohost_domain.py index f8d182d8..8fae0f05 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -6,7 +6,7 @@ import datetime import re import shutil 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, lemon_configuration a2_template_path = '/etc/yunohost/apache/templates' a2_app_conf_path = '/etc/yunohost/apache/domains'