controller

package
v0.0.0-...-8de47ec Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2019 License: MIT Imports: 16 Imported by: 0

README

Package controller provides the control aspects of Remocc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

Check BCrypt hash by matching

func DeviceDownlinkHandler

func DeviceDownlinkHandler(w http.ResponseWriter, r *http.Request, email string, devTable string)

Function users use to send a downlink message to the device

func DeviceInfoHandler

func DeviceInfoHandler(w http.ResponseWriter, r *http.Request, email string, devTable string)

Device preview page showing tunnel status and latest logs (up to 10)

func DeviceLoginHandler

func DeviceLoginHandler(w http.ResponseWriter, r *http.Request)

Provides JWT token when presented with valid device claims. Checks device name, user's email, and devices password to return back a JWT TODO: Make this agnostic to the user TODO: Add token validity period

func DeviceLogsHandler

func DeviceLogsHandler(w http.ResponseWriter, r *http.Request, email string, devTable string)

Device Logs

func DeviceManagerHandler

func DeviceManagerHandler(w http.ResponseWriter, r *http.Request, email string, tableName string)

Function to manage devices. Handles device registration and deletion

func DeviceSSHStatusHandler

func DeviceSSHStatusHandler(w http.ResponseWriter, r *http.Request, email string, devTable string)

Get SSHStatus, i.e, if user has scheduled a tunnel to be made, if device has launched that tunnel, or if it is stopped

func DeviceTunnelRequestHandler

func DeviceTunnelRequestHandler(w http.ResponseWriter, r *http.Request, devClaims *DevClaims)

func DeviceUplinkHandler

func DeviceUplinkHandler(w http.ResponseWriter, r *http.Request, devClaims *DevClaims)

func FrontPageHandler

func FrontPageHandler(w http.ResponseWriter, r *http.Request, email string, tableName string)

Render template for front page displaying all the devices registered to a particular user TODO: Add a more qualified user context here instead of tableName

func HashPassword

func HashPassword(password string) (string, error)

Simple BCrypt hash to store user and device passwords

func HeartBeatHandler

func HeartBeatHandler(w http.ResponseWriter, r *http.Request, devClaims *DevClaims)

func LogSession

func LogSession(w http.ResponseWriter, usr *models.User)

Log a users web session via cookies

func LoginHandler

func LoginHandler(w http.ResponseWriter, r *http.Request)

func LogoutHandler

func LogoutHandler(w http.ResponseWriter, r *http.Request)

func ProvideApiHandler

func ProvideApiHandler(fn func(http.ResponseWriter, *http.Request, *DevClaims)) http.HandlerFunc

Closure to provide requested API for devices. Checks for JWT token claims and services the requested api if token is valid. In addition, provides the devices claim to the underlying API

func ProvideWebHandler

func ProvideWebHandler(fn func(http.ResponseWriter, *http.Request, string, string)) http.HandlerFunc

Closure to provide web content. Checks for cookies and returns to the requester the requested page if user's session token is present in usrAuthCache. Also provides to the API function the users email and the device table name TODO: No need of device table. It can be constructed from user email

func RegisterHandler

func RegisterHandler(w http.ResponseWriter, r *http.Request)

func SSHRequestHandler

func SSHRequestHandler(w http.ResponseWriter, r *http.Request, email string, devTable string)

Functions users use to make an SSH request to schedule or stop

func Start

func Start()

func Testprovidehandler

func Testprovidehandler(fn func(http.ResponseWriter, *http.Request, string, string)) http.HandlerFunc

A test closure to wrap web functions for testing. A user "a" with email "a@a.com" password "a" is used

Types

type DevClaims

type DevClaims struct {
	DevName string `json:"devName"`
	Email   string `json:"email"`
	Pwd     string `json:"pwd"`
}

Claims structure for devices claiming a JWT

type DevEnv

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

Database environment for "device" related database accesses

type DownlinkReq

type DownlinkReq struct {
	Port        string `json:"port"`
	DownlinkMsg string `json:"downlinkMsg"`
	RespType    string `json:"reqType"` // schedule, stop or downlink
}

Structure users use to give either of the following -

send a downlink message OR ssh schedule/stop request

type HeartBeatReq

type HeartBeatReq struct {
	PingTime int `json:"pingTime"`
}

Structure devices use register that they are alive

type JWToken

type JWToken struct {
	Token string `json:"token"`
}

JWT response message structure

type SSHReq

type SSHReq struct {
	TunnelStatus string `json:"tunnelStatus"` // schedule, launch, stop
	Port         string `json:"port"`
	RemoccPort   string `json:"remoccPort"`
	Uname        string `json:"uname"`
	DevName      string `json:"devName"`
	DevUName     string `json:"devUName"`
	RemoccHost   string `json:"remoccHost"`
}

Structure users use to get SSH tunnel Status Structure devices use to make an SSH launch request

type UplinkReq

type UplinkReq struct {
	UplinkMsg string `json:"uplinkMsg"`
}

Structure devices use to send a message to server

type UsrEnv

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

type UsrListDevsReq

type UsrListDevsReq struct {
	NumEntries int `json:"numEntries"`
	Offset     int `json:"offset"`
}

Structure to list user's devices

Jump to

Keyboard shortcuts

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