1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the africc/pdns-client library. |
5
|
|
|
* |
6
|
|
|
* (c) Gunter Grodotzki <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE file |
9
|
|
|
* that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AfriCC\Pdns\Endpoints; |
13
|
|
|
|
14
|
|
|
use AfriCC\Pdns\Helper; |
15
|
|
|
use AfriCC\Pdns\Types\Typable; |
16
|
|
|
|
17
|
|
|
class Zones extends Endpoint |
18
|
|
|
{ |
19
|
|
|
protected $data; |
20
|
|
|
|
21
|
|
|
public function all() |
22
|
|
|
{ |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function show($name) |
26
|
|
|
{ |
27
|
|
|
$this->appendToUri(sprintf('/%s', Helper::canonical($name))); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function add($name, array $nameservers, $account = '') |
31
|
|
|
{ |
32
|
|
|
$this->method = 'POST'; |
33
|
|
|
$this->data = [ |
34
|
|
|
'account' => $account, |
35
|
|
|
'kind' => 'native', |
36
|
|
|
'soa_edit_api' => 'INCEPTION-INCREMENT', |
37
|
|
|
'masters' => [], |
38
|
|
|
'name' => Helper::canonical($name), |
39
|
|
|
'nameservers' => [], |
40
|
|
|
'rrsets' => array_merge($this->createSOA($name, $nameservers[0]), $this->createNS($name, $nameservers)), |
41
|
|
|
]; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function upsertRecord($name, Typable $rrset) |
45
|
|
|
{ |
46
|
|
|
$this->method = 'PATCH'; |
47
|
|
|
$this->data = ['rrsets' => [$rrset->payload('REPLACE')]]; |
|
|
|
|
48
|
|
|
$this->appendToUri(sprintf('/%s', Helper::canonical($name))); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function deleteRecord($name, Typable $rrset) |
52
|
|
|
{ |
53
|
|
|
$this->method = 'PATCH'; |
54
|
|
|
$this->data = ['rrsets' => [$rrset->payload('DELETE')]]; |
|
|
|
|
55
|
|
|
$this->appendToUri(sprintf('/%s', Helper::canonical($name))); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getPayload() |
59
|
|
|
{ |
60
|
|
|
return json_encode($this->data); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function createNS($name, array $nameservers) |
64
|
|
|
{ |
65
|
|
|
$rrsets = $records = []; |
66
|
|
|
|
67
|
|
|
foreach ($nameservers as $nameserver) { |
68
|
|
|
$records[] = [ |
69
|
|
|
'content' => Helper::canonical($nameserver), |
70
|
|
|
'disabled' => false, |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$rrsets[] = [ |
75
|
|
|
'records' => $records, |
76
|
|
|
'name' => Helper::canonical($name), |
77
|
|
|
'ttl' => 86400, |
78
|
|
|
'type' => 'NS', |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return $rrsets; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
protected function createSOA($name, $primary) |
85
|
|
|
{ |
86
|
|
|
$rrsets = [ |
87
|
|
|
'records' => [ |
88
|
|
|
[ |
89
|
|
|
'content' => sprintf( |
90
|
|
|
// primary | contact | serial | refresh | retry | expire | ttl |
91
|
|
|
'%s %s %s 3600 1800 604800 600', |
92
|
|
|
Helper::canonical($primary), |
93
|
|
|
Helper::canonical('dnsadmin.' . $name), |
94
|
|
|
date('Ymd') . sprintf('%02d', rand(0, 99)) |
95
|
|
|
), |
96
|
|
|
'disabled' => false, |
97
|
|
|
], |
98
|
|
|
], |
99
|
|
|
'name' => Helper::canonical($name), |
100
|
|
|
'ttl' => 86400, |
101
|
|
|
'type' => 'SOA', |
102
|
|
|
]; |
103
|
|
|
|
104
|
|
|
return [$rrsets]; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.