Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #100 from cloudflare/jwineman/PI-552-advanced-zone…
Browse files Browse the repository at this point in the history
…-editor-check

Jwineman/pi 552 advanced zone editor check
  • Loading branch information
jwineman committed Jul 19, 2016
2 parents 5e8129c + c7bd24c commit cdac9f3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Cpanel/ClientActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public function patchDNSRecord()
*/
public function deleteZone()
{
if(!$this->cpanelAPI->isAdvancedZoneEditEnabled()) {
return $this->api->createAPIError(Partial::ADVANCED_ZONE_EDIT_DISABLED_ERROR);
}

$path_array = explode('/', $this->request->getUrl());
$zone_tag = $path_array[1];

Expand Down
11 changes: 11 additions & 0 deletions src/Cpanel/CpanelAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,15 @@ public function get_cpanel_dns_record_name($cloudflare_dns_record_name)
//cpanel uses the trailing dot for all record names
return $cloudflare_dns_record_name . ".";
}

/**
* @return bool
*/
public function isAdvancedZoneEditEnabled() {
/* Advanced Zone Editor is required to edit DNS records for partial zone provisioning.
* https://documentation.cpanel.net/display/SDK/Guide+to+the+LiveAPI+System+-+The+cpanelfeature%28%29+Method
* cPanel returns 1 = enabled, 0 = disabled
*/
return ($this->cpanel_api->cpanelfeature("zoneedit") === 1);
}
}
3 changes: 3 additions & 0 deletions src/Cpanel/HostActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function setPartialZoneSet(Partial $partialZoneSet) {
*/
public function partialZoneSet()
{
if(!$this->cpanelAPI->isAdvancedZoneEditEnabled()) {
return $this->api->createAPIError(Partial::ADVANCED_ZONE_EDIT_DISABLED_ERROR);
}
$bodyParameters = $this->request->getBody();
if (isset($bodyParameters["zone_name"])) {
if ($this->partialZoneSet->partialZoneSet("www." . $bodyParameters["zone_name"] . ".", $bodyParameters["zone_name"])) {
Expand Down
1 change: 1 addition & 0 deletions src/Cpanel/Zone/Partial.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Partial

const FORWARD_TO_SUFFIX = "cdn.cloudflare.net";
const RESOLVE_TO_PREFIX = "cloudflare-resolve-to.";
const ADVANCED_ZONE_EDIT_DISABLED_ERROR = "CloudFlare cPanel Plugin configuration issue! Please contact your hosting provider to enable \"Advanced DNS Zone Editor\"";

/**
* @param CpanelAPI $cpanel_api
Expand Down
36 changes: 36 additions & 0 deletions src/Test/Cpanel/CpanelAPITest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace CF\Cpanel\Test;

interface MockCpanelLiveAPI {
public function cpanelfeature($feature);
}

use CF\Cpanel\CpanelAPI;

class CpanelAPITest extends \PHPUnit_Framework_TestCase
{
private $mockCpanelLiveAPI;
private $mockLogger;
private $cpanelAPI;

public function setup() {
$this->mockCpanelLiveAPI = $this->getMockBuilder('CF\Cpanel\Test\MockCpanelLiveAPI')
->disableOriginalConstructor()
->getMock();
$this->mockLogger = $this->getMockBuilder('CF\Integration\DefaultLogger')
->disableOriginalConstructor()
->getMock();
$this->cpanelAPI = new CpanelAPI($this->mockCpanelLiveAPI, $this->mockLogger);
}

public function testIsAdvancedZoneEditEnabledReturnsTrueIfEnabled() {
$this->mockCpanelLiveAPI->method('cpanelfeature')->with("zoneedit")->willReturn(1);
$this->assertTrue($this->cpanelAPI->isAdvancedZoneEditEnabled());
}

public function testIsAdvancedZoneEditEnabledReturnsFalseIfDisabled() {
$this->mockCpanelLiveAPI->method('cpanelfeature')->with("zoneedit")->willReturn(0);
$this->assertFalse($this->cpanelAPI->isAdvancedZoneEditEnabled());
}
}
2 changes: 1 addition & 1 deletion src/Test/Cpanel/DataStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use CF\Cpanel\DataStore;

class PartialTest extends \PHPUnit_Framework_TestCase
class DataStoreTest extends \PHPUnit_Framework_TestCase
{
private $mockCpanelAPI;
private $mockLogger;
Expand Down

0 comments on commit cdac9f3

Please sign in to comment.