mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Lemon configuration function
This commit is contained in:
parent
3d8e6fc09d
commit
8c83e0e59e
3 changed files with 31 additions and 15 deletions
26
yunohost.py
26
yunohost.py
|
@ -17,6 +17,8 @@ import string
|
||||||
if not __debug__:
|
if not __debug__:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
lemon_tmp_conf = '/tmp/tmplemonconf'
|
||||||
|
|
||||||
def random_password(length=8):
|
def random_password(length=8):
|
||||||
char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase
|
char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase
|
||||||
return ''.join(random.sample(char_set,length))
|
return ''.join(random.sample(char_set,length))
|
||||||
|
@ -186,6 +188,30 @@ def display_error(error):
|
||||||
print(json.dumps({ 'error' : error.message }))
|
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):
|
class YunoHostError(Exception):
|
||||||
"""
|
"""
|
||||||
Custom exception
|
Custom exception
|
||||||
|
|
|
@ -7,7 +7,7 @@ import shutil
|
||||||
import stat
|
import stat
|
||||||
import yaml
|
import yaml
|
||||||
import time
|
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
|
from yunohost_domain import domain_list, domain_add
|
||||||
|
|
||||||
repo_path = '/var/cache/yunohost/repo'
|
repo_path = '/var/cache/yunohost/repo'
|
||||||
|
@ -298,19 +298,9 @@ def app_install(app, domain, path='/', label=None, mode='private'):
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(22, _("Invalid privacy mode"))
|
raise YunoHostError(22, _("Invalid privacy mode"))
|
||||||
|
|
||||||
lemon_conf_lines = [
|
lemon_configuration({
|
||||||
"$tmp->{'locationRules'}->{'"+ domain +"'}->{'(?#"+ unique_app_id +"Z)^"+ path +"'} = '"+ lemon_mode +"';"
|
('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"))
|
|
||||||
|
|
||||||
|
|
||||||
##########
|
##########
|
||||||
# Apache #
|
# Apache #
|
||||||
|
|
|
@ -6,7 +6,7 @@ import datetime
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
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, lemon_configuration
|
||||||
|
|
||||||
a2_template_path = '/etc/yunohost/apache/templates'
|
a2_template_path = '/etc/yunohost/apache/templates'
|
||||||
a2_app_conf_path = '/etc/yunohost/apache/domains'
|
a2_app_conf_path = '/etc/yunohost/apache/domains'
|
||||||
|
|
Loading…
Reference in a new issue