From 89195f00ebfd92717c221775e48b879833da31e6 Mon Sep 17 00:00:00 2001 From: tituspijean Date: Thu, 25 Aug 2022 23:09:18 +0200 Subject: [PATCH] Implement user registration in config panel and fix service status detection --- conf/dendrite.yaml | 2 +- conf/systemd.service | 2 +- config_panel.toml | 12 ++++++++++ doc/DISCLAIMER.md | 6 ++++- manifest.json | 8 +++++-- scripts/change_url | 2 +- scripts/config | 55 ++++++++++++++++++++++++++++++++++++++++++++ scripts/install | 24 +++++++++++-------- scripts/restore | 2 +- scripts/upgrade | 26 +++++++++++---------- 10 files changed, 110 insertions(+), 29 deletions(-) create mode 100644 config_panel.toml create mode 100644 scripts/config diff --git a/conf/dendrite.yaml b/conf/dendrite.yaml index 06de6b0..df29574 100644 --- a/conf/dendrite.yaml +++ b/conf/dendrite.yaml @@ -152,7 +152,7 @@ client_api: # Prevents new users from being able to register on this homeserver, except when # using the registration shared secret below. - registration_disabled: __REGISTRATION__ + registration_disabled: __REGISTRATION_DISABLED__ # Prevents new guest accounts from being created. Guest registration is also # disabled implicitly by setting 'registration_disabled' above. diff --git a/conf/systemd.service b/conf/systemd.service index 5ad0e2d..e961638 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -7,7 +7,7 @@ Type=simple User=__APP__ Group=__APP__ WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/bin/dendrite-monolith-server --tls-cert=/etc/yunohost/certs/__DOMAIN__/crt.pem --tls-key=/etc/yunohost/certs/__DOMAIN__/key.pem --config=dendrite.yaml --http-bind-address=:__PORT__ --https-bind-address=:__TLS_PORT__ +ExecStart=__FINALPATH__/bin/dendrite-monolith-server --tls-cert=/etc/yunohost/certs/__DOMAIN__/crt.pem --tls-key=/etc/yunohost/certs/__DOMAIN__/key.pem --config=dendrite.yaml --http-bind-address=:__PORT__ --https-bind-address=:__TLS_PORT__ __REALLY_ENABLE_OPEN_REGISTRATION__ StandardOutput=append:/var/log/__APP__/__APP__.log StandardError=inherit diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..5f28876 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,12 @@ +version = "1.0" + +[main] +name = "Dendrite configuration" + + [main.registration] + name = "User registration" + + [main.registration.registration] + ask = "Should registration be enabled?" + type = "boolean" + default = false diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 765a28c..0a6bfe8 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -1,5 +1,9 @@ :warning: The upstream app is still in beta. Tread carefully. +## Features + +* Registration can be opened in the app config panel. + ## Limitations -* Upstream app still in beta. +* Dendrite does not implement secondary user registration schemes yet, so YunoHost users cannot be integrated at the moment. diff --git a/manifest.json b/manifest.json index ed2d06b..d990735 100644 --- a/manifest.json +++ b/manifest.json @@ -53,9 +53,13 @@ } }, { - "name": "is_public", + "name": "registration", "type": "boolean", - "default": false + "default": false, + "help": { + "en": "Should the server allow any visitor to register as a user?", + "fr": "Le serveur doit-il permettre à quiconque de s'enregistrer comme utilisateur?" + } } ] } diff --git a/scripts/change_url b/scripts/change_url index 21718ca..4932b26 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -127,7 +127,7 @@ ynh_add_systemd_config ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/Monolith.log" #================================================= # RELOAD NGINX diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..2ea3ea5 --- /dev/null +++ b/scripts/config @@ -0,0 +1,55 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS +#================================================= + +domain=$(ynh_app_setting_get --app=$app --key=domain) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) +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) +tls_port=$(ynh_app_setting_get --app=$app --key=tls_port) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#registration is not loaded since it's set up by the config panel + +#================================================= +# GENERIC FINALIZATION +#================================================= + +ynh_app_config_apply() { + _ynh_app_config_apply + + if [ "${changed[registration]}" == "true" ] + then + if [ $registration -eq 1 ] + then + registration_disabled="false" + really_enable_open_registration="--really-enable-open-registration" + else + registration_disabled="true" + really_enable_open_registration="" + fi + + ynh_add_config --template="../conf/dendrite.yaml" --destination="$final_path/dendrite.yaml" + ynh_add_systemd_config + ynh_systemd_action --service_name=$app --action="restart" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/$app.log" + ynh_app_setting_set --app=$app --key=registration --value=$registration + + fi +} + +ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index b06a6c1..289e6e5 100644 --- a/scripts/install +++ b/scripts/install @@ -27,10 +27,20 @@ ynh_abort_if_errors domain=$YNH_APP_ARG_DOMAIN path_url="/" server_name=$YNH_APP_ARG_SERVER_NAME -is_public=$YNH_APP_ARG_IS_PUBLIC +registration=$YNH_APP_ARG_REGISTRATION app=$YNH_APP_INSTANCE_NAME +# Allow or deny registration based on is_public +if [ $registration -eq 1 ] +then + registration_disabled="false" + really_enable_open_registration="--really-enable-open-registration" +else + registration_disabled="true" + really_enable_open_registration="" +fi + #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= @@ -50,6 +60,7 @@ ynh_script_progression --message="Storing installation settings..." --weight=1 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=server_name --value=$server_name +ynh_app_setting_set --app=$app --key=registration --value=$registration #================================================= # STANDARD MODIFICATIONS @@ -169,13 +180,6 @@ chown -R $app:root "$final_path" #================================================= ynh_script_progression --message="Adding a configuration file..." -# Allow or deny registration based of is_public -registration=false -if [ $is_public -eq 1 ] -then - registration=true -fi - # Copy and modify the config file ynh_add_config --template="../conf/dendrite.yaml" --destination="$final_path/dendrite.yaml" @@ -197,7 +201,7 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -ynh_permission_update --permission=main --show_tile=false --protected=true +ynh_permission_update --permission=main --show_tile=false ynh_permission_create --permission=server_api --url=$domain/_matrix \ --label="Server access for client apps." --show_tile=false --allowed=visitors \ @@ -235,7 +239,7 @@ yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/Monolith.log" #================================================= # RELOAD NGINX diff --git a/scripts/restore b/scripts/restore index 7875645..6bf8a10 100644 --- a/scripts/restore +++ b/scripts/restore @@ -112,7 +112,7 @@ yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/Monolith.log" #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index d5ab64b..8019612 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -26,6 +26,7 @@ tls_port=$(ynh_app_setting_get --app=$app --key=tls_port) db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +registration=$(ynh_app_setting_get --app=$app --key=registration) #================================================= # CHECK VERSION @@ -56,7 +57,7 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped Dendrite Matrix homeserver" --log_path="systemd" +ynh_systemd_action --service_name=$app --action="stop" --line_match="Stopped external Monolith listener" --log_path="systemd" #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -67,13 +68,23 @@ if ! groups $app | grep -q 'ssl-cert'; then adduser $app ssl-cert fi - # Define $server_name if not already defined if [ -z $server_name ]; then server_name=$domain ynh_app_setting_set --app=$app --key=server_name --value=$domain fi +# Load up registration variables +if [[ $registration -eq 1 ]] +then + registration_disabled="false" + really_enable_open_registration="--really-enable-open-registration" +else + registration_disabled="true" + really_enable_open_registration="" + ynh_app_setting_set --app=$app --key=registration --value=0 +fi + #================================================= # CREATE DEDICATED USER #================================================= @@ -152,13 +163,6 @@ chown -R $app:root "$final_path" #================================================= ynh_script_progression --message="Updating a configuration file..." -if ynh_permission_has_user --permission=main --user=visitors -then - registration="true" -else - registration="false" -fi - ynh_add_config --template="../conf/dendrite.yaml" --destination="$final_path/dendrite.yaml" chmod 400 "$final_path/dendrite.yaml" @@ -179,8 +183,6 @@ ynh_add_systemd_config #================================================= ynh_script_progression --message="Configuring permissions..." --weight=1 -ynh_permission_update --permission=main --show_tile=false --protected=true - if ! ynh_permission_exists --permission=server_api; then ynh_permission_create --permission=server_api --url=$domain/_matrix \ --label="Server access for client apps." --show_tile=false --allowed=visitors \ @@ -226,7 +228,7 @@ yunohost service add $app --description="Dendrite Matrix homeserver" --log="/var #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action="start" --line_match="Starting external Monolith listener" --log_path="/var/log/$app/Monolith.log" #================================================= # RELOAD NGINX