4 .
/lib
/functions
/network.sh
5 .
/usr
/share
/libubox
/jshn.sh
8 report_connected_v4
() {
11 if [ -n "$($IPT4 -S mwan3_connected 2> /dev/null)" ]; then
12 for address
in $
($IPS -o save list mwan3_connected_v4 |
grep add | cut
-d " " -f 3); do
13 json_add_string
"" "${address}"
18 report_connected_v6
() {
19 [ $NO_IPV6 -ne 0 ] && return
22 if [ -n "$($IPT6 -S mwan3_connected 2> /dev/null)" ]; then
23 for address
in $
($IPS -o save list mwan3_connected_v6 |
grep add | cut
-d " " -f 3); do
24 json_add_string
"" "${address}"
33 local percent total_weight weight iface
35 total_weight
=$
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
head -1 |
awk '{print $3}')
37 for iface
in $
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
awk '{print $1}'); do
38 weight
=$
($ipt -S $policy |
grep -v '.*--comment "out .*" .*$' | cut
-s -d'"' -f2 |
awk '$1 == "'$iface'"' |
awk '{print $2}')
39 percent
=$
(($weight*100/$total_weight))
41 json_add_string interface
"$iface"
42 json_add_int percent
"$percent"
47 report_policies_v4
() {
50 for policy
in $
($IPT4 -S |
awk '{print $2}' |
grep mwan3_policy_ |
sort -u); do
51 json_add_array
"${policy##*mwan3_policy_}"
52 report_policies
"$IPT4" "$policy"
57 report_policies_v6
() {
58 [ $NO_IPV6 -ne 0 ] && return
61 for policy
in $
($IPT6 -S |
awk '{print $2}' |
grep mwan3_policy_ |
sort -u); do
62 json_add_array
"${policy##*mwan3_policy_}"
63 report_policies
"$IPT6" "$policy"
71 time_p
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME
")"
72 [ -z "${time_p}" ] ||
{
73 time_n
="$(get_uptime)"
74 echo $
((time_n-time_p
))
79 local time_n time_d iface
81 time_d
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/OFFLINE
")"
82 [ -z "${time_d}" ] ||
[ "${time_d}" = "0" ] ||
{
83 time_n
="$(get_uptime)"
84 echo $
((time_n-time_d
))
90 local iface_select
="${2}"
95 local enabled time_p time_n time_u time_d status track_status up uptime
97 if [ "${iface}" != "${iface_select}" ] && [ "${iface_select}" != "" ]; then
101 track_status
="$(mwan3_get_mwan3track_status "$1")"
102 [ "$track_status" = "active" ] && running
="1"
103 age
=$
(get_age
"$iface")
104 online
=$
(get_online_time
"$iface")
105 offline
=$
(get_offline_time
"$iface")
107 config_get enabled
"$iface" enabled
0
109 if [ -d "${MWAN3_STATUS_DIR}" ]; then
110 network_get_uptime uptime
"$iface"
111 network_is_up
"$iface" && up
="1"
112 if [ -f "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS" ]; then
113 status
="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS
")"
123 json_add_object
"${iface}"
124 json_add_int age
"$age"
125 json_add_int online
"${online}"
126 json_add_int offline
"${offline}"
127 json_add_int uptime
"${uptime}"
128 json_add_int
"score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE
")"
129 json_add_int
"lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST
")"
130 json_add_int
"turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN
")"
131 json_add_string
"status" "${status}"
132 json_add_boolean
"enabled" "${enabled}"
133 json_add_boolean
"running" "${running}"
134 json_add_boolean
"up" "${up}"
135 json_add_array
"track_ip"
136 for file in $MWAN3TRACK_STATUS_DIR/${iface}/TRACK_
*; do
137 [ -z "${file#*/TRACK_OUTPUT}" ] && continue
138 [ -z "${file#*/TRACK_\*}" ] && continue
139 track
="${file#*/TRACK_}"
141 json_add_string ip
"${track}"
142 json_add_string status
"$(cat "${file}")"
143 json_add_int latency
"$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_
${track}")"
144 json_add_int packetloss
"$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_
${track}")"
156 json_add_object
"status"
157 json_add_string
"section" "x"
158 json_add_string
"interface" "x"
159 json_add_string
"policies" "x"
169 json_get_var section section
170 json_get_var iface interface
176 json_add_object interfaces
177 config_foreach get_mwan3_status interface
"${iface}"
181 json_add_object connected
191 json_add_object policies
202 json_add_object interfaces
203 config_foreach get_mwan3_status interface
206 json_add_object connected
215 json_add_object policies