104 Commits

Author SHA1 Message Date
darroyo 7b693bee5b Bump version to 1.0.58 2026-07-19 22:21:28 -04:00
darroyo 5cb21ddceb db: fix migration runner - proper schema_migrations checksum handling for existing DBs
- Check if checksum column exists before querying it
- For old DBs (no checksum col): use COUNT(*) to check if migration applied
- For new DBs (has checksum col): use checksum value
- All migrations run in a single transaction
2026-07-19 22:20:55 -04:00
darroyo dfb667e340 Bump version to 1.0.57 2026-07-19 22:18:46 -04:00
darroyo 02c1fd55fb Bump version to 1.0.56 2026-07-19 22:18:42 -04:00
darroyo d8aaaf5ca4 db: fix migration runner to handle existing DB without checksum col 2026-07-19 22:18:38 -04:00
darroyo 867794d846 Bump version to 1.0.55 2026-07-19 22:18:12 -04:00
darroyo f5d3ecfbf3 db: fix migration for existing schema_migrations without checksum column
- Add 0007 migration to ALTER TABLE adding checksum column
- Make migration runner INSERT conditional: if checksum col exists, use it; otherwise omit
- Handles existing databases (no checksum col) and fresh installs (has checksum col) correctly
2026-07-19 22:18:06 -04:00
darroyo a7ae619b76 Bump version to 1.0.54 2026-07-19 22:14:38 -04:00
darroyo 84b185be39 Phase A-E: stability, security, observability, and test coverage
Phase A - Stability:
- Engine.Start(): recovers orphaned jobs (running/queued/waking_up) after crash
- Engine.Stop(): graceful shutdown - cancels all in-flight jobs and waits
- Queue keyed by jobID (not syncPairID): cancel now targets exact job
- Local rsync uses jobCtx (context.Background() replaced)
- Migrations wrapped in transactions; checksums stored

Phase B - Security:
- admin/admin default removed: SYNCSERVER_ADMIN_PASSWORD required on first run
- Path validation: rejects .., leading -, null bytes in sync pair paths
- Rsync flags allowlist: dangerous flags blocked (--rsync-path, -e, --files-from)
- Shell concat in RunRemote replaced with proper sh -c escaping
- knownhosts: replaced custom parser with golang.org/x/crypto/ssh/knownhosts
- RequireAdmin wired: machine CRUD, SSH key ops, settings require admin role
- deploy-keys: uses authorized_keys only (no private key upload)
- Hardcoded /var/lib/syncserver/ssh paths replaced with cfg.SSHDir()

Phase C - Operational:
- /readyz health check: DB query + SSH dir accessibility
- /metrics endpoint: Prometheus text format (jobs, queue, machines)
- Event struct JSON tags: job_id, machine_id, type (snake_case)
- EventBus broadcast: fanned out to all subscribers
- SQLite VACUUM INTO backup: scheduled before cleanup if BackupDir set
- Filesystem job log cleanup: removes .log files for purged jobs
- Backup retention: old backups auto-purged

Phase D - Frontend:
- Schedules page: REST API + full CRUD UI for cron schedules
- Dashboard: cancel button for running/queued jobs
- JobDetail: server-side log download via API
- Settings: displays data_dir from server
- 404 page: proper NotFound component

Phase E - Tests:
- auth_test.go: JWT, bcrypt, middleware, seed (18 tests)
- models_test.go: Job, Machine, SyncPair, Schedule repos (18 tests)
- go test -race: no data races found
2026-07-19 22:14:30 -04:00
darroyo 300555d35f Bump version to 1.0.52 2026-07-19 19:49:10 -04:00
darroyo 6b29a4b419 Bump version to 1.0.51 2026-07-19 19:49:00 -04:00
darroyo 4ccf2fc2d6 Bump version to 1.0.50 2026-07-19 18:17:42 -04:00
darroyo ae33703ef9 Bump version to 1.0.49 2026-07-19 18:17:36 -04:00
darroyo 2285790257 Add Direction mode help text and mirror --delete warning in sync pair form 2026-07-19 18:17:29 -04:00
darroyo 2ec031c9dc Bump version to 1.0.48 2026-07-17 18:40:23 -04:00
darroyo b2172145e7 Always copy source directory contents, not the directory itself 2026-07-17 18:40:16 -04:00
darroyo 340370a43b Bump version to 1.0.47 2026-07-17 18:26:26 -04:00
darroyo 743882eb0e Allow remote-to-remote sync pairs 2026-07-17 18:26:19 -04:00
darroyo 0437a7b248 Bump version to 1.0.46 2026-07-13 15:20:20 -04:00
darroyo f476b7bd8b Fix shutdown UX: nohup wrapper prevents SSH session drop during host shutdown
When the host shuts down, sshd is killed before sending exit-status,
causing Go ssh library to return "wait: remote command exited without
exit status" — treated as failure even though the shutdown worked.

