Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Release 0.4.0 (#28)
Browse files Browse the repository at this point in the history
* feat: Add Server Side processing to large DataTables
* doc: Models documentation
* feat: Add 'Import zone' feature to ProBIND

Import zone will get a HTTP uploaded file and call 'probind:import'
Artisan command to parse the file. Data will be imported to a Zone.
* feat: Add a new Zone field to determine reverse zones
* fix: Fix bug on larapacks/setting package

There was a bug on larapacks/setting package reported by me, See issue
20. I've updated larapacks/setting to version 1.0.5 which solves it.

Closes #20

* feat: Create Users and Authentication Controller to ProBIND

Create User model and add authentication controllers / views to ProBIND

* feat: Add User management controller.

After adding User authentication it was necessary to add User's
management.
* Bump version 0.3.0 -> 0.4.0
  • Loading branch information
pacoorozco authored Oct 5, 2016
1 parent af0cc4d commit 5e71ef1
Show file tree
Hide file tree
Showing 103 changed files with 3,756 additions and 775 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

## 0.4.0 - 2016-10-05
### Added
- Add 'Import zone' feature which allows to import BIND (RFC 1033) zone files to ProBIND.
- Add support for **Reverse zones**. [What is a Reverse zone?](https://en.wikipedia.org/wiki/Reverse_DNS_lookup)
- Add user management and authentication. Now **only** authenticates with local database.

## 0.3.0 - 2016-09-02
- **Important**: This application has upgraded to [Laravel 5.3](https://laravel.com/docs/5.3) with a new requirement for PHP 7.0+. **No support will be available for PHP prior 7.0 version.**

Expand Down
107 changes: 107 additions & 0 deletions app/Console/Commands/ProBINDImportZone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace App\Console\Commands;

use App\FileDNSParser;
use App\Zone;
use Illuminate\Console\Command;

class ProBINDImportZone extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'probind:import
{zone : The zone domain name to create}
{zonefile : The file name to import}
{--force : Delete existing zone before import}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Import a BIND zone file to ProBIND';

/**
* Create a new command instance.
*/
public function __construct()
{
parent::__construct();
}

/**
* Delete the specified zone by domain search if exists.
*
* @param string $domain
*/
private function deleteZoneIfExists(string $domain)
{
// Check if Zone exists on database, including trashed zones.
$existingZone = Zone::withTrashed()
->where('domain', $domain)->first();

if ($existingZone) {
$existingZone->forceDelete();
}
}

/**
* Execute the console command.
*
* @return int
*/
public function handle() : int
{
// Cast supplied arguments and options.
$domain = (string)$this->argument('zone');
$zonefile = (string)$this->argument('zonefile');

$fileDNS = new FileDNSParser($domain);
$fileDNS->load($zonefile);

if (!$this->option('force')) {
// Check if Zone exists on database.
$existingZone = Zone::where('domain', $domain)->first();

if ($existingZone) {
$this->error('Zone \'' . $existingZone->domain . '\' exists on ProBIND. Use \'--force\' option if you want to import this zone.');
return 1;
}
}

// Delete zone, if exists on database.
$this->deleteZoneIfExists($domain);

// Create the zone and fill with parsed data.
$zoneData = $fileDNS->getZoneData();
$zone = new Zone();
$zone->domain = $domain;
$zone->reverse_zone = Zone::validateReverseDomainName($domain);
$zone->serial = $zoneData['serial'];
$zone->custom_settings = true;
$zone->fill(array_only($zoneData, ['refresh', 'retry', 'expire', 'negative_ttl', 'default_ttl']));
$zone->save();

// Associate parsed RR
$records = $fileDNS->getRecords();
foreach ($records as $item) {
$zone->records()->create([
'name' => $item['name'],
'ttl' => $item['ttl'],
'type' => $item['type'],
'priority' => array_get($item, 'options.preference', null),
'data' => $item['data']
]);
}

$this->info('Import zone \'' . $zone->domain . '\' has created with ' . $zone->records()->count() . ' imported records.');
activity()->log('Import zone <strong>' . $zone->domain . '</strong> has created <strong>' . $zone->records()->count() . '</strong> records.');
return 0;
}
}


28 changes: 14 additions & 14 deletions app/Console/Commands/ProBINDPushZones.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
use Illuminate\Support\Facades\View;
use phpseclib\Crypt\RSA;
use phpseclib\Net\SFTP;
use Registry;
use Setting;

/**
* Class ProBINDPushZones
Expand Down Expand Up @@ -91,7 +91,7 @@ public function handle()
// Now push files to servers using SFTP
$error = $this->handleAllServers();

if ( ! $error) {
if (!$error) {
// Clear pending changes on zones and clear deleted ones
foreach ($zonesToUpdate as $zone) {
$zone->setPendingChanges(false);
Expand Down Expand Up @@ -132,15 +132,15 @@ public function generateZoneFileForZone(Zone $zone)
$path = $this->localStoragePath . '/primary/' . $zone->domain;

// Get default settings, we will use to render view
$defaults = Registry::all();
$defaults = Setting::all();

// Get all Name Servers that had to be on NS records
$nameServers = Server::where('ns_record', true)
->orderBy('type')
->get();

// Create new Serial for this zone
$zone->setSerialNumber();
$zone->getNewSerialNumber();

// Get all records
$records = $zone->records()
Expand Down Expand Up @@ -172,7 +172,7 @@ public function handleAllServers()
// Get servers with push updates capability
$servers = Server::withPushCapability()->get();

$pushedWithoutErrors = ! $servers->isEmpty();
$pushedWithoutErrors = !$servers->isEmpty();
foreach ($servers as $server) {
$pushedWithoutErrors &= $this->handleServer($server);
}
Expand All @@ -194,11 +194,11 @@ public function handleServer(Server $server)
$filesToPush = [
[
'local' => $this->localStoragePath . '/configuration/' . $server->hostname . '.conf',
'remote' => Registry::get('ssh_default_remote_path') . '/configuration/named.conf',
'remote' => Setting::get('ssh_default_remote_path') . '/configuration/named.conf',
],
[
'local' => $this->localStoragePath . '/configuration/deadlist',
'remote' => Registry::get('ssh_default_remote_path') . '/configuration/deadlist',
'remote' => Setting::get('ssh_default_remote_path') . '/configuration/deadlist',
]
];

Expand All @@ -208,7 +208,7 @@ public function handleServer(Server $server)
$filename = basename($file);
$filesToPush[] = [
'local' => $file,
'remote' => Registry::get('ssh_default_remote_path') . '/primary/' . $filename
'remote' => Setting::get('ssh_default_remote_path') . '/primary/' . $filename
];
}
}
Expand Down Expand Up @@ -272,17 +272,17 @@ public function pushFilesToServer(Server $server, $filesToPush)
{
// Get RSA private key in order to connect to servers
$privateSSHKey = new RSA();
$privateSSHKey->loadKey(Registry::get('ssh_default_key'));
$privateSSHKey->loadKey(Setting::get('ssh_default_key'));

try {
$sftp = new SFTP($server->hostname, Registry::get('ssh_default_port'));
$sftp = new SFTP($server->hostname, Setting::get('ssh_default_port'));
} catch (\Exception $e) {
$this->error('Can\'t connect to ' . $server->hostname . ': ' . $e->getMessage());

return false;
}

if ( ! $sftp->login(Registry::get('ssh_default_user'), $privateSSHKey)) {
if (!$sftp->login(Setting::get('ssh_default_user'), $privateSSHKey)) {
$this->error('Invalid SSH credentials for ' . $server->hostname);

return false;
Expand All @@ -291,15 +291,15 @@ public function pushFilesToServer(Server $server, $filesToPush)
$this->info('Connected successfully to ' . $server->hostname);

// Create Remote Folders, last argument is to be recursive
$sftp->mkdir(Registry::get('ssh_default_remote_path') . '/configuration', -1, true);
$sftp->mkdir(Registry::get('ssh_default_remote_path') . '/primary', -1, true);
$sftp->mkdir(Setting::get('ssh_default_remote_path') . '/configuration', -1, true);
$sftp->mkdir(Setting::get('ssh_default_remote_path') . '/primary', -1, true);

$totalFiles = count($filesToPush);
$pushedFiles = 0;
foreach ($filesToPush as $file) {
$contents = Storage::get($file['local']);

if ( ! $sftp->put($file['remote'], $contents)) {
if (!$sftp->put($file['remote'], $contents)) {
$this->error('File ' . $file['local'] . ' can\'t be uploaded to ' . $server->hostname);
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace App\Console;

use App\Console\Commands\ProBINDImportZone;
use App\Console\Commands\ProBINDPushZones;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
Expand All @@ -31,6 +32,7 @@ class Kernel extends ConsoleKernel
*/
protected $commands = [
ProBINDPushZones::class,
ProBINDImportZone::class
];

/**
Expand Down
34 changes: 28 additions & 6 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

use Exception;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;

Expand All @@ -33,9 +35,11 @@ class Handler extends ExceptionHandler
* @var array
*/
protected $dontReport = [
AuthenticationException::class,
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
TokenMismatchException::class,
ValidationException::class,
];

Expand All @@ -44,23 +48,41 @@ class Handler extends ExceptionHandler
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @param \Exception $exception
*
* @return void
*/
public function report(Exception $e)
public function report(Exception $exception)
{
parent::report($e);
parent::report($exception);
}

/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @param \Exception $exception
*
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}

/**
* Convert an authentication exception into an unauthenticated response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
*
* @return \Illuminate\Http\RedirectResponse
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
return parent::render($request, $e);
if ($request->expectsJson()) {
return response()->json(['error' => $exception->getMessage()], 401);
}
return redirect()->guest('login');
}
}
Loading

0 comments on commit 5e71ef1

Please sign in to comment.