1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git synced 2024-09-03 19:46:01 +02:00

Merge pull request #74 from YunoHost-Apps/expose-config-panel

Add config panel with few config options and user management
This commit is contained in:
Dante 2023-02-04 20:10:51 +00:00 committed by GitHub
commit 56cacc1b38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 589 additions and 79 deletions

View file

@ -5,7 +5,7 @@ It shall NOT be edited by hand.
# Matrix-WhatsApp bridge for YunoHost # Matrix-WhatsApp bridge for YunoHost
[![Integration level](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Working status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg) [![Integration level](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Working status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg)
[![Install Matrix-WhatsApp bridge with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) [![Install Matrix-WhatsApp bridge with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp)
*[Lire ce readme en français.](./README_fr.md)* *[Lire ce readme en français.](./README_fr.md)*

View file

@ -5,15 +5,15 @@ It shall NOT be edited by hand.
# Matrix-WhatsApp bridge pour YunoHost # Matrix-WhatsApp bridge pour YunoHost
[![Niveau d'intégration](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg) [![Niveau dintégration](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg)
[![Installer Matrix-WhatsApp bridge avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) [![Installer Matrix-WhatsApp bridge avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp)
*[Read this readme in english.](./README.md)* *[Read this readme in english.](./README.md)*
> *Ce package vous permet d'installer Matrix-WhatsApp bridge rapidement et simplement sur un serveur YunoHost. > *Ce package vous permet dinstaller Matrix-WhatsApp bridge rapidement et simplement sur un serveur YunoHost.
Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* Si vous navez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment linstaller et en profiter.*
## Vue d'ensemble ## Vue densemble
Une passerelle entre Matrix et WhatsApp empaquetée comme un service YunoHost. Une passerelle entre Matrix et WhatsApp empaquetée comme un service YunoHost.
Les messages, médias et notifications sont relayées entre un compte WhatsApp et un compte Matrix. Les messages, médias et notifications sont relayées entre un compte WhatsApp et un compte Matrix.
@ -106,9 +106,9 @@ Si vous devez téléverser vos fichiers log quelque-part, soyez avertis qu'ils c
## Documentations et ressources ## Documentations et ressources
* Site officiel de l'app : <https://maunium.net/go/mautrix-whatsapp/> * Site officiel de lapp : <https://maunium.net/go/mautrix-whatsapp/>
* Documentation officielle de l'admin : <https://docs.mau.fi/bridges/go/whatsapp/index.html> * Documentation officielle de ladmin : <https://docs.mau.fi/bridges/go/whatsapp/index.html>
* Dépôt de code officiel de l'app : <https://github.com/mautrix/whatsapp> * Dépôt de code officiel de lapp : <https://github.com/mautrix/whatsapp>
* Documentation YunoHost pour cette app : <https://yunohost.org/app_mautrix_whatsapp> * Documentation YunoHost pour cette app : <https://yunohost.org/app_mautrix_whatsapp>
* Signaler un bug : <https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/issues> * Signaler un bug : <https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/issues>
@ -124,4 +124,4 @@ ou
sudo yunohost app upgrade mautrix_whatsapp -u https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/tree/testing --debug sudo yunohost app upgrade mautrix_whatsapp -u https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/tree/testing --debug
``` ```
**Plus d'infos sur le packaging d'applications :** <https://yunohost.org/packaging_apps> **Plus dinfos sur le packaging dapplications :** <https://yunohost.org/packaging_apps>

View file

@ -15,7 +15,7 @@ homeserver:
# Endpoint for reporting per-message status. # Endpoint for reporting per-message status.
message_send_checkpoint_endpoint: null message_send_checkpoint_endpoint: null
# Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246? # Does the homeserver support https://github.com/matrix-org/matrix-spec-proposals/pull/2246?
async_media: false async_media: __ASYNC_MEDIA__
# Application service host/registration related details. # Application service host/registration related details.
# Changing these values requires regeneration of the registration. # Changing these values requires regeneration of the registration.
@ -56,13 +56,13 @@ appservice:
username: __BOTNAME__ username: __BOTNAME__
# Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty
# to leave display name/avatar as-is. # to leave display name/avatar as-is.
displayname: WhatsApp bridge bot displayname: __DISPLAYNAME__
avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr avatar: __AVATAR__
# Whether or not to receive ephemeral events via appservice transactions. # Whether or not to receive ephemeral events via appservice transactions.
# Requires MSC2409 support (i.e. Synapse 1.22+). # Requires MSC2409 support (i.e. Synapse 1.22+).
# You should disable bridge -> sync_with_custom_puppets when this is enabled. # You should disable bridge -> sync_with_custom_puppets when this is enabled.
ephemeral_events: true ephemeral_events: __EPHEMERAL_EVENTS__
# Should incoming events be handled asynchronously? # Should incoming events be handled asynchronously?
# This may be necessary for large public instances with lots of messages going through. # This may be necessary for large public instances with lots of messages going through.
@ -79,24 +79,24 @@ segment_key: null
# Prometheus config. # Prometheus config.
metrics: metrics:
# Enable prometheus metrics? # Enable prometheus metrics?
enabled: false enabled: __ENABLE_METRICS__
# IP and port where the metrics listener should be. The path is always /metrics # IP and port where the metrics listener should be. The path is always /metrics
listen: 127.0.0.1:8001 listen: __LISTEN_PORT__
# Config for things that are directly sent to WhatsApp. # Config for things that are directly sent to WhatsApp.
whatsapp: whatsapp:
# Device name that's shown in the "WhatsApp Web" section in the mobile app. # Device name that's shown in the "WhatsApp Web" section in the mobile app.
os_name: Mautrix-WhatsApp bridge os_name: __OS_NAME__
# Browser name that determines the logo shown in the mobile app. # Browser name that determines the logo shown in the mobile app.
# Must be "unknown" for a generic icon or a valid browser name if you want a specific icon. # Must be "unknown" for a generic icon or a valid browser name if you want a specific icon.
# List of valid browser names: https://github.com/tulir/whatsmeow/blob/8b34d886d543b72e5f4699cf5b2797f68d598f78/binary/proto/def.proto#L38-L51 # List of valid browser names: https://github.com/tulir/whatsmeow/blob/8b34d886d543b72e5f4699cf5b2797f68d598f78/binary/proto/def.proto#L38-L51
browser_name: unknown browser_name: __BROWSER_NAME__
# Bridge config # Bridge config
bridge: bridge:
# Localpart template of MXIDs for WhatsApp users. # Localpart template of MXIDs for WhatsApp users.
# {{.}} is replaced with the phone number of the WhatsApp user. # {{.}} is replaced with the phone number of the WhatsApp user.
username_template: whatsapp_{{.}} username_template: __USERNAME_TEMPLATE__
# Displayname template for WhatsApp users. # Displayname template for WhatsApp users.
# {{.PushName}} - nickname set by the WhatsApp user # {{.PushName}} - nickname set by the WhatsApp user
# {{.BusinessName}} - validated WhatsApp business name # {{.BusinessName}} - validated WhatsApp business name
@ -107,9 +107,9 @@ bridge:
displayname_template: "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)" displayname_template: "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"
# Should the bridge create a space for each logged-in user and add bridged rooms to it? # Should the bridge create a space for each logged-in user and add bridged rooms to it?
# Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time. # Users who logged in before turning this on should run `!wa sync space` to create and fill the space for the first time.
personal_filtering_spaces: false personal_filtering_spaces: __PERSONAL_FILTERING_SPACES__
# Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp? # Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp?
delivery_receipts: false delivery_receipts: __DELIVERY_RECEIPTS__
# Whether the bridge should send the message status as a custom com.beeper.message_send_status event. # Whether the bridge should send the message status as a custom com.beeper.message_send_status event.
message_status_events: false message_status_events: false
# Whether the bridge should send error notices via m.notice events when a message fails to bridge. # Whether the bridge should send error notices via m.notice events when a message fails to bridge.
@ -226,7 +226,7 @@ bridge:
# Send the presence as "available" to whatsapp when users start typing on a portal. # Send the presence as "available" to whatsapp when users start typing on a portal.
# This works as a workaround for homeservers that do not support presence, and allows # This works as a workaround for homeservers that do not support presence, and allows
# users to see when the whatsapp user on the other side is typing during a conversation. # users to see when the whatsapp user on the other side is typing during a conversation.
send_presence_on_typing: false send_presence_on_typing: __SEND_PRESENCE_ON_TYPING__
# Should the bridge always send "active" delivery receipts (two gray ticks on WhatsApp) # Should the bridge always send "active" delivery receipts (two gray ticks on WhatsApp)
# even if the user isn't marked as online (e.g. when presence bridging isn't enabled)? # even if the user isn't marked as online (e.g. when presence bridging isn't enabled)?
# #
@ -298,7 +298,7 @@ bridge:
# Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview, # Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview,
# and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews` # and send it to WhatsApp? URL previews can always be sent using the `com.beeper.linkpreviews`
# key in the event content even if this is disabled. # key in the event content even if this is disabled.
url_previews: false url_previews: __URL_PREVIEWS__
# Send captions in the same message as images. This will send data compatible with both MSC2530 and MSC3552. # Send captions in the same message as images. This will send data compatible with both MSC2530 and MSC3552.
# This is currently not supported in most clients. # This is currently not supported in most clients.
caption_in_message: false caption_in_message: false
@ -342,11 +342,11 @@ bridge:
# Default to encryption, force-enable encryption in all portals the bridge creates # Default to encryption, 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. # This will cause the bridge bot to be in private chats for the encryption to work properly.
# It is recommended to also set private_chat_portal_meta to true when using this. # It is recommended to also set private_chat_portal_meta to true when using this.
default: false default: __ENCRYPTION_DEFAULT__
# Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data. # Whether to use MSC2409/MSC3202 instead of /sync long polling for receiving encryption-related data.
appservice: false appservice: false
# Require encryption, drop any unencrypted messages. # Require encryption, drop any unencrypted messages.
require: false require: __ENCRYPTION_REQUIRE__
# Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled.
# You must use a client that supports requesting keys from other users to use this feature. # You must use a client that supports requesting keys from other users to use this feature.
allow_key_sharing: false allow_key_sharing: false
@ -403,20 +403,18 @@ bridge:
# domain - All users on that homeserver # domain - All users on that homeserver
# mxid - Specific user # mxid - Specific user
permissions: permissions:
"*": relay "__LISTRELAY__": relay
#"example.com": user "__LISTUSER__": user
"__BOTUSERS__": user "__LISTADMIN__": admin
#"@admin:example.com": admin
"__BOTADMIN__": admin
# Settings for relay mode # Settings for relay mode
relay: relay:
# Whether relay mode should be allowed. If allowed, `!wa set-relay` can be used to turn any # Whether relay mode should be allowed. If allowed, `!wa set-relay` can be used to turn any
# authenticated user into a relaybot for that chat. # authenticated user into a relaybot for that chat.
#enabled: false #enabled: false
enabled: true enabled: __ENABLE_RELAYBOT__
# Should only admins be allowed to set themselves as relay users? # Should only admins be allowed to set themselves as relay users?
admin_only: true admin_only: __ADMIN_ONLY__
# The formats to use when sending messages to WhatsApp via the relaybot. # The formats to use when sending messages to WhatsApp via the relaybot.
message_formats: message_formats:
m.text: "<b>{{ .Sender.Displayname }}</b>: {{ .Message }}" m.text: "<b>{{ .Sender.Displayname }}</b>: {{ .Message }}"
@ -445,4 +443,4 @@ logging:
timestamp_format: "Jan _2, 2006 15:04:05" timestamp_format: "Jan _2, 2006 15:04:05"
# Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file. # Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file.
# Options: debug, info, warn, error, fatal # Options: debug, info, warn, error, fatal
print_level: INFO print_level: __PRINT_LEVEL__

219
config_panel.toml Normal file
View file

@ -0,0 +1,219 @@
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: Relay<User<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 WhatsApp through the RelayBot in a room where it has been activated with '!wa set-relay', no access otherwise."
visible = "enable_relaybot"
[main.permissions.listuser]
ask = "Bridge Users"
type = "tags"
help = "User Role: Access to use the bridge to chat with a WhatsApp account."
[main.permissions.listadmin]
ask = "Bridge Administrators"
type = "tags"
help = "Admin Role: User level and some additional administration tools."
[main.bridge]
name = "Puppetting Bridge Settings"
[main.bridge.enable_relaybot]
ask = "Should Relay Mode be allowed?"
type = "boolean"
yes = "true"
no = "false"
help = "If allowed, '!wa set-relay' can be used to turn any Bridge User into a RelayBot for that chat. This allows people to talk on WhatsApp without an own account."
bind = "relay>enabled:__FINALPATH__/config.yaml"
[main.bridge.admin_only]
ask = "Should only Bridge Admins be allowed to set themselves as Relay Users?"
type = "boolean"
yes = "true"
no = "false"
help = "See User management -> Admins"
bind = ":__FINALPATH__/config.yaml"
visible = "enable_relaybot"
[main.bot]
name = "Robot Settings"
[main.bot.botname]
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 = "bot>username:__FINALPATH__/config.yaml"
[main.bot.displayname]
ask = "Display name for Bot"
type = "string"
help = "Set to 'remove' to remove display name, leave empty to set default 'WhatsApp bridge bot'"
bind = ":__FINALPATH__/config.yaml"
[main.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 WhatsApp logo."
bind = ":__FINALPATH__/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:__FINALPATH__/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:__FINALPATH__/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:__FINALPATH__/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 WhatsApp?"
bind = ":__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 = ":__FINALPATH__/config.yaml"
[privacy.config.url_previews]
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 WhatsApp?"
bind = ":__FINALPATH__/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.whatsapp]
name = "WhatsApp Web API MetaData"
[advanced.whatsapp.username_template]
ask = "Localpart template of MXIDs for WhatsApp users"
type = "string"
help = "Defaults to 'whatsapp_{{.}}'. '{{.}}' is replaced with the phone number 'msidsn' of the WhatsApp user."
bind = ":__FINALPATH__/config.yaml"
[advanced.whatsapp.os_name]
ask = "Device name in the 'WhatsApp Web' section of the smartphone app"
type = "string"
bind = ":__FINALPATH__/config.yaml"
[advanced.whatsapp.browser_name]
ask = "Browser name that determines the logo shown in the smartphone app"
type = "select"
choices = ["unknown", "chrome", "firefox", "ie", "opera", "safari", "edge", "desktop", "ipad", "android_tablet", "ohana", "aloha", "catalina", "tcl_tv"]
help = "Must be 'unknown' for a generic icon or a valid browser name if you want a specific logo."
bind = ":__FINALPATH__/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 = ":__FINALPATH__/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 = ":__FINALPATH__/config.yaml"
[advanced.appservice.print_level]
ask = "Logging print level for Standard Output"
type = "select"
choices = ["debug", "info", "warn", "error", "fatal"]
help = "Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file."
bind = ":__FINALPATH__/config.yaml"
[advanced.metrics]
name = "Prometheus Metrics"
[advanced.metrics.enable_metrics]
ask = "Enable Prometheus Metrics?"
type = "boolean"
yes = "true"
no = "false"
bind = "metrics>enabled:__FINALPATH__/config.yaml"
[advanced.metrics.listen_port]
ask = "IP and Port for the Metrics listener?"
type = "string"
help = "Defaults to: '127.0.0.1:8001'. The path is always /metrics"
bind = "metrics>listen:__FINALPATH__/config.yaml"
visible = "enable_metrics"

View file

@ -104,11 +104,11 @@
"en": "Choose Matrix user(s) authorized to bridge with the WhatsApp bot.", "en": "Choose Matrix user(s) authorized to bridge with the WhatsApp bot.",
"fr": "Choisissez le/les compte(s) Matrix autorisés à utiliser la passerelle WhatsApp." "fr": "Choisissez le/les compte(s) Matrix autorisés à utiliser la passerelle WhatsApp."
}, },
"example": "admin or domain or @johndoe:server.name or server.name or *", "example": "local or @johndoe:server.name or server.name or *",
"default": "domain", "default": "local",
"help": { "help": {
"en": "Either the administrator only (admin), all local Synapse users (domain), a remote or local user (@johndoe:server.name), a remote server (matrix.org), or all remote/local servers (*) can be authorized. Give the Matrix server_name, not the full domain/URL.", "en": "Either all local Synapse users (local), a remote or local user (@johndoe:server.name), a remote server (matrix.org), or all remote/local servers (*) can be authorized. Give the Matrix server_name, not the full domain/URL.",
"fr": "L'administrateur seulement (admin), tous les comptes Synapse locaux (domain), un compte local ou distant (@johndoe:server.name), un serveur distant (matrix.org), ou tous les serveurs remote/local (*). Donner le nom du serveur Matrix, pas le domaine/URL complet." "fr": "Soit tous les comptes Synapse locaux (local), un compte local ou distant (@johndoe:server.name), un serveur distant (matrix.org), ou tous les serveurs remote/local (*). Donner le nom du serveur Matrix, pas le domaine/URL complet."
} }
} }
] ]

116
scripts/config Normal file
View file

@ -0,0 +1,116 @@
#!/bin/bash
source /usr/share/yunohost/helpers
ynh_abort_if_errors
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
get__botname() {
botname=$(ynh_app_setting_get --app $app --key botname)
echo "${botname}"
}
get__listuser() {
existingUsers=$(grep -- "\".*: user" "$final_path/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
cat <<EOF
"$existingUsers"
EOF
}
get__listrelay() {
existingRelayUsers=$(grep -- "\".*: relay" "$final_path/config.yaml" | sed -r 's/: relay//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
cat <<EOF
"$existingRelayUsers"
EOF
}
get__listadmin() {
existingAdmins=$(grep -- "\".*: admin" "$final_path/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
#=================================================
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' "$final_path/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:/,/relay:/{/: $role/d;}" "$final_path/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" "$final_path/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 $final_path/config.yaml"
}
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"
}
set__listuser() {
role="user"
ynh_app_setting_set --app=$app --key=listuser --value="$listuser"
apply_permissions
ynh_store_file_checksum --file="$final_path/config.yaml"
}
set__listrelay() {
role="relay"
ynh_app_setting_set --app=$app --key=listrelay --value="$listrelay"
apply_permissions
ynh_store_file_checksum --file="$final_path/config.yaml"
}
set__listadmin() {
role="admin"
ynh_app_setting_set --app=$app --key=listadmin --value="$listadmin"
apply_permissions
ynh_store_file_checksum --file="$final_path/config.yaml"
}
ynh_app_config_run $1

View file

@ -28,16 +28,11 @@ synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER
botname=$YNH_APP_ARG_BOTNAME botname=$YNH_APP_ARG_BOTNAME
bot_synapse_adm=$YNH_APP_ARG_BOT_SYNAPSE_ADM bot_synapse_adm=$YNH_APP_ARG_BOT_SYNAPSE_ADM
encryption=$YNH_APP_ARG_ENCRYPTION encryption=$YNH_APP_ARG_ENCRYPTION
botadmin=$YNH_APP_ARG_BOTADMIN listadmin=$YNH_APP_ARG_BOTADMIN
botusers=$YNH_APP_ARG_BOTUSERS listuser=$YNH_APP_ARG_BOTUSERS
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
if [ "$botusers" == "admin" ]
then
botusers=$botadmin
fi
# ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_whatsapp bridge # ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_whatsapp bridge
if [ $synapsenumber -eq "1" ] if [ $synapsenumber -eq "1" ]
then then
@ -49,6 +44,55 @@ server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
domain=$(ynh_app_setting_get --app $synapse_instance --key domain) domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
synapse_db_name="matrix_$synapse_instance" synapse_db_name="matrix_$synapse_instance"
if [ "$listuser" == "local" ]
then
listuser="$server_name"
fi
#=================================================
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
#=================================================
async_media="false"
displayname="WhatsApp bridge bot"
avatar="mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr"
ephemeral_events="true"
enable_metrics="false"
listen_port="127.0.0.1:8001"
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="*"
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
#================================================= #=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#================================================= #=================================================
@ -66,8 +110,8 @@ ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
ynh_app_setting_set --app=$app --key=botname --value=$botname ynh_app_setting_set --app=$app --key=botname --value=$botname
ynh_app_setting_set --app=$app --key=bot_synapse_adm --value=$bot_synapse_adm ynh_app_setting_set --app=$app --key=bot_synapse_adm --value=$bot_synapse_adm
ynh_app_setting_set --app=$app --key=encryption --value=$encryption ynh_app_setting_set --app=$app --key=encryption --value=$encryption
ynh_app_setting_set --app=$app --key=botadmin --value=$botadmin ynh_app_setting_set --app=$app --key=listuser --value=$listuser
ynh_app_setting_set --app=$app --key=botusers --value=$botusers ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin
ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance
ynh_app_setting_set --app=$app --key=server_name --value=$server_name 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=domain --value=$domain
@ -184,7 +228,7 @@ ynh_script_progression --message="Starting a systemd service..." --weight=15
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
# Wait until the synapse user is created # Wait until the synapse user is created
sleep 30 sleep 30
# (Note that, by default, non-admins might not have your homeserver's permission to create communities.) # (Note that, by default, non-admins might not have your homeserver's permission to create Spaces.)
if [ "$bot_synapse_adm" = true ] if [ "$bot_synapse_adm" = true ]
then then
ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";"

View file

@ -19,8 +19,6 @@ app=$YNH_APP_INSTANCE_NAME
appserviceid=$(ynh_app_setting_get --app=$app --key=appserviceid) appserviceid=$(ynh_app_setting_get --app=$app --key=appserviceid)
botname=$(ynh_app_setting_get --app=$app --key=botname) botname=$(ynh_app_setting_get --app=$app --key=botname)
encryption=$(ynh_app_setting_get --app=$app --key=encryption) encryption=$(ynh_app_setting_get --app=$app --key=encryption)
botadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
botusers=$(ynh_app_setting_get --app=$app --key=botusers)
domain=$(ynh_app_setting_get --app=$app --key=domain) domain=$(ynh_app_setting_get --app=$app --key=domain)
final_path=$(ynh_app_setting_get --app=$app --key=final_path) final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name) db_name=$(ynh_app_setting_get --app=$app --key=db_name)
@ -32,6 +30,32 @@ server_name=$(ynh_app_setting_get --app=$app --key=server_name)
synapse_db_name="matrix_$synapse_instance" synapse_db_name="matrix_$synapse_instance"
bot_synapse_db_user="@$botname:$server_name" bot_synapse_db_user="@$botname:$server_name"
#=================================================
# GET CONFIG PANEL SETTINGS
#=================================================
async_media=$(ynh_app_setting_get --app=$app --key=async_media)
displayname=$(ynh_app_setting_get --app=$app --key=displayname)
avatar=$(ynh_app_setting_get --app=$app --key=avatar)
ephemeral_events=$(ynh_app_setting_get --app=$app --key=ephemeral_events)
enable_metrics=$(ynh_app_setting_get --app=$app --key=enable_metrics)
listen_port=$(ynh_app_setting_get --app=$app --key=listen_port)
os_name=$(ynh_app_setting_get --app=$app --key=os_name)
browser_name=$(ynh_app_setting_get --app=$app --key=browser_name)
username_template=$(ynh_app_setting_get --app=$app --key=username_template)
personal_filtering_spaces=$(ynh_app_setting_get --app=$app --key=personal_filtering_spaces)
delivery_receipts=$(ynh_app_setting_get --app=$app --key=delivery_receipts)
send_presence_on_typing=$(ynh_app_setting_get --app=$app --key=send_presence_on_typing)
url_previews=$(ynh_app_setting_get --app=$app --key=url_previews)
encryption_default=$(ynh_app_setting_get --app=$app --key=encryption_default)
encryption_require=$(ynh_app_setting_get --app=$app --key=encryption_require)
enable_relaybot=$(ynh_app_setting_get --app=$app --key=enable_relaybot)
admin_only=$(ynh_app_setting_get --app=$app --key=admin_only)
print_level=$(ynh_app_setting_get --app=$app --key=print_level)
listrelay=$(ynh_app_setting_get --app=$app --key=listrelay)
listuser=$(ynh_app_setting_get --app=$app --key=listuser)
listadmin=$(ynh_app_setting_get --app=$app --key=listadmin)
#================================================= #=================================================
# CHECK VERSION # CHECK VERSION
#================================================= #=================================================
@ -67,21 +91,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app
#================================================= #=================================================
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
# Migration from <=1.10.0 to >0.2.1 # DB Backup missing because of wrong Upgrade from <=0.2.0
ynh_secure_remove --file="$final_path"/community.go
ynh_secure_remove --file="$final_path"/database/upgrades/2019-05-23-protoupgrade.go
ynh_secure_remove --file="$final_path"/database/upgrades/2019-05-16-message-delete-cascade.go
src_path="$final_path"_src
ynh_secure_remove --file="$src_path"
src_path="$final_path"/src
ynh_secure_remove --file="$src_path"
# Upgrade from >0.2.0
botname=$(ynh_app_setting_get --app=$app --key=botname)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd)
# Upgrade from <=0.2.0
if [ -z "$botname" ] if [ -z "$botname" ]
then then
botname=$(ynh_app_setting_get --app=$app --key=whatsappbot) botname=$(ynh_app_setting_get --app=$app --key=whatsappbot)
@ -89,7 +99,7 @@ then
fi fi
if [ -z "$db_name" ] if [ -z "$db_name" ]
then then
db_name=$(ynh_app_setting_get --app=$app --key=$app) db_name=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_name)
ynh_app_setting_set --app=$app --key=db_name --value=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name
fi fi
if [ -z "$db_pwd" ] if [ -z "$db_pwd" ]
@ -97,26 +107,126 @@ then
db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_pwd) db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_pwd)
ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd
fi fi
ynh_app_setting_delete --app=$app --key=whatsappbot
ynh_app_setting_delete --app=$app --key=mautrix_whatsapp_db_name
ynh_app_setting_delete --app=$app --key=mautrix_whatsapp_db_pwd
# If appserviceid doesn't exist, create it # SET STANDARD SETTINGS FROM DEFAULT CONFIG
if [ -z "$appserviceid" ]
if [ -z "$async_media" ]
then then
appserviceid=$app async_media="false"
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid ynh_app_setting_set --app=$app --key=async_media --value=$async_media
fi
if [ -z "$displayname" ]
then
displayname="WhatsApp bridge bot"
ynh_app_setting_set --app=$app --key=displayname --value=$displayname
fi
if [ -z "$avatar" ]
then
avatar="mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr"
ynh_app_setting_set --app=$app --key=avatar --value=$avatar
fi
if [ -z "$ephemeral_events" ]
then
ephemeral_events="true"
ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events
fi
if [ -z "$enable_metrics" ]
then
enable_metrics="false"
ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics
fi
if [ -z "$listen_port" ]
then
listen_port="127.0.0.1:8001"
ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port
fi
if [ -z "$os_name" ]
then
os_name="Mautrix-WhatsApp bridge"
ynh_app_setting_set --app=$app --key=os_name --value=$os_name
fi
if [ -z "$browser_name" ]
then
browser_name="unknown"
ynh_app_setting_set --app=$app --key=browser_name --value=$browser_name
fi
if [ -z "$username_template" ]
then
username_template="whatsapp_{{.}}"
ynh_app_setting_set --app=$app --key=username_template --value=$username_template
fi
if [ -z "$personal_filtering_spaces" ]
then
personal_filtering_spaces="false"
ynh_app_setting_set --app=$app --key=personal_filtering_spaces --value=$personal_filtering_spaces
fi
if [ -z "$delivery_receipts" ]
then
delivery_receipts="false"
ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts
fi
if [ -z "$send_presence_on_typing" ]
then
send_presence_on_typing="false"
ynh_app_setting_set --app=$app --key=send_presence_on_typing --value=$send_presence_on_typing
fi
if [ -z "$url_previews" ]
then
url_previews="false"
ynh_app_setting_set --app=$app --key=url_previews --value=$url_previews
fi
if [ -z "$encryption_default" ]
then
encryption_default="false"
ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default
fi
if [ -z "$encryption_require" ]
then
encryption_require="false"
ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require
fi
if [ -z "$enable_relaybot" ]
then
enable_relaybot="true"
ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot
fi
if [ -z "$admin_only" ]
then
admin_only="true"
ynh_app_setting_set --app=$app --key=admin_only --value=$admin_only
fi
if [ -z "$print_level" ]
then
print_level="info"
ynh_app_setting_set --app=$app --key=print_level --value=$print_level
fi
if [ -z "$listrelay" ]
then
listrelay="*"
ynh_app_setting_set --app=$app --key=listrelay --value=$listrelay
fi
if [ -z "$enable_relaybot" ]
then
enable_relaybot="true"
ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot
fi fi
if [ -z "$listuser" ]
then
listuser=$(ynh_app_setting_get --app=$app --key=botusers)
ynh_app_setting_set --app=$app --key=listuser --value=$listuser
ynh_app_setting_delete --app=$app --key=botusers
fi
# If db_name doesn't exist, create it if [ -z "$listadmin" ]
#if [ -z "$mautrix_whatsapp_db_name" ]; then then
# mautrix_whatsapp_db_name=$(ynh_sanitize_dbid --db_name=$app) listadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
# ynh_app_setting_set --app=$app --key=db_name --value=$mautrix_whatsapp_db_name ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin
#fi ynh_app_setting_delete --app=$app --key=botadmin
fi
# If final_path doesn't exist, create it
#if [ -z "$final_path" ]; then
# final_path=/opt/yunohost/$app
# ynh_app_setting_set --app=$app --key=final_path --value=$final_path
#fi
#================================================= #=================================================
# CREATE DEDICATED USER # CREATE DEDICATED USER
@ -161,11 +271,28 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#================================================= #=================================================
ynh_script_progression --message="Updating a configuration file..." --weight=2 ynh_script_progression --message="Updating a configuration file..." --weight=2
# reset permissions to be able to apply_permissions with app_setting values after upgrade
listrelay_=$listrelay
listuser_=$listuser
listadmin_=$listadmin
listrelay="*"
listuser="@user:domain.tld"
listadmin="@admin:domain.tld"
ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml" ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml"
chmod 400 "$final_path/config.yaml" chmod 400 "$final_path/config.yaml"
chown $app:$app "$final_path/config.yaml" chown $app:$app "$final_path/config.yaml"
listrelay=$listrelay_
listuser=$listuser_
listadmin=$listadmin_
# MIGRATION from previous version without config panel -> config panel does not exist yet, so we upgrade the config after starting the systemd service
# apply_permissions to have correct syntax in config file
#yunohost app config set $app main.permissions.listrelay -v "$listrelay"
#yunohost app config set $app main.permissions.listuser -v "$listuser"
#yunohost app config set $app main.permissions.listadmin -v "$listadmin"
#================================================= #=================================================
# REGISTER SYNAPSE APP-SERVICE # REGISTER SYNAPSE APP-SERVICE
#================================================= #=================================================
@ -215,6 +342,12 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1
# Start a systemd service # Start a systemd service
ynh_systemd_action --service_name=$app --action="start" ynh_systemd_action --service_name=$app --action="start"
# MIGRATION from previous version without config panel -> config panel does not exist yet, so we upgrade the config after starting the systemd service
# apply_permissions to have correct syntax in config file
yunohost app config set $app main.permissions.listrelay -v "$listrelay"
yunohost app config set $app main.permissions.listuser -v "$listuser"
yunohost app config set $app main.permissions.listadmin -v "$listadmin"
#================================================= #=================================================
# END OF SCRIPT # END OF SCRIPT
#================================================= #=================================================