mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] add check/remove/make app the default domain redirect
This commit is contained in:
parent
6a4da64be9
commit
1646d6737d
1 changed files with 69 additions and 23 deletions
|
@ -796,8 +796,10 @@ def app_makedefault(auth, app, domain=None):
|
||||||
from yunohost.domain import domain_list
|
from yunohost.domain import domain_list
|
||||||
|
|
||||||
app_settings = _get_app_settings(app)
|
app_settings = _get_app_settings(app)
|
||||||
app_domain = app_settings['domain']
|
if app_settings.get('domain') is not None:
|
||||||
app_path = app_settings['path']
|
app_domain = app_settings.get('domain')
|
||||||
|
else:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('app_no_domain'))
|
||||||
|
|
||||||
if domain is None:
|
if domain is None:
|
||||||
domain = app_domain
|
domain = app_domain
|
||||||
|
@ -808,31 +810,72 @@ def app_makedefault(auth, app, domain=None):
|
||||||
raise MoulinetteError(errno.EEXIST,
|
raise MoulinetteError(errno.EEXIST,
|
||||||
m18n.n('app_location_already_used'))
|
m18n.n('app_location_already_used'))
|
||||||
|
|
||||||
try:
|
app_setting(app, 'is_domain_default', value='Yes', delete=False)
|
||||||
with open('/etc/ssowat/conf.json.persistent') as json_conf:
|
|
||||||
ssowat_conf = json.loads(str(json_conf.read()))
|
|
||||||
except ValueError as e:
|
|
||||||
raise MoulinetteError(errno.EINVAL,
|
|
||||||
m18n.n('ssowat_persistent_conf_read_error', error=e.strerror))
|
|
||||||
except IOError:
|
|
||||||
ssowat_conf = {}
|
|
||||||
|
|
||||||
if 'redirected_urls' not in ssowat_conf:
|
app_ssowatconf(auth)
|
||||||
ssowat_conf['redirected_urls'] = {}
|
|
||||||
|
|
||||||
ssowat_conf['redirected_urls'][domain +'/'] = app_domain + app_path
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open('/etc/ssowat/conf.json.persistent', 'w+') as f:
|
|
||||||
json.dump(ssowat_conf, f, sort_keys=True, indent=4)
|
|
||||||
except IOError as e:
|
|
||||||
raise MoulinetteError(errno.EPERM,
|
|
||||||
m18n.n('ssowat_persistent_conf_write_error', error=e.strerror))
|
|
||||||
|
|
||||||
|
|
||||||
os.system('chmod 644 /etc/ssowat/conf.json.persistent')
|
def app_removedefault(auth, app, domain=None):
|
||||||
|
"""
|
||||||
|
Remove the default redirection to an app on a domain
|
||||||
|
|
||||||
logger.success(m18n.n('ssowat_conf_updated'))
|
Keyword argument:
|
||||||
|
app
|
||||||
|
domain
|
||||||
|
|
||||||
|
"""
|
||||||
|
from yunohost.domain import domain_list
|
||||||
|
|
||||||
|
app_settings = _get_app_settings(app)
|
||||||
|
if app_settings.get('domain') is not None:
|
||||||
|
app_domain = app_settings.get('domain')
|
||||||
|
else:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('app_no_domain'))
|
||||||
|
|
||||||
|
if domain is None:
|
||||||
|
domain = app_domain
|
||||||
|
elif domain not in domain_list(auth)['domains']:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
||||||
|
|
||||||
|
if '/' in app_map(raw=True)[domain]:
|
||||||
|
raise MoulinetteError(errno.EEXIST,
|
||||||
|
m18n.n('app_location_already_used'))
|
||||||
|
|
||||||
|
app_setting(app, 'is_domain_default', value=None, delete=True)
|
||||||
|
|
||||||
|
app_ssowatconf(auth)
|
||||||
|
|
||||||
|
|
||||||
|
def app_checkdefault(auth, app, domain=None):
|
||||||
|
"""
|
||||||
|
Check if an app is the default redirecton of a domain
|
||||||
|
|
||||||
|
Keyword argument:
|
||||||
|
app
|
||||||
|
domain
|
||||||
|
|
||||||
|
"""
|
||||||
|
from yunohost.domain import domain_list
|
||||||
|
|
||||||
|
app_settings = _get_app_settings(app)
|
||||||
|
if app_settings.get('domain') is not None:
|
||||||
|
app_domain = app_settings.get('domain')
|
||||||
|
else:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('app_no_domain'))
|
||||||
|
|
||||||
|
if domain is None:
|
||||||
|
domain = app_domain
|
||||||
|
elif domain not in domain_list(auth)['domains']:
|
||||||
|
raise MoulinetteError(errno.EINVAL, m18n.n('domain_unknown'))
|
||||||
|
|
||||||
|
if '/' in app_map(raw=True)[domain]:
|
||||||
|
raise MoulinetteError(errno.EEXIST,
|
||||||
|
m18n.n('app_location_already_used'))
|
||||||
|
|
||||||
|
if 'is_domain_default' in app_settings:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def app_setting(app, key, value=None, delete=False):
|
def app_setting(app, key, value=None, delete=False):
|
||||||
|
@ -1030,6 +1073,9 @@ def app_ssowatconf(auth):
|
||||||
redirected_urls.update(app_settings['redirected_urls'])
|
redirected_urls.update(app_settings['redirected_urls'])
|
||||||
if 'redirected_regex' in app_settings:
|
if 'redirected_regex' in app_settings:
|
||||||
redirected_regex.update(app_settings['redirected_regex'])
|
redirected_regex.update(app_settings['redirected_regex'])
|
||||||
|
if 'is_domain_default' in app_settings:
|
||||||
|
redirected_urls.update({ app_settings['domain']: app_settings['domain'] + app_settings['path']})
|
||||||
|
|
||||||
|
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
skipped_urls.extend([domain + '/yunohost/admin', domain + '/yunohost/api'])
|
skipped_urls.extend([domain + '/yunohost/admin', domain + '/yunohost/api'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue