From 7b3c6f0c196a6d4adbe594e0c2857c8486ded963 Mon Sep 17 00:00:00 2001 From: hanthor Date: Tue, 11 May 2021 15:18:28 -0400 Subject: [PATCH] Inital work, copeid from mautrix-amp PR --- group_vars/matrix_servers | 46 ++++++ .../defaults/main.yml | 113 +++++++++++++ .../tasks/init.yml | 16 ++ .../tasks/main.yml | 21 +++ .../tasks/setup_install.yml | 115 ++++++++++++++ .../tasks/setup_uninstall.yml | 24 +++ .../tasks/validate_config.yml | 11 ++ .../templates/config.yaml.j2 | 150 ++++++++++++++++++ .../matrix-mautrix-whatsapp.service.j2 | 43 +++++ setup.yml | 1 + 10 files changed, 540 insertions(+) create mode 100644 roles/matrix-bridge-mautrix-wsproxy/defaults/main.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/tasks/init.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/tasks/main.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/tasks/setup_uninstall.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml create mode 100644 roles/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 create mode 100644 roles/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-whatsapp.service.j2 diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 517e69224..713688b50 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -460,6 +460,46 @@ matrix_mautrix_whatsapp_database_password: "{{ matrix_synapse_macaroon_secret_ke # ###################################################################### +###################################################################### +# +# matrix-bridge-mautrix-wsproxy +# +###################################################################### + +# We don't enable bridges by default. +matrix_mautrix_wsproxy_enabled: false + +matrix_mautrix_wsproxy_systemd_required_services_list: | + {{ + ['docker.service'] + + + (['matrix-synapse.service'] if matrix_synapse_enabled else []) + + + (['matrix-postgres.service'] if matrix_postgres_enabled else []) + }} + +matrix_mautrix_wsproxy_homeserver_domain: '{{ matrix_domain }}' + +matrix_mautrix_wsproxy_homeserver_address: "{{ 'http://matrix-synapse:8008' if matrix_synapse_enabled else '' }}" + +matrix_mautrix_wsproxy_homeserver_token: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'wsproxy.hs.token') | to_uuid }}" + +matrix_mautrix_wsproxy_appservice_token: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'wsproxy.as.token') | to_uuid }}" + +matrix_mautrix_wsproxy_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" + +# Postgres is the default, except if not using `matrix_postgres` (internal postgres) +matrix_mautrix_wsproxy_database_engine: "{{ 'postgres' if matrix_postgres_enabled else 'sqlite' }}" +matrix_mautrix_wsproxy_database_password: "{{ matrix_synapse_macaroon_secret_key | password_hash('sha512', 'mauwsproxy.db') | to_uuid }}" + +###################################################################### +# +# /matrix-bridge-mautrix-wsproxy +# +###################################################################### + + + ###################################################################### # # matrix-sms-bridge @@ -1371,6 +1411,12 @@ matrix_postgres_additional_databases: | 'password': matrix_mautrix_whatsapp_database_password, }] if (matrix_mautrix_whatsapp_enabled and matrix_mautrix_whatsapp_database_engine == 'postgres' and matrix_mautrix_whatsapp_database_hostname == 'matrix-postgres') else []) + + ([{ + 'name': matrix_mautrix_wsproxy_database_name, + 'username': matrix_mautrix_wsproxy_database_username, + 'password': matrix_mautrix_wsproxy_database_password, + }] if (matrix_mautrix_wsproxy_enabled and matrix_mautrix_wsproxy_database_engine == 'postgres' and matrix_mautrix_wsproxy_database_hostname == 'matrix-postgres') else []) + + ([{ 'name': matrix_mx_puppet_skype_database_name, 'username': matrix_mx_puppet_skype_database_username, diff --git a/roles/matrix-bridge-mautrix-wsproxy/defaults/main.yml b/roles/matrix-bridge-mautrix-wsproxy/defaults/main.yml new file mode 100644 index 000000000..0ecf65140 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/defaults/main.yml @@ -0,0 +1,113 @@ +# mautrix-wsproxy is a Matrix <-> websocket bridge +# See: https://github.com/tulir/mautrix-wsproxy + +matrix_mautrix_wsproxy_enabled: true + +matrix_mautrix_wsproxy_version: latest +# See: https://mau.dev/tulir/mautrix-wsproxy/container_registry +matrix_mautrix_wsproxy_docker_image: "dock.mau.dev/tulir/mautrix-wsproxy:{{ matrix_mautrix_wsproxy_version }}" +matrix_mautrix_wsproxy_docker_image_force_pull: "{{ matrix_mautrix_wsproxy_docker_image.endswith(':latest') }}" + +matrix_mautrix_wsproxy_base_path: "{{ matrix_base_data_path }}/mautrix-wsproxy" +matrix_mautrix_wsproxy_config_path: "{{ matrix_mautrix_wsproxy_base_path }}/config" + +matrix_mautrix_wsproxy_homeserver_address: "{{ matrix_homeserver_container_url }}" +matrix_mautrix_wsproxy_homeserver_domain: "{{ matrix_domain }}" +matrix_mautrix_wsproxy_appservice_address: "http://matrix-mautrix-wsproxy:8080" + +# A list of extra arguments to pass to the container +matrix_mautrix_wsproxy_container_extra_arguments: [] + +# List of systemd services that matrix-mautrix-wsproxy.service depends on. +matrix_mautrix_wsproxy_systemd_required_services_list: ['docker.service'] + +# List of systemd services that matrix-mautrix-wsproxy.service wants +matrix_mautrix_wsproxy_systemd_wanted_services_list: [] + +matrix_mautrix_wsproxy_appservice_token: '' +matrix_mautrix_wsproxy_homeserver_token: '' + +matrix_mautrix_wsproxy_appservice_bot_username: wsproxy + + +# Database-related configuration fields. +# +# To use SQLite, stick to these defaults. +# +# To use Postgres: +# - change the engine (`matrix_mautrix_wsproxy_database_engine: 'postgres'`) +# - adjust your database credentials via the `matrix_mautrix_wsproxy_postgres_*` variables +matrix_mautrix_wsproxy_database_engine: 'sqlite' + +matrix_mautrix_wsproxy_sqlite_database_path_local: "{{ matrix_mautrix_wsproxy_data_path }}/mautrix-wsproxy.db" +matrix_mautrix_wsproxy_sqlite_database_path_in_container: "/data/mautrix-wsproxy.db" + +matrix_mautrix_wsproxy_database_username: 'matrix_mautrix_wsproxy' +matrix_mautrix_wsproxy_database_password: 'some-password' +matrix_mautrix_wsproxy_database_hostname: 'matrix-postgres' +matrix_mautrix_wsproxy_database_port: 5432 +matrix_mautrix_wsproxy_database_name: 'matrix_mautrix_wsproxy' + +matrix_mautrix_wsproxy_database_connection_string: 'postgresql://{{ matrix_mautrix_wsproxy_database_username }}:{{ matrix_mautrix_wsproxy_database_password }}@{{ matrix_mautrix_wsproxy_database_hostname }}:{{ matrix_mautrix_wsproxy_database_port }}/{{ matrix_mautrix_wsproxy_database_name }}?sslmode=disable' + +matrix_mautrix_wsproxy_appservice_database_type: "{{ + { + 'sqlite': 'sqlite3', + 'postgres':'postgres', + }[matrix_mautrix_wsproxy_database_engine] +}}" + +matrix_mautrix_wsproxy_appservice_database_uri: "{{ + { + 'sqlite': matrix_mautrix_wsproxy_sqlite_database_path_in_container, + 'postgres': matrix_mautrix_wsproxy_database_connection_string, + }[matrix_mautrix_wsproxy_database_engine] +}}" + + +# Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). +matrix_mautrix_wsproxy_login_shared_secret: '' + +# Default mautrix-wsproxy configuration template which covers the generic use case. +# You can customize it by controlling the various variables inside it. +# +# For a more advanced customization, you can extend the default (see `matrix_mautrix_wsproxy_configuration_extension_yaml`) +# or completely replace this variable with your own template. +matrix_mautrix_wsproxy_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" + +matrix_mautrix_wsproxy_configuration_extension_yaml: | + # Your custom YAML configuration goes here. + # This configuration extends the default starting configuration (`matrix_mautrix_wsproxy_configuration_yaml`). + # + # You can override individual variables from the default configuration, or introduce new ones. + # + # If you need something more special, you can take full control by + # completely redefining `matrix_mautrix_wsproxy_configuration_yaml`. + +matrix_mautrix_wsproxy_configuration_extension: "{{ matrix_mautrix_wsproxy_configuration_extension_yaml|from_yaml if matrix_mautrix_wsproxy_configuration_extension_yaml|from_yaml is mapping else {} }}" + +# Holds the final configuration (a combination of the default and its extension). +# You most likely don't need to touch this variable. Instead, see `matrix_mautrix_wsproxy_configuration_yaml`. +matrix_mautrix_wsproxy_configuration: "{{ matrix_mautrix_wsproxy_configuration_yaml|from_yaml|combine(matrix_mautrix_wsproxy_configuration_extension, recursive=True) }}" + +matrix_mautrix_wsproxy_registration_yaml: | + # appservice -> id from the config + id: wsproxy + # appservice -> as_token and hs_token from the config + as_token: random string + hs_token: random string + namespaces: + users: + # The localpart here is username_template from the config, but .+ instead of {{.}} + - regex: '@imessage_.+:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + exclusive: true + # Localpart here is appservice -> bot -> username from the config + - regex: '@imessagebot:{{ matrix_mautrix_telegram_homeserver_domain|regex_escape }}$' + exclusive: true + # Address that Synapse uses to contact mautrix-wsproxy + url: {{ matrix_mautrix_wsproxy_appservice_address }} + # Put a new random string here, it doesn't affect anything else + sender_localpart: random string + rate_limited: false + +matrix_mautrix_wsproxy_registration: "{{ matrix_mautrix_wsproxy_registration_yaml|from_yaml }}" diff --git a/roles/matrix-bridge-mautrix-wsproxy/tasks/init.yml b/roles/matrix-bridge-mautrix-wsproxy/tasks/init.yml new file mode 100644 index 000000000..f320bc743 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/tasks/init.yml @@ -0,0 +1,16 @@ +- set_fact: + matrix_systemd_services_list: "{{ matrix_systemd_services_list + ['matrix-mautrix-whatsapp.service'] }}" + when: matrix_mautrix_whatsapp_enabled|bool + +# If the matrix-synapse role is not used, these variables may not exist. +- set_fact: + matrix_synapse_container_extra_arguments: > + {{ matrix_synapse_container_extra_arguments|default([]) }} + + + ["--mount type=bind,src={{ matrix_mautrix_whatsapp_config_path }}/registration.yaml,dst=/matrix-mautrix-whatsapp-registration.yaml,ro"] + + matrix_synapse_app_service_config_files: > + {{ matrix_synapse_app_service_config_files|default([]) }} + + + {{ ["/matrix-mautrix-whatsapp-registration.yaml"] }} + when: matrix_mautrix_whatsapp_enabled|bool diff --git a/roles/matrix-bridge-mautrix-wsproxy/tasks/main.yml b/roles/matrix-bridge-mautrix-wsproxy/tasks/main.yml new file mode 100644 index 000000000..a01b40349 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/tasks/main.yml @@ -0,0 +1,21 @@ +- import_tasks: "{{ role_path }}/tasks/init.yml" + tags: + - always + +- import_tasks: "{{ role_path }}/tasks/validate_config.yml" + when: "run_setup|bool and matrix_mautrix_wsproxy_enabled|bool" + tags: + - setup-all + - setup-mautrix-wsproxy + +- import_tasks: "{{ role_path }}/tasks/setup_install.yml" + when: "run_setup and matrix_mautrix_wsproxy_enabled" + tags: + - setup-all + - setup-mautrix-wsproxy + +- import_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" + when: "run_setup and not matrix_mautrix_wsproxy_enabled" + tags: + - setup-all + - setup-mautrix-wsproxy diff --git a/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml b/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml new file mode 100644 index 000000000..214bdcc8c --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_install.yml @@ -0,0 +1,115 @@ +--- + +# If the matrix-synapse role is not used, `matrix_synapse_role_executed` won't exist. +# We don't want to fail in such cases. +- name: Fail if matrix-synapse role already executed + fail: + msg: >- + The matrix-bridge-mautrix-wsproxy role needs to execute before the matrix-synapse role. + when: "matrix_synapse_role_executed|default(False)" + +- set_fact: + matrix_mautrix_wsproxy_requires_restart: false + +- block: + - name: Check if an SQLite database already exists + stat: + path: "{{ matrix_mautrix_wsproxy_sqlite_database_path_local }}" + register: matrix_mautrix_wsproxy_sqlite_database_path_local_stat_result + + - block: + - set_fact: + matrix_postgres_db_migration_request: + src: "{{ matrix_mautrix_wsproxy_sqlite_database_path_local }}" + dst: "{{ matrix_mautrix_wsproxy_database_connection_string }}" + caller: "{{ role_path|basename }}" + engine_variable_name: 'matrix_mautrix_wsproxy_database_engine' + engine_old: 'sqlite' + systemd_services_to_stop: ['matrix-mautrix-wsproxy.service'] + pgloader_options: ['--with "quote identifiers"'] + + - import_tasks: "{{ role_path }}/../matrix-postgres/tasks/util/migrate_db_to_postgres.yml" + + - set_fact: + matrix_mautrix_wsproxy_requires_restart: true + when: "matrix_mautrix_wsproxy_sqlite_database_path_local_stat_result.stat.exists|bool" + when: "matrix_mautrix_wsproxy_database_engine == 'postgres'" + +- name: Ensure Mautrix wsproxy image is pulled + docker_image: + name: "{{ matrix_mautrix_wsproxy_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_mautrix_wsproxy_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_mautrix_wsproxy_docker_image_force_pull }}" + +- name: Ensure Mautrix wsproxy paths exists + file: + path: "{{ item }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - "{{ matrix_mautrix_wsproxy_base_path }}" + - "{{ matrix_mautrix_wsproxy_config_path }}" + - "{{ matrix_mautrix_wsproxy_data_path }}" + +- name: Check if an old database file exists + stat: + path: "{{ matrix_mautrix_wsproxy_base_path }}/mautrix-wsproxy.db" + register: matrix_mautrix_wsproxy_stat_database + +- name: Check if an old matrix state file exists + stat: + path: "{{ matrix_mautrix_wsproxy_base_path }}/mx-state.json" + register: matrix_mautrix_wsproxy_stat_mx_state + +- name: (Data relocation) Ensure matrix-mautrix-wsproxy.service is stopped + service: + name: matrix-mautrix-wsproxy + state: stopped + daemon_reload: yes + failed_when: false + when: "matrix_mautrix_wsproxy_stat_database.stat.exists" + +- name: (Data relocation) Move mautrix-wsproxy database file to ./data directory + command: "mv {{ matrix_mautrix_wsproxy_base_path }}/mautrix-wsproxy.db {{ matrix_mautrix_wsproxy_data_path }}/mautrix-wsproxy.db" + when: "matrix_mautrix_wsproxy_stat_database.stat.exists" + +- name: (Data relocation) Move mautrix-wsproxy mx-state file to ./data directory + command: "mv {{ matrix_mautrix_wsproxy_base_path }}/mx-state.json {{ matrix_mautrix_wsproxy_data_path }}/mx-state.json" + when: "matrix_mautrix_wsproxy_stat_mx_state.stat.exists" + +- name: Ensure mautrix-wsproxy config.yaml installed + copy: + content: "{{ matrix_mautrix_wsproxy_configuration|to_nice_yaml }}" + dest: "{{ matrix_mautrix_wsproxy_config_path }}/config.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure mautrix-wsproxy registration.yaml installed + copy: + content: "{{ matrix_mautrix_wsproxy_registration|to_nice_yaml }}" + dest: "{{ matrix_mautrix_wsproxy_config_path }}/registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-mautrix-wsproxy.service installed + template: + src: "{{ role_path }}/templates/systemd/matrix-mautrix-wsproxy.service.j2" + dest: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" + mode: 0644 + register: matrix_mautrix_wsproxy_systemd_service_result + +- name: Ensure systemd reloaded after matrix-mautrix-wsproxy.service installation + service: + daemon_reload: yes + when: "matrix_mautrix_wsproxy_systemd_service_result.changed" + +- name: Ensure matrix-mautrix-wsproxy.service restarted, if necessary + service: + name: "matrix-mautrix-wsproxy.service" + state: restarted + when: "matrix_mautrix_wsproxy_requires_restart|bool" diff --git a/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_uninstall.yml b/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_uninstall.yml new file mode 100644 index 000000000..345aa39c1 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/tasks/setup_uninstall.yml @@ -0,0 +1,24 @@ +--- + +- name: Check existence of matrix-mautrix-wsproxy service + stat: + path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" + register: matrix_mautrix_wsproxy_service_stat + +- name: Ensure matrix-mautrix-wsproxy is stopped + service: + name: matrix-mautrix-wsproxy + state: stopped + daemon_reload: yes + when: "matrix_mautrix_wsproxy_service_stat.stat.exists" + +- name: Ensure matrix-mautrix-wsproxy.service doesn't exist + file: + path: "{{ matrix_systemd_path }}/matrix-mautrix-wsproxy.service" + state: absent + when: "matrix_mautrix_wsproxy_service_stat.stat.exists" + +- name: Ensure systemd reloaded after matrix-mautrix-wsproxy.service removal + service: + daemon_reload: yes + when: "matrix_mautrix_wsproxy_service_stat.stat.exists" diff --git a/roles/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml b/roles/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml new file mode 100644 index 000000000..b08762bf9 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/tasks/validate_config.yml @@ -0,0 +1,11 @@ +--- + +- name: Fail if required settings not defined + fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - "matrix_mautrix_wsproxy_appservice_token" + - "matrix_mautrix_wsproxy_homeserver_token" + diff --git a/roles/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 b/roles/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 new file mode 100644 index 000000000..a486278d8 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/templates/config.yaml.j2 @@ -0,0 +1,150 @@ +# Homeserver details +homeserver: + # The address that this appservice can use to connect to the homeserver. + address: {{ matrix_mautrix_wsproxy_homeserver_address }} + # The domain of the homeserver (for MXIDs, etc). + domain: {{ matrix_mautrix_wsproxy_homeserver_domain }} + # Whether or not to verify the SSL certificate of the homeserver. + # Only applies if address starts with https:// + verify_ssl: true + +# Application service host/registration related details +# Changing these values requires regeneration of the registration. +appservice: + # The address that the homeserver can use to connect to this appservice. + address: {{ matrix_mautrix_wsproxy_appservice_address }} + # When using https:// the TLS certificate and key files for the address. + tls_cert: false + tls_key: false + + # The hostname and port where this appservice should listen. + hostname: 0.0.0.0 + port: 8080 + # The maximum body size of appservice API requests (from the homeserver) in mebibytes + # Usually 1 is enough, but on high-traffic bridges you might need to increase this to avoid 413s + max_body_size: 1 + + # The full URI to the database. Only Postgres is currently supported. + database: {{ matrix_mautrix_wsproxy_database_connection_string }} + + # Provisioning API part of the web server for automated portal creation and fetching information. + # Used by things like mautrix-manager (https://github.com/tulir/mautrix-manager). + provisioning: + # Whether or not the provisioning API should be enabled. + enabled: true + # The prefix to use in the provisioning API endpoints. + prefix: /_matrix/provision/v1 + # The shared secret to authorize users of the API. + # Set to "generate" to generate and save a new token. + shared_secret: generate + + # The unique ID of this appservice. + id: wsproxy + # Username of the appservice bot. + bot_username: {{ matrix_mautrix_wsproxy_appservice_bot_username|to_json }} + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + bot_displayname: Android Messages bridge bot + bot_avatar: mxc://maunium.net/VuvevQiMRlOxuBVMBNEZZrxi + + # Community ID for bridged users (changes registration file) and rooms. + # Must be created manually. + # + # Example: "+imessage:example.com". Set to false to disable. + community_id: false + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: "{{ matrix_mautrix_wsproxy_appservice_token }}" + hs_token: "{{ matrix_mautrix_wsproxy_homeserver_token }}" + +# Prometheus telemetry config. Requires prometheus-client to be installed. +metrics: + enabled: false + listen_port: 8000 + +# Bridge config +bridge: + # Localpart template of MXIDs for remote users. + # {userid} is replaced with the user ID (phone or name converted into a mxid-friendly format). + username_template: "imessage_{userid}" + # Displayname template for remote users. + # {displayname} is replaced with the display name of the user. + # {phone} is replaced with the phone number or name of the user. + displayname_template: "{displayname} (iMessage)" + + # Maximum length of displayname + displayname_max_length: 100 + + # Number of conversations to sync (and create portals for) on login. + # Set 0 to disable automatic syncing. + initial_conversation_sync: 10 + # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, custom puppets will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + login_shared_secret: null + # Whether or not created rooms should have federation enabled. + # If false, created portal rooms will never be federated. + federate_rooms: true + # Settings for backfilling messages from the Messages app. + backfill: + # If using double puppeting, should notifications be disabled + # while the initial backfill is in progress? + disable_notifications: false + # End-to-bridge encryption support options. These require matrix-nio to be installed with pip + # and login_shared_secret to be configured in order to get a device for the bridge bot. + # + # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal + # application service. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: false + # 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. + default: false + # Options for automatic key sharing. + key_sharing: + # 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: false + # Require the requesting device to have a valid cross-signing signature? + # This doesn't require that the bridge has verified the device, only that the user has verified it. + # Not yet implemented. + require_cross_signing: false + # Require devices to be verified by the bridge? + # Verification by the bridge is not yet implemented. + require_verification: true + # Whether or not to explicitly set the avatar and room name for private + # chat portal rooms. This will be implicitly enabled if encryption.default is true. + private_chat_portal_meta: false + # Whether or not the bridge should send a read receipt from the bridge bot when a message has + # been sent. + delivery_receipts: false + # Whether or not delivery errors should be reported as messages in the Matrix room. + delivery_error_reports: false + # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. + # This field will automatically be changed back to false after it, + # except if the config file is not writable. + resend_bridge_info: false + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "!im" + + # This bridge only supports a single user + user: "{{ matrix_mautrix_wsproxy_bridge_user }}" + +logging: + # The directory for log files. Will be created if not found. + directory: ./logs + # Available variables: .Date for the file date and .Index for different log files on the same day. + file_name_format: "{{ '{{.Date}}-{{.Index}}.log' }}" + # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants + file_date_format: "2006-01-02" + # Log file permissions. + file_mode: 0600 + # Timestamp format for log entries in the Go time format. + timestamp_format: "Jan _2, 2006 15:04:05" + # Minimum severity for log messages. + # Options: debug, info, warn, error, fatal + print_level: debug \ No newline at end of file diff --git a/roles/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-whatsapp.service.j2 b/roles/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-whatsapp.service.j2 new file mode 100644 index 000000000..7b31cd3f8 --- /dev/null +++ b/roles/matrix-bridge-mautrix-wsproxy/templates/systemd/matrix-mautrix-whatsapp.service.j2 @@ -0,0 +1,43 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix Mautrix wsproxy bridge +{% for service in matrix_mautrix_wsproxy_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_mautrix_wsproxy_systemd_wanted_services_list %} +Wants={{ service }} +{% endfor %} +DefaultDependencies=no + +[Service] +Type=simple +Environment="HOME={{ matrix_systemd_unit_home_path }}" +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mautrix-wsproxy 2>/dev/null' +ExecStartPre=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-wsproxy 2>/dev/null' + +# Intentional delay, so that the homeserver (we likely depend on) can manage to start. +ExecStartPre={{ matrix_host_command_sleep }} 5 + +ExecStart={{ matrix_host_command_docker }} run --rm --name matrix-mautrix-wsproxy \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_docker_network }} \ + -v {{ matrix_mautrix_wsproxy_config_path }}:/config:z \ + -v {{ matrix_mautrix_wsproxy_data_path }}:/data:z \ + --workdir=/data \ + {% for arg in matrix_mautrix_wsproxy_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_mautrix_wsproxy_docker_image }} \ + /usr/bin/mautrix-wsproxy -c /config/config.yaml -r /config/registration.yaml + +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} kill matrix-mautrix-wsproxy 2>/dev/null' +ExecStop=-{{ matrix_host_command_sh }} -c '{{ matrix_host_command_docker }} rm matrix-mautrix-wsproxy 2>/dev/null' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-mautrix-wsproxy + +[Install] +WantedBy=multi-user.target diff --git a/setup.yml b/setup.yml index 4e2879e59..16394cbd3 100755 --- a/setup.yml +++ b/setup.yml @@ -24,6 +24,7 @@ - matrix-bridge-mautrix-signal - matrix-bridge-mautrix-telegram - matrix-bridge-mautrix-whatsapp + - matrix-bridge-mautrix-wsproxy - matrix-bridge-mx-puppet-discord - matrix-bridge-mx-puppet-groupme - matrix-bridge-mx-puppet-steam