From f1ed976c17dd9e63c4f5eed4221f793918364a0d Mon Sep 17 00:00:00 2001 From: ssongliu Date: Mon, 13 Mar 2023 11:14:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E7=BB=88=E7=AB=AF=E5=8F=82=E6=95=B0=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E9=A1=B5=E9=9D=A2=E5=8D=A1=E6=AD=BB=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/terminal.go | 14 ++++++++++++-- backend/router/ro_setting.go | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/backend/app/api/v1/terminal.go b/backend/app/api/v1/terminal.go index 0be0d0589..43d04341f 100644 --- a/backend/app/api/v1/terminal.go +++ b/backend/app/api/v1/terminal.go @@ -9,6 +9,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/app/api/v1/helper" "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" + "github.com/1Panel-dev/1Panel/backend/utils/cmd" "github.com/1Panel-dev/1Panel/backend/utils/copier" "github.com/1Panel-dev/1Panel/backend/utils/ssh" "github.com/1Panel-dev/1Panel/backend/utils/terminal" @@ -156,6 +157,15 @@ func (b *BaseApi) ContainerWsSsh(c *gin.Context) { } defer wsConn.Close() + cmds := fmt.Sprintf("docker exec %s %s", containerID, command) + if len(user) != 0 { + cmds = fmt.Sprintf("docker exec -u %s %s %s", user, containerID, command) + } + stdout, err := cmd.Exec(cmds) + if wshandleError(wsConn, errors.WithMessage(err, stdout)) { + return + } + commands := fmt.Sprintf("docker exec -it %s %s", containerID, command) if len(user) != 0 { commands = fmt.Sprintf("docker exec -it -u %s %s %s", user, containerID, command) @@ -187,8 +197,8 @@ func wshandleError(ws *websocket.Conn, err error) bool { if err != nil { global.LOG.Errorf("handler ws faled:, err: %v", err) dt := time.Now().Add(time.Second) - if err := ws.WriteControl(websocket.CloseMessage, []byte(err.Error()), dt); err != nil { - global.LOG.Errorf("websocket writes control message failed, err: %v", err) + if ctlerr := ws.WriteControl(websocket.CloseMessage, []byte(err.Error()), dt); ctlerr != nil { + _ = ws.WriteMessage(websocket.TextMessage, []byte(err.Error())) } return true } diff --git a/backend/router/ro_setting.go b/backend/router/ro_setting.go index c06df62f8..544e21b1f 100644 --- a/backend/router/ro_setting.go +++ b/backend/router/ro_setting.go @@ -19,8 +19,8 @@ func (s *SettingRouter) InitSettingRouter(Router *gin.RouterGroup) { baseApi := v1.ApiGroupApp.BaseApi { router.POST("/search", baseApi.GetSettingInfo) + router.POST("/expired/handle", baseApi.HandlePasswordExpired) settingRouter.GET("/search/available", baseApi.GetSystemAvailable) - settingRouter.POST("/expired/handle", baseApi.HandlePasswordExpired) settingRouter.POST("/update", baseApi.UpdateSetting) settingRouter.POST("/port/update", baseApi.UpdatePort) settingRouter.POST("/password/update", baseApi.UpdatePassword)