diff --git a/register-matrix-bot.sh b/register-matrix-bot.sh index 5f1131e..5b714e1 100755 --- a/register-matrix-bot.sh +++ b/register-matrix-bot.sh @@ -46,7 +46,20 @@ ROOM_ID="$(cfg_get "['matrix'].get('room_id','')" 2>/dev/null || echo "")" # localpart from @maintainer-bot:semprini.me -> maintainer-bot BOT_LOCAL="${BOT_USER_ID#@}"; BOT_LOCAL="${BOT_LOCAL%%:*}" -echo "→ Homeserver : $HOMESERVER" +# Traefik refuses /_synapse/admin/* at the edge (semprini-core SR-05: it was +# reachable from the public internet). Talk to Synapse's own container address +# on semprini_internal instead, the same way scripts/setup-matrix-alerts.py +# does in semprini-core — this script already runs on the host with docker +# access. Only the admin API is guarded, so plain /_matrix/client/* calls +# (whoami, createRoom, profile) would work fine through $HOMESERVER too, but +# using the same base for both keeps this script off Traefik entirely. +SYNAPSE_IP="$(docker inspect -f \ + '{{with index .NetworkSettings.Networks "semprini_internal"}}{{.IPAddress}}{{end}}' \ + "$SYNAPSE_CONTAINER")" +[ -n "$SYNAPSE_IP" ] || { echo "ERROR: $SYNAPSE_CONTAINER has no semprini_internal address"; exit 1; } +API_BASE="http://$SYNAPSE_IP:8008" + +echo "→ Homeserver : $HOMESERVER (admin API via $API_BASE)" echo "→ Bot : $BOT_USER_ID" echo "→ Admin : $ADMIN_USER_ID" @@ -61,7 +74,7 @@ SHARED_SECRET="$(docker exec "$SYNAPSE_CONTAINER" \ # All the Matrix work happens in one Python block (stdlib only): ensure the bot # has a valid standalone access token, ensure the room, and write # access_token + room_id back into config.json. -python3 - "$CONFIG" "$HOMESERVER" "$SHARED_SECRET" "$BOT_LOCAL" "$BOT_USER_ID" "$ADMIN_USER_ID" "$ROOM_ID" <<'PY' +python3 - "$CONFIG" "$API_BASE" "$SHARED_SECRET" "$BOT_LOCAL" "$BOT_USER_ID" "$ADMIN_USER_ID" "$ROOM_ID" <<'PY' import hmac, hashlib, json, secrets, sys, urllib.request, urllib.error config, hs, shared, bot_local, bot_id, admin_id, room_id = sys.argv[1:8]