ssh

package
v0.0.0-...-5870b03 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: GPL-3.0 Imports: 25 Imported by: 2

Documentation

Index

Constants

View Source
const (
	//直连
	NormalSSHMode sshMode = iota
	//通过跳板机
	RemoteSSHMode
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Forward

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

func NewForward

func NewForward(httpCtx *hfw.HTTPContext, t ForwardType, forwardConfig ForwardConfig) (l *Forward, err error)

func NewLocalForward

func NewLocalForward(httpCtx *hfw.HTTPContext, forwardConfig ForwardConfig) (l *Forward, err error)

func NewRemoteForward

func NewRemoteForward(httpCtx *hfw.HTTPContext, forwardConfig ForwardConfig) (l *Forward, err error)

func (*Forward) Accept

func (l *Forward) Accept(c *SSH, listen net.Listener, fi ForwardIni)

func (*Forward) BindAndAccept

func (l *Forward) BindAndAccept(c *SSH, fi ForwardIni)

func (*Forward) Close

func (l *Forward) Close()

func (*Forward) Hand

func (l *Forward) Hand(c *SSH, conn net.Conn, fi ForwardIni)

type ForwardConfig

type ForwardConfig struct {
	SSHConfig
	Inner map[string]ForwardIni

	Indirect map[string]ForwardConfig
}

type ForwardIni

type ForwardIni struct {
	Addr string `toml:"addr"`
	Bind string `toml:"bind"`
}

type ForwardType

type ForwardType uint8
const (
	LOCAL  ForwardType = 1
	REMOTE ForwardType = 2
)

type Proxy

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

func NewProxy

func NewProxy(httpCtx *hfw.HTTPContext, sshConfig SSHConfig, pi *ProxyIni) (p *Proxy, err error)

func (*Proxy) Accept

func (p *Proxy) Accept()

func (*Proxy) Bind

func (p *Proxy) Bind() (err error)

func (*Proxy) Close

func (p *Proxy) Close()

func (*Proxy) HandHTTP

func (p *Proxy) HandHTTP(conn net.Conn) (err error)

func (*Proxy) HandSocks5

func (p *Proxy) HandSocks5(conn net.Conn) (err error)

func (*Proxy) Listener

func (p *Proxy) Listener() net.Listener

func (*Proxy) SSH

func (p *Proxy) SSH() *SSH

type ProxyIni

type ProxyIni struct {
	Bind string `toml:"bind"`
	//区分是http还是socks5
	IsHTTP bool `toml:"is_http"`
	//是否所有请求通过ssh访问
	IsSSH bool `toml:"is_ssh"`
	//是否根据pac决定是否通过ssh访问,如果IsSSH=true,此配置无效
	IsPac bool `toml:"is_pac"`
	//如果不在pac列表里,是否中断,IsPac=true才生效
	IsBreak bool `toml:"is_break"`
}

type SSH

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

SSH ..

func NewSSH

func NewSSH(sshConfig SSHConfig) (ins *SSH, err error)

NewSSH 建立第一个ssh连接,一般是跳板机

func (*SSH) Check

func (this *SSH) Check() (err error)

func (*SSH) Close

func (this *SSH) Close()

到0后,关闭连接

func (*SSH) Config

func (this *SSH) Config() SSHConfig

func (*SSH) Connect

func (this *SSH) Connect(addr string) (conn net.Conn, err error)

func (*SSH) Dial

func (this *SSH) Dial() (err error)

func (*SSH) DialRemote

func (this *SSH) DialRemote(sshConfig SSHConfig) (ins *SSH, err error)

DialRemote 通过跳板连接其他服务器

func (*SSH) Exec

func (this *SSH) Exec(cmd string) (string, error)

一个Session只能执行一次,获取ssh执行命令的结果

func (*SSH) ExecWithPty

func (this *SSH) ExecWithPty(cmd string, timeout time.Duration) error

一个Session只能执行一次,直接把结果输出到终端 不允许超过3s

func (*SSH) GetReconnectionTime

func (this *SSH) GetReconnectionTime() int

func (*SSH) Listen

func (this *SSH) Listen(addr string) (l net.Listener, err error)

func (*SSH) ListenTCP

func (this *SSH) ListenTCP(addr string) (l net.Listener, err error)

func (*SSH) Scp

func (this *SSH) Scp(src, des, exclude string) (err error)

实现了文件和目录的上传,未限速

可以实现过滤,不支持正则过滤

文件上传,src和des都可以包含文件名字 如果des是个已存在的目录,则上传到des下 如果des不存在,则文件会重命名为des

目录上传,如果src和des的base一样,则src将上传到des的父目录下面,否则上传到des下

func (*SSH) SetConfig

func (this *SSH) SetConfig(sshConfig SSHConfig)

func (*SSH) Shell

func (this *SSH) Shell() error

一个Session只能执行一次,进入ssh模式

type SSHConfig

type SSHConfig struct {
	Id   string `toml:"id"`
	Addr string `toml:"addr"`
	User string `toml:"user"`
	//证书和密码,可以共存
	Certs     []string      `toml:"certs"`
	Passwords []string      `toml:"passwords"`
	Timeout   time.Duration `toml:"timeout"`
	SkipKeep  bool          `toml:"skipKeep"`
	//以下两个是兼容
	Auth   string `toml:"auth"`
	Phrase string `toml:"phrase"`
}

SSHConfig ..

Jump to

Keyboard shortcuts

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