shell

package
v0.0.0-...-37d5b15 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 12 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
	BS  = 0x8
	LF  = 0xa
	CR  = 0xd
	ESC = 0x1b
	CSI = '['
	DEL = 0x7f
)

Variables

This section is empty.

Functions

This section is empty.

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
	HostKeyFile string `mapstructure:"host-key-file"`
	Users       map[string]User
	Bind        string
}

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(line 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 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) InstanceName

func (s *Shell) InstanceName() string

func (*Shell) OutputLine

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

func (*Shell) RW

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

func (*Shell) Read

func (s *Shell) Read() (string, 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.

func (*Shell) Refresh

func (s *Shell) Refresh() error

func (*Shell) SetPrompt

func (s *Shell) SetPrompt(prompt string)

type SshServer

type SshServer struct {
	*Config
	HandlerFactory
}

SshServer manages acceptance of and authenticating SSH connections and delegating input to a Handler for each session instantiated by the given HandlerFactory. The zero value of this struct will use reasonable defaults, but won't be very useful since the default handler just outputs remote inputs to logs.

func (*SshServer) ListenAndServe

func (s *SshServer) ListenAndServe() error

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

type User

type User struct {
	Password string
}

Jump to

Keyboard shortcuts

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