ssh

package
v0.0.0-...-2d4ef54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service interface {
	// SSH 会话。主机来自登记表 t_hosts,终端与文件只能连接登记了 SSH 信息的主机。
	CreateSession(ctx context.Context, hostID, clientIP, userID string) (string, error)
	DisconnectSession(ctx context.Context, sessionID string) error
	// CloseHostSessions 关闭某台主机上全部在线会话(主机连接信息变化或被删除后调用)。
	CloseHostSessions(hostID string)
	ResizeWindow(ctx context.Context, sessionID string, w, h int) error
	GetSessionConn(sessionID string) (*conn.SSHConn, bool)
	SessionBelongsToUser(sessionID, userID string) bool

	// SFTP
	SftpList(ctx context.Context, sessionID string, dirPath string) (interface{}, error)
	SftpUpload(ctx context.Context, sessionID string, dstPath string, files []*multipart.FileHeader) ([]string, error)
	SftpDownload(ctx context.Context, sessionID, filePath string) (*sftp.File, int64, string, error)
	SftpDelete(ctx context.Context, sessionID, path string) error
	SftpMkdir(ctx context.Context, sessionID, path string) error

	// 获取会话管理器(供 WebSocket handler 使用)
	GetSessionManager() *conn.SessionManager
}

Service SSH 服务接口

type ServiceImpl

type ServiceImpl struct {
	// contains filtered or unexported fields
}

ServiceImpl SSH 服务实现

func NewService

func NewService(hosts *dao.HostDAO) *ServiceImpl

NewService 创建 SSH 服务

func (*ServiceImpl) CloseHostSessions

func (s *ServiceImpl) CloseHostSessions(hostID string)

func (*ServiceImpl) CreateSession

func (s *ServiceImpl) CreateSession(ctx context.Context, hostID, clientIP, userID string) (string, error)

func (*ServiceImpl) DisconnectSession

func (s *ServiceImpl) DisconnectSession(ctx context.Context, sessionID string) error

func (*ServiceImpl) GetSessionConn

func (s *ServiceImpl) GetSessionConn(sessionID string) (*conn.SSHConn, bool)

func (*ServiceImpl) GetSessionManager

func (s *ServiceImpl) GetSessionManager() *conn.SessionManager

GetSessionManager 获取会话管理器

func (*ServiceImpl) ResizeWindow

func (s *ServiceImpl) ResizeWindow(ctx context.Context, sessionID string, w, h int) error

func (*ServiceImpl) SessionBelongsToUser

func (s *ServiceImpl) SessionBelongsToUser(sessionID, userID string) bool

func (*ServiceImpl) SftpDelete

func (s *ServiceImpl) SftpDelete(ctx context.Context, sessionID, filePath string) error

func (*ServiceImpl) SftpDownload

func (s *ServiceImpl) SftpDownload(ctx context.Context, sessionID, filePath string) (*sftp.File, int64, string, error)

func (*ServiceImpl) SftpList

func (s *ServiceImpl) SftpList(ctx context.Context, sessionID string, dirPath string) (interface{}, error)

func (*ServiceImpl) SftpMkdir

func (s *ServiceImpl) SftpMkdir(ctx context.Context, sessionID, dirPath string) error

func (*ServiceImpl) SftpUpload

func (s *ServiceImpl) SftpUpload(ctx context.Context, sessionID string, dstPath string, files []*multipart.FileHeader) ([]string, error)

Directories

Path Synopsis
Package dao 读取 SSH 连接需要的主机登记与凭据,并记录主机密钥指纹。
Package dao 读取 SSH 连接需要的主机登记与凭据,并记录主机密钥指纹。
Package model 定义 SSH 服务使用的数据结构。
Package model 定义 SSH 服务使用的数据结构。
Package rpc 提供 ssh 直连端点(WebSocket 终端、SFTP 流式上传/下载)的裸 HTTP 处理器, 经统一 HTTP 转发层 rawhandler 分派。
Package rpc 提供 ssh 直连端点(WebSocket 终端、SFTP 流式上传/下载)的裸 HTTP 处理器, 经统一 HTTP 转发层 rawhandler 分派。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址