-
Notifications
You must be signed in to change notification settings - Fork 1
/
Module.php
53 lines (46 loc) · 1.27 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
<?php declare(strict_types=1);
/**
* Custom PowerDNS Module
*
* @copyright Copyright (c) Apis Networks 2022
* @author Matt Saladna (matt@apisnetworks.com)
* @license MIT
*/
namespace apisnetworks\custom\powerdns;
class Module extends \Opcenter\Dns\Providers\Powerdns\Module
{
// @var string IPv4 or IPv6 parking IP address
const PARKING_IP = DNS_PARKING_IP;
public function add_zone(string $domain, string $ip): bool
{
$ns = $this->get_hosting_nameservers($domain);
if ($this->getParent($domain) || !$this->zone_exists($domain) ||
\Net_Gethost::gethostbyname_t($domain, 5000, $ns) !== self::PARKING_IP)
{
return parent::add_zone($domain, $ip);
}
return $this->reset($domain);
}
/**
* Remove DNS zone from nameserver
*
* @param string $domain
*
* @return bool
*/
public function remove_zone_backend(string $domain): bool
{
if (!$this->zone_exists($domain)) {
return true;
}
if (!$this->empty_zone($domain)) {
return warn("Failed to truncate zone `%s'", $domain);
}
$ttl = MAX($this->min_ttl(), 30);
foreach ((array)self::PARKING_IP as $ip) {
$rr = false === strpos(self::PARKING_IP, ':') ? 'A' : 'AAAA';
$this->add_record($domain, '', $rr, $ip, $ttl);
}
return true;
}
}