Core components of the web application. https://write.as
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

41 rinda
906 B

  1. #!/bin/bash
  2. #
  3. # Generates a Go map containing all bots that have accessed Write.as from the
  4. # application logs stored in /var/log/
  5. #
  6. # usage: findBots.sh application.log
  7. #
  8. cat /var/log/$1 | grep -i 'bot\|spider\|crawl\|scraper\|indexer\|voltron' | awk -F\" '{print $4}' | sort | uniq > bots.txt
  9. rm bots.go
  10. cat > bots.go << EOM
  11. // This package helps the backend determine which clients are bots or crawlers.
  12. // In Write.as, this is used to prevent certain things when viewing posts, like
  13. // incrementing the view count.
  14. package bots
  15. var bots = map[string]bool {
  16. EOM
  17. while read b; do
  18. if [ -n "$b" ]; then
  19. echo " \"$b\": true," >> bots.go
  20. fi
  21. done <bots.txt
  22. cat >> bots.go << EOM
  23. };
  24. // IsBot returns whether or not the provided User-Agent string is a known bot
  25. // or crawler.
  26. func IsBot(ua string) bool {
  27. if _, ok := bots[ua]; ok {
  28. return true
  29. }
  30. return false
  31. }
  32. EOM