parent
4fb5cdcffd
commit
ca1d4577dc
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Domain;
|
||||||
use App\Repository\DomainRepository;
|
use App\Repository\DomainRepository;
|
||||||
use App\Repository\NameserverRepository;
|
use App\Repository\NameserverRepository;
|
||||||
|
use Monolog\Logger;
|
||||||
|
|
||||||
error_reporting(error_level: E_ALL);
|
error_reporting(error_level: E_ALL);
|
||||||
|
|
||||||
|
@ -19,8 +21,13 @@ class DomainController
|
||||||
private string $namedConfLocalFile;
|
private string $namedConfLocalFile;
|
||||||
private string $zoneCachePath;
|
private string $zoneCachePath;
|
||||||
|
|
||||||
public function __construct(private NameserverRepository $nameserverRepository, private CheckController $checkController, private DomainRepository $domainRepository)
|
public function __construct(private NameserverRepository $nameserverRepository, private ApiController $checkController, private DomainRepository $domainRepository, private array $config, private Logger $log)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ($this->config['debug']) {
|
||||||
|
$this->log->debug(message: "__construct()");
|
||||||
|
}
|
||||||
|
|
||||||
$this->localZoneFile = '/etc/bind/local.zones';
|
$this->localZoneFile = '/etc/bind/local.zones';
|
||||||
$this->localZonesDir = '/etc/bind/zones/';
|
$this->localZonesDir = '/etc/bind/zones/';
|
||||||
$this->namedConfLocalFile = '/etc/bind/named.conf.local';
|
$this->namedConfLocalFile = '/etc/bind/named.conf.local';
|
||||||
|
@ -53,6 +60,10 @@ class DomainController
|
||||||
|
|
||||||
function createIncludeFile()
|
function createIncludeFile()
|
||||||
{
|
{
|
||||||
|
if ($this->config['debug']) {
|
||||||
|
$this->log->debug(message: "createIncludeFile()");
|
||||||
|
}
|
||||||
|
|
||||||
$domains = $this->domainRepository->findAll();
|
$domains = $this->domainRepository->findAll();
|
||||||
|
|
||||||
$oFile = fopen(filename: $this->localZoneFile, mode: 'w');
|
$oFile = fopen(filename: $this->localZoneFile, mode: 'w');
|
||||||
|
@ -63,69 +74,55 @@ class DomainController
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function delete(int $id)
|
function deleteOnNameservers(Domain $domain)
|
||||||
{
|
{
|
||||||
|
if ($this->config['debug']) {
|
||||||
if ($domain = $this->domainRepository->findByID(id: $id)) {
|
$this->log->debug(message: "deleteOnNameserver()");
|
||||||
$this->domainRepository->delete(id: $id);
|
|
||||||
$zoneFile = $this->localZonesDir . $domain['name'];
|
|
||||||
print($zoneFile . PHP_EOL);
|
|
||||||
if (file_exists(filename: $this->localZonesDir . $domain['name'])) {
|
|
||||||
print("file exists");
|
|
||||||
unlink(filename: $zoneFile);
|
|
||||||
$this->createIncludeFile();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->deleteOnNameservers(id: $id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function deleteOnNameservers(int $id)
|
|
||||||
{
|
|
||||||
$nameservers = $this->nameserverRepository->findAll();
|
$nameservers = $this->nameserverRepository->findAll();
|
||||||
foreach ($nameservers as $nameserver) {
|
foreach ($nameservers as $nameserver) {
|
||||||
echo($nameserver['name']);
|
|
||||||
$body = [
|
$body = [
|
||||||
'id' => $id
|
'name' => $domain->getName()
|
||||||
];
|
];
|
||||||
if (!empty($nameserver['aaaa'])) {
|
if (!empty($nameserver->getAaaa())) {
|
||||||
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver['name'], versionIP: 6, apiKey: $nameserver['apikey'], command: 'delete', serverType: 'nameserver', body: $body);
|
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 6, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body);
|
||||||
} else {
|
} else {
|
||||||
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver['name'], versionIP: 4, apiKey: $nameserver['apikey'], command: 'delete', serverType: 'nameserver', body: $body);
|
$this->checkController->sendCommand(requestType: 'DELETE', serverName: $nameserver->getName(), versionIP: 4, apiKey: $nameserver->getApikey(), command: 'delete', serverType: 'nameserver', body: $body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $id
|
* @param \App\Entity\Domain $domain
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function deleteZone(int $id)
|
function deleteZone(Domain $domain)
|
||||||
{
|
{
|
||||||
|
if ($this->config['debug']) {
|
||||||
if ($domain = $this->domainRepository->findByID(id: $id)) {
|
$this->log->debug(message: "deleteZone()");
|
||||||
$zoneFile = $this->localZonesDir . $domain['name'];
|
|
||||||
print($zoneFile . PHP_EOL);
|
|
||||||
if (file_exists(filename: $this->localZonesDir . $domain['name'])) {
|
|
||||||
print("file exists");
|
|
||||||
unlink(filename: $zoneFile);
|
|
||||||
$this->createIncludeFile();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->deleteOnNameservers(id: $id);
|
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||||
$this->domainRepository->delete(id: $id);
|
if (file_exists(filename: "$zoneFile")) {
|
||||||
|
unlink(filename: $zoneFile);
|
||||||
|
}
|
||||||
|
$this->createIncludeFile();
|
||||||
|
$this->deleteOnNameservers(domain: $domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function checkPermissions(): void
|
function checkPermissions(): void
|
||||||
{
|
{
|
||||||
|
if ($this->config['debug']) {
|
||||||
|
$this->log->debug(message: "checkPermissions()");
|
||||||
|
}
|
||||||
|
|
||||||
echo 'Checking permission:' . PHP_EOL . PHP_EOL;
|
echo 'Checking permission:' . PHP_EOL . PHP_EOL;
|
||||||
$uid = posix_geteuid();
|
$uid = posix_geteuid();
|
||||||
print("UID:\t$uid" . PHP_EOL);
|
print("UID:\t$uid" . PHP_EOL);
|
||||||
|
@ -173,6 +170,7 @@ class DomainController
|
||||||
*/
|
*/
|
||||||
function checkDomains(): array|bool
|
function checkDomains(): array|bool
|
||||||
{
|
{
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
/*
|
/*
|
||||||
$domains = $this->findAll();
|
$domains = $this->findAll();
|
||||||
|
@ -213,28 +211,33 @@ class DomainController
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $name
|
* @param \App\Entity\Domain $domain
|
||||||
* @param mixed $a
|
|
||||||
* @param mixed $aaaa
|
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function createZoneFile(string $name, string $a, string $aaaa): void
|
public function createZoneFile(Domain $domain): void
|
||||||
{
|
{
|
||||||
if ($zonefile = fopen(filename: $this->localZonesDir . $name, mode: 'w')) {
|
if ($this->config['debug']) {
|
||||||
fputs(stream: $zonefile, data: "zone \"$name\" IN {" . PHP_EOL);
|
$domainName = $domain->getName();
|
||||||
|
$this->log->debug(message: "createZoneFile($domainName)");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($zonefile = fopen(filename: $this->localZonesDir . $domain->getName(), mode: 'w')) {
|
||||||
|
fputs(stream: $zonefile, data: 'zone \"' . $domain->getA() . '"' . ' IN {' . PHP_EOL);
|
||||||
fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\ttype slave;" . PHP_EOL);
|
||||||
fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $name . '.db";' . PHP_EOL);
|
fputs(stream: $zonefile, data: "\tfile \"" . $this->zoneCachePath . $domain->getName() . '.db";' . PHP_EOL);
|
||||||
fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\tmasters {" . PHP_EOL);
|
||||||
if (!empty($a)) {
|
if (!empty($a)) {
|
||||||
fputs(stream: $zonefile, data: "\t\t$a;" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t\t" . $domain->getA() . ';' . PHP_EOL);
|
||||||
}
|
}
|
||||||
if (!empty($aaaa)) {
|
if (!empty($aaaa)) {
|
||||||
fputs(stream: $zonefile, data: "\t\t$aaaa;" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t\t" . $domain->getAaaa() . ';' . PHP_EOL);
|
||||||
}
|
}
|
||||||
fputs(stream: $zonefile, data: "\t};" . PHP_EOL);
|
fputs(stream: $zonefile, data: "\t};" . PHP_EOL);
|
||||||
fputs(stream: $zonefile, data: "};" . PHP_EOL);
|
fputs(stream: $zonefile, data: "};" . PHP_EOL);
|
||||||
}
|
}
|
||||||
$this->createIncludeFile();
|
$this->createIncludeFile();
|
||||||
|
|
||||||
|
// TODO add on nameservers
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue