rah_ip_range
Published under current TXP projects
Elegant Textpattern CMS plugin for blocking and allowing visitors based on their IP. You can define an IP range, and what to do to those whose IP is within the range; either allow, or the opposite, deny access to the page content. Powered by a single little tag.
Image: rah_ip_range
List of features
- Deny and allow visitors with IP ranges.
- Comes with a simple customizable tag,
<txp:rah_ip_range />. Include the tag anywhere on your page templates and forms, where you want the blocking take place. - Blocked visitors will see Textpattern’s native, customizable error page. Error messages and returned error status is fully configurable.
- Alternatively the tag can be used as a container. When container is used, the contained content is hidden from blocked visitors, instead of showing an error page.
Attributes
The tag is <txp:rah_ip_range /> attributes for it follow. Use the tag on places (pages/forms/sections) which you want to restrict from specific visitors.
message
Error message shown to blocked visitors. Message can be shown with the <txp:error_message /> tag. If the tag is used as a container, the message is shown instead of the contained content to the blocked users.
Default: message="Access denied" Example: "Sorry, we can not do that."
status
HTTP error status code returned to blocked visitors. The preferences will be ignored when the tag is used as a container.
Default: status="503" Example: "200"
fromip
IP-range’s starting IP (or partial IP). Default is unset.
Default: fromip="" Example: "127.0.0.1"
toip
IP-range’s ending IP (or partial IP). Default is unset.
Default: toip="" Example: "127.0.0.100"
method
Sets what to do to the visitor when IP is within the range. Either deny or allow. When set to deny, all visitors within the range are blocked, and others outside the range are allowed to see the content. Value allow is opposite to the deny.
Default: method="allow" Example: "deny"
Examples
Example #1: Using the self-closing single tag.
<txp:rah_ip_range fromip="127.0.0.1" toip="127.0.0.100" method="deny" />
Visitors within the range 127.0.0.1-127.0.0.100 are blocked will see an error page.
Example #2: Using the tags as a container.
Important link:
<txp:rah_ip_range fromip="127.0.0.1" toip="127.0.0.100" method="allow" message="Link is hidden.">
<a href="http://example.com">Click here</a>.
</txp: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 should be.
Changelog
Version 0.3
- Changed: parsing contents of
messageisn’t needed. Parser’s straight quote feature can be used instead. - Changed: pass parameters to
txp_die()as strings instead of an array.
Version 0.2
- Added: container tag mode.
Version 0.1
- Initial release.