ff_fastd_conn 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. #
  3. # Maximilian Wilhelm <max@rfc2324.org>
  4. # -- Mon 31 Aug 2015 08:55:27 AM CEST
  5. #
  6. if [ $# -lt 1 ]; then
  7. echo "Usage: $(basename $0) [ -c ] fastd_instance | -a" >&2
  8. exit 1
  9. fi
  10. fastd_ciphers () {
  11. socket_path=$(grep "status socket" "/etc/fastd/${1}/fastd.conf" | grep -o '/[0-9a-z/_.-]\+')
  12. echo -n "$1: "
  13. socat - "UNIX-CONNECT:${socket_path}" | jq '.peers[] | select (.connection) | .connection | .method ' | sort | uniq -c
  14. }
  15. fastd_con () {
  16. socket_path=$(grep "status socket" "/etc/fastd/${1}/fastd.conf" | grep -o '/[0-9a-z/_.-]\+')
  17. echo -n "$1: "
  18. socat - "UNIX-CONNECT:${socket_path}" | jq '.peers[] | select( .connection ) | .name' | wc -l
  19. }
  20. mode="count"
  21. if [ "${1}" = "-c" ]; then
  22. mode="ciphers"
  23. shift
  24. fi
  25. instances="${@}"
  26. if [ "${1}" = "-a" ]; then
  27. instances="all"
  28. fi
  29. # Verify existance of fastd instance
  30. if [ "$instances" != "all" -a ! -d "/etc/fastd/${instances}" ]; then
  31. echo "Invalid fastd instance \"$instances\"." >&2
  32. exit 1
  33. # Figure out all fastd instances
  34. elif [ "$instances" = "all" ]; then
  35. instances=$(find /etc/fastd -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | sort)
  36. if [ ! "${instances}" ]; then
  37. echo "Did not find any configured instances in /etc/fastd." >&2
  38. exit 1
  39. fi
  40. fi
  41. for inst in ${instances}; do
  42. if [ "${mode}" = "count" ]; then
  43. fastd_con ${inst}
  44. elif [ "$mode" = "ciphers" ]; then
  45. fastd_ciphers ${inst}
  46. fi
  47. done