mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/9687] Add ip banning support incl. CIDR support
PHPBB3-9687
This commit is contained in:
parent
d99968a800
commit
ec4a53169a
3 changed files with 107 additions and 0 deletions
|
@ -27,6 +27,16 @@ services:
|
||||||
tags:
|
tags:
|
||||||
- { name: ban.type }
|
- { name: ban.type }
|
||||||
|
|
||||||
|
ban.type.ip:
|
||||||
|
class: \phpbb\ban\type\ip
|
||||||
|
arguments:
|
||||||
|
- '@dbal.conn'
|
||||||
|
- '%tables.users%'
|
||||||
|
- '%tables.sessions%'
|
||||||
|
- '%tables.sessions_keys%'
|
||||||
|
tags:
|
||||||
|
- { name: ban.type }
|
||||||
|
|
||||||
ban.type.user:
|
ban.type.user:
|
||||||
class: \phpbb\ban\type\user
|
class: \phpbb\ban\type\user
|
||||||
arguments:
|
arguments:
|
||||||
|
|
20
phpBB/phpbb/ban/exception/no_valid_ips_exception.php
Normal file
20
phpBB/phpbb/ban/exception/no_valid_ips_exception.php
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\ban\exception;
|
||||||
|
|
||||||
|
use phpbb\exception\runtime_exception;
|
||||||
|
|
||||||
|
class no_valid_ips_exception extends runtime_exception
|
||||||
|
{
|
||||||
|
}
|
77
phpBB/phpbb/ban/type/ip.php
Normal file
77
phpBB/phpbb/ban/type/ip.php
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpbb\ban\type;
|
||||||
|
|
||||||
|
use phpbb\ban\exception\no_valid_ips_exception;
|
||||||
|
use Symfony\Component\HttpFoundation\IpUtils;
|
||||||
|
|
||||||
|
class ip extends base
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function get_type(): string
|
||||||
|
{
|
||||||
|
return 'ip';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function get_user_column(): ?string
|
||||||
|
{
|
||||||
|
return 'user_ip';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public function check(array $ban_rows, array $user_data)
|
||||||
|
{
|
||||||
|
return parent::check($ban_rows, $user_data); // TODO: Change the autogenerated stub
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function prepare_for_storage(array $items): array
|
||||||
|
{
|
||||||
|
$ban_items = [];
|
||||||
|
foreach ($items as $ip)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Misuse checkIp for checking validity of IP. Should return true if defined IP is valid.
|
||||||
|
if (!IpUtils::checkIp($ip, $ip))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ban_items[] = $ip;
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $exception)
|
||||||
|
{
|
||||||
|
// IPv6 not supported, therefore IPv6 address will not be added
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($ban_items))
|
||||||
|
{
|
||||||
|
throw new no_valid_ips_exception(); // TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ban_items;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue