You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.3 KiB

  1. #!/bin/sh
  2. . /lib/functions.sh
  3. SCRIPTS_DIR="/usr/libexec/atlas-probe-scripts"
  4. TMP_BASE_DIR="/tmp/ripe_atlas_probe"
  5. PUB_KEY_FILE="$SCRIPTS_DIR/etc/probe_key.pub"
  6. PRIV_KEY_FILE="$SCRIPTS_DIR/etc/probe_key"
  7. PROBE_ID_FILE="$TMP_BASE_DIR/status/reg_init_reply.txt"
  8. get_atlas_public_key() {
  9. local pub_key
  10. if [ -f "$PUB_KEY_FILE" ]; then
  11. pub_key=$(cat "$PUB_KEY_FILE")
  12. fi
  13. echo "{"
  14. echo \"pub-key\":\"$pub_key\"
  15. echo "}"
  16. }
  17. get_atlas_probeid() {
  18. local probe_id
  19. if /etc/init.d/atlas probeid 2>/dev/null; then
  20. probe_id="$(awk '/PROBE_ID/ {print $2}' "$PROBE_ID_FILE")"
  21. fi
  22. echo "{"
  23. echo \"probe-id\":\"$probe_id\"
  24. echo "}"
  25. }
  26. get_reg_info() {
  27. local pub_ip
  28. local asn
  29. local asn_org
  30. if [ -z "$pub_ip" ]; then
  31. pub_ip="$(dig -4 TXT +short o-o.myaddr.l.google.com @ns1.google.com|tr -d '"')"
  32. fi
  33. echo "{"
  34. echo \"public-ipv4\":\"$pub_ip\"
  35. echo "}"
  36. }
  37. get_status() {
  38. local status
  39. status="$(/etc/init.d/atlas status)"
  40. echo "{"
  41. echo \"status\":\"$status\"
  42. echo "}"
  43. }
  44. case "$1" in
  45. list)
  46. echo '{'
  47. echo ' "pub-key": {},'
  48. echo ' "probe-id": {},'
  49. echo ' "reg-info": {}'
  50. echo ' "status": {}'
  51. echo '}'
  52. ;;
  53. call)
  54. case "$2" in
  55. pub-key)
  56. get_atlas_public_key
  57. ;;
  58. probe-id)
  59. get_atlas_probeid
  60. ;;
  61. reg-info)
  62. get_reg_info
  63. ;;
  64. get-status)
  65. get_status
  66. ;;
  67. esac
  68. ;;
  69. esac