ip_ban.module in IP Ban 8
Same filename and directory in other branches
Module can "ban" or set site to "read only" by country or IP address.
Permissions, administration menu item, form, form theme, form validation, and code for handling read-only and banned IP addresses by country or individually.
File
ip_ban.moduleView source
<?php
use Drupal\Core\Access\AccessResult;
use Drupal\block\Entity\Block;
use Drupal\ip_ban\EventSubscriber\IpBanSubscriber;
/**
* @file
* Module can "ban" or set site to "read only" by country or IP address.
*
* Permissions, administration menu item, form, form theme, form validation,
* and code for handling read-only and banned IP addresses by country or
* individually.
*/
define('IP_BAN_NOBAN', 0);
define('IP_BAN_READONLY', 1);
define('IP_BAN_BANNED', 2);
/**
* Implements hook_theme().
*/
function ip_ban_theme() {
$themes = array(
'ip_ban_country_table' => array(
'render element' => 'ip_ban_table',
),
);
return $themes;
}
/**
* Implements hook_block_access($block).
*
* Todo: need to move the ip_ban_determine_action to a new location so it's not
* called once for each block.
*/
function ip_ban_block_access(Block $block) {
// Take no action if the user has the "Bypass ban" permission.
if (\Drupal::currentUser()
->hasPermission('ignore ip_ban')) {
return;
}
// $subscriber = new IpBanSubscriber();
// $banvalue = $subscriber->getBanValue();
// kint($banvalue);
$disabled_blocks = \Drupal::config('ip_ban.settings')
->get('ip_ban_disabled_blocks');
$disabled_block_list = array();
if (!empty($disabled_blocks)) {
$disabled_block_array = explode(PHP_EOL, $disabled_blocks);
foreach ($disabled_block_array as $disabled_block) {
$disabled_block_list[] = preg_replace('/\\s+/', '', $disabled_block);
}
}
if (!empty($disabled_block_list)) {
if (in_array($block
->id(), $disabled_block_list)) {
//return AccessResult::forbidden();
unset($block);
}
}
}
Functions
Name | Description |
---|---|
ip_ban_block_access | Implements hook_block_access($block). |
ip_ban_theme | Implements hook_theme(). |
Constants
Name | Description |
---|---|
IP_BAN_BANNED | |
IP_BAN_NOBAN | @file Module can "ban" or set site to "read only" by country or IP address. |
IP_BAN_READONLY |