|
@@ -23,9 +23,37 @@ if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == "admi
|
|
if (!empty($transport_details)) {
|
|
if (!empty($transport_details)) {
|
|
// Remove [ and ]
|
|
// Remove [ and ]
|
|
$hostname_w_port = preg_replace('/\[|\]/', '', $nexthop);
|
|
$hostname_w_port = preg_replace('/\[|\]/', '', $nexthop);
|
|
|
|
+ preg_match('/\[.+\](:.+)/', $nexthop, $hostname_port_match);
|
|
|
|
+ preg_match('/\[\d\.\d\.\d\.\d\](:.+)/', $nexthop, $ipv4_port_match);
|
|
|
|
+ $has_bracket_and_port = (isset($hostname_port_match[1])) ? true : false;
|
|
|
|
+ $is_ipv4_and_has_port = (isset($ipv4_port_match[1])) ? true : false;
|
|
$skip_lookup_mx = strpos($nexthop, '[');
|
|
$skip_lookup_mx = strpos($nexthop, '[');
|
|
// Explode to hostname and port
|
|
// Explode to hostname and port
|
|
- list($hostname, $port) = explode(':', $hostname_w_port);
|
|
|
|
|
|
+ if ($has_bracket_and_port) {
|
|
|
|
+ $port = substr($hostname_w_port, strrpos($hostname_w_port, ':') + 1);
|
|
|
|
+ $hostname = rtrim($hostname_w_port, ':' . $port);
|
|
|
|
+ if (filter_var($hostname, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
|
|
|
+ $hostname = '[' . $hostname . ']:';
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ if ($is_ipv4_and_has_port) {
|
|
|
|
+ $port = substr($hostname_w_port, strrpos($hostname_w_port, ':') + 1);
|
|
|
|
+ $hostname = rtrim($hostname_w_port, ':' . $port);
|
|
|
|
+ }
|
|
|
|
+ if (filter_var($hostname_w_port, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
|
|
|
|
+ $hostname = $hostname_w_port;
|
|
|
|
+ $port = null;
|
|
|
|
+ }
|
|
|
|
+ elseif (filter_var($hostname_w_port, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
|
|
|
+ $hostname = '[' . $hostname_w_port . ']';
|
|
|
|
+ $port = null;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ echo "Invalid transport";
|
|
|
|
+ die();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// Try to get MX if host is not [host]
|
|
// Try to get MX if host is not [host]
|
|
if ($skip_lookup_mx === false) {
|
|
if ($skip_lookup_mx === false) {
|
|
getmxrr($hostname, $mx_records, $mx_weight);
|
|
getmxrr($hostname, $mx_records, $mx_weight);
|