nuno revisou este gist 1 month ago. Ir para a revisão
1 file changed, 58 insertions
gistfile1.txt(arquivo criado)
| @@ -0,0 +1,58 @@ | |||
| 1 | + | function cmd::list::_precompute_all() { | |
| 2 | + | # Peer data | |
| 3 | + | declare -gA p_ips=() p_rules=() p_subtypes=() p_last_ts=() p_last_evt=() | |
| 4 | + | while IFS="|" read -r name ip rule subtype last_ts last_evt; do | |
| 5 | + | [[ -z "$name" ]] && continue | |
| 6 | + | p_ips["$name"]="$ip" | |
| 7 | + | p_rules["$name"]="${rule:-—}" | |
| 8 | + | p_subtypes["$name"]="$subtype" | |
| 9 | + | p_last_ts["$name"]="$last_ts" | |
| 10 | + | p_last_evt["$name"]="$last_evt" | |
| 11 | + | done < <(json::peer_data "$(ctx::clients)" "$(ctx::meta)" "$(ctx::events_log)") | |
| 12 | + | ||
| 13 | + | # WireGuard handshakes + endpoints | |
| 14 | + | declare -gA wg_handshakes=() wg_endpoints=() | |
| 15 | + | while IFS=$'\t' read -r pubkey ts; do | |
| 16 | + | [[ -n "$pubkey" ]] && wg_handshakes["$pubkey"]="$ts" | |
| 17 | + | done < <(wg show "$(config::interface)" latest-handshakes 2>/dev/null) | |
| 18 | + | while IFS=$'\t' read -r pubkey endpoint; do | |
| 19 | + | [[ -n "$pubkey" ]] && wg_endpoints["$pubkey"]="$endpoint" | |
| 20 | + | done < <(wg show "$(config::interface)" endpoints 2>/dev/null) | |
| 21 | + | ||
| 22 | + | # Block/restricted status | |
| 23 | + | declare -gA p_blocked=() p_restricted=() | |
| 24 | + | cmd::list::_precompute_block_status p_blocked p_restricted | |
| 25 | + | ||
| 26 | + | # Public keys | |
| 27 | + | declare -gA p_pubkeys=() | |
| 28 | + | local dir | |
| 29 | + | dir="$(ctx::clients)" | |
| 30 | + | for kf in "${dir}"/*_public.key; do | |
| 31 | + | [[ -f "$kf" ]] || continue | |
| 32 | + | local kname | |
| 33 | + | kname=$(basename "$kf" _public.key) | |
| 34 | + | p_pubkeys["$kname"]=$(cat "$kf" 2>/dev/null || echo "") | |
| 35 | + | done | |
| 36 | + | ||
| 37 | + | # Groups | |
| 38 | + | has_groups=false | |
| 39 | + | declare -gA peer_group_map=() | |
| 40 | + | local groups_dir | |
| 41 | + | groups_dir="$(ctx::groups)" | |
| 42 | + | local group_files=("${groups_dir}"/*.group) | |
| 43 | + | if [[ -f "${group_files[0]}" ]]; then | |
| 44 | + | has_groups=true | |
| 45 | + | while IFS=":" read -r peer_name group_name; do | |
| 46 | + | [[ -n "$peer_name" ]] && peer_group_map["$peer_name"]="$group_name" | |
| 47 | + | done < <(json::peer_group_map "$groups_dir") | |
| 48 | + | fi | |
| 49 | + | ||
| 50 | + | # Transfer/activity data — keyed by pubkey | |
| 51 | + | declare -gA p_rx=() p_tx=() p_activity=() | |
| 52 | + | while IFS="|" read -r pubkey rx tx level; do | |
| 53 | + | [[ -z "$pubkey" ]] && continue | |
| 54 | + | p_rx["$pubkey"]="$rx" | |
| 55 | + | p_tx["$pubkey"]="$tx" | |
| 56 | + | p_activity["$pubkey"]="$level" | |
| 57 | + | done < <(json::peer_transfer "$(config::interface)") | |
| 58 | + | } | |
Próximo
Anterior