feat(webconsole): keep_websocket_session option (#21782)

This commit is contained in:
Zexi Li
2024-12-11 14:26:29 +08:00
committed by GitHub
parent 85c50c66db
commit f7f7684058
3 changed files with 9 additions and 3 deletions
+2
View File
@@ -36,6 +36,8 @@ type WebConsoleOptions struct {
EnableWatermark bool `help:"enable water mark" default:"false"`
EnableCommandRecording bool `help:"enable command recording" default:"false"`
KeepWebsocketSession bool `help:"keep websocket session" default:"false"`
}
func OnOptionsChange(oldO, newO interface{}) bool {
+3 -1
View File
@@ -278,7 +278,9 @@ func (s *WebsocketServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
delSftpClient(s.Session.Id)
s.sftp.Close()
s.conn.Close()
s.Session.Close()
if !options.Options.KeepWebsocketSession {
s.Session.Close()
}
keepAliveDone <- struct{}{}
}()
+4 -2
View File
@@ -92,8 +92,10 @@ func (man *SSessionManager) Get(accessToken string) (*SSession, bool) {
s := obj.(*SSession)
protocol := s.GetProtocol()
if protocol != SPICE && time.Since(s.AccessedAt) < AccessInterval {
log.Warningf("Protol: %q, Token: %s, Session: %s can't be accessed during %s, last accessed at: %s", s.GetProtocol(), accessToken, s.Id, AccessInterval, s.AccessedAt)
return nil, false
if !(protocol == WS && o.Options.KeepWebsocketSession) {
log.Warningf("Protol: %q, Token: %s, Session: %s can't be accessed during %s, last accessed at: %s", s.GetProtocol(), accessToken, s.Id, AccessInterval, s.AccessedAt)
return nil, false
}
}
s.AccessedAt = time.Now()
return s, true