traffic

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AutobanProfiles = []AutobanProfile{
	{
		Limit:  dailyLimit,
		Reason: "daily limit",
		Group:  []string{},
		Time:   dailyLimitDuration,
	},
	{
		Limit:  hourlyLimit,
		Reason: "hourly limit",
		Group:  []string{"hour"},
		Time:   hourlyLimitDuration,
	},
	{
		Limit:  tenMinsLimit,
		Reason: "ten min limit",
		Group:  []string{"hour", "tenminute"},
		Time:   time.Hour * hoursInDay,
	},
	{
		Limit:  oneMinLimit,
		Reason: "min limit",
		Group:  []string{"hour", "tenminute", "minute"},
		Time:   halfDay,
	},
}

AutobanProfiles AutobanProfiles.

View Source
var ErrWhitelistItemNotFound = errors.New("whitelist item not found")

Functions

This section is empty.

Types

type APITrafficBlacklistPostRequestBody

type APITrafficBlacklistPostRequestBody struct {
	IP     net.IP `json:"ip"`
	Period int    `json:"period"`
	Reason string `json:"reason"`
}

APITrafficBlacklistPostRequestBody APITrafficBlacklistPostRequestBody.

type APITrafficWhitelistPostRequestBody

type APITrafficWhitelistPostRequestBody struct {
	IP net.IP `json:"ip"`
}

type AutobanProfile

type AutobanProfile struct {
	Limit  int
	Reason string
	Group  []string
	Time   time.Duration
}

AutobanProfile AutobanProfile.

type ListOfTopItem

type ListOfTopItem struct {
	IP    net.IP `json:"ip"`
	Count int    `json:"count"`
}

ListOfTopItem ListOfTopItem.

type Monitoring

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

Monitoring Main Object.

func NewMonitoring

func NewMonitoring(db *goqu.Database) (*Monitoring, error)

NewMonitoring constructor.

func (*Monitoring) Add

func (s *Monitoring) Add(ip net.IP, timestamp time.Time) error

Add item to Monitoring.

func (*Monitoring) Clear

func (s *Monitoring) Clear(ctx context.Context) error

Clear removes all collected data.

func (*Monitoring) ClearIP

func (s *Monitoring) ClearIP(ctx context.Context, ip net.IP) error

ClearIP removes all data collected for IP.

func (*Monitoring) ExistsIP

func (s *Monitoring) ExistsIP(ip net.IP) (bool, error)

ExistsIP ban list already contains IP.

func (*Monitoring) GC

func (s *Monitoring) GC(ctx context.Context) (int64, error)

GC Garbage Collect.

func (*Monitoring) ListByBanProfile

func (s *Monitoring) ListByBanProfile(ctx context.Context, profile AutobanProfile) ([]net.IP, error)

ListByBanProfile ListByBanProfile.

func (*Monitoring) ListOfTop

func (s *Monitoring) ListOfTop(ctx context.Context, limit int) ([]ListOfTopItem, error)

ListOfTop ListOfTop.

func (*Monitoring) Listen

func (s *Monitoring) Listen(url string, queue string, quitChan chan bool) error

Listen for incoming messages.

type MonitoringInputMessage

type MonitoringInputMessage struct {
	IP        net.IP    `json:"ip"`
	Timestamp time.Time `json:"timestamp"`
}

MonitoringInputMessage InputMessage.

type Traffic

type Traffic struct {
	Monitoring *Monitoring
	Whitelist  *Whitelist
	Ban        *ban.Repository
	// contains filtered or unexported fields
}

Traffic Traffic.

func NewTraffic

func NewTraffic(
	pool *goqu.Database,
	autowpDB *goqu.Database,
	enforcer *casbin.Enforcer,
	ban *ban.Repository,
	userExtractor *users.UserExtractor,
) (*Traffic, error)

NewTraffic constructor.

func (*Traffic) AutoBan

func (s *Traffic) AutoBan(ctx context.Context) error

func (*Traffic) AutoBanByProfile

func (s *Traffic) AutoBanByProfile(ctx context.Context, profile AutobanProfile) error

func (*Traffic) AutoWhitelist

func (s *Traffic) AutoWhitelist(ctx context.Context) error

func (*Traffic) AutoWhitelistIP

func (s *Traffic) AutoWhitelistIP(ctx context.Context, ip net.IP) error

func (*Traffic) SetupPrivateRouter

func (s *Traffic) SetupPrivateRouter(r *gin.Engine)

type Whitelist

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

Whitelist Main Object.

func NewWhitelist

func NewWhitelist(db *goqu.Database) (*Whitelist, error)

NewWhitelist constructor.

func (*Whitelist) Add

func (s *Whitelist) Add(ctx context.Context, ip net.IP, desc string) error

Add IP to whitelist.

func (*Whitelist) Exists

func (s *Whitelist) Exists(ctx context.Context, ip net.IP) (bool, error)

Exists whitelist already contains IP.

func (*Whitelist) Get

func (s *Whitelist) Get(ctx context.Context, ip net.IP) (*WhitelistItem, error)

Get whitelist item.

func (*Whitelist) List

func (s *Whitelist) List(ctx context.Context) ([]*WhitelistItem, error)

List whitelist items.

func (*Whitelist) MatchAuto

func (s *Whitelist) MatchAuto(ip net.IP) (bool, string)

MatchAuto MatchAuto.

func (*Whitelist) Remove

func (s *Whitelist) Remove(ctx context.Context, ip net.IP) error

Remove IP from whitelist.

type WhitelistItem

type WhitelistItem struct {
	IP          net.IP `json:"ip"`
	Description string `json:"description"`
}

WhitelistItem WhitelistItem.

Jump to

Keyboard shortcuts

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