|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the Vultr PHP library. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Albert Leitato <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Vultr\Api; |
|
11
|
|
|
|
|
12
|
|
|
use Vultr\Entity\FirewallRule as FirewallRuleEntity; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @author Albert Leitato <[email protected]> |
|
16
|
|
|
*/ |
|
17
|
|
|
class FirewallRule extends AbstractApi |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* List all firewall rules on the current account. |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://www.vultr.com/api/#firewall_rule_list |
|
23
|
|
|
* |
|
24
|
|
|
* @return FirewallRuleEntity |
|
25
|
|
|
*/ |
|
26
|
|
|
public function list($groupId, $direction, $ipType) |
|
27
|
|
|
{ |
|
28
|
|
|
$params = 'FIREWALLGROUPID=%s&direction=%s&ip_type=%s'; |
|
29
|
|
|
$response = $this->adapter->get(\sprintf('%s/firewall/rule_list' . $params, $this->endpoint, $groupId, $direction, $ipType)); |
|
30
|
|
|
|
|
31
|
|
|
return $this->handleResponse($response, self::class, true); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Create a rule in a firewall group. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $groupId Target firewall group |
|
38
|
|
|
* @param string $direction Direction of rule. Possible values: "in". |
|
39
|
|
|
* @param string $ipType IP address type. Possible values: "v4", "v6". |
|
40
|
|
|
* @param string $protocol Protocol type. Possible |
|
41
|
|
|
* @param string $subnet IP address representing a subnet |
|
42
|
|
|
* @param int $subnetSize iP prefix size in bits |
|
43
|
|
|
* @param string $port tCP/UDP only |
|
44
|
|
|
* |
|
45
|
|
|
* @throws HttpException |
|
46
|
|
|
*/ |
|
47
|
|
|
public function create(string $groupId, string $direction, string $ipType, string $protocol, string $subnet, int $subnetSize, $port = null) |
|
48
|
|
|
{ |
|
49
|
|
|
$content = [ |
|
50
|
|
|
'FIREWALLGROUPID' => $groupId, |
|
51
|
|
|
'direction' => $direction, |
|
52
|
|
|
'ip_type' => $ipType, |
|
53
|
|
|
'protocol' => $protocol, |
|
54
|
|
|
'subnet' => $subnet, |
|
55
|
|
|
'subnet_size' => $subnetSize, |
|
56
|
|
|
]; |
|
57
|
|
|
if (null !== $port) { |
|
58
|
|
|
$content['port'] = $port; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$response = $this->adapter->post(\sprintf('%s/firewall/rule_create', $this->endpoint), $content); |
|
62
|
|
|
|
|
63
|
|
|
return \json_decode($response); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Delete a rule in a firewall group. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $groupId Firewall group to delete |
|
70
|
|
|
* @param int $ruleNumber Rule number to delete |
|
71
|
|
|
* |
|
72
|
|
|
* @throws HttpException |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
public function delete($groupId, $ruleNumber) |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$data = [ |
|
77
|
|
|
'FIREWALLGROUPID' => $groupId, |
|
78
|
|
|
'rulenumber' => $ruleNumber, |
|
79
|
|
|
]; |
|
80
|
|
|
$this->adapter->post(\sprintf('%s/firewall/rule_delete', $this->endpoint), $data); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|