From 6e81572536afff94c52fcd9f049c32876d8c967e Mon Sep 17 00:00:00 2001 From: Malte Date: Tue, 12 Apr 2022 17:00:52 +0200 Subject: [PATCH] added custom logout url --- dyndns/handler/handler.go | 9 +++++++++ dyndns/main.go | 9 +++++++++ dyndns/static/js/actions-1.0.0.js | 6 ++++-- dyndns/views/layouts/master.html | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/dyndns/handler/handler.go b/dyndns/handler/handler.go index fd9305e..02d2f76 100644 --- a/dyndns/handler/handler.go +++ b/dyndns/handler/handler.go @@ -25,6 +25,7 @@ type Handler struct { LastClearedLogs time.Time ClearInterval uint64 AllowWildcard bool + LogoutUrl string } type Envs struct { @@ -125,6 +126,14 @@ func (h *Handler) ParseEnvs() (adminAuth bool, err error) { log.Info("Wildcard allowed") } } + logoutUrl, ok := os.LookupEnv("DDNS_LOGOUT_URL") + if ok { + if len(logoutUrl) > 0 { + log.Info("Logout url set: ", logoutUrl) + h.LogoutUrl = logoutUrl + } + } + clearEnv := os.Getenv("DDNS_CLEAR_LOG_INTERVAL") clearInterval, err := strconv.ParseUint(clearEnv, 10, 32) if err != nil { diff --git a/dyndns/main.go b/dyndns/main.go index b3174b5..610ff3a 100644 --- a/dyndns/main.go +++ b/dyndns/main.go @@ -79,6 +79,15 @@ func main() { groupAdmin.POST("/hosts/add", h.CreateHost) groupAdmin.POST("/hosts/edit/:id", h.UpdateHost) groupAdmin.GET("/hosts/delete/:id", h.DeleteHost) + //redirect to logout + groupAdmin.GET("/logout", func(c echo.Context) error { + // either custom url + if len(h.LogoutUrl) > 0 { + return c.Redirect(302, h.LogoutUrl) + } + // or standard url + return c.Redirect(302, "../") + }) groupAdmin.POST("/cnames/add", h.CreateCName) groupAdmin.GET("/cnames/delete/:id", h.DeleteCName) diff --git a/dyndns/static/js/actions-1.0.0.js b/dyndns/static/js/actions-1.0.0.js index eb06136..1331251 100644 --- a/dyndns/static/js/actions-1.0.0.js +++ b/dyndns/static/js/actions-1.0.0.js @@ -64,6 +64,7 @@ $("button.add, button.edit").click(function () { }); $("#logout").click(function (){ + //document.execCommand("ClearAuthenticationCache"); try { // This is for Firefox $.ajax({ @@ -73,7 +74,7 @@ $("#logout").click(function (){ password: 'reset', // If the return is 401, refresh the page to request new details. statusCode: { 401: function() { - document.location = document.location; + // document.location = document.location; } } }); @@ -83,9 +84,10 @@ $("#logout").click(function (){ if (!document.execCommand("ClearAuthenticationCache")) { // exeCommand returns false if it didn't work (which happens in Chrome) so as a last // resort refresh the page providing new, invalid details. - document.location = "http://reset:reset@" + document.location.hostname + document.location.pathname; + // document.location = location.protocol+"//reset:reset@" + document.location.hostname + document.location.pathname; } } + console.log("first logout") }); $("button.addCName").click(function () { diff --git a/dyndns/views/layouts/master.html b/dyndns/views/layouts/master.html index 90f18c2..8b84234 100644 --- a/dyndns/views/layouts/master.html +++ b/dyndns/views/layouts/master.html @@ -36,7 +36,7 @@ Logs