From 3bd7383bcac87be80500e2bc5afad6ba62816727 Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 26 Jul 2017 23:11:43 +0200 Subject: [PATCH] [Web] Add relay host testing tool --- data/web/inc/relay_check.php | 74 ++++++++++++++++++++++++++++++++++++ data/web/js/admin.js | 30 ++++++++++++++- data/web/lang/lang.de.php | 32 ++++++++-------- data/web/lang/lang.en.php | 32 ++++++++-------- data/web/modals/admin.php | 31 ++++++++++++++- 5 files changed, 167 insertions(+), 32 deletions(-) create mode 100644 data/web/inc/relay_check.php diff --git a/data/web/inc/relay_check.php b/data/web/inc/relay_check.php new file mode 100644 index 00000000..575a8ad8 --- /dev/null +++ b/data/web/inc/relay_check.php @@ -0,0 +1,74 @@ +SMTPDebug = 3; + $mail->Debugoutput = function($str, $level) { + foreach(preg_split("/((\r?\n)|(\r\n?)|\n)/", $str) as $line){ + if (empty($line)) { continue; } + if (preg_match("/SERVER \-\> CLIENT: 2\d\d.+/i", $line)) { + echo '' . htmlspecialchars($line) . '
'; + } + elseif (preg_match("/SERVER \-\> CLIENT: 3\d\d.+/i", $line)) { + echo '' . htmlspecialchars($line) . '
'; + } + elseif (preg_match("/SERVER \-\> CLIENT: 4\d\d.+/i", $line)) { + echo '' . htmlspecialchars($line) . '
'; + } + elseif (preg_match("/SERVER \-\> CLIENT: 5\d\d.+/i", $line)) { + echo '' . htmlspecialchars($line) . '
'; + } + elseif (preg_match("/CLIENT \-\> SERVER:.+/i", $line)) { + echo '' . htmlspecialchars($line) . '
'; + } + elseif (preg_match("/^(?!SERVER|CLIENT|Connection:|\)).+$/i", $line)) { + echo '    ↪ ' . htmlspecialchars($line) . '
'; + } + else { + echo htmlspecialchars($line) . '
'; + } + } + }; + $mail->isSMTP(); + $mail->Host = $hostname; + if (!empty($username)) { + $mail->SMTPAuth = true; + $mail->Username = $username; + $mail->Password = $password; + $mail->Port = $port; + } + $mail->setFrom($mail_from, 'Mailer'); + $mail->Subject = 'A subject for a SMTP test'; + $mail->addAddress($RELAY_TO, 'Joe Null'); + $mail->Body = 'This is our test body'; + $mail->send(); + } + else { + echo "Unknown relayhost."; + } +} +else { + echo "Permission denied."; +} \ No newline at end of file diff --git a/data/web/js/admin.js b/data/web/js/admin.js index 9676bd5a..fb255437 100644 --- a/data/web/js/admin.js +++ b/data/web/js/admin.js @@ -337,7 +337,7 @@ jQuery(function($){ {"name":"username","title":lang.username,"breakpoints":"xs sm"}, {"name":"used_by_domains","title":lang.in_use_by, "type": "text","breakpoints":"xs sm"}, {"name":"active","filterable": false,"style":{"maxWidth":"80px","width":"80px"},"title":lang.active}, - {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"180px","width":"180px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} + {"name":"action","filterable": false,"sortable": false,"style":{"text-align":"right","maxWidth":"280px","width":"280px"},"type":"html","title":lang.action,"breakpoints":"xs sm"} ], "rows": $.ajax({ dataType: 'json', @@ -349,6 +349,8 @@ jQuery(function($){ success: function (data) { $.each(data, function (i, item) { item.action = '
' + + ' Test' + + ' ' + lang.edit + '' + ' ' + lang.remove + '' + '
'; item.chkbox = ''; @@ -544,6 +546,32 @@ jQuery(function($){ draw_fwd_hosts(); draw_relayhosts(); draw_rspamd_history(); + + $('#testRelayhostModal').on('show.bs.modal', function (e) { + $('#test_relayhost_result').text("-"); + button = $(e.relatedTarget) + if (button != null) { + $('#relayhost_id').val(button.data('relayhost-id')); + } + }) + + $('#test_relayhost').on('click', function (e) { + e.preventDefault(); + prev = $('#test_relayhost').text(); + $(this).prop("disabled",true); + $(this).html(' '); + $.ajax({ + type: 'GET', + url: 'inc/relay_check.php', + dataType: 'text', + data: $('#test_relayhost_form').serialize(), + complete: function (data) { + $('#test_relayhost_result').html(data.responseText); + $('#test_relayhost').prop("disabled",false); + $('#test_relayhost').text(prev); + } + }); + }) }); $(window).load(function(){ diff --git a/data/web/lang/lang.de.php b/data/web/lang/lang.de.php index 893f3d04..7a2378cf 100644 --- a/data/web/lang/lang.de.php +++ b/data/web/lang/lang.de.php @@ -349,35 +349,35 @@ $lang['add']['domain'] = 'Domain'; $lang['add']['active'] = 'Aktiv'; $lang['add']['multiple_bookings'] = 'Mehrfaches Buchen möglich'; $lang['add']['save'] = 'Änderungen speichern'; -$lang['add']['description'] = 'Beschreibung:'; -$lang['add']['max_aliases'] = 'Max. mögliche Aliasse:'; -$lang['add']['max_mailboxes'] = 'Max. mögliche Mailboxen:'; -$lang['add']['mailbox_quota_m'] = 'Max. Speicherplatz pro Mailbox (MiB):'; -$lang['add']['domain_quota_m'] = 'Domain Speicherplatz gesamt (MiB):'; -$lang['add']['backup_mx_options'] = 'Backup MX Optionen:'; +$lang['add']['description'] = 'Beschreibung'; +$lang['add']['max_aliases'] = 'Max. mögliche Aliasse'; +$lang['add']['max_mailboxes'] = 'Max. mögliche Mailboxen'; +$lang['add']['mailbox_quota_m'] = 'Max. Speicherplatz pro Mailbox (MiB)'; +$lang['add']['domain_quota_m'] = 'Domain Speicherplatz gesamt (MiB)'; +$lang['add']['backup_mx_options'] = 'Backup MX Optionen'; $lang['add']['relay_all'] = 'Alle Empfänger-Adressen relayen'; $lang['add']['relay_domain'] = 'Relay Domain'; $lang['add']['relay_all_info'] = 'Wenn Sie nicht alle Empfänger-Adressen relayen möchten, müssen Sie eine Mailbox für jede Adresse, die relayt werden soll, erstellen.'; $lang['add']['alias'] = 'Alias(se)'; $lang['add']['alias_spf_fail'] = 'Hinweis: Wählen Sie ein externes Postfach als Ziel-Adresse, kann es unter Umständen zu fehlerhaften Spam-Erkennungen beim Empfänger kommen. Weitere Informationen zu diesem Thema finden Sie hier.'; -$lang['add']['alias_address'] = 'Alias-Adresse(n):'; +$lang['add']['alias_address'] = 'Alias-Adresse(n)'; $lang['add']['alias_address_info'] = 'Vollständige E-Mail-Adresse(n) oder @example.com, um alle Nachrichten einer Domain weiterzuleiten. Getrennt durch Komma. Nur eigene Domains.'; $lang['add']['alias_domain_info'] = 'Nur gültige Domains. Getrennt durch Komma.'; -$lang['add']['target_address'] = 'Ziel-Adresse(n):'; +$lang['add']['target_address'] = 'Ziel-Adresse(n)'; $lang['add']['target_address_info'] = 'Vollständige E-Mail-Adresse(n). Getrennt durch Komma.'; $lang['add']['alias_domain'] = 'Alias-Domain'; $lang['add']['select'] = 'Bitte auswählen'; -$lang['add']['target_domain'] = 'Ziel-Domain:'; +$lang['add']['target_domain'] = 'Ziel-Domain'; $lang['add']['mailbox'] = 'Mailbox'; $lang['add']['resource'] = 'Ressource'; $lang['add']['kind'] = 'Art'; -$lang['add']['mailbox_username'] = 'Benutzername (linker Teil der E-Mail-Adresse):'; -$lang['add']['resource_name'] = 'Ressourcenname:'; -$lang['add']['full_name'] = 'Vor- und Zuname:'; -$lang['add']['quota_mb'] = 'Speicherplatz (MiB):'; +$lang['add']['mailbox_username'] = 'Benutzername (linker Teil der E-Mail-Adresse)'; +$lang['add']['resource_name'] = 'Ressourcenname'; +$lang['add']['full_name'] = 'Vor- und Zuname'; +$lang['add']['quota_mb'] = 'Speicherplatz (MiB)'; $lang['add']['select_domain'] = 'Bitte zuerst eine Domain auswählen'; -$lang['add']['password'] = 'Passwort:'; -$lang['add']['password_repeat'] = 'Passwort (Wiederholung):'; +$lang['add']['password'] = 'Passwort'; +$lang['add']['password_repeat'] = 'Passwort (Wiederholung)'; $lang['add']['previous'] = 'Vorherige Seite'; $lang['add']['restart_sogo_hint'] = 'Der SOGo Container muss nach dem Hinzufügen einer neuen Domain neugestartet werden!'; @@ -502,3 +502,5 @@ $lang['success']['forwarding_host_removed'] = "Weiterleitungs-Host %s wurde entf $lang['success']['forwarding_host_added'] = "Weiterleitungs-Host %s wurde hinzugefügt"; $lang['success']['relayhost_removed'] = "Relayhost %s wurde entfernt"; $lang['success']['relayhost_added'] = "Relayhost %s wurde hinzugefügt"; +$lang['admin']['relay_from'] = "Absenderadresse"; +$lang['admin']['relay_run'] = "Test durchführen"; diff --git a/data/web/lang/lang.en.php b/data/web/lang/lang.en.php index f7af1b32..9c28de7b 100644 --- a/data/web/lang/lang.en.php +++ b/data/web/lang/lang.en.php @@ -354,35 +354,35 @@ $lang['add']['domain'] = 'Domain'; $lang['add']['active'] = 'Active'; $lang['add']['multiple_bookings'] = 'Multiple bookings'; $lang['add']['save'] = 'Save changes'; -$lang['add']['description'] = 'Description:'; -$lang['add']['max_aliases'] = 'Max. possible aliases:'; +$lang['add']['description'] = 'Description'; +$lang['add']['max_aliases'] = 'Max. possible aliases'; $lang['add']['resource_name'] = 'Resource name'; -$lang['add']['max_mailboxes'] = 'Max. possible mailboxes:'; -$lang['add']['mailbox_quota_m'] = 'Max. quota per mailbox (MiB):'; -$lang['add']['domain_quota_m'] = 'Total domain quota (MiB):'; -$lang['add']['backup_mx_options'] = 'Backup MX options:'; +$lang['add']['max_mailboxes'] = 'Max. possible mailboxes'; +$lang['add']['mailbox_quota_m'] = 'Max. quota per mailbox (MiB)'; +$lang['add']['domain_quota_m'] = 'Total domain quota (MiB)'; +$lang['add']['backup_mx_options'] = 'Backup MX options'; $lang['add']['relay_all'] = 'Relay all recipients'; $lang['add']['relay_domain'] = 'Relay this domain'; $lang['add']['relay_all_info'] = 'If you choose not to relay all recipients, you will need to add a ("blind") mailbox for every single recipient that should be relayed.'; $lang['add']['alias'] = 'Alias(es)'; $lang['add']['alias_spf_fail'] = 'Note: If your chosen destination address is an external mailbox, the receiving mailserver may reject your message due to an SPF failure.'; -$lang['add']['alias_address'] = 'Alias address/es:'; +$lang['add']['alias_address'] = 'Alias address/es'; $lang['add']['alias_address_info'] = 'Full email address/es or @example.com, to catch all messages for a domain (comma-separated). mailcow domains only.'; $lang['add']['alias_domain_info'] = 'Valid domain names only (comma-separated).'; -$lang['add']['target_address'] = 'Goto addresses:'; +$lang['add']['target_address'] = 'Goto addresses'; $lang['add']['target_address_info'] = 'Full email address/es (comma-separated).'; $lang['add']['alias_domain'] = 'Alias domain'; $lang['add']['select'] = 'Please select...'; -$lang['add']['target_domain'] = 'Target domain:'; +$lang['add']['target_domain'] = 'Target domain'; $lang['add']['mailbox'] = 'Mailbox'; $lang['add']['resource'] = 'Resource'; $lang['add']['kind'] = 'Kind'; -$lang['add']['mailbox_username'] = 'Username (left part of an email address):'; -$lang['add']['full_name'] = 'Full name:'; -$lang['add']['quota_mb'] = 'Quota (MiB):'; +$lang['add']['mailbox_username'] = 'Username (left part of an email address)'; +$lang['add']['full_name'] = 'Full name'; +$lang['add']['quota_mb'] = 'Quota (MiB)'; $lang['add']['select_domain'] = 'Please select a domain first'; -$lang['add']['password'] = 'Password:'; -$lang['add']['password_repeat'] = 'Confirmation password (repeat):'; +$lang['add']['password'] = 'Password'; +$lang['add']['password_repeat'] = 'Confirmation password (repeat)'; $lang['add']['previous'] = 'Previous page'; $lang['add']['restart_sogo_hint'] = 'You will need to restart the SOGo service container after adding a new domain!'; @@ -514,4 +514,6 @@ $lang['delete']['remove_forwardinghost_warning'] = 'Warning: You are abou $lang['success']['forwarding_host_removed'] = "Forwarding host %s has been removed"; $lang['success']['forwarding_host_added'] = "Forwarding host %s has been added"; $lang['success']['relayhost_removed'] = "Relayhost %s has been removed"; -$lang['success']['relayhost_added'] = "Relayhost %s has been added"; \ No newline at end of file +$lang['success']['relayhost_added'] = "Relayhost %s has been added"; +$lang['admin']['relay_from'] = '"From:" address'; +$lang['admin']['relay_run'] = "Run test"; diff --git a/data/web/modals/admin.php b/data/web/modals/admin.php index 5c9a2256..cce43b47 100644 --- a/data/web/modals/admin.php +++ b/data/web/modals/admin.php @@ -4,8 +4,8 @@ if (!isset($_SESSION['mailcow_cc_role'])) { exit(); } ?> -