sshshell

package
v0.0.0-...-8fa78e2 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfigHistorySize = 100
	DefaultBind              = ":22"
)
View Source
const (
	ETX = 0x3  // control-C
	EOT = 0x4  // control-D
	BEL = 0x7  // beep
	BS  = 0x8  // Backspace
	TAB = 0x9  // TAB
	LF  = 0xa  // linefeed
	FF  = 0xc  // formfeed (go to top of next page)
	CR  = 0xd  // carriage return
	ESC = 0x1b // Escape
	CSI = '['  // CSI escape code following
	DEL = 0x7f // Delete
	CUU = 'A'  // Cursor Up
	CUD = 'B'  // Cursor Down
	CUF = 'C'  // Cursor Forward
	CUB = 'B'  // Cursor Back
)

Variables

This section is empty.

Functions

func StartSSHShell

func StartSSHShell(ctx context.Context, createRoot func() *cobra.Command, config *Config)

Start a SSH server with given context and DPDK Infra API

Types

type Auth

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

func NewAuth

func NewAuth(config *Config) *Auth

func (*Auth) PasswordHandler

func (a *Auth) PasswordHandler(ctx ssh.Context, password string) bool

type Config

type Config struct {
	HistorySize int             `json:"historysize"`
	HostKeyFile string          `json:"hostkeyfile" mapstructure:"host-key-file"`
	Users       map[string]User `json:"users"`
	Bind        string          `json:"bind"`
}

type Handler

type Handler interface {
	// HandleLine is called with the next line that was consumed by the SSH shell. Typically this is due the user typing
	// a command string. If an error is returned, then the error is reported back to the SSH client and the SSH session
	// is closed.
	HandleLine(ctx context.Context, line string) error

	// handle completion requests
	HandleCompletion(ctx context.Context, line string) (string, error)

	// HandleEOF is called when the user types Control-D. If an error is returned, then the error is reported back to the
	// SSH client and the SSH session is closed.
	HandleEOF() error
}

type HandlerFactory

type HandlerFactory func(s *Shell) Handler

type HostKeyResolver

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

func NewHostKeyResolver

func NewHostKeyResolver(config *Config) *HostKeyResolver

func (*HostKeyResolver) Resolve

func (r *HostKeyResolver) Resolve() string

func (*HostKeyResolver) ResolveOption

func (r *HostKeyResolver) ResolveOption() ssh.Option

type SSHServer

type SSHServer struct {
	*Config
	HandlerFactory
	// contains filtered or unexported fields
}

SshServer manages acceptance of and authenticating SSH connections and delegating input to a Handler for each session instantiated by the given HandlerFactory.

func (*SSHServer) Listen

func (s *SSHServer) Listen(ctx context.Context) error

Listen will block listening for new SSH connections and serving those with a new instance of Shell/Handler.

func (*SSHServer) Quit

func (s *SSHServer) Quit()

Stop the SSH server and any open session!

type Shell

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

func NewShell

func NewShell(rw io.ReadWriter, instanceName string, config *Config) *Shell

func (*Shell) Add

func (s *Shell) Add(b byte) error

func (*Shell) AddString

func (s *Shell) AddString(val string) error

func (*Shell) Bell

func (s *Shell) Bell() error

func (*Shell) GetReadWrite

func (s *Shell) GetReadWrite() io.ReadWriter

func (*Shell) InstanceName

func (s *Shell) InstanceName() string

func (*Shell) Output

func (s *Shell) Output(line string) error

write string to output without adding \r\n

func (*Shell) OutputLine

func (s *Shell) OutputLine(line string) error

write string to output with adding \r\n

func (*Shell) Read

func (s *Shell) Read(line string) (string, bool, error)

Read blocks until the next line of input, such as a command, is available and returns that line. The error will be io.EOF if Control-D was pressed. If a line is given that will be the starting point for adding new input, this is for example used for tab completion return. If returned boolean is true, tab completion is requested on given line.

func (*Shell) Refresh

func (s *Shell) Refresh() error

func (*Shell) SetPrompt

func (s *Shell) SetPrompt(prompt string)

type User

type User struct {
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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