mirror of
https://github.com/openwrt/packages.git
synced 2026-01-10 19:54:50 +00:00
net/mwan3: add status track ubus interface
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
126
net/mwan3/files/usr/libexec/rpcd/mwan3
Executable file
126
net/mwan3/files/usr/libexec/rpcd/mwan3
Executable file
@@ -0,0 +1,126 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
MWAN3_STATUS_DIR="/var/run/mwan3track"
|
||||
MWAN3_PID_FILE="/var/run/mwan3track"
|
||||
|
||||
IPS="/usr/sbin/ipset"
|
||||
IPT4="/usr/sbin/iptables -t mangle -w"
|
||||
IPT6="/usr/sbin/ip6tables -t mangle -w"
|
||||
|
||||
report_connected_v4() {
|
||||
local address
|
||||
|
||||
if [ -n "$($IPT4 -S mwan3_connected 2> /dev/null)" ]; then
|
||||
for address in $($IPS list mwan3_connected_v4 | tail -n +8); do
|
||||
json_add_string "" "${address}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
report_connected_v6() {
|
||||
local address
|
||||
|
||||
if [ -n "$($IPT6 -S mwan3_connected 2> /dev/null)" ]; then
|
||||
for address in $($IPS list mwan3_connected_v6 | tail -n +8); do
|
||||
json_add_string "" "${address}"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
get_mwan3_status() {
|
||||
local iface="${1}"
|
||||
local iface_select="${2}"
|
||||
local running="0"
|
||||
local pid=""
|
||||
local status=""
|
||||
|
||||
if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
|
||||
if [ -f "${MWAN3_PID_FILE}-${iface}.pid" ]; then
|
||||
pid="$(cat "${MWAN3_PID_FILE}-${iface}.pid")"
|
||||
status="$(pgrep -f mwan3track | grep "${pid}")"
|
||||
if [ "${status}" != "" ]; then
|
||||
running="1"
|
||||
fi
|
||||
fi
|
||||
|
||||
json_add_object "${iface}"
|
||||
json_add_string "score" "$(cat "$MWAN3_STATUS_DIR/${iface}/SCORE")"
|
||||
json_add_string "lost" "$(cat "$MWAN3_STATUS_DIR/${iface}/LOST")"
|
||||
json_add_string "turn" "$(cat "$MWAN3_STATUS_DIR/${iface}/TURN")"
|
||||
json_add_string "status" "$(cat "$MWAN3_STATUS_DIR/${iface}/STATUS")"
|
||||
json_add_boolean "running" "${running}"
|
||||
json_add_array "track_ip"
|
||||
for file in $MWAN3_STATUS_DIR/${iface}/*; do
|
||||
track="${file#*/TRACK_}"
|
||||
if [ "${track}" != "${file}" ]; then
|
||||
json_add_object
|
||||
json_add_string ip "${track}"
|
||||
json_add_string status "$(cat "${file}")"
|
||||
json_close_object
|
||||
fi
|
||||
done
|
||||
json_close_array
|
||||
json_close_object
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
json_init
|
||||
json_add_object "status"
|
||||
json_add_string "section" "x"
|
||||
json_add_string "interface" "x"
|
||||
json_close_object
|
||||
json_dump
|
||||
;;
|
||||
call)
|
||||
case "$2" in
|
||||
status)
|
||||
local section iface
|
||||
read input;
|
||||
json_load "$input"
|
||||
json_get_var section section
|
||||
json_get_var iface interface
|
||||
|
||||
config_load mwan3
|
||||
json_init
|
||||
case "$section" in
|
||||
interfaces)
|
||||
json_add_object interfaces
|
||||
config_foreach get_mwan3_status interface "${iface}"
|
||||
json_close_object
|
||||
;;
|
||||
connected)
|
||||
json_add_object connected
|
||||
json_add_array ipv4
|
||||
report_connected_v4
|
||||
json_close_array
|
||||
json_add_array ipv6
|
||||
report_connected_v6
|
||||
json_close_array
|
||||
json_close_object
|
||||
;;
|
||||
*)
|
||||
# interfaces
|
||||
json_add_object interfaces
|
||||
config_foreach get_mwan3_status interface
|
||||
json_close_object
|
||||
# connected
|
||||
json_add_object connected
|
||||
json_add_array ipv4
|
||||
report_connected_v4
|
||||
json_close_array
|
||||
json_add_array ipv6
|
||||
report_connected_v6
|
||||
json_close_array
|
||||
json_close_object
|
||||
;;
|
||||
esac
|
||||
json_dump
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user