Merge remote-tracking branch 'origin/master'

# Conflicts:
#	bin/console
#	src/Controller/CLIController.php
#	src/Repository/PanelRepository.php
This commit is contained in:
tracer 2022-09-17 15:41:31 +02:00
commit 051e7cbd0b
11 changed files with 254 additions and 1417 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="PublishConfigData" autoUpload="On explicit save action" serverName="shadow.24unix.net" autoUploadExternalChanges="true"> <component name="PublishConfigData" autoUpload="On explicit save action" promptOnRemoteOverwrite="CHECK_TIMESTAMP" serverName="KeyHelpLocalDev" preserveFilePermissions="true" autoUploadExternalChanges="true" notifyRemoteChanges="true">
<serverData> <serverData>
<paths name="shadow.24unix.net"> <paths name="KeyHelpLocalDev">
<serverdata> <serverdata>
<mappings> <mappings>
<mapping deploy="/bindAPI" local="$PROJECT_DIR$" web="/" /> <mapping deploy="/" local="$PROJECT_DIR$" web="/" />
</mappings> </mappings>
</serverdata> </serverdata>
</paths> </paths>

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="PhpCodeSniffer">
<phpcs_settings>
<PhpCSConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpcs" />
</phpcs_settings>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.1"> <component name="PhpProjectSharedConfiguration" php_language_level="8.1">
<option name="suggestChangeDefaultLanguageLevel" value="false" /> <option name="suggestChangeDefaultLanguageLevel" value="false" />
</component> </component>

View File

@ -11,16 +11,17 @@
"minimum-stability": "stable", "minimum-stability": "stable",
"prefer-stable": true, "prefer-stable": true,
"require": { "require": {
"php": ">=8.1", "php": ">=8.1",
"ext-curl": "*", "ext-curl": "*",
"ext-json": "*", "ext-json": "*",
"ext-pdo": "*", "ext-pdo": "*",
"arubacao/tld-checker": "^1.2", "arubacao/tld-checker": "^1.2",
"monolog/monolog": "^2.3", "monolog/monolog": "^2.3",
"php-di/php-di": "^6.3", "php-di/php-di": "^6.3",
"phplucidframe/console-table": "^1.2", "phplucidframe/console-table": "^1.2",
"zircote/swagger-php": "^4.2" "squizlabs/php_codesniffer": "^3.7",
}, "zircote/swagger-php": "^4.2"
},
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,
"preferred-install": { "preferred-install": {
@ -39,6 +40,7 @@
} }
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.5" "escapestudios/symfony2-coding-standard": "3.x-dev",
} "phpunit/phpunit": "^9.5"
}
} }

