shell

package
v0.0.59 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package shell provides an HTTP handler that proxies browser WebSocket connections to a Slicer VM's interactive shell endpoint.

The handler upgrades the incoming HTTP request to a WebSocket, dials the Slicer API's /vm/{hostname}/shell endpoint (over TCP or Unix socket), and bidirectionally relays binary frames using the Slicer shell protocol.

Usage:

h := shell.NewProxyHandler(shell.Options{
    BaseURL:  "/var/run/slicer/api.sock",
    VMName:   "sandbox-1",
})
mux.Handle("/terminal", myAuth(h))

Index

Constants

View Source
const (
	FrameTypeData         = 0x01
	FrameTypeWindowSize   = 0x02
	FrameTypeShutdown     = 0x03
	FrameTypeHeartbeat    = 0x04
	FrameTypeSessionClose = 0x05
)

Frame type constants for the Slicer shell binary protocol. Each frame has a 5-byte header: 1 byte frame type + 4 bytes big-endian payload length.

Variables

This section is empty.

Functions

func NewProxyHandler

func NewProxyHandler(opts Options) http.Handler

NewProxyHandler returns an http.Handler that upgrades browser connections to WebSocket and proxies them to the Slicer VM shell endpoint.

Types

type Options

type Options struct {
	// BaseURL is the Slicer API URL: `http(s)://host[:port]` or an absolute
	// Unix socket path (`/path/to/slicer.sock` or `unix:///path`).
	BaseURL string

	// Token is the bearer token for the Slicer API. Optional for unix sockets
	// with no auth configured.
	Token string

	// VMName is the static hostname of the VM to shell into.
	// Ignored when VMNameFunc is set.
	VMName string

	// VMNameFunc dynamically resolves the VM hostname from the incoming
	// request. Takes precedence over VMName.
	VMNameFunc func(r *http.Request) string

	// Shell overrides the shell binary inside the guest (e.g. "/bin/bash").
	Shell string

	// UID sets the user ID for the shell session. 0 uses the guest default.
	UID int

	// GID sets the group ID for the shell session. 0 uses the guest default.
	GID int

	// Cwd sets the working directory for the shell session.
	Cwd string

	// CheckOrigin validates the Origin header on the incoming WebSocket
	// upgrade. If nil, same-origin policy is enforced.
	CheckOrigin func(r *http.Request) bool

	// Logger receives short progress strings. If nil, events are discarded.
	Logger *log.Logger
}

Options configures a shell proxy handler.

Jump to

Keyboard shortcuts

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