mirror of
https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git
synced 2024-09-03 19:46:01 +02:00
Add config panel with few config options and user management
This commit is contained in:
parent
845d0f9a57
commit
dac54950af
3 changed files with 207 additions and 0 deletions
111
config_panel.toml
Normal file
111
config_panel.toml
Normal file
|
@ -0,0 +1,111 @@
|
|||
version = "1.0"
|
||||
|
||||
[main]
|
||||
name = "General configuration"
|
||||
services = ["__APP__"]
|
||||
|
||||
[main.config]
|
||||
name = "Configuration options"
|
||||
|
||||
[main.config.botname]
|
||||
ask = "Set a bot name for the bridge puppet"
|
||||
type = "string"
|
||||
help = "Sets bot username. Please keep in mind that the bot admin room for previous bot username will stop working so you may need to create a new one using the new username"
|
||||
|
||||
[main.config.log_level]
|
||||
ask = "Sets log level of the application"
|
||||
choices = ["debug", "info", "warn", "error", "fatal"]
|
||||
default = "info"
|
||||
bind = "logging>print_level:__FINALPATH__/config.yaml"
|
||||
|
||||
[encryption]
|
||||
name = "Encryption"
|
||||
services = ["__APP__"]
|
||||
[encryption.config]
|
||||
name = "Encryption settings"
|
||||
|
||||
[encryption.config.encryption]
|
||||
ask = "Enable encryption"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Enables end to bridge encryption"
|
||||
bind = "encryption>allow:__FINALPATH__/config.yaml"
|
||||
|
||||
[encryption.config.default_encryption]
|
||||
ask = "Default encryption"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Force-enable encryption in all portals the bridge creates. This will cause the bridge bot to be in private chats for the encryption to work properly."
|
||||
bind = "encryption>default:__FINALPATH__/config.yaml"
|
||||
|
||||
[encryption.config.require_encryption]
|
||||
ask = "Require encryption"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Require encryption, drop any unencrypted messages."
|
||||
bind = "encryption>require:__FINALPATH__/config.yaml"
|
||||
|
||||
[usermanagement]
|
||||
name = "User management"
|
||||
services = ["__APP__"]
|
||||
|
||||
[usermanagement.config]
|
||||
name = "User management"
|
||||
|
||||
[usermanagement.config.helptext]
|
||||
ask = "Allowed values:\n  * - All Matrix users\n  domain - All users on that homeserver\n  mxid (@user:matrix.org) - Specific Matrix user\n  username - Specific local user"
|
||||
type = "markdown"
|
||||
|
||||
[usermanagement.config.listuser]
|
||||
ask = "Users"
|
||||
type = "tags"
|
||||
visible = "role == 'user'"
|
||||
|
||||
[usermanagement.config.listadmin]
|
||||
ask = "Admins"
|
||||
type = "tags"
|
||||
visible = "role == 'admin'"
|
||||
|
||||
[usermanagement.config.listrelay]
|
||||
ask = "Relay users"
|
||||
type = "tags"
|
||||
visible = "role == 'relay'"
|
||||
|
||||
[usermanagement.config.role]
|
||||
ask = "Role"
|
||||
type = "select"
|
||||
choices = ["user", "admin", "relay"]
|
||||
|
||||
[privacy]
|
||||
name = "Privacy"
|
||||
services = ["__APP__"]
|
||||
|
||||
[privacy.config]
|
||||
name = "Privacy settings"
|
||||
|
||||
[privacy.config.delivery_receipts]
|
||||
ask = "Delivery receipts"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Should the bridge send a read receipt from the bridge bot when a message has been sent to WhatsApp?"
|
||||
bind = "bridge>delivery_receipts:__FINALPATH__/config.yaml"
|
||||
|
||||
[privacy.config.send_presence_on_typing]
|
||||
ask = "Send presence on typing"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Send the presence as 'available' to whatsapp when users start typing on a portal."
|
||||
bind = "bridge>send_presence_on_typing:__FINALPATH__/config.yaml"
|
||||
|
||||
[privacy.config.url_previews]
|
||||
ask = "URL previews"
|
||||
type = "boolean"
|
||||
yes = "true"
|
||||
no = "false"
|
||||
help = "Should the bridge detect URLs in outgoing messages, ask the homeserver to generate a preview, and send it to WhatsApp?"
|
||||
bind = "bridge>url_previews:__FINALPATH__/config.yaml"
|
92
scripts/config
Normal file
92
scripts/config
Normal file
|
@ -0,0 +1,92 @@
|
|||
#!/bin/bash
|
||||
source /usr/share/yunohost/helpers
|
||||
ynh_abort_if_errors
|
||||
|
||||
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
||||
|
||||
function get__encryption {
|
||||
encryption=$(ynh_app_setting_get --app $app --key encryption)
|
||||
echo "'${encryption}'"
|
||||
}
|
||||
|
||||
function get__botname {
|
||||
botname=$(ynh_app_setting_get --app $app --key botname)
|
||||
echo "${botname}"
|
||||
}
|
||||
|
||||
function set__botname {
|
||||
old_botname=$(ynh_app_setting_get --app $app --key botname)
|
||||
if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed.
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
ynh_app_setting_set --app=$app --key=botname --value="$botname"
|
||||
synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance)
|
||||
|
||||
sed -i "s/username:.*/username: $botname/" "$final_path/config.yaml"
|
||||
"$final_path/mautrix-whatsapp" -g -c "$final_path/config.yaml" -r "/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||
"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die --message="Synapse can't restart with the appservice configuration"
|
||||
chown -R "$app:$app" "$final_path"
|
||||
ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml"
|
||||
ynh_store_file_checksum --file="$final_path/config.yaml"
|
||||
}
|
||||
|
||||
function get__listuser {
|
||||
existingUsers=$(grep -- "\".*: user" "$final_path/config.yaml" | sed -r 's/: user//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
value: '$existingUsers'
|
||||
EOF
|
||||
}
|
||||
|
||||
function get__listrelay {
|
||||
existingRelayUsers=$(grep -- "\".*: relay" "$final_path/config.yaml" | sed -r 's/: relay//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
value: '$existingRelayUsers'
|
||||
EOF
|
||||
}
|
||||
|
||||
function get__listadmin {
|
||||
existingAdmins=$(grep -- "\".*: admin" "$final_path/config.yaml" | sed -r 's/: admin//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr '\n' ',')
|
||||
|
||||
cat <<EOF
|
||||
value: '$existingAdmins'
|
||||
EOF
|
||||
}
|
||||
|
||||
function get__role {
|
||||
cat <<EOF
|
||||
choices: ["admin", "user", "relay"]
|
||||
default: "user"
|
||||
EOF
|
||||
}
|
||||
|
||||
function set__role {
|
||||
declare values="list$role"
|
||||
newValues="${!values}" # Here we expand the dynamic variable we created in the previous line. ! Does the trick
|
||||
usersArray=(${newValues//,/ }) # Split the values using comma (,) as separator.
|
||||
|
||||
if [ -n "${!values}" ]
|
||||
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 -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 echo "$allDefinedEntries" | grep -q -E "^${user}$"
|
||||
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
|
||||
|
||||
ynh_print_info "Users with role $role added in $final_path/config.yaml"
|
||||
}
|
||||
|
||||
ynh_app_config_run $1
|
|
@ -57,6 +57,10 @@ ynh_script_progression --message="Validating installation parameters..." --weigh
|
|||
final_path=/opt/yunohost/$app
|
||||
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
|
||||
|
||||
if [ $encryption -eq 1 ]; then
|
||||
encryption="true"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# STORE SETTINGS FROM MANIFEST
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue