Files
ArmA-3-web-server/README.md
T
MrFastwind 4d6f162b8f fix: code quality, memory safety, and install improvements
Critical fixes:
- Fix Dockerfile: reorder stages so frontend assets embed into Go binary
- Fix Go version 1.25 (nonexistent) to 1.24 across Dockerfile, go.mod, CI
- Add graceful game server shutdown on SIGTERM/SIGINT
- Order startup tasks: updates complete before auto-start
- Fix TOCTOU race in UpdateSettings with atomic Update() method

Security:
- Add optional AUTH_TOKEN bearer auth middleware on API/WS routes
- Fix path traversal in DeleteMod using filepath.Rel instead of HasPrefix
- Add input validation for IPPort, ServerParameters, ScheduledUpdate

Memory safety:
- Cap RPT buffer allocation to 64KB to prevent OOM on large logs
- Cap GetLog file read to 10MB
- Fix context cancel leak in SteamCmdManager.run()
- Remove data-raced cancel field in steamcmd.go
- Atomic file writes (write-temp-then-rename) across all managers

Reliability:
- Log save errors in ProcessManager.Stop()
- Atomic file writes prevent corruption on crash

Tests:
- Add mod_manager_test.go (12 tests: ListWorkshopMods, ListLocalMods,
  BuildUsageMap, RemoveMod, dirSize)
- Add scheduler_test.go (6 tests: Start/Stop, Refresh with empty,
  invalid, valid, and replaced cron expressions)
- Add TestRestart to server_process_test.go

CI/Docs:
- Add -race flag to go test in CI and Makefile
- Add npm lint step to CI
- Add Go/npm module caching to CI
- Update README: prerequisites, AUTH_TOKEN/GIN_MODE/SERVERS_DIR docs,
  fix manual quickstart to use make build
2026-07-25 02:47:04 +02:00

184 lines
7.1 KiB
Markdown

# Arma 3 Web Server
Web-based management panel for Arma 3 dedicated servers. Start, stop, configure, and monitor your server from a browser.
## Features
- **Server control** — Start, stop, restart, and view status
- **Live console** — WebSocket terminal showing server stdout/stderr and RPT log tailing
- **Config management** — Create, edit, duplicate, and delete `.cfg` configuration files with a Monaco editor
- **Modlist management** — Create modlists with reorderable entries, enable/disable per mod, import from HTML (e.g. ArmA 3 Steam Workshop collections), check download status
- **SteamCMD integration** — Update the server binary, download individual workshop mods, bulk download missing or outdated mods, all streamed live to the UI
- **Settings UI** — Edit server parameters, IP:port, platform, Steam branch/user, CBA/AI/difficulty presets, and select active config/modlist
- **Log viewer** — Browse and read server log files
## Quick Start
### Docker
```bash
docker compose up -d
```
The web UI is served on `http://localhost:8080`.
### Manual
**Prerequisites:**
- [Go](https://go.dev/dl/) >= 1.24
- [Node.js](https://nodejs.org/) >= 22 with npm
- GNU Make (optional, for `make` targets)
```bash
# Build for production (frontend + backend in one binary)
make build
./backend/arma3-web-server
# Or develop with hot reload (uses test stubs, no real SteamCMD needed)
make dev
```
The web UI is served on `http://localhost:8080`.
## Configuration
All paths are configurable via environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| `DATA_DIR` | `data` | Server metadata (settings, modlist JSON files) |
| `SERVERFILE_DIR` | `serverfiles` | Arma 3 server installation |
| `MODS_DIR` | `serverfiles/mods` | Local mod symlinks/copies |
| `CFG_DIR` | `serverfiles/cfg` | Server configuration `.cfg` files |
| `PROFILES_DIR` | `serverfiles/profiles` | Arma 3 profile and log directory |
| `LISTEN` | `:8080` | HTTP listen address |
| `SERVER_BINARY` | `arma3server_x64` | Server binary filename (overrides platform default) |
| `SERVER_PARAMS` | `-server -world=empty ...` | Override server launch parameters |
| `STEAMCMD_PATH` | `steamcmd` | Path to steamcmd binary |
| `AUTH_TOKEN` | _(empty)_ | Bearer token for API/WS auth. When set, all requests must include `Authorization: Bearer <token>`. When empty, no auth required. |
| `GIN_MODE` | `debug` | Gin framework mode. Use `release` for production (set automatically in Docker). |
| `SERVERS_DIR` | `./serverfiles` | Docker Compose only: host directory mounted as `/servers` in the container. |
## Automation
The panel can perform automatic operations at startup and on a schedule.
### Startup tasks
Configured in the **Automation** section of the Settings UI:
| Setting | Description |
|---------|-------------|
| **Auto-update server on startup** | Runs `steamcmd +app_update` for the Arma 3 server binary when the web service starts. |
| **Auto-update mods on startup** | Downloads workshop updates for every enabled mod in the active modlist when the web service starts. |
| **Auto-start server on startup** | Restarts the game server if it was running when the web service last stopped. Useful for recovery after host backup cycles or container restarts. |
All startup tasks run asynchronously — the web UI is available immediately. Server and mod updates run in parallel; auto-start waits for both to complete before launching the game server.
### Scheduled updates
Set a **cron expression** in the `Scheduled Update` field to run game + mod updates on a recurring schedule (e.g. `"0 4 * * *"` for daily at 4 AM). Leave empty to disable.
The scheduled update runs even if the game server is currently running.
## SteamCMD Authentication
The panel integrates with SteamCMD for server binary updates and workshop mod downloads.
### Anonymous (default)
The `Steam User` field in the settings UI defaults to `anonymous`.
In this mode, **no Steam account is required** — SteamCMD uses `+login anonymous`.
- Workshop mod downloads always use this mode, regardless of the configured user.
- The Arma 3 server binary update is available via `+login anonymous` only if the server files are publicly accessible on that Steam account.
### Authenticated login
To update the Arma 3 server binary (`app_update 233780`) with a real Steam account, set the `Steam User` field to your account name.
The web panel does not pass a password — SteamCMD relies on a **cached session**.
You must authenticate manually once so the login token is persisted:
```bash
# Docker
docker exec -it arma3-web steamcmd +login your_steam_username
```
Enter your password when prompted, including any Steam Guard code if enabled. The session is cached inside the container's filesystem (`~/.steam/`).
> **Note:** SteamCMD sessions may expire. Re-run the login command if the "Update Server" button fails with an authentication error.
### Security
- Steam credentials saved in `data/settings.json` are stored as **plain text**.
- It is recommended to use a **dedicated Steam account** with only the necessary game licenses for automated server management.
## API
REST API at `/api/*` and WebSocket endpoints at `/ws/*`. Key routes:
| Method | Path | Description |
|--------|------|-------------|
| `GET/PUT` | `/api/server/settings` | Read/update server settings |
| `POST` | `/api/server/start\|stop\|restart` | Server lifecycle |
| `GET` | `/api/server/status` | Running state |
| `GET/POST/PUT/DELETE` | `/api/configs` | CRUD for `.cfg` files |
| `GET/POST/PUT/DELETE` | `/api/modlists` | CRUD for modlists |
| `POST` | `/api/modlists/import` | Import HTML workshop list |
| `GET` | `/api/modlists/:id/export` | Export to downloadable HTML preset |
| `GET` | `/api/modlists/:id/check` | Check mod download status |
| `POST` | `/api/modlists/:id/download-missing\|update-all` | Bulk workshop operations |
| `POST` | `/api/server/steamcmd/update-game\|download-mod` | SteamCMD operations |
| `GET` | `/api/mods` | List installed mods (workshop + local) with usage info |
| `DELETE` | `/api/mods` | Delete a mod by path |
| `POST` | `/api/mods/cleanup` | Bulk-delete all orphaned mods |
| `GET` | `/api/server/logs` | List log files |
| `GET` | `/api/server/paths` | Show server file paths |
| `GET` | `/api/server/health` | Comprehensive health check |
| `WS` | `/ws/server/logs\|rpt\|steamcmd/logs` | Live log streaming |
## Project Structure
```
backend/
cmd/server/ Entry point
embed/ Embedded frontend assets (//go:embed)
internal/
api/ HTTP handlers and routes
models/ Data types
services/ Business logic
frontend/
src/
api/ HTTP and WebSocket client
components/ Shared UI components
pages/ Route-level views
types/ TypeScript interfaces
```
## Development
```bash
# Start both backend + frontend with hot reload (copies stubs to dev-deploy)
make dev
# Start backend only
make run
# Run all tests
make test
# Run backend tests only
make test-backend
# Run frontend tests only
make test-frontend
# Build for production
make build
```
## License
MIT