Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertToInt(s string) int
- func FileExists(file string) bool
- func FindConfigFile() string
- func FormatMacAddress(mac string) (net.HardwareAddr, error)
- func GetIPFromContext(r *http.Request) net.IP
- func LoadPolicyText(file string) []template.HTML
- func ParseTime(time string) (int64, error)
- func RegisterSystemInitFunc(f SystemInitFunc)
- func RunSystemInits(e *Environment) error
- func SetEnvironmentToContext(r *http.Request, e *Environment) *http.Request
- func SetIPToContext(r *http.Request) *http.Request
- func SetSessionToContext(r *http.Request, s *Session) *http.Request
- func StringInSlice(a string, list []string) bool
- type APIResponse
- type Config
- type DataFunc
- type DatabaseAccessor
- type Environment
- type EnvironmentEnv
- type Key
- type Logger
- type Options
- type Session
- func (s *Session) Delete(r *http.Request, w http.ResponseWriter) error
- func (s *Session) Get(key interface{}, def ...interface{}) interface{}
- func (s *Session) GetBool(key interface{}, def ...bool) bool
- func (s *Session) GetInt(key interface{}, def ...int) int
- func (s *Session) GetInt64(key interface{}, def ...int64) int64
- func (s *Session) GetString(key interface{}, def ...string) string
- func (s *Session) Set(key, val interface{})
- type SessionStore
- type SystemInitFunc
- type TestStore
- type View
- type Views
Constants ¶
const ContentTypeJSON = "application/json; charset=utf-8"
const ( // TimeFormat standard for the application TimeFormat string = "2006-01-02 15:04" )
Variables ¶
var ( DatabaseTableNames = []string{ "blacklist", "device", "lease", "lease_history", "sessions", "settings", "user", } BlacklistTableCols = []string{ "id", "value", "comment", } DeviceTableRows = []string{ "id", "mac", "username", "registered_from", "platform", "expires", "date_registered", "user_agent", "blacklisted", "description", "last_seen", } LeaseTableCols = []string{ "id", "ip", "mac", "network", "start", "end", "hostname", "abandoned", "registered", } UserTableCols = []string{ "id", "username", "password", "device_limit", "default_expiration", "expiration_type", "can_manage", "can_autoreg", "valid_start", "valid_end", "valid_forever", "ui_group", "api_group", "allow_status_api", } SessionTableCols = []string{ "id", "session_data", "created_on", "modified_on", } SettingTableCols = []string{ "id", "value", } )
Database table and column names for enumeration and misc use.
var PageSize = 30
PageSize is the number of items per page
var SystemVersion string
SystemVersion is the current version of the software.
Functions ¶
func ConvertToInt ¶
ConvertToInt converts s to an int and ignores errors
func FindConfigFile ¶ added in v0.8.0
func FindConfigFile() string
FindConfigFile searches for a configuration file. The order of search is environment, current dir, home dir, and /etc.
func FormatMacAddress ¶
func FormatMacAddress(mac string) (net.HardwareAddr, error)
FormatMacAddress will attempt to format and parse a string as a MAC address
func GetIPFromContext ¶ added in v0.14.0
GetIPFromContext retrieves the IP address from the current request.
func LoadPolicyText ¶ added in v0.8.0
LoadPolicyText loads a file and wraps it in a template type to ensure custom HTML is allowed. The file should be secured so unauthorized HTML/JS isn't allowed.
func ParseTime ¶
ParseTime return the number of seconds represented by the string. Valid input looks like "HH:mm". HH must be between 0-24 inclusive and mm must be between 0-59 inclusive.
func RegisterSystemInitFunc ¶ added in v1.3.0
func RegisterSystemInitFunc(f SystemInitFunc)
RegisterSystemInitFunc registers a function to be run on system init.
func RunSystemInits ¶ added in v1.3.0
func RunSystemInits(e *Environment) error
RunSystemInits executes the registered init functions in the order they were registered.
func SetEnvironmentToContext ¶
func SetEnvironmentToContext(r *http.Request, e *Environment) *http.Request
SetEnvironmentToContext sets an Environment for the current request.
func SetIPToContext ¶ added in v0.14.0
SetIPToContext sets an IP address for the current request.
func SetSessionToContext ¶
SetSessionToContext sets an Session for the current request.
func StringInSlice ¶
StringInSlice searches a slice for a string
Types ¶
type APIResponse ¶
type APIResponse struct { Message string Data interface{} }
A APIResponse is returned as a JSON struct to the client.
func NewAPIResponse ¶
func NewAPIResponse(m string, d interface{}) *APIResponse
NewAPIResponse creates an APIResponse object with status c, message m, and data d.
func NewEmptyAPIResponse ¶
func NewEmptyAPIResponse() *APIResponse
NewEmptyAPIResponse returns an APIResponse with no message or data.
func (*APIResponse) Encode ¶
func (a *APIResponse) Encode() []byte
Encode the APIResponse into JSON.
func (*APIResponse) WriteResponse ¶
func (a *APIResponse) WriteResponse(w http.ResponseWriter, code int) (int, error)
WriteResponse encodes and writes a response back to the client.
type Config ¶
type Config struct { Core struct { SiteTitle string SiteCompanyName string SiteDomainName string SiteFooterText string JobSchedulerWakeUp string PageSize int } Logging struct { Enabled bool EnableHTTP bool Level string Path string } Database struct { Type string Address string Port int Username string Password string Name string Retry int RetryTimeout string } Registration struct { RegistrationPolicyFile string AllowManualRegistrations bool DefaultDeviceLimit int DefaultDeviceExpirationType string RollingExpirationLength string DefaultDeviceExpiration string ManualRegPlatforms []string } Guest struct { Enabled bool GuestOnly bool DeviceLimit int DeviceExpirationType string DeviceExpiration string Checker string VerifyCodeExpiration int DisableCaptcha bool RegPageHeader string Email struct { } Twilio struct { AccountSID string AuthToken string PhoneNumber string } Smseagle struct { Address string Username string Password string HighPriority int FlashMsg int } } Webserver struct { Address string HTTPPort int HTTPSPort int TLSCertFile string TLSKeyFile string RedirectHTTPToHTTPS bool SessionStore string SessionName string SessionsDir string SessionsAuthKey string SessionsEncryptKey string CustomDataDir string } Auth struct { AuthMethod []string AdminUsers []string HelpDeskUsers []string ReadOnlyUsers []string APIReadOnlyUsers []string APIReadWriteUsers []string APIStatusUsers []string LDAP struct { Server string Port int UseSSL bool InsecureSkipVerify bool SkipTLS bool DomainName string } Radius struct { Servers []string Port int Secret string } CAS struct { Server string } Openid struct { Server string ClientID string ClientSecret string AuthorizeEndoint string `toml:"-"` TokenEndoint string `toml:"-"` UserinfoEndpoint string `toml:"-"` } } DHCP struct { ConfigFile string } Email struct { Address string Port int Username string Password string FromAddress string ToAddresses []string } // contains filtered or unexported fields }
Config defines the configuration struct for the application
func NewConfig ¶
NewConfig reads the given filename into a Config. If filename is empty, the config is looked for in the documented order.
func NewEmptyConfig ¶
func NewEmptyConfig() *Config
NewEmptyConfig returns an empty config with type defaults only.
type DatabaseAccessor ¶
DatabaseAccessor wraps an sql.DB with a driver string.
func (*DatabaseAccessor) SchemaVersion ¶ added in v1.3.0
func (d *DatabaseAccessor) SchemaVersion() int
SchemaVersion queries the database and returns the current version.
type Environment ¶
type Environment struct { Sessions *SessionStore DB *DatabaseAccessor Config *Config Views *Views Env EnvironmentEnv Log *Logger // contains filtered or unexported fields }
Environment holds "global" application information such as a database connection, logging, the config, sessions, etc.
func GetEnvironmentFromContext ¶
func GetEnvironmentFromContext(r *http.Request) *Environment
GetEnvironmentFromContext retrieves the Environment from the current request.
func NewEnvironment ¶
func NewEnvironment(t EnvironmentEnv) *Environment
NewEnvironment creates an environment.
func NewTestEnvironment ¶
func NewTestEnvironment() *Environment
NewTestEnvironment creates and environment setup for testing.
func (*Environment) IsDev ¶ added in v0.8.0
func (e *Environment) IsDev() bool
IsDev checks if the current environment is development
func (*Environment) IsProd ¶ added in v0.8.0
func (e *Environment) IsProd() bool
IsProd checks if the current environment is production
func (*Environment) IsTesting ¶ added in v0.8.0
func (e *Environment) IsTesting() bool
IsTesting checks if the current environment is testing
func (*Environment) SubscribeShutdown ¶ added in v1.1.0
func (e *Environment) SubscribeShutdown() <-chan bool
SubscribeShutdown returns a channel that the caller can block on. The channel will receive a value when the application receives a shutdown signal.
type EnvironmentEnv ¶ added in v0.8.0
type EnvironmentEnv string
EnvironmentEnv is an environment type
const ( EnvTesting EnvironmentEnv = "testing" EnvProd EnvironmentEnv = "production" EnvDev EnvironmentEnv = "development" )
Indicates what environment the software is running in
type Logger ¶
type Logger struct { *verbose.Logger // contains filtered or unexported fields }
Logger wraps a verbose.Logger with a config and timer.
var SystemLogger *Logger
SystemLogger application wide logger.
func (*Logger) GetLogger ¶
GetLogger returns a new Logger based on its parent but with a new name This can be used to separate logs from different sub-systems.
func (*Logger) StartTimer ¶ added in v0.8.0
StartTimer starts a named timer on this logger.
type Options ¶ added in v1.0.0
type Options struct { Path string Domain string MaxAge int Secure bool HTTPOnly bool TableName string }
Options to control the session cookie
type Session ¶
Session is a wrapper around Gorilla sessions to provide access methods
func GetSessionFromContext ¶
GetSessionFromContext retrieves the Session from the current request.
func (*Session) Get ¶
func (s *Session) Get(key interface{}, def ...interface{}) interface{}
Get a value from the session object
func (*Session) GetInt64 ¶ added in v0.8.0
GetInt64 takes the same arguments as Get but def must be an int type.
type SessionStore ¶
SessionStore wraps a Gorilla session and adds extra functionality.
func NewSessionStore ¶
func NewSessionStore(e *Environment) (*SessionStore, error)
NewSessionStore creates a new store based the application configuration.
func (*SessionStore) GetSession ¶
func (s *SessionStore) GetSession(r *http.Request) *Session
GetSession returns a session based on the http request.
type SystemInitFunc ¶ added in v1.3.0
type SystemInitFunc func(*Environment) error
SystemInitFunc is a function to be run at the start of the application.
type TestStore ¶
type TestStore struct{}
TestStore is a mock session store for testing.
type View ¶
type View struct {
// contains filtered or unexported fields
}
View represents a template associated with a specific request.
type Views ¶
type Views struct {
// contains filtered or unexported fields
}
Views is a collection of templates
func NewViews ¶
func NewViews(e *Environment, basepath string) (v *Views, err error)
NewViews reads a set of templates from a directory and loads them into a Views. Custom functions are injected into the templates.
func (*Views) InjectData ¶ added in v1.6.0
InjectData will always inject a specific key, value pair into every template
func (*Views) InjectDataFunc ¶ added in v1.6.0
InjectData will always inject a specific key, value pair into every template
func (*Views) Reload ¶
Reload replaces the Views object with a new one using the same source directory. DO NOT call this function in production. This functions should only be called in a development environment. This functions is very susceptible to race conditions.
func (*Views) RenderError ¶
RenderError renders an error template with the given data. If data is nil, the generic "error" template is used. If data is not nil, "custom-error" is used.