From 1e98784eee64240418d6e6df2336e2c0d7ac9dd2 Mon Sep 17 00:00:00 2001 From: FreddleSpl0it Date: Fri, 6 Jan 2023 12:09:15 +0100 Subject: [PATCH] [Web] Opt-In for third party ip_check --- data/web/admin.php | 1 + data/web/debug.php | 1 + data/web/inc/functions.customize.inc.php | 33 +++++++++++++++++++ data/web/json_api.php | 14 ++++---- data/web/lang/lang.de-de.json | 4 +++ data/web/lang/lang.en-gb.json | 4 +++ .../templates/admin/tab-config-customize.twig | 14 ++++++++ data/web/templates/debug.twig | 20 ++++++----- 8 files changed, 76 insertions(+), 15 deletions(-) diff --git a/data/web/admin.php b/data/web/admin.php index a3b908b7..cd3eb890 100644 --- a/data/web/admin.php +++ b/data/web/admin.php @@ -103,6 +103,7 @@ $template_data = [ 'rsettings' => $rsettings, 'rspamd_regex_maps' => $rspamd_regex_maps, 'logo_specs' => customize('get', 'main_logo_specs'), + 'ip_check' => customize('get', 'ip_check'), 'password_complexity' => password_complexity('get'), 'show_rspamd_global_filters' => @$_SESSION['show_rspamd_global_filters'], 'lang_admin' => json_encode($lang['admin']), diff --git a/data/web/debug.php b/data/web/debug.php index 45c4456c..52052f68 100644 --- a/data/web/debug.php +++ b/data/web/debug.php @@ -65,6 +65,7 @@ $template_data = [ 'solr_uptime' => round($solr_status['status']['dovecot-fts']['uptime'] / 1000 / 60 / 60), 'clamd_status' => $clamd_status, 'containers' => $containers, + 'ip_check' => customize('get', 'ip_check'), 'lang_admin' => json_encode($lang['admin']), 'lang_debug' => json_encode($lang['debug']), 'lang_datatables' => json_encode($lang['datatables']), diff --git a/data/web/inc/functions.customize.inc.php b/data/web/inc/functions.customize.inc.php index 16c5c036..6025d97d 100644 --- a/data/web/inc/functions.customize.inc.php +++ b/data/web/inc/functions.customize.inc.php @@ -160,6 +160,25 @@ function customize($_action, $_item, $_data = null) { 'msg' => 'ui_texts' ); break; + case 'ip_check': + $ip_check = ($_data['ip_check_opt_in'] == "1") ? 1 : 0; + try { + $redis->set('IP_CHECK', $ip_check); + } + catch (RedisException $e) { + $_SESSION['return'][] = array( + 'type' => 'danger', + 'log' => array(__FUNCTION__, $_action, $_item, $_data), + 'msg' => array('redis_error', $e) + ); + return false; + } + $_SESSION['return'][] = array( + 'type' => 'success', + 'log' => array(__FUNCTION__, $_action, $_item, $_data), + 'msg' => 'ip_check_opt_in_modified' + ); + break; } break; case 'delete': @@ -276,6 +295,20 @@ function customize($_action, $_item, $_data = null) { return false; } break; + case 'ip_check': + try { + $ip_check = ($ip_check = $redis->get('IP_CHECK')) ? $ip_check : 0; + return $ip_check; + } + catch (RedisException $e) { + $_SESSION['return'][] = array( + 'type' => 'danger', + 'log' => array(__FUNCTION__, $_action, $_item, $_data), + 'msg' => array('redis_error', $e) + ); + return false; + } + break; } break; } diff --git a/data/web/json_api.php b/data/web/json_api.php index 0d3dbb2f..1823e5a5 100644 --- a/data/web/json_api.php +++ b/data/web/json_api.php @@ -1544,18 +1544,15 @@ if (isset($_GET['query'])) { } else if ($extra == "ip") { // get public ips + $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, 'http://ipv4.mailcow.email'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 0); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_TIMEOUT, 15); + curl_setopt($curl, CURLOPT_URL, 'http://ipv4.mailcow.email'); $ipv4 = curl_exec($curl); curl_setopt($curl, CURLOPT_URL, 'http://ipv6.mailcow.email'); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_POST, 0); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); $ipv6 = curl_exec($curl); $ips = array( "ipv4" => $ipv4, @@ -1917,6 +1914,9 @@ if (isset($_GET['query'])) { case "ui_texts": process_edit_return(customize('edit', 'ui_texts', $attr)); break; + case "ip_check": + process_edit_return(customize('edit', 'ip_check', $attr)); + break; case "self": if ($_SESSION['mailcow_cc_role'] == "domainadmin") { process_edit_return(domain_admin('edit', $attr)); diff --git a/data/web/lang/lang.de-de.json b/data/web/lang/lang.de-de.json index bc94e619..1832cddd 100644 --- a/data/web/lang/lang.de-de.json +++ b/data/web/lang/lang.de-de.json @@ -204,6 +204,9 @@ "include_exclude": "Ein- und Ausschlüsse", "include_exclude_info": "Ohne Auswahl werden alle Mailboxen adressiert.", "includes": "Diese Empfänger einschließen", + "ip_check": "IP Check", + "ip_check_disabled": "IP check ist deaktiviert. Unter dem angegebenen Pfad kann es aktiviert werden
System > Configuration > Options > Customize", + "ip_check_opt_in": "Opt-In für die Nutzung der Drittanbieter-Dienste ipv4.mailcow.email und ipv6.mailcow.email zur Auflösung externer IP-Adressen.", "is_mx_based": "MX-basiert", "last_applied": "Zuletzt angewendet", "license_info": "Eine Lizenz ist nicht erforderlich, hilft jedoch der Entwicklung mailcows.
Hier kann die mailcow-GUID registriert werden. Alternativ ist die Bestellung von Support-Paketen möglich.", @@ -1004,6 +1007,7 @@ "forwarding_host_removed": "Weiterleitungs-Host %s wurde entfernt", "global_filter_written": "Filterdatei wurde erfolgreich geschrieben", "hash_deleted": "Hash wurde gelöscht", + "ip_check_opt_in_modified": "IP Check wurde erfolgreich gespeichert", "item_deleted": "Objekt %s wurde entfernt", "item_released": "Objekt %s freigegeben", "items_deleted": "Objekt(e) %s wurde(n) erfolgreich entfernt", diff --git a/data/web/lang/lang.en-gb.json b/data/web/lang/lang.en-gb.json index e1323f94..4472d039 100644 --- a/data/web/lang/lang.en-gb.json +++ b/data/web/lang/lang.en-gb.json @@ -206,6 +206,9 @@ "include_exclude": "Include/Exclude", "include_exclude_info": "By default - with no selection - all mailboxes are addressed", "includes": "Include these recipients", + "ip_check": "IP Check", + "ip_check_disabled": "IP check is disabled. You can enable it under
System > Configuration > Options > Customize", + "ip_check_opt_in": "Opt-In for using third party service ipv4.mailcow.email and ipv6.mailcow.email to resolve external IP addresses.", "is_mx_based": "MX based", "last_applied": "Last applied", "license_info": "A license is not required but helps further development.
Register your GUID here or buy support for your mailcow installation.", @@ -1016,6 +1019,7 @@ "forwarding_host_removed": "Forwarding host %s has been removed", "global_filter_written": "Filter was successfully written to file", "hash_deleted": "Hash deleted", + "ip_check_opt_in_modified": "IP check was saved successfully", "item_deleted": "Item %s successfully deleted", "item_released": "Item %s released", "items_deleted": "Item %s successfully deleted", diff --git a/data/web/templates/admin/tab-config-customize.twig b/data/web/templates/admin/tab-config-customize.twig index 4ec6aecb..766c0b6a 100644 --- a/data/web/templates/admin/tab-config-customize.twig +++ b/data/web/templates/admin/tab-config-customize.twig @@ -33,6 +33,20 @@ {% endif %} + {{ lang.admin.ip_check }}
+
+
+
+ + +
+

+ +

+
+
{{ lang.admin.app_links }}

{{ lang.admin.merged_vars_hint|raw }}

diff --git a/data/web/templates/debug.twig b/data/web/templates/debug.twig index a9399a12..60e78bdf 100644 --- a/data/web/templates/debug.twig +++ b/data/web/templates/debug.twig @@ -52,14 +52,18 @@ IPs - - - - - + {% if ip_check == 1 %} + - + - + + {% else %} + {{ lang.admin.ip_check_disabled|raw }} + {% endif %}