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 #87 from YunoHost-Apps/testing

Add config panel and upgrade to 0.8.1
This commit is contained in:
Dante 2023-02-28 20:07:50 +00:00 committed by GitHub
commit 16735d0c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 608 additions and 97 deletions

View file

@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch the source code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the updater script
@ -33,7 +33,7 @@ jobs:
- name: Create Pull Request
id: cpr
if: ${{ env.PROCEED == 'true' }}
uses: peter-evans/create-pull-request@v3
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Update to version ${{ env.VERSION }}

View file

@ -5,7 +5,8 @@ It shall NOT be edited by hand.
# 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)
*[Lire ce readme en français.](./README_fr.md)*
@ -24,7 +25,7 @@ Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh)
** Attention: always backup and restore the Yunohost matrix_synapse et mautrix_whatsapp apps together!**
**Shipped version:** 0.8.0~ynh1
**Shipped version:** 0.8.1~ynh1
## Disclaimers / important information
## List of known public services

View file

@ -5,7 +5,8 @@ It shall NOT be edited by hand.
# Matrix-WhatsApp bridge pour YunoHost
[![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)
[![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)
*[Read this readme in english.](./README.md)*
@ -24,7 +25,7 @@ C'est pourquoi [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_y
** Attention : sauvegardez et restaurez toujours les deux applications Yunohost matrix_synapse et mautrix_whatsapp en même temps!**
**Version incluse :** 0.8.0~ynh1
**Version incluse :** 0.8.1~ynh1
## Avertissements / informations importantes
## Liste de passerelles publiques

View file

@ -17,17 +17,17 @@
setup_private=0
setup_public=0
upgrade=1
# 0.3.0
upgrade=1 from_commit=42df5b910927283241e185dcb8a62089adeb9c85
# 0.2.4
upgrade=1 from_commit=23cd51919e2b09865256a21214865d798bd843f6
# 0.4.0
upgrade=1 from_commit=717b32f454819c1bb936152c69d9693d34434741
# 0.6.1
upgrade=1 from_commit=fdd1e0ff652ae47b5e3c62477eea678c465659cf
backup_restore=1
multi_instance=1
;;; Options
Email=
Notification=none
;;; Upgrade options
; commit=42df5b910927283241e185dcb8a62089adeb9c85
name=0.3.0
; commit=23cd51919e2b09865256a21214865d798bd843f6
name=0.2.4
; commit=717b32f454819c1bb936152c69d9693d34434741
name=0.4.0
; commit=fdd1e0ff652ae47b5e3c62477eea678c465659cf
name=0.6.1

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.0/mautrix-whatsapp-amd64
SOURCE_SUM=b7fcef1d665c08fb3fd0c24f65ab179aeef24d1558ef539374887f635bcd7c0e
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.1/mautrix-whatsapp-amd64
SOURCE_SUM=d50af9a4c65593bff3bb3a10382567505cde79929856304f35ae083066955d55
SOURCE_SUM_PRG=sha256sum
SOURCE_IN_SUBDIR=false
SOURCE_FILENAME=mautrix-whatsapp

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.0/mautrix-whatsapp-arm64
SOURCE_SUM=389f126bb25ad0d8173a761f59a731a351eb02f1d95478cc5e3e2af1ff97b1c3
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.1/mautrix-whatsapp-arm64
SOURCE_SUM=49e1b5308fd8b90e0871b27aa2febc324fbd78c175815312865b54102d04c966
SOURCE_SUM_PRG=sha256sum
SOURCE_IN_SUBDIR=false
SOURCE_FILENAME=mautrix-whatsapp

View file

@ -1,5 +1,5 @@
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.0/mautrix-whatsapp-arm
SOURCE_SUM=5ebe0488106ed1377a76380639a41eca473eafb3b8f24396005a2999a350de46
SOURCE_URL=https://github.com/mautrix/whatsapp/releases/download/v0.8.1/mautrix-whatsapp-arm
SOURCE_SUM=5f734a40793fc7223b6e15d781f02fae222507c125d12995a85bbb79e1e4370d
SOURCE_SUM_PRG=sha256sum
SOURCE_IN_SUBDIR=false
SOURCE_FILENAME=mautrix-whatsapp

View file

@ -15,7 +15,7 @@ homeserver:
# Endpoint for reporting per-message status.
message_send_checkpoint_endpoint: null
# 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.
# Changing these values requires regeneration of the registration.
@ -56,13 +56,13 @@ appservice:
username: __BOTNAME__
# Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty
# to leave display name/avatar as-is.
displayname: WhatsApp bridge bot
avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr
displayname: __DISPLAYNAME__
avatar: __AVATAR__
# Whether or not to receive ephemeral events via appservice transactions.
# Requires MSC2409 support (i.e. Synapse 1.22+).
# 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?
# This may be necessary for large public instances with lots of messages going through.
@ -79,24 +79,24 @@ segment_key: null
# Prometheus config.
metrics:
# Enable prometheus metrics?
enabled: false
enabled: __ENABLE_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.
whatsapp:
# 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.
# 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
browser_name: unknown
browser_name: __BROWSER_NAME__
# Bridge config
bridge:
# Localpart template of MXIDs for WhatsApp users.
# {{.}} is replaced with the phone number of the WhatsApp user.
username_template: whatsapp_{{.}}
username_template: __USERNAME_TEMPLATE__
# Displayname template for WhatsApp users.
# {{.PushName}} - nickname set by the WhatsApp user
# {{.BusinessName}} - validated WhatsApp business name
@ -107,9 +107,9 @@ bridge:
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?
# 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?
delivery_receipts: false
delivery_receipts: __DELIVERY_RECEIPTS__
# Whether the bridge should send the message status as a custom com.beeper.message_send_status event.
message_status_events: false
# Whether the bridge should send error notices via m.notice events when a message fails to bridge.
@ -137,6 +137,16 @@ bridge:
# Should the bridge request a full sync from the phone when logging in?
# This bumps the size of history syncs from 3 months to 1 year.
request_full_sync: false
# Configuration parameters that are sent to the phone along with the request full sync flag.
# By default (when the values are null or 0), the config isn't sent at all.
full_sync_config:
# Number of days of history to request.
# The limit seems to be around 3 years, but using higher values doesn't break.
days_limit: null
# This is presumably the maximum size of the transferred history sync blob, which may affect what the phone includes in the blob.
size_mb_limit: null
# This is presumably the local storage quota, which may affect what the phone includes in the history sync blob.
storage_quota_mb: null
# Settings for media requests. If the media expired, then it will not
# be on the WA servers.
# Media can always be requested by reacting with the ♻️ (recycle) emoji.
@ -226,7 +236,7 @@ bridge:
# 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
# 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)
# even if the user isn't marked as online (e.g. when presence bridging isn't enabled)?
#
@ -298,7 +308,7 @@ bridge:
# 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`
# 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.
# This is currently not supported in most clients.
caption_in_message: false
@ -342,11 +352,11 @@ bridge:
# 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.
# 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.
appservice: false
# 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.
# You must use a client that supports requesting keys from other users to use this feature.
allow_key_sharing: false
@ -403,20 +413,18 @@ bridge:
# domain - All users on that homeserver
# mxid - Specific user
permissions:
"*": relay
#"example.com": user
"__BOTUSERS__": user
#"@admin:example.com": admin
"__BOTADMIN__": admin
"__LISTRELAY__": relay
"__LISTUSER__": user
"__LISTADMIN__": admin
# Settings for relay mode
relay:
# 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.
#enabled: false
enabled: true
enabled: __ENABLE_RELAYBOT__
# 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.
message_formats:
m.text: "<b>{{ .Sender.Displayname }}</b>: {{ .Message }}"
@ -445,4 +453,4 @@ logging:
timestamp_format: "Jan _2, 2006 15:04:05"
# Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file.
# 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

@ -6,7 +6,7 @@
"en": "Matrix / Synapse puppeting bridge for WhatsApp",
"fr": "Passerelle Matrix / Synapse pour WhatsApp"
},
"version": "0.8.0~ynh1",
"version": "0.8.1~ynh1",
"url": "https://github.com/mautrix/whatsapp",
"upstream": {
"license": "AGPL-3.0-or-later",
@ -104,11 +104,11 @@
"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."
},
"example": "admin or domain or @johndoe:server.name or server.name or *",
"default": "domain",
"example": "local or @johndoe:server.name or server.name or *",
"default": "local",
"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.",
"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."
"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": "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."
}
}
]

