Skip to content

Commit 1f76fae

Browse files
committed
feat: Terminal connection supports reset
1 parent 191396c commit 1f76fae

File tree

18 files changed

+81
-17
lines changed

18 files changed

+81
-17
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
}

frontend/src/api/modules/terminal.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export const getHostByID = (id: number) => {
1313
export const getHostTree = (params: Host.ReqSearch) => {
1414
return http.post<Array<Host.HostTree>>(`/core/hosts/tree`, params);
1515
};
16+
export const updateLocalConn = (param: { withReset: boolean; defaultConn: string }) => {
17+
return http.post(`/settings/ssh/default`, param);
18+
};
1619
export const addHost = (params: Host.HostOperate) => {
1720
let request = deepCopy(params) as Host.HostOperate;
1821
if (request.password) {

frontend/src/components/del-dialog/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
<template #footer>
2424
<span class="dialog-footer">
25-
<el-button @click="open = false" :disabled="loading">
25+
<el-button @click="handleClose" :disabled="loading">
2626
{{ $t('commons.button.cancel') }}
2727
</el-button>
2828
<el-button type="primary" @click="onConfirm" :disabled="loading">
@@ -88,7 +88,6 @@ const onConfirm = async () => {
8888
await form
8989
.api(form.params)
9090
.then(() => {
91-
emit('cancel');
9291
emit('search');
9392
if (!noMsg.value) {
9493
MsgSuccess(successMsg.value ?? i18n.global.t('commons.msg.deleteSuccess'));

frontend/src/lang/modules/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,7 @@ const message = {
12701270
defaultConn: 'Default Connection',
12711271
defaultConnHelper:
12721272
'This operation will automatically connect to the node terminal after opening the terminal for 【{0}】. Continue?',
1273+
withReset: 'Reset Connection Information',
12731274
localConnJump:
12741275
'Default connection information is maintained in [Terminal - Settings]. If connection fails, please edit there!',
12751276
localHelper: 'The `local` name is used only for system local identification',

frontend/src/lang/modules/es-es.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,7 @@ const message = {
12791279
defaultConn: 'Conexión predeterminada',
12801280
defaultConnHelper:
12811281
'Esta operación conectará automáticamente al terminal del nodo después de abrir el terminal para 【{0}】. ¿Continuar?',
1282+
withReset: 'Restablecer Información de Conexión',
12821283
localConnJump:
12831284
'La información de conexión predeterminada se mantiene en [Terminal - Configuración]. Si la conexión falla, ¡edite allí!',
12841285
localHelper: 'El nombre `local` se utiliza solo para identificación interna del sistema',

frontend/src/lang/modules/ja.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ const message = {
12361236
defaultConn: 'デフォルト接続',
12371237
defaultConnHelper:
12381238
'この操作は【{0}】のターミナルを開いた後、自動的にノードターミナルに接続します。続行しますか?',
1239+
withReset: '接続情報をリセット',
12391240
localConnJump:
12401241
'デフォルト接続情報は【ターミナル - 設定】で管理されています。接続に失敗した場合はこちらで編集してください!',
12411242
localHelper: 'ローカル名はシステムのローカル識別にのみ使用されます。',

frontend/src/lang/modules/ko.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ const message = {
12251225
local: '로컬',
12261226
defaultConn: '기본 연결',
12271227
defaultConnHelper: '이 작업은 【{0}】의 터미널을 연 후 자동으로 노드 터미널에 연결됩니다. 계속하시겠습니까?',
1228+
withReset: '연결 정보 재설정',
12281229
localConnJump: '기본 연결 정보는 [터미널 - 설정]에서 관리됩니다. 연결 실패 시 해당 위치에서 편집하세요!',
12291230
localHelper: '로컬 이름은 시스템 로컬 식별에만 사용됩니다.',
12301231
connLocalErr: '자동 인증에 실패했습니다. 로컬 서버 로그인 정보를 입력해주세요.',

0 commit comments

Comments
 (0)