mirror of
https://github.com/AuxXxilium/docker-ddns-server.git
synced 2024-11-23 23:00:59 +07:00
replaced AuthHost by context set&get
This commit is contained in:
parent
13f52a4bd8
commit
6432c042f5
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user