Skip to content

Commit a8391c5

Browse files
committed
Fix TUI crash on Alpine Linux (busybox awk compatibility)
Replace gawk-only match() capture groups with POSIX index()/substr() in _load_all_cumulative_user_stats. Fixes #16.
1 parent 2a0e6b4 commit a8391c5

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

mtproxymax.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,20 +1397,26 @@ _load_all_cumulative_user_stats() {
13971397
_batch_cum_out["$_l"]=$(( ${_saved_out["$_l"]:-0} + doo ))
13981398
_batch_cum_conns["$_l"]=${_lc:-0}
13991399
done < <(echo "$_m" | awk '
1400+
function get_user(s, p,q) {
1401+
p = index(s, "user=\"")
1402+
if (!p) return ""
1403+
s = substr(s, p + 6)
1404+
q = index(s, "\"")
1405+
return q ? substr(s, 1, q - 1) : ""
1406+
}
14001407
/^telemt_user_octets_from_client\{/ {
1401-
match($0, /user="([^"]+)"/, m); users_in[m[1]] += $NF
1408+
u = get_user($0); if (u) users_in[u] += $NF
14021409
}
14031410
/^telemt_user_octets_to_client\{/ {
1404-
match($0, /user="([^"]+)"/, m); users_out[m[1]] += $NF
1411+
u = get_user($0); if (u) users_out[u] += $NF
14051412
}
14061413
/^telemt_user_connections_current\{/ {
1407-
match($0, /user="([^"]+)"/, m); users_conns[m[1]] += $NF
1414+
u = get_user($0); if (u) users_conns[u] += $NF
14081415
}
14091416
END {
14101417
for (u in users_in) {
14111418
printf "%s|%.0f|%.0f|%.0f\n", u, users_in[u]+0, users_out[u]+0, users_conns[u]+0
14121419
}
1413-
# Users with only out/conns but no in
14141420
for (u in users_out) {
14151421
if (!(u in users_in)) printf "%s|0|%.0f|%.0f\n", u, users_out[u]+0, users_conns[u]+0
14161422
}

0 commit comments

Comments
 (0)