nuno revisou este gist 1 month ago. Ir para a revisão
1 file changed, 70 insertions
gistfile1.txt(arquivo criado)
| @@ -0,0 +1,70 @@ | |||
| 1 | + | function cmd::inspect::_blocks_info() { | |
| 2 | + | local name="${1:-}" | |
| 3 | + | block::has_file "$name" || return 0 | |
| 4 | + | ||
| 5 | + | local blocked_direct | |
| 6 | + | blocked_direct=$(block::is_blocked_direct "$name") | |
| 7 | + | ||
| 8 | + | local blocked_groups | |
| 9 | + | blocked_groups=$(block::get_groups "$name") | |
| 10 | + | ||
| 11 | + | local rules_output | |
| 12 | + | rules_output=$(block::get_rules "$name") | |
| 13 | + | ||
| 14 | + | # Skip if truly empty | |
| 15 | + | if [[ "$blocked_direct" != "true" ]] && \ | |
| 16 | + | ui::empty "$blocked_groups" && \ | |
| 17 | + | ui::empty "$rules_output"; then | |
| 18 | + | block::cleanup "$name" # clean up stale empty file | |
| 19 | + | return 0 | |
| 20 | + | fi | |
| 21 | + | ||
| 22 | + | # Count rules for header | |
| 23 | + | local rule_count=0 | |
| 24 | + | while IFS= read -r line; do | |
| 25 | + | [[ -n "$line" ]] && (( rule_count++ )) || true | |
| 26 | + | done <<< "$rules_output" | |
| 27 | + | ||
| 28 | + | # Build header like firewall: Blocks (+N) | |
| 29 | + | local header_counts="" | |
| 30 | + | [[ "$rule_count" -gt 0 ]] && header_counts=" (${rule_count})" | |
| 31 | + | [[ "$blocked_direct" == "true" || -n "$blocked_groups" ]] && \ | |
| 32 | + | header_counts="${header_counts} 🚫" | |
| 33 | + | ||
| 34 | + | cmd::inspect::_section "Blocks${header_counts}" | |
| 35 | + | printf "\n" | |
| 36 | + | ||
| 37 | + | [[ "$blocked_direct" == "true" ]] && \ | |
| 38 | + | printf " \033[1;31m🚫\033[0m blocked directly\n" | |
| 39 | + | [[ -n "$blocked_groups" ]] && \ | |
| 40 | + | printf " \033[1;31m🚫\033[0m blocked by groups: %s\n" "$blocked_groups" | |
| 41 | + | ||
| 42 | + | block::format_rules "$name" | |
| 43 | + | return 0 | |
| 44 | + | } | |
| 45 | + | function cmd::inspect::_firewall_info() { | |
| 46 | + | local name="${1:-}" | |
| 47 | + | local ip | |
| 48 | + | ip=$(peers::get_ip "$name") | |
| 49 | + | ||
| 50 | + | local total=0 accepts=0 drops=0 | |
| 51 | + | local rules_output=() | |
| 52 | + | while IFS= read -r line; do | |
| 53 | + | [[ -z "$line" ]] && continue | |
| 54 | + | (( total++ )) || true | |
| 55 | + | [[ "$line" =~ ACCEPT ]] && (( accepts++ )) || true | |
| 56 | + | [[ "$line" =~ DROP ]] && (( drops++ )) || true | |
| 57 | + | rules_output+=("$line") | |
| 58 | + | done < <(fw::forward_rules_for_ip "$ip" | grep -v NFLOG) | |
| 59 | + | ||
| 60 | + | ui::empty "${rules_output[*]}" && return 0 | |
| 61 | + | ||
| 62 | + | printf "\n \033[0;37m── Firewall (%s %s) \033[0m%s\n\n" \ | |
| 63 | + | "$(color::green "+${accepts}")" \ | |
| 64 | + | "$(color::red "-${drops}")" \ | |
| 65 | + | "$(printf '\033[0;37m─%.0s' {1..28})" | |
| 66 | + | ||
| 67 | + | fw::list_peer_rules "$ip" false | |
| 68 | + | ||
| 69 | + | return 0 | |
| 70 | + | } | |
Próximo
Anterior