gistfile1.txt
· 3.3 KiB · Text
Surowy
# ── Table view ─────────────────────────────
log::section "WireGuard Clients"
cmd::list::_render_header $has_groups
for conf in "${dir}"/*.conf; do
[[ -f "$conf" ]] || continue
local client_name
client_name=$(basename "$conf" .conf)
local ip="${p_ips[$client_name]:-}"
if [[ -z "$ip" ]]; then
# Fallback for peers not in precomputed data
ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1)
fi
local ip="${p_ips[$client_name]}"
local type
type=$(cmd::list::_get_type "$ip")
[[ -n "$filter_type" && "$type" != "$filter_type" ]] && continue
local pubkey="${p_pubkeys[$client_name]:-}"
local handshake_ts="${wg_handshakes[$pubkey]:-0}"
local is_blocked="${p_blocked[$client_name]:-false}"
local is_restricted="${p_restricted[$client_name]:-false}"
local last_ts="${p_last_ts[$client_name]:-}"
# Filters
if $online_only; then
cmd::list::_is_connected "$handshake_ts" || continue
fi
if $offline_only; then
cmd::list::_is_connected "$handshake_ts" && continue
fi
if $restricted_only && [[ "$is_restricted" != "true" ]]; then
continue
fi
if $blocked_only && [[ "$is_blocked" != "true" ]]; then
continue
fi
if $allowed_only && { [[ "$is_blocked" == "true" ]] || [[ "$is_restricted" == "true" ]]; }; then
continue
fi
local status last_seen display_type rule group_display
status=$(cmd::list::_format_status "$client_name" "$pubkey" \
"$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts")
last_seen=$(cmd::list::_format_last_seen "$client_name" "$pubkey" \
"$is_blocked" "$last_ts" "" "$handshake_ts")
display_type=$(cmd::list::display_type "$client_name" "$type" "${p_subtypes[$client_name]:-}")
rule="${p_rules[$client_name]:-—}"
local padded_status
padded_status=$(cmd::list::pad_status "$status" 25)
if $has_groups; then
group_display="${peer_group_map[$client_name]:-—}"
local rule_col_width=12 group_col_width=12
[[ "$rule" == "—" ]] && rule_col_width=14
[[ "$group_display" == "—" ]] && group_col_width=14
printf " %-28s %-15s %-13s %-${rule_col_width}s %-${group_col_width}s %s %s\n" \
"$client_name" "$ip" "$display_type" "$rule" \
"$group_display" "$padded_status" "$last_seen"
else
local rule_col_width=12
[[ "$rule" == "—" ]] && rule_col_width=14
printf " %-28s %-15s %-13s %-${rule_col_width}s %s %s\n" \
"$client_name" "$ip" "$display_type" "$rule" \
"$padded_status" "$last_seen"
fi
done
cmd::list::_render_footer $has_groups
# Group summary
local group_summary=""
if $has_groups; then
declare -A group_counts
for peer in "${!peer_group_map[@]}"; do
local g="${peer_group_map[$peer]}"
group_counts["$g"]=$(( ${group_counts["$g"]:-0} + 1 )) || true
done
for g in "${!group_counts[@]}"; do
group_summary+="${group_counts[$g]} in ${g}, "
done
group_summary="${group_summary%, }"
fi
declare -A rule_counts
for name in "${!p_rules[@]}"; do
local r="${p_rules[$name]}"
rule_counts["$r"]=$(( ${rule_counts["$r"]:-0} + 1 )) || true
done
cmd::list::_render_summary "$group_summary" rule_counts
| 1 | # ── Table view ───────────────────────────── |
| 2 | |
| 3 | log::section "WireGuard Clients" |
| 4 | cmd::list::_render_header $has_groups |
| 5 | |
| 6 | for conf in "${dir}"/*.conf; do |
| 7 | [[ -f "$conf" ]] || continue |
| 8 | |
| 9 | local client_name |
| 10 | client_name=$(basename "$conf" .conf) |
| 11 | |
| 12 | local ip="${p_ips[$client_name]:-}" |
| 13 | if [[ -z "$ip" ]]; then |
| 14 | # Fallback for peers not in precomputed data |
| 15 | ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1) |
| 16 | fi |
| 17 | |
| 18 | local ip="${p_ips[$client_name]}" |
| 19 | local type |
| 20 | type=$(cmd::list::_get_type "$ip") |
| 21 | |
| 22 | [[ -n "$filter_type" && "$type" != "$filter_type" ]] && continue |
| 23 | |
| 24 | local pubkey="${p_pubkeys[$client_name]:-}" |
| 25 | local handshake_ts="${wg_handshakes[$pubkey]:-0}" |
| 26 | local is_blocked="${p_blocked[$client_name]:-false}" |
| 27 | local is_restricted="${p_restricted[$client_name]:-false}" |
| 28 | local last_ts="${p_last_ts[$client_name]:-}" |
| 29 | |
| 30 | # Filters |
| 31 | if $online_only; then |
| 32 | cmd::list::_is_connected "$handshake_ts" || continue |
| 33 | fi |
| 34 | if $offline_only; then |
| 35 | cmd::list::_is_connected "$handshake_ts" && continue |
| 36 | fi |
| 37 | if $restricted_only && [[ "$is_restricted" != "true" ]]; then |
| 38 | continue |
| 39 | fi |
| 40 | if $blocked_only && [[ "$is_blocked" != "true" ]]; then |
| 41 | continue |
| 42 | fi |
| 43 | if $allowed_only && { [[ "$is_blocked" == "true" ]] || [[ "$is_restricted" == "true" ]]; }; then |
| 44 | continue |
| 45 | fi |
| 46 | |
| 47 | local status last_seen display_type rule group_display |
| 48 | status=$(cmd::list::_format_status "$client_name" "$pubkey" \ |
| 49 | "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") |
| 50 | last_seen=$(cmd::list::_format_last_seen "$client_name" "$pubkey" \ |
| 51 | "$is_blocked" "$last_ts" "" "$handshake_ts") |
| 52 | display_type=$(cmd::list::display_type "$client_name" "$type" "${p_subtypes[$client_name]:-}") |
| 53 | rule="${p_rules[$client_name]:-—}" |
| 54 | |
| 55 | local padded_status |
| 56 | padded_status=$(cmd::list::pad_status "$status" 25) |
| 57 | |
| 58 | if $has_groups; then |
| 59 | group_display="${peer_group_map[$client_name]:-—}" |
| 60 | local rule_col_width=12 group_col_width=12 |
| 61 | [[ "$rule" == "—" ]] && rule_col_width=14 |
| 62 | [[ "$group_display" == "—" ]] && group_col_width=14 |
| 63 | printf " %-28s %-15s %-13s %-${rule_col_width}s %-${group_col_width}s %s %s\n" \ |
| 64 | "$client_name" "$ip" "$display_type" "$rule" \ |
| 65 | "$group_display" "$padded_status" "$last_seen" |
| 66 | else |
| 67 | local rule_col_width=12 |
| 68 | [[ "$rule" == "—" ]] && rule_col_width=14 |
| 69 | printf " %-28s %-15s %-13s %-${rule_col_width}s %s %s\n" \ |
| 70 | "$client_name" "$ip" "$display_type" "$rule" \ |
| 71 | "$padded_status" "$last_seen" |
| 72 | fi |
| 73 | done |
| 74 | |
| 75 | cmd::list::_render_footer $has_groups |
| 76 | |
| 77 | # Group summary |
| 78 | local group_summary="" |
| 79 | if $has_groups; then |
| 80 | declare -A group_counts |
| 81 | for peer in "${!peer_group_map[@]}"; do |
| 82 | local g="${peer_group_map[$peer]}" |
| 83 | group_counts["$g"]=$(( ${group_counts["$g"]:-0} + 1 )) || true |
| 84 | done |
| 85 | for g in "${!group_counts[@]}"; do |
| 86 | group_summary+="${group_counts[$g]} in ${g}, " |
| 87 | done |
| 88 | group_summary="${group_summary%, }" |
| 89 | fi |
| 90 | |
| 91 | declare -A rule_counts |
| 92 | for name in "${!p_rules[@]}"; do |
| 93 | local r="${p_rules[$name]}" |
| 94 | rule_counts["$r"]=$(( ${rule_counts["$r"]:-0} + 1 )) || true |
| 95 | done |
| 96 | cmd::list::_render_summary "$group_summary" rule_counts |