Skip to content

Commit

Permalink
Added function returning details for a request, updated referrer blac…
Browse files Browse the repository at this point in the history
…klist, updated dependencies.
  • Loading branch information
Kugelschieber committed Jan 13, 2025
1 parent 3ea4635 commit f82041a
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 6.19.4

* added function returning details for a request
* updated referrer blacklist
* updated dependencies

## 6.19.3

* added `Equal` to filter
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.24
github.com/oschwald/maxminddb-golang v1.13.1
github.com/stretchr/testify v1.10.0
golang.org/x/net v0.33.0
golang.org/x/net v0.34.0
)

require (
Expand All @@ -36,6 +36,6 @@ require (
github.com/shopspring/decimal v1.4.0 // indirect
go.opentelemetry.io/otel v1.33.0 // indirect
go.opentelemetry.io/otel/trace v1.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -316,6 +318,8 @@ golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
5 changes: 4 additions & 1 deletion pkg/tracker/referrer/hostname_blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var hostnameBlacklist = map[string]struct{}{
// custom
"temp-mail.org": {},

// https://github.com/matomo-org/referrer-spam-list/blob/master/spammers.txt (2025-01-02)
// https://github.com/matomo-org/referrer-spam-list/blob/master/spammers.txt (2025-01-13)
"0-0.fr": {},
"01casino-x.ru": {},
"033nachtvandeliteratuur.nl": {},
Expand Down Expand Up @@ -187,6 +187,7 @@ var hostnameBlacklist = map[string]struct{}{
"apteka-pharm.ru": {},
"apteka.info": {},
"arabic-poetry.com": {},
"arcarticle.online": {},
"arendadogovor.ru": {},
"arendakvartir.kz": {},
"arendovalka.xyz": {},
Expand Down Expand Up @@ -1236,6 +1237,7 @@ var hostnameBlacklist = map[string]struct{}{
"magicart.store": {},
"magicdiet.gq": {},
"magnetic-bracelets.ru": {},
"maigralr.site": {},
"mainhunter.com": {},
"makemoneyonline.com": {},
"makeprogress.ga": {},
Expand Down Expand Up @@ -2042,6 +2044,7 @@ var hostnameBlacklist = map[string]struct{}{
"ucban.xyz": {},
"ucoz.ru": {},
"ucsfstore.xyz": {},
"uctraffic.com": {},
"udav.net": {},
"ufolabs.net": {},
"uginekologa.com": {},
Expand Down
23 changes: 23 additions & 0 deletions pkg/tracker/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@ func (tracker *Tracker) ExtendSession(r *http.Request, clientID uint64, options
return false
}

// Accept runs the given request through the bot filters and returns the details if accepted.
// This function does not update the session, nor does it save the page view or request.
func (tracker *Tracker) Accept(r *http.Request, clientID uint64, options Options) *model.Session {
if tracker.stopped.Load() {
return nil
}

now := time.Now().UTC()
userAgent, ipAddress, ignoreReason := tracker.ignore(r)
options.validate(r)

if !options.Time.IsZero() {
now = options.Time
}

if ignoreReason == "" {
session, _, _, _ := tracker.getSession(pageView, clientID, r, now, userAgent, ipAddress, options)
return session
}

return nil
}

// Flush flushes all buffered data.
func (tracker *Tracker) Flush() {
tracker.stopWorker()
Expand Down
21 changes: 21 additions & 0 deletions pkg/tracker/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,27 @@ func TestTracker_ExtendSessionOverwriteTime(t *testing.T) {
assert.True(t, now.After(sessions[2].Time))
}

func TestTracker_Accept(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "https://example.com/foo/bar?utm_source=Source&utm_campaign=Campaign&utm_medium=Medium&utm_content=Content&utm_term=Term", nil)
req.Header.Add("User-Agent", userAgent)
req.Header.Set("Accept-Language", "fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5")
req.Header.Set("Referer", "https://google.com")
req.RemoteAddr = "81.2.69.142"
geoDB, _ := geodb.NewGeoDB("", "", "")
assert.NoError(t, geoDB.UpdateFromFile("../../test/GeoIP2-City-Test.mmdb"))
client := db.NewClientMock()
tracker := NewTracker(Config{
Store: client,
GeoDB: geoDB,
})
s := tracker.Accept(req, 123, Options{})
assert.NotNil(t, s)
assert.Equal(t, "example.com", s.Hostname)
assert.Equal(t, "fr", s.Language)
assert.Equal(t, "Linux", s.OS)
assert.Equal(t, "gb", s.CountryCode)
}

func TestTracker_Flush(t *testing.T) {
db.CleanupDB(t, dbClient)
tracker := NewTracker(Config{
Expand Down
12 changes: 12 additions & 0 deletions vendor/golang.org/x/sys/unix/syscall_dragonfly.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions vendor/golang.org/x/sys/windows/dll_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ go.opentelemetry.io/otel/internal/attribute
## explicit; go 1.22.0
go.opentelemetry.io/otel/trace
go.opentelemetry.io/otel/trace/embedded
# golang.org/x/net v0.33.0
# golang.org/x/net v0.34.0
## explicit; go 1.18
golang.org/x/net/html
golang.org/x/net/html/atom
# golang.org/x/sys v0.28.0
# golang.org/x/sys v0.29.0
## explicit; go 1.18
golang.org/x/sys/cpu
golang.org/x/sys/unix
Expand Down

0 comments on commit f82041a

Please sign in to comment.