firmware/src/packages/fff/fff-network/files/usr/lib/nodewatcher-json.d/51-clients.sh

36 lines
904 B
Bash

#!/bin/sh
MESH_INTERFACE=$(uci get nodewatcher.@network[0].mesh_interface)
SCRIPT_DATA_FILE=$(uci get nodewatcher.@script[0].data_file).json
debug() {
(>&2 echo "nodewatcher: $1")
}
debug "Collecting information about connected clients"
. /usr/share/libubox/jshn.sh
json_load_file $SCRIPT_DATA_FILE
json_add_object "clients"
json_add_array interfaces
client_count=0
CLIENT_INTERFACES=$(ls "/sys/class/net/$MESH_INTERFACE/brif" | grep -v '^bat')
for clientif in ${CLIENT_INTERFACES}; do
json_add_object ""
cc=$(bridge fdb show br "$MESH_INTERFACE" brport "$clientif" | grep -v self | grep -v permanent -c)
client_count=$((client_count + cc))
json_add_string "$clientif" "$cc"
json_close_object #iface object
done
json_close_object #interfaces array
json_add_string "count" "$client_count"
json_close_object #clients
json_dump > $SCRIPT_DATA_FILE
#exit 0