From 6ad1da14ba97eb5242b85847ba9123549796bb27 Mon Sep 17 00:00:00 2001 From: dushixiang Date: Tue, 26 Jan 2021 22:15:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=99=AE=E9=80=9A=E7=94=A8=E6=88=B7=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=8A=A8=E6=80=81=E5=91=BD=E4=BB=A4=E6=97=B6=E4=B9=9F?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/api/ssh.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/api/ssh.go b/pkg/api/ssh.go index f4ccf27..98d7503 100644 --- a/pkg/api/ssh.go +++ b/pkg/api/ssh.go @@ -3,6 +3,7 @@ package api import ( "bytes" "encoding/json" + "errors" "fmt" "github.com/gorilla/websocket" "github.com/labstack/echo/v4" @@ -11,6 +12,7 @@ import ( "golang.org/x/crypto/ssh" "net/http" "next-terminal/pkg/model" + "next-terminal/pkg/utils" "strconv" "sync" "time" @@ -74,6 +76,19 @@ func SSHEndpoint(c echo.Context) error { width, _ := strconv.Atoi(c.QueryParam("width")) height, _ := strconv.Atoi(c.QueryParam("height")) + user, _ := GetCurrentAccount(c) + if model.TypeUser == user.Type { + // 检测是否有访问权限 + assetIds, err := model.FindAssetIdsByUserId(user.ID) + if err != nil { + return err + } + + if !utils.Contains(assetIds, assetId) { + return errors.New("您没有权限访问此资产") + } + } + sshClient, err := CreateSshClient(assetId) if err != nil { logrus.Errorf("创建SSH客户端失败:%v", err.Error())