2017-06-29 10:29:56 +02:00
|
|
|
<?php
|
2023-07-10 13:54:23 +02:00
|
|
|
function fail2ban($_action, $_data = null, $_extra = null) {
|
2017-06-29 10:29:56 +02:00
|
|
|
global $redis;
|
2018-08-03 20:31:33 +02:00
|
|
|
$_data_log = $_data;
|
2017-06-29 10:29:56 +02:00
|
|
|
switch ($_action) {
|
|
|
|
case 'get':
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options = array();
|
2017-06-29 10:29:56 +02:00
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options = json_decode($redis->Get('F2B_OPTIONS'), true);
|
2020-08-27 20:43:33 +02:00
|
|
|
$f2b_options['regex'] = json_decode($redis->Get('F2B_REGEX'), true);
|
2017-06-29 10:29:56 +02:00
|
|
|
$wl = $redis->hGetAll('F2B_WHITELIST');
|
|
|
|
if (is_array($wl)) {
|
|
|
|
foreach ($wl as $key => $value) {
|
2018-04-25 10:54:13 +02:00
|
|
|
$tmp_wl_data[] = $key;
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
2018-04-25 10:54:13 +02:00
|
|
|
if (isset($tmp_wl_data)) {
|
2019-10-29 09:39:57 +02:00
|
|
|
natsort($tmp_wl_data);
|
2021-08-09 08:28:22 +02:00
|
|
|
$f2b_options['whitelist'] = implode(PHP_EOL, (array)$tmp_wl_data);
|
2017-07-29 10:32:17 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options['whitelist'] = "";
|
2017-07-29 10:32:17 +02:00
|
|
|
}
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options['whitelist'] = "";
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
2018-04-25 10:54:13 +02:00
|
|
|
$bl = $redis->hGetAll('F2B_BLACKLIST');
|
|
|
|
if (is_array($bl)) {
|
|
|
|
foreach ($bl as $key => $value) {
|
|
|
|
$tmp_bl_data[] = $key;
|
|
|
|
}
|
|
|
|
if (isset($tmp_bl_data)) {
|
2019-10-29 09:39:57 +02:00
|
|
|
natsort($tmp_bl_data);
|
2021-08-09 08:28:22 +02:00
|
|
|
$f2b_options['blacklist'] = implode(PHP_EOL, (array)$tmp_bl_data);
|
2018-04-25 10:54:13 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
$f2b_options['blacklist'] = "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$f2b_options['blacklist'] = "";
|
|
|
|
}
|
2018-07-09 22:22:45 +02:00
|
|
|
$pb = $redis->hGetAll('F2B_PERM_BANS');
|
|
|
|
if (is_array($pb)) {
|
|
|
|
foreach ($pb as $key => $value) {
|
2021-06-28 07:07:29 +02:00
|
|
|
$f2b_options['perm_bans'][] = array(
|
|
|
|
'network'=>$key,
|
|
|
|
'ip' => strtok($key,'/')
|
|
|
|
);
|
|
|
|
|
2018-07-09 22:22:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$f2b_options['perm_bans'] = "";
|
|
|
|
}
|
2018-07-03 23:27:00 +02:00
|
|
|
$active_bans = $redis->hGetAll('F2B_ACTIVE_BANS');
|
|
|
|
$queue_unban = $redis->hGetAll('F2B_QUEUE_UNBAN');
|
|
|
|
if (is_array($active_bans)) {
|
|
|
|
foreach ($active_bans as $network => $banned_until) {
|
|
|
|
$queued_for_unban = (isset($queue_unban[$network]) && $queue_unban[$network] == 1) ? 1 : 0;
|
|
|
|
$difference = $banned_until - time();
|
|
|
|
$f2b_options['active_bans'][] = array(
|
|
|
|
'queued_for_unban' => $queued_for_unban,
|
|
|
|
'network' => $network,
|
2021-06-28 07:07:29 +02:00
|
|
|
'ip' => strtok($network,'/'),
|
2018-07-03 23:27:00 +02:00
|
|
|
'banned_until' => sprintf('%02dh %02dm %02ds', ($difference/3600), ($difference/60%60), $difference%60)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$f2b_options['active_bans'] = "";
|
|
|
|
}
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2017-06-29 10:29:56 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-06-29 10:29:56 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-01 14:28:17 +02:00
|
|
|
return $f2b_options;
|
2017-06-29 10:29:56 +02:00
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2017-06-29 10:29:56 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-06-29 10:29:56 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
// Start to read actions, if any
|
|
|
|
if (isset($_data['action'])) {
|
|
|
|
// Reset regex filters
|
|
|
|
if ($_data['action'] == "reset-regex") {
|
2018-08-13 23:20:40 +02:00
|
|
|
try {
|
2020-08-27 20:43:33 +02:00
|
|
|
$redis->Del('F2B_REGEX');
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Rules will also be recreated on log events, but rules may seem empty for a second in the UI
|
|
|
|
docker('post', 'netfilter-mailcow', 'restart');
|
|
|
|
$fail_count = 0;
|
|
|
|
$regex_result = json_decode($redis->Get('F2B_REGEX'), true);
|
|
|
|
while (empty($regex_result) && $fail_count < 10) {
|
|
|
|
$regex_result = json_decode($redis->Get('F2B_REGEX'), true);
|
|
|
|
$fail_count++;
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
if ($fail_count >= 10) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('reset_f2b_regex')
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($_data['action'] == "edit-regex") {
|
|
|
|
if (!empty($_data['regex'])) {
|
|
|
|
$rule_id = 1;
|
|
|
|
$regex_array = array();
|
|
|
|
foreach($_data['regex'] as $regex) {
|
|
|
|
$regex_array[$rule_id] = $regex;
|
|
|
|
$rule_id++;
|
|
|
|
}
|
2020-08-27 21:13:20 +02:00
|
|
|
if (!empty($regex_array)) {
|
|
|
|
$redis->Set('F2B_REGEX', json_encode($regex_array, JSON_UNESCAPED_SLASHES));
|
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
}
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('object_modified', htmlspecialchars($network))
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start actions in dependency of network
|
|
|
|
if (!empty($_data['network'])) {
|
|
|
|
$networks = (array)$_data['network'];
|
|
|
|
foreach ($networks as $network) {
|
|
|
|
// Unban network
|
2018-08-13 23:20:40 +02:00
|
|
|
if ($_data['action'] == "unban") {
|
|
|
|
if (valid_network($network)) {
|
2020-08-27 20:43:33 +02:00
|
|
|
try {
|
|
|
|
$redis->hSet('F2B_QUEUE_UNBAN', $network, 1);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
}
|
2018-07-03 23:27:00 +02:00
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
// Whitelist network
|
2018-08-13 23:20:40 +02:00
|
|
|
elseif ($_data['action'] == "whitelist") {
|
2020-09-26 22:02:34 +02:00
|
|
|
if (empty($network)) { continue; }
|
2018-08-13 23:20:40 +02:00
|
|
|
if (valid_network($network)) {
|
2020-08-27 20:43:33 +02:00
|
|
|
try {
|
|
|
|
$redis->hSet('F2B_WHITELIST', $network, 1);
|
|
|
|
$redis->hDel('F2B_BLACKLIST', $network, 1);
|
|
|
|
$redis->hSet('F2B_QUEUE_UNBAN', $network, 1);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
}
|
2019-02-06 10:23:01 +02:00
|
|
|
else {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('network_host_invalid', $network)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-03 23:27:00 +02:00
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
// Blacklist network
|
2018-08-13 23:20:40 +02:00
|
|
|
elseif ($_data['action'] == "blacklist") {
|
2020-09-26 22:02:34 +02:00
|
|
|
if (empty($network)) { continue; }
|
2020-06-04 16:22:54 +02:00
|
|
|
if (valid_network($network) && !in_array($network, array(
|
|
|
|
'0.0.0.0',
|
|
|
|
'0.0.0.0/0',
|
|
|
|
getenv('IPV4_NETWORK') . '0/24',
|
|
|
|
getenv('IPV4_NETWORK') . '0',
|
|
|
|
getenv('IPV6_NETWORK')
|
|
|
|
))) {
|
2020-08-27 20:43:33 +02:00
|
|
|
try {
|
|
|
|
$redis->hSet('F2B_BLACKLIST', $network, 1);
|
|
|
|
$redis->hDel('F2B_WHITELIST', $network, 1);
|
|
|
|
//$response = docker('post', 'netfilter-mailcow', 'restart');
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
}
|
2019-02-06 10:23:01 +02:00
|
|
|
else {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('network_host_invalid', $network)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-03 23:27:00 +02:00
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2020-08-27 20:43:33 +02:00
|
|
|
'type' => 'success',
|
2018-08-13 23:20:40 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
2020-08-27 20:43:33 +02:00
|
|
|
'msg' => array('object_modified', htmlspecialchars($network))
|
2018-08-13 23:20:40 +02:00
|
|
|
);
|
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
return true;
|
2018-07-03 23:27:00 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 20:43:33 +02:00
|
|
|
// Start default edit without specific action
|
2017-06-29 10:29:56 +02:00
|
|
|
$is_now = fail2ban('get');
|
|
|
|
if (!empty($is_now)) {
|
|
|
|
$ban_time = intval((isset($_data['ban_time'])) ? $_data['ban_time'] : $is_now['ban_time']);
|
2023-03-17 19:22:16 +02:00
|
|
|
$ban_time_increment = (isset($_data['ban_time_increment']) && $_data['ban_time_increment'] == "1") ? 1 : 0;
|
2020-09-17 19:49:15 +02:00
|
|
|
$max_attempts = intval((isset($_data['max_attempts'])) ? $_data['max_attempts'] : $is_now['max_attempts']);
|
2023-03-17 19:22:16 +02:00
|
|
|
$max_ban_time = intval((isset($_data['max_ban_time'])) ? $_data['max_ban_time'] : $is_now['max_ban_time']);
|
2017-06-29 10:29:56 +02:00
|
|
|
$retry_window = intval((isset($_data['retry_window'])) ? $_data['retry_window'] : $is_now['retry_window']);
|
2018-01-24 10:25:28 +02:00
|
|
|
$netban_ipv4 = intval((isset($_data['netban_ipv4'])) ? $_data['netban_ipv4'] : $is_now['netban_ipv4']);
|
|
|
|
$netban_ipv6 = intval((isset($_data['netban_ipv6'])) ? $_data['netban_ipv6'] : $is_now['netban_ipv6']);
|
2018-04-25 10:54:13 +02:00
|
|
|
$wl = (isset($_data['whitelist'])) ? $_data['whitelist'] : $is_now['whitelist'];
|
|
|
|
$bl = (isset($_data['blacklist'])) ? $_data['blacklist'] : $is_now['blacklist'];
|
2023-07-11 10:13:00 +02:00
|
|
|
$manage_external = (isset($_data['manage_external'])) ? intval($_data['manage_external']) : 0;
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2017-06-29 10:29:56 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'access_denied'
|
2017-06-29 10:29:56 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options = array();
|
|
|
|
$f2b_options['ban_time'] = ($ban_time < 60) ? 60 : $ban_time;
|
2023-03-17 19:22:16 +02:00
|
|
|
$f2b_options['ban_time_increment'] = ($ban_time_increment == 1) ? true : false;
|
|
|
|
$f2b_options['max_ban_time'] = ($max_ban_time < 60) ? 60 : $max_ban_time;
|
2018-02-01 14:28:17 +02:00
|
|
|
$f2b_options['netban_ipv4'] = ($netban_ipv4 < 8) ? 8 : $netban_ipv4;
|
|
|
|
$f2b_options['netban_ipv6'] = ($netban_ipv6 < 8) ? 8 : $netban_ipv6;
|
|
|
|
$f2b_options['netban_ipv4'] = ($netban_ipv4 > 32) ? 32 : $netban_ipv4;
|
|
|
|
$f2b_options['netban_ipv6'] = ($netban_ipv6 > 128) ? 128 : $netban_ipv6;
|
|
|
|
$f2b_options['max_attempts'] = ($max_attempts < 1) ? 1 : $max_attempts;
|
|
|
|
$f2b_options['retry_window'] = ($retry_window < 1) ? 1 : $retry_window;
|
2023-07-11 10:13:00 +02:00
|
|
|
$f2b_options['banlist_id'] = $is_now['banlist_id'];
|
|
|
|
$f2b_options['manage_external'] = ($manage_external > 0) ? 1 : 0;
|
2017-06-29 10:29:56 +02:00
|
|
|
try {
|
2018-02-01 14:28:17 +02:00
|
|
|
$redis->Set('F2B_OPTIONS', json_encode($f2b_options));
|
2017-06-29 10:29:56 +02:00
|
|
|
$redis->Del('F2B_WHITELIST');
|
2018-04-25 10:54:13 +02:00
|
|
|
$redis->Del('F2B_BLACKLIST');
|
2017-06-29 10:29:56 +02:00
|
|
|
if(!empty($wl)) {
|
|
|
|
$wl_array = array_map('trim', preg_split( "/( |,|;|\n)/", $wl));
|
2020-06-04 16:22:54 +02:00
|
|
|
$wl_array = array_filter($wl_array);
|
2017-06-29 10:29:56 +02:00
|
|
|
if (is_array($wl_array)) {
|
|
|
|
foreach ($wl_array as $wl_item) {
|
2019-05-17 19:38:34 +02:00
|
|
|
if (valid_network($wl_item) || valid_hostname($wl_item)) {
|
2017-06-29 10:29:56 +02:00
|
|
|
$redis->hSet('F2B_WHITELIST', $wl_item, 1);
|
|
|
|
}
|
2020-05-04 07:51:50 +02:00
|
|
|
else {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('network_host_invalid', $wl_item)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-25 10:54:13 +02:00
|
|
|
if(!empty($bl)) {
|
|
|
|
$bl_array = array_map('trim', preg_split( "/( |,|;|\n)/", $bl));
|
2020-06-04 16:22:54 +02:00
|
|
|
$bl_array = array_filter($bl_array);
|
2018-04-25 10:54:13 +02:00
|
|
|
if (is_array($bl_array)) {
|
|
|
|
foreach ($bl_array as $bl_item) {
|
2020-06-04 16:22:54 +02:00
|
|
|
if (valid_network($bl_item) && !in_array($bl_item, array(
|
|
|
|
'0.0.0.0',
|
|
|
|
'0.0.0.0/0',
|
|
|
|
getenv('IPV4_NETWORK') . '0/24',
|
|
|
|
getenv('IPV4_NETWORK') . '0',
|
|
|
|
getenv('IPV6_NETWORK')
|
|
|
|
))) {
|
2018-04-25 10:54:13 +02:00
|
|
|
$redis->hSet('F2B_BLACKLIST', $bl_item, 1);
|
|
|
|
}
|
2020-05-04 07:51:50 +02:00
|
|
|
else {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('network_host_invalid', $bl_item)
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-25 10:54:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2017-06-29 10:29:56 +02:00
|
|
|
'type' => 'danger',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => array('redis_error', $e)
|
2017-06-29 10:29:56 +02:00
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-13 23:20:40 +02:00
|
|
|
$_SESSION['return'][] = array(
|
2017-06-29 10:29:56 +02:00
|
|
|
'type' => 'success',
|
2018-08-03 20:31:33 +02:00
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
|
|
|
'msg' => 'f2b_modified'
|
2017-06-29 10:29:56 +02:00
|
|
|
);
|
|
|
|
break;
|
2023-07-10 13:54:23 +02:00
|
|
|
case 'banlist':
|
|
|
|
try {
|
|
|
|
$f2b_options = json_decode($redis->Get('F2B_OPTIONS'), true);
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log, $_extra),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
2023-07-11 10:31:25 +02:00
|
|
|
http_response_code(500);
|
2023-07-10 13:54:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (is_array($_extra)) {
|
|
|
|
$_extra = $_extra[0];
|
|
|
|
}
|
|
|
|
if ($_extra != $f2b_options['banlist_id']){
|
2023-07-11 10:31:25 +02:00
|
|
|
http_response_code(404);
|
2023-07-10 13:54:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ($_data) {
|
|
|
|
case 'get':
|
|
|
|
try {
|
2023-07-11 10:13:00 +02:00
|
|
|
$bl = $redis->hKeys('F2B_BLACKLIST');
|
|
|
|
$active_bans = $redis->hKeys('F2B_ACTIVE_BANS');
|
2023-07-10 13:54:23 +02:00
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log, $_extra),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
2023-07-11 10:31:25 +02:00
|
|
|
http_response_code(500);
|
2023-07-10 13:54:23 +02:00
|
|
|
return false;
|
|
|
|
}
|
2023-07-11 10:13:00 +02:00
|
|
|
$banlist = implode("\n", array_merge($bl, $active_bans));
|
2023-07-10 13:54:23 +02:00
|
|
|
return $banlist;
|
|
|
|
break;
|
|
|
|
case 'refresh':
|
|
|
|
if ($_SESSION['mailcow_cc_role'] != "admin") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$f2b_options['banlist_id'] = uuid4();
|
|
|
|
try {
|
|
|
|
$redis->Set('F2B_OPTIONS', json_encode($f2b_options));
|
|
|
|
}
|
|
|
|
catch (RedisException $e) {
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'danger',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log, $_extra),
|
|
|
|
'msg' => array('redis_error', $e)
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$_SESSION['return'][] = array(
|
|
|
|
'type' => 'success',
|
|
|
|
'log' => array(__FUNCTION__, $_action, $_data_log, $_extra),
|
|
|
|
'msg' => 'f2b_banlist_refreshed'
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2017-06-29 10:29:56 +02:00
|
|
|
}
|
2017-11-19 16:13:43 +02:00
|
|
|
}
|