User Restrictions module for ProcessWire
This module provides additional restrictions for users. As of this writing it can be used to restrict login attempts to the admin using a predefined set of IPs or geolocations.
Note: geolocation data is fetched from an external API, which may require credentials. This feature has been built with ipgeolocation.io in mind, but should technically work with any other service as well — as long as said service returns data in JSON format.
Configuration settings are defined via $config->UserRestrictions:
$config->UserRestrictions = [
'login_restriction_enabled' => !$this->config->debug,
'login_restriction_enabled_for' => [
// array containing users that are restricted; supported formats:
// 'my_admin_username' or 'user:my_admin_user' (username)
// 41 or 'user:41' (user ID)
// 'role:superuser' (role)
// 'regex:/.*/' (regex pattern, which is matched against username)
],
'valid_ip_addresses' => [
// list of valid IP addresses; supported formats:
// '127.0.0.1' (individual IP)
// '127.0.0.1-127.0.0.255' (IP range)
// '127.0.0.0/24' (CIDR)
],
'valid_geolocations' => [
// list of valid geolocations; supported formats:
// 'Finland' or 'country:Finland' (country)
// 'prefix:value' (any other valid geolocation data key)
],
'geolocation_api_url' => 'https://api.ipgeolocation.io/v2/ipgeo?apiKey={api_key}&ip={ip}',
'geolocation_api_key' => '',
'display_errors' => false,
'log_errors' => true,
];
Install and use modules at your own risk. Always have a site and database backup before installing new modules.