1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Axsor\PhpIPAM\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Axsor\PhpIPAM\Models\Tag; |
6
|
|
|
use Axsor\PhpIPAM\Models\Address; |
7
|
|
|
use Axsor\PhpIPAM\Models\CustomField; |
8
|
|
|
use Axsor\PhpIPAM\Http\Requests\AddressRequest; |
9
|
|
|
|
10
|
|
|
class AddressController |
11
|
|
|
{ |
12
|
|
|
protected $request; |
13
|
|
|
|
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
$this->request = new AddressRequest; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param int $address |
21
|
|
|
* @return \Axsor\PhpIPAM\Models\Address |
22
|
|
|
*/ |
23
|
|
|
public function show($address) |
24
|
|
|
{ |
25
|
|
|
$response = $this->request->show($address); |
26
|
|
|
|
27
|
|
|
return new Address($response['data']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param int $address |
32
|
|
|
* @return bool |
33
|
|
|
*/ |
34
|
|
|
public function ping($address) |
35
|
|
|
{ |
36
|
|
|
$response = $this->request->ping($address); |
37
|
|
|
|
38
|
|
|
return $response['data']['exit_code'] == 0; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $ip |
43
|
|
|
* @return \Illuminate\Support\Collection |
44
|
|
|
*/ |
45
|
|
|
public function byIp(string $ip) |
46
|
|
|
{ |
47
|
|
|
$response = $this->request->byIp($ip); |
48
|
|
|
|
49
|
|
|
return response_to_collect($response, Address::class); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The provided hostname must match exactly. |
54
|
|
|
* |
55
|
|
|
* @param string $hostname |
56
|
|
|
* @return \Illuminate\Support\Collection |
57
|
|
|
*/ |
58
|
|
|
public function byHostname(string $hostname) |
59
|
|
|
{ |
60
|
|
|
$response = $this->request->byHostname($hostname); |
61
|
|
|
|
62
|
|
|
return response_to_collect($response, Address::class); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return \Illuminate\Support\Collection |
67
|
|
|
*/ |
68
|
|
|
public function customFields() |
69
|
|
|
{ |
70
|
|
|
$response = $this->request->customFields(); |
71
|
|
|
|
72
|
|
|
return response_to_collect($response, CustomField::class); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return \Illuminate\Support\Collection |
77
|
|
|
*/ |
78
|
|
|
public function tags() |
79
|
|
|
{ |
80
|
|
|
$response = $this->request->tags(); |
81
|
|
|
|
82
|
|
|
return response_to_collect($response, Tag::class); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param int $tag |
87
|
|
|
* @return \Axsor\PhpIPAM\Models\Tag |
88
|
|
|
*/ |
89
|
|
|
public function tag($tag) |
90
|
|
|
{ |
91
|
|
|
$response = $this->request->tag($tag); |
92
|
|
|
|
93
|
|
|
return new Tag($response['data']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param $tag |
98
|
|
|
* @return \Illuminate\Support\Collection |
99
|
|
|
*/ |
100
|
|
|
public function tagAddresses($tag) |
101
|
|
|
{ |
102
|
|
|
$response = $this->request->tagAddresses($tag); |
103
|
|
|
|
104
|
|
|
return response_to_collect($response, Address::class); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param array $address |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function create(array $address) |
112
|
|
|
{ |
113
|
|
|
$response = $this->request->create($address); |
114
|
|
|
|
115
|
|
|
return get_key_or_null($response, 'id'); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param $address |
120
|
|
|
* @param array $newData |
121
|
|
|
* @return mixed |
122
|
|
|
*/ |
123
|
|
|
public function update($address, array $newData) |
124
|
|
|
{ |
125
|
|
|
$response = $this->request->update($address, $newData); |
126
|
|
|
|
127
|
|
|
return $response['success']; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param $address |
132
|
|
|
* @return mixed |
133
|
|
|
*/ |
134
|
|
|
public function drop($address) |
135
|
|
|
{ |
136
|
|
|
$response = $this->request->drop($address); |
137
|
|
|
|
138
|
|
|
return $response['success']; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|