From 68a4bbd10c780538999359578c61191e88d0bbec Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Fri, 1 Apr 2022 08:05:07 +0200 Subject: [PATCH] be sure to close an SSH connection if all channels are idle Signed-off-by: Nicola Murino --- common/common.go | 6 ++++-- httpd/webadmin.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/common.go b/common/common.go index 17c2585f..107ee4f1 100644 --- a/common/common.go +++ b/common/common.go @@ -787,8 +787,10 @@ func (conns *ActiveConnections) checkIdles() { toClose := true for _, conn := range conns.connections { if strings.Contains(conn.GetID(), idToMatch) { - toClose = false - break + if time.Since(conn.GetLastActivity()) <= Config.idleTimeoutAsDuration { + toClose = false + break + } } } if toClose { diff --git a/httpd/webadmin.go b/httpd/webadmin.go index c7d47fab..474a5b22 100644 --- a/httpd/webadmin.go +++ b/httpd/webadmin.go @@ -1509,7 +1509,7 @@ func handleWebAddAdminPost(w http.ResponseWriter, r *http.Request) { renderForbiddenPage(w, r, err.Error()) return } - err = dataprovider.AddAdmin(&admin, claims.Username, util.GetIPFromRemoteAddress(r.Method)) + err = dataprovider.AddAdmin(&admin, claims.Username, util.GetIPFromRemoteAddress(r.RemoteAddr)) if err != nil { renderAddUpdateAdminPage(w, r, &admin, err.Error(), true) return