1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Axsor\PhpIPAM; |
4
|
|
|
|
5
|
|
|
use Axsor\PhpIPAM\Http\Controllers\SectionController; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use Axsor\PhpIPAM\Http\Requests\AddressRequest; |
8
|
|
|
use Axsor\PhpIPAM\Http\Controllers\AddressController; |
9
|
|
|
|
10
|
|
|
class PhpIPAM |
11
|
|
|
{ |
12
|
|
|
private $config; |
13
|
|
|
|
14
|
|
|
private $client; |
15
|
|
|
|
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->config = config('phpipam'); |
19
|
|
|
$this->client = new Client; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Set custom config to connect to PhpIPAM. |
24
|
|
|
* |
25
|
|
|
* @param array $config |
26
|
|
|
* @return $this |
27
|
|
|
*/ |
28
|
|
|
public function use(array $config) |
29
|
|
|
{ |
30
|
|
|
$this->config = $config; |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Unset custom config to connect to PhpIPAM. |
37
|
|
|
* Config will be read from your environment. |
38
|
|
|
* |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function useDefaultConfig() |
42
|
|
|
{ |
43
|
|
|
$this->config = config('phpipam'); |
44
|
|
|
|
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function setClient(Client $client) |
49
|
|
|
{ |
50
|
|
|
$this->client = $client; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getConfig() |
54
|
|
|
{ |
55
|
|
|
return $this->config; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getClient() |
59
|
|
|
{ |
60
|
|
|
return $this->client; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// WRAPPED DATA |
64
|
|
|
// ADDRESSES CONTROLLER |
65
|
|
|
public function address($address) |
66
|
|
|
{ |
67
|
|
|
return (new AddressController)->show($address); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function ping($address) |
71
|
|
|
{ |
72
|
|
|
return (new AddressController)->ping($address); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function searchIp(string $ip) |
76
|
|
|
{ |
77
|
|
|
return (new AddressController)->searchIp($ip); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function searchHostname(string $hostname) |
81
|
|
|
{ |
82
|
|
|
return (new AddressController)->searchHostname($hostname); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function customFields() |
86
|
|
|
{ |
87
|
|
|
return (new AddressController)->customFields(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function tags() |
91
|
|
|
{ |
92
|
|
|
return (new AddressController)->tags(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function tag($tag) |
96
|
|
|
{ |
97
|
|
|
return (new AddressController)->tag($tag); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function tagAddresses($tag) |
101
|
|
|
{ |
102
|
|
|
return (new AddressController)->tagAddresses($tag); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function addressCreate(array $address) |
106
|
|
|
{ |
107
|
|
|
return (new AddressController)->create($address); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function addressUpdate($address, array $newData) |
111
|
|
|
{ |
112
|
|
|
return (new AddressController)->update($address, $newData); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function addressDrop($address) |
116
|
|
|
{ |
117
|
|
|
return (new AddressController)->drop($address); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// SECTION CONTROLLER |
121
|
|
|
public function sections() |
122
|
|
|
{ |
123
|
|
|
return (new SectionController)->index(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function section($section) |
127
|
|
|
{ |
128
|
|
|
return (new SectionController)->show($section); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function sectionSubnets($section) |
132
|
|
|
{ |
133
|
|
|
return (new SectionController)->subnets($section); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function sectionByName(string $section) |
137
|
|
|
{ |
138
|
|
|
return (new SectionController)->byName($section); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// TODO upgrade PhpIPAM from 1.3 to 1.5 |
142
|
|
|
//public function sectionCustomFields() |
143
|
|
|
//{ |
144
|
|
|
// return (new SectionController)->customFields(); |
145
|
|
|
//} |
146
|
|
|
|
147
|
|
|
public function sectionCreate(array $section) |
148
|
|
|
{ |
149
|
|
|
return (new SectionController)->create($section); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function sectionUpdate($section, array $newData) |
153
|
|
|
{ |
154
|
|
|
return (new SectionController)->update($section, $newData); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function sectionDrop($section) |
158
|
|
|
{ |
159
|
|
|
return (new SectionController)->drop($section); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
|
164
|
|
|
// RAW DATA |
165
|
|
|
// ADDRESS REQUEST |
166
|
|
|
public function addressRaw($address) |
167
|
|
|
{ |
168
|
|
|
return (new AddressRequest)->show($address); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function pingRaw($address) |
172
|
|
|
{ |
173
|
|
|
return (new AddressRequest)->ping($address); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function searchIpRaw(string $ip) |
177
|
|
|
{ |
178
|
|
|
return (new AddressRequest)->searchIp($ip); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function searchHostnameRaw(string $hostname) |
182
|
|
|
{ |
183
|
|
|
return (new AddressRequest)->searchHostname($hostname); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function customFieldsRaw() |
187
|
|
|
{ |
188
|
|
|
return (new AddressRequest)->customFields(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function tagsRaw() |
192
|
|
|
{ |
193
|
|
|
return (new AddressRequest)->tags(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function tagRaw($tag) |
197
|
|
|
{ |
198
|
|
|
return (new AddressRequest)->tag($tag); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function tagAddressesRaw($tag) |
202
|
|
|
{ |
203
|
|
|
return (new AddressRequest)->tagAddresses($tag); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function addressCreateRaw(array $address) |
207
|
|
|
{ |
208
|
|
|
return (new AddressRequest)->create($address); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function addressUpdateRaw($address, array $newData) |
212
|
|
|
{ |
213
|
|
|
return (new AddressRequest)->update($address, $newData); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function addressDropRaw($address) |
217
|
|
|
{ |
218
|
|
|
return (new AddressRequest)->drop($address); |
219
|
|
|
} |
220
|
|
|
} |
221
|
|
|
|