ron

package
v2.0.0-...-da0b90c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PIPE_NEW_READER = iota
	PIPE_NEW_WRITER
	PIPE_CLOSE_READER
	PIPE_CLOSE_WRITER
	PIPE_DATA
)

Pipe modes

View Source
const (
	UFS_OPEN = iota
	UFS_CLOSE
	UFS_DATA
)

UFS modes

View Source
const (
	HEARTBEAT_RATE        = 5
	REAPER_RATE           = 30
	CLIENT_RECONNECT_RATE = 5
	CLIENT_EXPIRED        = 30
	RESPONSE_PATH         = "miniccc_responses"
)
View Source
const (
	BUFFER_SIZE = 32768
)
View Source
const PART_SIZE = 1024 * 100

Variables

This section is empty.

Functions

func SendFile

func SendFile(dir, fpath string, ID int, chunkSize int64, send func(m *Message) error) error

SendFile sends a file in chunks using the send func.

func Trunk

func Trunk(remote io.ReadCloser, uuid string, fn func(*Message) error)

Trunk reads data from remote, constructs a *Message, and sends it using fn. Returns the first error.

Types

type Client

type Client struct {
	UUID     string
	Arch     string
	OS       string
	Version  string
	Hostname string
	IPs      []string
	MACs     []string

	// Processes that are running in the background
	Processes map[int]*Process

	// Tags set via the command socket since the last heartbeat. Also used by
	// the server to determine whether the client matches a given filter.
	Tags map[string]string

	// Responses for commands processed since the last heartbeat
	Responses []*Response

	// LastCommandID is the last command ID that the client processed.
	LastCommandID int
}

func (*Client) Matches

func (c *Client) Matches(f *Filter) bool

Matches tests whether all the filters match the client.

type Command

type Command struct {
	ID int

	// run command in the background and return immediately
	Background bool

	// The command is a slice of strings with the first element being the
	// command, and any other elements as the arguments
	Command []string

	// Files to transfer to the client. Any path given in a file specified
	// here will be rooted at <BASE>/files
	FilesSend []string

	// Files to transfer back to the master
	FilesRecv []string

	// Connectivity test to execute
	ConnTest *ConnTest

	// PID of the process to signal, -1 signals all processes
	PID int

	// KillAll kills all processes by name
	KillAll string

	// Level adjusts the minilog level
	Level *log.Level

	// Filter for clients to process commands. Not all fields in a client
	// must be set (wildcards), but all set fields must match for a command
	// to be processed.
	Filter *Filter

	// clients that have responded to this command
	CheckedIn []string

	// Prefix is an optional field that can be used to track commands. It is
	// not used by the server or client.
	Prefix string

	// Once specifies whether or not this command should only be sent to clients
	// once, or if it should be sent after client reconnections.
	Once bool

	// Sent tracks whether or not this command has been sent already. Only used
	// when Once is enabled.
	Sent bool

	// plumber connections
	Stdin  string
	Stdout string
	Stderr string
}

func (*Command) Copy

func (c *Command) Copy() *Command

Creates a copy of c.

type ConnTest

type ConnTest struct {
	Endpoint string
	Wait     time.Duration
	Packet   []byte
}

type File

type File struct {
	ID   int         // command that requested the file
	Name string      // name of the file
	Perm os.FileMode // permissions

	Data   []byte // data chunk
	Offset int64  // offset for this chunk
	EOF    bool   // final chunk in file
}

File sent from server to client or client to server. The ID and name uniquely identify the transfer. Perm is only used for the first chunk. EOF signals that this is the last data chunk.

func (*File) Recv

func (f *File) Recv(fpath string) error

Recv part of a file, writing it to <fpath>.partial. Once the last piece of the file has been received, renames to remove .partial suffix.

func (*File) Write

func (f *File) Write(fpath string) error

Write file data to fpath at the appropriate permissions and offset. Creates the parent directory if needed.

type Filter

type Filter struct {
	UUID     string
	Hostname string
	Arch     string
	OS       string
	MAC      string
	IP       string
	Tags     map[string]string
}

func (*Filter) String

func (f *Filter) String() string

type Message

type Message struct {
	Type  Type
	UUID  string
	Error string

	// MESSAGE_COMMAND
	Commands map[int]*Command

	// MESSAGE_CLIENT
	Client *Client

	// MESSAGE_FILE
	File *File

	// MESSAGE_TUNNEL and MESSAGE_UFS
	Tunnel []byte

	// MESSAGE_PIPE
	Pipe     string
	PipeMode int
	PipeData string

	// MESSAGE_UFS
	UfsMode int

	// version of message
	// (initially added to help determine if server should send periodic
	// heartbeats to client in support of serial reconnect)
	Version string
}

type Process

type Process struct {
	PID     int
	Command []string
}

type Response

type Response struct {
	// ID counter, must match the corresponding Command
	ID int

	// Output from responding command, if any
	Stdout string
	Stderr string

	// exec'ed command exit code
	ExitCode int
	// should server record exit code
	RecordExitCode bool
}

type Server

type Server struct {
	// UseVMs controls whether ron uses VM callbacks or not (see ron.VM)
	UseVMs bool
	// contains filtered or unexported fields
}

