完成资产附加属性功能
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -362,8 +363,16 @@ func SessionLsEndpoint(c echo.Context) error {
|
||||
return errors.New("获取sftp客户端失败")
|
||||
}
|
||||
|
||||
if tun.Subject.NextTerminal == nil {
|
||||
nextTerminal, err := CreateNextTerminalBySession(session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tun.Subject.NextTerminal = nextTerminal
|
||||
}
|
||||
|
||||
if tun.Subject.NextTerminal.SftpClient == nil {
|
||||
sftpClient, err := CreateSftpClient(session)
|
||||
sftpClient, err := sftp.NewClient(tun.Subject.NextTerminal.SshClient)
|
||||
if err != nil {
|
||||
logrus.Errorf("创建sftp客户端失败:%v", err.Error())
|
||||
return err
|
||||
|
@ -4,9 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/pkg/sftp"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/crypto/ssh"
|
||||
"net/http"
|
||||
"next-terminal/pkg/global"
|
||||
"next-terminal/pkg/guacd"
|
||||
@ -97,6 +95,7 @@ func SSHEndpoint(c echo.Context) (err error) {
|
||||
|
||||
tun := global.Tun{
|
||||
Protocol: session.Protocol,
|
||||
Mode: session.Mode,
|
||||
WebSocket: ws,
|
||||
}
|
||||
|
||||
@ -242,18 +241,6 @@ func WriteMessage(ws *websocket.Conn, msg Message) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateSshClientBySession(session model.Session) (sshClient *ssh.Client, err error) {
|
||||
|
||||
var (
|
||||
username = session.Username
|
||||
password = session.Password
|
||||
privateKey = session.PrivateKey
|
||||
passphrase = session.Passphrase
|
||||
)
|
||||
|
||||
return term.NewSshClient(session.IP, session.Port, username, password, privateKey, passphrase)
|
||||
}
|
||||
|
||||
func WriteByteMessage(ws *websocket.Conn, p []byte) {
|
||||
err := ws.WriteMessage(websocket.TextMessage, p)
|
||||
if err != nil {
|
||||
@ -261,11 +248,14 @@ func WriteByteMessage(ws *websocket.Conn, p []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
func CreateSftpClient(session model.Session) (sftpClient *sftp.Client, err error) {
|
||||
sshClient, err := CreateSshClientBySession(session)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return sftp.NewClient(sshClient)
|
||||
func CreateNextTerminalBySession(session model.Session) (*term.NextTerminal, error) {
|
||||
var (
|
||||
username = session.Username
|
||||
password = session.Password
|
||||
privateKey = session.PrivateKey
|
||||
passphrase = session.Passphrase
|
||||
ip = session.IP
|
||||
port = session.Port
|
||||
)
|
||||
return term.NewNextTerminal(ip, port, username, password, privateKey, passphrase, 10, 10, "")
|
||||
}
|
||||
|
@ -154,8 +154,9 @@ func TunEndpoint(c echo.Context) error {
|
||||
|
||||
tun := global.Tun{
|
||||
Protocol: session.Protocol,
|
||||
Tunnel: tunnel,
|
||||
Mode: session.Mode,
|
||||
WebSocket: ws,
|
||||
Tunnel: tunnel,
|
||||
}
|
||||
|
||||
if len(session.ConnectionId) == 0 {
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
|
||||
type Tun struct {
|
||||
Protocol string
|
||||
Mode string
|
||||
WebSocket *websocket.Conn
|
||||
Tunnel *guacd.Tunnel
|
||||
NextTerminal *term.NextTerminal
|
||||
@ -25,7 +26,7 @@ func (r *Tun) Close(code int, reason string) {
|
||||
|
||||
ws := r.WebSocket
|
||||
if ws != nil {
|
||||
if r.Protocol == "rdp" || r.Protocol == "vnc" {
|
||||
if r.Mode == "guacd" {
|
||||
err := guacd.NewInstruction("error", reason, strconv.Itoa(code))
|
||||
_ = ws.WriteMessage(websocket.TextMessage, []byte(err.String()))
|
||||
disconnect := guacd.NewInstruction("disconnect")
|
||||
|
@ -92,6 +92,8 @@ func FindAssetAttrMapByAssetId(assetId string) (map[string]interface{}, error) {
|
||||
parameterNames = RDPParameterNames
|
||||
case "vnc":
|
||||
parameterNames = VNCParameterNames
|
||||
case "telnet":
|
||||
parameterNames = TelnetParameterNames
|
||||
}
|
||||
propertiesMap := FindAllPropertiesMap()
|
||||
var attributeMap = make(map[string]interface{})
|
||||
|
Reference in New Issue
Block a user