Merge pull request #1899 from mailcow/alias-autodiscover

Hide autodiscover records on DNS page for alias domains
This commit is contained in:
André Peters 2018-10-15 22:45:33 +02:00 committed by GitHub
commit 58d0f51242
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,9 +10,11 @@ define('state_optional', " <sup>2</sup>");
if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "admin"|| $_SESSION['mailcow_cc_role'] == "domainadmin")) { if (isset($_SESSION['mailcow_cc_role']) && ($_SESSION['mailcow_cc_role'] == "admin"|| $_SESSION['mailcow_cc_role'] == "domainadmin")) {
$domains = mailbox('get', 'domains'); $domains = mailbox('get', 'domains');
foreach(mailbox('get', 'domains') as $dn) { $alias_domains = array();
$domains = array_merge($domains, mailbox('get', 'alias_domains', $dn)); foreach($domains as $dn) {
$alias_domains = array_merge($alias_domains, mailbox('get', 'alias_domains', $dn));
} }
$domains = array_merge($domains, $alias_domains);
if (isset($_GET['domain'])) { if (isset($_GET['domain'])) {
if (is_valid_domain_name($_GET['domain'])) { if (is_valid_domain_name($_GET['domain'])) {
@ -105,6 +107,7 @@ if ($_SESSION['mailcow_cc_role'] == "admin") {
'TLSA', 'TLSA',
generate_tlsa_digest($autodiscover_config['smtp']['server'], 25, 1) generate_tlsa_digest($autodiscover_config['smtp']['server'], 25, 1)
); );
if (!in_array($domain, $alias_domains)) {
$records[] = array( $records[] = array(
'_'.$https_port. '_'.$https_port.
'._tcp.'.$mailcow_hostname, '._tcp.'.$mailcow_hostname,
@ -153,28 +156,31 @@ if ($_SESSION['mailcow_cc_role'] == "admin") {
'TLSA', 'TLSA',
generate_tlsa_digest($autodiscover_config['sieve']['server'], $autodiscover_config['sieve']['port'], 1) generate_tlsa_digest($autodiscover_config['sieve']['server'], $autodiscover_config['sieve']['port'], 1)
); );
}
} }
$records[] = array( $records[] = array(
$domain, $domain,
'MX', 'MX',
$mailcow_hostname $mailcow_hostname
); );
$records[] = array( if (!in_array($domain, $alias_domains)) {
$records[] = array(
'autodiscover.'.$domain, 'autodiscover.'.$domain,
'CNAME', 'CNAME',
$mailcow_hostname $mailcow_hostname
); );
$records[] = array( $records[] = array(
'_autodiscover._tcp.'.$domain, '_autodiscover._tcp.'.$domain,
'SRV', 'SRV',
$mailcow_hostname. $mailcow_hostname.
' '.$https_port ' '.$https_port
); );
$records[] = array( $records[] = array(
'autoconfig.'.$domain, 'autoconfig.'.$domain,
'CNAME', 'CNAME',
$mailcow_hostname $mailcow_hostname
); );
}
$records[] = array( $records[] = array(
$domain, $domain,
'TXT', 'TXT',
@ -195,8 +201,9 @@ if (!empty($dkim = dkim('details', $domain))) {
$dkim['dkim_txt'] $dkim['dkim_txt']
); );
} }
$current_records = dns_get_record('_pop3._tcp.' . $domain, DNS_SRV); if (!in_array($domain, $alias_domains)) {
if (count($current_records) == 0 || $current_records[0]['target'] != '') { $current_records = dns_get_record('_pop3._tcp.' . $domain, DNS_SRV);
if (count($current_records) == 0 || $current_records[0]['target'] != '') {
if ($autodiscover_config['pop3']['tlsport'] != '110') { if ($autodiscover_config['pop3']['tlsport'] != '110') {
$records[] = array( $records[] = array(
'_pop3._tcp.' . $domain, '_pop3._tcp.' . $domain,
@ -204,16 +211,16 @@ if (count($current_records) == 0 || $current_records[0]['target'] != '') {
$autodiscover_config['pop3']['server'] . ' ' . $autodiscover_config['pop3']['tlsport'] $autodiscover_config['pop3']['server'] . ' ' . $autodiscover_config['pop3']['tlsport']
); );
} }
} }
else { else {
$records[] = array( $records[] = array(
'_pop3._tcp.' . $domain, '_pop3._tcp.' . $domain,
'SRV', 'SRV',
'. 0' '. 0'
); );
} }
$current_records = dns_get_record('_pop3s._tcp.' . $domain, DNS_SRV); $current_records = dns_get_record('_pop3s._tcp.' . $domain, DNS_SRV);
if (count($current_records) == 0 || $current_records[0]['target'] != '') { if (count($current_records) == 0 || $current_records[0]['target'] != '') {
if ($autodiscover_config['pop3']['port'] != '995') { if ($autodiscover_config['pop3']['port'] != '995') {
$records[] = array( $records[] = array(
'_pop3s._tcp.' . $domain, '_pop3s._tcp.' . $domain,
@ -221,48 +228,49 @@ if (count($current_records) == 0 || $current_records[0]['target'] != '') {
$autodiscover_config['pop3']['server'] . ' ' . $autodiscover_config['pop3']['port'] $autodiscover_config['pop3']['server'] . ' ' . $autodiscover_config['pop3']['port']
); );
} }
} }
else { else {
$records[] = array( $records[] = array(
'_pop3s._tcp.' . $domain, '_pop3s._tcp.' . $domain,
'SRV', 'SRV',
'. 0' '. 0'
); );
} }
if ($autodiscover_config['imap']['tlsport'] != '143') { if ($autodiscover_config['imap']['tlsport'] != '143') {
$records[] = array( $records[] = array(
'_imap._tcp.' . $domain, '_imap._tcp.' . $domain,
'SRV', 'SRV',
$autodiscover_config['imap']['server'] . ' ' . $autodiscover_config['imap']['tlsport'] $autodiscover_config['imap']['server'] . ' ' . $autodiscover_config['imap']['tlsport']
); );
} }
if ($autodiscover_config['imap']['port'] != '993') { if ($autodiscover_config['imap']['port'] != '993') {
$records[] = array( $records[] = array(
'_imaps._tcp.' . $domain, '_imaps._tcp.' . $domain,
'SRV', 'SRV',
$autodiscover_config['imap']['server'] . ' ' . $autodiscover_config['imap']['port'] $autodiscover_config['imap']['server'] . ' ' . $autodiscover_config['imap']['port']
); );
} }
if ($autodiscover_config['smtp']['tlsport'] != '587') { if ($autodiscover_config['smtp']['tlsport'] != '587') {
$records[] = array( $records[] = array(
'_submission._tcp.' . $domain, '_submission._tcp.' . $domain,
'SRV', 'SRV',
$autodiscover_config['smtp']['server'] . ' ' . $autodiscover_config['smtp']['tlsport'] $autodiscover_config['smtp']['server'] . ' ' . $autodiscover_config['smtp']['tlsport']
); );
} }
if ($autodiscover_config['smtp']['port'] != '465') { if ($autodiscover_config['smtp']['port'] != '465') {
$records[] = array( $records[] = array(
'_smtps._tcp.' . $domain, '_smtps._tcp.' . $domain,
'SRV', 'SRV',
$autodiscover_config['smtp']['server'] . ' ' . $autodiscover_config['smtp']['port'] $autodiscover_config['smtp']['server'] . ' ' . $autodiscover_config['smtp']['port']
); );
} }
if ($autodiscover_config['sieve']['port'] != '4190') { if ($autodiscover_config['sieve']['port'] != '4190') {
$records[] = array( $records[] = array(
'_sieve._tcp.' . $domain, '_sieve._tcp.' . $domain,
'SRV', 'SRV',
$autodiscover_config['sieve']['server'] . ' ' . $autodiscover_config['sieve']['port'] $autodiscover_config['sieve']['server'] . ' ' . $autodiscover_config['sieve']['port']
); );
}
} }
$record_types = array( $record_types = array(