Bump version to 1.0.9
Fix Wake-on-LAN: set SO_BROADCAST on UDP socket, send 3 magic packets, expose broadcast_addr and wake timeout fields in UI, add Test Wake endpoint, surface send errors in job status, bump default wake timeout to 180s.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/syncserver/internal/models"
|
||||
"github.com/syncserver/internal/wol"
|
||||
)
|
||||
|
||||
type MachineHandler struct {
|
||||
@@ -74,7 +75,7 @@ func (h *MachineHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||
req.SSHUser = "root"
|
||||
}
|
||||
if req.WakeTimeoutSeconds <= 0 {
|
||||
req.WakeTimeoutSeconds = 120
|
||||
req.WakeTimeoutSeconds = 180
|
||||
}
|
||||
if req.WakeCheckIntervalSeconds <= 0 {
|
||||
req.WakeCheckIntervalSeconds = 5
|
||||
@@ -172,6 +173,42 @@ func (h *MachineHandler) Update(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, machineToResp(*existing))
|
||||
}
|
||||
|
||||
func (h *MachineHandler) TestWoL(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid id")
|
||||
return
|
||||
}
|
||||
repo := models.NewMachineRepository(h.db)
|
||||
m, err := repo.GetByID(id)
|
||||
if err == sql.ErrNoRows {
|
||||
writeError(w, http.StatusNotFound, "machine not found")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
writeError(w, http.StatusInternalServerError, "failed to fetch machine")
|
||||
return
|
||||
}
|
||||
if !m.WoLEnabled || m.MACAddress == nil {
|
||||
writeError(w, http.StatusBadRequest, "WoL is not enabled for this machine or MAC address is missing")
|
||||
return
|
||||
}
|
||||
mac, err := wol.ParseMAC(*m.MACAddress)
|
||||
if err != nil {
|
||||
writeError(w, http.StatusBadRequest, "invalid MAC address")
|
||||
return
|
||||
}
|
||||
bcast := ""
|
||||
if m.BroadcastAddr != nil {
|
||||
bcast = *m.BroadcastAddr
|
||||
}
|
||||
if err := wol.Send(mac, bcast); err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
writeJSON(w, map[string]interface{}{"ok": true, "sent": 3})
|
||||
}
|
||||
|
||||
func (h *MachineHandler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
id, err := strconv.ParseInt(chi.URLParam(r, "id"), 10, 64)
|
||||
if err != nil {
|
||||
|
||||
@@ -52,6 +52,7 @@ func NewServer(cfg *config.Config, db *sql.DB, engine *syncengine.Engine) *Serve
|
||||
r.Get("/{id}", machineHandler.Get)
|
||||
r.Put("/{id}", machineHandler.Update)
|
||||
r.Delete("/{id}", machineHandler.Delete)
|
||||
r.Post("/{id}/test-wol", machineHandler.TestWoL)
|
||||
})
|
||||
|
||||
r.With(auth.RequireAuth).Route("/sync-pairs", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user