From fdd5b7f39667569c7ddaa571f56947c65338a9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Tue, 17 Mar 2020 22:02:59 +0100 Subject: [PATCH] Fix SSO script --- conf/add_sso_conf.py | 24 +++++++++++++++--------- conf/remove_sso_conf.py | 9 ++++----- scripts/change_url | 7 +++++++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/conf/add_sso_conf.py b/conf/add_sso_conf.py index e7fc15d..62a3d25 100644 --- a/conf/add_sso_conf.py +++ b/conf/add_sso_conf.py @@ -1,4 +1,5 @@ import json +import sys server_name = sys.argv[1] domain = sys.argv[2] @@ -6,17 +7,22 @@ domain = sys.argv[2] with open("/etc/ssowat/conf.json.persistent", "r", encoding='utf-8') as jsonFile: data = json.load(jsonFile) - # Remove entry without the domain specified - data["skipped_urls"].remove("/_matrix") + if "skipped_urls" not in data: + data["skipped_urls"] = [] + if "protected_urls" not in data: + data["protected_urls"] = [] - if "skipped_urls" in data and "/_matrix" not in data: - data["skipped_urls"] += [domain + "/_matrix", server_name + "/.well-known/matrix/"] - else: - data["skipped_urls"] = [domain + "/_matrix", server_name + "/.well-known/matrix/"] - if "protected_urls" in data and domain + "/_matrix/cas_server.php/login" not in data: + # Remove entry without the domain specified + if "/_matrix" in data["skipped_urls"]: + data["skipped_urls"].remove("/_matrix") + + if domain + "/_matrix" not in data["skipped_urls"]: + data["skipped_urls"].append(domain + "/_matrix") + if server_name + "/.well-known/matrix/" not in data["skipped_urls"]: + data["skipped_urls"].append(server_name + "/.well-known/matrix/") + + if domain + "/_matrix/cas_server.php/login" not in data["protected_urls"]: data["protected_urls"].append(domain + "/_matrix/cas_server.php/login") - else: - data["protected_urls"] = [domain + "/_matrix/cas_server.php/login"] with open("/etc/ssowat/conf.json.persistent", "w", encoding='utf-8') as jsonFile: jsonFile.write(json.dumps(data, indent=4, sort_keys=True)) diff --git a/conf/remove_sso_conf.py b/conf/remove_sso_conf.py index a257b16..cc24cbf 100644 --- a/conf/remove_sso_conf.py +++ b/conf/remove_sso_conf.py @@ -1,14 +1,13 @@ import json -server_name = sys.argv[1] -domain = sys.argv[2] - with open("/etc/ssowat/conf.json.persistent", "r", encoding='utf-8') as jsonFile: data = json.load(jsonFile) - for entry in data["skipped_urls"]: + + for entry in data["skipped_urls"].copy(): if "/_matrix" in entry or "/.well-known/matrix/" in entry: data["skipped_urls"].remove(entry) - for entry in data["protected_urls"]: + + for entry in data["protected_urls"].copy(): if "/_matrix" in entry: data["protected_urls"].remove(entry) diff --git a/scripts/change_url b/scripts/change_url index d8065af..03260c1 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -137,6 +137,13 @@ fi ynh_store_file_checksum --file="$homeserver_config_path" ynh_store_file_checksum --file="/etc/matrix-$app/log.yaml" +#================================================= +# SETUP SSOWAT +#================================================= + +python3 ../conf/remove_sso_conf.py +python3 ../conf/add_sso_conf.py $domain $server_name || ynh_die --message="Your file /etc/ssowat/conf.json.persistent doesn't respect the json syntax. Please fix the syntax to install this app. For more information see here: https://github.com/YunoHost-Apps/synapse_ynh/issues/32" + #================================================= # RELOAD SERVICES #=================================================