truenasshell

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package truenasshell bridges honey web terminals to TrueNAS /websocket/shell.

Index

Constants

View Source
const ConsoleTrueNASAPI = "truenas_api"

ConsoleTrueNASAPI selects the TrueNAS middleware web shell instead of SSH.

View Source
const CtrlBracketDetach = byte(0x1d)

CtrlBracketDetach is ASCII GS (Ctrl+]); honey closes the session without forwarding it.

Variables

This section is empty.

Functions

func APIWSURL

func APIWSURL(raw string, insecure bool) (string, error)

APIWSURL normalizes a TrueNAS backend URL to wss://host/api/current.

func BridgeWebSocket

func BridgeWebSocket(_ context.Context, browser *websocket.Conn, sess *Session, rec Recorder)

BridgeWebSocket copies between a browser websocket and an opened TrueNAS shell session.

func PumpStdio

func PumpStdio(parentCtx context.Context, shell *Session, stdin io.Reader, stdout io.Writer, rec Recorder) error

PumpStdio copies stdin to the TrueNAS shell websocket and shell output to stdout until ctx ends, EOF, or error. Terminal resize is handled by the caller via Session.Resize (e.g. SIGWINCH).

func RecordSupportsAPIShell

func RecordSupportsAPIShell(rec hosts.Record) bool

RecordSupportsAPIShell reports whether rec has the metadata shape for TrueNAS /websocket/shell.

func RunRemoteCommand

func RunRemoteCommand(ctx context.Context, b hostexec.TrueNASBackendRuntime, rec hosts.Record, remoteCmd string) (output []byte, exitCode int, err error)

RunRemoteCommand runs one non-interactive shell command over an API shell session.

func ShellWSURL

func ShellWSURL(apiWSURL string) (string, error)

ShellWSURL returns the wss URL for /websocket/shell on the same host as apiWSURL.

func ShouldUseTrueNASShell

func ShouldUseTrueNASShell(rec hosts.Record, console string) bool

ShouldUseTrueNASShell reports whether the web terminal should bridge to TrueNAS /websocket/shell.

func StdinChunkToShell

func StdinChunkToShell(sess *Session, p []byte, rec Recorder) (detached bool, err error)

StdinChunkToShell forwards p to the TrueNAS shell. Ctrl+] detaches without sending the byte.

Types

type Recorder

type Recorder interface {
	RecordData(direction string, payload []byte)
	RecordResize(cols, rows int)
	RecordError(err error)
}

Recorder receives optional TTY telemetry (implemented by *ui.SessionRecorder).

type Session

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

Session bridges a TrueNAS /websocket/shell PTY; resize uses the JSON-RPC API connection.

func OpenSession

func OpenSession(ctx context.Context, b hostexec.TrueNASBackendRuntime, rec hosts.Record, rows, cols int) (*Session, error)

OpenSession authenticates to TrueNAS, opens /websocket/shell for rec, and applies initial resize.

func (*Session) Close

func (s *Session) Close() error

Close closes shell and API connections. Safe to call more than once.

func (*Session) ReadMessage

func (s *Session) ReadMessage() (messageType int, p []byte, err error)

ReadMessage reads the next message from the shell websocket.

func (*Session) Resize

func (s *Session) Resize(cols, rows int) error

Resize calls core.resize_shell on the API websocket.

func (*Session) SetReadDeadline

func (s *Session) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline on the shell websocket.

func (*Session) WriteBinary

func (s *Session) WriteBinary(p []byte) error

WriteBinary sends stdin bytes to the TrueNAS shell websocket.

Jump to

Keyboard shortcuts

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