nuno revidoval tento gist 1 month ago. Přejít na revizi
1 file changed, 45 insertions
gistfile1.txt(vytvořil soubor)
| @@ -0,0 +1,45 @@ | |||
| 1 | + | ||
| 2 | + | local endpoint_display | |
| 3 | + | endpoint_display=$(resolve::ip "${endpoint:-}") | |
| 4 | + | [[ -z "$endpoint_display" ]] && endpoint_display="${endpoint:--}" | |
| 5 | + | ||
| 6 | + | # Build row with ts prefix for sorting | |
| 7 | + | local row | |
| 8 | + | row=$(ui::watch::wg_row "$ts_fmt" "$client_name" "$endpoint_display" "handshake" \ | |
| 9 | + | "$w_client" "$w_dest") | |
| 10 | + | rows+=("${ts}|${row}") | |
| 11 | + | ||
| 12 | + | done < <(wg show "$(config::interface)" latest-handshakes 2>/dev/null) | |
| 13 | + | ||
| 14 | + | # Sort by ts descending (most recent first) and print | |
| 15 | + | if [[ ${#rows[@]} -gt 0 ]]; then | |
| 16 | + | printf '%s\n' "${rows[@]}" | sort -t'|' -k1,1rn | while IFS= read -r entry; do | |
| 17 | + | _WATCH_LAST_FW["$fw_key"]="$now" | |
| 18 | + | ||
| 19 | + | local ts_fmt | |
| 20 | + | ts_fmt=$(fmt::datetime_short "$(json::iso_to_ts "$ts" 2>/dev/null || echo 0)") | |
| 21 | + | ||
| 22 | + | local dest_display | |
| 23 | + | dest_display=$(resolve::dest "$dest_ip" "$dest_port" "$proto") | |
| 24 | + | ||
| 25 | + | ui::watch::fw_row "$ts_fmt" "$client" "$dest_display" "$w_client" "$w_dest" | |
| 26 | + | ||
| 27 | + | else | |
| 28 | + | $restricted_only && continue | |
| 29 | + | ||
| 30 | + | local ev_data | |
| 31 | + | ev_data=$(python3 "$(ctx::json_helper)" parse_event "$line" 2>/dev/null) || continue | |
| 32 | + | [[ -z "$ev_data" ]] && continue | |
| 33 | + | local endpoint_resolved | |
| 34 | + | endpoint_resolved=$(resolve::ip "${endpoint:-}") | |
| 35 | + | if [[ -z "$endpoint_resolved" && -n "$endpoint" ]]; then | |
| 36 | + | endpoint_resolved="$endpoint" | |
| 37 | + | fi | |
| 38 | + | [[ -z "$endpoint_resolved" ]] && endpoint_resolved="-" | |
| 39 | + | ||
| 40 | + | ui::watch::wg_row "$ts_fmt" "$client" "$endpoint_resolved" "$event" \ | |
| 41 | + | "$w_client" "$w_dest" | |
| 42 | + | fi | |
| 43 | + | done | |
| 44 | + | ||
| 45 | + | rm -f "$source_file" | |
Novější
Starší