matrix.juggler.jp 運用記録
!mjj
help-circle
rss
「Matrix日本サーバ勢の公開部屋リスト」へのサーバ追加について
---- ## 背景 [Matrix日本サーバ勢の公開部屋リスト](https://matrix-room-list-jp.netlify.app/)へのサーバ追加の問い合わせがあったが、試してみると403エラーが出た。 ---- ## 前提条件 - そのサーバが連合できる設定になっていること。 連合しないサーバはあのリストには載せません。 ---- ## 確認事項 (1)Synapseのhomeserrver.ymlの以下の項目を確認します。 ``` allow_public_rooms_without_auth: true allow_public_rooms_over_federation: true ``` 設定を変更した場合は、Synapseを再起動するなどして設定を反映します。 (2)適当な別のサーバにElement-Webでログインして、 https://lemmy.juggler.jp/post/786 の下の方の手順で、追加したいサーバの公開部屋リストを取得できるか確認します。

部屋別のメッセージ流速を調べるクエリ
``` # 部屋別メッセージ数の集計のためのインデクス create index x_events_message_speed on events(room_id,origin_server_ts) where type='m.room.message'; # 部屋別メッセージ数を集計するビュー CREATE OR REPLACE VIEW room_speed as SELECT events.room_id, count(*) AS speed FROM events WHERE events.type = 'm.room.message'::text AND events.origin_server_ts::double precision >= (date_part('epoch'::text, CURRENT_TIMESTAMP) * 1000::double precision - 86400000::double precision) GROUP BY events.room_id; # 集計して部屋の公開エイリアスと結合 select speed,canonical_alias from room_speed left join room_stats_state on room_stats_state.room_id = room_speed.room_id where speed>0 order by speed desc; ```

mjjのSynapseを1.30.1に更新しました
mjjのSynapseを1.30.1に更新しました

cron+perlで現在再生中の曲をSpotifyから取ってきて適当にフィルタしてMatrixに送るbotを書いてみた。導入とか色々はリンク先に。
2

ホームサーバのホスト名からWebUIを開く方法
https://matrix-room-list-jp.netlify.app/ から部屋を開くリンク。今は matrix.juggler.jp に固定してるんですが、たとえば部屋のあるホームサーバのWebUIに飛ばしたいとか、ユーザがクッキーに覚えさせたホームサーバのWebUIに飛ばしたいとかありますよね。 そこでホームサーバのホスト名からWebUIを開く標準的な方法を調べてみました。 - 単純に http://{ホームサーバ}/ に飛ばすのはNGです。Synapseが動いてるサーバのトップページにWebUIがない場合がいくつかあります。 - 基本的には`https://{ホームサーバ}/_matrix/client` にアクセスするとリダイレクトするかWebUIが開くことになってます。 では試してみましょう。 (追記:CloudFlareを使ってるサーバでUser-Agentの指定により挙動の違いが見られたので 最近のChromeのUAを設定した状態で再テストしました) |server|status code|contents or redirect location| |---|---|---| |matrix.org|404 Not Found|404 - No Such Resource No Such Resource Sorry. No luck finding that resource.| |matrix.juggler.jp|302 Found|Location: https://matrix.juggler.jp/| |matrix-jp.net|302 Found|Location: https://riot.matrix-jp.net/| |smith.gdgd.jp.net|302 Found|Location: https://neo.gdgd.jp.net/| |matrix.fedibird.com|200 OK|Element Sorry, Element requires JavaScript to be enabled. (script…)| |matrix.sabakan.industries|200 OK|Element Sorry, Element requires JavaScript to be enabled. (script…)| |nibbana.jp|200 OK|Element Sorry, Element requires JavaScript to be enabled. (script…)| - CloudFlareさんは302を内部で処理しちゃってるみたいですね。 - matrix.org にはデフォルトのWebUIが設定されてないようです。

https://matrix.juggler.jp/ の Element-Web を1.7.23 に更新しました。ブラウザで開く場合にはページのCTRL+リロードが必要かもしれません。
1

Matrix日本サーバ勢の公開部屋リスト
---- ## 概要 [Matrix日本サーバ勢の公開部屋リスト](https://matrix-room-list-jp.netlify.app/) を作ってみました。日本サーバいくつかの公開部屋リストを取得して表にするものです。 ---- ## Web - ソースコード https://github.com/tateisu/matrixRoomList-web 静的ファイルだけなのでGitHubのリポジトリに出力してGetlifyで公開してます。 ---- ## クローラー - クローラーのbotはkotlinで書きました。 - ソースコード https://github.com/tateisu/matrixRoomCrawler - 動かすと出力フォルダに `data.json` と `avatar/{site}/{key}` を生成します。 - このbotが直接いろんなサーバに接続してる訳ではなく、`matrix.juggler.jp` の `publicRooms` API にserver を指定して取得しています。つまり `matrix.juggler.jp` と連合できないサーバの部屋は多分このリストには出ません。

某部屋の名前の由来
``` MG_akita この部屋の名前の由来ねぇ・・・・・ MG_akita P2P地震情報の、雑談用プラグインで、 MG_akita 地震がないときに、今は居ないヤツとか、STK氏とか、俺が、 MG_akita 巫女画像でえらく盛り上がって、 MG_akita 「うざい」言われて移転先に選んだのが、i2ch@IRCってー流れで、 MG_akita チャンネル名を巫女にした記憶w MG_akita だから、最初は、「地震がない平穏なときは、巫女画像でもネタにしてgdgdして、巫女画像で和もう」くらいだったような機がするなーw ```

カスタムステッカーパックを作って/使ってみる
## 概要 [やまこさん](https://fedibird.com/@yamako)がMatrixのステッカーパックの自作を成功させていたので、ほぼそのまま試してステッカーパックを作って使ってみます。 - https://windish.kibe.la/shared/entries/18649f13-86b2-43af-8b41-89f6eb391121 - https://github.com/maunium/stickerpicker/ - https://github.com/maunium/stickerpicker/wiki/Creating-packs - https://github.com/maunium/stickerpicker/wiki/Hosting-on-GitHub-pages ---- ## 条件 - GitHubにアカウントがあり、他のリポジトリをフォークして更新できる程度の経験があること。 - Matrixサーバにアカウントがあること。(一般ユーザでOK) - Python3.6以上を動かせる環境が手元にあること。 ---- ## フォークとGitHub Pageの設定 今回利用する `maunium/stickerpicker` は GitHub Pages でのステッカーパック公開が想定されています。 Githubのサイトで以下の操作を行います。 - https://github.com/maunium/stickerpicker をフォークする - フォークしたリポジトリの「Settings => GitHub Pages => Source」に`master` ブランチを指定してSaveボタンを押す。 - "Your site is ready to be published at https://tateisu.github.io/stickerpicker/. " のような表示が出ることを確認する。 ---- ## 作業環境 ``` $ cat /etc/issue Ubuntu 18.04.3 LTS \n \l $ sudo apt install python3 python3-distutils $ python3 --version Python 3.6.9 ``` ---- ## クローンとpythonの設定 gitリポジトリのURLはフォークしたものに置き換えてください。 ``` $ git clone git@github.com:tateisu/stickerpicker.git stickerpicker $ cd stickerpicker/ $ virtualenv -p python3 .venv $ source .venv/bin/activate $ pip install . ``` フォルダを作って画像を入れる。 ピッカー上ではファイル名順に並ぶらしい。 ``` $ find jugglerJp/ -ls 12847750 4 drwxr-xr-x 2 tateisu tateisu 4096 Mar 11 18:13 jugglerJp/ 12847772 44 -rw-r--r-- 1 tateisu tateisu 44580 Mar 11 18:13 jugglerJp/camera.jpg 12847774 32 -rw-r--r-- 1 tateisu tateisu 28854 Mar 11 18:13 jugglerJp/chestnut.jpg 12847775 8 -rw-r--r-- 1 tateisu tateisu 4355 Mar 11 18:13 jugglerJp/hohoemi.png 12847771 40 -rw-r--r-- 1 tateisu tateisu 39748 Mar 11 18:13 jugglerJp/buta.jpg 12847770 8 -rw-r--r-- 1 tateisu tateisu 6868 Mar 11 18:13 jugglerJp/bonus_item.png 12847773 300 -rw-r--r-- 1 tateisu tateisu 305326 Mar 11 18:13 jugglerJp/cat.png 12847768 56 -rw-r--r-- 1 tateisu tateisu 54107 Mar 11 18:13 jugglerJp/announce-san-1.jpg 12847769 52 -rw-r--r-- 1 tateisu tateisu 49467 Mar 11 18:13 jugglerJp/announce-san-2.jpg ``` ---- ## Matrixアカウントのアクセストークンを調べる Element-Webの設定のヘルプの下の方にあるアクセストークンの文字列をコピーしておきます。 `sticker-pack`スクリプトがMatrixサーバに画像をアップロードする際に必要です。 ---- ## sticker-pack コマンドの概要 ``` $ sticker-pack --help usage: sticker-pack [-h] [--config file] [--title title] [--id id] [--add-to-index path] path positional arguments: path Path to the sticker pack directory optional arguments: -h, --help show this help message and exit --config file Path to JSON file with Matrix homeserver and access_token --title title Override the sticker pack displayname --id id Override the sticker pack ID --add-to-index path Sticker picker pack directory (usually 'web/packs/') ``` ---- ## パックする ``` $ sticker-pack --add-to-index web/packs/ --title "juggler.jpステッカー" jugglerJp Matrix config file not found. Please enter your homeserver and access token. Homeserver URL: https://matrix.juggler.jp/ Access token: {CENSORED} Access token validated (user ID: @tateisu-test2:matrix.juggler.jp) Wrote config to config.json Processing announce-san-1.jpg... uploaded (snip…) Processing subwayTooter.png... uploaded Wrote pack to jugglerJp/pack.json Copied pack to web/packs/jugglerJp.json Added jugglerJp.json to web/packs/index.json ``` 初回はホームサーバURLとアクセストークンを尋ねられます。 config.json に保存されて次回以降は尋ねられません。 ** config.jsonのパーミッションを適切に変更しておきましょう ** この時点でステッカー画像はサーバにアップロードされてます。 ---- ## リポジトリに上げる git add web/packs git commit -a -m "add web/packs" git push push後は以下のURLが見えます。 https://tateisu.github.io/stickerpicker/web/packs/index.json https://tateisu.github.io/stickerpicker/web/packs/jugglerJp.json ここまでで提供者としてのセットアップは終わりです。 ----- ## Element-Webにステッカーパックを指定する - Elements-Webでチャット入力欄に `/devtools` を入力して管理者ツールを開く。 ![](https://lemmy.juggler.jp/pictrs/image/Qg0D1pgdhv.jpg) - 「アカウントのデータを調べる」を選んで `m.widgets` で絞り込む。 ##### 何も出なかった場合 開発者ツール => 「アカウントのデータを送信する」で以下の内容を送信する。 - 「イベントの形式」に `m.widgets` - 「イベントの内容」に以下のjson ``` { "jugglerJp": { "content": { "type": "m.stickerpicker", "url": "https://tateisu.github.io/stickerpicker/web/?theme=$theme", "name": "jugglerJp", "data": {} }, "sender": "@tateisu-test2:matrix.juggler.jp", "state_key": "jugglerJp", "type": "m.widget", "id": "jugglerJp" } } ``` ##### 既に既存のウィジェットが存在した場合 そのjsonデータをコピーして↑のjsonとマージしたものを送りましょう。 なお、同じ種類のウィジェットは同時に1つしか設定できないようでした。 いくつか並べて試してみましたが出てきたのは最初の一つのパックだけ。 ---- ## 動作確認 送信してdevtoolsを閉じたらリロードなしでステッカーが使えてるはずです。 ##### Chromeではサードパーティクッキーの許可が必要です Chromeで出たエラー。 ``` Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. at https://tateisu.github.io/stickerpicker/web/src/frequently-used.js:16:43 ``` ブラウザの設定でサードパーティクッキーを許可してからリロードすると解決しました。 ![](https://lemmy.juggler.jp/pictrs/image/3Po2nIXZK5.jpg)

