-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
78 lines (68 loc) · 2.12 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php declare(strict_types=1);
/**
* Copyright (C) Apis Networks, Inc - All Rights Reserved.
*
* MIT License
*
* Written by Matt Saladna <matt@apisnetworks.com>, May 2020
*/
namespace Opcenter\Mail\Providers\Mxroute;
// stub to make apnscp happy
use GuzzleHttp\Client;
class Module extends \Opcenter\Mail\Providers\Null\Module
{
protected const DKIM_RECORD = 'x._domainkey';
/**
* Get DNS records
*
* @param string $domain
* @param string $subdomain
* @return array
*/
public function provisioning_records(string $domain, string $subdomain = ''): array
{
$ttl = $this->dns_get_default('ttl');
$server = $this->getServiceValue('mail', 'key', MAIL_PROVIDER_KEY);
if (!$server) {
fatal('MXRoute server unset?');
}
$meta = (new Api())->getMetadata($server);
$records = [
new \Opcenter\Dns\Record($domain, [
'name' => $subdomain,
'ttl' => $ttl,
'rr' => 'TXT',
'parameter' => (new Api())->getSPF()
]),
new \Opcenter\Dns\Record($domain,
['name' => $subdomain, 'ttl' => $ttl, 'rr' => 'MX', 'parameter' => "10 " . $meta['hostname']]),
new \Opcenter\Dns\Record($domain,
['name' => $subdomain, 'ttl' => $ttl, 'rr' => 'MX', 'parameter' => "20 " . $meta['backuphost']]),
new \Opcenter\Dns\Record($domain, [
'name' => rtrim("mail.${subdomain}",'.'),
'ttl' => $ttl,
'rr' => 'CNAME',
'parameter' => $meta['hostname'] . "."
]),
new \Opcenter\Dns\Record($domain, [
'name' => rtrim("webmail.${subdomain}", '.'),
'ttl' => $ttl,
'rr' => 'CNAME',
'parameter' => $meta['hostname'] . "."
]),
];
$hostname = self::DKIM_RECORD . '.' . ltrim("${subdomain}.${domain}", '.');
$parameter = silence(static function () use ($hostname) {
return (new \Net_Gethost(5000))->lookup($hostname, DNS_TXT);
});
if ($parameter) {
$records[] = new \Opcenter\Dns\Record($domain, [
'name' => rtrim(self::DKIM_RECORD . ".${subdomain}", '.'),
'ttl' => $ttl,
'rr' => 'TXT',
'parameter' => $parameter
]);
}
return $records;
}
}