Everything on this site so far has been a file built from git. This is the first component that runs code to answer a request and the first whose data git does not hold, so the trade is stated in the README and the backup script is not optional. Roles are owner, admin and user. The owner is seeded once from BOARD_OWNER and cannot be seeded again, because otherwise editing a compose file would be a quieter way to take the top role than asking for it; ownership moves only by transfer, inside the app. There is exactly one owner and a partial unique index enforces it, so the invariant holds even when a handler is wrong. The owner is beyond suspension and demotion by everyone, themselves included. Only the owner makes admins; admins make users. Sign-in goes through Gitea as a confidential OAuth client — the opposite of Decap, which has to be public because it runs in the browser. The rule the whole thing rests on is that a Gitea account is not a membership: entry needs an active row in `members`, or every account on the instance is a member, starting with the translations bot. Admins can delete any post; nobody can edit anyone else's, admins included. Taking a post down is visible to its author. Quietly rewriting it is not, and an admin who could do that could leave a sentence attributed to someone who never wrote it. The plan said admins could do both; this is the one place the implementation departs from it. Markdown renders with raw HTML disabled, which is the entire XSS defence and the reason there is no sanitiser: the renderer emits only its own tags and escapes the rest. The CSP carries no 'unsafe-inline', which makes an inline onsubmit silently inert rather than broken, so the confirmation dialogs live in a static file and a test fails any template that grows an inline handler. GDPR is in scope rather than deferred: erasure removes the member row and moves their authorship to a tombstone so the conversations around them still read, and any member can download their own writing. Verified: 63 checks pass, covering the membership gate, every role predicate, a direct insert of a second owner being refused by the index, atomic ownership transfer, CSRF, an offsite login redirect, script tags rendering as text, soft deletes leaving both listings and exports, and the member screens rendering for each role. Smoke-tested live: headers, both static assets, and the bare /comunidad redirect that the Caddy matcher has to cover. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NizVpJ2dwzCbjCrTLCjeHn
45 lines
1.6 KiB
Bash
Executable File
45 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Back up the members-area database.
|
|
#
|
|
# This is the only data on the server that git does not already hold. The site,
|
|
# the content, the translations and every config file can be rebuilt from the
|
|
# repository; the board's threads, comments and membership cannot. Losing the
|
|
# file loses the lot.
|
|
#
|
|
# Run nightly from cron, as the user owning /srv/board/data:
|
|
# 15 4 * * * /home/pablo/vienalatina/scripts/backup-board.sh >> /var/log/board-backup.log 2>&1
|
|
#
|
|
# bash scripts/backup-board.sh # -> /srv/board/backups
|
|
# bash scripts/backup-board.sh /mnt/elsewhere # -> somewhere else
|
|
|
|
set -euo pipefail
|
|
|
|
DB="${BOARD_DB:-/srv/board/data/board.db}"
|
|
DEST="${1:-/srv/board/backups}"
|
|
KEEP_DAYS="${KEEP_DAYS:-30}"
|
|
STAMP="$(date -u +%Y%m%dT%H%M%SZ)"
|
|
|
|
if [ ! -f "$DB" ]; then
|
|
echo "No database at $DB — nothing to back up." >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$DEST"
|
|
|
|
# `.backup` rather than `cp`: the app is running, and SQLite in WAL mode keeps
|
|
# recent writes in a side file. Copying board.db on its own can capture a
|
|
# database missing its most recent commits, or mid-checkpoint and unreadable.
|
|
# The backup API takes a consistent snapshot of a live database.
|
|
sqlite3 "$DB" ".backup '$DEST/board-$STAMP.db'"
|
|
gzip -f "$DEST/board-$STAMP.db"
|
|
|
|
# Prove it: a corrupt backup discovered during a restore is not a backup.
|
|
if ! gzip -t "$DEST/board-$STAMP.db.gz"; then
|
|
echo "Backup failed its own integrity check — keeping it for inspection." >&2
|
|
exit 1
|
|
fi
|
|
|
|
find "$DEST" -name 'board-*.db.gz' -mtime "+$KEEP_DAYS" -delete
|
|
|
|
echo "$(date -u +%FT%TZ) wrote $DEST/board-$STAMP.db.gz ($(du -h "$DEST/board-$STAMP.db.gz" | cut -f1))"
|