gistfile1.txt
· 1.5 KiB · Text
Исходник
local endpoint_display
endpoint_display=$(resolve::ip "${endpoint:-}")
[[ -z "$endpoint_display" ]] && endpoint_display="${endpoint:--}"
# Build row with ts prefix for sorting
local row
row=$(ui::watch::wg_row "$ts_fmt" "$client_name" "$endpoint_display" "handshake" \
"$w_client" "$w_dest")
rows+=("${ts}|${row}")
done < <(wg show "$(config::interface)" latest-handshakes 2>/dev/null)
# Sort by ts descending (most recent first) and print
if [[ ${#rows[@]} -gt 0 ]]; then
printf '%s\n' "${rows[@]}" | sort -t'|' -k1,1rn | while IFS= read -r entry; do
_WATCH_LAST_FW["$fw_key"]="$now"
local ts_fmt
ts_fmt=$(fmt::datetime_short "$(json::iso_to_ts "$ts" 2>/dev/null || echo 0)")
local dest_display
dest_display=$(resolve::dest "$dest_ip" "$dest_port" "$proto")
ui::watch::fw_row "$ts_fmt" "$client" "$dest_display" "$w_client" "$w_dest"
else
$restricted_only && continue
local ev_data
ev_data=$(python3 "$(ctx::json_helper)" parse_event "$line" 2>/dev/null) || continue
[[ -z "$ev_data" ]] && continue
local endpoint_resolved
endpoint_resolved=$(resolve::ip "${endpoint:-}")
if [[ -z "$endpoint_resolved" && -n "$endpoint" ]]; then
endpoint_resolved="$endpoint"
fi
[[ -z "$endpoint_resolved" ]] && endpoint_resolved="-"
ui::watch::wg_row "$ts_fmt" "$client" "$endpoint_resolved" "$event" \
"$w_client" "$w_dest"
fi
done
rm -f "$source_file"
| 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" |
| 46 |