[Web] Expand IPv6 addresses for better comparison

master
andryyy 2020-05-26 20:04:22 +02:00
parent ad3cd1be02
commit a6af7cbc2e
No known key found for this signature in database
GPG Key ID: 8EC34FF2794E25EF
3 changed files with 13 additions and 9 deletions

View File

@ -94,7 +94,7 @@ if ($_SESSION['mailcow_cc_role'] == "admin") {
$records[] = array(
$mailcow_hostname,
'AAAA',
$ip6
expand_ipv6($ip6)
);
$records[] = array(
$ptr6,
@ -335,6 +335,11 @@ foreach ($records as $record) {
}
unset($current);
}
elseif ($record[1] == 'AAAA') {
foreach ($currents as &$current) {
$current['ipv6'] = expand_ipv6($current['ipv6']);
}
}
}
if ($record[1] == 'CNAME' && count($currents) == 0) {
@ -346,8 +351,8 @@ foreach ($records as $record) {
$currents = array(array('host' => $record[0], 'class' => 'IN', 'type' => 'CNAME', 'target' => $record[2]));
$aaaa = dns_get_record($record[0], DNS_AAAA);
$cname = dns_get_record($record[2], DNS_AAAA);
if (count($aaaa) == 0 || count($cname) == 0 || $aaaa[0]['ipv6'] != $cname[0]['ipv6']) {
$currents[0]['target'] = $aaaa[0]['ipv6'] . ' <sup>1</sup>';
if (count($aaaa) == 0 || count($cname) == 0 || expand_ipv6($aaaa[0]['ipv6']) != expand_ipv6($cname[0]['ipv6'])) {
$currents[0]['target'] = expand_ipv6($aaaa[0]['ipv6']) . ' <sup>1</sup>';
}
}
else {

View File

@ -355,6 +355,11 @@ function pem_to_der($pem_key) {
unset($lines[0]);
return base64_decode(implode('', $lines));
}
function expand_ipv6($ip) {
$hex = unpack("H*hex", inet_pton($ip));
$ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
return $ip;
}
function generate_tlsa_digest($hostname, $port, $starttls = null) {
if (!is_valid_domain_name($hostname)) {
return "Not a valid hostname";

View File

@ -1,12 +1,6 @@
<?php
error_reporting(0);
function expand_ipv6($ip) {
$hex = unpack("H*hex", inet_pton($ip));
$ip = substr(preg_replace("/([A-f0-9]{4})/", "$1:", $hex['hex']), 0, -1);
return $ip;
}
function get_spf_allowed_hosts($check_domain)
{
$hosts = array();