-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from liberu-genealogy/main
DNS
- Loading branch information
Showing
5 changed files
with
106 additions
and
3 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,43 @@ | ||
<?php | ||
|
||
namespace App\Listeners; | ||
|
||
use App\Events\DnsSettingSaved; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class UpdateBindDnsRecords implements ShouldQueue | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param \App\Events\DnsSettingSaved $event | ||
* @return void | ||
*/ | ||
public function handle(DnsSettingSaved $event) | ||
{ | ||
$dnsSetting = $event->dnsSetting; | ||
|
||
try { | ||
$domain = $dnsSetting->domain->name; | ||
$recordType = $dnsSetting->record_type; | ||
$recordName = $dnsSetting->name; | ||
$recordValue = $dnsSetting->value; | ||
$ttl = $dnsSetting->ttl; | ||
|
||
$zoneFile = "./bind/records/{$domain}.db"; | ||
|
||
if ($recordType === 'A') { | ||
$recordLine = "{$recordName} {$ttl} IN A {$recordValue}"; | ||
} elseif ($recordType === 'MX') { | ||
$recordLine = "{$domain}. {$ttl} IN MX 10 {$recordValue}."; | ||
} | ||
|
||
file_put_contents($zoneFile, $recordLine . "\n", FILE_APPEND); | ||
|
||
exec('docker-compose restart bind9'); | ||
} catch (\Exception $e) { | ||
Log::error('Failed to update Bind9 DNS records: ' . $e->getMessage()); | ||
} | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use App\Models\DnsSetting; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
|
||
class DnsSettingSaved | ||
{ | ||
use Dispatchable; | ||
|
||
/** | ||
* The DnsSetting instance. | ||
* | ||
* @var \App\Models\DnsSetting | ||
*/ | ||
public $dnsSetting; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @param \App\Models\DnsSetting $dnsSetting | ||
* @return void | ||
*/ | ||
public function __construct(DnsSetting $dnsSetting) | ||
{ | ||
$this->dnsSetting = $dnsSetting; | ||
} | ||
} |
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