Documentation ¶
Overview ¶
package greylist implements a basic whitelisting/blacklisting http.Handler
It reads 2 files (whitelist file, blacklist file) and has option to periodically refresh the lists. It also provides an additional Blacklist(ip) method for temporary bans.
Index ¶
Constants ¶
const DefaultTemporaryBlacklistTime = time.Hour
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a greylist instance
func New ¶
New accepts whitelist filename, blacklist filename, and a refreshrate duration If the files don't exist or are empty, they are not used, and read errors will not be reported. refreshRate can be 0, in which case no automatic refreshing is done. (see RefreshLists())
After calling New(), a program can use l.Protect() to wrap a http.Handler.
By default, only non-GET requests are protected. If your program demands, use l.SetAllMethods(true)
By default, temporary bans are one hour. To change this, call l.SetTemporaryBlacklistTime(time.Duration)
func (*List) Protect ¶
Protect a http.Handler
http.ListenAndServe(":8080", glist.Protect(myHandler))
func (*List) RefreshLists ¶
func (l *List) RefreshLists()
RefreshLists reads the whitelist and blacklist files and sets new maps (removed ips will not be in new map) Errors are ignored, in case the file doesn't exist or is not readable.
Note: Files must end in an empty newline, and windows newlines are not supported. (Only checks '\n\n')
func (*List) ServeHTTP ¶
func (l *List) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler interface
func (*List) SetAllMethods ¶
SetAllMethods blocks all requests from blacklisted IPs. Use with caution as it currently slows requests for everyone
func (*List) SetTemporaryBlacklistTime ¶
SetTemporaryBlacklistTime sets the duration that offenders will be blacklisted for