Documentation ¶
Index ¶
- Constants
- Variables
- func DownloadFile(filename string)
- func GetFileSha1(filename string) (string, error)
- func GetGateWayIP() ([]string, error)
- func GetMachineID() (string, error)
- func GetPlatformString() string
- func GetProcessWorkingDirectory(pid int) (string, error)
- func GetenvInt(key string, defaultValue int) int
- func ModeStr(mode int) string
- func StartGhost(args []string, mid string, noLanDisc bool, noRPCServer bool, ...)
- func StartOverlord(bindAddr string, port int, lanDiscInterface string, lanDisc bool, auth bool, ...)
- func ToVTNewLine(text string) string
- func Ttyname(fd uintptr) (string, error)
- type BasicAuth
- func (auth *BasicAuth) Authenticate(user, passwd string) (bool, error)
- func (auth *BasicAuth) IsBlocked(r *http.Request) bool
- func (auth *BasicAuth) ResetFailCount(r *http.Request)
- func (auth *BasicAuth) Unauthorized(w http.ResponseWriter, r *http.Request, msg string, record bool)
- func (auth *BasicAuth) WrapHandler(h http.Handler) http.Handler
- func (auth *BasicAuth) WrapHandlerFunc(h http.HandlerFunc) http.Handler
- type ConnServer
- func (c *ConnServer) Listen()
- func (c *ConnServer) SendClearToDownload()
- func (c *ConnServer) SendUpgradeRequest() error
- func (c *ConnServer) SpawnFileServer(sid, terminalSid, action, filename, dest string, perm int, checkOnly bool)
- func (c *ConnServer) SpawnModeForwarder(sid string, port int)
- func (c *ConnServer) SpawnShell(sid string, command string)
- func (c *ConnServer) SpawnTerminal(sid, ttyDevice string)
- func (c *ConnServer) StopListen()
- func (c *ConnServer) Terminate()
- type ConnectLogcatCmd
- type EmptyArgs
- type EmptyReply
- type Ghost
- func (ghost *Ghost) AddToDownloadQueue(ttyName, filename string)
- func (ghost *Ghost) InitiateDownload(info downloadInfo)
- func (ghost *Ghost) InitiatefileOperation(res *Response) error
- func (ghost *Ghost) Listen() error
- func (ghost *Ghost) Ping() error
- func (ghost *Ghost) Register() error
- func (ghost *Ghost) RegisterSession(sesssionID, pidStr string)
- func (ghost *Ghost) RegisterTTY(sesssionID, ttyName string)
- func (ghost *Ghost) Reset()
- func (ghost *Ghost) ScanGateway()
- func (ghost *Ghost) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (ghost *Ghost) SetFileOp(operation, filename string, perm int) *Ghost
- func (ghost *Ghost) SetModeForwardPort(port int) *Ghost
- func (ghost *Ghost) SetPropFile(propFile string) *Ghost
- func (ghost *Ghost) SetShellCommand(command string) *Ghost
- func (ghost *Ghost) SetSid(sid string) *Ghost
- func (ghost *Ghost) SetTLSMode(mode int) *Ghost
- func (ghost *Ghost) SetTerminalSid(sid string) *Ghost
- func (ghost *Ghost) SetTtyDevice(ttyDevice string) *Ghost
- func (ghost *Ghost) SpawnPortModeForwardServer(res *Response) error
- func (ghost *Ghost) SpawnShellServer(res *Response) error
- func (ghost *Ghost) SpawnTTYServer(res *Response) error
- func (ghost *Ghost) Start(lanDisc bool, RPCServer bool)
- func (ghost *Ghost) StartDownloadServer() error
- func (ghost *Ghost) StartLanDiscovery()
- func (ghost *Ghost) StartRPCServer()
- func (ghost *Ghost) StartUploadServer() error
- func (ghost *Ghost) Upgrade() error
- type Message
- type Overlord
- func (ovl *Overlord) AddWebsocketContext(wc *webSocketContext)
- func (ovl *Overlord) GetAppDir() string
- func (ovl *Overlord) GetAppNames(ignoreSpecial bool) ([]string, error)
- func (ovl *Overlord) InitSocketIOServer()
- func (ovl *Overlord) Register(conn *ConnServer) (*websocket.Conn, error)
- func (ovl *Overlord) RegisterDownloadRequest(conn *ConnServer)
- func (ovl *Overlord) RegisterHTTPHandlers()
- func (ovl *Overlord) RegisterUploadRequest(conn *ConnServer)
- func (ovl *Overlord) Serv()
- func (ovl *Overlord) ServHTTP()
- func (ovl *Overlord) StartUDPBroadcast(port int)
- func (ovl *Overlord) Unregister(conn *ConnServer)
- type PollableProcess
- type RPCCore
- func (rpc *RPCCore) ClearRequests()
- func (rpc *RPCCore) ParseMessage(msgJSON string) (Message, error)
- func (rpc *RPCCore) ParseRequests(buffer string, single bool) []*Request
- func (rpc *RPCCore) ScanForTimeoutRequests() error
- func (rpc *RPCCore) SendMessage(msg Message) error
- func (rpc *RPCCore) SendRequest(req *Request, handler ResponseHandler) error
- func (rpc *RPCCore) SendResponse(res *Response) error
- func (rpc *RPCCore) SpawnReaderRoutine() (chan []byte, chan error)
- func (rpc *RPCCore) StopConn()
- type RegistrationFailedError
- type Request
- type Responder
- type Response
- type ResponseHandler
- type SpawnFileCmd
- type SpawnModeForwarderCmd
- type SpawnShellCmd
- type SpawnTerminalCmd
- type TLSCerts
- type TerminalControl
Constants ¶
const ( ModeNone = iota ModeControl ModeTerminal ModeShell ModeLogcat ModeFile ModeForward )
ConnServer Client mode
const ( Success = "success" Failed = "failed" )
RPC states
const ( TLSDetect = iota TLSForceDisable TLSForceEnable )
TLS modes
const (
RandomMID = "##random_mid##" // Random Machine ID identifier
)
Exported
const (
StdinClosed = "##STDIN_CLOSED##"
)
Stream control
Variables ¶
var ( OverlordLDPort = GetenvInt("OVERLORD_LD_PORT", 4456) // LAN discovery port DefaultHTTPPort = 80 DefaultHTTPSPort = 443 )
Overlord server ports.
Functions ¶
func DownloadFile ¶
func DownloadFile(filename string)
DownloadFile adds a file to the download queue, which would be pickup by the ghost control channel instance and perform download.
func GetFileSha1 ¶
GetFileSha1 return the sha1sum of a file.
func GetGateWayIP ¶
GetGateWayIP return the IPs of the gateways.
func GetMachineID ¶
GetMachineID generates machine-dependent ID string for a machine. There are many ways to generate a machine ID: 1. /sys/class/dmi/id/product_uuid (only available on intel machines) 2. MAC address We follow the listed order to generate machine ID, and fallback to the next alternative if the previous doesn't work.
func GetPlatformString ¶
func GetPlatformString() string
GetPlatformString returns machine platform string. Platform stream has the format of GOOS.GOARCH
func GetProcessWorkingDirectory ¶
GetProcessWorkingDirectory returns the current working directory of a process.
func GetenvInt ¶
GetenvInt parse an integer from environment variable, and return default value when error.
func StartGhost ¶
func StartGhost(args []string, mid string, noLanDisc bool, noRPCServer bool, tlsCertFile string, verify bool, propFile string, download string, reset bool, status bool, tlsMode int)
StartGhost starts the Ghost client.
func StartOverlord ¶
func StartOverlord(bindAddr string, port int, lanDiscInterface string, lanDisc bool, auth bool, certsString string, linkTLS bool, htpasswdPath string)
StartOverlord starts the overlord server.
func ToVTNewLine ¶
ToVTNewLine replace the newline character to VT100 newline control.
Types ¶
type BasicAuth ¶
type BasicAuth struct { Realm string Disable bool // Disable basic auth function, pass through // contains filtered or unexported fields }
BasicAuth is a class that provide WrapHandler and WrapHandlerFunc, which turns a http.Handler to a HTTP basic-auth enabled http handler.
func NewBasicAuth ¶
NewBasicAuth creates a BasicAuth object
func (*BasicAuth) Authenticate ¶
Authenticate authenticate an user with the provided user and passwd.
func (*BasicAuth) ResetFailCount ¶
ResetFailCount resets the fail count for the given IP.
func (*BasicAuth) Unauthorized ¶
func (auth *BasicAuth) Unauthorized(w http.ResponseWriter, r *http.Request, msg string, record bool)
Unauthorized returns a 401 Unauthorized response.
func (*BasicAuth) WrapHandler ¶
WrapHandler wraps an http.Hanlder and provide HTTP basic-auth.
func (*BasicAuth) WrapHandlerFunc ¶
func (auth *BasicAuth) WrapHandlerFunc(h http.HandlerFunc) http.Handler
WrapHandlerFunc wraps an http.HanlderFunc and provide HTTP basic-auth.
type ConnServer ¶
type ConnServer struct { *RPCCore Mode int // Client mode, see constants.go Command chan interface{} // Channel for overlord command Response chan string // Channel for reponsing overlord command Sid string // Session ID Mid string // Machine ID TerminalSid string // Associated terminal session ID Properties map[string]interface{} // Client properties Download fileDownloadContext // File download context // contains filtered or unexported fields }
ConnServer is the main struct for storing connection context between Overlord and Ghost.
func NewConnServer ¶
func NewConnServer(ovl *Overlord, conn net.Conn) *ConnServer
NewConnServer create a ConnServer object.
func (*ConnServer) Listen ¶
func (c *ConnServer) Listen()
Listen is the main routine for listen to socket messages.
func (*ConnServer) SendClearToDownload ¶
func (c *ConnServer) SendClearToDownload()
SendClearToDownload sends "clear_to_download" request to client to start downloading.
func (*ConnServer) SendUpgradeRequest ¶
func (c *ConnServer) SendUpgradeRequest() error
SendUpgradeRequest sends upgrade request to clients to trigger an upgrade.
func (*ConnServer) SpawnFileServer ¶
func (c *ConnServer) SpawnFileServer(sid, terminalSid, action, filename, dest string, perm int, checkOnly bool)
SpawnFileServer Spawn a remote file connection (a ghost with mode ModeFile). action is either 'download' or 'upload'. sid is used for uploading file, indicatiting which client's working directory to upload to.
func (*ConnServer) SpawnModeForwarder ¶
func (c *ConnServer) SpawnModeForwarder(sid string, port int)
SpawnModeForwarder spawns a forwarder connection (a ghost with mode ModeForward). sid is the session ID, which will be used as the session ID of the new ghost.
func (*ConnServer) SpawnShell ¶
func (c *ConnServer) SpawnShell(sid string, command string)
SpawnShell spawns a shell command connection (a ghost with mode ModeShell). sid is the session ID, which will be used as the session ID of the new ghost. command is the command to execute.
func (*ConnServer) SpawnTerminal ¶
func (c *ConnServer) SpawnTerminal(sid, ttyDevice string)
SpawnTerminal spawns a terminal connection (a ghost with mode ModeTerminal). sid is the session ID, which will be used as the session ID of the new ghost. ttyDevice is the target terminal device to open. If it's an empty string, a pseudo terminal will be open instead.
func (*ConnServer) StopListen ¶
func (c *ConnServer) StopListen()
StopListen stops ConnServer's Listen loop.
func (*ConnServer) Terminate ¶
func (c *ConnServer) Terminate()
Terminate terminats the connection and perform cleanup.
type ConnectLogcatCmd ¶
ConnectLogcatCmd is an overlord intend to connect to a logcat session.
type Ghost ¶
type Ghost struct { *RPCCore RegisterStatus string // Register status from server response // contains filtered or unexported fields }
Ghost type is the main context for storing the ghost state.
func (*Ghost) AddToDownloadQueue ¶
AddToDownloadQueue adds a downloadInfo to the download queue
func (*Ghost) InitiateDownload ¶
func (ghost *Ghost) InitiateDownload(info downloadInfo)
InitiateDownload initiates a client-initiated download request.
func (*Ghost) InitiatefileOperation ¶
InitiatefileOperation initiates a file operation. The operation could either be 'download' or 'upload' This function starts handshake with overlord then execute download sequence.
func (*Ghost) RegisterSession ¶
RegisterSession register the PID to a session.
func (*Ghost) RegisterTTY ¶
RegisterTTY register the TTY to a session.
func (*Ghost) ScanGateway ¶
func (ghost *Ghost) ScanGateway()
ScanGateway scans current network gateway and add it into addrs if not already exist.
func (*Ghost) ServeHTTP ¶
func (ghost *Ghost) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP method for serving JSON-RPC over HTTP.
func (*Ghost) SetModeForwardPort ¶
SetModeForwardPort sets the port to forward.
func (*Ghost) SetPropFile ¶
SetPropFile sets the property file filename.
func (*Ghost) SetShellCommand ¶
SetShellCommand sets the shell comamnd to execute.
func (*Ghost) SetTLSMode ¶
SetTLSMode sets the mode of tls detection.
func (*Ghost) SetTerminalSid ¶
SetTerminalSid sets the terminal session ID for the Ghost instance.
func (*Ghost) SetTtyDevice ¶
SetTtyDevice sets the TTY device name to open.
func (*Ghost) SpawnPortModeForwardServer ¶
SpawnPortModeForwardServer spawns a port forwarding server and forward I/O to the TCP socket.
func (*Ghost) SpawnShellServer ¶
SpawnShellServer spawns a Shell server and forward input/output from/to the TCP socket.
func (*Ghost) SpawnTTYServer ¶
SpawnTTYServer Spawns a TTY server and forward I/O to the TCP socket.
func (*Ghost) StartDownloadServer ¶
StartDownloadServer starts the download server.
func (*Ghost) StartLanDiscovery ¶
func (ghost *Ghost) StartLanDiscovery()
StartLanDiscovery starts listening to LAN discovery message.
func (*Ghost) StartRPCServer ¶
func (ghost *Ghost) StartRPCServer()
StartRPCServer starts a local RPC server used for communication between ghost instances.
func (*Ghost) StartUploadServer ¶
StartUploadServer starts the upload server.
type Overlord ¶
type Overlord struct {
// contains filtered or unexported fields
}
Overlord type is the main context for storing the overlord server state.
func NewOverlord ¶
func NewOverlord( bindAddr string, port int, lanDiscInterface string, lanDisc bool, auth bool, certsString string, linkTLS bool, htpasswdPath string) *Overlord
NewOverlord creates an Overlord object.
func (*Overlord) AddWebsocketContext ¶
func (ovl *Overlord) AddWebsocketContext(wc *webSocketContext)
AddWebsocketContext adds an websocket context to the overlord state.
func (*Overlord) GetAppNames ¶
GetAppNames return the name of overlord apps.
func (*Overlord) InitSocketIOServer ¶
func (ovl *Overlord) InitSocketIOServer()
InitSocketIOServer initializes the Socket.io server.
func (*Overlord) Register ¶
func (ovl *Overlord) Register(conn *ConnServer) (*websocket.Conn, error)
Register a client.
func (*Overlord) RegisterDownloadRequest ¶
func (ovl *Overlord) RegisterDownloadRequest(conn *ConnServer)
RegisterDownloadRequest registers a file download request.
func (*Overlord) RegisterHTTPHandlers ¶
func (ovl *Overlord) RegisterHTTPHandlers()
RegisterHTTPHandlers register handlers for http routes.
func (*Overlord) RegisterUploadRequest ¶
func (ovl *Overlord) RegisterUploadRequest(conn *ConnServer)
RegisterUploadRequest registers a file upload request.
func (*Overlord) Serv ¶
func (ovl *Overlord) Serv()
Serv is the main routine for starting all the overlord sub-server.
func (*Overlord) ServHTTP ¶
func (ovl *Overlord) ServHTTP()
ServHTTP is the Web server main routine.
func (*Overlord) StartUDPBroadcast ¶
StartUDPBroadcast is the main routine for broadcasting LAN discovery message.
func (*Overlord) Unregister ¶
func (ovl *Overlord) Unregister(conn *ConnServer)
Unregister a client.
type PollableProcess ¶
PollableProcess is a os.Process which supports the polling for it's status.
func (*PollableProcess) Poll ¶
func (p *PollableProcess) Poll() (uint32, error)
Poll polls the process for it's execution status.
type RPCCore ¶
type RPCCore struct { Conn net.Conn // handle to the TCP connection ReadBuffer string // internal read buffer // contains filtered or unexported fields }
RPCCore is the core implementation of the TCP-based 2-way RPC protocol.
func (*RPCCore) ClearRequests ¶
func (rpc *RPCCore) ClearRequests()
ClearRequests clear all the requests.
func (*RPCCore) ParseMessage ¶
ParseMessage parses a single JSON string into a Message object.
func (*RPCCore) ParseRequests ¶
ParseRequests parses a buffer from SpawnReaderRoutine into Request objects. The response message is automatically handled by the RPCCore itrpc by invoking the corresponding response handler.
func (*RPCCore) ScanForTimeoutRequests ¶
ScanForTimeoutRequests scans for timeout requests.
func (*RPCCore) SendMessage ¶
SendMessage sends a message.
func (*RPCCore) SendRequest ¶
func (rpc *RPCCore) SendRequest(req *Request, handler ResponseHandler) error
SendRequest sends a Request.
func (*RPCCore) SendResponse ¶
SendResponse sends a Response.
func (*RPCCore) SpawnReaderRoutine ¶
SpawnReaderRoutine spawnes a goroutine that actively read from the socket. This function returns two channels. The first one is the channel that send the content from the socket, and the second channel send an error object if there is one.
type RegistrationFailedError ¶
type RegistrationFailedError error
RegistrationFailedError indicates an registration fail error.
type Request ¶
type Request struct { Rid string `json:"rid"` Timeout int64 `json:"timeout"` Name string `json:"name"` Params json.RawMessage `json:"params"` }
Request Object. Implements the Message interface. If Timeout < 0, then the response can be omitted.
func NewRequest ¶
NewRequest creats a new Request object. name is the name of the request. params is map between string and any other JSON-serializable data structure.
func (*Request) SetTimeout ¶
SetTimeout sets the timeout of request. The default timeout is is defined in requestTimeoutSeconds.
type Responder ¶
type Responder struct { RequestTime int64 // Time of request Timeout int64 // Timeout in seconds Handler ResponseHandler // The corresponding request handler }
Responder is The structure that stores the response handler information.
type Response ¶
type Response struct { Rid string `json:"rid"` Response string `json:"response"` Params json.RawMessage `json:"params"` }
Response Object. Implements the Message interface.
func NewResponse ¶
NewResponse creates a new Response object. rid is the request ID of the request this response is intended for. response is the response status text. params is map between string and any other JSON-serializable data structure.
type ResponseHandler ¶
ResponseHandler is the function type of the response handler. if res is nil, means that the response timeout.
type SpawnFileCmd ¶
type SpawnFileCmd struct { Sid string // Session ID TerminalSid string // Target terminal's session ID Action string // Action, download or upload Filename string // File to perform action on Dest string // Destination, use for upload Perm int // File permissions to set CheckOnly bool // Check permission only (writable?) }
SpawnFileCmd is an overlord intend to perform file transfer.
type SpawnModeForwarderCmd ¶
SpawnModeForwarderCmd is an overlord intend to perform port forwarding.
type SpawnShellCmd ¶
SpawnShellCmd is an overlord intend to launch a shell command.
type SpawnTerminalCmd ¶
type SpawnTerminalCmd struct { Sid string // Session ID TtyDevice string // Termainl device to open }
SpawnTerminalCmd is an overlord intend to launch a terminal.
type TerminalControl ¶
TerminalControl is a JSON struct for storing terminal control messages.