From dac54950af5cd615b1ac40f1f372637a667e3857 Mon Sep 17 00:00:00 2001 From: Dante Date: Mon, 3 Oct 2022 15:39:39 +0100 Subject: [PATCH] Add config panel with few config options and user management --- config_panel.toml | 111 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/config | 92 ++++++++++++++++++++++++++++++++++++++ scripts/install | 4 ++ 3 files changed, 207 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..e0ba6e8 --- /dev/null +++ b/config_panel.toml @@ -0,0 +1,111 @@ +version = "1.0" + +[main] +name = "General configuration" +services = ["__APP__"] + + [main.config] + name = "Configuration options" + + [main.config.botname] + ask = "Set a bot name for the bridge puppet" + type = "string" + help = "Sets bot username. Please keep in mind that the bot admin room for previous bot username will stop working so you may need to create a new one using the new username" + + [main.config.log_level] + ask = "Sets log level of the application" + choices = ["debug", "info", "warn", "error", "fatal"] + default = "info" + bind = "logging>print_level:__FINALPATH__/config.yaml" + +[encryption] +name = "Encryption" +services = ["__APP__"] + [encryption.config] + name = "Encryption settings" + + [encryption.config.encryption] + ask = "Enable encryption" + type = "boolean" + yes = "true" + no = "false" + help = "Enables end to bridge encryption" + bind = "encryption>allow:__FINALPATH__/config.yaml" + + [encryption.config.default_encryption] + ask = "Default encryption" + type = "boolean" + yes = "true" + no = "false" + help = "Force-enable encryption in all portals the bridge creates. This will cause the bridge bot to be in private chats for the encryption to work properly." + bind = "encryption>default:__FINALPATH__/config.yaml" + + [encryption.config.require_encryption] + ask = "Require encryption" + type = "boolean" + yes = "true" + no = "false" + help = "Require encryption, drop any unencrypted messages." + bind = "encryption>require:__FINALPATH__/config.yaml" + +[usermanagement] +name = "User management" +services = ["__APP__"] + + [usermanagement.config] + name = "User management" + + [usermanagement.config.helptext] + ask = "Allowed values:\n  * - All Matrix users\n  domain - All users on that homeserver\n  mxid (@user:matrix.org) - Specific Matrix user\n  username - Specific local user" + type = "markdown" + + [usermanagement.config.listuser] + ask = "Users" + type = "tags" + visible = "role == 'user'" + + [usermanagement.config.listadmin] + ask = "Admins" + type = "tags" + visible = "role == 'admin'" + + [usermanagement.config.listrelay] + ask = "Relay users" + type = "tags" + visible = "role == 'relay'" + + [usermanagement.config.role] + ask = "Role" + type = "select" + choices = ["user", "admin", "relay"] + +[privacy] +name = "Privacy" +services = ["__APP__"] + + [privacy.config] + name = "Privacy settings" + + [privacy.config.delivery_receipts] + ask = "Delivery receipts" + type = "boolean" + yes = "true" + no = "false" + help = "Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp?" + bind = "bridge>delivery_receipts:__FINALPATH__/config.yaml" + + [privacy.config.send_presence_on_typing] + ask = "Send presence on typing" + type = "boolean" + yes = "true" + no = "false" + help = "Send the presence as 'available' to whatsapp when users start typing on a portal." + bind = "bridge>send_presence_on_typing:__FINALPATH__/config.yaml" + + [privacy.config.url_previews] + ask = "URL previews" + type = "boolean" + yes = "true" + no = "false" + help = "Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview, and send it to WhatsApp?" + bind = "bridge>url_previews:__FINALPATH__/config.yaml" diff --git a/scripts/config b/scripts/config new file mode 100644 index 0000000..dbe4b5a --- /dev/null +++ b/scripts/config @@ -0,0 +1,92 @@ +#!/bin/bash +source /usr/share/yunohost/helpers +ynh_abort_if_errors + +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +function get__encryption { + encryption=$(ynh_app_setting_get --app $app --key encryption) + echo "'${encryption}'" +} + +function get__botname { + botname=$(ynh_app_setting_get --app $app --key botname) + echo "${botname}" +} + +function set__botname { + old_botname=$(ynh_app_setting_get --app $app --key botname) + if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed. + then + return + fi + + ynh_app_setting_set --app=$app --key=botname --value="$botname" + synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance) + + sed -i "s/username:.*/username: $botname/" "$final_path/config.yaml" + "$final_path/mautrix-whatsapp" -g -c "$final_path/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml" + "/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die --message="Synapse can't restart with the appservice configuration" + chown -R "$app:$app" "$final_path" + ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" + ynh_store_file_checksum --file="$final_path/config.yaml" +} + +function get__listuser { + existingUsers=$(grep -- "\".*: user" "$final_path/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',') + + cat <