gistfile1.txt
· 936 B · Text
Sin formato
function cmd::logs::show_wg_events() {
local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}" limit="${4:-50}" collapse="${5:-1}"
[[ ! -f "$WG_EVENTS_LOG" ]] && return 0
local data
data=$(json::wg_events "$WG_EVENTS_LOG" "$filter_name" "$filter_type" "$limit" "$collapse" 2>/dev/null)
[[ -z "$data" ]] && return 0
# Measure column widths
local w_client=16 w_endpoint=16
while IFS='|' read -r ts client endpoint event count; do
[[ -z "$ts" ]] && continue
(( ${#client} > w_client )) && w_client=${#client}
(( ${#endpoint} > w_endpoint )) && w_endpoint=${#endpoint}
done <<< "$data"
(( w_client += 2 ))
(( w_endpoint += 2 ))
ui::logs::wg_section_header
while IFS='|' read -r ts client endpoint event count; do
[[ -z "$ts" ]] && continue
ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \
"$count" "$w_client" "$w_endpoint"
done <<< "$data"
printf "\n"
}
| 1 | function cmd::logs::show_wg_events() { |
| 2 | local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}" limit="${4:-50}" collapse="${5:-1}" |
| 3 | |
| 4 | [[ ! -f "$WG_EVENTS_LOG" ]] && return 0 |
| 5 | |
| 6 | local data |
| 7 | data=$(json::wg_events "$WG_EVENTS_LOG" "$filter_name" "$filter_type" "$limit" "$collapse" 2>/dev/null) |
| 8 | |
| 9 | [[ -z "$data" ]] && return 0 |
| 10 | |
| 11 | # Measure column widths |
| 12 | local w_client=16 w_endpoint=16 |
| 13 | while IFS='|' read -r ts client endpoint event count; do |
| 14 | [[ -z "$ts" ]] && continue |
| 15 | (( ${#client} > w_client )) && w_client=${#client} |
| 16 | (( ${#endpoint} > w_endpoint )) && w_endpoint=${#endpoint} |
| 17 | done <<< "$data" |
| 18 | (( w_client += 2 )) |
| 19 | (( w_endpoint += 2 )) |
| 20 | |
| 21 | ui::logs::wg_section_header |
| 22 | while IFS='|' read -r ts client endpoint event count; do |
| 23 | [[ -z "$ts" ]] && continue |
| 24 | ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \ |
| 25 | "$count" "$w_client" "$w_endpoint" |
| 26 | done <<< "$data" |
| 27 | printf "\n" |
| 28 | } |