Changes:
- shutdown.go: wrap shutdown-like commands with nohup so the SSH
  session exits cleanly before sshd is killed by shutdown
- IsShutdownCommand() helper detects shutdown/poweroff/halt/reboot commands
- handlers_machines.go: classify expected shutdown-side-effect errors
  (no exit status, connection refused/reset) as success so the UI
  shows a green toast instead of a false error
2026-07-13 15:20:13 -04:00
darroyo e6d550b3ab Bump version to 1.0.45 2026-07-13 13:43:40 -04:00
darroyo 50f73cd656 Fix ApproveFingerprint: extract real host key via SSH instead of writing fingerprint SHA256 to known_hosts
The old ApproveFingerprint passed the SHA256 fingerprint string to
AddKnownHost which expected authorized_key format, causing known_hosts
entries to be corrupted and subsequent SSH connections (including shutdown)
to fail with "host key not found".

Changes:
- dialSSH now returns (conn, fingerprint, pubKey, error) with the raw
  ssh.PublicKey captured from the server
- New ConnectForApproval() wraps dialSSH with strictHostKeyChecking=false
  for the approval handshake
- ApproveFingerprint now opens an SSH connection to the host (non-strict),
  captures the real public key, and writes it in authorized_keys format
  to known_hosts via AddKnownHost
- shutdown.go updated to handle the new 4-value dialSSH return
- Supports optional host_key field in request body for direct key submission
2026-07-13 13:43:33 -04:00
darroyo d12f76ca56 Bump version to 1.0.44 2026-07-13 13:35:02 -04:00
darroyo bc3bc44c4a Add shutdown machine feature with configurable command
Backend:
- New migration: add shutdown_command TEXT column to machines table
- Machine model updated with ShutdownCommand field (Create/GetAll/GetByID/Update)
- MachineRequest/MachineResponse DTOs updated with shutdown_command field
- New ShutdownResponse DTO
- New POST /api/machines/{id}/shutdown handler via SSH
- Refactor sshmanager/testconn.go: extract dialSSH() helper shared with shutdown.go
- New sshmanager/shutdown.go: RunRemoteCommand with 15s timeout

Frontend:
- New shutdownMachine() API helper and ShutdownResponse type in client.ts
- New shutdown_command field in MachineForm
- Power button (amber) in machines table actions
- Shutdown confirmation modal with WoL warning notice
- shutdown_command input field in machine edit/create form
- Machine interface updated with shutdown_command and last_seen_at fields
2026-07-13 10:02:18 -04:00
darroyo bf9bcccde2 Fix MachineResponse: expose last_seen_at/created_at, clean status string
The status field was being decorated with "(last seen ...)" suffix
which broke frontend statusVariant() matching and prevented the
LastSeen column from showing the separate timestamp.

Changes:
- machineToResp() now returns clean status ("online"/"offline")
- MachineResponse includes last_seen_at and created_at as separate fields
- Fix whitespace typo in WakeCheckIntervalSeconds field
2026-07-10 11:05:27 -04:00
darroyo 7a2a7a4935 Add Last Seen column and color-coded status badges in Machines table
- New Last Seen column showing last_seen_at timestamp per machine
- Status badges: online=green (success), offline=red (error), waking/pending=amber
- Update Machine interface with last_seen_at and created_at fields
2026-07-10 10:51:10 -04:00
darroyo 175fdf4dff Bump version to 1.0.40 2026-07-09 21:58:50 -04:00
darroyo 683c489a24 Bump version to 1.0.39 2026-07-09 21:58:46 -04:00
darroyo 5b28b46e6b fix: simplify RunRemote to not re-prefix source or dest
RunRemote was adding user@host: prefixes on top of the paths already
pre-prefixed by engine.go in the remote-to-remote branch, causing
"both remote" rsync errors. The source path was also incorrectly
prefixed with srcUserHost:, making rsync reject the command entirely.

The fix: buildArgs already orders args correctly for rsync (source
then dest), so just use args[-2] and args[-1] as-is without any
additional prefixing.
2026-07-09 21:58:02 -04:00
darroyo fce8962f2b Bump version to 1.0.38 2026-07-09 21:51:25 -04:00
darroyo 147c6d8ead fix: rsync double SSH spec in RunRemote, restore dropped flags in Run
- Fix Bug A: RunRemote was re-prefixing destination with user@host: when
  engine.go:135 already pre-prefixed it for remote-to-remote, causing
  "admin@host:admin@host:/path" to be passed to rsync
- Fix Bug B: Run used args[1:] when inserting -e ssh, silently dropping
  the first rsync flag (e.g. -aP became flag-less)
- Fix Bug C: RunRemote extracted source/dest in wrong order for pull
  direction (buildArgs reverses them but RunRemote assumed push order)
- Add rsync_runner_test.go covering buildArgs, RunRemote prefixing,
  and flag preservation
