[Mirror] The Firmware for FFBSee Community
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.

home 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/haserl
  2. <%
  3. echo -en "content-type: text/plain\r\n\r\n"
  4. . /lib/functions/network.sh
  5. addr() {
  6. local addr="$(ip -$1 address show dev $2 2> /dev/null | tr '/' ' '| awk '/inet/{ printf("%s ", $2); }')"
  7. echo "${addr:--}"
  8. }
  9. default_gw() {
  10. local prefix
  11. if [ $1 -eq 6 ]; then
  12. prefix="::/0"
  13. else
  14. prefix="0/0"
  15. fi
  16. ip -$1 route list $prefix dev $2 2> /dev/null | awk '{print($3); exit(0)}'
  17. }
  18. memory_usage_percent() {
  19. meminfo=$(cat /proc/meminfo)
  20. free=$(echo "$meminfo" | awk /^MemFree:/'{print($2)}')
  21. buffers=$(echo "$meminfo" | awk /^Buffers:/'{print($2)}')
  22. cached=$(echo "$meminfo" | awk /^Cached:/'{print($2)}')
  23. total=$(echo "$meminfo" | awk /^MemTotal:/'{print($2)}')
  24. echo $free $buffers $cached $total | awk '{ printf("%u%%", 100 * (1 - ($1 + $2 + $3) / $4))}'
  25. }
  26. rootfs_usage_percent() {
  27. df / | awk '/^overlayfs/{print($5); exit;}'
  28. }
  29. print() {
  30. echo " option $1 '$2'"
  31. }
  32. printList() {
  33. for item in $2; do
  34. echo " list $1 '$item'"
  35. done
  36. }
  37. vpn_server() {
  38. local vpn=$(sockread /var/run/fastd.status < /dev/null 2> /dev/null | grep 'established' | sed 's/\(.*\)"name": "\([^"]*\)"\(.*\)established\(.*\)/\2/g')
  39. echo "${vpn:--}"
  40. }
  41. #get physical device by config section
  42. wan="" lan="" freifunk=""
  43. network_get_physdev wan 'wan'
  44. network_get_physdev lan 'lan'
  45. network_get_physdev freifunk 'freifunk'
  46. #include LEDE version
  47. . /etc/openwrt_release
  48. echo "package misc"
  49. echo "config data 'data'"
  50. print 'mac' "$(uci -q get network.freifunk.macaddr)"
  51. printList 'freifunk_addr4' "$(addr 4 $freifunk)"
  52. printList 'freifunk_addr6' "$(addr 6 $freifunk)"
  53. printList 'lan_addr4' "$(addr 4 $lan)"
  54. printList 'lan_addr6' "$(addr 6 $lan)"
  55. printList 'wan_addr4' "$(addr 4 $wan)"
  56. printList 'wan_addr6' "$(addr 6 $wan)"
  57. up="$(uptime)"
  58. uptime="${up%%,*}"
  59. print 'load' "${up##*:}"
  60. print 'uptime' "${uptime##*up}"
  61. print 'memory_usage' "$(memory_usage_percent)"
  62. print 'rootfs_usage' "$(rootfs_usage_percent)"
  63. print 'uname' "$(uname -s -m -r)"
  64. print 'date' "$(date)"
  65. print 'vpn_server' "$(vpn_server)"
  66. print 'ip_version' "$(sockread /var/run/fastd.status < /dev/null 2> /dev/null | grep 'established' | sed 's/\(.*\)"address": "\([^"]*\)"\(.*\)established\(.*\)/\2/g' | sed 's/\(.*\):.*/\1/g' | sed /:/!s/\[[0-9]*\.*/IPv4/g | sed s/\.*:.*/IPv6/g)"
  67. if [ -n "$(default_gw 4 $wan)" -o -n "$(default_gw 6 $wan)" ]; then
  68. print 'has_internet' 'Ja'
  69. else
  70. print 'has_internet' 'Nein'
  71. fi
  72. print 'node_count' "$((`batctl transglobal 2> /dev/null | grep '^ [^ ]' | cut -b 39-55 | sort | uniq | wc -l`+1))"
  73. print 'neigh_count' "$(batctl neighbors 2> /dev/null | tail -n +3 | grep -v '^No' | cut -c -17 | sort | uniq | wc -l)"
  74. print 'firmware_version' "$(uci -q get freifunk.@settings[0].version)"
  75. print 'fastd_version' "$(fastd --version 2> /dev/null | cut -d' ' -f 2)"
  76. print 'batman_version' "$(batctl -v 2> /dev/null | awk -F '[][ \t]+' '{print($4); exit;}')"
  77. print 'routing-algo' "$(cat /sys/module/batman_adv/parameters/routing_algo 2> /dev/null)"
  78. print 'openwrt_version' "$DISTRIB_RELEASE"
  79. name="$(uci -q get freifunk.@settings[0].name)"
  80. print 'name' "${name:--}"
  81. print 'model' "$(cat /tmp/sysinfo/model 2> /dev/null)"
  82. print 'freifunk_user_count' "$(batctl translocal 2> /dev/null | grep -c 'W')"
  83. print 'lan_user_count' "$(cat /tmp/dhcp.lan.leases 2> /dev/null | sed '/^[0-9][0-9]* .* 192/!d' | wc -l)"
  84. print 'lan_rx_speed' "$(calc_speed.sh $lan rx 2> /dev/null)"
  85. print 'lan_tx_speed' "$(calc_speed.sh $lan tx 2> /dev/null)"
  86. print 'freifunk_rx_speed' "$(calc_speed.sh $freifunk rx 2> /dev/null)"
  87. print 'freifunk_tx_speed' "$(calc_speed.sh $freifunk tx 2> /dev/null)"
  88. print 'wan_rx_speed' "$(calc_speed.sh $wan rx 2> /dev/null)"
  89. print 'wan_tx_speed' "$(calc_speed.sh $wan tx 2> /dev/null)"
  90. print 'lan_rx_data' "$(cat /var/rx_data_$lan 2> /dev/null)"
  91. print 'lan_tx_data' "$(cat /var/tx_data_$lan 2> /dev/null)"
  92. print 'freifunk_rx_data' "$(cat /var/rx_data_$freifunk 2> /dev/null)"
  93. print 'freifunk_tx_data' "$(cat /var/tx_data_$freifunk 2> /dev/null)"
  94. print 'wan_rx_data' "$(cat /var/rx_data_$wan 2> /dev/null)"
  95. print 'wan_tx_data' "$(cat /var/tx_data_$wan 2> /dev/null)"
  96. %>