4 .
/lib
/functions
/network.sh
5 .
/usr
/share
/libubox
/jshn.sh
8 MWAN3TRACK_STATUS_DIR
="/var/run/mwan3track"
11 IPT4
="iptables -t mangle -w"
12 IPT6
="ip6tables -t mangle -w"
14 report_connected_v4
() {
17 if [ -n "$($IPT4 -S mwan3_connected 2> /dev/null)" ]; then
18 for address
in $
($IPS -o save list mwan3_connected_v4 |
grep add | cut
-d " " -f 3); do
19 json_add_string
"" "${address}"
24 report_connected_v6
() {
27 if [ -n "$($IPT6 -S mwan3_connected 2> /dev/null)" ]; then
28 for address
in $
($IPS -o save list mwan3_connected_v6 |
grep add | cut
-d " " -f 3); do
29 json_add_string
"" "${address}"
38 local percent total_weight weight iface
40 total_weight
=$
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
head -1 |
awk '{print $3}')
42 for iface
in $
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
awk '{print $1}'); do
43 weight
=$
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
awk '$1 == "'$iface'"' |
awk '{print $2}')
44 percent
=$
(($weight*100/$total_weight))
46 json_add_string interface
"$iface"
47 json_add_int percent
"$percent"
52 report_policies_v4
() {
55 for policy
in $
($IPT4 -S |
awk '{print $2}' |
grep mwan3_policy_ |
sort -u); do
56 json_add_array
"${policy##*mwan3_policy_}"
57 report_policies
"$IPT4" "$policy"
62 report_policies_v6
() {
65 for policy
in $
($IPT6 -S |
awk '{print $2}' |
grep mwan3_policy_ |
sort -u); do
66 json_add_array
"${policy##*mwan3_policy_}"
67 report_policies
"$IPT6" "$policy"
74 local iface_select
="${2}"
80 local enabled pid device time_p time_n time_u time_d status
82 network_get_device device
$1
84 if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
85 pid
="$(pgrep -f "mwan3track
$iface $device")"
86 if [ "${pid}" != "" ]; then
90 time_p
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME
")"
91 [ -z "${time_p}" ] ||
{
92 time_n
="$(get_uptime)"
96 time_u
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/ONLINE
")"
97 [ -z "${time_u}" ] ||
[ "${time_u}" = "0" ] ||
{
98 time_n
="$(get_uptime)"
99 let online
=time_n-time_u
102 time_d
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE
")"
103 [ -z "${time_d}" ] ||
[ "${time_d}" = "0" ] ||
{
104 time_n
="$(get_uptime)"
105 let offline
=time_n-time_d
110 config_get enabled
"$iface" enabled
0
111 network_get_uptime uptime
"$iface"
112 network_is_up
"$iface" && up
="1"
114 if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then
115 status
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS
")"
120 json_add_object
"${iface}"
121 json_add_int age
"$age"
122 json_add_int online
"${online}"
123 json_add_int offline
"${offline}"
124 json_add_int uptime
"${uptime}"
125 json_add_int
"score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE
")"
126 json_add_int
"lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST
")"
127 json_add_int
"turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN
")"
128 json_add_string
"status" "${status}"
129 json_add_boolean
"enabled" "${enabled}"
130 json_add_boolean
"running" "${running}"
131 json_add_boolean
"up" "${up}"
132 json_add_array
"track_ip"
133 for file in $MWAN3TRACK_STATUS_DIR/${iface}/*; do
134 track
="${file#*/TRACK_}"
135 if [ "${track}" != "${file}" ]; then
137 json_add_string ip
"${track}"
138 json_add_string status
"$(cat "${file}")"
139 json_add_int latency
"$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_
${track}")"
140 json_add_int packetloss
"$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_
${track}")"
154 json_add_object
"status"
155 json_add_string
"section" "x"
156 json_add_string
"interface" "x"
157 json_add_string
"policies" "x"
167 json_get_var section section
168 json_get_var iface interface
174 json_add_object interfaces
175 config_foreach get_mwan3_status interface
"${iface}"
179 json_add_object connected
189 json_add_object policies
200 json_add_object interfaces
201 config_foreach get_mwan3_status interface
204 json_add_object connected
213 json_add_object policies