added missing named parameters, added strict_types
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
30180e6d71
commit
518c4ae90d
@ -1,7 +1,9 @@
|
||||
<?php
|
||||
|
||||
<?php declare(strict_types=1);
|
||||
namespace App\Controller;
|
||||
|
||||
error_reporting(error_level: E_ALL);
|
||||
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
@ -29,13 +31,14 @@ class DomainController
|
||||
*/
|
||||
public function findAll(): bool|array
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
SELECT id, name, panel_id, a, aaaa
|
||||
FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
ORDER BY name";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->query($statement);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
return $statement->fetchAll(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
@ -56,10 +59,10 @@ class DomainController
|
||||
WHERE name = :name";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->execute();
|
||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
@ -79,10 +82,10 @@ class DomainController
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param:':id', var: $id);
|
||||
$statement->execute();
|
||||
return $statement->fetch(PDO::FETCH_ASSOC);
|
||||
return $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
@ -95,9 +98,9 @@ class DomainController
|
||||
* @param String $a
|
||||
* @param String $aaaa
|
||||
*
|
||||
* @return int
|
||||
* @return string|false
|
||||
*/
|
||||
public function insert(String $name, int $panelID, String $a, String $aaaa): int
|
||||
public function insert(String $name, int $panelID, String $a, String $aaaa): bool|string
|
||||
{
|
||||
// TODO create zone file and include
|
||||
$sql = "
|
||||
@ -105,7 +108,7 @@ class DomainController
|
||||
VALUES (:name, :panel_id, :a, :aaaa)";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->bindParam(param: ':panel_d', var: $panelID);
|
||||
$statement->bindParam(param: ':a', var: $a);
|
||||
@ -113,7 +116,7 @@ class DomainController
|
||||
$statement->execute();
|
||||
|
||||
|
||||
if ($panel = $this->panelController->findByID($panelID)) {
|
||||
if ($panel = $this->panelController->findByID(id: $panelID)) {
|
||||
$a = $panel['a'];
|
||||
$aaaa = $panel['aaaa'];
|
||||
}
|
||||
@ -121,9 +124,9 @@ class DomainController
|
||||
$zoneFilename = $this->localZonesDir . $name;
|
||||
echo $zoneFilename . PHP_EOL;
|
||||
|
||||
if ($localZones = fopen($this->localZoneFile, mode: 'a')) {
|
||||
fputs($localZones, data: "include \"$zoneFilename\";" . PHP_EOL);
|
||||
fclose($localZones);
|
||||
if ($localZones = fopen(filename: $this->localZoneFile, mode: 'a')) {
|
||||
fputs(stream: $localZones, data: "include \"$zoneFilename\";" . PHP_EOL);
|
||||
fclose(stream: $localZones);
|
||||
} else {
|
||||
echo "Error writing to $this->localZoneFile, check permissions";
|
||||
exit(1);
|
||||
@ -147,7 +150,7 @@ class DomainController
|
||||
*/
|
||||
public function update(Int $id, String $name, int $panelID, String $a, String $aaaa): bool|int
|
||||
{
|
||||
$current = $this->findByID($id);
|
||||
$current = $this->findByID(id: $id);
|
||||
|
||||
/* doesn't work
|
||||
$statement = "
|
||||
@ -182,7 +185,7 @@ class DomainController
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($sql);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->bindParam(param: 'name', var: $name);
|
||||
$statement->bindParam(param: 'panel_id', var: $panelID);
|
||||
@ -191,7 +194,7 @@ class DomainController
|
||||
$statement->execute();
|
||||
|
||||
// recreate zonefile
|
||||
if ($panel = $this->panelController->findByID($panelID)) {
|
||||
if ($panel = $this->panelController->findByID(id: intval(value: $panelID))) {
|
||||
$a = $panel['a'];
|
||||
$aaaa = $panel['aaaa'];
|
||||
}
|
||||
@ -214,12 +217,12 @@ class DomainController
|
||||
public function delete($id): int
|
||||
{
|
||||
// TODO delete zone file and include
|
||||
$statement = "
|
||||
$sql = "
|
||||
DELETE FROM " . DatabaseConnection::TABLE_DOMAINS . "
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($statement);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: 'id', var: $id);
|
||||
$statement->execute();
|
||||
return $statement->rowCount();
|
||||
@ -235,11 +238,11 @@ class DomainController
|
||||
*/
|
||||
public function getLongestEntry(String $field): int
|
||||
{
|
||||
$statement = "
|
||||
$sql = "
|
||||
SELECT MAX(LENGTH(" . $field . ")) as length FROM " . DatabaseConnection::TABLE_DOMAINS;
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare($statement);
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
$result = $statement->fetch();
|
||||
return $result['length'];
|
||||
@ -257,7 +260,7 @@ class DomainController
|
||||
$uid = posix_geteuid();
|
||||
print("UID:\t$uid" . PHP_EOL);
|
||||
|
||||
$pwuid = posix_getpwuid($uid);
|
||||
$pwuid = posix_getpwuid(user_id: $uid);
|
||||
$name = $pwuid['name'];
|
||||
print("Name:\t$name" . PHP_EOL);
|
||||
$bindGroup = posix_getgrnam(name: 'bind');
|
||||
@ -275,8 +278,8 @@ class DomainController
|
||||
}
|
||||
|
||||
echo "Checking $this->namedConfLocalFile" . PHP_EOL;
|
||||
if ($namedConfLocal = file_get_contents($this->namedConfLocalFile)) {
|
||||
if (!str_contains($namedConfLocal, $this->localZoneFile)) {
|
||||
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
|
||||
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
|
||||
echo "\t❌ $this->localZoneFile needs to be included in $this->namedConfLocalFile." . PHP_EOL;
|
||||
} else {
|
||||
echo "\t✅ $this->localZoneFile is included in $this->namedConfLocalFile" . PHP_EOL;
|
||||
@ -300,10 +303,12 @@ class DomainController
|
||||
*/
|
||||
function checkDomains(): array|bool
|
||||
{
|
||||
return true;
|
||||
/*
|
||||
$domains = $this->findAll();
|
||||
|
||||
if ($namedConfLocal = file_get_contents($this->namedConfLocalFile)) {
|
||||
if (!str_contains($namedConfLocal, $this->localZoneFile)) {
|
||||
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
|
||||
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
|
||||
return "$this->localZoneFile needs to be included in $this->namedConfLocalFile.";
|
||||
}
|
||||
} else {
|
||||
@ -333,6 +338,7 @@ class DomainController
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -346,18 +352,18 @@ class DomainController
|
||||
public function createZoneFile(String $name, String $a, String $aaaa): void
|
||||
{
|
||||
if ($zonefile = fopen(filename: $this->localZonesDir . $name, mode: 'w')) {
|
||||
fputs($zonefile, data: "zone \"$name\" IN {" . PHP_EOL);
|
||||
fputs($zonefile, data: "\ttype slave;" . PHP_EOL);
|
||||
fputs($zonefile, data: "\tfile \"" . $this->zoneCachePath . $name . '.db";' . PHP_EOL);
|
||||
fputs($zonefile, data: "\tmasters {" . PHP_EOL);
|
||||
fputs(stream: $zonefile, data: "zone \"$name\" IN {" . 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: "\tmasters {" . PHP_EOL);
|
||||
if (!empty($a)) {
|
||||
fputs($zonefile, data: "\t\t$a;" . PHP_EOL);
|
||||
fputs(stream: $zonefile, data: "\t\t$a;" . PHP_EOL);
|
||||
}
|
||||
if (!empty($aaaa)) {
|
||||
fputs($zonefile, data: "\t\t$aaaa;" . PHP_EOL);
|
||||
fputs(stream: $zonefile, data: "\t\t$aaaa;" . PHP_EOL);
|
||||
}
|
||||
fputs($zonefile, data: "\t};" . PHP_EOL);
|
||||
fputs($zonefile, data: "};" . PHP_EOL);
|
||||
fputs(stream: $zonefile, data: "\t};" . PHP_EOL);
|
||||
fputs(stream: $zonefile, data: "};" . PHP_EOL);
|
||||
}
|
||||
|
||||
// TODO check if ist exist in the include, else create
|
||||
|
Loading…
Reference in New Issue
Block a user