jshn-helper.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. ifaceStat() {
  3. . /usr/share/libubox/jshn.sh
  4. local _IFACE=$1
  5. local _STATUS="$(runSuid ubus call network.interface.$_IFACE status 2>/dev/null)"
  6. if [[ "$_STATUS" != "" ]]; then
  7. local State=""
  8. local Iface=""
  9. local Uptime=""
  10. local IP4=""
  11. local IP6=""
  12. local Subnet4=""
  13. local Subnet6=""
  14. local Gateway4=""
  15. local Gateway6=""
  16. local DNS=""
  17. local Protocol=""
  18. json_load "${_STATUS:-{}}"
  19. json_get_var State up
  20. json_get_var Uptime uptime
  21. json_get_var Iface l3_device
  22. json_get_var Protocol proto
  23. if json_get_type Status ipv4_address && [ "$Status" = array ]; then
  24. json_select ipv4_address
  25. json_get_type Status 1
  26. if [ "$Status" = object ]; then
  27. json_select 1
  28. json_get_var IP4 address
  29. json_get_var Subnet4 mask
  30. [ "$IP4" != "" ] && [ "$Subnet4" != "" ] && IP4="$IP4,$Subnet4"
  31. fi
  32. fi
  33. json_select
  34. if json_get_type Status ipv6_address && [ "$Status" = array ]; then
  35. json_select ipv6_address
  36. json_get_type Status 1
  37. if [ "$Status" = object ]; then
  38. json_select 1
  39. json_get_var IP6 address
  40. json_get_var Subnet6 mask
  41. [ "$IP6" != "" ] && [ "$Subnet6" != "" ] && IP6="$IP6,$Subnet6"
  42. fi
  43. fi
  44. json_select
  45. if json_get_type Status route && [ "$Status" = array ]; then
  46. json_select route
  47. local Index="1"
  48. while json_get_type Status $Index && [ "$Status" = object ]; do
  49. json_select "$((Index++))"
  50. json_get_var Status target
  51. case "$Status" in
  52. 0.0.0.0)
  53. json_get_var Gateway4 nexthop;;
  54. ::)
  55. json_get_var Gateway6 nexthop;;
  56. esac
  57. json_select ".."
  58. done
  59. fi
  60. json_select
  61. if json_get_type Status dns_server && [ "$Status" = array ]; then
  62. json_select dns_server
  63. local Index="1"
  64. while json_get_type Status $Index && [ "$Status" = string ]; do
  65. json_get_var Status "$((Index++))"
  66. DNS="${DNS:+$DNS }$Status"
  67. done
  68. fi
  69. if [ "$State" == "1" ]; then
  70. [ "$IP4" != "" ] && _echo "$IP4,$Gateway4,"
  71. [ "$IP6" != "" ] && _echo "$IP6,$Gateway6,"
  72. _echo "$Iface,$Uptime,"
  73. [ "$DNS" != "" ] && _echo "$DNS"
  74. fi
  75. fi
  76. # json_get_type _IFSTAT ipv4_address
  77. # if json_get_type _IFSTAT ipv4_address && [[ "$_IFSTAT" == 'array' ]]; then
  78. # json_select ipv4_address
  79. # json_get_type _IFSTAT 1
  80. # if [[ "$_IFSTAT" == 'object' ]]; then
  81. # json_select 1
  82. # json_get_var IP4 address
  83. # json_get_var Subnet4 mask
  84. # [[ "$IP4" != '' ]] && [[ "$Subnet4" != '' ]] && IP4="$IP4/$Subnet4"
  85. # fi
  86. # fi
  87. # logThis $IP4
  88. }