1: <?php
2:
3: namespace Cloudflare\User\Firewall;
4:
5: use Cloudflare\Api;
6: use Cloudflare\User;
7: use Cloudflare\User\Firewall;
8:
9: /**
10: * CloudFlare API wrapper
11: *
12: * User-level Firewall access rule
13: *
14: * @author James Bell <[email protected]>
15: *
16: * @version 1
17: */
18: class AccessRules extends Api
19: {
20: /**
21: * Default permissions level
22: *
23: * @var array
24: */
25: protected $permission_level = ['read' => '#billing:read', 'edit' => '#billing:edit'];
26:
27: /**
28: * List access rules (permission needed: #billing:read)
29: * Search, sort, and filter IP/country access rules
30: *
31: * @param string|null $mode The action to apply to a matched request
32: * @param string|null $configuration_target The rule configuration target
33: * @param string|null $configuration_value Search by IP, range, or country code
34: * @param int|null $page Page number of paginated results
35: * @param int|null $per_page Number of items per page
36: * @param string|null $order Field to order rules by
37: * @param string|null $direction Direction to order rules
38: * @param string|null $match Whether to match all search requirements or at least one (any)
39: */
40: public function rules($mode = null, $configuration_target = null, $configuration_value = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null)
41: {
42: $data = [
43: 'mode' => $mode,
44: 'configuration_target' => $configuration_target,
45: 'configuration_value' => $configuration_value,
46: 'page' => $page,
47: 'per_page' => $per_page,
48: 'order' => $order,
49: 'direction' => $direction,
50: 'match' => $match,
51: ];
52:
53: return $this->get('/user/firewall/access_rules/rules', $data);
54: }
55:
56: /**
57: * Create access rule (permission needed: #billing:edit)
58: * Make a new IP, IP range, or country access rule for all zones owned by the user.
59: * Note: If you would like to create an access rule that applies to a specific zone only, use the zone firewall endpoints.
60: *
61: * @param string $mode The action to apply to a matched request
62: * @param object $configuration Rule configuration
63: * @param string|null $notes A personal note about the rule. Typically used as a reminder or explanation for the rule.
64: */
65: public function create($mode, object $configuration, $notes = null)
66: {
67: $data = [
68: 'mode' => $mode,
69: 'configuration' => $configuration,
70: 'notes' => $notes,
71: ];
72:
73: return $this->post('/user/firewall/access_rules/rules', $data);
74: }
75:
76: /**
77: * Update access rule (permission needed: #billing:edit)
78: * Update rule state and/or configuration. This will be applied across all zones owned by the user.
79: *
80: * @param string $identifier
81: * @param string|null $mode The action to apply to a matched request
82: * @param object|null $configuration Rule configuration
83: * @param string|null $notes A personal note about the rule. Typically used as a reminder or explanation for the rule.
84: */
85: public function update($identifier, $mode = null, $configuration = null, $notes = null)
86: {
87: $data = [
88: 'mode' => $mode,
89: 'configuration' => $configuration,
90: 'notes' => $notes,
91: ];
92:
93: return $this->patch('/user/firewall/access_rules/rules/'.$identifier, $data);
94: }
95:
96: /**
97: * Delete access rule (permission needed: #billing:edit)
98: * Remove an access rule so it is no longer evaluated during requests. This will apply to all zones owned by the user
99: *
100: * @param string $identifier
101: */
102: public function delete_rule($identifier)
103: {
104: return $this->delete('/user/firewall/access_rules/rules/'.$identifier);
105: }
106: }
107: