#!/bin/sh . /usr/share/libubox/jshn.sh add_object () { json_set_namespace NEW json_add_object "${1}" json_add_string radio "${2}" json_add_string ssid "${3}" json_add_int disconnected_time "${4}" json_close_object json_set_namespace ORG } read_unconnected_clients() { local uptime=$(cut -f1 -d. < /proc/uptime) local type Idx=1 json_set_namespace NEW json_init json_add_object "clients" json_set_namespace ORG json_init json_load "$(/usr/sbin/update_wifi_client_list.sh read)" if json_select "clients" > /dev/null; then while json_get_type type $Idx && [ "$type" = object ]; do local connected mac radio ssid time_stamp json_select $Idx json_get_var connected connected if [ "$connected" = "0" ]; then json_get_var mac mac json_get_var radio radio json_get_var ssid ssid json_get_var time_stamp time_stamp add_object "$mac" "$radio" "$ssid" "$(($uptime - $time_stamp))" fi json_select .. Idx=$((Idx+1)) done fi json_set_namespace NEW json_close_object json_dump } case "$1" in list) echo '{ "wifi_script_running": { }, "unconnected_clients": { } }' ;; call) case "$2" in wifi_script_running) json_init pidof wifi > /dev/null if [ "$?" = "0" ]; then json_add_string "running" "yes" else json_add_string "running" "no" fi json_dump ;; unconnected_clients) read_unconnected_clients ;; esac ;; esac