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.

69 lines
1.2 KiB

  1. #!/bin/sh
  2. . /lib/functions.sh
  3. get_onion_hostname() {
  4. local name="$1"
  5. config_get hs_dir common HSDir
  6. if [ -f "$hs_dir/$name/hostname" ]; then
  7. cat "$hs_dir/$name/hostname"
  8. fi
  9. }
  10. get_port_list() {
  11. local config="$1"
  12. config_get ports "$config" PublicLocalPort
  13. tmp="$(echo $ports |sed "s| |','|g")"
  14. echo -ne "['$tmp']"
  15. }
  16. parse_hs_conf() {
  17. local name description public_port local_port enable_bool public_local_port ipv4
  18. local config="$1"
  19. local custom="$2"
  20. config_get name "$config" Name
  21. config_get description "$config" Description
  22. config_get_bool enable_hs "$config" Enabled 0
  23. config_get ipv4 "$config" IPv4
  24. hostname="$(get_onion_hostname $name)"
  25. port_list="$(get_port_list $config)"
  26. echo "{"
  27. echo \"name\":\"$name\",
  28. echo \"description\":\"$description\",
  29. echo \"enabled\":\"$enable_hs\",
  30. echo \"ipv4\":\"$ipv4\",
  31. echo \"hostname\":\"$hostname\",
  32. echo \"ports\":$port_list
  33. echo "},"
  34. }
  35. get_tor_hs_list() {
  36. config_load tor-hs
  37. echo "{"
  38. echo '"hs-list":['
  39. config_foreach parse_hs_conf hidden-service
  40. echo "]"
  41. echo "}"
  42. }
  43. case "$1" in
  44. list)
  45. echo '{ "list-hs": { } }'
  46. ;;
  47. call)
  48. case "$2" in
  49. list-hs)
  50. # return json object
  51. get_tor_hs_list
  52. ;;
  53. esac
  54. ;;
  55. esac