gistfile1.txt
· 2.4 KiB · Text
Исходник
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
}
| 1 | function cmd::inspect::_peer_info() { |
| 2 | local name="${1:-}" |
| 3 | |
| 4 | local ip type rule public_key allowed_ips |
| 5 | ip=$(peers::get_ip "$name") |
| 6 | type=$(peers::get_type "$name") |
| 7 | rule=$(peers::get_meta "$name" "rule") |
| 8 | public_key=$(keys::public "$name" 2>/dev/null || echo "") |
| 9 | allowed_ips=$(grep "^AllowedIPs" "$(ctx::clients)/${name}.conf" \ |
| 10 | 2>/dev/null | cut -d'=' -f2- | xargs) |
| 11 | |
| 12 | # Status |
| 13 | local handshake_ts is_blocked last_ts |
| 14 | handshake_ts=$(monitor::get_handshake_ts "$public_key") |
| 15 | peers::is_blocked "$name" && is_blocked="true" || is_blocked="false" |
| 16 | last_ts=$(monitor::last_attempt "$name") |
| 17 | |
| 18 | local is_restricted="false" |
| 19 | block::has_specific_rules "$name" 2>/dev/null && is_restricted="true" |
| 20 | |
| 21 | local status last_seen endpoint |
| 22 | status=$(peers::format_status "$name" "$public_key" \ |
| 23 | "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") |
| 24 | last_seen=$(peers::format_last_seen "$name" "$public_key" \ |
| 25 | "$is_blocked" "$last_ts" "" "$handshake_ts") |
| 26 | endpoint=$(monitor::get_cached_endpoint "$name") |
| 27 | |
| 28 | local activity_total |
| 29 | activity_total=$(peers::format_activity_total "$public_key") |
| 30 | |
| 31 | local activity_current |
| 32 | activity_current=$(peers::format_activity_current "$public_key") |
| 33 | |
| 34 | local subtype |
| 35 | subtype=$(peers::get_meta "$name" "subtype") |
| 36 | |
| 37 | local rule_extends="" |
| 38 | if [[ -n "$rule" ]]; then |
| 39 | local rule_file |
| 40 | rule_file="$(rule::path "$rule" 2>/dev/null)" || true |
| 41 | if [[ -n "$rule_file" ]]; then |
| 42 | local ext=() |
| 43 | mapfile -t ext < <(json::get "$rule_file" "extends" 2>/dev/null || true) |
| 44 | if [[ ${#ext[@]} -gt 0 && -n "${ext[0]:-}" ]]; then |
| 45 | rule_extends=" (↳ ${ext[*]})" |
| 46 | fi |
| 47 | fi |
| 48 | fi |
| 49 | |
| 50 | # Rule formatting |
| 51 | local rule_display="${rule:-—}" |
| 52 | if [[ -n "$rule_file" && ${#ext[@]} -gt 0 && -n "${ext[0]:-}" ]]; then |
| 53 | local extends_str |
| 54 | extends_str=$(printf '%s, ' "${ext[@]}" | sed 's/, $//') |
| 55 | rule_display="${rule} ↳ (${extends_str})" |
| 56 | fi |
| 57 | |
| 58 | cmd::inspect::_section "Client" |
| 59 | ui::row "Name" "$name" |
| 60 | ui::row "IP" "$ip" |
| 61 | ui::row "Type" "$(peers::display_type "$type" "$subtype")" |
| 62 | ui::row "Rule" "$rule_display" |
| 63 | ui::row "Status" "$(echo -e "$status")" |
| 64 | ui::row "Endpoint" "${endpoint:-—}" |
| 65 | ui::row "Last seen" "$last_seen" |
| 66 | ui::row "AllowedIPs" "$allowed_ips" |
| 67 | ui::row "Public key" "${public_key:-—}" |
| 68 | ui::row "Activity (total)" "$activity_total" |
| 69 | ui::row "Activity (current)" "$activity_current" |
| 70 | |
| 71 | return 0 |
| 72 | } |