gistfile1.txt
· 2.7 KiB · Text
Bruto
function cmd::list::_render_row() {
local client_name="$1" ip="$2" type="$3"
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]:-}"
# Apply status filters
if $online_only; then peers::is_online "$client_name" "$handshake_ts" "$last_ts" || return 0; fi
if $offline_only; then peers::is_offline "$client_name" "$handshake_ts" "$last_ts" || return 0; fi
if $restricted_only && [[ "$is_restricted" != "true" ]]; then return 0; fi
if $blocked_only && [[ "$is_blocked" != "true" ]]; then return 0; fi
if $allowed_only && { [[ "$is_blocked" == "true" ]] || \
[[ "$is_restricted" == "true" ]]; }; then return 0; fi
if [[ -n "$filter_group" ]]; then
local peer_group="${peer_group_map[$client_name]:-}"
[[ "$peer_group" != "$filter_group" ]] && return 0
fi
# Format display values
local status last_seen display_type rule group_display
status=$(peers::format_status "$client_name" "$pubkey" \
"$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts")
last_seen=$(peers::format_last_seen "$client_name" "$pubkey" \
"$is_blocked" "$last_ts" "" "$handshake_ts")
display_type=$(peers::display_type "$type" "${p_subtypes[$client_name]:-}")
rule="${p_rules[$client_name]:-—}"
if [[ -n "$filter_rule" && "$rule" != "$filter_rule" ]]; then return 0; fi
# Print header on first match
if [[ "${_list_header_printed:-false}" == "false" ]]; then
log::section "WireGuard Clients"
cmd::list::_render_header $has_groups
_list_header_printed=true
fi
# Update rule counts for summary (outer scope array)
rule_counts["$rule"]=$(( ${rule_counts[$rule]:-0} + 1 )) || true
# Pad status
local padded_status
padded_status=$(ui::pad_status "$status" 25)
# Render row
if $has_groups; then
group_display="${peer_group_map[$client_name]:-—}"
if [[ -n "${peer_group_map[$client_name]:-}" ]]; then
group_counts["$group_display"]=$(( ${group_counts[$group_display]:-0} + 1 )) || true
fi
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
}
| 1 | function cmd::list::_render_row() { |
| 2 | local client_name="$1" ip="$2" type="$3" |
| 3 | |
| 4 | local pubkey="${p_pubkeys[$client_name]:-}" |
| 5 | local handshake_ts="${wg_handshakes[$pubkey]:-0}" |
| 6 | local is_blocked="${p_blocked[$client_name]:-false}" |
| 7 | local is_restricted="${p_restricted[$client_name]:-false}" |
| 8 | local last_ts="${p_last_ts[$client_name]:-}" |
| 9 | |
| 10 | # Apply status filters |
| 11 | if $online_only; then peers::is_online "$client_name" "$handshake_ts" "$last_ts" || return 0; fi |
| 12 | if $offline_only; then peers::is_offline "$client_name" "$handshake_ts" "$last_ts" || return 0; fi |
| 13 | if $restricted_only && [[ "$is_restricted" != "true" ]]; then return 0; fi |
| 14 | if $blocked_only && [[ "$is_blocked" != "true" ]]; then return 0; fi |
| 15 | if $allowed_only && { [[ "$is_blocked" == "true" ]] || \ |
| 16 | [[ "$is_restricted" == "true" ]]; }; then return 0; fi |
| 17 | |
| 18 | if [[ -n "$filter_group" ]]; then |
| 19 | local peer_group="${peer_group_map[$client_name]:-}" |
| 20 | [[ "$peer_group" != "$filter_group" ]] && return 0 |
| 21 | fi |
| 22 | |
| 23 | # Format display values |
| 24 | local status last_seen display_type rule group_display |
| 25 | status=$(peers::format_status "$client_name" "$pubkey" \ |
| 26 | "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") |
| 27 | last_seen=$(peers::format_last_seen "$client_name" "$pubkey" \ |
| 28 | "$is_blocked" "$last_ts" "" "$handshake_ts") |
| 29 | display_type=$(peers::display_type "$type" "${p_subtypes[$client_name]:-}") |
| 30 | rule="${p_rules[$client_name]:-—}" |
| 31 | |
| 32 | if [[ -n "$filter_rule" && "$rule" != "$filter_rule" ]]; then return 0; fi |
| 33 | |
| 34 | # Print header on first match |
| 35 | if [[ "${_list_header_printed:-false}" == "false" ]]; then |
| 36 | log::section "WireGuard Clients" |
| 37 | cmd::list::_render_header $has_groups |
| 38 | _list_header_printed=true |
| 39 | fi |
| 40 | |
| 41 | # Update rule counts for summary (outer scope array) |
| 42 | rule_counts["$rule"]=$(( ${rule_counts[$rule]:-0} + 1 )) || true |
| 43 | |
| 44 | # Pad status |
| 45 | local padded_status |
| 46 | padded_status=$(ui::pad_status "$status" 25) |
| 47 | |
| 48 | # Render row |
| 49 | if $has_groups; then |
| 50 | group_display="${peer_group_map[$client_name]:-—}" |
| 51 | |
| 52 | if [[ -n "${peer_group_map[$client_name]:-}" ]]; then |
| 53 | group_counts["$group_display"]=$(( ${group_counts[$group_display]:-0} + 1 )) || true |
| 54 | fi |
| 55 | |
| 56 | local rule_col_width=12 group_col_width=12 |
| 57 | [[ "$rule" == "—" ]] && rule_col_width=14 |
| 58 | [[ "$group_display" == "—" ]] && group_col_width=14 |
| 59 | printf " %-28s %-15s %-13s %-${rule_col_width}s %-${group_col_width}s %s %s\n" \ |
| 60 | "$client_name" "$ip" "$display_type" "$rule" \ |
| 61 | "$group_display" "$padded_status" "$last_seen" |
| 62 | else |
| 63 | local rule_col_width=12 |
| 64 | [[ "$rule" == "—" ]] && rule_col_width=14 |
| 65 | printf " %-28s %-15s %-13s %-${rule_col_width}s %s %s\n" \ |
| 66 | "$client_name" "$ip" "$display_type" "$rule" \ |
| 67 | "$padded_status" "$last_seen" |
| 68 | fi |
| 69 | } |