gistfile1.txt
· 1.6 KiB · Text
原始文件
function cmd::logs::show_wg_events() {
local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}" \
limit="${4:-50}" collapse="${5:-1}" \
since="${6:-}" filter_event="${7:-}" sort_order="${8:-desc}"
[[ ! -f "$WG_EVENTS_LOG" ]] && return 0
local data
data=$(json::wg_events \
"$WG_EVENTS_LOG" "$filter_name" "$filter_type" \
"$limit" "$collapse" "$since" "$filter_event" \
"$(ctx::endpoint_cache)" "$sort_order" \
2>/dev/null)
[[ -z "$data" ]] && return 0
# Resolve endpoints and measure column widths
local w_client=16 w_endpoint=16
local resolved_data=""
while IFS='|' read -r ts client endpoint event count gap_seconds; do
[[ -z "$ts" ]] && continue
(( ${#client} > w_client )) && w_client=${#client}
# Estimate endpoint column width — raw IP + " → resolved_name"
# Max annotation is " → " (3) + ~12 chars for hostname = ~15 extra
local ep_len=${#endpoint}
[[ -z "$endpoint" ]] && ep_len=1
(( ep_len > w_endpoint )) && w_endpoint=$ep_len
done <<< "$data"
(( w_client += 2 ))
# Add extra width for annotation (resolved name after →)
(( w_endpoint += 18 )) # " → resolved_name" typical max
echo "DEBUG: data_lines=$(echo "$data" | wc -l) resolved_lines=$(echo "$resolved_data" | wc -l)" >&2
ui::logs::wg_section_header
while IFS='|' read -r ts client endpoint event count gap_seconds resolved; do
[[ -z "$ts" ]] && continue
ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \
"$count" "$w_client" "$w_endpoint" "$gap_seconds" "$resolved"
done <<< "$resolved_data"
printf "\n"
}
| 1 | function cmd::logs::show_wg_events() { |
| 2 | local filter_ip="${1:-}" filter_name="${2:-}" filter_type="${3:-}" \ |
| 3 | limit="${4:-50}" collapse="${5:-1}" \ |
| 4 | since="${6:-}" filter_event="${7:-}" sort_order="${8:-desc}" |
| 5 | |
| 6 | [[ ! -f "$WG_EVENTS_LOG" ]] && return 0 |
| 7 | |
| 8 | local data |
| 9 | data=$(json::wg_events \ |
| 10 | "$WG_EVENTS_LOG" "$filter_name" "$filter_type" \ |
| 11 | "$limit" "$collapse" "$since" "$filter_event" \ |
| 12 | "$(ctx::endpoint_cache)" "$sort_order" \ |
| 13 | 2>/dev/null) |
| 14 | |
| 15 | [[ -z "$data" ]] && return 0 |
| 16 | |
| 17 | # Resolve endpoints and measure column widths |
| 18 | local w_client=16 w_endpoint=16 |
| 19 | local resolved_data="" |
| 20 | while IFS='|' read -r ts client endpoint event count gap_seconds; do |
| 21 | [[ -z "$ts" ]] && continue |
| 22 | (( ${#client} > w_client )) && w_client=${#client} |
| 23 | # Estimate endpoint column width — raw IP + " → resolved_name" |
| 24 | # Max annotation is " → " (3) + ~12 chars for hostname = ~15 extra |
| 25 | local ep_len=${#endpoint} |
| 26 | [[ -z "$endpoint" ]] && ep_len=1 |
| 27 | (( ep_len > w_endpoint )) && w_endpoint=$ep_len |
| 28 | done <<< "$data" |
| 29 | (( w_client += 2 )) |
| 30 | # Add extra width for annotation (resolved name after →) |
| 31 | (( w_endpoint += 18 )) # " → resolved_name" typical max |
| 32 | |
| 33 | echo "DEBUG: data_lines=$(echo "$data" | wc -l) resolved_lines=$(echo "$resolved_data" | wc -l)" >&2 |
| 34 | |
| 35 | ui::logs::wg_section_header |
| 36 | while IFS='|' read -r ts client endpoint event count gap_seconds resolved; do |
| 37 | [[ -z "$ts" ]] && continue |
| 38 | ui::logs::wg_row "$ts" "$client" "$endpoint" "$event" \ |
| 39 | "$count" "$w_client" "$w_endpoint" "$gap_seconds" "$resolved" |
| 40 | done <<< "$resolved_data" |
| 41 | printf "\n" |
| 42 | } |