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"?>
<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>
<paths name="shadow.24unix.net">
<paths name="KeyHelpLocalDev">
<serverdata>
<mappings>
<mapping deploy="/bindAPI" local="$PROJECT_DIR$" web="/" />
<mapping deploy="/" local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<option name="suggestChangeDefaultLanguageLevel" value="false" />
</component>

View File

@ -11,16 +11,17 @@
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
"php": ">=8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-pdo": "*",
"arubacao/tld-checker": "^1.2",
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
"phplucidframe/console-table": "^1.2",
"zircote/swagger-php": "^4.2"
},
"php": ">=8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-pdo": "*",
"arubacao/tld-checker": "^1.2",
"monolog/monolog": "^2.3",
"php-di/php-di": "^6.3",
"phplucidframe/console-table": "^1.2",
"squizlabs/php_codesniffer": "^3.7",
"zircote/swagger-php": "^4.2"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
@ -39,6 +40,7 @@
}
},
"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",
"This file is @generated automatically"
],
"content-hash": "f7096254eb316738d722dfff777682ef",
"content-hash": "ebdf6dd62a66775d7344acac9e59a5ce",
"packages": [
{
"name": "arubacao/tld-checker",
@ -745,6 +745,62 @@
},
"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",
"version": "v6.0.3",
@ -1109,6 +1165,64 @@
],
"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",
"version": "1.11.0",
@ -3058,7 +3172,9 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"escapestudios/symfony2-coding-standard": 20
},
"prefer-stable": true,
"prefer-lowest": false,
"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)
{
extract(array: $this->config);
// TODO create config => encryption key
try {
$this->dbConnection = new PDO(
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",

View File

@ -17,16 +17,23 @@ error_reporting(error_level: E_ALL);
*/
class DomainController
{
private string $localZoneFile;
private string $localZonesDir;
private string $namedConfLocalFile;
public string $localZoneFile;
public string $localZonesDir;
public string $namedConfLocalFile;
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()");
}
@ -37,9 +44,9 @@ class DomainController
}
function createIncludeFile()
function createIncludeFile(): void
{
if ($this->config['debug']) {
if ($this->debug) {
$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';
}
@ -81,7 +88,7 @@ class DomainController
$domains = $this->domainRepository->findAll();
foreach ($domains as $domain) {
if ($this->config['verbose']) {
if ($this->verbose) {
echo 'Create zone: ' . $domain->getName() . PHP_EOL;
}
$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()");
}
@ -116,9 +123,9 @@ class DomainController
*
* @return void
*/
function deleteZone(Domain $domain)
function deleteZone(Domain $domain): void
{
if ($this->config['debug']) {
if ($this->debug) {
$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()");
}
echo 'Checking permission:' . PHP_EOL . PHP_EOL;
if ($this->verbose) {
echo 'Checking permissions...' . PHP_EOL;
}
$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);
$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');
$members = $bindGroup['members'];
if (in_array(needle: $name, haystack: $members)) {
echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
} else {
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;
if ($this->verbose) {
echo "\t$name" . COLOR_DEFAULT . ' is in group ' . COLOR_YELLOW . 'bind' . PHP_EOL;
}
} 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);
if ($localZoneDirPermissions & 0x0010) {
echo "\t✅ Group has write access." . PHP_EOL;
if ($this->verbose) {
echo "\t✅ Group has write access." . PHP_EOL;
}
} 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
{
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);
$maxNameLength = $this->domainRepository->getLongestEntry(field: 'name');
$domains = $this->domainRepository->findAll();
@ -227,7 +273,7 @@ class DomainController
public function createSlaveZoneFile(Domain $domain): void
{
$domainName = $domain->getName();
if ($this->config['debug']) {
if ($this->debug) {
$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);
use App\Controller\DatabaseConnection;
use App\Controller\PanelController;
use App\Entity\Apikey;
use Exception;
use PDO;
@ -15,7 +14,7 @@ use PDOException;
*/
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
*
* @return \App\Entity\Nameserver
* @return null|\App\Entity\Nameserver
*/
public function findByID(int $id): Nameserver
public function findByID(int $id): ?Nameserver
{
$sql = "
SELECT id, name, a, aaaa, apikey
@ -80,8 +80,11 @@ class NameserverRepository
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
$statement->bindParam(param: ':id', var: $id);
$statement->execute();
$result = $statement->fetch(mode: PDO::FETCH_ASSOC);
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
} else {
return null;
}
} catch (PDOException $e) {
exit($e->getMessage());
}