1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cloudflare\Zone\WAF\Packages; |
4
|
|
|
|
5
|
|
|
use Cloudflare\Api; |
6
|
|
|
use Cloudflare\Zone; |
7
|
|
|
use Cloudflare\Zone\WAF; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* CloudFlare API wrapper |
11
|
|
|
* |
12
|
|
|
* WAF Rules properties |
13
|
|
|
* |
14
|
|
|
* @author James Bell <[email protected]> |
15
|
|
|
* |
16
|
|
|
* @version 1 |
17
|
|
|
*/ |
18
|
|
View Code Duplication |
class Rules extends Api |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* List rule (permission needed: #zone:read) |
22
|
|
|
* Search, list, and filter rules within a package |
23
|
|
|
* |
24
|
|
|
* @param string $zone_id |
25
|
|
|
* @param string $package_id |
26
|
|
|
* @param string|null $description Public description of the rule |
27
|
|
|
* @param object|null $mode The rule mode |
28
|
|
|
* @param int|null $priority The order in which the individual rule is executed within the related group |
29
|
|
|
* @param string|null $group_id WAF group identifier tag |
30
|
|
|
* @param int|null $page Page number of paginated results |
31
|
|
|
* @param int|null $per_page Number of rules per page |
32
|
|
|
* @param string|null $order Field to order rules by |
33
|
|
|
* @param string|null $direction Direction to order rules |
34
|
|
|
* @param string|null $match Whether to match all search requirements or at least one (any) |
35
|
|
|
*/ |
36
|
|
|
public function rules($zone_id, $package_id, $description = null, $mode = null, $priority = null, $group_id = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null) |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$data = [ |
39
|
|
|
'description' => $description, |
40
|
|
|
'mode' => $mode, |
41
|
|
|
'priority' => $priority, |
42
|
|
|
'group_id' => $group_id, |
43
|
|
|
'page' => $page, |
44
|
|
|
'per_page' => $per_page, |
45
|
|
|
'order' => $order, |
46
|
|
|
'direction' => $direction, |
47
|
|
|
'match' => $match, |
48
|
|
|
]; |
49
|
|
|
|
50
|
|
|
return $this->get('/zones/'.$zone_id.'/firewall/waf/packages/'.$package_id.'/rules', $data); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Rule info (permission needed: #zone:read) |
55
|
|
|
* Individual information about a rule |
56
|
|
|
* |
57
|
|
|
* @param string $zone_id |
58
|
|
|
* @param string $package_id |
59
|
|
|
* @param string $identifier |
60
|
|
|
*/ |
61
|
|
|
public function info($zone_id, $package_id, $identifier) |
62
|
|
|
{ |
63
|
|
|
return $this->get('/zones/'.$zone_id.'/firewall/waf/packages/'.$package_id.'/rules/'.$identifier); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Update Rule group (permission needed: #zone:edit) |
68
|
|
|
* Update the state of a rule group |
69
|
|
|
* |
70
|
|
|
* @param string $zone_id |
71
|
|
|
* @param string $package_id |
72
|
|
|
* @param string $identifier |
73
|
|
|
* @param string|null $mode The mode to use when the rule is triggered. Value is restricted based on the allowed_modes of the rule |
74
|
|
|
*/ |
75
|
|
|
public function update($zone_id, $package_id, $identifier, $mode = null) |
76
|
|
|
{ |
77
|
|
|
$data = [ |
78
|
|
|
'mode' => $mode, |
79
|
|
|
]; |
80
|
|
|
|
81
|
|
|
return $this->patch('/zones/'.$zone_id.'/firewall/waf/packages/'.$package_id.'/rules/'.$identifier, $data); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.