utils

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2020 License: MIT Imports: 25 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Filter is the IPFilter used to block connections
	Filter *ipfilter.IPFilter
)

Functions

func CheckPort

func CheckPort(port uint32, portRanges string) (uint32, error)

CheckPort verifies if a port exists within the port range

func CommaSplitFields

func CommaSplitFields(c rune) bool

CommaSplitFields is a function used by strings.FieldsFunc to split around commas

func GetOpenAlias

func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection) string

GetOpenAlias returns open aliases

func GetOpenHost

func GetOpenHost(addr string, state *State, sshConn *SSHConnection) string

GetOpenHost returns a random open host

func GetRandomPortInRange

func GetRandomPortInRange(portRange string) uint32

GetRandomPortInRange returns a random port in the provided range

func GetSSHConfig

func GetSSHConfig() *ssh.ServerConfig

GetSSHConfig Returns an SSH config for the ssh muxer

func RandStringBytesMaskImprSrc

func RandStringBytesMaskImprSrc(n int) string

RandStringBytesMaskImprSrc creates a random string of length n https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang

func Setup

func Setup()

Setup main utils

func WatchCerts

func WatchCerts()

WatchCerts watches ssh keys for changes

Types

type ProxyHolder

type ProxyHolder struct {
	ProxyHost string
	ProxyTo   string
	Scheme    string
	SSHConn   *SSHConnection
}

ProxyHolder holds proxy and connection info

type SSHConnection

type SSHConnection struct {
	SSHConn        *ssh.ServerConn
	Listeners      *sync.Map
	Close          chan bool
	Messages       chan string
	ProxyProto     byte
	Session        chan bool
	CleanupHandler bool
}

SSHConnection handles state for a SSHConnection

func (*SSHConnection) CleanUp

func (s *SSHConnection) CleanUp(state *State)

CleanUp closes all allocated resources and cleans them up

func (*SSHConnection) SendMessage

func (s *SSHConnection) SendMessage(message string, block bool)

SendMessage sends a console message to the connection

type State

type State struct {
	Console        *WebConsole
	SSHConnections *sync.Map
	Listeners      *sync.Map
	HTTPListeners  *sync.Map
	TCPListeners   *sync.Map
	IPFilter       *ipfilter.IPFilter
}

State handles overall state

func NewState

func NewState() *State

NewState returns a new state struct

type WebClient

type WebClient struct {
	Conn    *websocket.Conn
	Console *WebConsole
	Send    chan []byte
	Route   string
}

WebClient represents a primitive web console client

func (*WebClient) Handle

func (c *WebClient) Handle()

Handle is the only place socket reads and writes happen

type WebConsole

type WebConsole struct {
	Clients     *sync.Map
	RouteTokens *sync.Map
	State       *State
}

WebConsole represents the data structure that stores web console client information Clients is a map[string][]*WebClient

func NewWebConsole

func NewWebConsole() *WebConsole

NewWebConsole set's up the WebConsole

func (*WebConsole) AddClient

func (c *WebConsole) AddClient(route string, w *WebClient)

AddClient adds a client to the console

func (*WebConsole) AddRoute

func (c *WebConsole) AddRoute(route string, token string)

AddRoute adds a route to the console

func (*WebConsole) BroadcastRoute

func (c *WebConsole) BroadcastRoute(route string, message []byte)

BroadcastRoute sends a message to all clients on a route

func (*WebConsole) HandleAllRoutes

func (c *WebConsole) HandleAllRoutes(hostname string, g *gin.Context)

HandleAllRoutes handles returning all connected routes (tunnels)

func (*WebConsole) HandleClients

func (c *WebConsole) HandleClients(hostname string, g *gin.Context)

HandleClients handles returning all connected clients

func (*WebConsole) HandleDisconnectClient

func (c *WebConsole) HandleDisconnectClient(hostname string, g *gin.Context)

HandleDisconnectClient handles the disconnection request for a client

func (*WebConsole) HandleDisconnectRoute

func (c *WebConsole) HandleDisconnectRoute(hostname string, g *gin.Context)

HandleDisconnectRoute handles the disconnection request for a route

func (*WebConsole) HandleRequest

func (c *WebConsole) HandleRequest(hostname string, hostIsRoot bool, g *gin.Context)

HandleRequest handles an incoming WS request

func (*WebConsole) HandleRoutes

func (c *WebConsole) HandleRoutes(hostname string, g *gin.Context)

HandleRoutes handles returning available http routes to join

func (*WebConsole) HandleTemplate

func (c *WebConsole) HandleTemplate(hostname string, hostIsRoot bool, userIsAdmin bool, g *gin.Context)

HandleTemplate handles rendering the console template

func (*WebConsole) HandleWebSocket

func (c *WebConsole) HandleWebSocket(hostname string, g *gin.Context)

HandleWebSocket handles the websocket route

func (*WebConsole) RemoveClient

func (c *WebConsole) RemoveClient(route string, w *WebClient)

RemoveClient removes a client from the console

func (*WebConsole) RemoveRoute

func (c *WebConsole) RemoveRoute(route string)

RemoveRoute adds a route to the console

func (*WebConsole) RouteExists

func (c *WebConsole) RouteExists(route string) bool

RouteExists check if a route exists

Jump to

Keyboard shortcuts

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