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