Add our own botlist for user-agent matching. Closes #51
This commit is contained in:
parent
46b3922e1d
commit
ab21706d73
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/mssola/user_agent"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/gabek/owncast/config"
|
"github.com/gabek/owncast/config"
|
||||||
@ -38,9 +37,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ua := user_agent.New(r.UserAgent())
|
if utils.IsUserAgentABot(r.UserAgent()) && isIndexRequest {
|
||||||
|
|
||||||
if ua != nil && ua.Bot() && isIndexRequest {
|
|
||||||
handleScraperMetadataPage(w, r)
|
handleScraperMetadataPage(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mssola/user_agent"
|
||||||
)
|
)
|
||||||
|
|
||||||
//GetTemporaryPipePath gets the temporary path for the streampipe.flv file
|
//GetTemporaryPipePath gets the temporary path for the streampipe.flv file
|
||||||
@ -41,3 +43,24 @@ func Copy(source, destination string) error {
|
|||||||
|
|
||||||
return ioutil.WriteFile(destination, input, 0644)
|
return ioutil.WriteFile(destination, input, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsUserAgentABot returns if a web client user-agent is seen as a bot
|
||||||
|
func IsUserAgentABot(userAgent string) bool {
|
||||||
|
if userAgent == "" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
botStrings := []string{
|
||||||
|
"mastodon",
|
||||||
|
"pleroma",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, botString := range botStrings {
|
||||||
|
if strings.Contains(strings.ToLower(userAgent), botString) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ua := user_agent.New(userAgent)
|
||||||
|
return ua.Bot()
|
||||||
|
}
|
||||||
|
16
utils/utils_test.go
Normal file
16
utils/utils_test.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestUserAgent(t *testing.T) {
|
||||||
|
testAgents := []string{
|
||||||
|
"Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site; https://pleroma.site info@pleroma.site",
|
||||||
|
"Mastodon 1.2.3 Bot",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, agent := range testAgents {
|
||||||
|
if !IsUserAgentABot(agent) {
|
||||||
|
t.Error("Incorrect parsing of useragent", agent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user