#!/usr/bin/env bash # Outside-in public HTTPS checks (no SSH). set -euo pipefail ROOT=$(cd "$(dirname "$0")" && pwd) # shellcheck source=lib.sh source "$ROOT/lib.sh" # Area www-### — public HTTPS (outside-in) set_area www section "www · public URLs · ${TALER_DOMAIN:-?} (outside-in, no SSH)" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT check_url() { local label="$1" expect="$2" url="$3" local code code=$(http_code "$url") case ",$expect," in *",$code,"*) ok "$label $url" ;; *) fail "$label $url" "got $code want $expect" ;; esac } # Soft check: OK on expect, WARN on foreign stack if down, ERROR on local stack check_url_soft() { local label="$1" expect="$2" url="$3" local code code=$(http_code "$url") case ",$expect," in *",$code,"*) ok "$label $url" ;; *) if [ "${LOCAL_STACK:-1}" = "0" ]; then warn "$label $url" "got $code (optional on remote domain)" else fail "$label $url" "got $code want $expect" fi ;; esac } expect_currency() { local label="$1" file="$2" want="${EXPECT_CURRENCY:-}" local cur cur=$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1])).get("currency",""))' "$file" 2>/dev/null || true) if [ -z "$want" ]; then info "$label currency" "${cur:-?}" return fi if [ "$cur" = "$want" ]; then ok "$label currency=$want" else fail "$label currency" "got ${cur:-?} want $want" fi } # Legal docs: /terms and /privacy must be HTTP 200 with a real document body # (not empty, not "not configured", not JSON API error). # $1=label $2=url $3=optional needle regex (case-insensitive) for local stack check_legal_doc() { local label="$1" url="$2" needle="${3:-}" local f code soft soft=0 [ "${LOCAL_STACK:-1}" = "0" ] && soft=1 f=$(mktemp) code=$(curl -skS --max-redirs 5 -L -m "${TIMEOUT}" \ -H "Accept: text/html,text/markdown,text/plain,*/*" \ -o "$f" -w '%{http_code}' "$url" 2>/dev/null || echo 000) if [ "$code" != "200" ]; then rm -f "$f" if [ "$soft" = "1" ]; then warn "$label" "HTTP $code — $url" else fail "$label" "HTTP $code — $url" fi return fi if [ ! -s "$f" ]; then rm -f "$f" fail "$label" "empty body — $url" return fi # merchant returns plain "not configured" when PRIVACY_ETAG missing if grep -qiE '^(not configured)\s*$' "$f" 2>/dev/null \ || grep -qiE '"code"\s*:\s*21' "$f" 2>/dev/null; then rm -f "$f" fail "$label" "not configured / API error — $url" return fi if [ -n "$needle" ] && [ "${LOCAL_STACK:-1}" = "1" ]; then if ! grep -qiE "$needle" "$f" 2>/dev/null; then warn "$label content" "missing /$needle/ — $url" rm -f "$f" return fi fi ok "$label" "HTTP 200 · $(wc -c <"$f" | tr -d ' ') bytes" rm -f "$f" } # --- exchange (core; always required) --- www-001 … check_url "exchange /config" 200 "$EXCHANGE_PUBLIC/config" code=$(http_body "$EXCHANGE_PUBLIC/config" "$tmp/ec.json") if [ "$code" = "200" ]; then expect_currency "exchange" "$tmp/ec.json" # currency_specification.alt_unit_names (wallet codec) if json_has_alt_unit_names "$tmp/ec.json" "${EXPECT_CURRENCY:-}" >/tmp/alt-ex.$$ 2>&1; then ok "exchange /config alt_unit_names" "$(tr '\n' '; ' /tmp/alt-bank.$$ 2>&1; then ok "bank /config alt_unit_names" "$(tr '\n' '; ' /tmp/alt-mer.$$ 2>&1; then ok "merchant /config currencies alt_unit_names" "$(tr '\n' '; '