iopsys-feed/netmode/files/sbin/netmode-client-detect
2018-10-06 19:24:05 +02:00

59 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
# receive new client events
# and trigger wificontrol in --router mode for that client
. /usr/share/libubox/jshn.sh
action=
ipaddr=
macaddr=
network=
timed_check() {
while true; do
network=${network:-lan}
ubus call repeater get_creds '{"network":"'$network'","file":"/tmp/wificontrol.txt"}'
wificontrol --router
sleep $1
done
}
is_known_macaddr()
{
macaddr=$1
echo $macaddr | grep -i -e "^00:22:07" \
-e "^02:22:07" \
-e "^44:D4:37" \
-e "^00:0C:07" \
-e "^02:0C:07" \
-e "^06:0C:07" \
-e "^00:0C:43" \
-e "^02:0C:43" \
-e "^06:0C:43" \
&& return
false
}
timed_check 60 &
while true ; do
ubus listen client | \
while read event ; do
#echo "netmode-client-detect got event: $event" >/dev/console
json_load "$event"
json_select client
json_get_var action action
[ "$action" == "connect" ] || continue
json_get_var macaddr macaddr
json_get_var ipaddr ipaddr
json_get_var network network "lan"
if is_known_macaddr $macaddr; then
logger -s -p user.info -t $0 "netmode-client-detect: a new known device detected on '$network' network (MACAddr:$macaddr IPAddr:$ipaddr)" >/dev/console
ubus call repeater get_creds '{"network":"'$network'","file":"/tmp/wificontrol.txt"}'
/sbin/wificontrol --router --destination $ipaddr
fi
done
done