2026-07-09 21:51:05 -04:00
darroyo 969ccacfc8 Bump version to 1.0.36 2026-07-09 21:25:53 -04:00
darroyo 935fa83b93 fix: add json tags to DeployResult for camelCase serialization
DeployResult struct fields were serializing as PascalCase (Success,
Messages, Errors) but the TypeScript frontend expected camelCase
(success, messages, errors). Adding json:"..." tags fixes the mismatch.
2026-07-09 21:25:49 -04:00
darroyo 0a82f4e777 Bump version to 1.0.35 2026-07-09 21:19:56 -04:00
darroyo 7a88fb861d fix: ssh-keyscan failures are warnings, not fatal in deploy-keys
ssh-keyscan failures no longer set Success=false. Keys were uploaded
successfully which is the critical part. Only session errors remain as
errors, ssh-keyscan failures are advisory.
2026-07-09 21:19:52 -04:00
darroyo 0a42f157f7 Bump version to 1.0.34 2026-07-09 20:58:52 -04:00
darroyo c7337a3bbc fix: remove public key deployment from deploy-keys
Deploy-keys now only:
- Creates /var/lib/syncserver/ssh/keys on remote
- Uploads private keys of all other machines to that path
- Populates known_hosts with all other machine hosts

No longer touches authorized_keys or reads server public key.
2026-07-09 20:58:48 -04:00
darroyo 048b99921e Bump version to 1.0.33 2026-07-09 20:52:37 -04:00
darroyo f7801585a6 feat: deploy all machine keys (mesh)
When deploying keys to a machine, upload ALL private keys from ALL
other machines (not just sync pair peers). Also populate known_hosts
with all other machine hosts. Creates a full mesh where any machine
can SSH to any other.

- sshmanager/deploy.go: change knownHostsHost string parameter to
  knownHostsHosts []string for multi-host ssh-keyscan
- handlers_machines.go: replace sync-pair-based key detection with
  loop over all machines, deduplicating by local key path
2026-07-09 20:52:33 -04:00
darroyo e0252829b3 Bump version to 1.0.32 2026-07-09 20:45:37 -04:00
darroyo cb39df63bc fix: deploy keys StdinPipe order and add structured logging
- sshmanager/deploy.go: StdinPipe() must be called BEFORE Start(),
  not after. Reordered the calls to fix "ssh: StdinPipe after
  process started" error.
- Return DeployResult instead of nil error on SSH dial failure
  so the frontend always gets a parseable response.
- Add slog.Debug for key upload, slog.Warn for ssh-keyscan and
  authorized_keys failures, slog.Info for final result summary.
2026-07-09 20:45:32 -04:00
darroyo be2d2d1a8d Bump version to 1.0.31 2026-07-09 20:38:45 -04:00
darroyo 179b2d8fbd fix: deploy keys modal crash on null/undefined arrays
- sshmanager/deploy.go: initialize DeployResult with empty slices
  instead of nil to prevent null serialization in JSON
- Machines.tsx: use ?? [] fallback for messages and errors arrays
  in deploy keys modal to handle null/undefined gracefully
2026-07-09 20:38:41 -04:00
darroyo c0bf16f132 Bump version to 1.0.30 2026-07-09 20:33:43 -04:00
darroyo ee5372c9fd Bump version to 1.0.29 2026-07-09 20:33:19 -04:00
darroyo dbf998703f feat: add Deploy Keys function to Machines UI
- sshmanager/deploy.go: new DeployKeysToMachine function that uploads
  private keys, populates known_hosts via ssh-keyscan, and adds server
  pub key to authorized_keys on remote machines
- handlers_machines.go: new DeployKeys handler with auto-detection of
  keys needed per sync pair (source->dest uploads dest key, dest->source
  uploads source key)
- router.go: POST /machines/{id}/deploy-keys route
- client.ts: deployKeys() API method
- Machines.tsx: Deploy Keys button + modal with result display
2026-07-09 20:33:04 -04:00
darroyo 5d708e1d7b fix: RunRemote SSH-to-source with pre-installed dest key, eliminating base64 round-trip
- Regenerate qnap.key and baby-nas.key to OpenSSH native format (387 bytes vs 119 PKCS8)
- Pre-install qnap.key on Baby NAS at /var/lib/syncserver/ssh/keys/
- Pre-populate Baby NAS known_hosts with Qnap host keys
- Simplify RunRemote: LXC SSH to Baby NAS, Baby NAS runs rsync with local qnap.key
- Remove wrapper script approach (rsync rejects remote-to-remote)
2026-07-09 20:03:00 -04:00
darroyo 727d8676a6 Bump version to 1.0.27 2026-07-09 18:41:13 -04:00
darroyo f76cdaf140 Bump version to 1.0.26 2026-07-09 18:40:30 -04:00
darroyo afe399d3a9 fix: use git add -f to bypass spurious ignore on cmd/server 2026-07-09 18:40:15 -04:00