Rah_ip_range is a Textpattern CMS plugin for restricting visitors’ access to certain parts of site content based on their IP addresses. The plugin introduces a little Textpattern tag that takes an IP address range and an executed action. The tag can either be used to hide parts of a page template or to invoke a customizable error page.
Using Composer:
$ composer require rah/rah_ip_range
Or download an installer package.
<rah::ip_range deny from="127.0.0.1" to="127.0.0.1">
...contained statements...
</rah::ip_range>
The plugin introduces a new Textpattern tag, <rah::ip_range />
. The tag can be used to restrict visitor’s access to certain parts of page template content or full pages based on their IP address. The tag takes an IP range, set by from
and to
attributes. A visitor that is in the specified range will be either denied or allowed access to the content based on deny
or allow
boolean attribute.
The tag can be used both as a container and as a self-closing single tag. When used as single tag, the tag invokes an error page when the visitor is within denied range. As a container, the tag hides the wrapped content, but doesn’t invoke an error page. A container can also take a else statement, which is served as an alternative content to denied visitors.
message
Error message shown to blocked visitors.
Example: message="Sorry, we can not do that."
Default: "Forbidden."
status
HTTP error status code returned to blocked visitors. The option is ignored when the tag is used as a container.
Example: status="404"
Default: "403"
from
IP-range’s starting IP (or partial IP). Default is unset.
Example: from="127.0.0.1"
Default: ""
to
IP-range’s ending IP (or partial IP). Default is unset.
Example: to="127.0.0.100"
Default: ""
allow
Allow visitors within the specified IP range. This is the default action.
Example: allow
Default: allow
deny
Deny visitors within the specified IP range. Opposite of allow.
Example: deny
Default: undefined
<rah::ip_range deny from="127.0.0.1" to="127.0.0.100" message="Access denied."/>
Visitors within the range of 127.0.0.1-127.0.0.100 are blocked will see an error page.
<rah::ip_range from="127.0.0.1" to="127.0.0.100">
<a href="http://example.com">Important link</a>.
<txp:else />
Link is hidden.
</rah::ip_range>
Visitors within the range 127.0.0.1-127.0.0.100 will see an important link, while others won’t. Instead they are treated with “Link is hidden.” message where the link would be.
- Register the tag for Textpattern >= 4.7.0 compatibility.
- Rename
fromip
tofrom
,toip
toto
, splitmethod
attribute toallow
anddeny
boolean attributes. - Now requires Textpattern >= 4.7.0.
- Added: else (
<txp:else />
) tag support for container mode. - Changed: default HTTP status to 403 Forbidden from 503 Service Unavailable.
- Changed: default message to
Forbidden.
,403_forbidden
l18n string. - Changed:
message
attribute doesn’t apply when tag is used as a container, instead of else can be used.
- Changed: parsing contents of
message
isn’t needed. Parser’s straight quote feature can be used instead. - Changed: pass parameters to
txp_die()
as strings instead of an array.
- Added: container tag mode.
- Initial release.