Syanpseの内部構造をどう改善していったか説明されている。

URLプレビューを有効にする
Synapseのhomeserver.ymlの設定変更が必要です。 ``` @@ -944,7 +954,7 @@ media_store_path: "/data/media_store" # 'false' by default: uncomment the following to enable it (and specify a # url_preview_ip_range_blacklist blacklist). # -#url_preview_enabled: true +url_preview_enabled: true # List of IP address CIDR ranges that the URL preview spider is denied # from accessing. There are no defaults: you must explicitly @@ -960,26 +970,26 @@ media_store_path: "/data/media_store" # This must be specified if url_preview_enabled is set. It is recommended that # you uncomment the following list as a starting point. # -#url_preview_ip_range_blacklist: -# - '127.0.0.0/8' -# - '10.0.0.0/8' -# - '172.16.0.0/12' -# - '192.168.0.0/16' -# - '100.64.0.0/10' -# - '192.0.0.0/24' -# - '169.254.0.0/16' -# - '192.88.99.0/24' -# - '198.18.0.0/15' -# - '192.0.2.0/24' -# - '198.51.100.0/24' -# - '203.0.113.0/24' -# - '224.0.0.0/4' -# - '::1/128' -# - 'fe80::/10' -# - 'fc00::/7' -# - '2001:db8::/32' -# - 'ff00::/8' -# - 'fec0::/10' +url_preview_ip_range_blacklist: + - '127.0.0.0/8' + - '10.0.0.0/8' + - '172.16.0.0/12' + - '192.168.0.0/16' + - '100.64.0.0/10' + - '192.0.0.0/24' + - '169.254.0.0/16' + - '192.88.99.0/24' + - '198.18.0.0/15' + - '192.0.2.0/24' + - '198.51.100.0/24' + - '203.0.113.0/24' + - '224.0.0.0/4' + - '::1/128' + - 'fe80::/10' + - 'fc00::/7' + - '2001:db8::/32' + - 'ff00::/8' + - 'fec0::/10' # List of IP address CIDR ranges that the URL preview spider is allowed # to access even if they are specified in url_preview_ip_range_blacklist. @@ -1044,13 +1054,14 @@ media_store_path: "/data/media_store" # # Example: # -# url_preview_accept_language: -# - en-UK -# - en-US;q=0.9 -# - fr;q=0.8 -# - *;q=0.7 -# + url_preview_accept_language: + - "ja-JP;q=0.9" + - "en-US;q=0.8" + - "*;q=0.7" + +# +# url_preview_accept_language: # - en ```

