olsrinfo 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. . /usr/share/libubox/jshn.sh
  3. . /lib/functions.sh
  4. HOSTSFILE="-1"
  5. find_hosts_config() {
  6. local cfg="$1"
  7. config_get library "$cfg" library
  8. if [ "$library" != "olsrd_nameservice" ]; then
  9. return 1
  10. fi
  11. config_get hosts_file "$cfg" hosts_file
  12. HOSTSFILE=$hosts_file
  13. }
  14. load_hosts() {
  15. config_load olsrd
  16. config_foreach find_hosts_config LoadPlugin
  17. local hosts4=$(cat $HOSTSFILE)
  18. HOSTSFILE=""
  19. config_load olsrd6
  20. config_foreach find_hosts_config LoadPlugin
  21. if [ -f "$HOSTSFILE" ]; then
  22. local hosts6=$(cat "$HOSTSFILE")
  23. else
  24. local hosts6=""
  25. fi
  26. local hosts="$hosts4$hosts6"
  27. json_init
  28. json_add_string hosts "$hosts"
  29. json_dump
  30. }
  31. case "$1" in
  32. list)
  33. json_init
  34. json_add_object "getjsondata"
  35. json_add_string 'otable' 'String'
  36. json_add_int 'v4_port' 'Integer'
  37. json_add_int 'v6_port' 'Integer'
  38. json_close_object
  39. json_add_object "hasipip"
  40. json_close_object
  41. json_add_object "hosts"
  42. json_close_object
  43. json_dump
  44. ;;
  45. call)
  46. case "$2" in
  47. getjsondata)
  48. json_init
  49. json_load "$(cat)"
  50. json_get_var otable otable
  51. json_get_var v4_port v4_port
  52. json_get_var v6_port v6_port
  53. jsonreq4=$(echo "/${otable}" | nc 127.0.0.1 "${v4_port}" | sed -n '/^[}{ ]/p' 2>/dev/null)
  54. jsonreq6=$(echo "/${otable}" | nc ::1 "${v6_port}" | sed -n '/^[}{ ]/p' 2>/dev/null)
  55. json_init
  56. json_add_string "jsonreq4" "$jsonreq4"
  57. json_add_string "jsonreq6" "$jsonreq6"
  58. json_dump
  59. ;;
  60. hasipip)
  61. result=$(ls /etc/modules.d/ | grep -E "[0-9]*-ipip")
  62. json_init
  63. json_add_string "result" "$result"
  64. json_dump
  65. ;;
  66. hosts)
  67. load_hosts
  68. ;;
  69. esac
  70. ;;
  71. esac