This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
af0cc4d
commit 5e71ef1
Showing
103 changed files
with
3,756 additions
and
775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.