From 69a96a03488cc4d53ddc8bde230abbf0e5910ff2 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 28 Feb 2024 17:29:21 +0000 Subject: [PATCH] Finish install and upgrade logic for restoring permissions --- conf/config.yaml | 6 +- config_panel.toml | 2 +- scripts/_common.sh | 2 +- scripts/config | 20 ++++-- scripts/install | 53 +++++++-------- scripts/upgrade | 156 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 204 insertions(+), 35 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index c0f96cb..193f7f8 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -500,9 +500,9 @@ bridge: # domain - All users on that homeserver # mxid - Specific user permissions: - "*": "relaybot" - "__BOTUSERS__": "puppeting" - "__BOTADMIN__": "admin" + "__LISTRELAYBOT__": "relaybot" + "__LISTPUPPETING__": "puppeting" + "__LISTADMIN__": "admin" # Options related to the message relay Telegram bot. relaybot: private_chat: diff --git a/config_panel.toml b/config_panel.toml index 79aad49..c6a23ce 100644 --- a/config_panel.toml +++ b/config_panel.toml @@ -17,7 +17,7 @@ services = ["__APP__"] ''' type = "markdown" - [main.permissions.listrelay] + [main.permissions.listrelaybot] ask = "Users bridged thanks to Relay Mode" type = "tags" help = "Relay Role: Talk on Telegram through the RelayBot in a room. No access to commands." diff --git a/scripts/_common.sh b/scripts/_common.sh index 85ac4b5..eaf6a34 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,7 +15,7 @@ apply_permissions() { then #ynh_systemd_action --service_name="$app" --action=stop # Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes. - allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' ) + allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relaybot:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relaybot|full|puppeting)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' ) # Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users. sed -i "/permissions:/,/relaybot:/{/: $role/d;}" "$install_dir/config.yaml" # Ensure that entries with value surrounded with quotes are deleted too. E.g. "users". diff --git a/scripts/config b/scripts/config index 047c683..8da63fe 100644 --- a/scripts/config +++ b/scripts/config @@ -7,13 +7,19 @@ ynh_abort_if_errors # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= +get_config_permission() { + result=$(grep -- ".*: $role" "$install_dir/config.yaml" | sed -r "s/: $role//" | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr -d "'" | tr '\n' ',') + echo $result +} + get__botname() { botname=$(ynh_app_setting_get --app $app --key botname) echo "${botname}" } get__listrelaybot() { - existingRelaybotUsers=$(grep -- "\".*: relaybot" "$install_dir/config.yaml" | sed -r 's/: relaybot//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',') + role="relaybot" + existingRelaybotUsers=$(get_config_permission) cat <