Share
Embed
ActivityPub Server の snac その3
発表:: 鹿児島Linux勉強会 2025.12(オンライン開催) https://kagolug.connpass.com/event/376238/
source:: https://codeberg.org/matoken/kagolug-2025.12/src/branch/main/slide/slide.adoc
Kenichiro MATOHARA
December 21, 2025
Transcript
45 slides
-
鹿児島の右下の山奥から参加 好きなLinuxディストリビューションは Debian GNU/Linux ActivityPub @ @ matrix @matoken:matrix.org Signal
matoken.256 map: © OpenStreetMap contributors Kenichiro Matohara(matoken) https://matoken.org [email protected] [email protected] 2 -
最近 さくらインターネットのさくらのナレッジにsnacの記事を寄稿さくらイ ンターネットのさくらのナレッジにsnacの記事を寄稿 なんとなく12月に入ってからblog 毎日更新中‥‥(1日遅刻) 内11記事がsnacネタ クッションテーブル購入,WebCam新調 Logicool C310 →
eMeet C960(思ったよりでかい!) さくらのVPSで試す、軽量ActivityPub実装「snac」によるセル フホストSNS構築 | さくらのナレッジ https://matoken.org/blog/tag/snac/ 3 -
最近軽量なActivityPub実装のsnac を利用 軽量,依存関係が最小限 マルチユーザー,コマンドラインで操作可能 データベース,JavaScript,Cookies なし Mastodon API のサポート →
Mastodon アプリが利用可能 開発も活発 有料ホスティングサービスもあり $2.75/mo grunfink/snac2: A simple, minimalistic ActivityPub instance written in portable C - Codeberg.org Snac2 Hosting and Support | K&T Host 5 -
最近のsnac カスタマイズなど robots.txt Welcome pageのhtmlファイルカスタマイズ Welcome pageを設定ファイルでカスタマイズ themeを設定 通知 自動投稿
Bluesky連携 SPAM対策 サーバーブロック 8 -
source を確認 httpd.c の中でハードコーディングされている $ grep -n -A5 robots.txt httpd.c
321: if (strcmp(q_path, "/robots.txt") == 0) { 322- status = HTTP_STATUS_OK; 323- *ctype = "text/plain"; 324- *body = xs_str_new("User-agent: *\n" 325- "Disallow: /\n"); 326- } 11 -
issues — httpd proxy 側でカスタマイズするなどできるしということで恐らく snac 側では修正されない Actually, I am
able to work around this by returning a custom robots.txt with nginx: location = /robots.txt { return 200 'User-agent: FediFetcher\nAllow: /\nUser-agent: *\nDisallow: /\n'; } #223 - default robots.txt breaks integration with fedi- fetcher - grunfink/snac2 - Codeberg.org 12 -
source 書き換え(robots.txtを削る) $ git diff httpd.c diff --git a/httpd.c b/httpd.c
index a8cd849..976fdd6 100644 --- a/httpd.c +++ b/httpd.c @@ -318,13 +318,6 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = xs_json_dumps(j, 4); } else - if (strcmp(q_path, "/robots.txt") == 0) { - status = HTTP_STATUS_OK; - *ctype = "text/plain"; - *body = xs_str_new("User-agent: *\n" - "Disallow: /\n"); - } - else if (strcmp(q_path, "/style.css") == 0) { FILE *f; xs *css_fn = xs_fmt("%s/style.css", srv_basedir); 13 -
source 書き換え(robots.txt 全て許 可に書き換え) $ git diff httpd.c diff --git
a/httpd.c b/httpd.c index a8cd849..c0bcaef 100644 --- a/httpd.c +++ b/httpd.c @@ -322,7 +322,7 @@ int server_get_handler(xs_dict *req, const char *q_path, status = HTTP_STATUS_OK; *ctype = "text/plain"; *body = xs_str_new("User-agent: *\n" - "Disallow: /\n"); + "Allow: /\n"); } else if (strcmp(q_path, "/style.css") == 0) { 15 -
Apache2 httpd でLinuxファイルシ ステム上のrobots.txt に差し替え る /var/lib/snac2/robots.txt が /robots.txt になるはず
$ sudo git diff /etc/apache2/sites-available/011-snac.kagolug.org.conf diff --git a/apache2/sites-available/011-snac.kagolug.org.conf b/apache2/sites-available/011-snac.kagolug.org.conf index f5b5c7f..7bb72c1 100644 --- a/apache2/sites-available/011-snac.kagolug.org.conf +++ b/apache2/sites-available/011-snac.kagolug.org.conf @@ -58,6 +58,11 @@ </Location> Alias /static /var/www/static + Alias /robots.txt /var/lib/snac2/robots.txt + <Location "/robots.txt"> + ProxyPass ! + Require all granted + </Location> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. 17 -
Apache2 httpd 反映 このファイルが, /robots.txt に反映 source 書き換えより手間なく,robots.txt の編集も容易なのでこ ちらを採用
$ sudo apache2ctl configtest $ sudo systemctl reload apache2 $ sudo -u www-data cat /var/lib/snac2/robots.txt User-agent: * Allow: / $ w3m -dump https://snac.kagolug.org/robots.txt User-agent: * Allow: / 18 -
Welcome pageのhtmlファイルカス タマイズ で挨拶ページが表示される. https://snac.kagolug.org/ $ w3m -dump https://snac.kagolug.org/ snac.kagolug.org
is a Fediverse instance that uses the ActivityPub protocol. In other words, users at this host can communicate with people that use software like Mastodon, Pleroma, Friendica, etc. all around the world. This server runs the snac software and there is no automatic sign-up process. The following users are part of this community: @[email protected] (info) @[email protected] (matoken) This site is powered by snac. 20 -
site名や参加ユーザ一覧も $SNAC_BASEDIR/greeting.html を表示しているのでこれを書き換える ことでカスタマイズできる <!DOCTYPE html> <html><head> <meta name="viewport" content="width=device-width,
initial-scale=1"/> <link rel="icon" type="image/x-icon" href="https://%host%/favicon.ico"/> <style>*{color-scheme:light dark}body{margin:auto;max-width:50em}</style> <title>Welcome to %host%</title> </head> <body> <p><b>%host%</b> is a <a href="https://en.wikipedia.org/wiki/Fediverse">Fediverse</a> instance that uses the <a hr <p>This server runs the <a href="https://comam.es/what-is-snac">snac</a> software and there is no automatic sign-u <p>The following users are part of this community:</p> %userlist% <p>This site is powered by <abbr title="Social Networks Are Crap">snac</abbr>.</p> </body></html> 21 -
日本語化例 $ w3m -dump https://snac.kagolug.org/ snac.kagolug.orgはActivityPubプロトコルを利用したFediverseインスタンスです.こ のホストのユーザーは世界中のMastodon, Pleroma, Friendica, などのソフトウェアを
利用している人々とコミニュケーションを取ることが出来ます. このサーバーはsnac ソフトウェアを利用しています.自動登録プロセスはありません. 以下のユーザーがこのコミュニティに参加しています: • @[email protected] (info) • @[email protected] (matoken) This site is powered by snac. 22 -
show_instance_timeline 最新のユーザーが投稿したタイムラインを表示 admin_email インスタンス管理者の電子メールアドレス admin_account インスタンス管理者のアカウント title インスタンスのタイトル short_description インスタンスに対する短い説明
short_description_raw short_description を生として解釈するか,HTML に変換する か 25 -
設定例 $ grep -A5 show_instance_timeline snac-data/server.json "show_instance_timeline": true, "admin_email": "",
"admin_account": "matoken", "title": "<F0><9F><90><88><F0><9F><90><88><F0><9F><90><88>", "short_description": "matokenの個人ActivityPub インスタンスです.", "short_description_raw": false, 26 -
README.md の Incredibly awesome CSS themes for snac 部分にいく つかのtheme
が紹介されている $ grep -A5 'Incredibly awesome CSS themes for snac' README.md ## Incredibly awesome CSS themes for snac - [A compilation of themes for snac (by Во )](https://codeberg.org/voron/snac-style). - [A cool, elegant theme (by Haijo7)](https://codeberg.org/Haijo7/snac-custom-css). - [A terminal-like theme (by Tetra)](https://codeberg.org/ERROR404NULLNOTFOUND/snac-terminal-theme). 31 -
e-mail snacサーバーのメールシステムが設定済であればユーザーの「User Settings… 」から「Email address for notifications:」に宛先の e-main address を入力するることで利用可能
メールシステムの設定がされていなかったり,外部のメールシステムを 利用したい場合 server.json を設定することでもメールが送信が可 能 — snac(8)より smtp_url Since version 2.76, email notifications can be sent via direct connection to an SMTP se sage to /usr/sbin/sendmail. Set this value to the SMTP url to be used for sending emai clude a port number if it's not running on the usual one, like in smtp://mail.example.c smtp_user smtp_password To be filled if the SMTP server defined by the previous directive needs credentials. 35 -
Telegram Telegram bot とチャンネルを自分で作成して利用する必要がある ので初期設定が面倒 Telegram bot が作成できたら各ユーザの「User Settings… 」の
「Telegram notifications (bot key and chat id):」に設定す ることで利用可能 Nextcloud 14 の Telegram を使った2要素認証 – matoken’s blog 36 -
ntfy OSS でセルフホスト可能でウェブブラウザやスマートフォンに通知が できるサービス及びソフトウェア セルフホスト可能だが,とりあえずntfy.sh の無料アカウントを利用し て試すと良さそう 「User Settings… 」の「ntfy
notifications (ntfy server and token):」に設定 ntfy.sh | Send push notifications to your phone via PUT/POST 37 -
Webhook 色々なサービスが対応しているWebhook も利用可能 例えばDiscord であれば,「チャンネルの編集」→「連携サービス」→ 「ウェブフックを作成」で生成されるURL を「User Settings… 」の 「Notify
webhook:」に入力 Webhook には各種変数が利用可能 man(1) の`Webhook for notifications` を参照 38 -
Mastodon アプリケーションでの 通知 snac はMastodon API に対応していて,(大抵の)Mastodon ア プリケーションが利用可能 Mastodon
アプリケーションの通知機能を使って通知を受けること が可能 39 -
snac note コマンド snac の動作している環境で実行できるのであればsnac のnote コ マンドが利用可能 添付ファイルなども利用可能 →
man(1) を参照 man(1) にある例を真似してみる 認証等はないので基本サーバ管理者以外には使えない感じ $ uptime | pee "./snac note snac-test test -" cat 23:32:36 up 4 days, 10:17, 1 user, load average: 1.56, 1.90, 1.69 23:32:36 [test] enqueue_message http://127.0.0.1:8001/test/p/1766154756.511450/Create 8 /� 42 -
Mastodon API で投稿 アクセストークンを取得してcurl コマンドで投稿してみる 次のページで認証情報を入力 次のようなトークンが帰ってくる 1f3ea50e9ab7cc85f5ff01b8f43fb1ae curl コマンドで投稿.JSON
で返り値が帰ってくる https://$SNAC_HOST/oauth/x-snac-get-token $ curl -X POST http://127.0.0.1:8001/api/v1/statuses --header \ "Authorization: Bearer 1f3ea50e9ab7cc85f5ff01b8f43fb1ae" \ -d "status=$(uptime)" 43 -
Bluesky連携 ポストTwitter の一つでAT Protocol を利用した分散型SNS の Bluesky とsnac をBridgy Fed
というブリッジサービスを利用し て連携 Bridgy Fed 45 -
ActivityPub から連携するには で 認証後,「Enable」ボタンを押すとなっているが,ログインしてもボタ ンが見当たらない snac の該当アカウントで @ を follow,follow
が返されるので許可すると連携される 連携元アカウントが, @[user]@[instance] の場合Bluesky ブリ ッジアカウントのハンドルは [user].[instance].ap.brid.gy にな る ブリッジアカウントの削除を行いたい場合は,Bridgy Fedボットユー ザー( @ )をブロックすることで削除 できる https://fed.brid.gy/login [email protected] [email protected] 46 -
SPAM対策 snac では2つの対策がある アカウント作成から日の浅いアカウントを拒否 server.json で設定できる min_account_age で,投稿を受け付け るアカウントが作成されてからの時間が設定 寝かせてから運用したり,アカウントの作成日を返さない実装もあ
るらしいのであまり役に立たないらしい 投稿内容を正規表現でフィルタリング $SNAC_BASEDIR/filter_reject.txt を用意してこのファイル中に1 行ずつ正規表現で拒否内容を記述できる 48 -
その他 httpd を apachw2 httpd から lighttpd あたりに変更したい (多分軽くなる) FastCGI化(アクセスが少ないと有利そう)
Relay Server インスタンス移行機能 build option の変更 key.json bug 表示上のbug 51 -
奥付 発表 発表者 2025-12- 21(sun) 利用ソフトウェア NeoVim + textlint +
ライセンス 鹿児島Linux勉強会 2025.12(オンライン開催) Kenichiro Matohara(matoken) Asciidoctor Reveal.js CC BY 4.0 53