Skip to content

Commit 8c0a163

Browse files
author
Rafael Grigorian
committed
Fixed #48
1 parent 1fb8b15 commit 8c0a163

File tree

9 files changed

+383
-71
lines changed

9 files changed

+383
-71
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Controller\Adminhtml\Api\Dns\CustomNameservers;
4+
5+
use JetRails\Cloudflare\Controller\Adminhtml\Action;
6+
7+
/**
8+
* This controller inherits from a generic controller that implements the
9+
* base functionality for interfacing with a selection section. This section
10+
* simply loads the initial value through the Cloudflare API as well as
11+
* gives the ability to change the value of said section to whatever value
12+
* is being passed though the 'update' action.
13+
* @version 1.2.6
14+
* @package JetRails® Cloudflare
15+
* @author Rafael Grigorian <[email protected]>
16+
* @copyright © 2018 JETRAILS, All rights reserved
17+
* @license MIT https://opensource.org/licenses/MIT
18+
*/
19+
class Edit extends Action {
20+
21+
public function execute () {
22+
$response = $this->_api->edit (
23+
$this->_request->getParam ("nameservers")
24+
? $this->_request->getParam ("nameservers")
25+
: array ()
26+
);
27+
return $this->_sendResponse ( $response );
28+
}
29+
30+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Controller\Adminhtml\Api\Dns\CustomNameservers;
4+
5+
use JetRails\Cloudflare\Controller\Adminhtml\Getter;
6+
7+
/**
8+
* This controller inherits from a generic controller that implements the
9+
* base functionality for interfacing with a getter model. This action
10+
* simply loads the initial value through the Cloudflare API. The rest of
11+
* this class extends on that functionality and adds more endpoints.
12+
* @version 1.2.6
13+
* @package JetRails® Cloudflare
14+
* @author Rafael Grigorian <[email protected]>
15+
* @copyright © 2018 JETRAILS, All rights reserved
16+
* @license MIT https://opensource.org/licenses/MIT
17+
*/
18+
class Index extends Getter {}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace JetRails\Cloudflare\Model\Adminhtml\Api\Dns;
4+
5+
use stdClass;
6+
use JetRails\Cloudflare\Model\Adminhtml\Api\Getter;
7+
use JetRails\Cloudflare\Model\Adminhtml\Api\Request;
8+
9+
/**
10+
* This class is a parent class that child classes inherit from. It
11+
* implements functionality to easily get a setting value from Cloudflare
12+
* using their API.
13+
* @version 1.2.6
14+
* @package JetRails® Cloudflare
15+
* @author Rafael Grigorian <[email protected]>
16+
* @copyright © 2018 JETRAILS, All rights reserved
17+
* @license MIT https://opensource.org/licenses/MIT
18+
*/
19+
class CustomNameservers extends Getter {
20+
21+
/**
22+
* @var string _endpoint Appended to zone endpoint
23+
*/
24+
protected $_endpoint = "";
25+
26+
/**
27+
* This method simply constructs a GET request to the endpoint that is
28+
* most appropriate based on how this object was configured.
29+
* @return stdClass CF response to request
30+
*/
31+
public function getValue () {
32+
$endpoint = $this->getEndpoint ();
33+
$this->_requestModel->setType ( Request::REQUEST_GET );
34+
$response = $this->_requestModel->resolve ( $endpoint );
35+
if ( $response->success ) {
36+
$response->result = $response->result->vanity_name_servers_ips
37+
? $response->result->vanity_name_servers_ips
38+
: new stdClass ();
39+
}
40+
return $response;
41+
}
42+
43+
/**
44+
* This method takes in a list of custom nameservers and it updates it
45+
* accordingly using Cloudflare's API.
46+
* @param array records List of custom nameservers
47+
* @return stdClass CF response to request
48+
*/
49+
public function edit ( $records ) {
50+
$endpoint = $this->getEndpoint ();
51+
$this->_requestModel->setType ( Request::REQUEST_PATCH );
52+
$this->_requestModel->setData ( array ( "vanity_name_servers" => $records ));
53+
$response = $this->_requestModel->resolve ( $endpoint );
54+
if ( $response->success ) {
55+
$response->result = $response->result->vanity_name_servers_ips
56+
? $response->result->vanity_name_servers_ips
57+
: new stdClass ();
58+
}
59+
return $response;
60+
}
61+
62+
}

src/app/code/JetRails/Cloudflare/etc/acl.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
<resource
5454
id="JetRails_Cloudflare::cloudflare_nameservers"
5555
title="Cloudflare Nameservers" />
56+
<resource
57+
id="JetRails_Cloudflare::custom_nameservers"
58+
title="Custom Nameservers" />
5659
<resource
5760
id="JetRails_Cloudflare::cname_flattening"
5861
title="CNAME Flattening" />

src/app/code/JetRails/Cloudflare/view/adminhtml/templates/dns.phtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
echo $block->renderSections ( "dns", array (
44
"dns_records",
55
"cloudflare_nameservers",
6+
"custom_nameservers",
67
"cname_flattening"
78
));
89

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<section
2+
class="cloudflare dns custom_nameservers initialize loading"
3+
data-endpoint="<?php echo $block->getApiEndpoint () ?>"
4+
data-form-key="<?php echo $block->getFormKey () ?>"
5+
data-tab-name="dns"
6+
data-section-name="custom_nameservers" >
7+
<div class="row" >
8+
<div class="wrapper_left" >
9+
<span class="section_title" >Custom Nameservers</span>
10+
<p>Custom nameservers allow you to create your own, unique nameservers in place of your assigned Cloudflare nameservers. To switch to using custom nameservers, first create them here, then add them as glue records at your registrar.</p>
11+
</div>
12+
<div class="wrapper_right" >
13+
<div>
14+
<input id="action" class="trigger" type="button" value="Add custom nameservers" data-target="edit" />
15+
</div>
16+
</div>
17+
</div>
18+
<div class="row" >
19+
<table class="nameservers" cellpadding="0" cellspacing="0" >
20+
<thead>
21+
<tr>
22+
<th>Nameserver</th>
23+
<th>IPv4 Address</th>
24+
<th>IPv6 Address</th>
25+
</tr>
26+
</thead>
27+
<tbody></tbody>
28+
</table>
29+
</div>
30+
<div class="lightbox" style="background-image: url(<?php echo $block->getViewFileUrl ('JetRails_Cloudflare/images/loading.svg') ?>)" ></div>
31+
<div class="row collapsable" >
32+
<div class="wrapper_bottom" >
33+
<a data-tab="help" >Help</a>
34+
</div>
35+
<div data-tab-content="help" >
36+
<h4>What is a custom nameserver?</h4>
37+
<p>Cloudflare enables you to use nameservers which reflect your own domain (eg. ns.example.com). You can use them in place of your Cloudflare assigned nameservers.</p>
38+
<p>Custom nameservers have the following limitations:</p>
39+
<ul>
40+
<li>You must have between two and five custom nameservers</li>
41+
<li>The custom nameservers can only be created as subdomains of example.com (e.g. ns1.example.com and ns2.example.com).</li>
42+
<li>When custom nameservers are created, glue records need to be created at your registrar with the IP addresses of your custom nameservers. Failure to do so can cause all DNS lookups for your site to fail. Further information can be found here: <a href="https://support.cloudflare.com/hc/articles/200169006" >Can I get vanity or custom nameservers using Cloudflare?</a></li>
43+
</ul>
44+
<p><strong>Note:</strong> Your assigned Cloudflare nameservers will continue to work even after custom nameservers are enabled.</p>
45+
</div>
46+
</div>
47+
</section>

0 commit comments

Comments
 (0)