From 8f2b11f672c3d8387938bfab930951c17f8efdcc Mon Sep 17 00:00:00 2001 From: yandexru45 Date: Sat, 14 Mar 2026 14:56:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B3=D1=80=D1=83=D0=BF=D0=BF=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- podkop/files/usr/bin/podkop | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/podkop/files/usr/bin/podkop b/podkop/files/usr/bin/podkop index b88fa6b..d3d2f30 100755 --- a/podkop/files/usr/bin/podkop +++ b/podkop/files/usr/bin/podkop @@ -864,6 +864,19 @@ sing_box_build_subscription_country_groups() { ' 2>/dev/null } +is_truthy_option() { + local value="$1" + + case "$value" in + 1|true|TRUE|True|on|ON|yes|YES|enabled|ENABLED) + return 0 + ;; + *) + return 1 + ;; + esac +} + configure_outbound_handler() { local section="$1" @@ -962,13 +975,25 @@ configure_outbound_handler() { log "Detected proxy configuration type: subscription" "debug" local subscription_url subscription_json_path urltest_tag selector_tag \ urltest_outbounds selector_outbounds urltest_check_interval urltest_tolerance \ - urltest_testing_url subscription_group_by_countries + urltest_testing_url subscription_group_by_countries subscription_group_by_countries_raw config_get subscription_url "$section" "subscription_url" config_get urltest_check_interval "$section" "urltest_check_interval" "3m" config_get urltest_tolerance "$section" "urltest_tolerance" 50 config_get urltest_testing_url "$section" "urltest_testing_url" "https://www.gstatic.com/generate_204" - config_get_bool subscription_group_by_countries "$section" "subscription_group_by_countries" 0 + config_get subscription_group_by_countries_raw "$section" "subscription_group_by_countries" "" + if [ -z "$subscription_group_by_countries_raw" ]; then + # Backward-compatible alias in case custom builds used another key + config_get subscription_group_by_countries_raw "$section" "group_by_countries" "" + fi + + if is_truthy_option "$subscription_group_by_countries_raw"; then + subscription_group_by_countries=1 + else + subscription_group_by_countries=0 + fi + + log "Subscription country grouping for section '$section': raw='${subscription_group_by_countries_raw:-}', enabled=$subscription_group_by_countries" "debug" if [ -z "$subscription_url" ]; then log "Subscription URL is not set. Aborted." "fatal" @@ -1029,7 +1054,7 @@ configure_outbound_handler() { if [ "$subscription_group_by_countries" -eq 1 ]; then local grouping_json country_flag country_group_outbounds country_group_tag \ - selector_outbound_tags selector_default ungrouped_outbound_tags + selector_outbound_tags selector_default ungrouped_outbound_tags grouped_count ungrouped_count grouping_json="$(sing_box_build_subscription_country_groups "$SUBSCRIPTION_OUTBOUND_TAGS")" if [ -z "$grouping_json" ]; then @@ -1037,6 +1062,10 @@ configure_outbound_handler() { exit 1 fi + grouped_count="$(echo "$grouping_json" | jq -r '.country_order | length' 2>/dev/null)" + ungrouped_count="$(echo "$grouping_json" | jq -r '.ungrouped | length' 2>/dev/null)" + log "Country grouping prepared for section '$section': groups=$grouped_count, ungrouped=$ungrouped_count" "debug" + for country_flag in $(echo "$grouping_json" | jq -r '.country_order[]' 2>/dev/null); do country_group_outbounds="$(echo "$grouping_json" | jq -c --arg country_flag "$country_flag" '.country_groups[$country_flag] // []' 2>/dev/null)" if [ -z "$country_group_outbounds" ] || [ "$country_group_outbounds" = "[]" ]; then