Files
Paul HittandClaude Fable 5.1 145883fb40 suspend.sh speaks Postgres: the column is a timestamp, not an epoch
Fluent's .datetime is timestamptz on Postgres, so to_timestamp() on it and
assigning extract(epoch from now()) to it both fail. now() in, the column
itself out.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-15 09:05:52 -04:00

37 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Suspend an account on this relay, or lift a suspension.
#
# A suspended account cannot sign in, cannot mint a credential, and every
# request it makes with a credential it already holds is refused with
# account_suspended. Its messages, keys and devices are untouched: this is a
# door, not a deletion, and lifting it puts everything back.
#
# Scripts/suspend.sh <handle> suspend
# Scripts/suspend.sh <handle> --lift lift
# Scripts/suspend.sh --list who is suspended, and since when
set -euo pipefail
cd /srv/prod/messenger
q() { docker compose exec -T db psql -U flamenet -d flamenet -qAt -c "$1"; }
if [ "${1:-}" = "--list" ]; then
echo "== suspended accounts =="
q "select username || ' ' || suspended_at from users where suspended_at is not null order by suspended_at;"
exit 0
fi
handle="${1:?usage: suspend.sh <handle> [--lift] | --list}"
handle="$(printf '%s' "$handle" | tr '[:upper:]' '[:lower:]')"
safe="${handle//\'/\'\'}"
id=$(q "select id from users where username = '${safe}';")
[ -n "$id" ] || { echo "no account named $handle" >&2; exit 1; }
if [ "${2:-}" = "--lift" ]; then
q "update users set suspended_at = null where id = ${id};" >/dev/null
echo "lifted: $handle (user $id) can sign in again"
else
q "update users set suspended_at = now() where id = ${id} and suspended_at is null;" >/dev/null
echo "suspended: $handle (user $id). Lift with: Scripts/suspend.sh $handle --lift"
fi