# BWT: bash web token bwt_sign() { data=$( #include #include #include int main(int argc, char **argv) { if (argc != 3) error(1, EINVAL, "expected exactly 2 arguments, got %d", argc - 1); int result = argon2id_verify(argv[1], argv[2], strlen(argv[2])); if (result == ARGON2_OK) return 0; else return 1; }') "${1?need hash}" "$(%s' "$(escape <<< "${1?}")" } info_box() { printf '
%s
' "$(escape <<< "${1?}")" } parse_posts() { pipe=$(mktemp -u) mkfifo "$pipe" for instance in "$@"; do { name=$(jq -r .name <<< "$instance") endpoint=$(jq -r .feed <<< "$instance") echo "requesting feed from instance ${name@Q}" >&2 curl -fsSL "$endpoint" | jq -r ".[] | .[5] |= $(jq -Rr @json <<< "$name") | @json" >> "$pipe" echo "feed from ${name@Q} consumed" >&2 } & done jq -sr 'sort_by(.[2] | sub(" "; "T") | sub("$"; "Z") | fromdate | -.) | .[] | "([username]=" + (.[1] | @html | @sh) + " [timestamp]=" + (.[2] | @html | @sh) + " [contents]=" + (.[0] | @html | @sh) + " [instance]=" + (.[5] | @html | @sh) + ")"' < "$pipe" wait || : rm "$pipe" } json_err() { printf '%s' "$1" | jq -R '{ error: true, reason: (if . == "" then null else . end) }' } check_token() { if ! verified=$(bwt_verify <<< "$1"); then printf 'invalid' return 1 fi till=$(jq -r '.till' <<< "$verified") now=$(date '+%s') if (( till < now )); then printf 'expired' return 1 fi printf '%s' "$verified" }