gswitch

package
v1.2.25 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TelnetIAC  = 255 // Interpret As Command
	TelnetDONT = 254 // Don't
	TelnetDO   = 253 // Do
	TelnetWONT = 252 // Won't
	TelnetWILL = 251 // Will
	TelnetSB   = 250 // Subnegotiation Begin
	TelnetSE   = 240 // Subnegotiation End

	// Telnet options
	TelnetEcho              = 1  // Echo
	TelnetSuppressGoAhead   = 3  // Suppress Go Ahead
	TelnetStatus            = 5  // Status
	TelnetTimingMark        = 6  // Timing Mark
	TelnetTerminalType      = 24 // Terminal Type
	TelnetWindowSize        = 31 // Window Size
	TelnetTerminalSpeed     = 32 // Terminal Speed
	TelnetRemoteFlowControl = 33 // Remote Flow Control
	TelnetLinemode          = 34 // Linemode
	TelnetEnvironment       = 36 // Environment
)

Telnet commands and options

Variables

This section is empty.

Functions

func LoadAuthorizedKeysFromFile

func LoadAuthorizedKeysFromFile(path string) ([]ssh.PublicKey, error)

LoadAuthorizedKeysFromFile parses an OpenSSH authorized_keys file.

func ParseAuthorizedKeys

func ParseAuthorizedKeys(data []byte, pathHint string) ([]ssh.PublicKey, error)

ParseAuthorizedKeys parses authorized_keys file contents (path is only for errors).

func ServeSSH

func ServeSSH(ctx context.Context, ln net.Listener, opts SSHServerOptions) error

ServeSSH accepts SSH connections on ln until ln is closed or ctx is cancelled.

func ServeTelnet

func ServeTelnet(ctx context.Context, ln net.Listener, opts SSHServerOptions) error

ServeTelnet accepts Telnet connections on ln until ln is closed or ctx is cancelled.

Types

type CLIMode

type CLIMode int

CLIMode represents CLI operating mode

const (
	ModeLogin CLIMode = iota
	ModeUser
	ModeEnable
	ModeConfig
)

type CLISession

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

func NewCLISession

func NewCLISession(conn ssh.Channel, username, password string, logger *zap.Logger, vendor vendor) *CLISession

NewCLISession creates new CLI session

func NewCLISessionWithAuth

func NewCLISessionWithAuth(conn ssh.Channel, username, password string, logger *zap.Logger) *CLISession

func (*CLISession) Run

func (s *CLISession) Run(ctx context.Context) error

type CLIState

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

CLIState stores CLI session state

func NewCLIState

func NewCLIState(username, password string) *CLIState

func NewCLIStateWithAuth

func NewCLIStateWithAuth(username, password string) *CLIState

func (*CLIState) NewMode

func (s *CLIState) NewMode(mode CLIMode)

func (*CLIState) NewSubMode

func (s *CLIState) NewSubMode(mode string)

type SSHServerOptions

type SSHServerOptions struct {
	Logger *zap.Logger
	// Username and Password are used for password-based client auth.
	Username string
	Password string
	// ConnectionErrorProb is the probability (0–1) to drop a connection right after accept.
	ConnectionErrorProb float64
	// AuthorizedKeys, when non-empty, enables public-key client auth for Username.
	AuthorizedKeys []ssh.PublicKey
}

SSHServerOptions configures the mock SSH switch listener.

type TelnetConnection

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

TelnetConnection implements ssh.Channel over a Telnet TCP connection.

func (*TelnetConnection) Close

func (t *TelnetConnection) Close() error

func (*TelnetConnection) CloseWrite

func (t *TelnetConnection) CloseWrite() error

func (*TelnetConnection) Read

func (t *TelnetConnection) Read(data []byte) (n int, err error)

func (*TelnetConnection) SendRequest

func (t *TelnetConnection) SendRequest(name string, wantReply bool, payload []byte) (bool, error)

func (*TelnetConnection) Stderr

func (t *TelnetConnection) Stderr() io.ReadWriter

func (*TelnetConnection) Write

func (t *TelnetConnection) Write(data []byte) (n int, err error)

Jump to

Keyboard shortcuts

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