From 9cdbdde6210f7bb76f9c76582b880d71bbff8e1c Mon Sep 17 00:00:00 2001 From: tituspijean Date: Fri, 11 Aug 2023 17:18:17 +0200 Subject: [PATCH] Implement .well-known location --- conf/server_name.conf | 5 +++++ scripts/backup | 5 +++++ scripts/install | 6 ++++++ scripts/remove | 3 +++ scripts/restore | 7 +++++-- scripts/upgrade | 6 ++++++ 6 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 conf/server_name.conf diff --git a/conf/server_name.conf b/conf/server_name.conf new file mode 100644 index 0000000..81c3548 --- /dev/null +++ b/conf/server_name.conf @@ -0,0 +1,5 @@ +location /.well-known/matrix/server { + return 200 '{"m.server": "__DOMAIN__:443"}'; + add_header Content-Type application/json; + add_header Access-Control-Allow-Origin '*'; +} diff --git a/scripts/backup b/scripts/backup index f8e82aa..92bfdc5 100755 --- a/scripts/backup +++ b/scripts/backup @@ -27,6 +27,11 @@ ynh_backup --src_path="$install_dir" ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +if yunohost --output-as plain domain list | grep -q "^$server_name$" +then + ynh_backup --src_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +fi + #================================================= # BACKUP SYSTEMD #================================================= diff --git a/scripts/install b/scripts/install index 3f58958..171fccb 100755 --- a/scripts/install +++ b/scripts/install @@ -30,6 +30,12 @@ ynh_script_progression --message="Adding system configurations related to $app.. # Create a dedicated NGINX config using the conf/nginx.conf template ynh_add_nginx_config +# Create .well-known redirection for access by federation +if yunohost --output-as plain domain list | grep -q "^$server_name$" +then + ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +fi + # Create a dedicated systemd config ynh_add_systemd_config diff --git a/scripts/remove b/scripts/remove index dda87b5..4a52fca 100755 --- a/scripts/remove +++ b/scripts/remove @@ -29,6 +29,9 @@ ynh_remove_systemd_config ynh_remove_nginx_config +# Remove the well-known location +ynh_secure_remove --file="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/restore b/scripts/restore index 6122364..6cda2ba 100755 --- a/scripts/restore +++ b/scripts/restore @@ -22,12 +22,15 @@ chown -R $app:root "$install_dir" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -# RESTORE THE PHP-FPM CONFIGURATION -#================================================= ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +if yunohost --output-as plain domain list | grep -q "^$server_name$" +then + ynh_restore_file --origin_path="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +fi + ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service --quiet diff --git a/scripts/upgrade b/scripts/upgrade index a372401..d093cf4 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -42,6 +42,12 @@ ynh_script_progression --message="Upgrading system configurations related to $ap ynh_add_nginx_config +# Create .well-known redirection for access by federation +if yunohost --output-as plain domain list | grep -q "^$server_name$" +then + ynh_add_config --template="server_name.conf" --destination="/etc/nginx/conf.d/${server_name}.d/${app}_server_name.conf" +fi + ynh_add_systemd_config yunohost service add $app --description="Chat server powered by Matrix" --log="/var/log/$app/$app.log"