84b185be39
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
145 lines
5.1 KiB
Go
145 lines
5.1 KiB
Go
package api
|
|
|
|
type MachineRequest struct {
|
|
Name string `json:"name"`
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
SSHUser string `json:"ssh_user"`
|
|
SSHKeyID *int64 `json:"ssh_key_id"`
|
|
MACAddress *string `json:"mac_address"`
|
|
WoLEnabled bool `json:"wol_enabled"`
|
|
BroadcastAddr *string `json:"broadcast_addr"`
|
|
WakeTimeoutSeconds int `json:"wake_timeout_seconds"`
|
|
WakeCheckIntervalSeconds int `json:"wake_check_interval_seconds"`
|
|
ShutdownCommand string `json:"shutdown_command,omitempty"`
|
|
}
|
|
|
|
type MachineResponse struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Host string `json:"host"`
|
|
Port int `json:"port"`
|
|
SSHUser string `json:"ssh_user"`
|
|
SSHKeyID *int64 `json:"ssh_key_id"`
|
|
MACAddress *string `json:"mac_address"`
|
|
WoLEnabled bool `json:"wol_enabled"`
|
|
BroadcastAddr *string `json:"broadcast_addr"`
|
|
WakeTimeoutSeconds int `json:"wake_timeout_seconds"`
|
|
WakeCheckIntervalSeconds int `json:"wake_check_interval_seconds"`
|
|
FingerprintConfirmed bool `json:"fingerprint_confirmed"`
|
|
HostKeyFingerprint *string `json:"host_key_fingerprint"`
|
|
Status string `json:"status"`
|
|
LastSeenAt *string `json:"last_seen_at"`
|
|
CreatedAt string `json:"created_at"`
|
|
ShutdownCommand string `json:"shutdown_command"`
|
|
}
|
|
|
|
type TestConnectionResponse struct {
|
|
Success bool `json:"success"`
|
|
Output string `json:"output,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
Fingerprint string `json:"fingerprint,omitempty"`
|
|
}
|
|
|
|
type ShutdownResponse struct {
|
|
Success bool `json:"success"`
|
|
Output string `json:"output,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
type SyncPairRequest struct {
|
|
Name string `json:"name"`
|
|
SourceMachineID *int64 `json:"source_machine_id"`
|
|
SourcePath string `json:"source_path"`
|
|
DestMachineID *int64 `json:"dest_machine_id"`
|
|
DestPath string `json:"dest_path"`
|
|
Direction string `json:"direction"`
|
|
RsyncFlags string `json:"rsync_flags"`
|
|
ExcludePatterns string `json:"exclude_patterns"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type SyncPairResponse struct {
|
|
ID int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
SourceMachineID *int64 `json:"source_machine_id"`
|
|
SourcePath string `json:"source_path"`
|
|
DestMachineID *int64 `json:"dest_machine_id"`
|
|
DestPath string `json:"dest_path"`
|
|
Direction string `json:"direction"`
|
|
RsyncFlags string `json:"rsync_flags"`
|
|
ExcludePatterns string `json:"exclude_patterns"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type JobResponse struct {
|
|
ID int64 `json:"id"`
|
|
SyncPairID int64 `json:"sync_pair_id"`
|
|
TriggerType string `json:"trigger_type"`
|
|
Status string `json:"status"`
|
|
StartedAt *string `json:"started_at"`
|
|
FinishedAt *string `json:"finished_at"`
|
|
LogFile *string `json:"log_file"`
|
|
ErrorMessage *string `json:"error_message,omitempty"`
|
|
ErrorCode *string `json:"error_code,omitempty"`
|
|
DurationSeconds *int64 `json:"duration_seconds,omitempty"`
|
|
LogLineCount *int64 `json:"log_line_count,omitempty"`
|
|
TotalSizeBytes *int64 `json:"total_size_bytes,omitempty"`
|
|
SentBytes *int64 `json:"sent_bytes,omitempty"`
|
|
}
|
|
|
|
type LogLineResponse struct {
|
|
ID int64 `json:"id"`
|
|
JobID int64 `json:"job_id"`
|
|
Stream string `json:"stream"`
|
|
Content string `json:"content"`
|
|
Timestamp string `json:"timestamp"`
|
|
}
|
|
|
|
type SSHKeyRequest struct {
|
|
Label string `json:"label"`
|
|
Generate bool `json:"generate"`
|
|
PublicKey string `json:"public_key"`
|
|
}
|
|
|
|
type SSHKeyResponse struct {
|
|
ID int64 `json:"id"`
|
|
Label string `json:"label"`
|
|
PublicKey string `json:"public_key"`
|
|
Fingerprint string `json:"fingerprint"`
|
|
InUse bool `json:"in_use"`
|
|
HasPrivateKey bool `json:"has_private_key"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
type ErrorResponse struct {
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
type SettingsInfoResponse struct {
|
|
Version string `json:"version"`
|
|
DataDir string `json:"data_dir"`
|
|
SSHPubKey string `json:"ssh_pub_key"`
|
|
}
|
|
|
|
type CreateScheduleRequest struct {
|
|
SyncPairID int64 `json:"sync_pair_id"`
|
|
CronExpr string `json:"cron_expr"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type UpdateScheduleRequest struct {
|
|
CronExpr string `json:"cron_expr"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
type ScheduleResponse struct {
|
|
ID int64 `json:"id"`
|
|
SyncPairID int64 `json:"sync_pair_id"`
|
|
SyncPairName string `json:"sync_pair_name"`
|
|
CronExpr string `json:"cron_expr"`
|
|
NextRun *string `json:"next_run_at"`
|
|
Enabled bool `json:"enabled"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|