Skip to content

Commit 0f0e721

Browse files
committed
feat: Terminal connection supports reset
1 parent 3db8e47 commit 0f0e721

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

agent/app/api/v2/setting.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ func (b *BaseApi) CheckLocalConn(c *gin.Context) {
8484
helper.SuccessWithData(c, err == nil)
8585
}
8686

87+
// @Tags System Setting
88+
// @Summary Update local is conn
89+
// @Accept json
90+
// @Param request body dto.SSHDefaultConn true "request"
91+
// @Success 200
92+
// @Security ApiKeyAuth
93+
// @Security Timestamp
94+
// @Router /settings/ssh/conn/default [post]
95+
// @x-panel-log {"bodyKeys":["defaultConn"],"paramKeys":[],"BeforeFunctions":[],"formatZH":"本地终端默认连接 [defaultConn]","formatEN":"update system default conn [defaultConn]"}
96+
func (b *BaseApi) SetDefaultIsConn(c *gin.Context) {
97+
var req dto.SSHDefaultConn
98+
if err := helper.CheckBindAndValidate(&req, c); err != nil {
99+
return
100+
}
101+
102+
if err := settingService.SetDefaultIsConn(req); err != nil {
103+
helper.InternalServer(c, err)
104+
return
105+
}
106+
helper.Success(c)
107+
}
108+
87109
// @Tags System Setting
88110
// @Summary Check local conn info
89111
// @Success 200 {boolean} isOk

agent/app/dto/setting.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ type Clean struct {
6262
Size uint64 `json:"size"`
6363
}
6464

65+
type SSHDefaultConn struct {
66+
WithReset bool `json:"withReset"`
67+
DefaultConn string `json:"defaultConn"`
68+
}
6569
type SSHConnData struct {
6670
Addr string `json:"addr" validate:"required"`
6771
Port uint `json:"port" validate:"required,number,max=65535,min=1"`

agent/app/service/setting.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/1Panel-dev/1Panel/agent/app/model"
1010
"github.com/1Panel-dev/1Panel/agent/app/repo"
1111
"github.com/1Panel-dev/1Panel/agent/buserr"
12+
"github.com/1Panel-dev/1Panel/agent/constant"
1213
"github.com/1Panel-dev/1Panel/agent/utils/encrypt"
1314
"github.com/1Panel-dev/1Panel/agent/utils/ssh"
1415
"github.com/jinzhu/copier"
@@ -22,6 +23,7 @@ type ISettingService interface {
2223

2324
TestConnByInfo(req dto.SSHConnData) bool
2425
SaveConnInfo(req dto.SSHConnData) error
26+
SetDefaultIsConn(req dto.SSHDefaultConn) error
2527
GetSystemProxy() (*dto.SystemProxy, error)
2628
GetLocalConn() dto.SSHConnData
2729
GetSettingByKey(key string) string
@@ -125,6 +127,15 @@ func (u *SettingService) SaveConnInfo(req dto.SSHConnData) error {
125127
return nil
126128
}
127129

130+
func (u *SettingService) SetDefaultIsConn(req dto.SSHDefaultConn) error {
131+
if req.DefaultConn == constant.StatusDisable && req.WithReset {
132+
if err := settingRepo.Update("LocalSSHConn", ""); err != nil {
133+
return err
134+
}
135+
}
136+
return settingRepo.Update("LocalSSHConnShow", req.DefaultConn)
137+
}
138+
128139
func (u *SettingService) GetSystemProxy() (*dto.SystemProxy, error) {
129140
systemProxy := dto.SystemProxy{}
130141
systemProxy.Type, _ = settingRepo.GetValueByKey("ProxyType")
@@ -138,6 +149,7 @@ func (u *SettingService) GetSystemProxy() (*dto.SystemProxy, error) {
138149

139150
func (u *SettingService) GetLocalConn() dto.SSHConnData {
140151
var data dto.SSHConnData
152+
data.LocalSSHConnShow, _ = settingRepo.GetValueByKey("LocalSSHConnShow")
141153
connItem, _ := settingRepo.GetValueByKey("LocalSSHConn")
142154
if len(connItem) == 0 {
143155
return data

agent/router/ro_setting.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (s *SettingRouter) InitRouter(Router *gin.RouterGroup) {
3232

3333
settingRouter.POST("/ssh/check", baseApi.CheckLocalConn)
3434
settingRouter.GET("/ssh/conn", baseApi.LoadLocalConn)
35+
settingRouter.POST("/ssh/default", baseApi.SetDefaultIsConn)
3536
settingRouter.POST("/ssh", baseApi.SaveLocalConn)
3637
settingRouter.POST("/ssh/check/info", baseApi.CheckLocalConnByInfo)
3738
}

0 commit comments

Comments
 (0)