diff --git a/geoip_shop_manager.py b/geoip_shop_manager.py index 1a83204..c761aa4 100644 --- a/geoip_shop_manager.py +++ b/geoip_shop_manager.py @@ -10,7 +10,7 @@ Supports three modes: - php-only: GeoIP blocking without CrowdSec - bot-only: Block only bots, shop remains globally accessible -v3.2.0: Added bot-only blocking mode +v3.3.0: Added option to activate only direct shops (not behind Link11) """ import os @@ -795,6 +795,26 @@ def uses_crowdsec(mode): return mode in ['php+crowdsec', 'bot+crowdsec'] +def get_direct_shops(available_shops): + """Return list of shops that are NOT behind Link11 (direct exposure)""" + direct_shops = [] + for shop in available_shops: + link11_info = check_link11(shop) + if not link11_info['is_link11']: + direct_shops.append(shop) + return direct_shops + + +def get_link11_shops(available_shops): + """Return list of shops that ARE behind Link11""" + link11_shops = [] + for shop in available_shops: + link11_info = check_link11(shop) + if link11_info['is_link11']: + link11_shops.append(shop) + return link11_shops + + # ============================================================================= # MAIN FUNCTIONS # ============================================================================= @@ -1129,6 +1149,153 @@ def activate_all_shops(): print(f"{'=' * 60}") +def activate_direct_shops_only(): + """Activate blocking only for shops that are NOT behind Link11 (direct exposure)""" + available_shops = [s for s in get_available_shops() if s not in get_active_shops()] + + if not available_shops: + print("\n⚠️ Keine Shops zum Aktivieren verfügbar") + return + + # Filter: only shops NOT behind Link11 + direct_shops = get_direct_shops(available_shops) + link11_shops = get_link11_shops(available_shops) + + if not direct_shops: + print("\n⚠️ Keine direkten Shops gefunden (alle sind hinter Link11)") + if link11_shops: + print(f"\n📋 {len(link11_shops)} Shop(s) hinter Link11 (werden übersprungen):") + for shop in link11_shops: + print(f" {COLOR_GREEN}• {shop} [Link11]{COLOR_RESET}") + return + + print(f"\n{'=' * 60}") + print(f" Blocking für DIREKTE Shops aktivieren (ohne Link11)") + print(f"{'=' * 60}") + print(f" {COLOR_GREEN}Grün = hinter Link11 (übersprungen){COLOR_RESET}") + print(f" {COLOR_RED}Rot = Direkt (wird aktiviert){COLOR_RESET}") + + print(f"\n📋 {len(direct_shops)} direkte Shop(s) werden aktiviert:") + for shop in direct_shops: + print(f" {COLOR_RED}• {shop} [Direkt]{COLOR_RESET}") + + if link11_shops: + print(f"\n⏭️ {len(link11_shops)} Shop(s) hinter Link11 werden übersprungen:") + for shop in link11_shops: + print(f" {COLOR_GREEN}• {shop} [Link11]{COLOR_RESET}") + + mode = select_mode() + is_bot_mode = is_bot_only_mode(mode) + + if is_bot_mode: + geo_region = "none" + region_info = get_geo_region_info("none") + else: + geo_region = select_geo_region() + region_info = get_geo_region_info(geo_region) + + print(f"\n⚠️ Modus: {get_mode_description(mode)} {get_mode_icon(mode)}") + if not is_bot_mode: + print(f" Region: {region_info['icon']} {region_info['name']}") + print(f" Aktiviert: {len(direct_shops)} direkte Shop(s)") + print(f" Übersprungen: {len(link11_shops)} Link11-Shop(s)") + + if input(f"\nFortfahren? (ja/nein): ").strip().lower() not in ['ja', 'j', 'yes', 'y']: + print("\n❌ Abgebrochen") + return + + print(f"\n{'=' * 60}") + + if uses_crowdsec(mode) and check_crowdsec(): + if not [s for s in get_active_shops() if uses_crowdsec(get_shop_mode(s))]: + print("\n📦 Installiere CrowdSec-Watcher-Service...") + install_watcher_service() + + success_count = 0 + for i, shop in enumerate(direct_shops, 1): + print(f"\n[{i}/{len(direct_shops)}] {shop}") + + httpdocs = os.path.join(VHOSTS_DIR, shop, 'httpdocs') + index_php = os.path.join(httpdocs, 'index.php') + backup_php = os.path.join(httpdocs, f'index.php{BACKUP_SUFFIX}') + blocking_file = os.path.join(httpdocs, BLOCKING_FILE) + + if os.path.isfile(backup_php) or not os.path.isfile(index_php): + print(f" ⚠️ Übersprungen") + continue + + shutil.copy2(index_php, backup_php) + + with open(index_php, 'r', encoding='utf-8') as f: + content = f.read() + lines = content.split('\n') + insert_line = 0 + for idx, line in enumerate(lines): + if 'declare(strict_types' in line: + insert_line = idx + 1 + break + elif '