Documentation ¶
Overview ¶
Package utils implements utilities used across different areas of the sish application. There are utility functions that help with overall state management and are core to the application.
Index ¶
- Variables
- func CheckPort(port uint32, portRanges string) (uint32, error)
- func CommaSplitFields(c rune) bool
- func CopyBoth(writer net.Conn, reader io.ReadWriteCloser)
- func GetRandomPortInRange(portRange string) uint32
- func GetSSHConfig() *ssh.ServerConfig
- func LoadProxyProtoConfig(l *proxyproto.Listener)
- func RandStringBytesMaskImprSrc(n int) string
- func Setup(logWriter io.Writer)
- func WatchCerts()
- type AliasHolder
- type HTTPHolder
- type IdleTimeoutConn
- type ListenerHolder
- type ListenerType
- type LogWriter
- type SSHConnection
- type State
- type TCPHolder
- type WebClient
- type WebConsole
- func (c *WebConsole) AddClient(route string, w *WebClient)
- func (c *WebConsole) AddRoute(route string, token string)
- func (c *WebConsole) BroadcastRoute(route string, message []byte)
- func (c *WebConsole) HandleClients(hostname string, g *gin.Context)
- func (c *WebConsole) HandleDisconnectClient(hostname string, g *gin.Context)
- func (c *WebConsole) HandleDisconnectRoute(hostname string, g *gin.Context)
- func (c *WebConsole) HandleRequest(hostname string, hostIsRoot bool, g *gin.Context)
- func (c *WebConsole) HandleTemplate(hostname string, hostIsRoot bool, userIsAdmin bool, g *gin.Context)
- func (c *WebConsole) HandleWebSocket(hostname string, g *gin.Context)
- func (c *WebConsole) RemoveClient(route string, w *WebClient)
- func (c *WebConsole) RemoveRoute(route string)
- func (c *WebConsole) RouteExists(route string) bool
- func (c *WebConsole) RouteToken(route string) (string, bool)
Constants ¶
This section is empty.
Variables ¶
var ( // Filter is the IPFilter used to block connections. Filter *ipfilter.IPFilter )
Functions ¶
func CheckPort ¶
CheckPort verifies if a port exists within the port range. It will return 0 and an error if not (0 allows the kernel to select) the port.
func CommaSplitFields ¶
CommaSplitFields is a function used by strings.FieldsFunc to split around commas.
func CopyBoth ¶
func CopyBoth(writer net.Conn, reader io.ReadWriteCloser)
CopyBoth copies betwen a reader and writer and will cleanup each.
func GetRandomPortInRange ¶
GetRandomPortInRange returns a random port in the provided range. The port range is a comma separated list of ranges or ports.
func GetSSHConfig ¶
func GetSSHConfig() *ssh.ServerConfig
GetSSHConfig Returns an SSH config for the ssh muxer. It handles auth and storing user connection information.
func LoadProxyProtoConfig ¶ added in v1.0.10
func LoadProxyProtoConfig(l *proxyproto.Listener)
LoadProxyProtoConfig will load the timeouts and policies for the proxy protocol.
func RandStringBytesMaskImprSrc ¶
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
Types ¶
type AliasHolder ¶
type AliasHolder struct { AliasHost string SSHConnections *sync.Map Balancer *roundrobin.RoundRobin }
AliasHolder holds alias and connection info. SSHConnections is a map[string]*SSHConnection.
func GetOpenAlias ¶
func GetOpenAlias(addr string, port string, state *State, sshConn *SSHConnection) (string, *AliasHolder)
GetOpenAlias returns open aliases or a random one if it is not enabled. If load balancing is enabled, it will return the requested alias.
type HTTPHolder ¶
type HTTPHolder struct { HTTPHost string Scheme string SSHConnections *sync.Map Forward *forward.Forwarder Balancer *roundrobin.RoundRobin }
HTTPHolder holds proxy and connection info. SSHConnections is a map[string]*SSHConnection.
func GetOpenHost ¶
func GetOpenHost(addr string, state *State, sshConn *SSHConnection) (string, *HTTPHolder)
GetOpenHost returns an open host or a random host if that one is unavailable. If load balancing is enabled, it will return the requested domain.
type IdleTimeoutConn ¶
IdleTimeoutConn handles the connection with a context deadline. code adapted from https://qiita.com/kwi/items/b38d6273624ad3f6ae79
type ListenerHolder ¶
type ListenerHolder struct { net.Listener ListenAddr string Type ListenerType SSHConn *SSHConnection }
ListenerHolder represents a generic listener.
type ListenerType ¶
type ListenerType int
ListenerType represents any listener sish supports.
const ( // AliasListener represents a tcp alias. AliasListener ListenerType = iota // HTTPListener represents a HTTP proxy. HTTPListener // TCPListener represents a generic tcp listener. TCPListener // ProcessListener represents a process specific listener. ProcessListener )
type SSHConnection ¶
type SSHConnection struct { SSHConn *ssh.ServerConn Listeners *sync.Map Closed *sync.Once Close chan bool Messages chan string ProxyProto byte Session chan bool CleanupHandler bool SetupLock *sync.Mutex }
SSHConnection handles state for a SSHConnection. It wraps an ssh.ServerConn and allows us to pass other state around the application. Listeners is a map[string]net.Listener.
func (*SSHConnection) CleanUp ¶
func (s *SSHConnection) CleanUp(state *State)
CleanUp closes all allocated resources for a SSH session and cleans them up.
func (*SSHConnection) SendMessage ¶
func (s *SSHConnection) SendMessage(message string, block bool)
SendMessage sends a console message to the connection. If block is true, it will block until the message is sent. If it is false, it will try to send the message 5 times, waiting 100ms each time.
type State ¶
type State struct { Console *WebConsole SSHConnections *sync.Map Listeners *sync.Map HTTPListeners *sync.Map AliasListeners *sync.Map TCPListeners *sync.Map IPFilter *ipfilter.IPFilter LogWriter io.Writer }
State handles overall state. It retains mutexed maps for various datastructures and shared objects. SSHConnections is a map[string]*SSHConnection. Listeners is a map[string]net.Listener. HTTPListeners is a map[string]HTTPHolder. AliasListeners is a map[string]AliasHolder. TCPListeners is a map[string]TCPHolder.
type TCPHolder ¶
type TCPHolder struct { TCPHost string Listener net.Listener SSHConnections *sync.Map Balancer *roundrobin.RoundRobin }
TCPHolder holds proxy and connection info. SSHConnections is a map[string]*SSHConnection.
func GetOpenPort ¶
func GetOpenPort(addr string, port uint32, state *State, sshConn *SSHConnection) (string, uint32, *TCPHolder)
GetOpenPort returns open ports that can be bound. It verifies the host to bind the port to and attempts to listen to the port to ensure it is open. If load balancing is enabled, it will return the port if used.
type WebClient ¶
type WebClient struct { Conn *websocket.Conn Console *WebConsole Send chan []byte Route string }
WebClient represents a primitive web console client. It maintains references that allow us to communicate and track a client connection.
type WebConsole ¶
WebConsole represents the data structure that stores web console client information. Clients is a map[string][]*WebClient. RouteTokens is a map[string]string.
func (*WebConsole) AddClient ¶
func (c *WebConsole) AddClient(route string, w *WebClient)
AddClient adds a client to the console route.
func (*WebConsole) AddRoute ¶
func (c *WebConsole) AddRoute(route string, token string)
AddRoute adds a route token 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) HandleClients ¶
func (c *WebConsole) HandleClients(hostname string, g *gin.Context)
HandleClients handles returning all connected SSH clients. This will also go through all of the forwarded connections for the SSH client and return them.
func (*WebConsole) HandleDisconnectClient ¶
func (c *WebConsole) HandleDisconnectClient(hostname string, g *gin.Context)
HandleDisconnectClient handles the disconnection request for a SSH client.
func (*WebConsole) HandleDisconnectRoute ¶
func (c *WebConsole) HandleDisconnectRoute(hostname string, g *gin.Context)
HandleDisconnectRoute handles the disconnection request for a forwarded route.
func (*WebConsole) HandleRequest ¶
func (c *WebConsole) HandleRequest(hostname string, hostIsRoot bool, g *gin.Context)
HandleRequest handles an incoming web request, handles auth, and then routes it.
func (*WebConsole) HandleTemplate ¶
func (c *WebConsole) HandleTemplate(hostname string, hostIsRoot bool, userIsAdmin bool, g *gin.Context)
HandleTemplate handles rendering the console templates.
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 route.
func (*WebConsole) RemoveRoute ¶
func (c *WebConsole) RemoveRoute(route string)
RemoveRoute removes a route token from the console.
func (*WebConsole) RouteExists ¶
func (c *WebConsole) RouteExists(route string) bool
RouteExists check if a route token exists.
func (*WebConsole) RouteToken ¶
func (c *WebConsole) RouteToken(route string) (string, bool)
RouteToken returns the route token for a specific route.