webssh

package module
v0.0.0-...-426fec6 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: MIT Imports: 19 Imported by: 0

README

WEBSSH

基于vue、xterm、golang实现的web ssh客户端程序

特性

  • 前后端分离,前端使用xterm、vue,后端使用golang写的服务
  • 支持录像审计,支持录像回看

run demo

  • 编译前端程序
$ cd front
$ npm -i
$ npm run build # 可以看到在front生成一个dist目录,里头就是编译后的前端文件
  • 编译golang程序

修改main.go文件中目标主机和登录方式

confing := &webssh.WebSSHConfig{
		Record:     true,
		RecPath:    "./rec/cast/",
		RemoteAddr: "localhost:22",
		User:       "wida",
		Password:   "wida",
		AuthModel:  webssh.PASSWORD,
	}
$ go build -o webssh bin/sever/main.go   
$ ./webssh
  • 用浏览器打开http://localhost:8080/#/term

查看录像

  • 用浏览器打开http://localhost:8080/#/rec,顶部有选择器,选择生成的文件播放(手动点击播放)。

动画演示

动画演示

Documentation

Index

Constants

View Source
const (
	MsgData   = '1'
	MsgResize = '2'
)

Variables

This section is empty.

Functions

func NewSSHClient

func NewSSHClient(conf *SSHClientConfig) (*ssh.Client, error)

Types

type AuthModel

type AuthModel int8
const (
	PASSWORD AuthModel = iota + 1
	PUBLICKEY
)

type RecHeader

type RecHeader struct {
	Version   int   `json:"version"`
	Width     int   `json:"width"`
	Height    int   `json:"height"`
	Timestamp int64 `json:"timestamp"`
	Env       struct {
		Shell string `json:"SHELL"`
		Term  string `json:"TERM"`
	} `json:"env"`
}

type RecType

type RecType string
const (
	InputType  RecType = "i"
	OutPutType RecType = "o"
)

type Recorder

type Recorder struct {
	StartTime time.Time
	Writer    io.Writer
	sync.Mutex
}

func NewRecorder

func NewRecorder(writer io.Writer) *Recorder

func (*Recorder) WriteData

func (rec *Recorder) WriteData(rectype RecType, data string)

func (*Recorder) WriteHeader

func (rec *Recorder) WriteHeader(height, width int)

type Resize

type Resize struct {
	Columns int
	Rows    int
}

type SSHClientConfig

type SSHClientConfig struct {
	AuthModel AuthModel
	HostAddr  string
	User      string
	Password  string
	KeyPath   string
	Timeout   time.Duration
}

func SSHClientConfigPassword

func SSHClientConfigPassword(hostAddr, user, Password string) *SSHClientConfig

func SSHClientConfigPulicKey

func SSHClientConfigPulicKey(hostAddr, user, keyPath string) *SSHClientConfig

type Turn

type Turn struct {
	StdinPipe io.WriteCloser
	Session   *ssh.Session
	WsConn    *websocket.Conn
	Recorder  *Recorder
}

func NewTurn

func NewTurn(wsConn *websocket.Conn, sshClient *ssh.Client, rec *Recorder) (*Turn, error)

func (*Turn) Close

func (t *Turn) Close() error

func (*Turn) LoopRead

func (t *Turn) LoopRead(logBuff *bytes.Buffer, context context.Context) error

func (*Turn) Read

func (t *Turn) Read(p []byte) (n int, err error)

func (*Turn) SessionWait

func (t *Turn) SessionWait() error

func (*Turn) Write

func (t *Turn) Write(p []byte) (n int, err error)

type WebSSH

type WebSSH struct {
	*WebSSHConfig
}

func NewWebSSH

func NewWebSSH(conf *WebSSHConfig) *WebSSH

func (WebSSH) RecoderList

func (w WebSSH) RecoderList(c *gin.Context)

func (WebSSH) ServeConn

func (w WebSSH) ServeConn(c *gin.Context)

type WebSSHConfig

type WebSSHConfig struct {
	Record     bool
	RecPath    string
	RemoteAddr string
	User       string
	Password   string
	AuthModel  AuthModel
	PkPath     string
}

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

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