Country Ban Request

Created on 15 May 2025, 22 days ago

Problem/Motivation

The Advanced Ban module currently provides IP-based banning but lacks the functionality to conveniently ban entire countries. Administrators have to manually input extensive IP ranges, making management cumbersome and inefficient.

Steps to reproduce

  1. Attempt to block all IP addresses from a specific country.
  2. Observe that there is no simple interface or method to ban by country.
  3. Administrators must manually compile and input IP addresses, leading to potential errors and inefficiency.

Proposed resolution

  • Integrate NirSoft's Country IP database (https://www.nirsoft.net/countryip/) into the Advanced Ban module.
  • Provide an admin interface for importing and regularly syncing IP ranges based on country selection.
  • Allow administrators to select countries to ban/unban through a simplified UI.

Remaining tasks

  • Evaluate the NirSoft IP database for feasibility and compatibility.
  • Design and implement the administrative interface.
  • Develop synchronization or import mechanisms for IP ranges.
  • Ensure performance optimizations to handle large datasets.
  • Testing and validation.

User interface changes

  • Add a new section or tab within the Advanced Ban module admin settings for country-based banning.
  • Provide intuitive controls for selecting countries and managing country-based ban rules.

API changes

No significant API changes anticipated beyond the necessary hooks for IP range synchronization and administration.

Data model changes

Introduction of new tables or configurations to store country-based IP ranges and corresponding ban settings.

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands ndf Amsterdam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @ndf
  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    Hi, Niels
    Thanks for your proposition
    I think we could use ip2country β†’
    I'm not sure if the data on https://www.nirsoft.net/countryip/ is up to date, and the Drupal module seems pretty easy to use.

  • πŸ‡³πŸ‡±Netherlands ndf Amsterdam

    Hi Serhii, yes ip2country module sounds like a better option! So that module already has the IP country data in it and fetches it regularly from ARIN.

    Then we need a module that combines both; i.e. 'advban_ip2country' with a UI for administrators to select banned countries, and code that fetches the country ip-ranges from the ip2country module.

  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    Niels,
    I've installed the ip2country module and applied a patch from https://www.drupal.org/project/ip2country/issues/2571835 ✨ Use HTTP instead of FTP Needs review ( https://www.drupal.org/files/issues/2025-03-24/ip2country-2571835-21.patch β†’ ).

    I think we need to create advban_bycountry submodule of the advban module.
    We can get coutry code for user and check the selected forbidden countries from the module's setings.

    $ip = \Drupal::request()->getClientIp();
    $country_code = \Drupal::service('ip2country.lookup')->getCountry($ip);
    if (in_array($country_code,$forbidded_countries)) {
        // Ban the ip in the middleware class
    } 
    

    We need also to get countries list for settings by combine 2 lists:

    $countries = \Drupal\Core\Locale\CountryManager::getStandardList();
    "SELECT country FROM {ip2country} GROUP BY country"

    I think we need to create a plugins system, then use getDefinitions() and createInstance() for checking all advban extentions.
    After the submodule was completed we will have 2 ways for IP banning: by IP list and by country. What should be the priority?

  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    Niels, it's extremely hard for me - creating forks, merge requests. It's done in an inconvenient and unclear way.
    I've created https://git.drupalcode.org/project/advban/-/merge_requests/8 - please review

  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    goodboy β†’ changed the visibility of the branch 3524654-country_ban_request to hidden.

  • πŸ‡ΊπŸ‡¦Ukraine goodboy Kharkiv, Ukraine

    goodboy β†’ changed the visibility of the branch 3524654-country-ban-request to hidden.

Production build 0.71.5 2024