fetch-all 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # Download all current v2 directory status documents, then download
  3. # the descriptors and extra info documents.
  4. # Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining a copy
  7. # of this software and associated documentation files (the "Software"), to deal
  8. # in the Software without restriction, including without limitation the rights
  9. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. # copies of the Software, and to permit persons to whom the Software is
  11. # furnished to do so, subject to the following conditions:
  12. #
  13. # The above copyright notice and this permission notice shall be included in
  14. # all copies or substantial portions of the Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. # SOFTWARE.
  23. TZ=UTC
  24. export TZ
  25. DIRSERVERS=""
  26. DIRSERVERS="$DIRSERVERS 86.59.21.38:80" # tor26
  27. DIRSERVERS="$DIRSERVERS 128.31.0.34:9031" # moria1
  28. DIRSERVERS="$DIRSERVERS 128.31.0.34:9032" # moria2
  29. #DIRSERVERS="$DIRSERVERS 140.247.60.64:80" # lefkada
  30. DIRSERVERS="$DIRSERVERS 194.109.206.212:80" # dizum
  31. DATEDIR=$(date "+%Y/%m/%d")
  32. TIME=$(date "+%Y%m%d-%H%M%S")
  33. . fetch-all-functions
  34. statuses=""
  35. for dirserver in $DIRSERVERS; do
  36. authorities=$(wget -q -O - http://$dirserver/tor/status/all | egrep '^fingerprint ' | awk '{print $2}')
  37. if [ "$authorities" == "" ]; then
  38. echo "Did not get a list of authorities from $dirserver, going to next" 2>&1
  39. continue
  40. fi
  41. dir="status/$DATEDIR"
  42. [ -d "$dir" ] || mkdir -p "$dir"
  43. authprefix="$dir/$TIME-"
  44. for fp in $authorities; do
  45. wget -q -O "$authprefix$fp" http://$dirserver/tor/status/fp/"$fp"
  46. bzip2 "$authprefix$fp"
  47. statuses="$statuses $authprefix$fp.bz2"
  48. done
  49. if [ "$statuses" == "" ]; then
  50. echo "Did not get any statuses from $dirserver, going to next" 2>&1
  51. continue
  52. else
  53. break
  54. fi
  55. done
  56. if [ "$statuses" = "" ]; then
  57. echo "No statuses available" 2>&1
  58. exit 1
  59. fi
  60. digests=$( for i in ` bzcat $statuses | awk '$1 == "r" {printf "%s===\n", $4}' | sort -u `; do
  61. echo $i | \
  62. base64-decode | \
  63. perl -e 'undef $/; $a=<>; print unpack("H\*", $a),"\n";';
  64. done )
  65. for digest in $digests; do
  66. fetch_digest "$digest" "server-descriptor"
  67. done