[Web] Show ratelimited messages, allow to delete Redis hash to reset status of a bucket
This commit is contained in:
@@ -1263,7 +1263,7 @@ function get_u2f_registrations($username) {
|
||||
$sel->execute(array($username));
|
||||
return $sel->fetchAll(PDO::FETCH_OBJ);
|
||||
}
|
||||
function get_logs($container, $lines = false) {
|
||||
function get_logs($application, $lines = false) {
|
||||
if ($lines === false) {
|
||||
$lines = $GLOBALS['LOG_LINES'] - 1;
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ function get_logs($container, $lines = false) {
|
||||
return false;
|
||||
}
|
||||
// SQL
|
||||
if ($container == "mailcow-ui") {
|
||||
if ($application == "mailcow-ui") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$stmt = $pdo->prepare("SELECT * FROM `logs` ORDER BY `id` DESC LIMIT :from, :to");
|
||||
$stmt->execute(array(
|
||||
@@ -1304,7 +1304,7 @@ function get_logs($container, $lines = false) {
|
||||
}
|
||||
}
|
||||
// Redis
|
||||
if ($container == "dovecot-mailcow") {
|
||||
if ($application == "dovecot-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('DOVECOT_MAILLOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1318,7 +1318,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "postfix-mailcow") {
|
||||
if ($application == "postfix-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('POSTFIX_MAILLOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1332,7 +1332,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "sogo-mailcow") {
|
||||
if ($application == "sogo-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('SOGO_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1346,7 +1346,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "watchdog-mailcow") {
|
||||
if ($application == "watchdog-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('WATCHDOG_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1360,7 +1360,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "acme-mailcow") {
|
||||
if ($application == "acme-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('ACME_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1374,7 +1374,21 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "api-mailcow") {
|
||||
if ($application == "ratelimited") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('RL_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
else {
|
||||
$data = $redis->lRange('RL_LOG', 0, $lines);
|
||||
}
|
||||
if ($data) {
|
||||
foreach ($data as $json_line) {
|
||||
$data_array[] = json_decode($json_line, true);
|
||||
}
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($application == "api-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('API_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1388,7 +1402,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "netfilter-mailcow") {
|
||||
if ($application == "netfilter-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('NETFILTER_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1402,7 +1416,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "autodiscover-mailcow") {
|
||||
if ($application == "autodiscover-mailcow") {
|
||||
if (isset($from) && isset($to)) {
|
||||
$data = $redis->lRange('AUTODISCOVER_LOG', $from - 1, $to - 1);
|
||||
}
|
||||
@@ -1416,7 +1430,7 @@ function get_logs($container, $lines = false) {
|
||||
return $data_array;
|
||||
}
|
||||
}
|
||||
if ($container == "rspamd-history") {
|
||||
if ($application == "rspamd-history") {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_UNIX_SOCKET_PATH, '/var/lib/rspamd/rspamd.sock');
|
||||
if (!is_numeric($lines)) {
|
||||
|
@@ -192,5 +192,44 @@ function ratelimit($_action, $_scope, $_data = null) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'delete':
|
||||
$data['hash'] = $_data;
|
||||
if ($_SESSION['mailcow_cc_role'] != 'admin' || !preg_match('/^RL[0-9A-Za-z=]+$/i', trim($data['hash']))) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr),
|
||||
'msg' => 'access_denied'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
if ($redis->exists($data['hash'])) {
|
||||
$redis->delete($data['hash']);
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'success',
|
||||
'log' => array(__FUNCTION__, $_action, $_scope, $_data_log),
|
||||
'msg' => 'hash_deleted'
|
||||
);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'warning',
|
||||
'log' => array(__FUNCTION__, $_action, $_scope, $_data_log),
|
||||
'msg' => 'hash_not_found'
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (RedisException $e) {
|
||||
$_SESSION['return'][] = array(
|
||||
'type' => 'danger',
|
||||
'log' => array(__FUNCTION__, $_action, $_scope, $_data_log),
|
||||
'msg' => array('redis_error', $e)
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user