Documentation ¶
Index ¶
- Constants
- type API
- type Block
- func (b *Block) ASNNamespace(asn int) []byte
- func (b *Block) AllASNs() ([]asndb.ASN, error)
- func (b *Block) AllIPs() ([]*data.IPBlockMessage, error)
- func (b *Block) AllNetworks() ([]net.IPNet, error)
- func (b *Block) BlockASN(msg data.BlockMessage) error
- func (b *Block) BlockIP(msg data.IPBlockMessage) error
- func (b *Block) BlockNetwork(msg data.NetworkBlockMessage) error
- func (b *Block) BlockedASNs() []data.BlockMessage
- func (b *Block) BlockedIPs() []data.IPBlockMessage
- func (b *Block) BlockedNetworks() []data.NetworkBlockMessage
- func (b *Block) CIDRNamespace(cidr string) []byte
- func (b *Block) CheckBlocked()
- func (b *Block) Clear()
- func (b *Block) CountASNs() int
- func (b *Block) CountIPs() int
- func (b *Block) CountNetworks() int
- func (b *Block) GetASN(asn *asndb.ASN) (*data.BlockMessage, error)
- func (b *Block) GetIP(ip net.IP) (*IPDetails, error)
- func (b *Block) GetNetwork(network net.IPNet) (*data.BlockMessage, error)
- func (b *Block) IPNamespace(ip []byte) []byte
- func (b *Block) IsBlocked(ip net.IP, asn *asndb.ASN) bool
- func (b *Block) IsBlockedByASN(asn *asndb.ASN) (blocked bool, reason string)
- func (b *Block) RemoveASN(asn *asndb.ASN) error
- func (b *Block) RemoveIP(ip net.IP) error
- func (b *Block) RemoveNetwork(network net.IPNet) error
- type Botex
- type CIDRWhitelistRule
- type Decision
- type History
- func (h *History) Add(r *data.Request) (ipd *IPData, newIP bool)
- func (h *History) Each(callback func(key string, ipd *IPData))
- func (h *History) IPData(ip net.IP) *IPData
- func (h *History) IPDetails(ip net.IP) *IPDetails
- func (h *History) SetHostname(ip net.IP, hostname string)
- func (h *History) Size() int
- func (h *History) TotalStats() data.IPStats
- type IPData
- func (ipd *IPData) Add(r *data.Request) Decision
- func (ipd *IPData) Expire() int
- func (ipd *IPData) IPStats() data.IPStats
- func (ipd *IPData) SetHostname(hostname string)
- func (ipd *IPData) ShouldBeBlocked() bool
- func (ipd *IPData) Stats() data.Stats
- func (ipd *IPData) Update(stats data.IPStats, force bool)
- type IPDetails
- type IPResolv
- type MapWindow
- type Plugin
- type Requests
- func (r *Requests) Add(req *data.Request)
- func (r *Requests) App() int
- func (r *Requests) AppStats() map[int]int64
- func (r *Requests) CanBeExpired() bool
- func (r *Requests) Expire() int
- func (r *Requests) Latest() []*data.Request
- func (r *Requests) Other() int
- func (r *Requests) Ratio() float64
- func (r *Requests) Total() int
- func (r *Requests) TotalStats() map[int]int64
- func (r *Requests) Useragents() map[string]int
- type RequestsWindow
- type Resolver
- type Resources
- type Stats
- type StatsWindows
- type WebserverSocket
- type Whitelist
- func (wl *Whitelist) IsCIDRWhitelisted(ip net.IP) (bool, string)
- func (wl *Whitelist) IsURLWhitelisted(url string) bool
- func (wl *Whitelist) IsWhitelisted(ipd *IPDetails) (whitelisted bool, description string)
- func (wl *Whitelist) IsWhitelistedByServerHost(r *data.Request) bool
- func (wl *Whitelist) IsWhitelistedByServerPath(r *data.Request) bool
- func (wl *Whitelist) IsWhitelistedByUseragent(r *data.Request) bool
- func (wl *Whitelist) Load() error
- type WhitelistRegexps
- type WhitelistRule
- type WhitelistRules
- type Window
Constants ¶
const DNSLookupError = "lookup error"
DNSLookupError denotes a dns lookup error
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API provides the HTTP REST API for botex
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block is used to add IPs to the blocklist and to check whether an IP is blocked
func NewBlock ¶
func NewBlock(ctx context.Context, wlChan, blChan chan bool, resources *Resources, blockTTL time.Duration) *Block
NewBlock creates a new Blocklist. The parent context and application configuration are passed on to the new instance
func (*Block) ASNNamespace ¶
func (*Block) AllIPs ¶
func (b *Block) AllIPs() ([]*data.IPBlockMessage, error)
AllIPs returns all currently blocked IPs
func (*Block) AllNetworks ¶
AllNetworks returns all currently blocked IPs
func (*Block) BlockASN ¶
func (b *Block) BlockASN(msg data.BlockMessage) error
BlockaASN writes an entire autonomous system (AS) to the block list It returns an error if writing the information failed
func (*Block) BlockIP ¶
func (b *Block) BlockIP(msg data.IPBlockMessage) error
BlockIP writes an IPs details to the blocklist. It returns an error if writing the information failed
func (*Block) BlockNetwork ¶
func (b *Block) BlockNetwork(msg data.NetworkBlockMessage) error
BlockNetwork writes an entire network to the block list It returns an error if writing the information failed
func (*Block) BlockedASNs ¶
func (b *Block) BlockedASNs() []data.BlockMessage
func (*Block) BlockedIPs ¶
func (b *Block) BlockedIPs() []data.IPBlockMessage
func (*Block) BlockedNetworks ¶
func (b *Block) BlockedNetworks() []data.NetworkBlockMessage
func (*Block) CIDRNamespace ¶
func (*Block) CheckBlocked ¶
func (b *Block) CheckBlocked()
func (*Block) Clear ¶
func (b *Block) Clear()
Clear removes all currently blocked items from the store
func (*Block) CountNetworks ¶
CountNetworks returns the number of currently blocked networks
func (*Block) GetASN ¶
func (b *Block) GetASN(asn *asndb.ASN) (*data.BlockMessage, error)
GetASN retrieves a blocked ASN. If the ASN isn't blocked an error is returned
func (*Block) GetIP ¶
GetIP retrieves an IPDetails item about a blocked IP. If the IP isn't blocked an error is returned
func (*Block) GetNetwork ¶
GetNetworkretrieves an IPDetails item about a blocked IP. If the IP isn't blocked an error is returned
func (*Block) IPNamespace ¶
func (*Block) IsBlockedByASN ¶
type Botex ¶
type Botex struct {
// contains filtered or unexported fields
}
Botex detects bad bots
func (*Botex) HandleRequest ¶
HandleRequest handles incoming requests
type CIDRWhitelistRule ¶
CIDRWhitelistRule is a CIDR whitelist rule
type History ¶
type History struct {
// contains filtered or unexported fields
}
History is the history of all IPs for which the application has received a request
func NewHistory ¶
func NewHistory(ctx context.Context, plugins []Plugin, resources *Resources, config *config.Config) *History
NewHistory creates a new History item and passes on the context and configuration from its parent
func (*History) Add ¶
Add adds a single HTTP request to the history If Add has added a new item to the data map it returns true, otherwise it returns false
func (*History) SetHostname ¶
SetHostname sets the reverse hotname for a given IP
func (*History) TotalStats ¶
TotalStats returns the sum of the stats for all IPs
type IPData ¶
type IPData struct { IPDetails `json:"ipdetails"` Requests *Requests `json:"requests"` // contains filtered or unexported fields }
IPData contains IPDetails and the most recent HTTP requests. It handles updating the aggregated stats when it receives new requests
func NewIPData ¶
func NewIPData(updateChan chan data.IPStats, ip net.IP, plugins []Plugin, resources *Resources, config *config.Config) *IPData
NewIPData creates a new IPData item fro a given IP. the parent context and app configuration are passed on from the parent
func (*IPData) SetHostname ¶
SetHostname sets the reverse hostname for an IP
func (*IPData) ShouldBeBlocked ¶
ShouldBeBlocked deterines whether the IP represented by this item should be blocked
type IPDetails ¶
type IPDetails struct { IP net.IP `json:"ip"` Hostname string `json:"hostname"` ASN *asndb.ASN `json:"asn"` GeoIP *geoip.GeoIP `json:"geoip"` Total int `json:"total"` App int `json:"app"` Other int `json:"other"` Ratio float64 `json:"ratio"` IsBlocked bool `json:"is_blocked"` BlockReason string `json:"block_reason"` Whitelisted bool `json:"whitelisted"` WhitelistReason string `json:"whitelist_reason"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` LastBlockAt time.Time `json:"lastblock_at"` ForceBlock bool `json:"-"` }
IPDetails contains meta information about an IP, its aggregated statistics and a reason for why it was blocked
type IPResolv ¶
type IPResolv struct { IP net.IP `json:"ip"` Host string `json:"host"` Err string `json:"err"` Tries int `json:"tries"` TEnd time.Time `json:"tend"` TStart time.Time `json:"tstart"` }
IPResolv contains an IP address and its corresponding reverse hostname
func NewIPResolv ¶
NewIPResolv creates a new IP that needs to be resolved
type MapWindow ¶
type MapWindow struct {
// contains filtered or unexported fields
}
MapWindow is a map that contains a rolling.TimePolicy for each entry
func NewMapWindow ¶
NewMapWindow creates a new MapWindow. windowSize determines the size of each window, numWindows how many windows there should be The context of the parent gets passed on to the new instance
type Requests ¶
Requests contains all HTTP requests for a given time. The requests are divied by their type: app and other (assets) Requests notifies its parent of changes through updateChan
func NewRequests ¶
NewRequests creates a new Requests item. The app context and configuration get passed into the new item
func (*Requests) AppStats ¶
AppStats returns a map that has the timestamp (unix nanoseconds) as key and the count of app requests as value
func (*Requests) CanBeExpired ¶
CanBeExpired determines whether there are requests that can be expired
func (*Requests) TotalStats ¶
TotalStats returns a map that has the timestamp (unix nanoseconds) as key and the count of requests as value
func (*Requests) Useragents ¶
Useragents returns a map made up of the user agent and its responding count
type RequestsWindow ¶
type RequestsWindow struct {
// contains filtered or unexported fields
}
RequestsWindow contains the most recent requests The number of requests is limited by a maximum number of requests the list may contain (maxSize) and ttl, the time requests stay in the list before they expire and are removed
func NewRequestsWindow ¶
func NewRequestsWindow(maxRequests int, windowSize time.Duration, numWindows int) *RequestsWindow
NewRequestsWindow creates a new RequestsWindow. The app context and configuration get passed into the new item
func (*RequestsWindow) Add ¶
func (rw *RequestsWindow) Add(r *data.Request)
Add adds a single request
func (*RequestsWindow) Expire ¶
func (rw *RequestsWindow) Expire() int
Expire removes expired requests from the window
func (*RequestsWindow) Len ¶
func (rw *RequestsWindow) Len() int
Len returns the number of items in a RequestsWindow
func (*RequestsWindow) Requests ¶
func (rw *RequestsWindow) Requests() []*data.Request
Requests returns an array of all requests in the list
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver is a DNS resolver with Redis cache
func NewResolver ¶
func NewResolver(ctx context.Context, resources *Resources, config *config.Config) (*Resolver, error)
NewResolver creates a new Resolver item
func (*Resolver) StartWorkers ¶
StartWorkers starts the resolver workers. It pulls IPs from the input queue and processes them internally. when an IP has been resolved the result is sent over the output channel
type Resources ¶
type Resources struct { ASNDB *asndb.DB GEOIPDB *geoip.DB NatsServer *natsd.Server NatsConn *nats.Conn Store store.KVStore Whitelist *Whitelist Resolver *Resolver WebsocketChan chan interface{} BlockChan chan *IPDetails }
func NewResources ¶
func NewResources() *Resources
type Stats ¶
type Stats struct { Total int64 `json:"total"` Whitelisted int64 `json:"whitelisted"` Blocked int64 `json:"blocked"` Human int64 `json:"human"` Time time.Time `json:"time,string"` UpdatedAt time.Time `json:"updated_at,string"` }
func (Stats) MarshalJSON ¶
func (*Stats) UnmarshalJSON ¶
type StatsWindows ¶
type StatsWindows struct { Stats Map *treemap.Map `json:"data"` // contains filtered or unexported fields }
func NewStatsWindows ¶
func NewStatsWindows(resources *Resources, config *config.Config) *StatsWindows
func (*StatsWindows) All ¶
func (s *StatsWindows) All() map[string]Stats
func (*StatsWindows) Expire ¶
func (s *StatsWindows) Expire()
type WebserverSocket ¶
type WebserverSocket struct {
// contains filtered or unexported fields
}
type Whitelist ¶
Whitelist is the structure that contains all whitelist logic
func NewWhitelist ¶
func NewWhitelist(ctx context.Context, blocklistRecheckChan chan bool, config *config.Config) (*Whitelist, error)
NewWhitelist creates a new whitelist data structure from MongoDB
func (*Whitelist) IsCIDRWhitelisted ¶
IsCIDRWhitelisted determines if the given IP is part of a network specified by the cidr
func (*Whitelist) IsURLWhitelisted ¶
IsURLWhitelisted determines whether a requested URL is whitelisted and should not be processed
func (*Whitelist) IsWhitelisted ¶
IsWhitelisted determines whether the IP represented by ipd is whitelisted. The method returns whether the IP is whitelisted and the description of the rule that matched
func (*Whitelist) IsWhitelistedByServerHost ¶
IsWhitelistedByServerHost checks whether an incoming request is whitelisted by a server hostname rule
func (*Whitelist) IsWhitelistedByServerPath ¶
IsWhitelistedByServerPath checks whether an incoming request is whitelisted by a server path (URL) rule
func (*Whitelist) IsWhitelistedByUseragent ¶
IsWhitelistedByUseragent checks whether an incoming request is whitelisted by a useragent rule
type WhitelistRegexps ¶
type WhitelistRegexps struct { IP *regexp.Regexp Host *regexp.Regexp Org *regexp.Regexp ASN *regexp.Regexp Target *regexp.Regexp URL *regexp.Regexp UserAgent *regexp.Regexp }
WhitelistRegexps contains whitelist regexps for various data fields
type WhitelistRule ¶
WhitelistRule represents a single Whitelist rule
type WhitelistRules ¶
type WhitelistRules struct { IP []WhitelistRule CIDR []WhitelistRule ClientHost []WhitelistRule Org []WhitelistRule ASN []WhitelistRule Useragent []WhitelistRule ServerHost []WhitelistRule ServerPath []WhitelistRule }
WhitelistRules contains the Whitelist configuration
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window implements a rolling window using a TreeMap as storage
func NewWindow ¶
NewWindow creates a new TreemapWindow instance with numWindows buckets that each cover a windowSize time range TODO: remove ctx as arg