Skip to content
Snippets Groups Projects
Commit 16e00c4b authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Issue #3328610 by grevil, anybody: Document optional dependency "ip2country"

parent 968bb5b3
No related branches found
No related tags found
No related merge requests found
Pipeline #378034 passed
Whitelisting IPs in settings.php
# Whitelisting IPs in settings.php
Settings can be whitelisted in settings.php by creating the following array
containing each IP addresses to be whitelisted.
$config['restrict_ip.settings']['ip_whitelist'] = [
'111.111.111.1',
'111.111.111.2',
];
######################################
#
# Questions and Answers
#
######################################
Question: I locked myself out of my site, what do I do?
## Table of Contents
* About
* Installation
* Configuration
* Questions and Answers
* Support
Answer: Open add the following line to sites/default/settings.php
## About
$config['restrict_ip.settings']['enable'] = FALSE;
This module allows administrators to restrict access to the site to an
administrator defined set of IP addresses. Anyone trying to access the site
from an IP address not in the list of allowed IP addresses will be redirected
to access denied page with the message "Your address is not in the list of
allowed IP addresses". No blocks will be rendered, and no JavaScript will be
added to the page. This will happen for any and all pages these users try to
access. The module also has various configuration options to whitelist or
blacklist pages, bypass IP checking by role, and alter the output when the
user is blocked.
You will now be able to access the site (as will anyone else). Go to the
configuration page, and fix your settings. Remove this code when you are
finished.
## Installation
--------------------------------------------
Install the UI Patterns Setting module as you would normally install a
contributed Drupal module. Visit https://www.drupal.org/node/1897420.
Question: I want to redirect users to a different site when they do not have
access. How can I do this?
## Configuration
Answer: You will need to write some code for this. The easiest way is in your
theme (though it can also be done in a custom module).
Settings can be whitelisted in settings.php by creating the following array
containing each IP addresses to be whitelisted.
First, you'll need the theme key of your theme. This will be the name of the
folder that your theme lies in. My examples below will be for a fictional theme,
jaypanify.
$config['restrict_ip.settings']['ip_whitelist'] = [
'111.111.111.1',
'111.111.111.2',
];
Next, open up the file named template.php in your theme. If this file does not
exist, you can create it (though most themes will already have it). At the
bottom of this file, add the hook below, changing 'hook' to your actual theme
key, and changing the link from google.com to the URL to which you want to
redirect your users:
### Modules that expand on restrict IP
1. [IP-based Determination of a Visitor's Country](https://www.drupal.org/project/ip2country)
> This module uses a visitor's IP address to identify the geographical location (country)
> of the user. The module makes this determination and stores the result as an
> ISO 3166 2-character country code in the Drupal $user object, but otherwise
> has no effect on the operation of your site. The intent is simply to provide
> the information for use by other modules. A function is also provided for you
> to perform your own lookup, to use in your own manner. Features
> include automatic updates of the IP-country database and admin spoofing
> of an arbitrary IP or Country for testing purposes.
## Questions and Answers
1. Question: I locked myself out of my site, what do I do?
* Answer: Open add the following line to sites/default/settings.php
* $config['restrict_ip.settings']['enable'] = FALSE;
* You will now be able to access the site (as will anyone else).
* Go to the configuration page, and fix your settings.
* Remove this code when you are finished.
2. Question: I want to redirect users to a different site when they do not have
access. How can I do this?
* Answer: You will need to write some code for this. The easiest way is in your
theme (though it can also be done in a custom module).
* First, you'll need the theme key of your theme. This will be the name of the
folder that your theme lies in. My examples below will be for a fictional theme,
jaypanify.
* Next, open up the file named template.php in your theme. If this file does not
exist, you can create it (though most themes will already have it). At the
bottom of this file, add the hook below, changing 'hook' to your actual theme
key, and changing the link from Google.com to the URL to which you want to
redirect your users:
function hook_restrict_ip_access_denied_page_alter(&$page)
{
$response = new \Symfony\Component\HttpFoundation\RedirectResponse('https://www.google.com/');
$response->send();
$response = new \Symfony\Component\HttpFoundation\RedirectResponse('https://www.google.com/');
$response->send();
}
Clear your Drupal cache, and the redirect should work.
--------------------------------------------
Question: I want to alter the access denied page. How can I do this?
Answer: It depends on whether you want to add to this page, remove from it, or
alter it. However, whichever it is, all methods work under the same principle.
* Clear your Drupal cache, and the redirect should work.
First, you'll need the key of your theme (see the previous question for
directions on how to get this). Next you'll need to open template.php, and add
one of the following snippets to this file. Note that you will need to change
'hook' to the actual name of your theme.
3. Question: I want to alter the access denied page. How can I do this?
* Answer: It depends on whether you want to add to this page, remove from it, or
alter it. However, whichever it is, all methods work under the same principle.
* First, you'll need the key of your theme (see the previous question for
directions on how to get this). Next you'll need to open template.php, and add
one of the following snippets to this file. Note that you will need to change
'hook' to the actual name of your theme.
***
......@@ -81,7 +103,7 @@ function hook_restrict_ip_access_denied_page_alter(&$page)
***
REMOVING from the page:
The following example shows how to remove the logout link for logged in users
The following example shows how to remove the logout link for logged-in users
who are denied access
function hook_restrict_ip_access_denied_page_alter(&$page)
......@@ -113,7 +135,7 @@ function jaypanify_restrict_ip_access_denied_page_alter(&$page)
}
}
--------------------------------------------------------
## Support
If you are having troubles with any of the above recipes, please open a support
ticket in the module issue queue:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment