Add bots component

Include generation script for extracting bots from server logs
This commit is contained in:
Matt Baer
2015-06-28 18:22:40 -04:00
parent 1b278fa92b
commit d2454e8900
2 changed files with 66 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
#!/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
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
};
func IsBot(ua string) bool {
if _, ok := bots[ua]; ok {
return true
}
return false
}
EOM