From aec22ac9e4152da505d374f72ceed64ce4d8bd75 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Sat, 26 Feb 2022 22:44:20 +0100 Subject: [PATCH] Fix integration with Synapse --- conf/nginx.conf | 28 ---------------------------- conf/synapse.nginx.conf | 8 ++++++++ manifest.json | 12 +++++------- scripts/backup | 3 +++ scripts/install | 9 ++++++++- scripts/remove | 7 ++++++- scripts/restore | 2 ++ scripts/upgrade | 13 ++++++++++++- 8 files changed, 44 insertions(+), 38 deletions(-) create mode 100644 conf/synapse.nginx.conf diff --git a/conf/nginx.conf b/conf/nginx.conf index 79b2fd8..a990259 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -15,31 +15,3 @@ location / { # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } - -location /.well-known/acme-challenge { - proxy_pass http://127.0.0.1:8009; -} - -location /.well-known/matrix/server { - return 200 '{ "m.server": "__SYNAPSE_DOMAIN__:443" }'; -} - -location /.well-known/matrix/client { - return 200 '{ "m.homeserver": { "base_url": "https://__SYNAPSE_DOMAIN__" } }'; -} - -location /_matrix { - proxy_pass http://127.0.0.1:8008; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Host $host; - proxy_read_timeout 600; - client_max_body_size 100M; -} - -location /_synapse/admin { - proxy_pass http://127.0.0.1:8008; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Host $host; - proxy_read_timeout 600; - client_max_body_size 100M; -} diff --git a/conf/synapse.nginx.conf b/conf/synapse.nginx.conf new file mode 100644 index 0000000..d7b771b --- /dev/null +++ b/conf/synapse.nginx.conf @@ -0,0 +1,8 @@ +location /_synapse/admin { + proxy_pass http://localhost:__SYNAPSE_PORT__; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $host; + + client_max_body_size 100M; +} diff --git a/manifest.json b/manifest.json index 92c9e6f..ebc4779 100644 --- a/manifest.json +++ b/manifest.json @@ -31,14 +31,12 @@ "type": "domain" }, { - "name": "synapse_domain", - "type": "domain", + "name": "synapse_app", + "type": "app", "ask": { - "en": "The domain of your Synapse server", - "fr": "Le domain de votre serveur Synapse" - }, - "example": "synapse.example.com", - "default": "" + "en": "Select the Synapse app you wish to connect to.", + "fr": "Sélectionnez l'app Synapse à laquelle vous souhaitez vous connecter." + } }, { "name": "is_public", diff --git a/scripts/backup b/scripts/backup index d104a02..d50ae1f 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,6 +25,8 @@ app=$YNH_APP_INSTANCE_NAME final_path=$(ynh_app_setting_get --app=$app --key=final_path) domain=$(ynh_app_setting_get --app=$app --key=domain) +synapse_app=$(ynh_app_setting_get --app=$app --key=synapse_app) +synapse_domain=$(ynh_app_setting_get --app=$app --key=synapse_domain) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -42,6 +44,7 @@ ynh_backup --src_path="$final_path" #================================================= ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup --src_path="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf" #================================================= # BACKUP LOGROTATE diff --git a/scripts/install b/scripts/install index dec0259..8895085 100644 --- a/scripts/install +++ b/scripts/install @@ -23,7 +23,9 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" is_public=$YNH_APP_ARG_IS_PUBLIC -synapse_domain=$YNH_APP_ARG_SYNAPSE_DOMAIN +synapse_app=$YNH_APP_ARG_SYNAPSE_APP +synapse_domain=$(ynh_app_setting_get --app=$synapse_app --key=domain) +synapse_port=$(ynh_app_setting_get --app=$synapse_app --key=synapse_port) app=$YNH_APP_INSTANCE_NAME @@ -45,7 +47,9 @@ ynh_script_progression --message="Storing installation settings..." --weight=2 ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url +ynh_app_setting_set --app=$app --key=synapse_app --value=$synapse_app ynh_app_setting_set --app=$app --key=synapse_domain --value=$synapse_domain +ynh_app_setting_set --app=$app --key=synapse_port --value=$synapse_port #================================================= # STANDARD MODIFICATIONS @@ -98,6 +102,9 @@ ynh_script_progression --message="Configuring NGINX web server..." --weight=2 # Create a dedicated NGINX config ynh_add_nginx_config +# Create NGINX config to access /_synapse/admin endpoint +ynh_add_config --template="synapse.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf" + #================================================= # SPECIFIC SETUP #============================================== diff --git a/scripts/remove b/scripts/remove index 09d8112..42a027e 100644 --- a/scripts/remove +++ b/scripts/remove @@ -19,6 +19,8 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) port=$(ynh_app_setting_get --app=$app --key=port) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +synapse_app=$(ynh_app_setting_get --app=$app --key=synapse_app) +synapse_domain=$(ynh_app_setting_get --app=$synapse_app --key=synapse_domain) #================================================= # STANDARD REMOVE @@ -70,9 +72,12 @@ ynh_secure_remove --file="$final_path" #================================================= ynh_script_progression --message="Removing NGINX web server configuration..." --weight=5 -# Remove the dedicated nginx config +# Remove the dedicated NGINX config ynh_remove_nginx_config +# Remove NGINX config that enabled /_synapse/admin endpoint +ynh_secure_remove --file="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf" + #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index e3da35e..3e6478f 100644 --- a/scripts/restore +++ b/scripts/restore @@ -26,6 +26,7 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +synapse_domain=$(ynh_app_setting_get --app=$app --key=synapse_domain) #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -42,6 +43,7 @@ test ! -d $final_path || ynh_die --message="There is already a directory: $final ynh_script_progression --message="Restoring the NGINX configuration..." ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore_file --origin_path="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf" #================================================= # RECREATE THE DEDICATED USER diff --git a/scripts/upgrade b/scripts/upgrade index 3028825..7fb2947 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -20,7 +20,11 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) -synapse_domain=$(ynh_app_setting_get --app=$app --key=synapse_domain) +synapse_app=$(ynh_app_setting_get --app=$app --key=synapse_app) + +# Reload Synapse's settings, in case of they changed +synapse_domain=$(ynh_app_setting_get --app=$synapse_app --key=domain) +synapse_port=$(ynh_app_setting_get --app=$synapse_app --key=synapse_port) #================================================= # CHECK VERSION @@ -58,6 +62,10 @@ if ynh_legacy_permissions_exists; then ynh_app_setting_delete --app=$app --key=is_public fi +# Store Synapse's settings, in case of they changed +ynh_app_setting_set --app=$app --key=synapse_domain --value=$synapse_domain +ynh_app_setting_set --app=$app --key=synapse_port --value=$synapse_port + #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -98,6 +106,9 @@ ynh_script_progression --message="Upgrading NGINX web server configuration..." - # Create a dedicated nginx config ynh_add_nginx_config +# Create NGINX config to access /_synapse/admin endpoint +ynh_add_config --template="synapse.nginx.conf" --destination="/etc/nginx/conf.d/${synapse_domain}.d/synapse-admin.conf" + #================================================= # UPGRADE DEPENDENCIES #=================================================