From 1dab47a36f6e74c9cfe41cf8668e8556deecd366 Mon Sep 17 00:00:00 2001 From: anmol Date: Fri, 4 Jan 2019 20:45:48 +0530 Subject: [PATCH] Added admin to the sso --- conf/add_sso_conf.py | 11 +++++++++++ conf/remove_sso_conf.py | 8 ++++++++ scripts/install | 11 +++++++++++ scripts/remove | 3 +++ scripts/restore | 5 +++++ scripts/upgrade | 8 ++++++++ 6 files changed, 46 insertions(+) create mode 100644 conf/add_sso_conf.py create mode 100644 conf/remove_sso_conf.py diff --git a/conf/add_sso_conf.py b/conf/add_sso_conf.py new file mode 100644 index 0000000..a0ef335 --- /dev/null +++ b/conf/add_sso_conf.py @@ -0,0 +1,11 @@ +import json + +with open("/etc/ssowat/conf.json.persistent", "r", encoding='utf-8') as jsonFile: + data = json.load(jsonFile) + if "protected_urls" in data: + data["protected_urls"].append("__DOMAIN__/__PATH__/admin") + else: + data["protected_urls"] = ["__DOMAIN__/__PATH__/admin"] + +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 new file mode 100644 index 0000000..b67e36b --- /dev/null +++ b/conf/remove_sso_conf.py @@ -0,0 +1,8 @@ +import json + +with open("/etc/ssowat/conf.json.persistent", "r", encoding='utf-8') as jsonFile: + data = json.load(jsonFile) + data["protected_urls"].remove("__DOMAIN__/__PATH__/admin") + +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 ebab6e4..0b9467f 100644 --- a/scripts/install +++ b/scripts/install @@ -122,6 +122,17 @@ ynh_replace_string "yourlsuser" "$admin" "$final_path/user/config.php" ynh_replace_string "yourpassword" "$pass" "$final_path/user/config.php" ynh_replace_string "modify this text with something random" "$(ynh_string_random 24)$(ynh_string_random 24)" "$final_path/user/config.php" +# The script "add_sso_conf.py" will just add en entry for the path "/admin" in the sso conf.json.persistent file in the cathegory "protected_urls". +cp ../conf/add_sso_conf.py $final_path +cp ../conf/remove_sso_conf.py $final_path +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/add_sso_conf.py" +ynh_replace_string "__PATH__" "$path_url" "$final_path/user/add_sso_conf.py" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/remove_sso_conf.py" +ynh_replace_string "__PATH__" "$path_url" "$final_path/user/remove_sso_conf.py" + +python3 $final_path/add_sso_conf.py || ynh_die "Your file /etc/ssowat/conf.json.persistent don't respect the json synaxe. Please fix the synaxe to install this app. For more information see here : https://github.com/YunoHost-Apps/synapse_ynh/issues/32" + + # Set permissions sudo chown -R $app: $final_path diff --git a/scripts/remove b/scripts/remove index 3fb4845..d3b5bab 100644 --- a/scripts/remove +++ b/scripts/remove @@ -27,6 +27,9 @@ ynh_mysql_remove_db $db_name $db_name # REMOVE APP MAIN DIR #================================================= +# Remove the protected_urls +python3 $final_path/remove_sso_conf.py + # Remove the app directory securely ynh_secure_remove "$final_path" diff --git a/scripts/restore b/scripts/restore index fe577e6..1d74a9e 100644 --- a/scripts/restore +++ b/scripts/restore @@ -56,6 +56,11 @@ ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore_file "$final_path" +# 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 $final_path/add_sso_conf.py || ynh_die "Your file /etc/ssowat/conf.json.persistent don't respect the json synaxe. Please fix the synaxe to install this app. For more information see here : https://github.com/YunoHost-Apps/synapse_ynh/issues/32" + + #================================================= # RESTORE THE MYSQL DATABASE #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 96841a8..e8f9a41 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -80,6 +80,14 @@ sudo cp -a "$tmpdir/index.php" "$final_path" sudo cp -a "$tmpdir/.htaccess" "$final_path" sudo cp -a "$tmpdir/user/config.php" "$final_path/user" +# The script "add_sso_conf.py" will just add en entry for the path "/admin" in the sso conf.json.persistent file in the cathegory "protected_urls". +cp ../conf/add_sso_conf.py $final_path +cp ../conf/remove_sso_conf.py $final_path +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/add_sso_conf.py" +ynh_replace_string "__PATH__" "$path_url" "$final_path/user/add_sso_conf.py" +ynh_replace_string "__DOMAIN__" "$domain" "$final_path/user/remove_sso_conf.py" +ynh_replace_string "__PATH__" "$path_url" "$final_path/user/remove_sso_conf.py" + #remove tmp dir sudo rm -Rf "$tmpdir"