Documentation
¶
Overview ¶
Package webterminal 实现 Web 终端:通过 WebSocket 在浏览器中使用 SSH、Telnet 或本机 Shell, 会话由服务端持久保存,浏览器断开后可按设置保留并重新附着。
SSH 主机密钥采用"首次信任":第一次连接时记录指纹,之后指纹变化会拒绝连接,防止中间人攻击。 本机 Shell 等同于服务器的完全控制权,默认关闭,需要在模块设置中显式开启。
Index ¶
- Constants
- func Fingerprint(k ssh.PublicKey) string
- type Connection
- type LocalConfig
- type Module
- func (m *Module) ID() string
- func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
- func (m *Module) Init(env module.Env) error
- func (m *Module) Routes(r module.Router)
- func (m *Module) Start(context.Context) error
- func (m *Module) Stop() error
- func (m *Module) Title() string
- type Proxy
- type SSHConfig
- type Security
- type Settings
- type Shortcut
- type TelnetConfig
Constants ¶
const ( ProxySOCKS5 = "socks5" ProxyHTTP = "http" )
代理类型
const ( TypeSSH = "ssh" TypeTelnet = "telnet" TypeLocal = "local" )
连接类型
const ID = "webterminal"
ID 是模块标识。
Variables ¶
This section is empty.
Functions ¶
func Fingerprint ¶
Fingerprint 返回主机密钥的 SHA256 指纹(与 ssh-keygen -lf 输出格式一致)。
Types ¶
type Connection ¶
type Connection struct {
Key string `json:"key"`
Name string `json:"name"`
Type string `json:"type"`
SSH SSHConfig `json:"ssh"`
Telnet TelnetConfig `json:"telnet"`
Local LocalConfig `json:"local"`
Remark string `json:"remark"`
// Enable 为复用通用接口保留,终端连接始终可用
Enable bool `json:"enable"`
// QuickAccessDirs 为 SFTP 快速访问目录
QuickAccessDirs []string `json:"quickAccessDirs"`
}
Connection 是一个终端连接配置。
type LocalConfig ¶
type LocalConfig struct {
Shell string `json:"shell"`
WorkDir string `json:"workDir"`
// Env 为附加环境变量
Env map[string]string `json:"env"`
}
LocalConfig 是本机 Shell 参数。
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module 是 Web 终端模块。
func (*Module) ImportLucky ¶
func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)
ImportLucky 实现 luckyimport.Importer。
type Proxy ¶ added in v0.3.0
type Proxy struct {
Enabled bool `json:"enabled"`
Type string `json:"type"`
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
Password string `json:"password"`
}
Proxy 是 SSH / Telnet 连接使用的出口代理。
type SSHConfig ¶
type SSHConfig struct {
Host string `json:"host"`
Port int `json:"port"`
Username string `json:"username"`
// AuthType 为 password 或 key
AuthType string `json:"authType"`
Password string `json:"password"`
PrivateKey string `json:"privateKey"`
// KeyFile 为服务器本机上的私钥文件路径,PrivateKey 为空时使用
KeyFile string `json:"keyFile"`
Passphrase string `json:"passphrase"`
// HostKey 为首次连接时记录的主机密钥指纹(SHA256),为空表示下次连接时重新信任
HostKey string `json:"hostKey"`
// KeepAlive 为保活间隔(秒)
KeepAlive int `json:"keepAlive"`
// WorkDir 为登录后切换到的目录
WorkDir string `json:"workDir"`
// Timeout 为连接超时(秒)
Timeout int `json:"timeout"`
Proxy Proxy `json:"proxy"`
}
SSHConfig 是 SSH 连接参数。
type Security ¶ added in v0.3.0
type Security struct {
AgreementAccepted bool `json:"agreementAccepted"`
TwoFAEnable bool `json:"twoFAEnable"`
// TwoFAKey 为 TOTP 密钥,仅在服务端保存,接口不输出
TwoFAKey string `json:"twoFAKey"`
}
Security 是用户协议与二次验证配置。
type Settings ¶
type Settings struct {
// AllowLocalShell 允许打开本机 Shell
AllowLocalShell bool `json:"allowLocalShell"`
MaxSessions int `json:"maxSessions"`
// IdleTimeout 为会话无输入输出自动结束的时间(分钟),0 不限
IdleTimeout int `json:"idleTimeout"`
// BufferSize 为每个会话的输出回放缓冲(KB)
BufferSize int `json:"bufferSize"`
// HeartbeatInterval 为 WebSocket 心跳间隔(秒)
HeartbeatInterval int `json:"heartbeatInterval"`
// SessionKeepAlive 为浏览器断开后会话保留时间(分钟),0 表示断开即结束
SessionKeepAlive int `json:"sessionKeepAlive"`
}
Settings 是模块级配置。