From aa99d1514f8c5edc469045ae96b68e2e96bb5d08 Mon Sep 17 00:00:00 2001 From: Dante Date: Sat, 13 Jan 2024 17:39:34 +0000 Subject: [PATCH 1/5] Config panel WIP --- config_panel.toml | 200 +++++++++++++++++++++++++++++++++++++++++++++ scripts/_common.sh | 71 ++++++++++++++++ scripts/config | 81 ++++++++++++++++++ scripts/install | 48 +++++++++++ 4 files changed, 400 insertions(+) create mode 100644 config_panel.toml create mode 100644 scripts/config diff --git a/config_panel.toml b/config_panel.toml new file mode 100644 index 0000000..79aad49 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,200 @@ +version = "1.0" + +[main] +name = "Main Settings" +services = ["__APP__"] + + [main.permissions] + name = "Permissions for using the bridge" + + [main.permissions.helptext] + ask = ''' + Roles with Increasing Power: Relaybot Date: Wed, 28 Feb 2024 17:29:21 +0000 Subject: [PATCH 2/5] 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 < Date: Wed, 28 Feb 2024 17:29:44 +0000 Subject: [PATCH 3/5] Auto-update README --- README.md | 4 ++-- README_fr.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 75fe3e2..ddd147e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ @@ -41,4 +41,4 @@ or sudo yunohost app upgrade mautrix_telegram -u https://github.com/YunoHost-Apps/mautrix_telegram_ynh/tree/testing --debug ``` -**More info regarding app packaging:** +**More info regarding app packaging:** \ No newline at end of file diff --git a/README_fr.md b/README_fr.md index 3390ff2..9bb3562 100644 --- a/README_fr.md +++ b/README_fr.md @@ -1,5 +1,5 @@ From f0e75c5d27d556cc1564142d69ba3921e1bebebe Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 28 Feb 2024 18:41:16 +0000 Subject: [PATCH 4/5] Fix upgrade list permissions variables name --- scripts/upgrade | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/upgrade b/scripts/upgrade index 19fc7b9..c1c6211 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -211,11 +211,11 @@ chown -R $app:$app "$install_dir" ynh_script_progression --message="Updating a configuration file..." --weight=2 # reset permissions to be able to apply_permissions with app_setting values after upgrade -listrelaybot=$listrelaybot -listuser=$listuser -listpuppeting=$listpuppeting -listfull=$listfull -listadmin=$listadmin +listrelaybot_=$listrelaybot +listuser_=$listuser +listpuppeting_=$listpuppeting +listfull_=$listfull +listadmin_=$listadmin listrelaybot="*" listuser="@user:domain.tld" listpuppeting="@puppet:domain.tld" From 254c671780835c13c327492765a9928f109c3b20 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 28 Feb 2024 19:23:19 +0000 Subject: [PATCH 5/5] Bump version --- README.md | 2 +- README_fr.md | 2 +- manifest.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ddd147e..089c403 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in A puppeting bridge between Matrix and Telegram packaged as a YunoHost service. Messages, notifications (and sometimes media) are bridged between a Telegram user and a Matrix user. Currently the Matrix user can NOT invite other Matrix user in a bridged Telegram room, so only someone with a Telegram account can participate to Telegram group conversations. The ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/index.html) bridge is a Synapse App Service and relies on postgresql. Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) should be installed beforehand. -**Shipped version:** 0.15.1~ynh1 +**Shipped version:** 0.15.1~ynh2 ## Documentation and resources * Official app website: diff --git a/README_fr.md b/README_fr.md index 9bb3562..b604082 100644 --- a/README_fr.md +++ b/README_fr.md @@ -22,7 +22,7 @@ La passerelle ["Mautrix-Telegram"](https://docs.mau.fi/bridges/python/telegram/i ** Attention : sauvegardez et restaurez toujours les deux applications Yunohost matrix-synapse et mautrix_telegram en même temps!** -**Version incluse :** 0.15.1~ynh1 +**Version incluse :** 0.15.1~ynh2 ## Documentations et ressources * Site officiel de l’app : diff --git a/manifest.toml b/manifest.toml index 4e3355c..7bf9f98 100644 --- a/manifest.toml +++ b/manifest.toml @@ -3,7 +3,7 @@ id = "mautrix_telegram" name = "Matrix-Telegram bridge" description.en = "Telegram puppeting bridge for Matrix/Synapse" description.fr = "Passerelle Telegram pour Matrix/Synapse" -version = "0.15.1~ynh1" +version = "0.15.1~ynh2" maintainers = ["thardev"] [upstream]