mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
move web config functions to yunohost_domain.py
This commit is contained in:
parent
e0036030d4
commit
bf2bfe626e
4 changed files with 81 additions and 78 deletions
|
@ -172,8 +172,11 @@ domain:
|
||||||
domains:
|
domains:
|
||||||
help: Domain name to add
|
help: Domain name to add
|
||||||
nargs: '*'
|
nargs: '*'
|
||||||
ask: "New domain"
|
|
||||||
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
||||||
|
web:
|
||||||
|
help: Auto-configure Apache and LemonLDAP for the domain
|
||||||
|
action: store_true
|
||||||
|
default: False
|
||||||
|
|
||||||
### domain_remove()
|
### domain_remove()
|
||||||
remove:
|
remove:
|
||||||
|
@ -484,11 +487,6 @@ tools:
|
||||||
### tools_ldapinit()
|
### tools_ldapinit()
|
||||||
ldapinit:
|
ldapinit:
|
||||||
action_help: YunoHost LDAP initialization
|
action_help: YunoHost LDAP initialization
|
||||||
arguments:
|
|
||||||
-d:
|
|
||||||
full: --domain
|
|
||||||
help: YunoHost main domain
|
|
||||||
pattern: '^([a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)(\.[a-zA-Z0-9]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)*(\.[a-zA-Z]{1}([a-zA-Z0-9\-]*[a-zA-Z0-9])*)$'
|
|
||||||
|
|
||||||
### tools_adminpw()
|
### tools_adminpw()
|
||||||
adminpw:
|
adminpw:
|
||||||
|
|
|
@ -15,9 +15,6 @@ apps_path = '/usr/share/yunohost/apps'
|
||||||
apps_setting_path= '/etc/yunohost/apps/'
|
apps_setting_path= '/etc/yunohost/apps/'
|
||||||
install_tmp = '/tmp/yunohost/install'
|
install_tmp = '/tmp/yunohost/install'
|
||||||
app_tmp_folder = install_tmp + '/from_file'
|
app_tmp_folder = install_tmp + '/from_file'
|
||||||
a2_template_path = '/etc/yunohost/apache/templates'
|
|
||||||
a2_app_conf_path = '/etc/yunohost/apache/domains'
|
|
||||||
lemon_tmp_conf = '/tmp/tmplemonconf'
|
|
||||||
|
|
||||||
def app_listlists():
|
def app_listlists():
|
||||||
"""
|
"""
|
||||||
|
@ -205,10 +202,8 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
|
||||||
try:
|
try:
|
||||||
domain_list(filter="virtualdomain="+ domain)
|
domain_list(filter="virtualdomain="+ domain)
|
||||||
except YunoHostError:
|
except YunoHostError:
|
||||||
domain_add([domain])
|
domain_add([domain], web=True)
|
||||||
|
|
||||||
_apache_config(domain)
|
|
||||||
_lemon_config(domain)
|
|
||||||
|
|
||||||
|
|
||||||
# Copy files to the right place
|
# Copy files to the right place
|
||||||
|
@ -411,65 +406,6 @@ def _exec_app_script(step, path, var_dict, app_type):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def _apache_config(domain):
|
|
||||||
"""
|
|
||||||
Fill Apache configuration templates
|
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
domain -- Domain to configure Apache around
|
|
||||||
|
|
||||||
"""
|
|
||||||
# TMP: remove old conf
|
|
||||||
if os.path.exists(a2_app_conf_path +'/'+ domain +'.conf'): os.remove(a2_app_conf_path +'/'+ domain +'.conf')
|
|
||||||
if os.path.exists(a2_app_conf_path +'/'+ domain +'.d/'): shutil.rmtree(a2_app_conf_path +'/'+ domain +'.d/')
|
|
||||||
|
|
||||||
try: os.listdir(a2_app_conf_path +'/'+ domain +'.d/')
|
|
||||||
except OSError: os.makedirs(a2_app_conf_path +'/'+ domain +'.d/')
|
|
||||||
|
|
||||||
with open(a2_app_conf_path +'/'+ domain +'.conf', 'a') as a2_conf:
|
|
||||||
for line in open(a2_template_path +'/template.conf.tmp'):
|
|
||||||
line = line.replace('[domain]',domain)
|
|
||||||
a2_conf.write(line)
|
|
||||||
|
|
||||||
if os.system('service apache2 reload') == 0:
|
|
||||||
win_msg(_("Apache configured"))
|
|
||||||
else:
|
|
||||||
raise YunoHostError(1, _("An error occured during Apache configuration"))
|
|
||||||
|
|
||||||
def _lemon_config(domain):
|
|
||||||
"""
|
|
||||||
Configure LemonLDAP
|
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
domain -- Domain to configure LemonLDAP around
|
|
||||||
|
|
||||||
"""
|
|
||||||
if os.path.exists(lemon_tmp_conf): os.remove(lemon_tmp_conf)
|
|
||||||
|
|
||||||
lemon_conf_lines = [
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Auth-User'} = '$uid';",
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Remote-User'} = '$uid';",
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Desc'} = '$description';",
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Email'} = '$uid';",
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Name'} = '$cn';",
|
|
||||||
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Authorization'} = '\"Basic \".encode_base64(\"$uid:$_password\")';",
|
|
||||||
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostMaintenance'} = 0;",
|
|
||||||
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostPort'} = -1;",
|
|
||||||
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostHttps'} = -1;",
|
|
||||||
"$tmp->{'locationRules'}->{'"+ domain +"'}->{'default'} = 'accept';",
|
|
||||||
"$tmp->{'locationRules'}->{'"+ domain +"'}->{'(?#logout)^/logout'} = 'logout_app_sso https://"+ domain +"/';",
|
|
||||||
]
|
|
||||||
|
|
||||||
with open(lemon_tmp_conf,'a') 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"))
|
|
||||||
|
|
||||||
|
|
||||||
def _installed_instance_number(app):
|
def _installed_instance_number(app):
|
||||||
"""
|
"""
|
||||||
Check if application is installed and return instance number
|
Check if application is installed and return instance number
|
||||||
|
|
|
@ -7,6 +7,10 @@ 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
|
||||||
|
|
||||||
|
a2_template_path = '/etc/yunohost/apache/templates'
|
||||||
|
a2_app_conf_path = '/etc/yunohost/apache/domains'
|
||||||
|
lemon_tmp_conf = '/tmp/tmplemonconf'
|
||||||
|
|
||||||
def domain_list(filter=None, limit=None, offset=None):
|
def domain_list(filter=None, limit=None, offset=None):
|
||||||
"""
|
"""
|
||||||
List YunoHost domains
|
List YunoHost domains
|
||||||
|
@ -41,12 +45,13 @@ def domain_list(filter=None, limit=None, offset=None):
|
||||||
return { 'Domains': result_list }
|
return { 'Domains': result_list }
|
||||||
|
|
||||||
|
|
||||||
def domain_add(domains):
|
def domain_add(domains, web=False):
|
||||||
"""
|
"""
|
||||||
Add one or more domains
|
Add one or more domains
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
domains -- List of domains to add
|
domains -- List of domains to add
|
||||||
|
web -- Configure Apache and LemonLDAP for the domain too
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict
|
Dict
|
||||||
|
@ -105,6 +110,10 @@ def domain_add(domains):
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(169, _("An error occured during domain creation"))
|
raise YunoHostError(169, _("An error occured during domain creation"))
|
||||||
|
|
||||||
|
if web:
|
||||||
|
_apache_config(domain)
|
||||||
|
_lemon_config(domain)
|
||||||
|
|
||||||
win_msg(_("Domain(s) successfully created"))
|
win_msg(_("Domain(s) successfully created"))
|
||||||
|
|
||||||
return { 'Domains' : result }
|
return { 'Domains' : result }
|
||||||
|
@ -153,3 +162,65 @@ def domain_remove(domains):
|
||||||
|
|
||||||
return { 'Domains' : result }
|
return { 'Domains' : result }
|
||||||
|
|
||||||
|
|
||||||
|
def _apache_config(domain):
|
||||||
|
"""
|
||||||
|
Fill Apache configuration templates
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
domain -- Domain to configure Apache around
|
||||||
|
|
||||||
|
"""
|
||||||
|
# TMP: remove old conf
|
||||||
|
if os.path.exists(a2_app_conf_path +'/'+ domain +'.conf'): os.remove(a2_app_conf_path +'/'+ domain +'.conf')
|
||||||
|
if os.path.exists(a2_app_conf_path +'/'+ domain +'.d/'): shutil.rmtree(a2_app_conf_path +'/'+ domain +'.d/')
|
||||||
|
|
||||||
|
try: os.listdir(a2_app_conf_path +'/'+ domain +'.d/')
|
||||||
|
except OSError: os.makedirs(a2_app_conf_path +'/'+ domain +'.d/')
|
||||||
|
|
||||||
|
with open(a2_app_conf_path +'/'+ domain +'.conf', 'a') as a2_conf:
|
||||||
|
for line in open(a2_template_path +'/template.conf.tmp'):
|
||||||
|
line = line.replace('[domain]',domain)
|
||||||
|
a2_conf.write(line)
|
||||||
|
|
||||||
|
if os.system('service apache2 reload') == 0:
|
||||||
|
win_msg(_("Apache configured"))
|
||||||
|
else:
|
||||||
|
raise YunoHostError(1, _("An error occured during Apache configuration"))
|
||||||
|
|
||||||
|
|
||||||
|
def _lemon_config(domain):
|
||||||
|
"""
|
||||||
|
Configure LemonLDAP
|
||||||
|
|
||||||
|
Keyword arguments:
|
||||||
|
domain -- Domain to configure LemonLDAP around
|
||||||
|
|
||||||
|
"""
|
||||||
|
if os.path.exists(lemon_tmp_conf): os.remove(lemon_tmp_conf)
|
||||||
|
|
||||||
|
lemon_conf_lines = [
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Auth-User'} = '$uid';",
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Remote-User'} = '$uid';",
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Desc'} = '$description';",
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Email'} = '$uid';",
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Name'} = '$cn';",
|
||||||
|
"$tmp->{'exportedHeaders'}->{'"+ domain +"'}->{'Authorization'} = '\"Basic \".encode_base64(\"$uid:$_password\")';",
|
||||||
|
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostMaintenance'} = 0;",
|
||||||
|
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostPort'} = -1;",
|
||||||
|
"$tmp->{'vhostOptions'}->{'"+ domain +"'}->{'vhostHttps'} = -1;",
|
||||||
|
"$tmp->{'locationRules'}->{'"+ domain +"'}->{'default'} = 'accept';",
|
||||||
|
"$tmp->{'locationRules'}->{'"+ domain +"'}->{'(?#logout)^/logout'} = 'logout_app_sso https://"+ domain +"/';",
|
||||||
|
]
|
||||||
|
|
||||||
|
with open(lemon_tmp_conf,'a') 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"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,10 @@ import getpass
|
||||||
from yunohost import YunoHostError, YunoHostLDAP, validate, colorize, get_required_args, win_msg
|
from yunohost import YunoHostError, YunoHostLDAP, validate, colorize, get_required_args, win_msg
|
||||||
from yunohost_domain import domain_add
|
from yunohost_domain import domain_add
|
||||||
|
|
||||||
def tools_ldapinit(domain):
|
def tools_ldapinit():
|
||||||
"""
|
"""
|
||||||
Initialize YunoHost LDAP scheme
|
Initialize YunoHost LDAP scheme
|
||||||
|
|
||||||
Keyword arguments:
|
|
||||||
domain -- Main domain name for initialization
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
dict
|
dict
|
||||||
|
|
||||||
|
@ -30,7 +27,6 @@ def tools_ldapinit(domain):
|
||||||
for rdn, attr_dict in ldap_map['childs'].items():
|
for rdn, attr_dict in ldap_map['childs'].items():
|
||||||
yldap.add(rdn, attr_dict)
|
yldap.add(rdn, attr_dict)
|
||||||
|
|
||||||
domain_add([domain])
|
|
||||||
|
|
||||||
admin_dict = {
|
admin_dict = {
|
||||||
'cn': 'admin',
|
'cn': 'admin',
|
||||||
|
@ -113,6 +109,8 @@ def tools_maindomain(old_domain, new_domain):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
sources.write(re.sub(r''+ old_domain +'', new_domain, line))
|
sources.write(re.sub(r''+ old_domain +'', new_domain, line))
|
||||||
|
|
||||||
|
domain_add([domain], web=True)
|
||||||
|
|
||||||
lemon_tmp_conf = '/tmp/tmplemonconf'
|
lemon_tmp_conf = '/tmp/tmplemonconf'
|
||||||
if os.path.exists(lemon_tmp_conf): os.remove(lemon_tmp_conf)
|
if os.path.exists(lemon_tmp_conf): os.remove(lemon_tmp_conf)
|
||||||
|
|
||||||
|
@ -181,7 +179,7 @@ def tools_postinstall(domain, password):
|
||||||
tools_maindomain(old_domain='yunohost.org', new_domain=domain)
|
tools_maindomain(old_domain='yunohost.org', new_domain=domain)
|
||||||
|
|
||||||
# Initialize YunoHost LDAP base
|
# Initialize YunoHost LDAP base
|
||||||
tools_ldapinit(domain=domain)
|
tools_ldapinit()
|
||||||
|
|
||||||
# Change LDAP admin password
|
# Change LDAP admin password
|
||||||
tools_adminpw(old_password='yunohost', new_password=password)
|
tools_adminpw(old_password='yunohost', new_password=password)
|
||||||
|
|
Loading…
Add table
Reference in a new issue