Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.git
.jj
.claude
.env
ref
bin
.settings
.classpath
.project
.github
.vscode
build
Expand All @@ -15,4 +23,5 @@ secrets
LICENSE
README.md
CHANGELOG
docker-compose.yml
docker-compose.example.yml
62 changes: 62 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
# CHANGELOG

Everything in this file is part of version 0.1.0, the first release. Entries are grouped by the date they were made.

## 11-24-26
- Switching the active server between two known servers that are not paired now updates the dashboard (state and event stream) straight away; before, it kept showing the previous server until something else refreshed it
- Events forwarded from the server to the dashboard are re-serialized as compact JSON on one line, so a server cannot add its own event fields to the dashboard stream
- A backup whose file name does not end in `.zip` (or ends in `.part`) is refused before anything is downloaded: a manual pickup answers `400`, an automatic one is skipped and logged as a warning
- After a successful automatic pickup, the client removes the earlier `*-media-backup-AD.zip` copies of the older archives the active server still lists, not only the one before the latest. Newer copies, copies of archives the server no longer lists (for example from another server), your own copies (`*-media-backup.zip`) and other files are never touched

## 11-22-26
- A state file the client cannot read (wrong owner or permissions, for example after switching to `user:`) now stops startup with a message naming the file and the UID, instead of being moved aside as `.corrupt-*` and dropping every pairing. Only a file that is really malformed is moved aside
- The pickup interval is limited to 365 days: `PUT /api/client/pickup-interval` answers `400` above that, the dashboard field takes at most 525600 minutes and checks it, and an out-of-range value in the state file or `CLIENT_PICKUP_INTERVAL` is ignored with a warning in favour of the default of 12 hours
- A server that has no backups yet is reported once at INFO, then only at DEBUG on each retry, instead of a WARN every time
- The image has a `HEALTHCHECK` that asks the dashboard's open `/api/auth/status` on `CLIENT_PORT`
- Documented that with `network_mode: host` `CLIENT_PORT` must stay at 1024 or above and that `cap_drop: ALL` needs `CHOWN`, `SETUID` and `SETGID` (or `user:`), and that the `MEDIAGARRD_SERVER_CA` file must be readable by UID 1000 or `PUID`
- The container no longer runs Java as root. It starts as root only to give UID 1000 (or `PUID` and `PGID`) ownership of the state and download folders and of the client's own files in them (the state file with its `.tmp` and `.corrupt-*` copies, `password.json`, and `*-media-backup.zip`, `*-media-backup-AD.zip` and their `.part` files), then runs the client as that user. Other files in your folders are left alone, and the state folder is never changed recursively. Existing installs keep working without a manual `chown`; with `user:` in Compose the entrypoint skips the ownership step, so the folders must already belong to that user. `PUID=0` keeps running as root. The base image is pinned to `eclipse-temurin:21.0.13_9-jre`
- A scan merges the servers it finds into Known Servers instead of replacing the list: servers already known (for example an `https://` one outside the LAN) stay, new ones are added, and the active server stays selected
- Server Configuration checks the backup interval (15 minutes to 365 days, as the server does; the field takes 0.25 to 8760 hours) before sending anything, and `PUT /api/client/server-config` answers `400` for an interval outside that range without changing the location or retention either
- Clearer messages: a server that has not paired this client no longer produces "Connect to a server" hints, Server Configuration says to pair on the Dashboard, a proxy timeout reads as one instead of "POST ... failed (504)", the rejected-token note leads with a pairing code, and disabled buttons are muted
- Pairing confirms itself: after the server issues a token the client makes one authenticated request (`GET /api/v1/health`) to confirm it, retried up to 3 times after a network error or a 502, 503 or 504. The client stores the token first and discards it only when the server refuses the confirmation (a `401` or a reply that is not a confirmation, reported as a `400` or `502`), so the same PIN or pairing code can be entered again; any other failure keeps the token, answers `paired: true` with a new `note` saying the server confirms it on the next connection, and a lost reply can no longer leave the server with a client the Client has forgotten. Pairing while a stored token still works is refused with `409` (unpair first), and pairing and unpairing no longer run at the same time
- The warnings after unpairing no longer point at the server's `/config` page (it is disabled after setup); they say to remove the client with `DELETE /api/v1/clients/{id}` on the server
- Works with the Server's confirm-on-first-use pairing (Server 11-22-26) and with earlier 11-19-26 servers, where the confirmation request simply succeeds

## 11-21-26
- Server Configuration has a Failure Notifications panel for the server's optional failure webhook: Save, Clear and Send Test, showing only `Configured: https://host` (the URL is a secret and is never shown or pre-filled). New proxy endpoints `GET` and `PUT /api/client/notifications/webhook` and `POST /api/client/notifications/webhook/test`; a `429` from the server's test cooldown is passed on with its `Retry-After`
- Fixed the missing space between the note and the first field of the set-password form
- Routine reads (`GET /api/client/server-config` and `/services`, and the event stream's "subscribing" and "no event stream" lines, and a preferred server that does not answer) are logged at DEBUG instead of INFO, so polling no longer fills the log; changes, pairing, downloads and errors still log at INFO or WARN
- The pickup schedule survives restarts. The client keeps the time of the last successful pickup of the latest archive (`lastPickupAt` in the state file) and the next pickup is due one interval after it. After a restart an overdue pickup runs on the first check once the client is paired with the active server and the server answers; one that is not overdue waits for its original due time. Changing the pickup interval recomputes the due time from the last pickup
- A pickup that fails or cannot reach the server is retried after 1, 2, 5, 10 and then every 15 minutes, instead of after a full interval. A client that is not paired waits quietly. A scheduled pickup and a manual download of the same archive no longer download it twice
- Switching the active server clears the last pickup time, so the first pickup from the new server is due at once instead of waiting for the old server's schedule. If the pickup time cannot be saved to the state file, the client backs off instead of retrying every minute, and a backward clock jump delays a retry by at most 15 minutes
- A download that finishes after the active server was switched no longer sets the new server's last pickup time. A scheduled pickup records its time before its task reports completed
- Incomplete `.part` files left behind by a crash or restart are deleted on startup and before each pickup, unless they belong to a transfer in progress
- On a phone-width screen the dashboard and Server Configuration no longer scroll sideways: grid columns, form rows and notes shrink to the screen, and the archives and services tables scroll inside their panel
- Server Configuration puts Backup Settings alone in the left column, with Add Service and then Failure Notifications stacked in the right column (in that order under Backup Settings on a narrow screen)

## 11-19-26
- The client pairs with the server. Selecting a server that has no stored token shows a pairing form in the Server Status panel: enter the `Pairing PIN` from the server's logs or a pairing code, and the client calls the server's `POST /api/v1/pair` and keeps the token per server address in its state file (readable by its owner only). The token is never logged, shown, or sent to the browser
- Every request to the server (API calls, the event stream, backup downloads, scheduled pickups, and the health check once paired) sends `Authorization: Bearer <token>`. Requests to the server no longer follow redirects, so the token cannot be replayed elsewhere; a redirect is reported with the address it points to
- When the server rejects the token (`401`) the client answers `502` with `"pairing": "required"`, the dashboard says the token was rejected and offers to pair again, and the event stream stops retrying until the client is paired again. The dashboard state has a new `pairing` field and event (`NONE`, `PAIRED`, `REQUIRED`, `REJECTED`)
- New endpoints: `POST /api/client/pairing`, `POST /api/client/pairing/code` (a one-time code that pairs another client) and `DELETE /api/client/pairing` (revokes this client on the server and forgets the token, also when the server cannot be reached)
- The dashboard has a password. The first visitor sets it (at least 8 characters), or `CLIENT_PASSWORD` sets it and disables the form; `CLIENT_RESET_PASSWORD=true` removes a stored one on start. It is stored as a salted PBKDF2-HMAC-SHA256 hash (600,000 iterations) in `password.json` next to the state file. Sessions use an `HttpOnly`, `SameSite=Strict` cookie (`Secure` over HTTPS or with `X-Forwarded-Proto: https`) and end after 12 hours idle or 7 days; failed logins from one address are delayed from 5 seconds up to 5 minutes (`429`)
- Every `/api/client` endpoint, including `GET /events`, now needs the session; only the page, its assets and `/api/auth/status`, `login`, `set-password` and `logout` do not. Changing requests are refused when the browser marks them as cross-site. Scripts log in with `POST /api/auth/login` and keep the cookie
- An address typed with `https://` (in "Connect by IP" or `MEDIAGARRD_SERVER_IP`) keeps its scheme and defaults to port 443; no port scan is done for it. Plain `ip` and `ip:port` behave as before
- `MEDIAGARRD_SERVER_CA` trusts extra certificate authorities, or a self-signed certificate, for connections to the server, next to the system ones. The GitHub update check is unaffected. The client refuses to start if the file cannot be read
- Server addresses are normalized (lowercase scheme and host, default port and trailing slash dropped); stored addresses are migrated when the state is loaded. Tokens are tied to the exact address, so switching from `http://<ip>:38471` to `https://<host>` needs pairing again
- The client needs a server from 11-19-26 or later; older servers have no pairing
- Changing requests without `Sec-Fetch-Site` or `Origin` headers must send `X-MediaGarrd-Request: 1`. A login attempt is checked one at a time per address and a few at a time overall, and all addresses together get 30 password checks a minute (a successful login gives its check back); when they are used up, logins get `429` with `Retry-After` until the next check is free
- Every response carries `X-Frame-Options: DENY` and `Content-Security-Policy: frame-ancestors 'none'`, so the dashboard cannot be embedded in another page
- An unexpected failure (HTTP 500) answers with `{"error": "Internal error"}`; the details are only in the log
- When the server accepts the token again after rejecting it, the event stream restarts at most once every 5 minutes, and only if the stream itself was rejected
- Added [docs/https.md](./docs/https.md) with nginx and Caddy examples
- Selecting a server by URL now checks that a MediaGarrd server answers at that address before it is stored (`400` with `No MediaGarrd server found at <url>` otherwise). Servers the client already knows are not checked again
- Request bodies on `/api` are limited to 64 KiB, also when sent chunked (`413` with `{"error": "Request body is too large"}`). A pairing PIN or code is limited to 64 characters and the client name to 64. Service names in the path must be letters, digits, `.`, `_` or `-` (at most 64). A line or event on the server's event stream is limited to 1 MiB
- Every response now also carries `X-Content-Type-Options: nosniff`, `Referrer-Policy: no-referrer` and a `Content-Security-Policy` of `default-src 'self'` (plus `frame-ancestors 'none'`); `/api` responses carry `Cache-Control: no-store`
- Every error answer is `{"error": "..."}`. Unexpected failures and failures reported by the server with a 5xx status carry no detail (`Internal error`, or `MediaGarrd server responded with <status>`); the details are only in the log. The one exception is a failed `POST /api/client/backups/run`, which answers `500` with the run's failure reason from the server (the server does the same for that call), because the dashboard shows it. The messages of failed downloads in the progress of a pickup no longer include file paths
- Downloaded archives are saved with owner-only permissions (`0600`, new directories `0700`). A download that receives no data for 60 seconds fails
- Pairing while this client still holds a working token is refused with `409` (unpair first), and nothing is revoked on the server. `DELETE /pairing` answers `{"serverRevoked", "warning"}`; `warning` says why the server was not told, or is `null`
- A request that the server answers with `401` marks the pairing as rejected at once, without waiting for the next health check
- The live event stream of the browser ends when its session ends (logout, a new password, expiry)
- A `state.json` that cannot be read is moved to `state.json.corrupt-<timestamp>` and logged as an error instead of being overwritten. Changes to the state are written to disk before they take effect, so a failed save no longer leaves the client and its file out of step
- The scheduled pickup no longer runs on the shared scheduler thread. A pickup whose archive name leaves the download directory no longer leaves a stuck task behind, and the scheduled pickup never deletes an archive it did not download itself
- The release link of the update check must point to `https://github.com/`; otherwise it is built from the tag

## 11-12-26
- The client now owns the dashboard state (active and known servers, link state, run state, the server's backup interval and retention, both versions) and pushes it to every open page on `GET /api/client/events`: one `snapshot` on subscribe, then `link`, `state`, `run-started`, `run-finished`, `servers`, `config`, `backups-changed`, `versions` and `ping`. `GET /api/client/dashboard` returns the same snapshot
- Link states: `LIVE` (the server's event stream is open), `DEGRADED` (no stream, because of an older server, the subscriber cap or a backoff, but the server answers its health check), `CONNECTING` (a server was just selected or its stream dropped and the first health check has not answered) and `DOWN` (no server, or the health check failed). While not `LIVE`, the client checks the server's health every 8 seconds, once per client instead of once per open page
Expand Down
1 change: 1 addition & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@AGENTS.md
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,18 @@ WORKDIR /workspace
COPY . .
RUN --mount=type=cache,target=/home/gradle/.gradle gradle :bootJar --no-daemon --stacktrace --info --warning-mode all

FROM eclipse-temurin:21-jre
FROM eclipse-temurin:21.0.13_9-jre
WORKDIR /app
RUN set -eux; \
if getent passwd 1000 >/dev/null; then userdel "$(getent passwd 1000 | cut -d: -f1)"; fi; \
if getent group 1000 >/dev/null; then groupdel "$(getent group 1000 | cut -d: -f1)"; fi; \
groupadd --gid 1000 mediagarrd; \
useradd --uid 1000 --gid 1000 --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin mediagarrd; \
mkdir -p /var/lib/mediagarrd/client /var/lib/mediagarrd/downloads; \
chown -R 1000:1000 /var/lib/mediagarrd
COPY --from=build /workspace/build/libs/*.jar app.jar
COPY --chmod=755 docker-entrypoint.sh /usr/local/bin/mediagarrd-entrypoint
EXPOSE 8081
ENTRYPOINT ["java", "-jar", "/app/app.jar"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=3 CMD ["sh", "-c", "curl -fsS -o /dev/null \"http://127.0.0.1:${CLIENT_PORT:-8081}/api/auth/status\""]
ENTRYPOINT ["/usr/local/bin/mediagarrd-entrypoint"]
CMD ["java", "-jar", "/app/app.jar"]
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ Full documentation is on the [MediaGarrd website](https://mediagarrd.github.io/M

## Docs
- [settings.md](./docs/settings.md): every environment variable and its default.
- [https.md](./docs/https.md): HTTPS with nginx or Caddy, and self-signed certificates.
- [network.md](./docs/network.md): how the client finds servers on the network.
- [API.md](./docs/API.md): every HTTP endpoint and what it returns.
- [testing.md](./docs/testing.md): running the Java and browser tests.

## Requirements
- Docker with Compose v2
- A MediaGarrd Server that has finished its first-time setup
- A MediaGarrd Server from 11-19-26 or later that has finished its first-time setup. Older servers have no pairing, so this client cannot use them

The dashboard has a password and the client pairs with each server. Whoever opens a new dashboard first can choose its password, so do it right after installing, or set `CLIENT_PASSWORD`. Beyond a trusted network, put both behind HTTPS: see [https.md](./docs/https.md).

## Installation
```bash
Expand All @@ -22,7 +25,9 @@ cp docker-compose.example.yml docker-compose.yml
docker compose up --build -d
```

Then open `http://<client-host>:8081` and connect to your server by IP or with "Scan Local Network". To connect automatically, add `MEDIAGARRD_SERVER_IP=<server-ip>` to `environment` in `docker-compose.yml`.
Then open `http://<client-host>:8081` and choose a dashboard password (or set `CLIENT_PASSWORD`). Connect to your server by IP or with "Scan Local Network", then pair: enter the `Pairing PIN` that the server's setup page shows after Finish Setup, which it also prints in its logs (`docker logs mediagarrd-server 2>&1 | grep "Pairing PIN"`). To connect automatically, add `MEDIAGARRD_SERVER_IP=<server-ip>` to `environment` in `docker-compose.yml`.

The container runs the client as UID 1000, not as root. On first start it gives that user ownership of the mounted state and downloads folders (`./data/client/state` and `./data/client/downloads` in the example) and of the client's own files in them, so existing installs keep working. To use another owner, add `PUID` and `PGID` to `environment` in `docker-compose.yml` (see [settings](./docs/settings.md)).

## Updating
```bash
Expand Down
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
java
id("org.springframework.boot") version "3.3.5"
id("io.spring.dependency-management") version "1.1.6"
id("org.springframework.boot") version "4.1.3"
id("io.spring.dependency-management") version "1.1.7"
}

version = "0.1.0"
Expand All @@ -13,7 +13,8 @@ repositories {
dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
implementation("org.springframework.boot:spring-boot-starter-web")
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
implementation("org.springframework.boot:spring-boot-starter-webmvc")
implementation("org.springframework.boot:spring-boot-starter")
}

Expand Down
Loading
Loading