From d8b208277805727e8d5eba19b6be2d46b1bd3772 Mon Sep 17 00:00:00 2001 From: tracer Date: Thu, 27 Jan 2022 15:15:19 +0100 Subject: [PATCH] improved handling/creation of zone files Signed-off-by: tracer --- src/Controller/DomainController.php | 33 ++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Controller/DomainController.php b/src/Controller/DomainController.php index 202355d..abe3156 100644 --- a/src/Controller/DomainController.php +++ b/src/Controller/DomainController.php @@ -102,7 +102,7 @@ class DomainController */ public function insert(String $name, int $panelID, String $a, String $aaaa): bool|string { - // TODO create zone file and include + print("here"); $sql = " INSERT INTO " . DatabaseConnection::TABLE_DOMAINS . " (name, panel_id, a, aaaa) VALUES (:name, :panel_id, :a, :aaaa)"; @@ -110,13 +110,13 @@ class DomainController try { $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: ':name', var: $name); - $statement->bindParam(param: ':panel_d', var: $panelID); + $statement->bindParam(param: ':panel_id', var: $panelID); $statement->bindParam(param: ':a', var: $a); $statement->bindParam(param: ':aaaa', var: $aaaa); $statement->execute(); + print(PHP_EOL . "there"); - - if ($panel = $this->panelController->findByID(id: $panelID)) { + if ($panel = $this->panelController->findByID(id: intval(value: $panelID))) { $a = $panel['a']; $aaaa = $panel['aaaa']; } @@ -209,6 +209,19 @@ class DomainController } + function createIncludeFile() + { + $domains = $this->findAll(); + + print("$this->localZoneFile"); + $oFile = fopen(filename: $this->localZoneFile, mode: 'w'); + foreach ($domains as $domain) { + fputs(stream: $oFile, data: 'include "' . $this->localZonesDir . $domain['name'] . '";' . PHP_EOL); + } + fclose(stream: $oFile); + } + + /** * @param $id * @@ -216,7 +229,15 @@ class DomainController */ public function delete($id): int { - // TODO delete zone file and include + if ($domain = $this->findByID(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); + } + } + $sql = " DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . " WHERE id = :id"; @@ -225,6 +246,8 @@ class DomainController $statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement->bindParam(param: 'id', var: $id); $statement->execute(); + + $this->createIncludeFile(); return $statement->rowCount(); } catch (PDOException $e) { exit($e->getMessage());