session

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package session provides session lifecycle management for ShellGate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager tracks active sessions with lifecycle controls.

func NewManager

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a new session manager.

func (*Manager) Close

func (m *Manager) Close()

Close shuts down the manager and all active sessions.

func (*Manager) Count

func (m *Manager) Count() int

Count returns the number of active sessions.

func (*Manager) Create

func (m *Manager) Create(id, clientIP, userAgent string, ptySess *pty.Session, rec *Recorder) (*Session, error)

Create registers a new session. Returns an error if max sessions exceeded.

func (*Manager) Get

func (m *Manager) Get(id string) (*Session, bool)

Get retrieves a session by ID.

func (*Manager) List

func (m *Manager) List() []SessionInfo

List returns info about all active sessions.

func (*Manager) Remove

func (m *Manager) Remove(id string)

Remove removes and cleans up a session.

type ManagerConfig

type ManagerConfig struct {
	MaxSessions int
	Timeout     time.Duration
	IdleTimeout time.Duration
}

ManagerConfig holds configuration for the session manager.

type Recorder

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

Recorder records terminal I/O in asciicast v2 format.

func NewRecorder

func NewRecorder(cfg RecorderConfig) (*Recorder, error)

NewRecorder creates a new session recorder that writes asciicast v2 files.

func (*Recorder) Close

func (r *Recorder) Close() error

Close flushes and closes the recorder.

func (*Recorder) FilePath

func (r *Recorder) FilePath() string

FilePath returns the path to the recording file.

func (*Recorder) Flush

func (r *Recorder) Flush() error

Flush writes any buffered data to disk.

func (*Recorder) WriteInput

func (r *Recorder) WriteInput(data []byte) error

WriteInput records terminal input data.

func (*Recorder) WriteOutput

func (r *Recorder) WriteOutput(data []byte) error

WriteOutput records terminal output data.

func (*Recorder) WriteResize

func (r *Recorder) WriteResize(cols, rows int) error

WriteResize records a terminal resize event.

type RecorderConfig

type RecorderConfig struct {
	Dir       string
	SessionID string
	Width     int
	Height    int
	Shell     string
	Title     string
}

RecorderConfig holds configuration for session recording.

type Session

type Session struct {
	ID        string
	StartedAt time.Time
	ClientIP  string
	UserAgent string
	PTY       *pty.Session
	Recorder  *Recorder
	LastInput time.Time
	// contains filtered or unexported fields
}

Session represents an active terminal session.

func (*Session) UpdateLastInput

func (s *Session) UpdateLastInput()

UpdateLastInput records the timestamp of the last input.

type SessionInfo

type SessionInfo struct {
	ID        string    `json:"id"`
	StartedAt time.Time `json:"started_at"`
	ClientIP  string    `json:"client_ip"`
	UserAgent string    `json:"user_agent"`
	Duration  string    `json:"duration"`
}

SessionInfo is a serializable snapshot of session metadata.

type ShareLink struct {
	Token      string
	SessionID  string
	CreatedAt  time.Time
	ExpiresAt  time.Time
	MaxViewers int
	Viewers    int
	// contains filtered or unexported fields
}

ShareLink represents a shareable read-only terminal link.

func (*ShareLink) AddViewer

func (sl *ShareLink) AddViewer() bool

AddViewer increments the viewer count. Returns false if max viewers reached.

func (*ShareLink) Broadcast

func (sl *ShareLink) Broadcast(data []byte)

Broadcast sends output data to all viewers.

func (*ShareLink) Close

func (sl *ShareLink) Close()

Close closes the share link broadcast channel.

func (*ShareLink) Output

func (sl *ShareLink) Output() <-chan []byte

Output returns the channel for receiving broadcast output.

func (*ShareLink) RemoveViewer

func (sl *ShareLink) RemoveViewer()

RemoveViewer decrements the viewer count.

func (*ShareLink) ViewerCount

func (sl *ShareLink) ViewerCount() int

ViewerCount returns the current viewer count.

type ShareManager

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

ShareManager manages shareable read-only session links.

func NewShareManager

func NewShareManager() *ShareManager

NewShareManager creates a new share link manager.

func (*ShareManager) BroadcastToSession

func (sm *ShareManager) BroadcastToSession(sessionID string, data []byte)

BroadcastToSession sends output data to all share links associated with a session.

func (*ShareManager) Close

func (sm *ShareManager) Close()

Close shuts down the share manager.

func (*ShareManager) Create

func (sm *ShareManager) Create(sessionID string, ttl time.Duration, maxViewers int) (*ShareLink, error)

Create generates a new share link for a session.

func (*ShareManager) Get

func (sm *ShareManager) Get(token string) (*ShareLink, bool)

Get retrieves a share link by token.

func (*ShareManager) Remove

func (sm *ShareManager) Remove(token string)

Remove deletes a share link.

Jump to

Keyboard shortcuts

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