added custom logout url

This commit is contained in:
Malte 2022-04-12 17:00:52 +02:00
parent f9b4c4dddc
commit 6e81572536
4 changed files with 23 additions and 3 deletions

View File

@ -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 {

View File

@ -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)

View File

@ -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 () {

View File

@ -36,7 +36,7 @@
<a class="nav-link nav-logs" href="/admin/logs">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link nav-logout" href="" id="logout">Logout</a>
<a class="nav-link nav-logout" href="/admin/logout" id="logout">Logout</a>
</li>
</ul>
</nav>