sshlib

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Ciphers = []string{
		"aes128-ctr",
		"aes192-ctr",
		"aes256-ctr",
		"aes128-gcm@openssh.com",
		"chacha20-poly1305@openssh.com",
		"arcfour256",
		"arcfour128",
		"arcfour",
		"aes128-cbc",
		"3des-cbc",
		"blowfish-cbc",
		"cast128-cbc",
		"aes192-cbc",
		"aes256-cbc",
	}

	KeyExchanges = []string{
		"diffie-hellman-group-exchange-sha256",
		"diffie-hellman-group18-sha512",
		"diffie-hellman-group16-sha512",
		"diffie-hellman-group14-sha256",
	}

	Outputs = []io.Writer{os.Stdout}
)

Functions

func CoverDefaults

func CoverDefaults(node interface{}, defaults interface{}, override bool)

CoverDefaults assigns default values to zero-valued fields in node if override is set to false. It overrides node values for all non-zero fields in defaults if override is set to true. The two arguments should be of the same type.

func TeeReader

func TeeReader(r io.Reader, wList ...io.Writer) io.Reader

TeeReader returns an io.Reader that writes to wList what it reads from r.

Types

type BufferedReader

type BufferedReader struct {
	*bufio.Reader
}

func NewBufferedReader

func NewBufferedReader(r io.Reader, wList ...io.Writer) *BufferedReader

NewBufferedReader returns a BufferedReader that writes to wList what it reads from r.

func (BufferedReader) ReadUntil

func (br BufferedReader) ReadUntil(pattern string) (result []byte, err error)

ReadUntil reads from r one byte at a time until the bytes read match the given pattern

func (BufferedReader) ReadUntilEOF

func (br BufferedReader) ReadUntilEOF() (result []byte)

ReadUntilEOF reads from r one byte at a time until io.EOF

type Config

type Config struct {
	Settings *Settings `yaml:"settings"`
	Defaults *Node     `yaml:"default"`
	Nodes    []*Node   `yaml:"nodes"`
}

func LoadConfig

func LoadConfig(filenames ...string) (config *Config, err error)

func (*Config) String

func (c *Config) String() string

type Node

type Node struct {
	Name       string `yaml:"name"`
	Alias      string `yaml:"alias"`
	Host       string `yaml:"host"`
	Port       int    `yaml:"port"`
	User       string `yaml:"user"`
	Password   string `yaml:"password"`
	KeyPath    string `yaml:"keypath"`
	Passphrase string `yaml:"passphrase"`
}

func GetNode

func GetNode(config *Config, target string, chosen *Node, defaultsOnly bool, overrider *Node) (node *Node)

Get node from target, or choose from menu, and then override fields with overrider. chosen will be ignored if target is not empty. If defaultsOnly is set to true, empty values will only be covered with defaults, logins section will not be used. Values in overrider have top priority.

func (*Node) AuthMethods

func (n *Node) AuthMethods() (authMethods []ssh.AuthMethod)

func (*Node) SetDefaults

func (n *Node) SetDefaults(defaults *Node, settings *Settings)

SetDefaults sets sensible values for unset fields in node

func (*Node) SetLogin

func (n *Node) SetLogin(logins []*Node, override bool)

SetLogin sets values for unset fields in node if override is set to false. It overrides node values if override is set to true.

func (Node) String

func (n Node) String() string

type SSHClient

type SSHClient struct {
	Host string
	Port int

	*BufferedReader
	*WriteCloser
	// contains filtered or unexported fields
}

func (*SSHClient) CurrentClient

func (c *SSHClient) CurrentClient() *ssh.Client

func (*SSHClient) CurrentSession

func (c *SSHClient) CurrentSession() *ssh.Session

func (*SSHClient) Login

func (c *SSHClient) Login(user, password string) (err error)

Login to remote server with user/password

func (*SSHClient) LoginAuth

func (c *SSHClient) LoginAuth(user string, authMethods []ssh.AuthMethod) (err error)

Login to remote server with multiple auth methods

func (*SSHClient) RequestTerminal

func (c *SSHClient) RequestTerminal() (fd int, state *term.State, err error)

func (*SSHClient) RestoreTerminal

func (c *SSHClient) RestoreTerminal(fd int, state *term.State) error

func (*SSHClient) Run

func (c *SSHClient) Run(cmd string) (output string, err error)

Run cmd and get its output (Does not need terminal)

func (*SSHClient) Shell

func (c *SSHClient) Shell() error

Interactive Shell (Need terminal)

func (*SSHClient) Start

func (c *SSHClient) Start(cmd string) error

Start cmd (Need terminal)

func (*SSHClient) Wait

func (c *SSHClient) Wait() error

type Settings

type Settings struct {
	Domain string  `yaml:"domain"`
	Logins []*Node `yaml:"logins"`
}

type WriteCloser

type WriteCloser struct {
	io.WriteCloser
}

func (*WriteCloser) WriteLine

func (w *WriteCloser) WriteLine(s string) (n int, err error)

func (*WriteCloser) WriteString

func (w *WriteCloser) WriteString(s string) (n int, err error)

Jump to

Keyboard shortcuts

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