nuno ревизій цього gist 1 month ago. До ревизії
1 file changed, 78 insertions
gistfile1.txt(файл створено)
| @@ -0,0 +1,78 @@ | |||
| 1 | + | function cmd::list::_collect_all_rows() { | |
| 2 | + | local dir | |
| 3 | + | dir="$(ctx::clients)" | |
| 4 | + | local _verbose_status="${LIST_VERBOSE_STATUS:-true}" | |
| 5 | + | ||
| 6 | + | for conf in "${dir}"/*.conf; do | |
| 7 | + | [[ -f "$conf" ]] || continue | |
| 8 | + | local client_name | |
| 9 | + | client_name=$(basename "$conf" .conf) | |
| 10 | + | [[ -z "$client_name" ]] && continue | |
| 11 | + | ||
| 12 | + | if [[ ${#p_identity_filter[@]} -gt 0 && \ | |
| 13 | + | -z "${p_identity_filter[$client_name]:-}" ]]; then | |
| 14 | + | continue | |
| 15 | + | fi | |
| 16 | + | ||
| 17 | + | local ip="${p_ips[$client_name]:-}" | |
| 18 | + | [[ -z "$ip" ]] && ip=$(grep "^Address" "$conf" | awk '{print $3}' | cut -d'/' -f1) | |
| 19 | + | [[ -z "$ip" ]] && continue | |
| 20 | + | ||
| 21 | + | local type="${p_types[$client_name]:-unknown}" | |
| 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 | + | local rule="${p_rules[$client_name]:-}" | |
| 30 | + | local group="${p_main_groups[$client_name]:-}" | |
| 31 | + | ||
| 32 | + | if $online_only; then peers::is_online "$client_name" "$handshake_ts" "$last_ts" || continue; fi | |
| 33 | + | if $offline_only; then peers::is_offline "$client_name" "$handshake_ts" "$last_ts" || continue; fi | |
| 34 | + | if $restricted_only && [[ "$is_restricted" != "true" ]]; then continue; fi | |
| 35 | + | if $blocked_only && [[ "$is_blocked" != "true" ]]; then continue; fi | |
| 36 | + | if $allowed_only && { [[ "$is_blocked" == "true" ]] || \ | |
| 37 | + | [[ "$is_restricted" == "true" ]]; }; then continue; fi | |
| 38 | + | if [[ -n "$filter_rule" && "$rule" != "$filter_rule" ]]; then continue; fi | |
| 39 | + | if [[ -n "$filter_group" ]]; then | |
| 40 | + | local all_groups="${peer_group_map[$client_name]:-}" | |
| 41 | + | [[ "$all_groups" != *"$filter_group"* ]] && continue | |
| 42 | + | fi | |
| 43 | + | ||
| 44 | + | # Resolve status — verbose or simple | |
| 45 | + | local status | |
| 46 | + | if [[ "$_verbose_status" == "true" ]]; then | |
| 47 | + | status=$(peers::format_status_verbose "$client_name" "$pubkey" \ | |
| 48 | + | "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts" | \ | |
| 49 | + | sed 's/\x1b\[[0-9;]*m//g') | |
| 50 | + | else | |
| 51 | + | local state | |
| 52 | + | state=$(peers::connection_state "$is_blocked" "$is_restricted" "$handshake_ts" "$last_ts") | |
| 53 | + | status="${state%%|*}" | |
| 54 | + | fi | |
| 55 | + | ||
| 56 | + | # Resolve last seen | |
| 57 | + | local last_seen="-" | |
| 58 | + | if [[ "$is_blocked" == "true" && -n "$last_ts" && "$last_ts" != "0" ]]; then | |
| 59 | + | local attempt_ts | |
| 60 | + | attempt_ts=$(json::iso_to_ts "$last_ts") | |
| 61 | + | last_seen="$(fmt::datetime_short "$attempt_ts") (dropped)" | |
| 62 | + | elif [[ -n "$handshake_ts" && "$handshake_ts" != "0" ]]; then | |
| 63 | + | local ts_display | |
| 64 | + | ts_display=$(fmt::datetime_short "$handshake_ts") | |
| 65 | + | if [[ "$status" == "online"* ]]; then | |
| 66 | + | last_seen="${ts_display} (handshake)" | |
| 67 | + | else | |
| 68 | + | last_seen="$ts_display" | |
| 69 | + | fi | |
| 70 | + | fi | |
| 71 | + | ||
| 72 | + | printf "%s|%s|%s|%s|%s|%s|%s|%s|%s\n" \ | |
| 73 | + | "$client_name" "$ip" "$type" \ | |
| 74 | + | "${rule:--}" "${group:--}" \ | |
| 75 | + | "$status" "$last_seen" \ | |
| 76 | + | "$is_blocked" "$is_restricted" | |
| 77 | + | done | |
| 78 | + | } | |
Новіше
Пізніше