model

package
v0.0.0-...-07b4fab Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCachedIpGeoQuerier

func NewCachedIpGeoQuerier(querier ipgeo.Querier, db *Database) ipgeo.Querier

Types

type AbuseipdbReport

type AbuseipdbReport struct {
	Id         int64
	Ip         string `gorm:"size:39"`
	ReportedAt time.Time
	Score      int

	CreatedAt time.Time `gorm:"<-:create"`
	UpdatedAt time.Time
}

type BruteAttempt

type BruteAttempt struct {
	Id            int64
	Ip            string           `gorm:"size:39,index:ip_kind"` // max ipv6 length
	Kind          BruteAttemptKind `gorm:"index:ip_kind"`
	User          string           `gorm:"size:255"`
	Password      string           `gorm:"size:255"`
	ClientVersion string           `gorm:"size:255"`
	StartedAt     time.Time
	StoppedAt     time.Time
	Count         int64

	CreatedAt time.Time `gorm:"<-:create"`
	UpdatedAt time.Time `gorm:"index"`
}

func (*BruteAttempt) BeforeSave

func (r *BruteAttempt) BeforeSave(_ *gorm.DB) error

func (*BruteAttempt) Duration

func (r *BruteAttempt) Duration() time.Duration

func (*BruteAttempt) MaskedPassword

func (r *BruteAttempt) MaskedPassword() string

func (*BruteAttempt) ShortClientVersion

func (r *BruteAttempt) ShortClientVersion() string

type BruteAttemptKind

type BruteAttemptKind int
const (
	BruteAttemptKindSsh  BruteAttemptKind // ssh
	BruteAttemptKindHttp                  // http
	BruteAttemptKindFtp                   // ftp
)

func (BruteAttemptKind) String

func (i BruteAttemptKind) String() string

type Database

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

func NewDatabase

func NewDatabase(ctx context.Context, cfg config.Database) (*Database, error)

func (*Database) Create

func (db *Database) Create(ctx context.Context, value any) error

func (*Database) IncrBruteAttempt

func (db *Database) IncrBruteAttempt(
	ctx context.Context,
	ip string,
	kind BruteAttemptKind,
	timestamp time.Time,
	user, password, clientVersion string,
	after time.Time,
) (*BruteAttempt, error)

func (*Database) LastAbuseipdbReport

func (db *Database) LastAbuseipdbReport(ctx context.Context, ip string) (*AbuseipdbReport, bool, error)

func (*Database) Save

func (db *Database) Save(ctx context.Context, value any) error

func (*Database) ScanBruteAttempt

func (db *Database) ScanBruteAttempt(ctx context.Context, updatedAfter time.Time, f func(attempt *BruteAttempt, geo *IpGeo) bool) error

func (*Database) TakeIpGeo

func (db *Database) TakeIpGeo(ctx context.Context, ip string) (*IpGeo, bool, error)

type IpGeo

type IpGeo struct {
	Ip        string `gorm:"primaryKey; size:39"`
	Location  string `gorm:"size:255"`
	Latitude  float64
	Longitude float64

	CreatedAt time.Time `gorm:"<-:create"`
	UpdatedAt time.Time
}

func (*IpGeo) BeforeSave

func (m *IpGeo) BeforeSave(_ *gorm.DB) error

func (*IpGeo) FillInfo

func (m *IpGeo) FillInfo(r *ipgeo.Info) *IpGeo

func (*IpGeo) Info

func (m *IpGeo) Info() *ipgeo.Info

Jump to

Keyboard shortcuts

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