dashPi: a self-hosted home dashboard, its sync server and phone app

The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end
encrypted sync mailbox (PHP + SQLite) and the Android companion app
(Flutter), with docs, clean-install checks and screenshots made from
demo data.

Built mostly with an AI coding assistant; not yet reviewed line by line
by a human (see README and SECURITY.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-10-24 09:35:12 +02:00
commit fb3c01cdd7
333 changed files with 45151 additions and 0 deletions

41
tests/clean-install.sh Executable file
View file

@ -0,0 +1,41 @@
#!/bin/bash
# The dashboard from scratch, the way docs/dashboard.md says, in clean Debian containers (Docker):
# install.sh, every plugin on, then every page and the food search must answer, and a foreign Host is refused.
#
# tests/clean-install.sh Debian 12 (bookworm) and 13 (trixie)
# tests/clean-install.sh debian:trixie just that one
set -euo pipefail
REPO=$(cd "$(dirname "$0")/.." && pwd)
IMAGES=("${@:-debian:bookworm}"); [ $# -gt 0 ] || IMAGES=(debian:bookworm debian:trixie)
INSIDE='
set -e
cp -r /repo /tmp/repo && cd /tmp/repo/dashboard && rm -rf __pycache__
./install.sh --headless --no-service --user dash > /tmp/install.log 2>&1 || { tail -30 /tmp/install.log; exit 1; }
apt-get install -y -qq curl > /dev/null 2>&1
python3 - <<PY
import json; p = "/opt/dashboard/dash_config.json"; c = json.load(open(p))
for n in ("health", "food", "cycle", "workload", "activity", "notes"):
c.setdefault("plugins", {}).setdefault(n, {})["enabled"] = True
json.dump(c, open(p, "w"))
PY
cd /opt/dashboard && su -s /bin/bash dash -c "python3 dash.py --headless > /tmp/dash.log 2>&1 &"
for i in $(seq 30); do curl -s -o /dev/null http://127.0.0.1:8080/login && break; sleep 1; done
fail=0
for p in / /settings /weather /stations /week /month /health /health/sleep /food /cycle /work /activity /notes /app /login; do
code=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: localhost" http://127.0.0.1:8080$p)
[ "$code" = 200 ] || { echo "FAIL $p → $code"; fail=1; }
done
code=$(curl -s -o /dev/null -w "%{http_code}" -H "Host: evil.example" http://127.0.0.1:8080/)
[ "$code" = 400 ] || { echo "FAIL a foreign Host got $code (want 400)"; fail=1; }
n=$(curl -s -H "Host: localhost" "http://127.0.0.1:8080/food/api/foods?q=apple" | python3 -c "import json,sys; print(len(json.load(sys.stdin)[\"db\"]))")
[ "$n" -gt 0 ] || { echo "FAIL the food search found nothing"; fail=1; }
grep -q Traceback /tmp/dash.log && { echo "FAIL tracebacks in the log:"; grep -B2 -A12 Traceback /tmp/dash.log | head -60; fail=1; }
echo "python $(python3 -c "import sys; print(sys.version.split()[0])") · $(grep -c "plugin .*loaded" /tmp/dash.log) plugins loaded"
exit $fail
'
status=0
for img in "${IMAGES[@]}"; do
echo "== $img"
if docker run --rm -v "$REPO":/repo:ro "$img" bash -c "$INSIDE"; then echo "ok"; else echo "FAILED"; status=1; fi
done
exit $status

70
tests/server-setup.sh Executable file
View file

@ -0,0 +1,70 @@
#!/bin/bash
# The sync server from scratch, the way docs/server.md says (bin/setup-server.sh with Apache), in a clean
# Debian container — certbot left out (no public name here). Checks: no token → 401, the printed token
# works, data/ isn't reachable from the web. Leaves it running on http://127.0.0.1:18080 with --keep
# (then: docker rm -f dash-sync-test), e.g. to connect a test dashboard to it.
set -euo pipefail
REPO=$(cd "$(dirname "$0")/.." && pwd)
KEEP=0; [ "${1:-}" = --keep ] && KEEP=1
docker rm -f dash-sync-test > /dev/null 2>&1 || true
docker run -d --name dash-sync-test -p 18080:80 -v "$REPO":/repo:ro debian:bookworm sleep infinity > /dev/null
trap '[ $KEEP = 1 ] || docker rm -f dash-sync-test > /dev/null' EXIT
docker exec dash-sync-test bash -c '
set -e
apt-get update -qq > /dev/null && apt-get install -y -qq apache2 libapache2-mod-php php-sqlite3 php-cli sudo curl rsync > /dev/null 2>&1
printf "#!/bin/sh\napache2ctl -k graceful\n" > /usr/local/bin/systemctl && chmod +x /usr/local/bin/systemctl
mkdir -p /etc/letsencrypt/live/sync.test # stands in for certbot
apache2ctl start
rsync -a /repo/server/ /srv/dash-sync/
bash /srv/dash-sync/bin/setup-server.sh sync.test me > /tmp/setup.log 2>&1
a2dissite -q 000-default && apache2ctl -k graceful' > /dev/null
TOKEN=$(docker exec dash-sync-test grep -oE '^ +[A-Za-z0-9_-]{40,}$' /tmp/setup.log | head -1 | tr -d ' ')
sleep 1
fail=0
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:18080/v1/hello)
[ "$code" = 401 ] || { echo "FAIL no token → $code (want 401)"; fail=1; }
hello=$(curl -s -H "Authorization: Bearer $TOKEN" http://127.0.0.1:18080/v1/hello)
echo "$hello" | grep -q '"device":"dashboard"' || { echo "FAIL the token: $hello"; fail=1; }
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:18080/../data/sync.db)
[ "$code" != 200 ] || { echo "FAIL data/sync.db is reachable"; fail=1; }
# many devices at once: 60 batches, 8 new devices and 20 reads in parallel must all succeed (no "database is locked")
# — on a throw-away account, so the 'dashboard' token above stays clean for a test dashboard
docker exec dash-sync-test bash -c 'sudo -u www-data php /srv/dash-sync/bin/admin.php add-account load > /dev/null
sudo -u www-data php /srv/dash-sync/bin/admin.php add-device load loader' > /tmp/dash-load-token.$$ 2>&1
LOAD=$(grep -oE '[A-Za-z0-9_-]{40,}' /tmp/dash-load-token.$$ | head -1); rm -f /tmp/dash-load-token.$$
python3 - "$LOAD" <<'PY' || fail=1
import os, sys, urllib.request, concurrent.futures as cf
T, B = sys.argv[1], "http://127.0.0.1:18080"
def call(kind):
h = {"Authorization": "Bearer " + T}
if kind == "batch":
req = urllib.request.Request(B + "/v1/batches", data=b"DS1\0" + os.urandom(4000), headers=h)
elif kind == "dev":
req = urllib.request.Request(B + "/v1/devices", data=b'{"name":"d%d"}' % int.from_bytes(os.urandom(3), "big"),
headers=dict(h, **{"Content-Type": "application/json"}))
else:
req = urllib.request.Request(B + "/v1/batches?after=0&limit=5", headers=h)
try:
return urllib.request.urlopen(req, timeout=60).status
except urllib.error.HTTPError as e:
return e.code
key = urllib.request.Request(B + "/v1/key", data=b'{"v":1,"salt":"x","nonce":"x","box":"x"}', # a dummy key: the
headers={"Authorization": "Bearer " + T}, method="PUT") # loader manages devices
urllib.request.urlopen(key, timeout=30)
with cf.ThreadPoolExecutor(30) as ex:
codes = list(ex.map(call, ["batch"] * 60 + ["dev"] * 8 + ["get"] * 20))
bad = [c for c in codes if c != 200]
get = lambda path: __import__("json").loads(urllib.request.urlopen(urllib.request.Request(B + path, headers={"Authorization": "Bearer " + T}), timeout=30).read())
latest, devices = get("/v1/hello")["latest"], len(get("/v1/devices")["devices"])
if bad:
print(f"FAIL {len(bad)} of {len(codes)} parallel requests failed: {sorted(set(bad))}")
elif latest < 60 or devices < 9: # answered 200, but was it kept? (a rolled-back write says ok too)
print(f"FAIL not kept: {latest} batches (want 60), {devices} devices (want 9)")
bad = [0]
else:
print(f"{len(codes)} parallel requests ok, all kept")
sys.exit(1 if bad else 0)
PY
[ $fail = 0 ] && echo "ok — token for the device 'dashboard': $TOKEN"
[ $KEEP = 1 ] && echo "running on http://127.0.0.1:18080 (docker rm -f dash-sync-test)"
exit $fail