func NewServer

func NewServer(path, subpath string, plumber *miniplumber.Plumber) (*Server, error)

NewServer creates a ron server. Must call Listen* to actually allow ron to start accepting connections from clients.

func (*Server) ClearCommands

func (s *Server) ClearCommands()

ClearCommands deletes all commands and sets the command ID counter back to zero. As with DeleteCommand, any in-flight responses may still be returned.

func (*Server) ClearResponses

func (s *Server) ClearResponses() error

ClearResponses deletes all responses received so far. It may not affect responses that are still in-flight.

func (*Server) Clients

func (s *Server) Clients() int

Clients returns the number of clients connected to the server.

func (*Server) CloseForward

func (s *Server) CloseForward(uuid string, id int) error

func (*Server) CloseUnix

func (s *Server) CloseUnix(path string) error

CloseUnix closes a unix domain socket created via ListenUnix.

func (*Server) DeleteCommand

func (s *Server) DeleteCommand(id int) error

DeleteCommand removes a command from the active command list. Any in-flight messages held by any clients may still return a response to the deleted command.

func (*Server) DeleteCommands

func (s *Server) DeleteCommands(prefix string) error

DeleteCommands removes all commands with the specified prefix.

func (*Server) DeleteResponse

func (s *Server) DeleteResponse(id int) error

DeleteResponse removes all responses for the given ID. Any in-flight responses will not be deleted.

func (*Server) DeleteResponses

func (s *Server) DeleteResponses(prefix string) error

DeleteResponses removes all commands with the specified prefix.

func (*Server) Destroy

func (s *Server) Destroy()

func (*Server) DialSerial

func (s *Server) DialSerial(path, uuid string) error

Dial a client serial port. The server will maintain this connection until a client connects and then disconnects.

func (*Server) DisconnectUFS

func (s *Server) DisconnectUFS(uuid string) error

func (*Server) Forward

func (s *Server) Forward(uuid string, source int, host string, dest int) error

Forward creates a tunnel from host->guest, based on UUID, source, host, and destination port. This is similar to the ssh -L command.

func (*Server) GetClients

func (s *Server) GetClients() map[string]*Client

GetClients returns a list of every active client

func (*Server) GetCommand

func (s *Server) GetCommand(id int) *Command

GetCommand returns copy of a command by ID or nil if it doesn't exist

func (*Server) GetCommands

func (s *Server) GetCommands() map[int]*Command

GetCommands returns a deep copy of the current command list

func (*Server) GetExitCode

func (s *Server) GetExitCode(id int, client string) (int, error)

func (*Server) GetProcesses

func (s *Server) GetProcesses(uuid string) ([]*Process, error)

func (*Server) GetResponse

func (s *Server) GetResponse(id int, raw bool) (string, error)

func (*Server) GetResponses

func (s *Server) GetResponses(raw bool) (string, error)

func (*Server) HasClient

func (s *Server) HasClient(c string) bool

HasClient checks whether a client exists with the given identifier.

func (*Server) ListForwards

func (s *Server) ListForwards(uuid string) (map[int]string, error)

func (*Server) Listen

func (s *Server) Listen(port int) error

Listen starts accepting TCP connections on the specified port, accepting connections in a goroutine. Returns an error if the server is already listening on that port or if there was another error.

func (*Server) ListenUFS

func (s *Server) ListenUFS(uuid string) (int, error)

ListenUFS starts a listener to connect to UFS running on the VM specified by the UUID. Returns the TCP port or an error.

func (*Server) ListenUnix

func (s *Server) ListenUnix(path string) error

ListenUnix creates a unix domain socket at the given path and listens for incoming connections. ListenUnix returns on the successful creation of the socket, and accepts connections in a goroutine. Returns an error if the server is already listening on that path or if there was another error.

func (*Server) NewCommand

func (s *Server) NewCommand(c *Command) int

NewCommand posts a new command to the active command list. The command ID is returned.

func (*Server) NewFilesSendCommand

func (s *Server) NewFilesSendCommand(files []string) (*Command, error)

NewFilesSendCommand creates a command to send to clients to read the listed files, expanding globs.

func (*Server) RegisterVM

func (s *Server) RegisterVM(vm VM)

func (*Server) Reverse

func (s *Server) Reverse(filter *Filter, source int, host string, dest int) error

Reverse creates a reverse tunnel from guest->host. It is possible to have multiple clients create a reverse tunnel simultaneously. filter allows specifying which clients to have create the tunnel.

func (*Server) UnregisterVM

func (s *Server) UnregisterVM(vm VM)

type Type

type Type int
const (
	MESSAGE_COMMAND Type = iota
	MESSAGE_CLIENT
	MESSAGE_TUNNEL
	MESSAGE_FILE
	MESSAGE_PIPE
	MESSAGE_UFS
	MESSAGE_HEARTBEAT
)

Message types to inform the mux on either end how to route the message

func (Type) String

func (t Type) String() string

type VM

type VM interface {
	GetNamespace() string
	GetUUID() string
	SetCCActive(bool)
	GetTags() map[string]string
	SetTag(string, string)
	Info(string) (string, error)
}

Jump to

Keyboard shortcuts

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