Última atividade 1 month ago

Revisão 51ac0583a78741e63fd86b301288fb447f2da876

gistfile1.txt Bruto
1 log::error "Service not found: ${filter_service}"
2 return 1
3 fi
4 fi
5 [[ -n "$filter_ip" ]] && service_ip="$filter_ip"
6
7 # Fetch aggregated data
8 local data
9 data=$(json::activity_aggregate \
10 "$(ctx::fw_events_log)" \
11 "$(ctx::events_log)" \
12 "$(config::interface)" \
13 "$(ctx::net)" \
14 "$(ctx::clients)" \
15 "$(ctx::meta)" \
16 "$hours" \
17 "$filter_peer" \
18 "$service_ip" 2>/dev/null)
19
20 if [[ -z "$data" ]]; then
21 log::wg_warning "No activity data found"
22 return 0
23 fi
24
25 # Measure column widths
26 local w_peer=16 w_drops=1
27 while IFS='|' read -r type rest; do
28 case "$type" in
29 peer)
30 local name drops
31 name=$(echo "$rest" | cut -d'|' -f1)
32 drops=$(echo "$rest" | cut -d'|' -f4)
33 (( ${#name} > w_peer )) && w_peer=${#name}
34 (( ${#drops} > w_drops )) && w_drops=${#drops}
35 ;;
36 service)
37 local count
38 count=$(echo "$rest" | cut -d'|' -f3)
39 (( ${#count} > w_drops )) && w_drops=${#count}
40 ;;
41 esac
42 done <<< "$data"
43
44 (( w_peer += 2 ))
45
46 # Compute column where drop count starts on peer row:
47 # " " (2) + name (w_peer) + " ↓" (3) + rx (10) + " ↑" (3) + tx (10) + " " (2)
48 # ↓ and ↑ are multi-byte (3 bytes, 1 visible) — 2 extra bytes each
49 # Visible: 2 + w_peer + 2+1 + 10 + 2+1 + 10 + 2 = w_peer + 30
50 local drops_col=$(( w_peer + 30 ))
51