Skip to content

Commit

Permalink
feat(webconsole): keep_websocket_session option (#21781)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexi authored Dec 11, 2024
1 parent 5602b16 commit 93587b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/webconsole/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 {
Expand Down
4 changes: 3 additions & 1 deletion pkg/webconsole/server/ssh_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}()

Expand Down
6 changes: 4 additions & 2 deletions pkg/webconsole/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93587b6

Please sign in to comment.