120
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f7096254eb316738d722dfff777682ef", "content-hash": "ebdf6dd62a66775d7344acac9e59a5ce",
"packages": [ "packages": [
{ {
"name": "arubacao/tld-checker", "name": "arubacao/tld-checker",
@ -745,6 +745,62 @@
}, },
"time": "2021-07-14T16:46:02+00:00" "time": "2021-07-14T16:46:02+00:00"
}, },
{
"name": "squizlabs/php_codesniffer",
"version": "3.7.1",
"source": {
"type": "git",
"url": "https://github.com/squizlabs/PHP_CodeSniffer.git",
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619",
"reference": "1359e176e9307e906dc3d890bcc9603ff6d90619",
"shasum": ""
},
"require": {
"ext-simplexml": "*",
"ext-tokenizer": "*",
"ext-xmlwriter": "*",
"php": ">=5.4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"bin": [
"bin/phpcs",
"bin/phpcbf"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Greg Sherwood",
"role": "lead"
}
],
"description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.",
"homepage": "https://github.com/squizlabs/PHP_CodeSniffer",
"keywords": [
"phpcs",
"standards"
],
"support": {
"issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues",
"source": "https://github.com/squizlabs/PHP_CodeSniffer",
"wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki"
},
"time": "2022-06-18T07:21:10+00:00"
},
{ {
"name": "symfony/finder", "name": "symfony/finder",
"version": "v6.0.3", "version": "v6.0.3",
@ -1109,6 +1165,64 @@
], ],
"time": "2022-03-03T08:28:38+00:00" "time": "2022-03-03T08:28:38+00:00"
}, },
{
"name": "escapestudios/symfony2-coding-standard",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/djoos/Symfony-coding-standard.git",
"reference": "5cc7ad11da242182d9776b98b950d5565c32acd0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/djoos/Symfony-coding-standard/zipball/5cc7ad11da242182d9776b98b950d5565c32acd0",
"reference": "5cc7ad11da242182d9776b98b950d5565c32acd0",
"shasum": ""
},
"require": {
"squizlabs/php_codesniffer": "^3.3.1"
},
"conflict": {
"squizlabs/php_codesniffer": "<3 || >=4"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^6.0 || ^7.0"
},
"default-branch": true,
"type": "phpcodesniffer-standard",
"extra": {
"branch-alias": {
"dev-master": "3.x-dev"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "David Joos",
"email": "iam@davidjoos.com"
},
{
"name": "Community contributors",
"homepage": "https://github.com/djoos/Symfony-coding-standard/graphs/contributors"
}
],
"description": "CodeSniffer ruleset for the Symfony 2+ coding standard",
"homepage": "https://github.com/djoos/Symfony-coding-standard",
"keywords": [
"Coding Standard",
"Symfony2",
"phpcs",
"symfony"
],
"support": {
"issues": "https://github.com/djoos/Symfony-coding-standard/issues",
"source": "https://github.com/djoos/Symfony-coding-standard"
},
"time": "2021-03-24T15:17:16+00:00"
},
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.11.0", "version": "1.11.0",
@ -3058,7 +3172,9 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"escapestudios/symfony2-coding-standard": 20
},
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {

File diff suppressed because it is too large Load Diff

View File

@ -24,7 +24,7 @@ class DatabaseConnection
public function __construct(private array $config) public function __construct(private array $config)
{ {
extract(array: $this->config); extract(array: $this->config);
// TODO create config => encryption key
try { try {
$this->dbConnection = new PDO( $this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase", dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",

View File

@ -17,16 +17,23 @@ error_reporting(error_level: E_ALL);
*/ */
class DomainController class DomainController
{ {
private string $localZoneFile; public string $localZoneFile;
private string $localZonesDir; public string $localZonesDir;
private string $namedConfLocalFile; public string $namedConfLocalFile;
private string $zoneCachePath; private string $zoneCachePath;
public function __construct(private NameserverRepository $nameserverRepository, private ApiController $checkController, private DomainRepository $domainRepository, private PanelRepository $panelRepository, private array $config, private Logger $log) public function __construct(
private readonly NameserverRepository $nameserverRepository,
private readonly ApiController $checkController,
private readonly DomainRepository $domainRepository,
private readonly PanelRepository $panelRepository,
private readonly bool $verbose,
private readonly bool $debug,
private readonly Logger $log)
{ {
if ($this->config['debug']) { if ($this->$debug) {
$this->log->debug(message: "__construct()"); $this->log->debug(message: "__construct()");
} }
@ -37,9 +44,9 @@ class DomainController
} }
function createIncludeFile() function createIncludeFile(): void
{ {
if ($this->config['debug']) { if ($this->debug) {
$this->log->debug(message: "createIncludeFile()"); $this->log->debug(message: "createIncludeFile()");
} }
@ -67,9 +74,9 @@ class DomainController
} }
function updateSlaveZones() function updateSlaveZones(): void
{ {
if ($this->config['verbose']) { if ($this->verbose) {
echo 'Delete all slave zones'; echo 'Delete all slave zones';
} }
@ -81,7 +88,7 @@ class DomainController
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
foreach ($domains as $domain) { foreach ($domains as $domain) {
if ($this->config['verbose']) { if ($this->verbose) {
echo 'Create zone: ' . $domain->getName() . PHP_EOL; echo 'Create zone: ' . $domain->getName() . PHP_EOL;
} }
$this->createSlaveZoneFile(domain: $domain); $this->createSlaveZoneFile(domain: $domain);
@ -91,9 +98,9 @@ class DomainController
} }
function deleteOnNameservers(Domain $domain) function deleteOnNameservers(Domain $domain): void
{ {
if ($this->config['debug']) { if ($this->debug) {
$this->log->debug(message: "deleteOnNameserver()"); $this->log->debug(message: "deleteOnNameserver()");
} }
@ -116,9 +123,9 @@ class DomainController
* *
* @return void * @return void
*/ */
function deleteZone(Domain $domain) function deleteZone(Domain $domain): void
{ {
if ($this->config['debug']) { if ($this->debug) {
$this->log->debug(message: "deleteZone()"); $this->log->debug(message: "deleteZone()");
} }
@ -132,55 +139,90 @@ class DomainController
/** /**
* @return void * @return bool
*/ */
function checkPermissions(): void function checkPermissions(): bool
{ {
if ($this->config['debug']) { $setupIsValid = true;
if ($this->debug) {
$this->log->debug(message: "checkPermissions()"); $this->log->debug(message: "checkPermissions()");
} }
echo 'Checking permission:' . PHP_EOL . PHP_EOL; if ($this->verbose) {
echo 'Checking permissions...' . PHP_EOL;
}
$uid = posix_geteuid(); $uid = posix_geteuid();
echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL; if ($this->verbose) {
echo "UID:\t" . COLOR_YELLOW . $uid . PHP_EOL;
}
$pwuid = posix_getpwuid(user_id: $uid); $pwuid = posix_getpwuid(user_id: $uid);
$name = $pwuid['name']; $name = $pwuid['name'];
echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL; if ($this->verbose) {
echo COLOR_DEFAULT . "Name:\t" . COLOR_YELLOW . $name . PHP_EOL;
}
$bindGroup = posix_getgrnam(name: 'bind'); $bindGroup = posix_getgrnam(name: 'bind');
$members = $bindGroup['members']; $members = $bindGroup['members'];
if (in_array(needle: $name, haystack: $members)) { if (in_array(needle: $name, haystack: $members)) {
echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL; if ($this->verbose) {
} else { echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
echo "\t$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL;
}
echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL;
$localZoneFilePermissions = @fileperms(filename: $this->localZoneFile);
if ($localZoneFilePermissions & 0x0010) {
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
} else {
echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL;
}
echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
echo "\t$this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
} else {
echo "\t$this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
} }
} else { } else {
echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL; $setupIsValid = false;
if ($this->verbose) {
echo COLOR_RED . "\t$name needs to be in group " . COLOR_YELLOW . 'bind' . COLOR_DEFAULT . '!' . PHP_EOL;
}
}
if ($this->verbose) {
echo COLOR_DEFAULT . 'Checking ' . COLOR_YELLOW . $this->localZoneFile . PHP_EOL;
}
$localZoneFilePermissions = @fileperms(filename: $this->localZoneFile);
if ($localZoneFilePermissions & 0x0010) {
if ($this->verbose) {
echo COLOR_DEFAULT . "\t✅ Group has write access." . PHP_EOL;
}
} else {
$setupIsValid = false;
if ($this->verbose) {
echo COLOR_RED . "\t❌Group needs write permission!" . COLOR_DEFAULT . PHP_EOL;
}
}
if ($this->verbose) {
echo 'Checking ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
}
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
if (!str_contains(haystack: $namedConfLocal, needle: $this->localZoneFile)) {
$setupIsValid = false;
if ($this->verbose) {
echo "\t$this->localZoneFile" . COLOR_RED . ' needs to be included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
}
} else {
if ($this->verbose) {
echo "\t$this->localZoneFile" . COLOR_DEFAULT . ' is included in ' . COLOR_YELLOW . $this->namedConfLocalFile . PHP_EOL;
}
}
} else {
$setupIsValid = false;
if ($this->verbose) {
echo "\t❌ No access to '$this->namedConfLocalFile' . Please check permissions" . PHP_EOL;
}
}
if ($this->verbose) {
echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL;
} }
echo COLOR_DEFAULT . 'Checking directory: ' . COLOR_YELLOW . $this->localZonesDir . PHP_EOL;
$localZoneDirPermissions = @fileperms(filename: $this->localZonesDir); $localZoneDirPermissions = @fileperms(filename: $this->localZonesDir);
if ($localZoneDirPermissions & 0x0010) { if ($localZoneDirPermissions & 0x0010) {
echo "\t✅ Group has write access." . PHP_EOL; if ($this->verbose) {
echo "\t✅ Group has write access." . PHP_EOL;
}
} else { } else {
echo "\t❌Group needs write permission!" . PHP_EOL; $setupIsValid = false;
if ($this->verbose) {
echo COLOR_RED . "\t❌Group needs write permission!" . PHP_EOL;
}
} }
return $setupIsValid;
} }
@ -189,6 +231,10 @@ class DomainController
*/ */
function checkDomains(): void function checkDomains(): void
{ {
if (!file_exists(filename: $this->localZoneFile)) {
echo COLOR_DEFAULT . 'Local Zone file ' . COLOR_YELLOW . $this->localZoneFile . COLOR_DEFAULT . ' does not exist.' . PHP_EOL;
exit(1);
}
$localZones = file_get_contents(filename: $this->localZoneFile); $localZones = file_get_contents(filename: $this->localZoneFile);
$maxNameLength = $this->domainRepository->getLongestEntry(field: 'name'); $maxNameLength = $this->domainRepository->getLongestEntry(field: 'name');
$domains = $this->domainRepository->findAll(); $domains = $this->domainRepository->findAll();
@ -227,7 +273,7 @@ class DomainController
public function createSlaveZoneFile(Domain $domain): void public function createSlaveZoneFile(Domain $domain): void
{ {
$domainName = $domain->getName(); $domainName = $domain->getName();
if ($this->config['debug']) { if ($this->debug) {
$this->log->debug(message: "createZoneFile($domainName)"); $this->log->debug(message: "createZoneFile($domainName)");
} }

View File

@ -1,18 +0,0 @@
<?php declare(strict_types=1);
namespace App\Controller;
error_reporting(error_level: E_ALL);
/**
*
*/
class NameserverController
{
public function __construct(private DatabaseConnection $databaseConnection)
{}
}

View File

@ -1,19 +0,0 @@
<?php declare(strict_types=1);
namespace App\Controller;
error_reporting(error_level: E_ALL);
/**
*
*/
class PanelController
{
public function __construct(private DatabaseConnection $databaseConnection)
{}
}

View File

@ -4,7 +4,6 @@ namespace App\Repository;
error_reporting(error_level: E_ALL); error_reporting(error_level: E_ALL);
use App\Controller\DatabaseConnection; use App\Controller\DatabaseConnection;
use App\Controller\PanelController;
use App\Entity\Apikey; use App\Entity\Apikey;
use Exception; use Exception;
use PDO; use PDO;
@ -15,7 +14,7 @@ use PDOException;
*/ */
class ApikeyRepository class ApikeyRepository
{ {
public function __construct(private DatabaseConnection $databaseConnection, PanelController $panelController) public function __construct(private readonly DatabaseConnection $databaseConnection)
{} {}

View File

@ -67,9 +67,9 @@ class NameserverRepository
/** /**
* @param int $id * @param int $id
* *
* @return \App\Entity\Nameserver * @return null|\App\Entity\Nameserver
*/ */
public function findByID(int $id): Nameserver public function findByID(int $id): ?Nameserver
{ {
$sql = " $sql = "
SELECT id, name, a, aaaa, apikey SELECT id, name, a, aaaa, apikey
@ -80,8 +80,11 @@ class NameserverRepository
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql); $statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':id', var: $id); $statement->bindParam(param: ':id', var: $id);
$statement->execute(); $statement->execute();
$result = $statement->fetch(mode: PDO::FETCH_ASSOC); if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']); return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
} else {
return null;
}
} catch (PDOException $e) { } catch (PDOException $e) {
exit($e->getMessage()); exit($e->getMessage());
} }