Documentation
¶
Overview ¶
Package authguard provides a tool for handle and processing login attempts.
It's designed for use with a Gelada (https://github.com/iu0v1/gelada), but it can operate as an independent package.
Index ¶
- type AuthGuard
- func (ag *AuthGuard) Check(username string, req *http.Request) bool
- func (ag *AuthGuard) ClearUntrackedVisitors()
- func (ag *AuthGuard) Complaint(username string, req *http.Request)
- func (ag *AuthGuard) GetAllVisitors() []*Visitor
- func (ag *AuthGuard) GetVisitor(username string, req *http.Request) (*Visitor, bool)
- func (ag *AuthGuard) Sync() error
- type BindType
- type LogHandlerFunc
- type LogLevelType
- type Options
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthGuard ¶
type AuthGuard struct {
// contains filtered or unexported fields
}
AuthGuard - main struct.
func (*AuthGuard) ClearUntrackedVisitors ¶
func (ag *AuthGuard) ClearUntrackedVisitors()
ClearUntrackedVisitors is used to release the Store data from visitors, who do not have any violations. Store will be synchronized after the process.
Need to reduce the space occupied by the Store.
func (*AuthGuard) GetAllVisitors ¶
GetAllVisitors return all aviable Visitors.
func (*AuthGuard) GetVisitor ¶
GetVisitor returns current Visitor.
type LogHandlerFunc ¶
type LogHandlerFunc func(message string, lvl LogLevelType)
LogHandlerFunc type for log handler function
type LogLevelType ¶
type LogLevelType int
LogLevelType declare the level of informatyvity of log message
const ( LogLevelNone LogLevelType = iota LogLevelInfo LogLevelError LogLevelErrorOnly )
predefined LogLevelType levels
type Options ¶
type Options struct { // Attempts - the number of password attempts. Attempts int // LockoutDuration - lock duration after the end of password attempts. // Seconds. LockoutDuration int // MaxLockouts - the maximum amount of lockouts, before ban. MaxLockouts int // BanDuration - duration of ban. // Seconds. BanDuration int // AttemptsResetDuration - time after which to reset the number of attempts. // Seconds. AttemptsResetDuration int // LockoutsResetDuration - time after which to reset the number of lockouts. LockoutsResetDuration int // BindMethod - visitor binding type. Only IP or IP + username. BindMethod BindType // SyncAfter - sync data with the Store file after X updates. SyncAfter int // Store - place for store user data. // Filepath. // // If Store == "::memory::", then Gelada does not place the data in the file // and store everything in memory. Store string // Exceptions - Hosts(IP) whitelist. Exceptions []string // LogLevel provides the opportunity to choose the level of // information messages. // Each level includes the messages from the previous level, // except LogLevelErrorOnly. // LogLevelNone - no messages // 0 // LogLevelInfo - info // 1 // LogLevelError - error // 2 // LogLevelErrorOnly - only errors // 3 // // Default: LogLevelNone. LogLevel LogLevelType // LogDestination provides the opportunity to choose the own // destination for log messages (errors, info, etc). // // Default: 'os.Stdout'. LogDestination io.Writer // LogHandler takes log messages to bypass the internal // mechanism of the message processing // // If LogHandler is selected - all log settings will be ignored. LogHandler LogHandlerFunc // ProxyIPHeaderName - http header name for handle user IP behind proxy ProxyIPHeaderName string }
Options - structure, which is used to configure authguard.
type Visitor ¶
type Visitor struct { Username string Host string UserAgent string Attempts int Lockouts int Ban bool ResetAttemptsAfter time.Time ResetLockoutsAfter time.Time LockUntil time.Time // contains filtered or unexported fields }
Visitor contain info about the current user and provide some helper methods.
func (*Visitor) LockRemainingTime ¶
LockRemainingTime - return the time until the lockouts ends, in seconds.