From 70b322f6e1b3db3c05ed9f63e91f303b7f625f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Sat, 14 Mar 2020 14:35:20 +0100 Subject: [PATCH] Add support for .well_known access --- conf/add_sso_conf.py | 17 ++++++++++++----- conf/remove_sso_conf.py | 11 +++++++++-- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/conf/add_sso_conf.py b/conf/add_sso_conf.py index 33d0622..e7fc15d 100644 --- a/conf/add_sso_conf.py +++ b/conf/add_sso_conf.py @@ -1,15 +1,22 @@ 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) + + # Remove entry without the domain specified + data["skipped_urls"].remove("/_matrix") + if "skipped_urls" in data and "/_matrix" not in data: - data["skipped_urls"].append("/_matrix") + data["skipped_urls"] += [domain + "/_matrix", server_name + "/.well-known/matrix/"] else: - data["skipped_urls"] = ["/_matrix"] - if "protected_urls" in data and "/_matrix/cas_server.php/login" not in data: - data["protected_urls"].append("/_matrix/cas_server.php/login") + 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: + data["protected_urls"].append(domain + "/_matrix/cas_server.php/login") else: - data["protected_urls"] = ["/_matrix/cas_server.php/login"] + 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 748edf4..a257b16 100644 --- a/conf/remove_sso_conf.py +++ b/conf/remove_sso_conf.py @@ -1,9 +1,16 @@ 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) - data["skipped_urls"].remove("/_matrix") - data["protected_urls"].remove("/_matrix/cas_server.php/login") + for entry in data["skipped_urls"]: + if "/_matrix" in entry or "/.well-known/matrix/" in entry: + data["skipped_urls"].remove(entry) + for entry in data["protected_urls"]: + if "/_matrix" in entry: + data["protected_urls"].remove(entry) 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/scripts/install b/scripts/install index a98e7ed..cae73e0 100644 --- a/scripts/install +++ b/scripts/install @@ -390,7 +390,7 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=1 # Open access to server without a button the home # The script "add_sso_conf.py" will just add en entry for the path "/_matrix" in the sso conf.json.persistent file in the cathegory "skipped_urls". -python3 ../conf/add_sso_conf.py || 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" +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" ynh_permission_url --permission main --url $domain/_matrix/cas_server.php/login #================================================= diff --git a/scripts/restore b/scripts/restore index ed6dd26..d3d3cfb 100644 --- a/scripts/restore +++ b/scripts/restore @@ -215,7 +215,7 @@ ynh_script_progression --message="Configuring SSOwat..." # Open access to server without a button the home # The script "add_sso_conf.py" will just add en entry for the path "/_matrix" in the sso conf.json.persistent file in the cathegory "skipped_urls". -python3 ../settings/conf/add_sso_conf.py || 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" +python3 ../settings/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" #================================================= # SETUP LOGROTATE diff --git a/scripts/upgrade b/scripts/upgrade index 7361f60..eb1c418 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -438,7 +438,7 @@ ynh_script_progression --message="Configuring SSOwat..." --weight=1 # Open access to server without a button the home # The script "add_sso_conf.py" will just add en entry for the path "/_matrix" in the sso conf.json.persistent file in the cathegory "skipped_urls". -python3 ../conf/add_sso_conf.py || 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" +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" ynh_permission_url --permission main --url $domain/_matrix/cas_server.php/login #=================================================