Files
web-core-fr-gp/bots/findBots.sh
T

38 lines
775 B
Bash
Raw Normal View History

2015-06-28 18:22:40 -04:00
#!/bin/bash
#
# Generates a Go map containing all bots that have accessed Write.as
#
cat /var/log/$1 | grep -i bot | awk -F\" '{print $4}' | sort | uniq > bots.txt
rm bots.go
cat > bots.go << EOM
2015-07-07 02:35:17 -04:00
// This package helps the backend determine which clients are bots or crawlers.
// In Write.as, this is used to prevent certain things when viewing posts, like
// incrementing the view count.
2015-06-28 18:22:40 -04:00
package bots
var bots = map[string]bool {
EOM
while read b; do
if [ -n "$b" ]; then
echo " \"$b\": true," >> bots.go
fi
done <bots.txt
cat >> bots.go << EOM
};
2015-07-07 02:35:17 -04:00
// IsBot returns whether or not the provided User-Agent string is a known bot
// or crawler.
2015-06-28 18:22:40 -04:00
func IsBot(ua string) bool {
if _, ok := bots[ua]; ok {
return true
}
return false
}
EOM