ElementのIRCスタイルレイアウト
IRCに慣れた人の場合、ElementのIRCスタイルレイアウトを使うと表示がコンパクトで見やすいかもしれません。 ![メイン画面から設定を開く](https://lemmy.juggler.jp/pictrs/image/fte7LgEJt7.jpg) - メイン画面の左上の自分の名前が表示されてる場所の「↓」ボタンを押して「全ての設定」を開く ![設定の外観カテゴリ](https://lemmy.juggler.jp/pictrs/image/PciTZy7HGg.jpg) - 設定の外観カテゴリの、「高度な設定を表示」を押す - 「コンパクトなIRCスタイルレイアウトを使用」を選択 - お好みでフォントも指定できます ![設定後のメイン画面](https://lemmy.juggler.jp/pictrs/image/BDiECmckeh.jpg) - 設定後のメイン画面はこんな表示になります。

ガイド:ElementのPCデスクトップ版をインストールしてアカウントを作って部屋に入るまで
---- ## 背景 `irc.juggler.jp` は今まで Slackの`jugglerjp`ワークスペースとの間でコンテンツのリレーを行っていましたが、このたび SlackからMatrixに移行しました。 ---- ## このガイドで説明すること - Element (WebアプリまたはPC用アプリ)の導入 - Matrixサーバ `matrix.juggler.jp` にアカウントを作る手順 ---- ## Element (WebアプリまたはPC用アプリ)の導入 ### Webアプリの場合 - ブラウザで https://matrix-element.juggler.jp を開きます。 ### PC用アプリの場合 - ブラウザで https://element.io/download を開きます。 - 右側のDesktop をダウンロードします。 - Element Setup.exe がダウンロードされます。実行します。 - インストールステップは一切なく、唐突にElementが起動します。 ---- ## アカウントの作成 ![Elementへようこそ!](https://juggler.jp/matrixElementDesktopInstallGuide/2.jpg) - 「Elementへようこそ!」が表示されたら、「アカウントの作成」を選びます。 ![アカウントを作成A](https://juggler.jp/matrixElementDesktopInstallGuide/3.jpg) - 「アカウントを作成」が表示されたら、「HostAccount on」の右にある「編集」ボタンを推します。 ![Decide where your account is hosted](https://juggler.jp/matrixElementDesktopInstallGuide/4.jpg) - 「Decide where your account is hosted」が表示されたら、「Other homeserver」のラジオボタンにチェックをつけて、homeserver に `matrix.juggler.jp` を入力して、「続ける」を押します。 ![アカウントを作成B](https://juggler.jp/matrixElementDesktopInstallGuide/5.jpg) - 「アカウントを作成」に戻ってきたら、ユーザー名とパスワードを入力します。 **注意:ユーザー名は公開されます。後から変更はできません。** **注意:ユーザ名に使える文字はかなり制限されています。すべて半角文字で、アルファベット小文字、数字、アンダーバーだけのようです。** - メールアドレスの入力は荒らし対策のため必須になりました。 ~~**メールアドレスは入力してもしなくても構いません。**~~ - 入力が終わったら「登録」ボタンを押します。 ![Continuing without email](https://juggler.jp/matrixElementDesktopInstallGuide/6.jpg) - ~~メールアドレスを入力しなかった場合、再度メールアドレスの入力を促されます。~~ - ~~**メールアドレスは入力してもしなくても構いません。**~~ 2021/6/30追記:スパムbotが多発している関係でメールアドレス確認を必須にするサーバが増えています。 ---- ## メールアドレスの確認 (メールアドレスを入力しなかったひとはこの節を読み飛ばしてください) ![メールアドレスの確認](https://juggler.jp/matrixElementDesktopInstallGuide/7.jpg) - メールアドレスを入力した場合は確認まちの画面になります。 - あなたのメールアプリで確認メールを探して開きます。 -![メールアドレスの確認2](https://juggler.jp/matrixElementDesktopInstallGuide/mail.jpg) - 「Verify Your Email Address」のリンクを開きます。 ![メールアドレスの確認2](https://juggler.jp/matrixElementDesktopInstallGuide/8.jpg) - メールアドレスの確認が終わったら、元のElement-Desktopアプリに戻っても、PCブラウザからログインしても構いません。 - 「ログイン」リンクを押します。 ---- ## サインイン ![サインイン](https://juggler.jp/matrixElementDesktopInstallGuide/9.jpg) - サインイン画面でユーザ名とパスワードを入力してサインインします。 ---- ## サインイン後の流れ ![部屋を探す](https://juggler.jp/matrixElementDesktopInstallGuide/10.jpg) - サインインしたらメイン画面が表示されますが、まだ何も部屋が登録されていません。 - 左上の検索欄で部屋を検索するか、その右のコンパスボタンで「部屋を探す」を開いてください。 ![部屋の一覧](https://juggler.jp/matrixElementDesktopInstallGuide/11.jpg) - 「部屋を探す」に部屋の一覧が出ます。 - 右上に「Matrix rooms (`matrix.juggler.jp`)」と表示されていることを確認してください。もし別のサーバ名が表示されていたら、アカウントを作るサーバを間違えています。 - もしあなたの入りたい部屋が一覧に表示されているなら、参加ボタンを押すと参加できます。 - また、右上のサーバ名の部分を押すと、別のサーバを選んだり、「+Add a new server…」で任意のサーバの部屋の一覧を表示できます。

Synapse 1.29.0
https://matrix.juggler.jp/ のSynapse を1.29.0に更新しました。
1

Element-DesktopでreCAPCHAがエラーを出す
![](https://lemmy.juggler.jp/pictrs/image/JVLHOnF9y8.jpg) - Element-DesktopでreCAPCHAがエラーを出す。 - マージされてないPRに回避方法が書かれていた。 - https://github.com/matrix-org/synapse/pull/7324/files Element-DesktopでreCAPCHAエラーが出る問題を回避したい場合、ドメインに「vector」を追加する必要があります。例えばドメインに `matrix.your.domain` と `vector` (はい、`.im` なし) の2つを設定します。

matrix.juggler.jpを設置してみた
matrix.juggler.jpを設置してみたので、インストール手順をメモしておくよ。 ---- ## Matrixとは - https://ja.wikipedia.org/wiki/Matrix_(%E3%83%97%E3%83%AD%E3%83%88%E3%82%B3%E3%83%AB) - https://wiki.matrix-jp.net/what_is_matrix ----- ## reCAPCHAの申し込み https://github.com/matrix-org/synapse/blob/develop/docs/CAPTCHA_SETUP.md - https://www.google.com/recaptcha/admin/create でreCAPCHAのキーを作っておく。 - 種類はv2にすること。 - https://github.com/matrix-org/synapse/pull/7324/files Element-DesktopでreCAPCHAエラーが出る問題を回避したい場合、ドメインに「vector」を追加する必要があります。例えばドメインに `matrix.your.domain` と `vector` (はい、` .im`なし) の2つを設定します。 ----- ## フォルダ構成 ``` /somewhere/matrix/ db/ (自動的に作成される) redis/ (自動的に作成される) data/ (自動的に作成される) homeserver.yaml (自動生成した後に手動で設定する) matrix1/ (手動で作る) docker-compose.yml (手動で作る) static/ (手動で作る) element-v1.7.22/ ``` フォルダを作っておく。 ``` mkdir -p /somewhere/matrix/matrix1 mkdir -p /somewhere/matrix/static ``` ----- ## Synapse - Pythonで書かれたサーバ実装の一つ。 - 今回はdockerイメージで雑に入れる。 - https://github.com/matrix-org/synapse/blob/develop/INSTALL.md - https://github.com/matrix-org/synapse/blob/develop/docs/federate.md - https://hub.docker.com/r/matrixdotorg/synapse ### docker-compose.ymlの用意 /somewhere/matrix/matrix1/docker-compose.yml を作る。 ``` version: '3' services: redis: restart: always image: redis:4.0-alpine volumes: - ../redis:/data networks: - internal_network db: restart: always image: postgres:13.2-alpine volumes: - ../db:/var/lib/postgresql/data networks: - internal_network environment: - POSTGRES_PASSWORD=PLEASE_REPLACE_THIS - POSTGRES_USER=PLEASE_REPLACE_THIS - POSTGRES_DB=PLEASE_REPLACE_THIS - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --locale=C synapse: restart: always image: matrixdotorg/synapse:v1.28.0 volumes: - ../data:/data environment: - SYNAPSE_SERVER_NAME=matrix.juggler.jp - SYNAPSE_REPORT_STATS=yes ports: - "PLEASE_REPLACE_THIS:PLEASE_REPLACE_THIS:8008" networks: - external_network - internal_network networks: external_network: internal_network: internal: true ``` 注意点。 - POSTGRES_INITDB_ARGSでエンコーディングとロケールを指定しないとsynapseはエラーを出す。 - SYNAPSE_SERVER_NAMEはあなたのサーバの名前に置き換える。 - ポート指定はnginxからリバースプロキシされたリクエストを受けるアドレスとポートをコンテナ内部の8008に転送するもの。状況にあわせてどうぞ ### generateの実行 generateコマンドを実行して設定ファイルを生成する。 ``` $ cd /somewhere/matrix/matrix1 $ docker-compose run --rm synapse generate ``` 出力はこんな感じ。 ``` Creating network "matrix1_default" with the default driver Creating matrix1_matrix_run ... done Creating log config /data/matrix.juggler.jp.log.config /usr/local/lib/python3.8/site-packages/twisted/conch/ssh/common.py:15: CryptographyDeprecationWarning: int_from_bytes is deprecated, use int.from_bytes instead from cryptography.utils import int_from_bytes, int_to_bytes Generating config file /data/homeserver.yaml Generating signing key file /data/matrix.juggler.jp.signing.key A config file has been generated in '/data/homeserver.yaml' for server name 'matrix.juggler.jp'. Please review this file and customise it to your needs. ``` ### homeserver.yamlの編集 $ cd /somewhere/matrix/data $ cp -a homeserver.yaml homeserver.yaml.orig 編集内容。 ``` $ diff -Naru0 homeserver.yaml.orig homeserver.yaml --- homeserver.yaml.orig 2021-03-07 01:18:59.548334869 +0900 +++ homeserver.yaml 2021-03-07 11:03:48.131579966 +0900 @@ -52 +52 @@ -#public_baseurl: https://example.com/ +public_baseurl: https://matrix.juggler.jp/ @@ -83 +83 @@ -#allow_public_rooms_without_auth: true +allow_public_rooms_without_auth: true @@ -88 +88 @@ -#allow_public_rooms_over_federation: true +allow_public_rooms_over_federation: true @@ -287 +287 @@ -#admin_contact: 'mailto:admin@server.com' +admin_contact: 'mailto:tateisu@gmail.com' @@ -759,0 +760,5 @@ - name: sqlite3 - args: - database: /data/homeserver.db + name: psycopg2 + user: matrix + password: PLEASE_REPLACE_THIS + database: PLEASE_REPLACE_THIS + host: db + cp_min: 5 + cp_max: 10 @@ -1063 +1073 @@ -#recaptcha_public_key: "YOUR_PUBLIC_KEY" +recaptcha_public_key: "PLEASE_REPLACE_THIS" @@ -1068 +1078 @@ -#recaptcha_private_key: "YOUR_PRIVATE_KEY" +recaptcha_private_key: "PLEASE_REPLACE_THIS" @@ -1074 +1084 @@ -#enable_registration_captcha: true +enable_registration_captcha: true @@ -1079 +1089 @@ -#recaptcha_siteverify_api: "https://my.recaptcha.site" +recaptcha_siteverify_api: "https://www.google.com/recaptcha/api/siteverify" @@ -1118 +1128 @@ -#enable_registration: false +enable_registration: true @@ -2225 +2235 @@ - #smtp_host: mail.server - #smtp_port: 587 - #smtp_user: "exampleusername" - #smtp_pass: "examplepassword" + smtp_host: PLEASE_REPLACE_THIS + smtp_port: PLEASE_REPLACE_THIS + smtp_user: "PLEASE_REPLACE_THIS" + smtp_pass: "PLEASE_REPLACE_THIS" @@ -2254 +2264 @@ - #notif_from: "Your Friendly %(app)s homeserver <noreply@example.com>" + notif_from: "%(app)s notifications <noreply@juggler.jp>" @@ -2259 +2269 @@ - #app_name: my_branded_matrix_server + app_name: "matrix.juggler.jp" @@ -2277 +2287 @@ - #client_base_url: "http://localhost/riot" + client_base_url: "http://matrix.juggler.jp/" @@ -2780 +2790 @@ - #enabled: true + enabled: true @@ -2785,2 +2795,2 @@ - #host: localhost - #port: 6379 + host: redis + port: 6379 @@ -2791 +2800,0 @@ ``` - SMTPサーバはお手持ちのものを使う。 - database.psycopg2 の指定はdocker-compose.yml のものと揃える。 ### 起動、終了、ログ確認 ``` $ docker-compose down $ docker-compose up -d $ docker-compose logs --tail=100 -f ``` ---- ## Element-web SynapseにはWebUIが含まれないのでElementを入れる。 - https://github.com/vector-im/element-web 上記リポジトリのリリースのAssetsから .tar.gz へのリンクをコピーしておく。 ``` cd /somewhere/matrix/static wget https://github.com/vector-im/element-web/releases/download/v1.7.22/element-v1.7.22.tar.gz tar xvzf element-v1.7.22.tar.gz cd element-v1.7.22 cp -a config.sample.json config.json ``` config.jsonを編集する。 ``` $ diff -Naru1 config.sample.json config.json --- config.sample.json 2021-03-01 22:20:42.000000000 +0900 +++ config.json 2021-03-07 13:17:12.223214258 +0900 @@ -3,4 +3,4 @@ "m.homeserver": { - "base_url": "https://matrix-client.matrix.org", - "server_name": "matrix.org" + "base_url": "https://matrix.juggler.jp", + "server_name": "Juggler.jp Matrix サービス" }, @@ -34,2 +35,6 @@ "servers": [ + "matrix.fedibird.com", + "matrix-jp.net", + "matrix.sabakan.industries", + "nibbana.jp", "matrix.org" ``` ---- ## nginx - https://github.com/matrix-org/synapse/blob/master/docs/reverse_proxy.md ``` $ cat matrix.juggler.jp.conf server { listen 80; listen [::]:80; server_name matrix.juggler.jp; location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen 8448 ssl http2; # for federation server_name matrix.juggler.jp; ssl_certificate /etc/letsencrypt/live/juggler.jp/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/juggler.jp/privkey.pem; (snip TLS関連のなんやかんや) # Hide nginx version server_tokens off; # Enable compression for JS/CSS/HTML bundle, for improved client load times. # It might be nice to compress JSON, but leaving that out to protect against potential # compression+encryption information leak attacks like BREACH. gzip on; gzip_types text/css application/javascript image/svg+xml; gzip_vary on; # Only connect to this site via HTTPS for the two years add_header Strict-Transport-Security "max-age=63072000"; add_header X-Frame-Options SAMEORIGIN; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Content-Security-Policy "frame-ancestors 'none'"; # Client Well-Known URI location /.well-known/matrix/client { return 200 '{"m.homeserver": {"base_url": "https://matrix.juggler.jp/"}}'; default_type application/json; add_header Access-Control-Allow-Origin *; } # reverse proxy to synapse location ~* ^(\/_matrix|\/_synapse\/client) { proxy_pass http://PLEASE_REPLACE_THIS:PLEASE_REPLACE_THIS; proxy_set_header X-Forwarded-For $remote_addr; # Nginx by default only allows file uploads up to 1M in size # Increase client_max_body_size to match max_upload_size defined in homeserver.yaml client_max_body_size 50M; } root /somewhere/matrix/static/element-v1.7.22; } ``` ---- ## 管理ユーザの作成 ``` docker-compose exec synapse register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008 -u tateisu -p XXXXXXXXX -a ``` - https://github.com/matrix-org/synapse/blob/develop/debian/register_new_matrix_user.ronn でオプションの説明を読める。 - この手順で作るとアカウントのクロス署名が設定されず暗号化メッセージを読めない状態になる。ログイン後にアカウント設定からセットアップできる。[別記事:「このログインを承認」とクロス署名](https://lemmy.juggler.jp/post/761) を参照のこと ---- ## 動作確認 - https://matrix.juggler.jp/_matrix/client/versions をブラウザで開いて、何かJSONぽいものが出力されるか確認する。ダメならnginxのログやsynapseのログを確認する。 - https://matrix.juggler.jp/.well-known/matrix/client をブラウザで開いて、他サーバの同pathの内容と比較する。 - https://matrix.juggler.jp/ を開いてElement-webが表示されるか確認する。 - 管理ユーザとは別にアカウントを作成して、reCAPTCHAやメールアドレス認証が正常に行われるか確認する。 ---- # その他 - [VoIP用にturnサーバを設置してみる](https://lemmy.juggler.jp/post/769)

既存ツールもいくつかあるのだけど、日本のIRCは文字コード事情が「ISO-2022-JPとMS932のちゃんぽん」という特殊なやつが主に使われていた歴史的事情があるので自前ツールで処理してる。 今回そのツールをMatrixにも対応させて、ついでに3方向リレーができるようにした。

VoIP用にturnサーバを設置してみる
https://github.com/matrix-org/synapse/blob/develop/docs/turn-howto.md を読みながらVoIP用のTURNサーバを設置してSynapseから使うよう設定する。 ubuntuのパッケージを使うだけのお手軽版。 ---- ## Turnサーバを用意してUbuntuのパッケージを入れる ##### 試験環境 ``` # cat /etc/issue Ubuntu 20.04.1 LTS \n \l ``` ##### パッケージのインストール ``` # apt-get update # apt install coturn pwgen ``` ---- ## サーバ証明書をコピーする coturnはturnserverユーザの権限でサーバ証明書を読もうとするが、`/etc/letsencrypt/live` はrootしかアクセスできない。 coturnの設定ファイルにproc-user=rootと書くのも試したがcoturnごと落ちるので、 turnserverユーザだけ読める位置に証明書のコピーを置くことにした。 (turnserverユーザ/グループはubuntuのcoturnパッケージのインストール時に作成されます) ``` #/bin/bash set -eux SRCDIR=/etc/letsencrypt/live/juggler.jp DSTDIR=/*********** mkdir -p $DSTDIR cp $SRCDIR/fullchain.pem $SRCDIR/privkey.pem $DSTDIR/ chown -R turnserver:turnserver $DSTDIR chmod -R o-rwx $DSTDIR ``` 証明書更新の度に行う作業が増えたので、手持ちの更新手順書を更新しておく。 ---- ## Turnサーバの設置 ##### 設定ファイルの存在確認 ``` # cd /etc # ls -ld turnserver.conf -rw-r--r-- 1 root root 25983 Dec 14 22:50 turnserver.conf ``` ##### オリジナルの保存 ``` # cp -a turnserver.conf turnserver.conf.orig ``` ##### static-auth-secret の生成 ``` # pwgen -s 64 1 Ohf7hPHTVUp6hWD5RSbiCw897gimqU0FjQrvCspbs4BH842ooRwCEG534UkL1nvN ``` (これはサンプルです。私はこの値を使っていません。) ##### 設定ファイルの編集 ``` # diff -Naru0 turnserver.conf.orig turnserver.conf --- turnserver.conf.orig 2020-12-14 22:50:15.000000000 +0900 +++ turnserver.conf 2021-03-08 10:23:54.468540036 +0900 @@ -18 +18 @@ -#listening-port=3478 +listening-port=3478 @@ -30 +30 @@ -#tls-listening-port=5349 +tls-listening-port=5349 @@ -41 +41 @@ -#alt-listening-port=0 +alt-listening-port=0 @@ -46 +46 @@ -#alt-tls-listening-port=0 +alt-tls-listening-port=0 @@ -54,0 +55 @@ +listening-ip=153.126.151.77 @@ -154 +155 @@ -#verbose +verbose @@ -217 +218 @@ -#use-auth-secret +use-auth-secret @@ -225 +226 @@ -#static-auth-secret=north +static-auth-secret=Ohf7hPHTVUp6hWD5RSbiCw897gimqU0FjQrvCspbs4BH842ooRwCEG534UkL1nvN @@ -339 +340 @@ -#realm=mycompany.org +realm=turn.juggler.jp @@ -352,0 +354 @@ +user-quota=12 # 4 streams per video call, so 12 streams = 3 simultaneous relayed calls per user. @@ -358,0 +361 @@ +total-quota=1200 @@ -403 +406 @@ -#no-tcp-relay +no-tcp-relay @@ -439 +442 @@ -#cert=/usr/local/etc/turn_server_cert.pem +cert=/********/fullchain.pem @@ -446 +449 @@ -#pkey=/usr/local/etc/turn_server_pkey.pem +pkey=/********/privkey.pem @@ -605,0 +609,4 @@ +denied-peer-ip=10.0.0.0-10.255.255.255 +denied-peer-ip=192.168.0.0-192.168.255.255 +denied-peer-ip=172.16.0.0-172.31.255.255 +allowed-peer-ip=153.126.151.77 ``` ##### coturn の再起動 ``` # systemctl restart coturn ``` ##### Listenアドレスとポートの確認 ``` # netstat -nlap |grep turn tcp 0 0 153.126.151.77:3478 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:3478 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:3478 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:3478 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:5349 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:5349 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:5349 0.0.0.0:* LISTEN nnn/turnserver tcp 0 0 153.126.151.77:5349 0.0.0.0:* LISTEN nnn/turnserver sctp 153.126.151.77:3478 LISTEN nnn/turnserver sctp 153.126.151.77:3478 LISTEN nnn/turnserver sctp 153.126.151.77:3478 LISTEN nnn/turnserver sctp 153.126.151.77:3478 LISTEN nnn/turnserver sctp 153.126.151.77:5349 LISTEN nnn/turnserver sctp 153.126.151.77:5349 LISTEN nnn/turnserver sctp 153.126.151.77:5349 LISTEN nnn/turnserver sctp 153.126.151.77:5349 LISTEN nnn/turnserver udp 0 0 153.126.151.77:5349 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:5349 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:5349 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:5349 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:3478 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:3478 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:3478 0.0.0.0:* nnn/turnserver udp 0 0 153.126.151.77:3478 0.0.0.0:* nnn/turnserver unix 2 [ ] DGRAM 16971766 nnn/turnserver ``` turnサーバでの作業はここまで。 ---- ## Synapseサーバの設定変更 ##### homeserver.yamlの編集 (turn関係だけ抜粋) ``` $ diff -Naru0 homeserver.yaml.orig homeserver.yaml --- homeserver.yaml.orig 2021-03-07 01:18:59.548334869 +0900 +++ homeserver.yaml 2021-03-08 10:25:32.221379383 +0900 @@ -1086 +1096,6 @@ -#turn_uris: [] +turn_uris: [ + "turns:turn.juggler.jp?transport=udp", + "turns:turn.juggler.jp?transport=tcp", + "turn:turn.juggler.jp?transport=udp", + "turn:turn.juggler.jp?transport=tcp" +] @@ -1090 +1105 @@ -#turn_shared_secret: "YOUR_SHARED_SECRET" +turn_shared_secret: "Ohf7hPHTVUp6hWD5RSbiCw897gimqU0FjQrvCspbs4BH842ooRwCEG534UkL1nvN" @@ -1100 +1115 @@ -#turn_user_lifetime: 1h +turn_user_lifetime: 1h @@ -1108 +1123 @@ -#turn_allow_guests: true +turn_allow_guests: false ``` ##### Synapseの再起動 ``` $ docker-compose down && docker-compose up -d ``` ---- ## 動作確認 https://test.voip.librepush.net/ で緩いテストが行える。 - voIPテスト用のMatrixユーザを作っておく - サイトURL、ユーザ、パスワードをテストサイトに指定する #### テスト結果 ##### 一回目 エラーとなった。証明書の問題でcoturnがポート5349をListenしていなかった。syslogに警告が出てた。証明書を読める位置にコピーして対応した。 ##### 二回目 ![](https://lemmy.juggler.jp/pictrs/image/HIjsv1sWTo.jpg) TURN onlyでSTUNをサポートしていないと言われた。Synapseの設定にturns: スキーマだけではなく turn: スキーマを追加した。 ##### 三回目 ![](https://lemmy.juggler.jp/pictrs/image/YUZFD5Exvq.jpg) ポート443でもListenすればファイアウォールを越えられるぞと言われたが、悪いな443はnginxに使わせてるんだ。今回は手を加えない。 ---- ## 動作確認(手動) Android端末二つで{Wifi,au} x {Wifi,docomo系NVMO} の組み合わせ4通りで接続を確認した。オッケー!

「このログインを承認」とクロス署名
---- ログイン時に「このログインを承認」が表示される。 - ![PC](https://lemmy.juggler.jp/pictrs/image/62eDtfVV7U.jpg) - ![Android](https://lemmy.juggler.jp/pictrs/image/n7qenReoLt.jpg) ---- しかし選択肢がスキップしかない場合がある。 クロス署名をセットアップすると解決する。 - ![クロス署名](https://lemmy.juggler.jp/pictrs/image/16w8oBhqwT.jpg) ---- クロス署名を設定したら「このログインを承認」でログイン中の他のデバイスを使って承認を行える。 - ![](https://lemmy.juggler.jp/pictrs/image/SmiAi49cH8.jpg) - ![](https://lemmy.juggler.jp/pictrs/image/nHVQDI0pE5.jpg) ---- 管理者ユーザをコマンドラインで作成したからクロス署名が設定されていなかったからこの事案が発生したらしい。

matrix.juggler.jp 運用記録
!mjj
    • 0 users online
    • 1 user / day
    • 1 user / week
    • 1 user / month
    • 1 user / 6 months
    • 6 subscribers
    • 19 Posts
    • 9 Comments
    • Modlog