diff --git a/geoip_handler.py b/geoip_handler.py index 1177aab..09e1115 100644 --- a/geoip_handler.py +++ b/geoip_handler.py @@ -1198,27 +1198,13 @@ class ConfigGenerator: config += "# " + "="*77 + "\n" config += "\n" - # MAP BODY (aggregate per country to preserve country mapping) - for country, nets in sorted(country_networks.items()): - if aggregate: - nets = ConfigGenerator._aggregate_networks(nets) - else: - nets = sorted(set(nets)) + # MAP BODY + for network in all_networks: + country = next((c for c, nets in country_networks.items() if network in nets), 'XX') + config += f"{network} {country}\n" - for network in nets: - config += f"{network} {country}\n" + return config - if redis_ips: - redis_list = list(redis_ips) - if aggregate: - redis_list = ConfigGenerator._aggregate_networks(redis_list) - else: - redis_list = sorted(set(redis_list)) - - for network in redis_list: - config += f"{network} REDIS\n" - - return config @staticmethod def generate_haproxy_lua(country_networks: dict, aggregate: bool = True, redis_ips: set = None) -> str: