2021-11-07 21:31:22 +01:00
|
|
|
// mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
|
2022-02-23 13:30:21 +01:00
|
|
|
// Copyright (C) 2022 Tulir Asokan
|
2021-11-07 21:31:22 +01:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-03-01 19:39:05 +01:00
|
|
|
"strings"
|
2021-11-07 21:31:22 +01:00
|
|
|
|
2022-05-22 00:06:30 +02:00
|
|
|
"maunium.net/go/mautrix/bridge/bridgeconfig"
|
2022-08-04 19:42:03 +02:00
|
|
|
"maunium.net/go/mautrix/util"
|
2022-05-21 11:06:07 +02:00
|
|
|
up "maunium.net/go/mautrix/util/configupgrade"
|
2021-11-07 21:31:22 +01:00
|
|
|
)
|
|
|
|
|
2022-05-22 00:06:30 +02:00
|
|
|
func DoUpgrade(helper *up.Helper) {
|
|
|
|
bridgeconfig.Upgrader.DoUpgrade(helper)
|
2022-05-21 11:06:07 +02:00
|
|
|
|
|
|
|
helper.Copy(up.Str|up.Null, "segment_key")
|
2023-02-01 03:35:31 +01:00
|
|
|
helper.Copy(up.Str|up.Null, "segment_user_id")
|
2022-05-21 11:06:07 +02:00
|
|
|
|
|
|
|
helper.Copy(up.Bool, "metrics", "enabled")
|
|
|
|
helper.Copy(up.Str, "metrics", "listen")
|
|
|
|
|
|
|
|
helper.Copy(up.Str, "whatsapp", "os_name")
|
|
|
|
helper.Copy(up.Str, "whatsapp", "browser_name")
|
|
|
|
|
|
|
|
helper.Copy(up.Str, "bridge", "username_template")
|
|
|
|
helper.Copy(up.Str, "bridge", "displayname_template")
|
|
|
|
helper.Copy(up.Bool, "bridge", "personal_filtering_spaces")
|
|
|
|
helper.Copy(up.Bool, "bridge", "delivery_receipts")
|
2022-05-31 16:28:58 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "message_status_events")
|
|
|
|
helper.Copy(up.Bool, "bridge", "message_error_notices")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Int, "bridge", "portal_message_buffer")
|
|
|
|
helper.Copy(up.Bool, "bridge", "call_start_notices")
|
|
|
|
helper.Copy(up.Bool, "bridge", "identity_change_notices")
|
|
|
|
helper.Copy(up.Bool, "bridge", "history_sync", "create_portals")
|
|
|
|
helper.Copy(up.Bool, "bridge", "history_sync", "backfill")
|
|
|
|
helper.Copy(up.Bool, "bridge", "history_sync", "double_puppet_backfill")
|
|
|
|
helper.Copy(up.Bool, "bridge", "history_sync", "request_full_sync")
|
2023-01-04 21:37:25 +01:00
|
|
|
helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "days_limit")
|
|
|
|
helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "size_mb_limit")
|
|
|
|
helper.Copy(up.Int|up.Null, "bridge", "history_sync", "full_sync_config", "storage_quota_mb")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "history_sync", "media_requests", "auto_request_media")
|
|
|
|
helper.Copy(up.Str, "bridge", "history_sync", "media_requests", "request_method")
|
|
|
|
helper.Copy(up.Int, "bridge", "history_sync", "media_requests", "request_local_time")
|
|
|
|
helper.Copy(up.Int, "bridge", "history_sync", "max_initial_conversations")
|
2022-10-12 21:32:48 +02:00
|
|
|
helper.Copy(up.Int, "bridge", "history_sync", "unread_hours_threshold")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Int, "bridge", "history_sync", "immediate", "worker_count")
|
|
|
|
helper.Copy(up.Int, "bridge", "history_sync", "immediate", "max_events")
|
|
|
|
helper.Copy(up.List, "bridge", "history_sync", "deferred")
|
|
|
|
helper.Copy(up.Bool, "bridge", "user_avatar_sync")
|
|
|
|
helper.Copy(up.Bool, "bridge", "bridge_matrix_leave")
|
|
|
|
helper.Copy(up.Bool, "bridge", "sync_with_custom_puppets")
|
|
|
|
helper.Copy(up.Bool, "bridge", "sync_direct_chat_list")
|
|
|
|
helper.Copy(up.Bool, "bridge", "default_bridge_receipts")
|
|
|
|
helper.Copy(up.Bool, "bridge", "default_bridge_presence")
|
|
|
|
helper.Copy(up.Bool, "bridge", "send_presence_on_typing")
|
|
|
|
helper.Copy(up.Bool, "bridge", "force_active_delivery_receipts")
|
|
|
|
helper.Copy(up.Map, "bridge", "double_puppet_server_map")
|
|
|
|
helper.Copy(up.Bool, "bridge", "double_puppet_allow_discovery")
|
|
|
|
if legacySecret, ok := helper.Get(up.Str, "bridge", "login_shared_secret"); ok && len(legacySecret) > 0 {
|
2021-11-07 21:31:22 +01:00
|
|
|
baseNode := helper.GetBaseNode("bridge", "login_shared_secret_map")
|
2022-05-21 11:06:07 +02:00
|
|
|
baseNode.Map[helper.GetBase("homeserver", "domain")] = up.StringNode(legacySecret)
|
|
|
|
baseNode.UpdateContent()
|
2021-11-07 21:31:22 +01:00
|
|
|
} else {
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Map, "bridge", "login_shared_secret_map")
|
2021-11-07 21:31:22 +01:00
|
|
|
}
|
2023-04-14 12:40:34 +02:00
|
|
|
if legacyPrivateChatPortalMeta, ok := helper.Get(up.Bool, "bridge", "private_chat_portal_meta"); ok {
|
|
|
|
updatedPrivateChatPortalMeta := "default"
|
|
|
|
if legacyPrivateChatPortalMeta == "true" {
|
|
|
|
updatedPrivateChatPortalMeta = "always"
|
|
|
|
}
|
|
|
|
helper.Set(up.Str, updatedPrivateChatPortalMeta, "bridge", "private_chat_portal_meta")
|
|
|
|
} else {
|
|
|
|
helper.Copy(up.Str, "bridge", "private_chat_portal_meta")
|
|
|
|
}
|
2022-09-29 13:39:58 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "parallel_member_sync")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "bridge_notices")
|
|
|
|
helper.Copy(up.Bool, "bridge", "resend_bridge_info")
|
|
|
|
helper.Copy(up.Bool, "bridge", "mute_bridging")
|
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "archive_tag")
|
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "pinned_tag")
|
|
|
|
helper.Copy(up.Bool, "bridge", "tag_only_on_create")
|
|
|
|
helper.Copy(up.Bool, "bridge", "enable_status_broadcast")
|
2022-06-13 19:01:39 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "disable_status_broadcast_send")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "mute_status_broadcast")
|
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "status_broadcast_tag")
|
|
|
|
helper.Copy(up.Bool, "bridge", "whatsapp_thumbnail")
|
|
|
|
helper.Copy(up.Bool, "bridge", "allow_user_invite")
|
|
|
|
helper.Copy(up.Str, "bridge", "command_prefix")
|
|
|
|
helper.Copy(up.Bool, "bridge", "federate_rooms")
|
|
|
|
helper.Copy(up.Bool, "bridge", "disable_bridge_alerts")
|
2022-09-06 21:38:47 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "crash_on_stream_replaced")
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "url_previews")
|
2022-06-17 10:34:24 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "caption_in_message")
|
2022-11-26 17:53:08 +01:00
|
|
|
if intPolls, ok := helper.Get(up.Int, "bridge", "extev_polls"); ok {
|
|
|
|
val := "false"
|
|
|
|
if intPolls != "0" {
|
|
|
|
val = "true"
|
|
|
|
}
|
|
|
|
helper.Set(up.Bool, val, "bridge", "extev_polls")
|
|
|
|
} else {
|
|
|
|
helper.Copy(up.Bool, "bridge", "extev_polls")
|
|
|
|
}
|
2023-03-08 16:14:31 +01:00
|
|
|
helper.Copy(up.Bool, "bridge", "cross_room_replies")
|
2023-04-19 16:26:21 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "disable_reply_fallbacks")
|
2022-06-30 13:41:37 +02:00
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "error_after")
|
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "message_handling_timeout", "deadline")
|
2022-06-29 19:05:55 +02:00
|
|
|
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome")
|
|
|
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_connected")
|
|
|
|
helper.Copy(up.Str, "bridge", "management_room_text", "welcome_unconnected")
|
|
|
|
helper.Copy(up.Str|up.Null, "bridge", "management_room_text", "additional_help")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "allow")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "default")
|
2022-06-22 19:09:21 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "require")
|
2022-08-25 10:59:09 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "appservice")
|
2023-03-02 12:54:27 +01:00
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "plaintext_mentions")
|
2023-04-13 16:09:44 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_outbound_on_ack")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "dont_store_outbound")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "ratchet_on_decrypt")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_fully_used_on_decrypt")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_prev_on_new_session")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "delete_on_device_delete")
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "delete_keys", "periodically_delete_expired")
|
2022-06-22 19:09:21 +02:00
|
|
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "receive")
|
|
|
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "send")
|
|
|
|
helper.Copy(up.Str, "bridge", "encryption", "verification_levels", "share")
|
|
|
|
|
|
|
|
legacyKeyShareAllow, ok := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "allow")
|
|
|
|
if ok {
|
|
|
|
helper.Set(up.Bool, legacyKeyShareAllow, "bridge", "encryption", "allow_key_sharing")
|
|
|
|
legacyKeyShareRequireCS, legacyOK1 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_cross_signing")
|
|
|
|
legacyKeyShareRequireVerification, legacyOK2 := helper.Get(up.Bool, "bridge", "encryption", "key_sharing", "require_verification")
|
|
|
|
if legacyOK1 && legacyOK2 && legacyKeyShareRequireVerification == "false" && legacyKeyShareRequireCS == "false" {
|
|
|
|
helper.Set(up.Str, "unverified", "bridge", "encryption", "verification_levels", "share")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "allow_key_sharing")
|
|
|
|
}
|
|
|
|
|
2022-06-21 19:57:08 +02:00
|
|
|
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
|
|
|
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
|
|
|
|
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
|
2022-05-22 00:06:30 +02:00
|
|
|
if prefix, ok := helper.Get(up.Str, "appservice", "provisioning", "prefix"); ok {
|
|
|
|
helper.Set(up.Str, strings.TrimSuffix(prefix, "/v1"), "bridge", "provisioning", "prefix")
|
|
|
|
} else {
|
|
|
|
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
|
|
|
|
}
|
|
|
|
if secret, ok := helper.Get(up.Str, "appservice", "provisioning", "shared_secret"); ok && secret != "generate" {
|
|
|
|
helper.Set(up.Str, secret, "bridge", "provisioning", "shared_secret")
|
|
|
|
} else if secret, ok = helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {
|
2022-08-04 19:42:03 +02:00
|
|
|
sharedSecret := util.RandomString(64)
|
2022-05-22 00:06:30 +02:00
|
|
|
helper.Set(up.Str, sharedSecret, "bridge", "provisioning", "shared_secret")
|
|
|
|
} else {
|
|
|
|
helper.Copy(up.Str, "bridge", "provisioning", "shared_secret")
|
|
|
|
}
|
2022-05-21 11:06:07 +02:00
|
|
|
helper.Copy(up.Map, "bridge", "permissions")
|
|
|
|
helper.Copy(up.Bool, "bridge", "relay", "enabled")
|
|
|
|
helper.Copy(up.Bool, "bridge", "relay", "admin_only")
|
|
|
|
helper.Copy(up.Map, "bridge", "relay", "message_formats")
|
2021-11-15 13:21:43 +01:00
|
|
|
}
|
|
|
|
|
2022-05-22 00:06:30 +02:00
|
|
|
var SpacedBlocks = [][]string{
|
2022-08-25 11:04:42 +02:00
|
|
|
{"homeserver", "software"},
|
2022-05-22 00:06:30 +02:00
|
|
|
{"appservice"},
|
|
|
|
{"appservice", "hostname"},
|
|
|
|
{"appservice", "database"},
|
|
|
|
{"appservice", "id"},
|
|
|
|
{"appservice", "as_token"},
|
|
|
|
{"segment_key"},
|
|
|
|
{"metrics"},
|
|
|
|
{"whatsapp"},
|
|
|
|
{"bridge"},
|
|
|
|
{"bridge", "command_prefix"},
|
|
|
|
{"bridge", "management_room_text"},
|
|
|
|
{"bridge", "encryption"},
|
|
|
|
{"bridge", "provisioning"},
|
|
|
|
{"bridge", "permissions"},
|
|
|
|
{"bridge", "relay"},
|
|
|
|
{"logging"},
|
2021-11-07 21:31:22 +01:00
|
|
|
}
|