Skip to content

Commit 2fec7e6

Browse files
committed
Fixed #164
1 parent 35df648 commit 2fec7e6

35 files changed

+1277
-10
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Caching_ArgoTieredCache
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
public function getValue () {
16+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
17+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "argo/tiered_caching" );
18+
$api = Mage::getModel ("cloudflare/api_request");
19+
$api->setType ( $api::REQUEST_GET );
20+
return $api->resolve ( $endpoint );
21+
}
22+
23+
public function setValue ( $value ) {
24+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
25+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "argo/tiered_caching" );
26+
$api = Mage::getModel ("cloudflare/api_request");
27+
$api->setType ( $api::REQUEST_PATCH );
28+
$api->setPayload ( array ( "value" => $value ? "on" : "off" ) );
29+
return $api->resolve ( $endpoint );
30+
}
31+
32+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Caching_CrawlerHints
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
public function getValue () {
16+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
17+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "flags" );
18+
$api = Mage::getModel ("cloudflare/api_request");
19+
$api->setType ( $api::REQUEST_GET );
20+
$response = $api->resolve ( $endpoint );
21+
$value = null;
22+
if (
23+
isset ( $response ) &&
24+
isset ( $response->result ) &&
25+
isset ( $response->result->cache ) &&
26+
isset ( $response->result->cache->crawlhints_enabled )
27+
) {
28+
$value = $response->result->cache->crawlhints_enabled ? "on" : "off";
29+
}
30+
return array ( "result" => array ( "value" => $value ) );
31+
}
32+
33+
public function setValue ( $value ) {
34+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
35+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "flags/products/cache/changes" );
36+
$api = Mage::getModel ("cloudflare/api_request");
37+
$api->setType ( $api::REQUEST_POST );
38+
$api->setPayload ( array ( "feature" => "crawlhints_enabled", "value" => $value ) );
39+
return $api->resolve ( $endpoint );
40+
}
41+
42+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Caching_TieredCacheTopology
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
/**
16+
* @var string _endpoint Appended to zone endpoint
17+
* @var string _dataKey Key name used for value
18+
* @var integer _settingType Value cast type before sending
19+
*/
20+
protected $_endpoint = "cache/tiered_cache_smart_topology_enable";
21+
protected $_dataKey = "value";
22+
protected $_settingType = self::TYPE_STRING;
23+
24+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
3+
/**
4+
* This class inherits from the PageGetter class, so loading of the initial
5+
* values gets processed through the parent class.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Firewall_FirewallRules
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_PageGetter {
14+
15+
/**
16+
* @var string _endpoint Postfixed to zone endpoint
17+
*/
18+
protected $_endpoint = "firewall/rules";
19+
20+
/**
21+
* This method takes in an firewall rule id and asks the Cloudflare API to
22+
* delete the rule that corresponds to that id.
23+
* @param string id Firewall rule id
24+
* @return stdClass CF response to request
25+
*/
26+
public function deleteEntry ( $id ) {
27+
$endpoint = $this->getEndpoint ("firewall/rules/$id");
28+
$api = Mage::getModel ("cloudflare/api_request");
29+
$api->setType ( $api::REQUEST_DELETE );
30+
return $api->resolve ( $endpoint );
31+
}
32+
33+
/**
34+
* This method takes in all the information necessary to create an
35+
* firewall rule.
36+
* @param string name Rule description
37+
* @param string expression Rule expression
38+
* @param string action Rule action
39+
* @param int priority Rule priority
40+
* @param boolean paused Is the rule paused?
41+
* @param array<string> products Products if action == bypass
42+
* @return stdClass CF response to request
43+
*/
44+
public function create ( $name, $expression, $action, $priority, $paused, $products ) {
45+
$endpoint = $this->getEndpoint ("filters");
46+
$api = Mage::getModel ("cloudflare/api_request");
47+
$api->setType ( $api::REQUEST_POST );
48+
$api->setPayload ( array ( array (
49+
"expression" => $expression,
50+
)));
51+
$filter = $api->resolve ( $endpoint );
52+
if ( $filter && $filter->success ) {
53+
$endpoint = $this->getEndpoint ("firewall/rules");
54+
$api = Mage::getModel ("cloudflare/api_request");
55+
$api->setType ( $api::REQUEST_POST );
56+
$api->setPayload ( array ( array (
57+
"filter" => array ( "id" => $filter->result [0]->id ),
58+
"action" => $action,
59+
"description" => $name,
60+
"priority" => $priority,
61+
"products" => $products,
62+
"paused" => $paused
63+
)));
64+
return $api->resolve ( $endpoint );
65+
}
66+
return $filter;
67+
}
68+
69+
/**
70+
* This method takes in a new mode and an firewall rule it. It then asks
71+
* the Cloudflare API to change the mode based on what we passed.
72+
* @param string id Firewall rule id
73+
* @param string name Rule description
74+
* @param string filterId Filter expression id
75+
* @param string filterExpression Filter expression
76+
* @param string action Rule action
77+
* @param int priority Rule priority
78+
* @param boolean paused Is the rule paused?
79+
* @param array<string> products Products if action == bypass
80+
* @return stdClass CF response to request
81+
*/
82+
public function update ( $id, $name, $filterId, $filterExpression, $action, $priority, $paused, $products ) {
83+
$endpoint = $this->getEndpoint ("filters");
84+
$api = Mage::getModel ("cloudflare/api_request");
85+
$api->setType ( $api::REQUEST_PUT );
86+
$api->setPayload ( array ( array (
87+
"id" => $filterId,
88+
"expression" => $filterExpression
89+
)));
90+
$filter = $api->resolve ( $endpoint );
91+
if ( $filter && $filter->success ) {
92+
$endpoint = $this->getEndpoint ("firewall/rules");
93+
$api = Mage::getModel ("cloudflare/api_request");
94+
$api->setType ( $api::REQUEST_PUT );
95+
$api->setPayload ( array ( array (
96+
"id" => $id,
97+
"description" => $name,
98+
"paused" => $paused,
99+
"action" => $action,
100+
"priority" => $priority,
101+
"products" => $products,
102+
"filter" => array (
103+
"id" => $filterId,
104+
"expression" => $filterExpression
105+
)
106+
)));
107+
return $api->resolve ( $endpoint );
108+
}
109+
return $filter;
110+
}
111+
112+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Network_Grpc
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
public function getValue () {
16+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
17+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "flags" );
18+
$api = Mage::getModel ("cloudflare/api_request");
19+
$api->setType ( $api::REQUEST_GET );
20+
$response = $api->resolve ( $endpoint );
21+
$value = null;
22+
if (
23+
isset ( $response ) &&
24+
isset ( $response->result ) &&
25+
isset ( $response->result->protocols ) &&
26+
isset ( $response->result->protocols->gRPC )
27+
) {
28+
$value = $response->result->protocols->gRPC ? "on" : "off";
29+
}
30+
return array ( "result" => array ( "value" => $value ) );
31+
}
32+
33+
public function setValue ( $value ) {
34+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
35+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "flags/products/protocols/changes" );
36+
$api = Mage::getModel ("cloudflare/api_request");
37+
$api->setType ( $api::REQUEST_POST );
38+
$api->setPayload ( array ( "feature" => "gRPC", "value" => $value ) );
39+
return $api->resolve ( $endpoint );
40+
}
41+
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Network_Http2ToOrigin
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
public function getValue () {
16+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
17+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "origin_max_http_version" );
18+
$api = Mage::getModel ("cloudflare/api_request");
19+
$api->setType ( $api::REQUEST_GET );
20+
$response = $api->resolve ( $endpoint );
21+
if ( isset ( $response ) && isset ( $response->result ) && isset ( $response->result->value ) ) {
22+
$response->result->value = $response->result->value === "2" ? "on" : "off";
23+
}
24+
return $response;
25+
}
26+
27+
public function setValue ( $value ) {
28+
$zoneId = Mage::getSingleton ("cloudflare/api_overview_configuration")->getZoneId ();
29+
$endpoint = sprintf ( "zones/%s/%s", $zoneId, "origin_max_http_version" );
30+
$api = Mage::getModel ("cloudflare/api_request");
31+
$api->setType ( $api::REQUEST_PATCH );
32+
$api->setPayload ( array ( "value" => $value ? "2" : "1" ) );
33+
return $api->resolve ( $endpoint );
34+
}
35+
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* This model class inherits from the Setter model. It essentially wraps
5+
* that class in order to send passed data to the Cloudflare API endpoint.
6+
* @version 1.2.7
7+
* @package JetRails® Cloudflare
8+
* @author Rafael Grigorian <[email protected]>
9+
* @copyright © 2018 JETRAILS, All rights reserved
10+
* @license MIT https://opensource.org/licenses/MIT
11+
*/
12+
class JetRails_Cloudflare_Model_Adminhtml_Api_Speed_EarlyHints
13+
extends JetRails_Cloudflare_Model_Adminhtml_Api_Setter {
14+
15+
/**
16+
* @var string _endpoint Appended to zone endpoint
17+
* @var string _dataKey Key name used for value
18+
* @var integer _settingType Value cast type before sending
19+
*/
20+
protected $_endpoint = "settings/early_hints";
21+
protected $_dataKey = "value";
22+
protected $_settingType = self::TYPE_SWITCH;
23+
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This controller inherits from a generic controller that implements the
5+
* base functionality for interfacing with a switch section. This section
6+
* simply loads the initial value through the Cloudflare API as well as
7+
* gives the ability to change the value of said section to be on or off
8+
* though the 'toggle' action.
9+
* @version 1.2.7
10+
* @package JetRails® Cloudflare
11+
* @author Rafael Grigorian <[email protected]>
12+
* @copyright © 2018 JETRAILS, All rights reserved
13+
* @license MIT https://opensource.org/licenses/MIT
14+
*/
15+
class JetRails_Cloudflare_Cloudflare_Api_Caching_ArgoTieredCacheController
16+
extends JetRails_Cloudflare_Controller_Toggle {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This controller inherits from a generic controller that implements the
5+
* base functionality for interfacing with a switch section. This section
6+
* simply loads the initial value through the Cloudflare API as well as
7+
* gives the ability to change the value of said section to be on or off
8+
* though the 'toggle' action.
9+
* @version 1.2.7
10+
* @package JetRails® Cloudflare
11+
* @author Rafael Grigorian <[email protected]>
12+
* @copyright © 2018 JETRAILS, All rights reserved
13+
* @license MIT https://opensource.org/licenses/MIT
14+
*/
15+
class JetRails_Cloudflare_Cloudflare_Api_Caching_CrawlerHintsController
16+
extends JetRails_Cloudflare_Controller_Toggle {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/**
4+
* This controller inherits from a generic controller that implements the
5+
* base functionality for interfacing with a selection section. This section
6+
* simply loads the initial value through the Cloudflare API as well as
7+
* gives the ability to change the value of said section to whatever value
8+
* is being passed though the 'update' action.
9+
* @version 1.2.7
10+
* @package JetRails® Cloudflare
11+
* @author Rafael Grigorian <[email protected]>
12+
* @copyright © 2018 JETRAILS, All rights reserved
13+
* @license MIT https://opensource.org/licenses/MIT
14+
*/
15+
class JetRails_Cloudflare_Cloudflare_Api_Caching_TieredCacheTopologyController
16+
extends JetRails_Cloudflare_Controller_Update {}

0 commit comments

Comments
 (0)