From d28fd4070b8b21ca58185e8af56e5142c7847004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Tue, 21 Aug 2018 21:06:22 +0200 Subject: [PATCH] [Web] Allow to set rate limit in add_domain modal [Web] Cleanup rate limits when deleting objects --- data/web/inc/functions.mailbox.inc.php | 16 +++++++++++++ data/web/inc/functions.ratelimit.inc.php | 4 ++-- data/web/lang/lang.de.php | 1 + data/web/lang/lang.en.php | 5 ++-- data/web/modals/mailbox.php | 30 ++++++++++++++++++------ 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/data/web/inc/functions.mailbox.inc.php b/data/web/inc/functions.mailbox.inc.php index 0db72594..13a33934 100644 --- a/data/web/inc/functions.mailbox.inc.php +++ b/data/web/inc/functions.mailbox.inc.php @@ -415,6 +415,9 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { ); return false; } + if (!empty(intval($_data['rl_value']))) { + ratelimit('edit', 'domain', array('rl_value' => $rl_value, 'rl_frame' => $_data['rl_frame'], 'object' => $domain)); + } if (!empty($restart_sogo)) { $restart_reponse = json_decode(docker('post', 'sogo-mailcow', 'restart'), true); if ($restart_reponse['type'] == "success") { @@ -3094,6 +3097,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { )); try { $redis->hDel('DOMAIN_MAP', $domain); + $redis->hDel('RL_VALUE', $domain); } catch (RedisException $e) { $_SESSION['return'][] = array( @@ -3182,6 +3186,7 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { )); try { $redis->hDel('DOMAIN_MAP', $alias_domain); + $redis->hDel('RL_VALUE', $domain); } catch (RedisException $e) { $_SESSION['return'][] = array( @@ -3301,6 +3306,17 @@ function mailbox($_action, $_type, $_data = null, $_extra = null) { ':address' => $gotos['address'] )); } + try { + $redis->hDel('RL_VALUE', $username); + } + catch (RedisException $e) { + $_SESSION['return'][] = array( + 'type' => 'danger', + 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr), + 'msg' => array('redis_error', $e) + ); + continue; + } $_SESSION['return'][] = array( 'type' => 'success', 'log' => array(__FUNCTION__, $_action, $_type, $_data_log, $_attr), diff --git a/data/web/inc/functions.ratelimit.inc.php b/data/web/inc/functions.ratelimit.inc.php index 8218a7bd..2ead02e4 100644 --- a/data/web/inc/functions.ratelimit.inc.php +++ b/data/web/inc/functions.ratelimit.inc.php @@ -62,7 +62,7 @@ function ratelimit($_action, $_scope, $_data = null) { $_SESSION['return'][] = array( 'type' => 'success', 'log' => array(__FUNCTION__, $_action, $_scope, $_data_log), - 'msg' => array('object_modified', $object) + 'msg' => array('rl_saved', $object) ); } break; @@ -123,7 +123,7 @@ function ratelimit($_action, $_scope, $_data = null) { $_SESSION['return'][] = array( 'type' => 'success', 'log' => array(__FUNCTION__, $_action, $_scope, $_data_log), - 'msg' => array('object_modified', $object) + 'msg' => array('rl_saved', $object) ); } break; diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index ef8805e3..5741f968 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -42,6 +42,7 @@ $lang['danger']['filter_type'] = "Falscher Filtertyp"; $lang['danger']['domain_cannot_match_hostname'] = "Domain darf nicht dem Hostnamen entsprechen"; $lang['warning']['domain_added_sogo_failed'] = "Domain wurde hinzugefügt; SOGo konnte nicht neugestartet werden"; $lang['danger']['rl_timeframe'] = "Ratelimit Zeitraum ist inkorrekt"; +$lang['success']['rl_saved'] = "Ratelimit für Objekt %s wurde gesetzt"; $lang['success']['deleted_syncjobs'] = "Syncjobs gelöscht: %s"; $lang['success']['deleted_syncjob'] = "Syncjobs ID %s gelöscht"; $lang['success']['delete_filters'] = "Filter gelöscht: %s"; diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index 6f345fb0..0a04f649 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -41,7 +41,8 @@ $lang['danger']['value_missing'] = "Please provide all values"; $lang['danger']['filter_type'] = "Wrong filter type"; $lang['danger']['domain_cannot_match_hostname'] = "Domain cannot match hostname"; $lang['warning']['domain_added_sogo_failed'] = "Added domain but failed to restart SOGo, please check your server logs."; -$lang['danger']['rl_timeframe'] = "Ratelimit time frame is incorrect"; +$lang['danger']['rl_timeframe'] = "Rate limit time frame is incorrect"; +$lang['success']['rl_saved'] = "Rate limit for object %s saved"; $lang['success']['deleted_syncjobs'] = "Deleted syncjobs: %s"; $lang['success']['deleted_syncjob'] = "Deleted syncjob ID %s"; $lang['success']['delete_filters'] = "Deleted filters: %s"; @@ -489,7 +490,7 @@ $lang['admin']['rsetting_desc'] = 'Short description'; $lang['admin']['rsetting_content'] = 'Rule content'; $lang['admin']['rsetting_none'] = 'No rule available'; $lang['admin']['rsetting_no_selection'] = 'Please select a rule'; -$lang['admin']['rsettings_preset_1'] = 'Disable all but DKIM and ratelimit for authenticated users'; +$lang['admin']['rsettings_preset_1'] = 'Disable all but DKIM and rate limit for authenticated users'; $lang['admin']['rsettings_preset_2'] = 'Postmasters want spam'; $lang['admin']['rsettings_insert_preset'] = 'Insert example preset "%s"'; $lang['admin']['rsetting_add_rule'] = 'Add rule'; diff --git a/data/web/modals/mailbox.php b/data/web/modals/mailbox.php index 94f881e4..b4a51893 100644 --- a/data/web/modals/mailbox.php +++ b/data/web/modals/mailbox.php @@ -123,6 +123,28 @@ if (!isset($_SESSION['mailcow_cc_role'])) { +
+
+
+ +
+
+
+
+
+ +
+ +
+
+ +
+
+
@@ -134,13 +156,7 @@ if (!isset($_SESSION['mailcow_cc_role'])) {
-
-
-
- -
-
-
+