diff --git a/go.mod b/go.mod index c911a7242f9b1448b4da1dc55caca9202efe843d..f5e5452565eb8b9a475742b0d4b2836fa7c43a41 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/csrf v1.7.1 github.com/gorilla/mux v1.8.0 github.com/gorilla/securecookie v1.1.1 - github.com/mssola/user_agent v0.5.3 + github.com/mssola/user_agent v0.6.0 github.com/oschwald/maxminddb-golang v1.10.0 github.com/prometheus/client_golang v1.12.2 github.com/rs/cors v1.8.3 diff --git a/go.sum b/go.sum index e7a38e635313894b10791c3b632f657b626d5716..36944d1aed83b278eba21447de57545f443d9f5b 100644 --- a/go.sum +++ b/go.sum @@ -637,6 +637,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwd github.com/mreiferson/go-httpclient v0.0.0-20160630210159-31f0106b4474/go.mod h1:OQA4XLvDbMgS8P0CevmM4m9Q3Jq4phKUzcocxuGJ5m8= github.com/mssola/user_agent v0.5.3 h1:lBRPML9mdFuIZgI2cmlQ+atbpJdLdeVl2IDodjBR578= github.com/mssola/user_agent v0.5.3/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw= +github.com/mssola/user_agent v0.6.0 h1:uwPR4rtWlCHRFyyP9u2KOV0u8iQXmS7Z7feTrstQwk4= +github.com/mssola/user_agent v0.6.0/go.mod h1:TTPno8LPY3wAIEKRpAtkdMT0f8SE24pLRGPahjCH4uw= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-proto-validators v0.0.0-20180403085117-0950a7990007/go.mod h1:m2XC9Qq0AlmmVksL6FktJCdTYyLk7V3fKyp0sl1yWQo= diff --git a/vendor/github.com/mssola/user_agent/.travis.yml b/vendor/github.com/mssola/user_agent/.travis.yml deleted file mode 100644 index 3bc82c0ebb7ed33a414d4050505e455e7880810f..0000000000000000000000000000000000000000 --- a/vendor/github.com/mssola/user_agent/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: go - -git: - depth: false - -arch: - - amd64 - - ppc64le - -go: - - 1.4.x - - 1.5.x - - 1.6.x - - 1.7.x - - 1.8.x - - 1.9.x - - 1.10.x - - 1.11.x - - 1.12.x - - 1.13.x - - 1.14.x - - 1.x - - tip -matrix: - allow_failures: - - go: tip - exclude: - - go: 1.4.x - arch: ppc64le - -before_install: - - chmod +x ./ci/install.sh && ./ci/install.sh - -script: - - make ci diff --git a/vendor/github.com/mssola/user_agent/CHANGELOG.md b/vendor/github.com/mssola/user_agent/CHANGELOG.md index 90730fe71fd9082ef490f4caefede1335549bc32..fa9509c42f793522931020f7932515345bf058a6 100644 --- a/vendor/github.com/mssola/user_agent/CHANGELOG.md +++ b/vendor/github.com/mssola/user_agent/CHANGELOG.md @@ -1,6 +1,15 @@ # Changelog -## Not yet released +## 0.6.0 + +- Added information on the model of mobile devices. See [746647ad73b5](https://github.com/mssola/user_agent/commit/746647ad73b5ad8648175bbd07319c0a8ac559c6). +- Added support for PhantomJS. See [6b5e6f6ebfa8](https://github.com/mssola/user_agent/commit/6b5e6f6ebfa87464ccdb42bac5448cbf46ce1ba1). + +## 0.5.4 + +- Add detection of Coc Coc Browser. See [897eb45aec23](https://github.com/mssola/user_agent/commit/897eb45aec2330e7566c48c9e54192aae84bd8e9). +- Add detection of Headless Chrome. See [897eb45aec23](https://github.com/mssola/user_agent/commit/897eb45aec2330e7566c48c9e54192aae84bd8e9). +- Add detection of iOS WebViews. See [897eb45aec23](https://github.com/mssola/user_agent/commit/897eb45aec2330e7566c48c9e54192aae84bd8e9). ## 0.5.3 diff --git a/vendor/github.com/mssola/user_agent/CONTRIBUTING.md b/vendor/github.com/mssola/user_agent/CONTRIBUTING.md index f982c3b88437b830957eef3d6c5d58a7e9455bc8..1c4b850575174f81c6969b55eedc4d5c89cf0b44 100644 --- a/vendor/github.com/mssola/user_agent/CONTRIBUTING.md +++ b/vendor/github.com/mssola/user_agent/CONTRIBUTING.md @@ -2,57 +2,21 @@ ## Check that your changes do not break anything -You can safely run the `ci` target locally: +You can safely run tests and the linting utilities with the default `make` target: ``` -$ make ci +$ make ``` -This will run all the make targets that will also be run on the CI, which are -described below. +Note that this target assumes that you have +[golangci-lint](https://github.com/golangci/golangci-lint) and +[git-valitation](https://github.com/vbatts/git-validation) already installed. If +that is not the case, first install them to get a proper execution of the +default `make` target. -### Running tests - -Call the `test` make target: - -```bash -$ make test -``` - -### Checking the style - -This project uses some standard tools in order to check the Go style. You can -run them by calling the `validate-go` make target: - -```bash -$ make validate-go -``` - -This target is included inside of the `validate` one. - -### Git validation - -In order to ensure that the git log is as maintainable as possible, the -[git-validation](https://github.com/vbatts/git-validation) tool is used. You can -install this tool by running: - -```bash -$ go get -u github.com/vbatts/git-validation -``` - -If you already have this tool installed, then simply perform: - -```bash -$ make git-validation -``` - -One of the things you will notice is that it will check that the commits have a -sign off, that is, that you have used the `-s` flag when calling `git -commit`. This is a lightweight way for contributors to certify that they wrote -or otherwise have the right to submit the code they are contributing into this -project. - -This target is included inside of the `validate` one. +Otherwise, if you want to be more specific, refer to the `Makefile` to check +which target fits your needs. That being said, the default target is usually +what you want. ## Issue reporting diff --git a/vendor/github.com/mssola/user_agent/LICENSE b/vendor/github.com/mssola/user_agent/LICENSE index b07e93363b947959087698844bf28ab6dd136cd8..b18c275bc9abce77e0fc28312c75d74bce2ece46 100644 --- a/vendor/github.com/mssola/user_agent/LICENSE +++ b/vendor/github.com/mssola/user_agent/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012-2021 Miquel Sabaté Solà +Copyright (c) 2012-2023 Miquel Sabaté Solà Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/vendor/github.com/mssola/user_agent/Makefile b/vendor/github.com/mssola/user_agent/Makefile index 89c5f4a18a2d9c85c8518c49496a1d95dded68a8..d1526f176bddc8f75e6ec786b751319083463668 100644 --- a/vendor/github.com/mssola/user_agent/Makefile +++ b/vendor/github.com/mssola/user_agent/Makefile @@ -2,12 +2,7 @@ GO ?= go GO_SRC = $(shell find . -name \*.go) .DEFAULT: build -build: $(GO_SRC) - @$(GO) build - -# -# Unit & integration tests. -# +all: test lint .PHONY: test test: @@ -17,37 +12,14 @@ test: bench: @$(GO) test -bench=. -# -# Validation tools. -# +.PHONY: lint +lint: git-validation cilint -EPOCH_COMMIT ?= 2046da2a89bd +EPOCH_COMMIT ?= 834b6d4d9e84 .PHONY: git-validation git-validation: -ifeq (, $(shell which git-validation 2> /dev/null)) - @echo "You don't have 'git-validation' installed, consider installing it (see the CONTRIBUTING.md file)." -else - @git-validation -q -range $(EPOCH_COMMIT)..HEAD -travis-pr-only=false -endif - -.PHONY: validate-go -validate-go: - @which gofmt >/dev/null 2>/dev/null || (echo "ERROR: gofmt not found." && false) - @test -z "$$(gofmt -s -l . | grep -vE '^vendor/' | tee /dev/stderr)" - @chmod +x ci/lint.sh - @./ci/lint.sh -# Go 1.4.x does not have go vet, so there is no point on trying. -ifneq ("$(TRAVIS_GO_VERSION)","1.4.x") - @go doc cmd/vet >/dev/null 2>/dev/null || (echo "ERROR: go vet not found." && false) - @test -z "$$(go vet . | grep -v vendor | tee /dev/stderr)" -endif - -.PHONY: validate -validate: git-validation validate-go - -# -# Travis-CI -# + @git-validation -v -D -range $(EPOCH_COMMIT)..HEAD -.PHONY: ci -ci: build validate test +.PHONY: cilint +cilint: + @golangci-lint run diff --git a/vendor/github.com/mssola/user_agent/README.md b/vendor/github.com/mssola/user_agent/README.md index 6cceddec82174a375f544b47619e9487e1332755..34873ebb629af0f852ae95f2a50fbf5396dc0327 100644 --- a/vendor/github.com/mssola/user_agent/README.md +++ b/vendor/github.com/mssola/user_agent/README.md @@ -1,7 +1,6 @@ - <p align="center"> - <a href="https://travis-ci.org/mssola/user_agent" title="Travis CI status for the master branch"><img src="https://travis-ci.org/mssola/user_agent.svg?branch=master" alt="Build Status for master branch" /></a> - <a href="http://godoc.org/github.com/mssola/user_agent" title="godoc.org page"><img src="https://godoc.org/github.com/mssola/user_agent?status.png" alt="godoc.org page" /></a> + <a href="https://github.com/mssola/user_agent/actions/workflows/ci.yml" title="Travis CI status for the default branch"><img src="https://github.com/mssola/user_agent/actions/workflows/ci.yml/badge.svg" alt="Build Status for the default branch" /></a> + <a href="https://pkg.go.dev/github.com/mssola/user_agent" title="go.dev page"><img src="https://pkg.go.dev/badge/github.com/mssola/user_agent" alt="go.dev page" /></a> <a href="https://en.wikipedia.org/wiki/MIT_License" rel="nofollow"><img alt="MIT" src="https://img.shields.io/badge/license-MIT-blue.svg" style="max-width:100%;"></a> </p> @@ -22,22 +21,23 @@ func main() { // The "New" function will create a new UserAgent object and it will parse // the given string. If you need to parse more strings, you can re-use // this object and call: ua.Parse("another string") - ua := user_agent.New("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11") + ua := user_agent.New("Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1") - fmt.Printf("%v\n", ua.Mobile()) // => false + fmt.Printf("%v\n", ua.Mobile()) // => true fmt.Printf("%v\n", ua.Bot()) // => false fmt.Printf("%v\n", ua.Mozilla()) // => "5.0" + fmt.Printf("%v\n", ua.Model()) // => "Nexus One" - fmt.Printf("%v\n", ua.Platform()) // => "X11" - fmt.Printf("%v\n", ua.OS()) // => "Linux x86_64" + fmt.Printf("%v\n", ua.Platform()) // => "Linux" + fmt.Printf("%v\n", ua.OS()) // => "Android 2.3.7" name, version := ua.Engine() fmt.Printf("%v\n", name) // => "AppleWebKit" - fmt.Printf("%v\n", version) // => "537.11" + fmt.Printf("%v\n", version) // => "533.1" name, version = ua.Browser() - fmt.Printf("%v\n", name) // => "Chrome" - fmt.Printf("%v\n", version) // => "23.0.1271.97" + fmt.Printf("%v\n", name) // => "Android" + fmt.Printf("%v\n", version) // => "4.0" // Let's see an example with a bot. @@ -52,7 +52,7 @@ func main() { ``` If you want to read the full API documentation simply check -[godoc](http://godoc.org/github.com/mssola/user_agent). +[godoc](https://pkg.go.dev/github.com/mssola/user_agent). ## Installation @@ -72,7 +72,7 @@ Read the [CHANGELOG.md](./CHANGELOG.md) file. ## License ``` -Copyright (c) 2012-2021 Miquel Sabaté Solà +Copyright (c) 2012-2023 Miquel Sabaté Solà Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/vendor/github.com/mssola/user_agent/bot.go b/vendor/github.com/mssola/user_agent/bot.go index 9a79076c6473b0508ee6d40b6cba4dddb4af373b..4f2afd541711b6e2be82e1625676018482281549 100644 --- a/vendor/github.com/mssola/user_agent/bot.go +++ b/vendor/github.com/mssola/user_agent/bot.go @@ -1,4 +1,4 @@ -// Copyright (C) 2014-2021 Miquel Sabaté Solà <mikisabate@gmail.com> +// Copyright (C) 2014-2023 Miquel Sabaté Solà <mikisabate@gmail.com> // This file is licensed under the MIT license. // See the LICENSE file. @@ -9,7 +9,7 @@ import ( "strings" ) -var botFromSiteRegexp = regexp.MustCompile("http[s]?://.+\\.\\w+") +var botFromSiteRegexp = regexp.MustCompile(`http[s]?://.+\.\w+`) // Get the name of the bot from the website that may be in the given comment. If // there is no website in the comment, then an empty string is returned. @@ -50,7 +50,7 @@ func (p *UserAgent) googleOrBingBot() bool { // (See https://support.google.com/webmasters/answer/1061943) // and Bing's mobile bot // (See https://www.bing.com/webmaster/help/which-crawlers-does-bing-use-8c184ec0) - if strings.Index(p.ua, "Google") != -1 || strings.Index(p.ua, "bingbot") != -1 { + if strings.Contains(p.ua, "Google") || strings.Contains(p.ua, "bingbot") { p.platform = "" p.undecided = true } @@ -63,10 +63,10 @@ func (p *UserAgent) iMessagePreview() bool { // iMessage-Preview doesn't advertise itself. We have a to rely on a hack // to detect it: it impersonates both facebook and twitter bots. // See https://medium.com/@siggi/apples-imessage-impersonates-twitter-facebook-bots-when-scraping-cef85b2cbb7d - if strings.Index(p.ua, "facebookexternalhit") == -1 { + if !strings.Contains(p.ua, "facebookexternalhit") { return false } - if strings.Index(p.ua, "Twitterbot") == -1 { + if !strings.Contains(p.ua, "Twitterbot") { return false } p.bot = true diff --git a/vendor/github.com/mssola/user_agent/browser.go b/vendor/github.com/mssola/user_agent/browser.go index a31815dd0c90f6cbaf58d1fe5461b086fc9226c1..55825d19e0b08e88dff5c65635ded415749d14ba 100644 --- a/vendor/github.com/mssola/user_agent/browser.go +++ b/vendor/github.com/mssola/user_agent/browser.go @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com> +// Copyright (C) 2012-2023 Miquel Sabaté Solà <mikisabate@gmail.com> // This file is licensed under the MIT license. // See the LICENSE file. @@ -73,7 +73,7 @@ func (p *UserAgent) detectBrowser(sections []section) { p.browser.Engine = "EdgeHTML" p.browser.EngineVersion = "" case "Edg": - if p.undecided != true { + if !p.undecided { p.browser.Name = "Edge" p.browser.Version = sections[slen-1].version p.browser.Engine = "AppleWebKit" @@ -82,22 +82,38 @@ func (p *UserAgent) detectBrowser(sections []section) { case "OPR": p.browser.Name = "Opera" p.browser.Version = sections[slen-1].version + case "Mobile": + p.browser.Name = "Mobile App" + p.browser.Version = "" default: switch sections[slen-3].name { case "YaBrowser": p.browser.Name = "YaBrowser" p.browser.Version = sections[slen-3].version + case "coc_coc_browser": + p.browser.Name = "Coc Coc" + p.browser.Version = sections[slen-3].version default: switch sections[slen-2].name { case "Electron": p.browser.Name = "Electron" p.browser.Version = sections[slen-2].version + case "DuckDuckGo": + p.browser.Name = "DuckDuckGo" + p.browser.Version = sections[slen-2].version + case "PhantomJS": + p.browser.Name = "PhantomJS" + p.browser.Version = sections[slen-2].version default: switch sections[sectionIndex].name { case "Chrome", "CriOS": p.browser.Name = "Chrome" + case "HeadlessChrome": + p.browser.Name = "Headless Chrome" case "Chromium": p.browser.Name = "Chromium" + case "GSA": + p.browser.Name = "Google App" case "FxiOS": p.browser.Name = "Firefox" default: diff --git a/vendor/github.com/mssola/user_agent/model.go b/vendor/github.com/mssola/user_agent/model.go new file mode 100644 index 0000000000000000000000000000000000000000..f8e5c19f77cffd323854c75aee23b63543b150cf --- /dev/null +++ b/vendor/github.com/mssola/user_agent/model.go @@ -0,0 +1,35 @@ +package user_agent + +import ( + "strings" +) + +// detectModel some properties of the model from the given section. +func (p *UserAgent) detectModel(s section) { + if !p.mobile { + return + } + if p.platform == "iPhone" || p.platform == "iPad" { + p.model = p.platform + return + } + // Android model + if s.name == "Mozilla" && p.platform == "Linux" && len(s.comment) > 2 { + mostAndroidModel := s.comment[2] + if strings.Contains(mostAndroidModel, "Android") || strings.Contains(mostAndroidModel, "Linux") { + mostAndroidModel = s.comment[len(s.comment)-1] + } + tmp := strings.Split(mostAndroidModel, "Build") + if len(tmp) > 0 { + p.model = strings.Trim(tmp[0], " ") + return + } + } + // traverse all item + for _, v := range s.comment { + if strings.Contains(v, "Build") { + tmp := strings.Split(v, "Build") + p.model = strings.Trim(tmp[0], " ") + } + } +} diff --git a/vendor/github.com/mssola/user_agent/operating_systems.go b/vendor/github.com/mssola/user_agent/operating_systems.go index 123078ca6ba99b23f2eceaad15e4a729744d37ea..78630fa02880e9ab43bae2723d16807d290bce33 100644 --- a/vendor/github.com/mssola/user_agent/operating_systems.go +++ b/vendor/github.com/mssola/user_agent/operating_systems.go @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com> +// Copyright (C) 2012-2023 Miquel Sabaté Solà <mikisabate@gmail.com> // This file is licensed under the MIT license. // See the LICENSE file. @@ -310,6 +310,11 @@ func (p *UserAgent) Localization() string { return p.localization } +// Model returns a string containing the Phone Model like "Nexus 5X" +func (p *UserAgent) Model() string { + return p.model +} + // Return OS name and version from a slice of strings created from the full name of the OS. func osName(osSplit []string) (name, version string) { if len(osSplit) == 1 { diff --git a/vendor/github.com/mssola/user_agent/user_agent.go b/vendor/github.com/mssola/user_agent/user_agent.go index f96d3646868313124c160539e4660ea6bc3cdbc7..02619ed55e531340016c72970af72c5192450ac0 100644 --- a/vendor/github.com/mssola/user_agent/user_agent.go +++ b/vendor/github.com/mssola/user_agent/user_agent.go @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2021 Miquel Sabaté Solà <mikisabate@gmail.com> +// Copyright (C) 2012-2023 Miquel Sabaté Solà <mikisabate@gmail.com> // This file is licensed under the MIT license. // See the LICENSE file. @@ -26,6 +26,7 @@ type UserAgent struct { platform string os string localization string + model string browser Browser bot bool mobile bool @@ -103,7 +104,7 @@ func parseSection(ua string, index *int) (s section) { // Discards any trailing data within square brackets if *index < len(ua) && ua[*index] == '[' { *index++ - buffer = readUntil(ua, index, ']', true) + _ = readUntil(ua, index, ']', true) *index++ } return s @@ -116,6 +117,7 @@ func (p *UserAgent) initialize() { p.platform = "" p.os = "" p.localization = "" + p.model = "" p.browser.Engine = "" p.browser.EngineVersion = "" p.browser.Name = "" @@ -158,6 +160,7 @@ func (p *UserAgent) Parse(ua string) { p.detectBrowser(sections) p.detectOS(sections[0]) + p.detectModel(sections[0]) if p.undecided { p.checkBot(sections) diff --git a/vendor/modules.txt b/vendor/modules.txt index 77695919cb5e4d3741fa3d6f68617e0a20f93573..c002437269e8065dbe650e406fa490712dae7ff4 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -218,7 +218,7 @@ github.com/mitchellh/mapstructure github.com/modern-go/concurrent # github.com/modern-go/reflect2 v1.0.2 github.com/modern-go/reflect2 -# github.com/mssola/user_agent v0.5.3 +# github.com/mssola/user_agent v0.6.0 ## explicit github.com/mssola/user_agent # github.com/olekukonko/tablewriter v0.0.5