ChatMatrix: Difference between revisions

From FlowerHouseWiki
Line 144: Line 144:


<p>Check if federation configuration is correct: https://federationtester.matrix.org/</p>
<p>Check if federation configuration is correct: https://federationtester.matrix.org/</p>
=== .well-known ===


=== Add User ===
=== Add User ===

Revision as of 13:55, 19 August 2022

Matrix-logo.png

Network


IP: 192.168.88.19
MAC: BE:B1:89:38:28:44
Domain: chat.flowerhouse.at

System


OS: Debian Bullseye
RAM: 4096MB
Cores: 2
Privileged: No

The ChatMatrix-LXC is reachable under 192.168.88.19 which is located in the ServerVLAN.

The subdomain is chat.flowerhouse.at which is handled by the ReverseProxy.

Basic Setup

Be up to date

apt update && apt upgrade

Change timezone

timedatectl set-timezone Europe/Berlin

Installation

Install required packages

apt install -y lsb-release wget apt-transport-https

Add repository

wget -O /usr/share/keyrings/matrix-org-archive-keyring.gpg https://packages.matrix.org/debian/matrix-org-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/matrix-org-archive-keyring.gpg] https://packages.matrix.org/debian/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/matrix-org.list
apt update

Install matrix-synapse

apt install matrix-synapse-py3

Check status

systemctl status matrix-synapse

Postgres database

Install required packages

apt install libpq5 postgresql

Open Postgres console

su - postgres

Create user for matrix-synapse

createuser --pwprompt synapse_user

Create database for matrix-synapse

createdb --encoding=UTF8 --locale=C --template=template0 --owner=synapse_user synapse

Exit Postgres console

exit

Edit matrix-synapse configuration file

nano /etc/matrix-synapse/homeserver.yaml

Edit the database entry

database:
  name: psycopg2
  args:
    user: synapse_user
    password: <pass>
    database: synapse
    host: localhost
    cp_min: 5
    cp_max: 10

Check if it works

systemctl restart matrix-synapse
systemctl status matrix-synapse

Setting up reverse proxy

NGINX Proxy Manager configuration without exposing admin API

{
  "id": 3,
  "created_on": "2022-07-28 21:08:35",
  "modified_on": "2022-08-19 01:23:10",
  "owner_user_id": 1,
  "domain_names": [
    "matrix.flowerhouse.at"
  ],
  "forward_host": "192.168.88.19",
  "forward_port": 80,
  "access_list_id": 0,
  "certificate_id": 25,
  "ssl_forced": true,
  "caching_enabled": true,
  "block_exploits": true,
  "advanced_config": "listen 8448 ssl http2 default_server;\r\nlisten [::]:8448 ssl http2 default_server;\r\n\r\nserver_name matrix.flowerhouse.at;",
  "meta": {
    "letsencrypt_agree": false,
    "dns_challenge": false
  },
  "allow_websocket_upgrade": true,
  "http2_support": true,
  "forward_scheme": "http",
  "enabled": 1,
  "locations": [
    {
      "path": "~ ^(/_matrix|/_synapse/client)",
      "advanced_config": "proxy_set_header X-Forwarded-For $remote_addr;\nproxy_set_header X-Forwarded-Proto $scheme;\nproxy_set_header Host $host;\n\n# Nginx by default only allows file uploads up to 1M in size\nclient_max_body_size 50M;",
      "forward_scheme": "http",
      "forward_host": "192.168.88.19",
      "forward_port": 8008
    }
  ],
  "hsts_enabled": true,
  "hsts_subdomains": false
}

If you want to expose admin api, change custom location to

~ ^(/_matrix|/_synapse)

Check if federation configuration is correct: https://federationtester.matrix.org/

.well-known

Add User

register_new_matrix_user -c /etc/matrix-synapse/homeserver.yaml http://localhost:8008

Optional

Configure puppeting

Install required packages

apt install pip git pwgen

Activate synapse virtual enviroment

cd /opt/venvs/matrix-synapse
source ./bin/activate

Install packages

pip install git+https://github.com/devture/matrix-synapse-shared-secret-auth
deactivate

Generate shared secret

pwgen -s 128 1

Edit configuration and add configuration

nano /etc/matrix-synapse/homeserver.yaml

General information about puppeting

Administration

Administration-Tools:

Or make API-Request with curl

Install Bridges

ffmpeg is needed to support media files

apt install ffmpeg

WhatsApp

Installation

Create user for mautrix-whatsapp

adduser --system mautrix-whatsapp --home /opt/mautrix-whatsapp

Enter user folder

cd /opt/mautrix-whatsapp

Download binary from https://github.com/mautrix/whatsapp/releases

wget https://github.com/mautrix/whatsapp/releases/download/v0.5.0/mautrix-whatsapp-amd64

Rename binary

mv mautrix-whatsapp-amd64 mautrix-whatsapp

Create database

Open Postgres console

su - postgres

Create user for mautrix-whatsapp

createuser --pwprompt whatsapp_user

Create database for mautrix-whatsapp

createdb --encoding=UTF8 --locale=C --template=template0 --owner=whatsapp_user whatsapp

Exit Postgres console

exit

Configuration

Create and paste config file: mautrix-whatsapp-config.yaml

nano config.yaml

Modify permissions

chmod 755 mautrix-whatsapp

Generate the appservice registration file

./mautrix-whatsapp -g

Modify permissions

chmod 555 registration.yaml

Edit matrix-synapse configuration file

