Problem/Motivation
The original request was to restrict access by country using an IP database such as MaxMind, because entering every range for a country by hand is not practical.
Rather than integrating any particular database, this module should provide an extension point so other modules can supply or adjust IP ranges from whatever source they like: settings.php, an external list, or a country database.
Proposed resolution
Add hook_restrict_by_ip_ranges_alter(), plus type-specific variants, letting modules alter each allow list before it is applied:
- the global login ranges,
- each user's ranges,
- each role's ranges, including roles with no ranges configured.
The allow/deny decision itself stays in this module: after altering, an empty list means the context is unrestricted, and a non-empty list means the request IP must match one of the ranges.
Country-level restriction is possible by implementing the hook in a module that maintains country ranges from an IP database. A point-lookup integration (querying a geo service per request) is out of scope here and better suited to a dedicated module.
API changes
New hooks: hook_restrict_by_ip_ranges_alter(), hook_restrict_by_ip_login_global_ranges_alter(), hook_restrict_by_ip_login_user_ranges_alter(), hook_restrict_by_ip_role_ranges_alter(). Documented in restrict_by_ip.api.php.
Issue fork restrict_by_ip-3419590
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybodyI guess defining the white-listed IPs should be possible through settings.php, which could then retrieve the IPs from outside? Alternatively maybe a service could be used?
Comment #3
darvanenClosing as a duplicate of #3283846: Store per user IP range in database instead of config
Comment #5
darvanenOn second thoughts, #3283846: Store per user IP range in database instead of config is different. Reopening this ticket as the place to handle providing extension points for this kind of request.
Comment #6
darvanenComment #7
darvanenComment #9
darvanenComment #10
darvanenComment #11
darvanenCame back with fresh eyes and had a read, happy with this.
Comment #13
darvanen