Skip to content

Commit

Permalink
perf: 会话最大连接时间
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Aug 9, 2023
1 parent 07512cc commit 9c21cd5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/jms-sdk-go/model/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type TerminalConfig struct {
SessionKeepDuration int `json:"TERMINAL_SESSION_KEEP_DURATION"`
TelnetRegex string `json:"TERMINAL_TELNET_REGEX"`
MaxIdleTime int `json:"SECURITY_MAX_IDLE_TIME"`
MaxSessionTime int `json:"SECURITY_MAX_SESSION_TIME"`
HeartbeatDuration int `json:"TERMINAL_HEARTBEAT_INTERVAL"`
HostKey string `json:"TERMINAL_HOST_KEY"`
MaxStoreFTPFileSize int `json:"FTP_FILE_MAX_STORE"`
Expand Down
10 changes: 10 additions & 0 deletions pkg/tunnel/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (t *Connection) Run(ctx *gin.Context) (err error) {
}
}(t)
maxIndexTime := t.Sess.TerminalConfig.MaxIdleTime
maxSessionTimeInt := t.Sess.TerminalConfig.MaxSessionTime
maxSessionDuration := time.Duration(maxSessionTimeInt) * time.Hour
maxSessionTime := time.Now().Add(maxSessionDuration)
maxIdleMinutes := time.Duration(maxIndexTime) * time.Minute
activeDetectTicker := time.NewTicker(time.Minute)
defer activeDetectTicker.Stop()
Expand All @@ -258,6 +261,13 @@ func (t *Connection) Run(ctx *gin.Context) (err error) {
case <-activeChan:
latestActive = time.Now()
case detectTime := <-activeDetectTicker.C:
if detectTime.After(maxSessionTime) {
errSession := NewJMSMaxSessionTimeError(t.Sess.TerminalConfig.MaxSessionTime)
_ = t.SendWsMessage(errSession.Instruction())
logger.Errorf("Session[%s] terminated by max session time %d hour",
t, maxSessionTimeInt)
return nil
}
if detectTime.After(latestActive.Add(maxIdleMinutes)) {
errIdle := NewJMSIdleTimeOutError(maxIndexTime)
_ = t.SendWsMessage(errIdle.Instruction())
Expand Down
8 changes: 6 additions & 2 deletions pkg/tunnel/ws_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ func NewJMSIdleTimeOutError(min int) JMSGuacamoleError {
return NewJMSGuacamoleError(1003, strconv.Itoa(min))
}

func NewJMSMaxSessionTimeError(min int) JMSGuacamoleError {
return NewJMSGuacamoleError(1010, strconv.Itoa(min))
}

var (
ErrNoSession = NewJMSGuacamoleError(1000, "Not Found Session")

ErrAuthUser = NewJMSGuacamoleError(1001, "Not auth user")

ErrBadParams = NewJMSGuacamoleError(1002, "Not session params")

ErrIdleTimeOut = NewJMSGuacamoleError(1003, "Terminated by idle timeout")
//ErrIdleTimeOut = NewJMSGuacamoleError(1003, "Terminated by idle timeout")

ErrPermissionExpired = NewJMSGuacamoleError(1004, "Terminated by permission expired")

ErrTerminatedByAdmin = NewJMSGuacamoleError(1005, "Terminated by Admin")
//ErrTerminatedByAdmin = NewJMSGuacamoleError(1005, "Terminated by Admin")

ErrAPIFailed = NewJMSGuacamoleError(1006, "API failed")

Expand Down
3 changes: 3 additions & 0 deletions ui/src/components/GuacamoleConnect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ export default {
case 1003:
msg = msg.replace('{PLACEHOLDER}', status.message)
break
case 1010:
msg = msg.replace('{PLACEHOLDER}', status.message)
break
}
this.$alert(msg, this.$t('ErrTitle'), {
confirmButtonText: this.$t('OK'),
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/lang/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const message = {
JMSErrGatewayFailed: '网关连接失败',
JMSErrGuacamoleServer: '无法连接 Guacamole 服务器',
JMSErrDisconnected: '会话连接已断开',
JMSErrMaxSession: '超过最大会话时间{PLACEHOLDER}小时,断开连接',
GuaErrUpstreamNotFound: '无法连接到远程桌面服务器(网络不可达 | 安全策略错误)',
GuaErrSessionConflict: '因与另一个连接冲突,远程桌面服务器关闭了本连接。请稍后重试。',
GuaErrClientUnauthorized: '用户名和密码认证错误,登录失败',
Expand Down
1 change: 1 addition & 0 deletions ui/src/i18n/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const message = {
JMSErrGatewayFailed: 'Gateway not available',
JMSErrGuacamoleServer: 'Connect guacamole server failed',
JMSErrDisconnected: 'Session Disconnected',
JMSErrMaxSession: 'Session connection time more than {PLACEHOLDER} hours, disconnect',
GuaErrUpstreamNotFound: 'The remote desktop server does not appear to exist, or cannot be reached over the network.',
GuaErrSessionConflict: 'The session has ended because it conflicts with another session.',
GuaErrClientUnauthorized: 'User failed to logged in. (username and password are incorrect)',
Expand Down
3 changes: 2 additions & 1 deletion ui/src/utils/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const ErrorStatusCodes = {
1006: 'JMSErrAPIFailed',
1007: 'JMSErrGatewayFailed',
1008: 'JMSErrGuacamoleServer',
1009: 'JMSErrDisconnected'
1009: 'JMSErrDisconnected',
1010: 'JMSErrMaxSession'
}

export function ConvertAPIError(errMsg) {
Expand Down

0 comments on commit 9c21cd5

Please sign in to comment.