From bcab66f88c1f81a1dfa2eecb66d89692e9749d94 Mon Sep 17 00:00:00 2001 From: Ivan K Date: Wed, 21 May 2025 09:48:53 +0300 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(podkop):=20enhanc?= =?UTF-8?q?e=20check=5Fnft=20function=20for=20domain-specific=20set=20stat?= =?UTF-8?q?istics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- podkop/files/usr/bin/podkop | 79 ++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 27 deletions(-) diff --git a/podkop/files/usr/bin/podkop b/podkop/files/usr/bin/podkop index 52be61d..43789ea 100755 --- a/podkop/files/usr/bin/podkop +++ b/podkop/files/usr/bin/podkop @@ -1890,31 +1890,60 @@ check_nft() { return 1 fi - # List of possible sets - local sets="podkop_subnets podkop_domains interfaces podkop_discord_subnets localv4" + local found_hetzner=0 + local found_ovh=0 - echo "Sets statistics:" - for set_name in $sets; do - if nft list set inet PodkopTable $set_name >/dev/null 2>&1; then - # Count elements using grep to count commas and add 1 (last element has no comma) - local count=$(nft list set inet PodkopTable $set_name 2>/dev/null | grep -o ',\|{' | wc -l) - echo "- $set_name: $count elements" + check_domain_list_contains() { + local section="$1" + + config_get_bool domain_list_enabled "$section" "domain_list_enabled" "0" + if [ "$domain_list_enabled" -eq 1 ]; then + config_list_foreach "$section" "domain_list" check_domain_value fi - done + } + + check_domain_value() { + local domain_value="$1" + + if [ "$domain_value" = "hetzner" ]; then + found_hetzner=1 + elif [ "$domain_value" = "ovh" ]; then + found_ovh=1 + fi + } + + config_foreach check_domain_list_contains + + if [ "$found_hetzner" -eq 1 ] || [ "$found_ovh" -eq 1 ]; then - echo "" - echo "Chain configurations:" - - # Create a temporary file for processing - local tmp_file=$(mktemp) - nft list table inet PodkopTable > "$tmp_file" - - # Extract chain configurations without element listings - sed -n '/chain mangle {/,/}/p' "$tmp_file" | grep -v "elements" | grep -v "^[[:space:]]*[0-9]" - sed -n '/chain proxy {/,/}/p' "$tmp_file" | grep -v "elements" | grep -v "^[[:space:]]*[0-9]" - - # Clean up - rm -f "$tmp_file" + local sets="podkop_subnets podkop_domains interfaces podkop_discord_subnets localv4" + + nolog "Sets statistics:" + for set_name in $sets; do + if nft list set inet PodkopTable $set_name >/dev/null 2>&1; then + # Count elements using grep to count commas and add 1 (last element has no comma) + local count=$(nft list set inet PodkopTable $set_name 2>/dev/null | grep -o ',\|{' | wc -l) + echo "- $set_name: $count elements" + fi + done + + nolog "Chain configurations:" + + # Create a temporary file for processing + local tmp_file=$(mktemp) + nft list table inet PodkopTable > "$tmp_file" + + # Extract chain configurations without element listings + sed -n '/chain mangle {/,/}/p' "$tmp_file" | grep -v "elements" | grep -v "^[[:space:]]*[0-9]" + sed -n '/chain proxy {/,/}/p' "$tmp_file" | grep -v "elements" | grep -v "^[[:space:]]*[0-9]" + + # Clean up + rm -f "$tmp_file" + else + # Simple view as originally implemented + nolog "Sets configuration:" + nft list table inet PodkopTable + fi nolog "NFT check completed" } @@ -2389,11 +2418,7 @@ global_check() { print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━" print_global "🧱 NFT table" - if ! nft list table inet PodkopTable >/dev/null 2>&1; then - print_global "❌ PodkopTable not found" - else - check_nft - fi + check_nft print_global "━━━━━━━━━━━━━━━━━━━━━━━━━━━" print_global "📄 WAN config"