You are here

README.txt in Restrict IP 8

Same filename and directory in other branches
  1. 8.2 README.txt
  2. 7.2 README.txt
  3. 3.x README.txt
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?

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.

--------------------------------------------

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();
}

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.

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 acutal name of your theme.

***

ADDING to the page:
The following example shows how to add a new element to the page

function hook_restrict_ip_access_denied_page_alter(&$page)
{
  // note that 'some_key' is arbitrary, and you should use something descriptive instead
  $page['some_key'] = [
    '#markup' => t('This is some markup which I would like to add'),
    '#prefix' => '<p>', // You can use any tag you want here,
    '#suffix' => '</p>', // the closing tag needs to match the #prefix tag
  ];
}

***

REMOVING from the page:
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)
{
  if(isset($page['logout_link']))
  {
    unset($page['logout_link']);
  }
}

***

ALTERING the page:
As of the time of writing, this module provides the following keys that can be altered:
* access_denied
* contact_us (may not exist, depending on the module configuration)
* logout_link (may not exist, depending on the module configuration)
* login_link (may not exist, depending on the module configuration)

The following example shows how to change the text of the 'access denied' message to your own custom message

function jaypanify_restrict_ip_access_denied_page_alter(&$page)
{
  if(isset($page['access_denied']))
  {
  	$page['access_denied'] = t('My custom access denied message');
  }
}

--------------------------------------------------------

If you are having troubles with any of the above recipes, please open a support ticket in the
module issue queue: https://drupal.org/project/issues/search/restrict_ip

Please list the following:

1) What you are trying to achieve
2) The code you have tried that isn't working
3) A description of how it is not working

File

README.txt
View source
  1. Whitelisting IPs in settings.php
  2. Settings can be whitelisted in settings.php by creating the following array
  3. containing each IP addresses to be whitelisted.
  4. $config['restrict_ip.settings']['ip_whitelist'] = [
  5. '111.111.111.1',
  6. '111.111.111.2',
  7. ];
  8. ######################################
  9. #
  10. # Questions and Answers
  11. #
  12. ######################################
  13. Question: I locked myself out of my site, what do I do?
  14. Answer: Open add the following line to sites/default/settings.php
  15. $config['restrict_ip.settings']['enable'] = FALSE;
  16. You will now be able to access the site (as will anyone else). Go to the configuration page,
  17. and fix your settings. Remove this code when you are finished.
  18. --------------------------------------------
  19. Question: I want to redirect users to a different site when they do not have access.
  20. How can I do this?
  21. Answer: You will need to write some code for this. The easiest way is in your theme
  22. (though it can also be done in a custom module).
  23. First, you'll need the theme key of your theme. This will be the name of the folder
  24. that your theme lies in. My examples below will be for a fictional theme, jaypanify.
  25. Next, open up the file named template.php in your theme. If this file does not exist,
  26. you can create it (though most themes will already have it). At the bottom of this file,
  27. add the hook below, changing 'hook' to your actual theme key, and changing the link
  28. from google.com to the URL to which you want to redirect your users:
  29. function hook_restrict_ip_access_denied_page_alter(&$page)
  30. {
  31. $response = new \Symfony\Component\HttpFoundation\RedirectResponse('https://www.google.com/');
  32. $response->send();
  33. }
  34. Clear your Drupal cache, and the redirect should work.
  35. --------------------------------------------
  36. Question: I want to alter the access denied page. How can I do this?
  37. Answer: It depends on whether you want to add to this page, remove from it, or alter it. However,
  38. whichever it is, all methods work under the same principle.
  39. First, you'll need the key of your theme (see the previous question for directions on how to get this).
  40. Next you'll need to open template.php, and add one of the following snippets to this file. Note that you
  41. will need to change 'hook' to the acutal name of your theme.
  42. ***
  43. ADDING to the page:
  44. The following example shows how to add a new element to the page
  45. function hook_restrict_ip_access_denied_page_alter(&$page)
  46. {
  47. // note that 'some_key' is arbitrary, and you should use something descriptive instead
  48. $page['some_key'] = [
  49. '#markup' => t('This is some markup which I would like to add'),
  50. '#prefix' => '

    ', // You can use any tag you want here,

  51. '#suffix' => '

    ', // the closing tag needs to match the #prefix tag
  52. ];
  53. }
  54. ***
  55. REMOVING from the page:
  56. The following example shows how to remove the logout link for logged in users who are denied access
  57. function hook_restrict_ip_access_denied_page_alter(&$page)
  58. {
  59. if(isset($page['logout_link']))
  60. {
  61. unset($page['logout_link']);
  62. }
  63. }
  64. ***
  65. ALTERING the page:
  66. As of the time of writing, this module provides the following keys that can be altered:
  67. * access_denied
  68. * contact_us (may not exist, depending on the module configuration)
  69. * logout_link (may not exist, depending on the module configuration)
  70. * login_link (may not exist, depending on the module configuration)
  71. The following example shows how to change the text of the 'access denied' message to your own custom message
  72. function jaypanify_restrict_ip_access_denied_page_alter(&$page)
  73. {
  74. if(isset($page['access_denied']))
  75. {
  76. $page['access_denied'] = t('My custom access denied message');
  77. }
  78. }
  79. --------------------------------------------------------
  80. If you are having troubles with any of the above recipes, please open a support ticket in the
  81. module issue queue: https://drupal.org/project/issues/search/restrict_ip
  82. Please list the following:
  83. 1) What you are trying to achieve
  84. 2) The code you have tried that isn't working
  85. 3) A description of how it is not working