diff --git a/dyndns/handler/handler.go b/dyndns/handler/handler.go index 90de6be..9d33fe4 100644 --- a/dyndns/handler/handler.go +++ b/dyndns/handler/handler.go @@ -18,7 +18,6 @@ import ( type Handler struct { DB *gorm.DB - AuthHost *model.Host AuthAdmin bool Config Envs Title string @@ -49,15 +48,13 @@ type Error struct { // To gather admin rights the username password combination must match with the credentials given by the env var. func (h *Handler) AuthenticateUpdate(username, password string, c echo.Context) (bool, error) { h.CheckClearInterval() - h.AuthHost = nil host := &model.Host{} if err := h.DB.Where(&model.Host{UserName: username, Password: password}).First(host).Error; err != nil { log.Error("Error:", err) return false, nil } - - h.AuthHost = host + c.Set("updateHost", host) return true, nil } diff --git a/dyndns/handler/host.go b/dyndns/handler/host.go index 84723ca..3a5919f 100644 --- a/dyndns/handler/host.go +++ b/dyndns/handler/host.go @@ -227,11 +227,12 @@ func (h *Handler) DeleteHost(c echo.Context) (err error) { // Hostname, IP and senders IP are validated, a log entry is created // and finally if everything is ok, the DNS Server will be updated func (h *Handler) UpdateIP(c echo.Context) (err error) { - if h.AuthHost == nil { + host, ok := c.Get("updateHost").(*model.Host) + if !ok { return c.String(http.StatusBadRequest, "badauth\n") } - log := &model.Log{Status: false, Host: *h.AuthHost, TimeStamp: time.Now(), UserAgent: nswrapper.ShrinkUserAgent(c.Request().UserAgent())} + log := &model.Log{Status: false, Host: *host, TimeStamp: time.Now(), UserAgent: nswrapper.ShrinkUserAgent(c.Request().UserAgent())} log.SentIP = c.QueryParam(("myip")) // Get caller IP @@ -250,7 +251,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { // Validate hostname hostname := c.QueryParam("hostname") - if hostname == "" || hostname != h.AuthHost.Hostname+"."+h.AuthHost.Domain { + if hostname == "" || hostname != host.Hostname+"."+host.Domain { log.Message = "Hostname or combination of authenticated user and hostname is invalid" if err = h.CreateLogEntry(log); err != nil { l.Error(err)