package web import ( "errors" "net/http" "strings" "git.ulra.eu/adro/miniwol/config" "git.ulra.eu/adro/miniwol/lib" "github.com/labstack/echo/v4" ) func add(c echo.Context) error { device := config.Device{} err := c.Bind(&device) if err != nil { return err } config.Config.Devices = append(config.Config.Devices, device) config.Save() if err != nil { return err } return c.Redirect(http.StatusSeeOther, "/") } func wake(c echo.Context) error { _device := config.Device{} err := c.Bind(&_device) if err != nil { return err } for _, device := range config.Config.Devices { if device == _device { if !strings.Contains(device.IP, ":") { device.IP += ":9" } err := lib.SendPacket(":0", device.IP, device.MAC) if err != nil { return err } return c.Redirect(http.StatusSeeOther, "/") } } return errors.New("device not found") } func remove(c echo.Context) error { _device := config.Device{} err := c.Bind(&_device) if err != nil { return err } for i, device := range config.Config.Devices { if device == _device { config.Config.Devices = append(config.Config.Devices[:i], config.Config.Devices[i+1:]...) err := config.Save() if err != nil { return err } return c.Redirect(http.StatusSeeOther, "/") } } return errors.New("device not found") }