nano /etc/matrix-synapse/homeserver.yaml

To register WhatsApp add following lines

app_service_config_files:
- /opt/mautrix-whatsapp/registration.yaml

Restart matrix-synapse

systemctl restart matrix-synapse

Check if bridge works

./mautrix-whatsapp

systemd service

Create systemd service file and copy from service

nano /etc/systemd/system/mautrix-whatsapp.service

Apply changes

systemctl daemon-reload

Start and check status

systemctl start mautrix-whatsapp
systemctl status mautrix-whatsapp

Enable autostart

systemctl enable mautrix-whatsapp

Signal

Install Signald

Add repository

wget -O /usr/share/keyrings/signald-org-archive-keyring.asc https://updates.signald.org/apt-signing-key.asc
echo "deb [signed-by=/usr/share/keyrings/signald-org-archive-keyring.asc] https://updates.signald.org unstable main" | tee /etc/apt/sources.list.d/signald.list
apt update

Install signald

apt install signald

Check if it works correctly

systemctl start signald
systemctl status signald

Enable autostart

systemctl enable signald

Install Bridge

Install prerequisites

apt install python pip libolm-dev
pip install virtualenv

Create user for bridge and join signald group

adduser --system mautrix-signal --home /opt/mautrix-signal
usermod -aG signald mautrix-signal

Go to directory

cd /opt/mautrix-signal

Create virtual environment

virtualenv -p /usr/bin/python3 .

Activate virtual environment

source ./bin/activate

Install signal bridge

pip install --upgrade mautrix-signal[all]

Create database

Open Postgres console

su - postgres

Create user for mautrix-whatsapp

createuser --pwprompt signal_user

Create database for mautrix-whatsapp

createdb --encoding=UTF8 --locale=C --template=template0 --owner=signal_user signal

Exit Postgres console

exit

Configuration

Copy configuration file and edit...

cp example-config.yaml config.yaml

Generate access file

python -m mautrix_signal -g

Set permissions

chown -R mautrix-signal:root ../mautrix-signal/

Edit matrix-synapse configuration file

nano /etc/matrix-synapse/homeserver.yaml

To register WhatsApp add following lines

app_service_config_files:
- /opt/mautrix-signal/registration.yaml

Restart matrix-synapse

systemctl restart matrix-synapse

Check if bridge works

python -m mautrix_signal

systemd service

Create systemd service file and copy from service

nano /etc/systemd/system/mautrix-signal.service

Apply changes

systemctl daemon-reload

Start and check status

systemctl start mautrix-signal
systemctl status mautrix-signal

Enable autostart

systemctl enable mautrix-signal

Telegram

Installation

Create user for bridge

adduser --system mautrix-telegram --home /opt/mautrix-telegram

Go to directory

cd /opt/mautrix-telegram

Create virtual environment

virtualenv -p /usr/bin/python3 .

Activate virtual environment

source ./bin/activate

Install signal bridge

pip install --upgrade mautrix-telegram[all]

Create database

Open Postgres console

su - postgres

Create user for mautrix-whatsapp

createuser --pwprompt telegram_user

Create database for mautrix-whatsapp

createdb --encoding=UTF8 --locale=C --template=template0 --owner=telegram_user telegram

Exit Postgres console

exit

Configuration

Copy configuration file and edit...

cp example-config.yaml config.yaml

Generate access file

python -m mautrix_telegram -g

Set permissions

chown -R mautrix-telegram:root ../mautrix-telegram/

Edit matrix-synapse configuration file

nano /etc/matrix-synapse/homeserver.yaml

To register WhatsApp add following lines

app_service_config_files:
- /opt/mautrix-telegram/registration.yaml

Restart matrix-synapse

systemctl restart matrix-synapse

Check if bridge works

python -m mautrix_telegram

systemd service

Create systemd service file and copy from service

nano /etc/systemd/system/mautrix-telegram.service

Apply changes

systemctl daemon-reload

Start and check status

systemctl start mautrix-telegram
systemctl status mautrix-telegram

Enable autostart

systemctl enable mautrix-telegram

IRC

Installation

Create user for bridge

adduser --system mautrix-irc --home /opt/mautrix-irc

Go to directory

cd /opt/mautrix-irc

Create virtual environment

virtualenv -p /usr/bin/python3 .

Activate virtual environment

source ./bin/activate

Install heisenbridge

pip install heisenbridge

Generate access file

python -m heisenbridge -c /opt/mautrix-irc/registration.yaml --generate

Set permissions

chown -R mautrix-irc:root ../mautrix-irc/

Edit matrix-synapse configuration file

nano /etc/matrix-synapse/homeserver.yaml

To register WhatsApp add following lines

app_service_config_files:
- /opt/mautrix-irc/registration.yaml

Restart matrix-synapse

systemctl restart matrix-synapse

Check if bridge works

python -m heisenbridge -c /opt/mautrix-irc/registration.yaml

If no .well-known file is configured, startup may take a few minutes

systemd service

Create systemd service file and copy from mautrix-irc.service

nano /etc/systemd/system/mautrix-irc.service

Apply changes

systemctl daemon-reload

Start and check status

systemctl start mautrix-irc
systemctl status mautrix-irc

Enable autostart

systemctl enable mautrix-irc

Configuration

This bridge is not configured with an config file but via the bot chat.

The first person chatting with the bot will automatically be set as the admin.

Set mediaurl

MEDIAURL chat.flowerhouse.at