mirror of
https://github.com/YunoHost-Apps/mautrix_telegram_ynh.git
synced 2024-09-03 19:45:55 +02:00
Config panel WIP
This commit is contained in:
parent
e1b64031cc
commit
aa99d1514f
4 changed files with 400 additions and 0 deletions
200
config_panel.toml
Normal file
200
config_panel.toml
Normal file
|
@ -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<User<Puppeting<Full<Admin
|
||||
Allowed values for roles:
|
||||
- * : All Matrix users
|
||||
- domain.tld : All users on a given homeserver
|
||||
- mxid (@user:matrix.org) : Specific Matrix user
|
||||
'''
|
||||
type = "markdown"
|
||||
|
||||
[main.permissions.listrelay]
|
||||
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."
|
||||
|
||||
[main.permissions.listuser]
|
||||
ask = "Bridge Users"
|
||||
type = "tags"
|
||||
help = "User Role: Relaybot level + access to commands to create bridges."
|
||||
|
||||
[main.permissions.listpuppeting]
|
||||
ask = "Bridge Puppeting"
|
||||
type = "tags"
|
||||
help = "Puppeting Role: User level + logging in with a Telegram account."
|
||||
|
||||
[main.permissions.listfull]
|
||||
ask = "Bridge Full"
|
||||
type = "tags"
|
||||
help = "Full Role: Full access to use the bridge, i.e. previous levels + Matrix login."
|
||||
|
||||
[main.permissions.listadmin]
|
||||
ask = "Bridge Administrators"
|
||||
type = "tags"
|
||||
help = "Admin Role: Full access to use the bridge and some extra administration commands."
|
||||
|
||||
[main.bot]
|
||||
name = "Bot Settings"
|
||||
|
||||
[main.bot.bot_username]
|
||||
ask = "Username of the AppService Bot"
|
||||
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"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[main.bot.bot_displayname]
|
||||
ask = "Display name for Bot"
|
||||
type = "string"
|
||||
help = "Set to 'remove' to remove display name, leave empty to set default 'Telegram bridge bot'"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[main.bot.bot_avatar]
|
||||
ask = "Avatar for Bot"
|
||||
type = "string"
|
||||
help = "Should be in format 'mxc://server_name/NeXNQarUbrlYBiPCpprYsRqr', see README for tutorial. Set to 'remove' to remove avatar, leave empty to use standard Telegram logo."
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[privacy]
|
||||
name = "Privacy"
|
||||
services = ["__APP__"]
|
||||
|
||||
[privacy.portal_rooms]
|
||||
name = "Portal Rooms & Encryption Settings"
|
||||
|
||||
[privacy.portal_rooms.text]
|
||||
ask = '''
|
||||
!! Inviting the Bridge in an encrypted room !!
|
||||
!! breaks real End-to-End Encryption (e2ee) !!
|
||||
!! Messages will be unencrypted on the Bridge Server !!
|
||||
'''
|
||||
type = "markdown"
|
||||
|
||||
[privacy.portal_rooms.encryption]
|
||||
ask = "Allow Encryption between Matrix Client and Bridge Server?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Enable so-called End-to-Bridge (e2b) Encryption. For the Bridge to work in group chat Rooms with End-to-End Encryption (e2ee) enabled."
|
||||
bind = "encryption>allow:__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[privacy.portal_rooms.encryption_default]
|
||||
ask = "Force-enable Encryption in all Portal Rooms the Bridge creates?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "This will cause the Bridge Bot to be in private chats for the Encryption to work properly."
|
||||
bind = "encryption>default:__INSTALL_DIR__/config.yaml"
|
||||
visible = "encryption"
|
||||
|
||||
[privacy.portal_rooms.encryption_require]
|
||||
ask = "Require encryption?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Require encryption, drop any unencrypted messages."
|
||||
bind = "encryption>require:__INSTALL_DIR__/config.yaml"
|
||||
visible = "encryption"
|
||||
|
||||
[privacy.config]
|
||||
name = "Privacy Settings"
|
||||
|
||||
[privacy.config.delivery_receipts]
|
||||
ask = "Enable 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 Telegram?"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[privacy.config.telegram_link_preview]
|
||||
ask = "Enable URL Preview?"
|
||||
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 Telegram?"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced]
|
||||
name = "Advanced Settings"
|
||||
services = ["__APP__"]
|
||||
|
||||
[advanced.help]
|
||||
name = "SETTINGS FOR EXPERTS IN SERVER ADMINISTRATION"
|
||||
|
||||
[advanced.help.text]
|
||||
ask = "!! There are **security and privacy risks** if you change these settings without knowing what you do !!"
|
||||
type = "markdown"
|
||||
|
||||
[advanced.telegram]
|
||||
name = "Telegram API MetaData"
|
||||
|
||||
[advanced.telegram.username_template]
|
||||
ask = "Localpart template of MXIDs for Telegram users"
|
||||
type = "string"
|
||||
help = "Defaults to 'telegram_{userid}'. '{userid}' is replaced with the user ID of the Telegram user"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.telegram.alias_template]
|
||||
ask = "Localpart template of room aliases for Telegram portal rooms"
|
||||
type = "string"
|
||||
help = "Defaults to 'telegram_{groupname}'. '{groupname}' is replaced with the name part of the public channel/group invite link"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.telegram.displayname_template]
|
||||
ask = "Displayname template for Telegram users"
|
||||
type = "string"
|
||||
help = "Defaults to '{displayname} (Telegram)'. '{displayname}' is replaced with the display name of the Telegram user"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.telegram.device_model]
|
||||
ask = "Device info sent to Telegram"
|
||||
type = "string"
|
||||
help = "Defaults to 'mautrix-telegram'. 'auto' would set OS name+version"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.appservice]
|
||||
name = "HomeServer Application Service"
|
||||
|
||||
[advanced.appservice.async_media]
|
||||
ask = "Enable asynchronous media uploads?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Enable only if HomeServer supports https://github.com/matrix-org/matrix-spec-proposals/pull/2246"
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.appservice.ephemeral_events]
|
||||
ask = "Receive Ephemeral Events via AppService transactions?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Enable only if HomeServer supports MSC2409 (i.e. Synapse 1.22+). If enabled, you should disable bridge -> 'sync_with_custom_puppets'."
|
||||
bind = ":__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.metrics]
|
||||
name = "Prometheus Metrics"
|
||||
|
||||
[advanced.metrics.enable_metrics]
|
||||
ask = "Enable Prometheus Metrics?"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Requires prometheus-client to be installed"
|
||||
bind = "metrics>enabled:__INSTALL_DIR__/config.yaml"
|
||||
|
||||
[advanced.metrics.listen_port]
|
||||
ask = "Port for the Metrics listener?"
|
||||
type = "string"
|
||||
help = "Defaults to: '8000'. The path is always /metrics"
|
||||
bind = "metrics>listen_port:__INSTALL_DIR__/config.yaml"
|
||||
visible = "enable_metrics"
|
||||
|
|
@ -1,5 +1,76 @@
|
|||
#!/bin/bash
|
||||
|
||||
#=================================================
|
||||
# CONFIG PANEL SETTERS
|
||||
#=================================================
|
||||
|
||||
apply_permissions() {
|
||||
set -o noglob # Disable globbing to avoid expansions when passing * as value.
|
||||
declare values="list$role"
|
||||
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
|
||||
newValues="${newValues//\"}"
|
||||
usersArray=(${newValues//,/ }) # Split the values using comma (,) as separator.
|
||||
|
||||
if [ -n "$newValues" ]
|
||||
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' )
|
||||
# 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".
|
||||
sed -i "/permissions:/,/relaybot:/{/: \"$role\"/d;}" "$install_dir/config.yaml"
|
||||
for user in "${usersArray[@]}"
|
||||
do
|
||||
if grep -q -x "${user}" <<< "$allDefinedEntries"
|
||||
then
|
||||
ynh_print_info "User $user already defined in another role."
|
||||
else
|
||||
sed -i "/permissions:/a \ \\\"$user\": $role" "$install_dir/config.yaml" # Whitespaces are needed so that the file can be correctly parsed
|
||||
fi
|
||||
done
|
||||
fi
|
||||
set +o noglob
|
||||
|
||||
ynh_print_info "Users with role $role added in $install_dir/config.yaml"
|
||||
}
|
||||
|
||||
|
||||
set__listrelaybot() {
|
||||
role="relaybot"
|
||||
ynh_app_setting_set --app=$app --key=listrelaybot --value="$listrelaybot"
|
||||
apply_permissions
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
set__listuser() {
|
||||
role="user"
|
||||
ynh_app_setting_set --app=$app --key=listuser --value="$listuser"
|
||||
apply_permissions
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
set__listpuppeting() {
|
||||
role="puppeting"
|
||||
ynh_app_setting_set --app=$app --key=listpuppeting --value="$listpuppeting"
|
||||
apply_permissions
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
set__listfull() {
|
||||
role="full"
|
||||
ynh_app_setting_set --app=$app --key=listfull --value="$listfull"
|
||||
apply_permissions
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
set__listadmin() {
|
||||
role="admin"
|
||||
ynh_app_setting_set --app=$app --key=listadmin --value="$listadmin"
|
||||
apply_permissions
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# COMMON VARIABLES
|
||||
#=================================================
|
||||
|
|
81
scripts/config
Normal file
81
scripts/config
Normal file
|
@ -0,0 +1,81 @@
|
|||
#!/bin/bash
|
||||
source _common.sh
|
||||
source /usr/share/yunohost/helpers
|
||||
ynh_abort_if_errors
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC GETTERS FOR TOML SHORT KEY
|
||||
#=================================================
|
||||
|
||||
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' ',')
|
||||
|
||||
cat <<EOF
|
||||
"$existingRelaybotUsers"
|
||||
EOF
|
||||
}
|
||||
|
||||
get__listuser() {
|
||||
existingUsers=$(grep -- "\".*: user" "$install_dir/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
"$existingUsers"
|
||||
EOF
|
||||
}
|
||||
|
||||
get__listpuppeting() {
|
||||
existingPuppeting=$(grep -- "\".*: puppeting" "$install_dir/config.yaml" | sed -r 's/: puppeting//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
"$existingPuppeting"
|
||||
EOF
|
||||
}
|
||||
|
||||
get__listfull() {
|
||||
existingFull=$(grep -- "\".*: full" "$install_dir/config.yaml" | sed -r 's/: full//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
"$existingFull"
|
||||
EOF
|
||||
}
|
||||
|
||||
get__listadmin() {
|
||||
existingAdmins=$(grep -- "\".*: admin" "$install_dir/config.yaml" | sed -r 's/: admin//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
"$existingAdmins"
|
||||
EOF
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
|
||||
#=================================================
|
||||
# SPECIFIC SETTERS FOR TOML SHORT KEYS
|
||||
#=================================================
|
||||
|
||||
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/bot_username:.*/bot_username: $botname/" "$install_dir/config.yaml"
|
||||
"$install_dir/mautrix-whatsapp" -g -c "$install_dir/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" "$install_dir"
|
||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||
ynh_store_file_checksum --file="$install_dir/config.yaml"
|
||||
}
|
||||
|
||||
ynh_app_config_run $1
|
|
@ -21,6 +21,54 @@ ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
|||
ynh_app_setting_set --app=$app --key=domain --value=$domain
|
||||
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
||||
|
||||
#=================================================
|
||||
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
|
||||
#=================================================
|
||||
|
||||
appserviceid=$app
|
||||
async_media="false"
|
||||
displayname="Telegram bridge bot"
|
||||
avatar="mxc://maunium.net/tJCRmUyJDsgRNgqhOgoiHWbX"
|
||||
ephemeral_events="false"
|
||||
enable_metrics="false"
|
||||
listen_port="8000"
|
||||
os_name="Mautrix-WhatsApp bridge"
|
||||
browser_name="unknown"
|
||||
username_template="whatsapp_{{.}}"
|
||||
personal_filtering_spaces="false"
|
||||
delivery_receipts="false"
|
||||
send_presence_on_typing="false"
|
||||
url_previews="false"
|
||||
encryption_default="false"
|
||||
encryption_require="false"
|
||||
admin_only="true"
|
||||
print_level="info"
|
||||
enable_relaybot="true"
|
||||
listrelay="*"
|
||||
listadmin="$botadmin"
|
||||
listuser="$botusers"
|
||||
|
||||
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
|
||||
ynh_app_setting_set --app=$app --key=async_media --value=$async_media
|
||||
ynh_app_setting_set --app=$app --key=displayname --value=$displayname
|
||||
ynh_app_setting_set --app=$app --key=avatar --value=$avatar
|
||||
ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events
|
||||
ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics
|
||||
ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port
|
||||
ynh_app_setting_set --app=$app --key=os_name --value=$os_name
|
||||
ynh_app_setting_set --app=$app --key=browser_name --value=$browser_name
|
||||
ynh_app_setting_set --app=$app --key=username_template --value=$username_template
|
||||
ynh_app_setting_set --app=$app --key=personal_filtering_spaces --value=$personal_filtering_spaces
|
||||
ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts
|
||||
ynh_app_setting_set --app=$app --key=send_presence_on_typing --value=$send_presence_on_typing
|
||||
ynh_app_setting_set --app=$app --key=url_previews --value=$url_previews
|
||||
ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default
|
||||
ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require
|
||||
ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot
|
||||
ynh_app_setting_set --app=$app --key=admin_only --value=$admin_only
|
||||
ynh_app_setting_set --app=$app --key=print_level --value=$print_level
|
||||
ynh_app_setting_set --app=$app --key=listrelay --value=$listrelay
|
||||
|
||||
#=================================================
|
||||
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue