1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of Badcow DNS Library. |
7
|
|
|
* |
8
|
|
|
* (c) Samuel Williams <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Badcow\DNS\Validator; |
15
|
|
|
|
16
|
|
|
use Badcow\DNS\Rdata\CNAME; |
17
|
|
|
use Badcow\DNS\ResourceRecord; |
18
|
|
|
use Badcow\DNS\Zone; |
19
|
|
|
|
20
|
|
|
abstract class AbstractValidator |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Test jf the the $record can be added to the $zone. |
24
|
|
|
* |
25
|
|
|
* @param Zone $zone |
26
|
|
|
* @param ResourceRecord $record |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
abstract public static function canAddToZone(Zone $zone, ResourceRecord $record): bool; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Ensure $zone does not contain existing CNAME alias corresponding to $record's name. |
34
|
|
|
* |
35
|
|
|
* E.g. |
36
|
|
|
* www IN CNAME example.com. |
37
|
|
|
* www IN TXT "This is a violation of DNS specifications." |
38
|
|
|
* |
39
|
|
|
* @see https://tools.ietf.org/html/rfc1034#section-3.6.2 |
40
|
|
|
* |
41
|
|
|
* @param Zone $zone |
42
|
|
|
* @param ResourceRecord $record |
43
|
|
|
* |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
2 |
|
public static function noCNAMEinZone(Zone $zone, ResourceRecord $record): bool |
47
|
|
|
{ |
48
|
2 |
|
foreach ($zone as $rr) { |
49
|
2 |
|
if (CNAME::TYPE === $rr->getType() |
50
|
2 |
|
&& $record->getName() === $rr->getName()) { |
51
|
2 |
|
return false; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Ensure $zone does not contain existing record corresponding to $record's name and type. |
60
|
|
|
* |
61
|
|
|
* @param Zone $zone |
62
|
|
|
* @param ResourceRecord $record |
63
|
|
|
* |
64
|
|
|
* @return bool |
65
|
|
|
*/ |
66
|
1 |
|
public static function noDuplicate(Zone $zone, ResourceRecord $record): bool |
67
|
|
|
{ |
68
|
1 |
|
foreach ($zone as $rr) { |
69
|
1 |
|
if ($record->getType() === $rr->getType() |
70
|
1 |
|
&& $record->getName() === $rr->getName()) { |
71
|
1 |
|
return false; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
1 |
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Ensure $zone does not contain existing record corresponding to $record's name only. |
80
|
|
|
* |
81
|
|
|
* @param Zone $zone |
82
|
|
|
* @param ResourceRecord $record |
83
|
|
|
* |
84
|
|
|
* @return bool |
85
|
|
|
*/ |
86
|
1 |
|
public static function nameDoesntExists(Zone $zone, ResourceRecord $record): bool |
87
|
|
|
{ |
88
|
1 |
|
foreach ($zone as $rr) { |
89
|
1 |
|
if ($record->getName() === $rr->getName()) { |
90
|
1 |
|
return false; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
return true; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|