advban.module in Advanced ban 8
Allows to ban individual or range IP addresses.
File
advban.moduleView source
<?php
/**
* @file
* Allows to ban individual or range IP addresses.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function advban_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.advban':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Advanced Ban module allows administrators to ban visits to their site from individual or range IP addresses.') . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dl>';
$output .= '<dt>' . t('Banning IP addresses: individual or range.') . '</dt>';
$output .= '<dt>' . t('Addig expiry dates to blocked IP addresses and unblocking them after a certain amount of time.') . '</dt>';
$output .= '<dt>' . t('Uses Blacklist or whitelist, where blacklisted IPs are denied from the site, and whitelisted are allowed. Whitelists always override blacklists.') . '</dt>';
$output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [
':bans' => Url::fromRoute('advban.admin_page')
->toString(),
]) . '</dd>';
$output .= '</dl>';
return $output;
case 'advban.admin_page':
return '<p>' . t('IP addresses (individual or range) listed here are banned from your site. Banned addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation. Banned addresses can be unblocked after expiration.') . '</p>';
}
}
/**
* Implements hook_cron().
*/
function advban_cron() {
$unbannedIp = \Drupal::service('advban.ip_manager')
->unblockExpiredIp();
if ($unbannedIp > 0) {
\Drupal::logger('advanced ban')
->notice('Unbanned expired IP count: %count', [
'%count' => $unbannedIp,
]);
}
}
Functions
Name | Description |
---|---|
advban_cron | Implements hook_cron(). |
advban_help | Implements hook_help(). |