#!/bin/bash # # Purpose : The Matrix server Hermes' gateway talks to, and whether you've let # its sandbox reach it. Source this file; used by sandbox/setup.sh, # configure hermes and a migration. # # Hermes' settings (~/.hermes/.env) name the server, but Hermes can change them # from inside its sandbox, so they say only what Hermes wants to reach. The # server it may reach is in your own hermes.json, which no sandbox can write; # configure hermes asks you before adding it there. HERMES_ENV="$HOME/.hermes/.env" HERMES_SANDBOX_CONF="$HOME/.config/coredesktop/sandbox/hermes.json" # The host in MATRIX_HOMESERVER, e.g. matrix.example.org, or nothing. Only a # plain host name or IPv4 address counts, so it can't be a wildcard or carry # characters that would change what a terminal shows when it's asked about. hermes_homeserver() { local host host="$(sed -nE "s#^MATRIX_HOMESERVER=[\"']?https?://([^/:\"']+).*#\1#p" "$HERMES_ENV" 2> /dev/null | head -n 1)" [[ "$host" =~ ^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$ ]] && echo "$host" } # hermes_homeserver_allowed HOST: true if Hermes' sandbox may reach HOST hermes_homeserver_allowed() { [ -n "$1" ] && jq -e --arg host "$1" '(.network.allowedDomains // []) | index($host) != null' \ "$HERMES_SANDBOX_CONF" > /dev/null 2>&1 } # hermes_allow_homeserver HOST: let Hermes' sandbox reach HOST hermes_allow_homeserver() { source "${COREDESKTOP:-$HOME/.local/share/coredesktop}/configure.d/lib/json.sh" edit_json "$HERMES_SANDBOX_CONF" '{}' --arg host "$1" \ '.network.allowedDomains = ((.network.allowedDomains // []) - [$host] + [$host])' }