diff --git a/action_map.yml b/action_map.yml index 88f0a5da..8ad93885 100644 --- a/action_map.yml +++ b/action_map.yml @@ -200,11 +200,6 @@ domain: help: "" 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])*)$' - ### domain_ssowatconf() - ssowatconf: - action_help: Regenerate SSOwat configuration file - api: PUT /ssowatconf - ############################# # App # @@ -372,6 +367,11 @@ app: -s: full: --sql help: Initial SQL file + + ### app_ssowatconf() + ssowatconf: + action_help: Regenerate SSOwat configuration file + api: PUT /ssowatconf ### app_addaccess() TODO: Write help addaccess: diff --git a/yunohost_app.py b/yunohost_app.py index ea267f91..fd4dbbde 100644 --- a/yunohost_app.py +++ b/yunohost_app.py @@ -33,8 +33,8 @@ import time import re import socket from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password, is_true, validate -from yunohost_domain import domain_list, domain_add, domain_ssowatconf -from yunohost_user import user_info +from yunohost_domain import domain_list, domain_add +from yunohost_user import user_info, user_list from yunohost_hook import hook_exec repo_path = '/var/cache/yunohost/repo' @@ -456,7 +456,7 @@ def app_addaccess(apps, users): app_setting(app, 'allowed_users', new_users.strip()) - domain_ssowatconf() + app_ssowatconf() def app_removeaccess(apps, users): @@ -492,7 +492,7 @@ def app_removeaccess(apps, users): app_setting(app, 'allowed_users', new_users.strip()) - domain_ssowatconf() + app_ssowatconf() def app_setting(app, key, value=None): @@ -609,6 +609,65 @@ def app_initdb(user, password=None, db=None, sql=None): win_msg(_("Database initiliazed")) +def app_ssowatconf(): + """ + Regenerate SSOwat conf from YunoHost settings + + Keyword argument: + + """ + + with open('/etc/yunohost/current_host', 'r') as f: + main_domain = f.readline().rstrip() + + domains = domain_list()['Domains'] + + apps = {} + for app, v in app_list(raw=True).items(): + app_settings = app_info(raw=True, app=app)['settings'] + if 'domain' in app_settings: + if 'path' not in app_settings: + app_settings['path'] = '/' + if 'mode' not in app_settings: + app_settings['mode'] = 'private' + if 'allowed_users' not in app_settings: + app_settings['allowed_users'] = '' + + apps[app] = { + 'domain': app_settings['domain'], + 'path': app_settings['path'], + 'mode': app_settings['mode'], + 'allowed_users': app_settings['allowed_users'] + } + + users = {} + for user in user_list()['Users']: + users[user['Username']] = app_map(user=user['Username']) + + conf_dict = { + 'portal_domain': main_domain, + 'portal_path': '/ynhsso/', + 'portal_port': '443', + 'portal_scheme': 'https', + 'additional_headers': { + 'Auth-User': 'uid', + 'Remote-User': 'uid', + 'Name': 'cn', + 'Email': 'mail' + }, + 'domains': domains, + 'skipped_urls': ['https://'+ main_domain +'/ynhadmin'], + 'unprotected_urls': [], + 'apps': apps, + 'users': users + } + + with open('/etc/ssowat/conf.json', 'wb') as f: + json.dump(conf_dict, f) + + win_msg(_('SSOwat configuration generated')) + + def _extract_app_from_file(path, remove=False): """ Unzip or untar application tarball in app_tmp_folder, or copy it from a directory diff --git a/yunohost_domain.py b/yunohost_domain.py index fb4a313f..5329b232 100644 --- a/yunohost_domain.py +++ b/yunohost_domain.py @@ -31,7 +31,6 @@ import shutil import json from urllib import urlopen from yunohost import YunoHostError, YunoHostLDAP, win_msg, colorize, validate, get_required_args -#from yunohost_app import app_list, app_info, app_map def domain_list(filter=None, limit=None, offset=None): @@ -206,7 +205,7 @@ def domain_add(domains, main=False): raise YunoHostError(169, _("An error occured during domain creation")) - domain_ssowatconf() + os.system('yunohost app ssowatconf') win_msg(_("Domain(s) successfully created")) @@ -253,67 +252,9 @@ def domain_remove(domains): else: raise YunoHostError(169, _("An error occured during domain deletion")) - domain_ssowatconf() + os.system('yunohost app ssowatconf') win_msg(_("Domain(s) successfully deleted")) return { 'Domains' : result } - -def domain_ssowatconf(): - """ - Regenerate SSOwat conf from YunoHost settings - - Keyword argument: - - """ - - with open('/etc/yunohost/current_host', 'r') as f: - main_domain = f.readline().rstrip() - - domains = domain_list()['Domains'] - - #apps = {} - #for app, v in app_list(raw=True): - # app_settings = app_info(raw=True, app=app)['settings'] - # if 'domain' in app_settings: - # if 'path' not in app_settings: - # app_settings['path'] = '/' - # if 'mode' not in app_settings: - # app_settings['mode'] = 'private' - # if 'allowed_users' not in app_settings: - # app_settings['allowed_users'] = '' - - # apps[app] = { - # 'domain': app_settings['domain'], - # 'path': app_settings['path'], - # 'mode': app_settings['mode'], - # 'allowed_users': app_settings['allowed_users'] - # } - - #users = {} - #for user, v in user_list()['Users']: - # users[user] = app_map(user=user) - - conf_dict = { - 'portal_domain': main_domain, - 'portal_path': '/ynhsso/', - 'portal_port': '443', - 'portal_scheme': 'https', - 'additional_headers': { - 'Auth-User': 'uid', - 'Remote-User': 'uid', - 'Name': 'cn', - 'Email': 'mail' - }, - 'domains': domains, - 'skipped_urls': ['https://'+ main_domain +'/ynhadmin'], - 'unprotected_urls': [], - # 'apps': apps, - # 'users': users - } - - with open('/etc/ssowat/conf.json', 'wb') as f: - json.dump(conf_dict, f) - - win_msg(_('SSOwat configuration generated')) diff --git a/yunohost_tools.py b/yunohost_tools.py index 9b57ddf8..4eeb3721 100644 --- a/yunohost_tools.py +++ b/yunohost_tools.py @@ -32,9 +32,10 @@ import subprocess import requests import json from yunohost import YunoHostError, YunoHostLDAP, validate, colorize, get_required_args, win_msg -from yunohost_domain import domain_add, domain_list, domain_ssowatconf +from yunohost_domain import domain_add, domain_list from yunohost_dyndns import dyndns_subscribe from yunohost_backup import backup_init +from yunohost_app import app_ssowatconf def tools_ldapinit(password=None): @@ -276,7 +277,7 @@ def tools_postinstall(domain, password, dyndns=False): tools_maindomain(old_domain='yunohost.org', new_domain=domain, dyndns=dyndns) # Generate SSOwat configuration file - domain_ssowatconf() + app_ssowatconf() # Change LDAP admin password tools_adminpw(old_password='yunohost', new_password=password)