View file

@ -8,13 +8,57 @@
pkg_dependencies="g++ postgresql ffmpeg"
#=================================================
# PERSONAL HELPERS
# CONFIG PANEL SETTERS
#=================================================
#=================================================
# EXPERIMENTAL HELPERS
#=================================================
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.
#=================================================
# FUTURE OFFICIAL HELPERS
#=================================================
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__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"
}

67
scripts/config Normal file
View file

@ -0,0 +1,67 @@
#!/bin/bash
source _common.sh
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
#=================================================
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"
}
ynh_app_config_run $1

View file

@ -28,16 +28,11 @@ synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER
botname=$YNH_APP_ARG_BOTNAME
bot_synapse_adm=$YNH_APP_ARG_BOT_SYNAPSE_ADM
encryption=$YNH_APP_ARG_ENCRYPTION
botadmin=$YNH_APP_ARG_BOTADMIN
botusers=$YNH_APP_ARG_BOTUSERS
listadmin=$YNH_APP_ARG_BOTADMIN
listuser=$YNH_APP_ARG_BOTUSERS
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
if [ $synapsenumber -eq "1" ]
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)
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
#=================================================
@ -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=bot_synapse_adm --value=$bot_synapse_adm
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=botusers --value=$botusers
ynh_app_setting_set --app=$app --key=listuser --value=$listuser
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=server_name --value=$server_name
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"
# Wait until the synapse user is created
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 ]
then
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)
botname=$(ynh_app_setting_get --app=$app --key=botname)
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)
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
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"
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
#=================================================
@ -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
# Migration from <=1.10.0 to >0.2.1
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
# DB Backup missing because of wrong Upgrade from <=0.2.0
if [ -z "$botname" ]
then
botname=$(ynh_app_setting_get --app=$app --key=whatsappbot)
@ -97,26 +107,126 @@ then
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
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
if [ -z "$appserviceid" ]
# SET STANDARD SETTINGS FROM DEFAULT CONFIG
if [ -z "$async_media" ]
then
appserviceid=$app
ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid
async_media="false"
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
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 "$mautrix_whatsapp_db_name" ]; then
# mautrix_whatsapp_db_name=$(ynh_sanitize_dbid --db_name=$app)
# ynh_app_setting_set --app=$app --key=db_name --value=$mautrix_whatsapp_db_name
#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
if [ -z "$listadmin" ]
then
listadmin=$(ynh_app_setting_get --app=$app --key=botadmin)
ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin
ynh_app_setting_delete --app=$app --key=botadmin
fi
#=================================================
# 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
# 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"
chmod 400 "$final_path/config.yaml"
chown $app:$app "$final_path/config.yaml"
listrelay=$listrelay_
listuser=$listuser_
listadmin=$listadmin_
# apply_permissions to have correct syntax in config file
set__listuser
set__listrelay
set__listadmin
#=================================================
# REGISTER SYNAPSE APP-SERVICE
#=================================================