sd 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2005, 2006, 2007, 2008 Peter Palfrader <peter@palfrader.org>
  4. # Copyright (c) 2008, 2009 Jacob Appelbaum <jacob@appelbaum.net>
  5. #
  6. # Permission is hereby granted, free of charge, to any person obtaining
  7. # a copy of this software and associated documentation files (the
  8. # "Software"), to deal in the Software without restriction, including
  9. # without limitation the rights to use, copy, modify, merge, publish,
  10. # distribute, sublicense, and/or sell copies of the Software, and to
  11. # permit persons to whom the Software is furnished to do so, subject to
  12. # the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be
  15. # included in all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. #
  25. # This small script fetches information about a server when given a nickname.
  26. # It currently uses the v2 dir information and not the v3 consensus by default.
  27. # It requires wget, perl, awk to function properly. This is based on a zsh
  28. # dotfile from weasel and adapted to be a small bash utility.
  29. #
  30. # Feel free to set any authority you desire, we're using weasel's by default
  31. # You could also try the v3 directory infomation in weasel's dir authority:
  32. # http://tor.noreply.org/tor/status-vote/current/consensus
  33. #
  34. # Users can select between the two
  35. v3authority="http://tor.noreply.org/tor/status-vote/current/consensus";
  36. v2authority="http://tor.noreply.org:80/tor/status/authority";
  37. authority=$v2authority;
  38. function usage {
  39. echo "Usage: $0 [-2|-3] nodenickname";
  40. }
  41. if [ -z "$1" ];
  42. then
  43. usage;
  44. exit;
  45. fi
  46. # Are we switching between v2 or v3?
  47. if [ "$1" == "-2" -o "$1" == "-3" ];
  48. then
  49. if [ "$1" == "-2" -a -n "$2" ];
  50. then
  51. authority=$v2authority;
  52. nickname="$2";
  53. elif [ "$1" == "-3" -a -n "$2" ];
  54. then
  55. authority=$v3authority;
  56. nickname="$2";
  57. else
  58. usage;
  59. exit;
  60. fi
  61. else
  62. nickname="$1";
  63. fi
  64. # Fetch it and decode the fingerprint
  65. fp=`wget -q -O - $authority | \
  66. awk '$1 == "r" && $2 == "'$nickname'" {printf "%s===", $3}' | \
  67. perl -MMIME::Base64 -e "print unpack(\"H*\", decode_base64(<>)),\"\n\"";`
  68. # If we don't have a fingerprint, we don't have a match
  69. if [ "$fp" != "" ];
  70. then
  71. wget -q -O - http://tor.noreply.org:80/tor/server/fp/$fp;
  72. exit $?;
  73. else
  74. echo "It appears the nickname is not currently known by the directory" \
  75. "authority."
  76. exit 1;
  77. fi