Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
archey347 committed Jun 20, 2018
2 parents 8b00128 + 58b5569 commit 471f257
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 98 deletions.
4 changes: 2 additions & 2 deletions routes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$app->get('', 'UserFrosting\Sprinkle\Dnsadmin\Controller\AdminController:pageZonesAdmin');
$app->get('/zones/z/{id}', 'UserFrosting\Sprinkle\Dnsadmin\Controller\AdminController:pageZoneEntriesAdmin');

});
})->add('authGuard');

$app->group('/modals/dnsadmin', function () use ($app) {
$app->get('/create-zone', 'UserFrosting\Sprinkle\Dnsadmin\Controller\AdminController:modalCreateZone');
Expand All @@ -19,4 +19,4 @@



});
})->add('authGuard');
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@



});
})->add('authGuard');
104 changes: 99 additions & 5 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use UserFrosting\Fortress\Adapter\JqueryValidationAdapter;
use UserFrosting\Sprinkle\Dnsadmin\Database\Models\Zone;
use UserFrosting\Sprinkle\Dnsadmin\Database\Models\ZoneEntry;

use Badcow\DNS\Rdata\RdataException;
use UserFrosting\Support\Exception\ForbiddenException;

/**
* Controller class that manages all of the DNS Admin front end UI
Expand All @@ -34,6 +35,16 @@ class AdminController extends SimpleController
*/
public function pageZonesAdmin(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

// Get the zone create validation rules
$schema_create = new RequestSchema('schema://requests/zone-create.yaml');
$validator_create = new JqueryValidationAdapter($schema_create, $this->ci->translator);
Expand Down Expand Up @@ -62,6 +73,16 @@ public function pageZonesAdmin(Request $request, Response $response, $args)
*/
public function pageZoneEntriesAdmin(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$zone = Zone::find($args['id']);

if(!$zone) {
Expand Down Expand Up @@ -98,6 +119,16 @@ public function pageZoneEntriesAdmin(Request $request, Response $response, $args
*/
public function modalCreateZone(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

return $this->ci->view->render($response, 'modals/zone.html.twig', [
"form" => [
"id" => "form-zone-create",
Expand All @@ -118,6 +149,16 @@ public function modalCreateZone(Request $request, Response $response, $args)
*/
public function modalEditZone(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_id = $request->getQueryParam('id');
Expand Down Expand Up @@ -155,6 +196,16 @@ public function modalEditZone(Request $request, Response $response, $args)
*/
public function modalDeleteZone(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_id = $request->getQueryParam('id');
Expand Down Expand Up @@ -189,6 +240,16 @@ public function modalDeleteZone(Request $request, Response $response, $args)
*/
public function modalCreateZoneEntry(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_id = $request->getQueryParam('id');
Expand Down Expand Up @@ -223,6 +284,16 @@ public function modalCreateZoneEntry(Request $request, Response $response, $args
*/
public function modalEditZoneEntry(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_entry_id = $request->getQueryParam('id');
Expand Down Expand Up @@ -258,6 +329,16 @@ public function modalEditZoneEntry(Request $request, Response $response, $args)
*/
public function modalDeleteZoneEntry(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_entry_id = $request->getQueryParam('id');
Expand Down Expand Up @@ -307,6 +388,16 @@ public function getEntryTypes($zone_type)
*/
public function modalExportZoneEntry(Request $request, Response $response, $args)
{
/** @var UserFrosting\Sprinkle\Account\Authorize\AuthorizationManager */
$authorizer = $this->ci->authorizer;

/** @var UserFrosting\Sprinkle\Account\Model\User $currentUser */
$currentUser = $this->ci->currentUser;

if (!$authorizer->checkAccess($currentUser, 'uri_dnsadmin')) {
throw new ForbiddenException();
}

$ms = $this->ci->alerts;

$zone_id = $request->getQueryParam('id');
Expand All @@ -316,11 +407,14 @@ public function modalExportZoneEntry(Request $request, Response $response, $args
$ms->addMessage('danger', 'Invalid Zone ID.');
return $response->withStatus(400);
}
try {
$dnsConfigGenerator = $this->ci->dnsConfigGenerator;

$dnsConfigGenerator = $this->ci->dnsConfigGenerator;

$config = $dnsConfigGenerator->getZoneConfig($zone);

$config = $dnsConfigGenerator->getZoneConfig($zone);
} catch (RdataException $e) {
$ms->addMessage('danger', 'Error Generating Zone: '. $e->getMessage());
return $response->withStatus(400);
}
$zone = $zone->toArray();

$zone['config'] = $config;
Expand Down
Loading

0 comments on commit 471f257

Please sign in to comment.