Skip to content

Commit

Permalink
Merge pull request #2 from benjaminbear/improve-error-logging
Browse files Browse the repository at this point in the history
Improve error logging
  • Loading branch information
benjaminbear authored Apr 29, 2020
2 parents dfba93a + 3ad186b commit d84bcbe
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
5 changes: 5 additions & 0 deletions dyndns/handler/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions dyndns/handler/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

Expand Down
1 change: 1 addition & 0 deletions dyndns/model/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Log struct {
gorm.Model
Status bool
Message string
Host Host
HostID uint
SentIP string
Expand Down
7 changes: 0 additions & 7 deletions dyndns/static/css/bootstrap.min.css

This file was deleted.

11 changes: 10 additions & 1 deletion dyndns/static/js/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ $("button.generateHash").click(function () {

let input = document.getElementById(id);
input.value = randomHash();
});
});

$(document).ready(function(){
$(".errorTooltip").tooltip({
track: true,
content: function () {
return $(this).prop('title');
}
});
});
7 changes: 0 additions & 7 deletions dyndns/static/js/bootstrap.min.js

This file was deleted.

2 changes: 0 additions & 2 deletions dyndns/static/js/jquery-3.4.1.min.js

This file was deleted.

12 changes: 8 additions & 4 deletions dyndns/views/layouts/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<title>TheBBCloud DynDNS</title>

<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<!-- JQueryUI base CSS -->
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.min.css" integrity="sha256-sEGfrwMkIjbgTBwGLVK38BG/XwIiNC/EAG9Rzsfda6A=" crossorigin="anonymous" />

<!-- Custom styles for this template -->
<link href="/static/css/narrow-jumbotron.css" rel="stylesheet">
Expand Down Expand Up @@ -50,9 +53,10 @@ <h3 class="text-muted">TheBBCloud DynDNS</h3>
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/static/js/ie10-viewport-bug-workaround.js"></script>
<script src="/static/js/jquery-3.4.1.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<script src="/static/js/actions.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion dyndns/views/listlogs.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h3 class="text-center mb-4">Log Entries</h3>
</thead>
<tbody>
{{range .logs}}
<tr>
<tr class="errorTooltip" title="<b>{{if .Status}}Successful{{else}}Failed{{end}}</b><br>{{.Message}}">
<td class="align-middle mx-auto"><div class="{{if .Status}}bg-success{{else}}bg-danger{{end}}" style="width: 16px; height: 16px; margin: auto"></div></td>
<td>{{.Host.Hostname}}.{{.Host.Domain}}</td>
<td>{{.SentIP}}</td>
Expand Down

0 comments on commit d84bcbe

Please sign in to comment.