Последняя активность 1 month ago

nuno ревизий этого фрагмента 1 month ago. К ревизии

1 file changed, 64 insertions

gistfile1.txt(файл создан)

@@ -0,0 +1,64 @@
1 + function ui::logs::wg_row() {
2 + local ts="${1:-}" client="${2:-}" endpoint="${3:-}" event="${4:-}" \
3 + count="${5:-1}" w_client="${6:-20}" w_endpoint="${7:-20}" \
4 + gap_seconds="${8:-}" resolved="${9:-}"
5 +
6 + local event_color
7 + case "$event" in
8 + handshake) event_color="\033[1;32m" ;;
9 + attempt) event_color="\033[1;31m" ;;
10 + *) event_color="\033[0;37m" ;;
11 + esac
12 +
13 + local count_suffix=""
14 + [[ "$count" -gt 1 ]] && count_suffix=" \033[2m(x${count})\033[0m"
15 +
16 + # Gap suffix with offline label only when gap > threshold * 2
17 + local gap_suffix=""
18 + if [[ "$event" == "handshake" && -n "$gap_seconds" && "$gap_seconds" -gt 0 ]]; then
19 + local gap_int="$gap_seconds"
20 + local threshold="${WG_HANDSHAKE_CHECK_TIME_SEC:-300}"
21 + local offline_threshold=$(( threshold * 2 ))
22 + local offline_label=""
23 + [[ "$gap_int" -gt "$offline_threshold" ]] && offline_label=" offline"
24 + if (( gap_int >= 3600 )); then
25 + gap_suffix=" \033[2m↑ $(( gap_int / 3600 ))h${offline_label}\033[0m"
26 + elif (( gap_int >= 60 )); then
27 + gap_suffix=" \033[2m↑ $(( gap_int / 60 ))m${offline_label}\033[0m"
28 + fi
29 + fi
30 +
31 + # Build endpoint display: raw_ip [→ resolved dim]
32 + local endpoint_display="${endpoint:--}"
33 + if [[ -n "$resolved" && -n "$endpoint" ]]; then
34 + endpoint_display="${endpoint} \033[2m→ ${resolved}\033[0m"
35 + fi
36 +
37 + if [[ -n "$endpoint" ]]; then
38 + local resolved
39 + resolved=$(resolve::ip "$endpoint" 2>/dev/null || echo "")
40 + if [[ -n "$resolved" && "$resolved" != "$endpoint" ]]; then
41 + endpoint_display="${endpoint} \033[2m→ ${resolved}\033[0m"
42 + else
43 + endpoint_display="$endpoint"
44 + fi
45 + else
46 + endpoint_display="-"
47 + fi
48 +
49 + local client_pad endpoint_pad_n
50 + client_pad=$(printf "%-${w_client}s" "$client")
51 + # Use raw endpoint length for padding (resolved part is dim/extra)
52 + local ep_raw_len=${#endpoint}
53 + [[ -z "$endpoint" ]] && ep_raw_len=1 # "-"
54 + endpoint_pad_n=$(( w_endpoint - ep_raw_len ))
55 + [[ $endpoint_pad_n -lt 0 ]] && endpoint_pad_n=0
56 +
57 + local ts_pad
58 + ts_pad=$(printf "%-11s" "$ts")
59 +
60 + printf " %s %s %b%*s %b%s\033[0m%b%b\n" \
61 + "$ts_pad" "$client_pad" \
62 + "$endpoint_display" "$endpoint_pad_n" "" \
63 + "$event_color" "$event" "$count_suffix" "$gap_suffix"
64 + }
Новее Позже