Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/phpunit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ jobs:
listen-address=127.0.0.1
bind-interfaces
resolv-file=/etc/dnsmasq-upstream-resolv.conf
address=/${{ env.DAV_DOMAIN }}/127.0.0.1
local=/${{ env.DAV_DOMAIN }}/
host-record=${{ env.DAV_DOMAIN }},127.0.0.1
srv-host=_caldav._tcp.${{ env.DAV_DOMAIN }},${{ env.DAV_HOST }},10080,0,0
EOF

Expand Down
30 changes: 28 additions & 2 deletions lib/Service/CoreService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,41 @@ public function locateAccount(array $configuration): ?array {
}
// find dns service records
if (empty($configuration['location_host'])) {
$dns = dns_get_record('_caldavs._tcp.' . $identityDomain, DNS_SRV);
// attempt to locate service host and port using dns srv records
// example: _caldavs._tcp.example.com. IN SRV 0 5 443 dav.example.com.
$dnsService = '_caldavs._tcp.' . $identityDomain;
$dns = dns_get_record($dnsService, DNS_SRV);
if (empty($dns)) {
$dns = dns_get_record('_caldav._tcp.' . $identityDomain, DNS_SRV);
$dnsService = '_caldav._tcp.' . $identityDomain;
$dns = dns_get_record($dnsService, DNS_SRV);
}
if (empty($dns)) {
$dnsService = '_carddavs._tcp.' . $identityDomain;
$dns = dns_get_record($dnsService, DNS_SRV);
}
if (empty($dns)) {
$dnsService = '_carddav._tcp.' . $identityDomain;
$dns = dns_get_record($dnsService, DNS_SRV);
}
if (!empty($dns) && ($dns[0]['type'] ?? null) === 'SRV') {
$dnsTarget = $dns[0]['target'];
$dnsPort = $dns[0]['port'];
$configuration['location_host'] = $dnsTarget;
$configuration['location_port'] = $dnsPort;
// attempt to locate service path using dns txt records
// example: _caldavs._tcp.example.com. IN TXT "path=/dav/"
if (empty($configuration['location_path'])) {
$dnsTxt = dns_get_record($dnsService, DNS_TXT);
foreach (is_array($dnsTxt) ? $dnsTxt : [] as $record) {
if (($record['type'] ?? null) !== 'TXT') {
continue;
}
if (preg_match('/(?:^|\s)path=(\S+)/', $record['txt'] ?? '', $matches) === 1) {
$configuration['location_path'] = $matches[1];
break;
}
}
}
}
}
// find template for dns service target
Expand Down
Loading