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