From 3ad186bcb4061f8761794e6a72104840d52520f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4rthlein?= Date: Wed, 29 Apr 2020 10:43:22 +0200 Subject: [PATCH] added error messages to logs and implemented visibility via tooltips --- dyndns/handler/host.go | 5 +++++ dyndns/handler/log.go | 3 +-- dyndns/model/log.go | 1 + dyndns/static/js/actions.js | 11 ++++++++++- dyndns/views/listlogs.html | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/dyndns/handler/host.go b/dyndns/handler/host.go index 5446749..0b02465 100644 --- a/dyndns/handler/host.go +++ b/dyndns/handler/host.go @@ -205,6 +205,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { if log.CallerIP == "" { log.CallerIP, _, err = net.SplitHostPort(c.Request().RemoteAddr) if err != nil { + log.Message = "Bad Request: Unable to get caller IP" if err = h.CreateLogEntry(log); err != nil { fmt.Println(err) } @@ -216,6 +217,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 { + log.Message = "Hostname or combination of authenticated user and hostname is invalid" if err = h.CreateLogEntry(log); err != nil { fmt.Println(err) } @@ -229,6 +231,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { log.SentIP = log.CallerIP ipType = getIPType(log.SentIP) if ipType == "" { + log.Message = "Bad Request: Sent IP is invalid" if err = h.CreateLogEntry(log); err != nil { fmt.Println(err) } @@ -239,6 +242,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { // add/update DNS record if err = h.updateRecord(log.Host.Hostname, log.SentIP, ipType, log.Host.Domain, log.Host.Ttl); err != nil { + log.Message = fmt.Sprintf("DNS error: %v", err) if err = h.CreateLogEntry(log); err != nil { fmt.Println(err) } @@ -249,6 +253,7 @@ func (h *Handler) UpdateIP(c echo.Context) (err error) { log.Host.Ip = log.SentIP log.Host.LastUpdate = log.TimeStamp log.Status = true + log.Message = "No errors occurred" if err = h.CreateLogEntry(log); err != nil { fmt.Println(err) } diff --git a/dyndns/handler/log.go b/dyndns/handler/log.go index e71564a..2e3240f 100644 --- a/dyndns/handler/log.go +++ b/dyndns/handler/log.go @@ -26,8 +26,7 @@ func (h *Handler) ShowLogs(c echo.Context) (err error) { } return c.Render(http.StatusOK, "listlogs", echo.Map{ - "logs": logs, - "config": h.Config, + "logs": logs, }) } diff --git a/dyndns/model/log.go b/dyndns/model/log.go index 30612b2..50764aa 100644 --- a/dyndns/model/log.go +++ b/dyndns/model/log.go @@ -9,6 +9,7 @@ import ( type Log struct { gorm.Model Status bool + Message string Host Host HostID uint SentIP string diff --git a/dyndns/static/js/actions.js b/dyndns/static/js/actions.js index 4a9b3c1..318c87e 100644 --- a/dyndns/static/js/actions.js +++ b/dyndns/static/js/actions.js @@ -113,4 +113,13 @@ $("button.generateHash").click(function () { let input = document.getElementById(id); input.value = randomHash(); -}); \ No newline at end of file +}); + +$(document).ready(function(){ + $(".errorTooltip").tooltip({ + track: true, + content: function () { + return $(this).prop('title'); + } + }); +}); diff --git a/dyndns/views/listlogs.html b/dyndns/views/listlogs.html index 9440aee..e79eeb1 100644 --- a/dyndns/views/listlogs.html +++ b/dyndns/views/listlogs.html @@ -14,7 +14,7 @@ {{range .logs}} - +
{{.Host.Hostname}}.{{.Host.Domain}} {{.SentIP}}