2019-06-07 19:33:51 +02:00
|
|
|
<?php
|
2019-09-29 00:43:51 +02:00
|
|
|
namespace Misuzu;
|
|
|
|
|
2019-12-12 01:42:28 +01:00
|
|
|
use Misuzu\Net\IPAddressBlacklist;
|
|
|
|
|
2019-06-07 19:33:51 +02:00
|
|
|
require_once '../../../misuzu.php';
|
|
|
|
|
2019-12-06 02:04:10 +01:00
|
|
|
if(!perms_check_user(MSZ_PERMS_GENERAL, user_session_current('user_id'), General::PERM_MANAGE_BLACKLIST)) {
|
2019-06-07 19:33:51 +02:00
|
|
|
echo render_error(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$notices = [];
|
|
|
|
|
|
|
|
if(!empty($_POST)) {
|
2019-12-11 19:10:54 +01:00
|
|
|
if(!CSRF::validateRequest()) {
|
2019-06-07 19:33:51 +02:00
|
|
|
$notices[] = 'Verification failed.';
|
|
|
|
} else {
|
2019-12-11 19:10:54 +01:00
|
|
|
header(CSRF::header());
|
2019-06-07 19:33:51 +02:00
|
|
|
|
|
|
|
if(!empty($_POST['blacklist']['remove']) && is_array($_POST['blacklist']['remove'])) {
|
2019-06-10 19:04:53 +02:00
|
|
|
foreach($_POST['blacklist']['remove'] as $cidr) {
|
2019-12-12 01:42:28 +01:00
|
|
|
if(!IPAddressBlacklist::remove($cidr)) {
|
2019-06-07 19:33:51 +02:00
|
|
|
$notices[] = sprintf('Failed to remove "%s" from the blacklist.', $cidr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!empty($_POST['blacklist']['add']) && is_string($_POST['blacklist']['add'])) {
|
|
|
|
$cidrs = explode("\n", $_POST['blacklist']['add']);
|
|
|
|
|
|
|
|
foreach($cidrs as $cidr) {
|
|
|
|
$cidr = trim($cidr);
|
|
|
|
|
|
|
|
if(empty($cidr)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-12 01:42:28 +01:00
|
|
|
if(!IPAddressBlacklist::add($cidr)) {
|
2019-06-07 19:33:51 +02:00
|
|
|
$notices[] = sprintf('Failed to add "%s" to the blacklist.', $cidr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-04 19:16:22 +01:00
|
|
|
Template::render('manage.general.blacklist', [
|
2019-06-07 19:33:51 +02:00
|
|
|
'notices' => $notices,
|
2019-12-12 01:42:28 +01:00
|
|
|
'blacklist' => IPAddressBlacklist::list(),
|
2019-06-07 19:33:51 +02:00
|
|
|
]);
|