function cmd::inspect::_peer_info() { local name="${1:-}" local ip type rule public_key allowed_ips ip=$(peers::get_ip "$name") type=$(peers::get_type "$name") rule=$(peers::get_meta "$name" "rule") public_key=$(keys::public "$name" 2>/dev/null || echo "") allowed_ips=$(grep "^AllowedIPs" "$(ctx::clients)/${name}.conf" \ 2>/dev/null | cut -d'=' -f2- | xargs) # Status local handshake_ts is_blocked last_ts handshake_ts=$(monitor::get_handshake_ts "$public_key") peers::is_blocked "$name" && is_blocked="true" || is_blocked="false" last_ts=$(monitor::last_attempt "$name") local is_restricted="false" block::has_specific_rules "$name" 2>/dev/null && is_restricted="true" local status last_seen endpoint status=$(peers::format_status "$name" "$public_key" \ "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") last_seen=$(peers::format_last_seen "$name" "$public_key" \ "$is_blocked" "$last_ts" "" "$handshake_ts") endpoint=$(monitor::get_cached_endpoint "$name") local activity_total activity_total=$(peers::format_activity_total "$public_key") local activity_current activity_current=$(peers::format_activity_current "$public_key") local subtype subtype=$(peers::get_meta "$name" "subtype") local rule_extends="" if [[ -n "$rule" ]]; then local rule_file rule_file="$(rule::path "$rule" 2>/dev/null)" || true if [[ -n "$rule_file" ]]; then local ext=() mapfile -t ext < <(json::get "$rule_file" "extends" 2>/dev/null || true) if [[ ${#ext[@]} -gt 0 && -n "${ext[0]:-}" ]]; then rule_extends=" (↳ ${ext[*]})" fi fi fi # Rule formatting local rule_display="${rule:-—}" if [[ -n "$rule_file" && ${#ext[@]} -gt 0 && -n "${ext[0]:-}" ]]; then local extends_str extends_str=$(printf '%s, ' "${ext[@]}" | sed 's/, $//') rule_display="${rule} ↳ (${extends_str})" fi cmd::inspect::_section "Client" ui::row "Name" "$name" ui::row "IP" "$ip" ui::row "Type" "$(peers::display_type "$type" "$subtype")" ui::row "Rule" "$rule_display" ui::row "Status" "$(echo -e "$status")" ui::row "Endpoint" "${endpoint:-—}" ui::row "Last seen" "$last_seen" ui::row "AllowedIPs" "$allowed_ips" ui::row "Public key" "${public_key:-—}" ui::row "Activity (total)" "$activity_total" ui::row "Activity (current)" "$activity_current" return 0 }