Compare commits
No commits in common. "79942030fa747cf9ddf607ca9a66ae57da0056da" and "9a59a2563d25ee2fade13d8aeb494a883ccbce03" have entirely different histories.
79942030fa
...
9a59a2563d
|
@ -7,6 +7,7 @@ use UnhandledMatchError;
|
|||
error_reporting(error_level: E_ALL);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
@ -110,37 +111,4 @@ class ApiController
|
|||
];
|
||||
}
|
||||
|
||||
function fileGetContents(string $url, int $versionIP): ?array
|
||||
{
|
||||
$curl = curl_init(url: $url);
|
||||
|
||||
$options = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_FOLLOWLOCATION => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
CURLOPT_CONNECTTIMEOUT => 120,
|
||||
CURLOPT_TIMEOUT => 120,
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
);
|
||||
|
||||
if ($versionIP == 4) {
|
||||
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V4);
|
||||
} else {
|
||||
curl_setopt(handle: $curl, option: CURLOPT_IPRESOLVE, value: CURL_IPRESOLVE_V6);
|
||||
}
|
||||
|
||||
curl_setopt_array(handle: $curl, options: $options);
|
||||
$content = curl_exec(handle: $curl);
|
||||
$error = curl_errno(handle: $curl);
|
||||
$errorMessage = curl_error(handle: $curl);
|
||||
$header = curl_getinfo(handle: $curl);
|
||||
curl_close(handle: $curl);
|
||||
|
||||
$header['error'] = $error;
|
||||
$header['errorMessage'] = $errorMessage;
|
||||
$header['content'] = $content;
|
||||
|
||||
return $header;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1755,7 +1755,7 @@ class CLIController
|
|||
}
|
||||
|
||||
if (!$quiet) {
|
||||
echo COLOR_DEFAULT . 'Checking domain ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
echo COLOR_DEFAULT . 'Checking domain ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . PHP_EOL;
|
||||
}
|
||||
|
||||
if (!$domain = $this->domainRepository->findByName(name: $domainName)) {
|
||||
|
@ -1780,8 +1780,8 @@ class CLIController
|
|||
$webmailDomain = 'webmail.' . $domainName;
|
||||
|
||||
if (!empty($panel->getAAAA())) {
|
||||
if (!$quiet && $verbose) {
|
||||
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . '.' . COLOR_DEFAULT . PHP_EOL;
|
||||
if ($verbose) {
|
||||
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . COLOR_DEFAULT . PHP_EOL;
|
||||
}
|
||||
$result = $this->apiController->sendCommand(
|
||||
requestType: 'GET',
|
||||
|
@ -1791,7 +1791,7 @@ class CLIController
|
|||
command: 'domains/name/' . $webmailDomain,
|
||||
serverType: 'panel');
|
||||
} else {
|
||||
if (!$quiet && $verbose) {
|
||||
if ($verbose) {
|
||||
echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL;
|
||||
}
|
||||
$result = $this->apiController->sendCommand(
|
||||
|
@ -1800,70 +1800,24 @@ class CLIController
|
|||
versionIP: 4,
|
||||
apiKey: $decryptedKey,
|
||||
command: 'domains/name/' . $webmailDomain,
|
||||
serverType: 'panel');
|
||||
serverType: 'panel' );
|
||||
}
|
||||
|
||||
if ($result['header'] === 404) {
|
||||
if (!$quiet) {
|
||||
echo 'The domain ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . " doesn't exist." . PHP_EOL;
|
||||
echo 'The domain ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . ' doesn\'t exist.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
if(!$quiet) {
|
||||
echo 'Found ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
if ($v4 = dns_get_record(hostname: $webmailDomain, type: DNS_A)[0]) {
|
||||
if (!$quiet) {
|
||||
echo "Found IPv4 entry: " . COLOR_YELLOW . $v4['ip'] . COLOR_DEFAULT . '.' .PHP_EOL;
|
||||
}
|
||||
$v4Test = $this->apiController->fileGetContents(url: $webmailDomain, versionIP: 4);
|
||||
|
||||
if ($v4Test['error']) {
|
||||
if (!$quiet) {
|
||||
echo 'There was an error: ' . COLOR_YELLOW . $v4Test['errorMessage'] . COLOR_DEFAULT . '.';
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Successfully connected to webserver via ' . COLOR_YELLOW . 'IPv4' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo "Found no IPv4 entry for " . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($v6 = dns_get_record(hostname: $webmailDomain, type: DNS_AAAA)[0]) {
|
||||
if (!$quiet) {
|
||||
echo "Found IPv6 entry: " . COLOR_YELLOW . $v6['ipv6'] . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
$v6Test = $this->apiController->fileGetContents(url: $webmailDomain, versionIP: 6);
|
||||
|
||||
if ($v6Test['error']) {
|
||||
if (!$quiet) {
|
||||
echo 'There was an error: ' . COLOR_YELLOW . $v6Test['errorMessage'] . COLOR_DEFAULT . '.';
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Successfully connected to webserver via ' . COLOR_YELLOW . 'IPv6' . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo "Found no IPv6 entry for " . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . '.' . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO check that at least IPv4 or IP6 exists?
|
||||
|
||||
|
||||
$domainData = json_decode(json: $result['data']);
|
||||
$apacheData = $domainData->apache;
|
||||
|
||||
$httpDirectives = $apacheData->http_directives;
|
||||
$httpsDirectives = $apacheData->https_directives . PHP_EOL;
|
||||
|
||||
if (!str_contains(haystack: $httpsDirectives, needle: '# bindAPI - webmailer')) {
|
||||
|
@ -1871,54 +1825,25 @@ class CLIController
|
|||
echo 'Generated config is missing.' . PHP_EOL;
|
||||
}
|
||||
exit(1);
|
||||
} else {
|
||||
if (!$quiet) {
|
||||
echo 'Generated config is valid.' . PHP_EOL;
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function webmailCreate(): bool
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function webmailCreate()
|
||||
{
|
||||
|
||||
// TODO
|
||||
|
||||
/*
|
||||
$webmailConfig = '# bindAPI - webmailer' . PHP_EOL;
|
||||
$webmailConfig .= 'SSLProxyEngine On' . PHP_EOL;
|
||||
$webmailConfig .= 'ProxyPass /.well-known/ !' . PHP_EOL;
|
||||
$webmailConfig .= 'ProxyPass "/" "https://webmail' . $panel->getName() . '"' . PHP_EOL;
|
||||
$webmailConfig .= 'ProxyPass "/" "https://' . $panel->getName() . '/webmail/"' . PHP_EOL;
|
||||
$webmailConfig .= '## bindAPI - webmailer' . PHP_EOL;
|
||||
|
||||
echo $webmailConfig;
|
||||
|
||||
//$httpsDirectives += $w
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
private function checkMail(): void
|
||||
{
|
||||
}
|
||||
|
||||
private function checksVersion(): void
|
||||
{
|
||||
}
|
||||
|
||||
private function dynDnyUpdate(): void
|
||||
{
|
||||
}
|
||||
|
||||
private function dynDnsDelete(): void
|
||||
{
|
||||
}
|
||||
|
||||
private function webmailDelete(): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
//error_reporting(error_level: E_ALL);
|
||||
error_reporting(error_level: E_ALL);
|
||||
|
||||
|
||||
use PDO;
|
||||
|
@ -30,17 +30,16 @@ class DatabaseConnection
|
|||
$dbUser = $this->configController->getConfig(configKey: 'dbUser');
|
||||
$dbPassword = $this->configController->getConfig(configKey: 'dbPassword');
|
||||
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'test')) {
|
||||
// TODO create config => encryption key
|
||||
try {
|
||||
$this->dbConnection = new PDO(
|
||||
dsn: "mysql:host=$dbHost;port=$dbPort;charset=utf8mb4;dbname=$dbDatabase",
|
||||
username: $dbUser,
|
||||
password: $dbPassword
|
||||
);
|
||||
|
||||
if (!$this->configController->getConfig(configKey: 'test')) {
|
||||
// TODO create config => encryption key
|
||||
try {
|
||||
$sql = "SHOW TABLES";
|
||||
|
||||
$statement = $this->dbConnection->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
$result = $statement->fetch();
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
namespace App\Entity;
|
||||
|
||||
|
||||
use App\Enums\PanelType;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -4,8 +4,8 @@ namespace App\Repository;
|
|||
error_reporting(error_level: E_ALL);
|
||||
|
||||
use App\Controller\DatabaseConnection;
|
||||
use App\Controller\EncryptionController;
|
||||
use App\Entity\Apikey;
|
||||
use Exception;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
|
@ -14,7 +14,7 @@ use PDOException;
|
|||
*/
|
||||
class ApikeyRepository
|
||||
{
|
||||
public function __construct(private readonly DatabaseConnection $databaseConnection, EncryptionController $encryptionController)
|
||||
public function __construct(private readonly DatabaseConnection $databaseConnection)
|
||||
{}
|
||||
|
||||
|
||||
|
@ -23,9 +23,8 @@ class ApikeyRepository
|
|||
*/
|
||||
public function findAll(): bool|array
|
||||
{
|
||||
|
||||
$sql = "
|
||||
SELECT id, name, apikey_prefix, apikey
|
||||
SELECT id, name, api_token_prefix, api_token
|
||||
FROM " . DatabaseConnection::TABLE_APIKEYS;
|
||||
|
||||
try {
|
||||
|
@ -35,7 +34,7 @@ class ApikeyRepository
|
|||
$apikeys = [];
|
||||
|
||||
while ($result = $statement->fetch()) {
|
||||
$apikey = new Apikey(id: $result['id'], name: $result['name'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
$apikey = new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token'], id: $result['id']);
|
||||
$apikeys[] = $apikey;
|
||||
}
|
||||
return $apikeys;
|
||||
|
@ -48,12 +47,12 @@ class ApikeyRepository
|
|||
/**
|
||||
* @param Int $id
|
||||
*
|
||||
* @return Apikey|bool
|
||||
* @return \App\Entity\Apikey|bool
|
||||
*/
|
||||
public function findByID(Int $id): Apikey|bool
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, apikey_prefix, apikey
|
||||
SELECT id, name, api_token_prefix, api_token
|
||||
FROM " . DatabaseConnection::TABLE_APIKEYS . "
|
||||
WHERE id = :id;
|
||||
";
|
||||
|
@ -63,7 +62,7 @@ class ApikeyRepository
|
|||
$statement->bindParam(param: ':id', var: $id);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Apikey(id: $result['id'], name: $result['name'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
return new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token'], id: $result['id']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -76,21 +75,21 @@ class ApikeyRepository
|
|||
/**
|
||||
* @param String $prefix
|
||||
*
|
||||
* @return Apikey|bool
|
||||
* @return \App\Entity\Apikey|bool
|
||||
*/
|
||||
public function findByPrefix(String $prefix): Apikey|bool
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, apikey_prefix, apikey
|
||||
SELECT id, name, api_token_prefix, api_token
|
||||
FROM " . DatabaseConnection::TABLE_APIKEYS . "
|
||||
WHERE apikey_prefix = :prefix";
|
||||
WHERE api_token_prefix = :prefix";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':prefix', var: $prefix);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Apikey(id: $result['id'], name: $result['name'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
return new Apikey(name: $result['name'], apiTokenPrefix: $result['api_token_prefix'], apiToken: $result['api_token'], id: $result['id']);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -101,46 +100,51 @@ class ApikeyRepository
|
|||
|
||||
|
||||
/**
|
||||
* @param Apikey $apikey
|
||||
* @return int
|
||||
* @return array|void
|
||||
*/
|
||||
public function insert(ApiKey $apikey): int
|
||||
public function create(String $name = '')
|
||||
{
|
||||
|
||||
$name = $apikey->getName();
|
||||
$apikeyPrefix = $apikey->getApikeyPrefix();
|
||||
$apikeyValue = $apikey->getApikey();
|
||||
$tokenPrefix = uniqid();
|
||||
$result['tokenPrefix'] = $tokenPrefix;
|
||||
try {
|
||||
$key = bin2hex(string: random_bytes(length: 24));
|
||||
$result['key'] = $key;
|
||||
} catch (Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
$token = password_hash(password: $tokenPrefix . '.' . $key, algo: PASSWORD_ARGON2ID);
|
||||
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_APIKEYS . " (name, apikey_prefix, apikey)
|
||||
VALUES (:name, :apikey_prefix, :apikey)";
|
||||
INSERT INTO " . DatabaseConnection::TABLE_APIKEYS . " (name, api_token_prefix, api_token)
|
||||
VALUES (:name, :token_prefix, :token)";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':token_prefix', var: $tokenPrefix);
|
||||
$statement->bindParam(param: ':token', var: $token);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->bindParam(param: ':apikey_prefix', var: $apikeyPrefix);
|
||||
$statement->bindParam(param: ':apikey', var: $apikeyValue);
|
||||
|
||||
$statement->execute();
|
||||
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
||||
$result['row'] = $this->databaseConnection->getConnection()->lastInsertId();
|
||||
return $result;
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Apikey $apikey
|
||||
* @param Int $id
|
||||
* @param String $name
|
||||
*
|
||||
* @return false|int
|
||||
*/
|
||||
public function update(Apikey $apikey): bool|int
|
||||
public function update(int $id, string $name): bool|int
|
||||
{
|
||||
$id = $apikey->getId();
|
||||
$name = $apikey->getName();
|
||||
|
||||
$current = $this->findByID(id: $id);
|
||||
|
||||
if (empty($name)) {
|
||||
$name = $current->getName();
|
||||
$name = $current['name'];
|
||||
}
|
||||
|
||||
$sql = "
|
||||
|
|
|
@ -6,7 +6,6 @@ use App\Controller\DatabaseConnection;
|
|||
use App\Entity\Nameserver;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use SodiumException;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -15,18 +14,17 @@ class NameserverRepository
|
|||
{
|
||||
public function __construct(private readonly DatabaseConnection $databaseConnection)
|
||||
{
|
||||
// no body
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
* @return array
|
||||
*/
|
||||
public function findAll(): ?array
|
||||
public function findAll(): array
|
||||
{
|
||||
$nameservers = [];
|
||||
$sql = "
|
||||
SELECT id, name, a, aaaa, apikey, apikey_prefix
|
||||
SELECT id, name, a, aaaa, apikey
|
||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
ORDER BY name";
|
||||
|
||||
|
@ -34,7 +32,7 @@ class NameserverRepository
|
|||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
while ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
$nameserver = new Nameserver(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
$nameserver = new Nameserver(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
|
||||
$nameservers[] = $nameserver;
|
||||
}
|
||||
return $nameservers;
|
||||
|
@ -45,12 +43,13 @@ class NameserverRepository
|
|||
|
||||
|
||||
/**
|
||||
* @return Nameserver|null
|
||||
* @return \App\Entity\Nameserver
|
||||
*/
|
||||
public function findFirst(): ?Nameserver
|
||||
public function findFirst(): Nameserver
|
||||
{
|
||||
$nameservers = [];
|
||||
$sql = "
|
||||
SELECT id, name, a, aaaa, apikey, apikey_prefix
|
||||
SELECT id, name, a, aaaa, apikey
|
||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
ORDER BY name";
|
||||
|
||||
|
@ -58,7 +57,7 @@ class NameserverRepository
|
|||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->execute();
|
||||
$result = $statement->fetch(mode: PDO::FETCH_ASSOC);
|
||||
return new Nameserver(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
return new Nameserver(name: $result['name'], id: $result['id'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
}
|
||||
|
@ -68,12 +67,12 @@ class NameserverRepository
|
|||
/**
|
||||
* @param int $id
|
||||
*
|
||||
* @return null|Nameserver
|
||||
* @return null|\App\Entity\Nameserver
|
||||
*/
|
||||
public function findByID(int $id): ?Nameserver
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, a, aaaa, apikey, apikey_prefix
|
||||
SELECT id, name, a, aaaa, apikey
|
||||
FROM . " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
WHERE id = :id";
|
||||
|
||||
|
@ -82,7 +81,7 @@ class NameserverRepository
|
|||
$statement->bindParam(param: ':id', var: $id);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey']);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -95,12 +94,12 @@ class NameserverRepository
|
|||
/**
|
||||
* @param String $name
|
||||
*
|
||||
* @return Nameserver|null
|
||||
* @return \App\Entity\Nameserver|bool
|
||||
*/
|
||||
public function findByName(string $name): ?Nameserver
|
||||
public function findByName(string $name): Nameserver|bool
|
||||
{
|
||||
$sql = "
|
||||
SELECT id, name, a, aaaa, apikey, apikey_prefix
|
||||
SELECT id, name, a, aaaa, apikey
|
||||
FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
WHERE name = :name";
|
||||
|
||||
|
@ -109,9 +108,9 @@ class NameserverRepository
|
|||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->execute();
|
||||
if ($result = $statement->fetch(mode: PDO::FETCH_ASSOC)) {
|
||||
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa'], apikey: $result['apikey'], apikeyPrefix: $result['apikey_prefix']);
|
||||
return new Nameserver(name: $result['name'], a: $result['a'], aaaa: $result['aaaa']);
|
||||
} else {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage());
|
||||
|
@ -120,55 +119,57 @@ class NameserverRepository
|
|||
|
||||
|
||||
/**
|
||||
* @param Nameserver $nameserver
|
||||
* @param \App\Entity\Nameserver $nameserver
|
||||
*
|
||||
* @return int|null
|
||||
* @return string|false
|
||||
*/
|
||||
public function insert(Nameserver $nameserver): ?int
|
||||
public function insert(Nameserver $nameserver): bool|string
|
||||
{
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey)
|
||||
VALUES (:name, :a, :aaaa, :apikey)";
|
||||
|
||||
try {
|
||||
$name = $nameserver->getName();
|
||||
$a = $nameserver->getA();
|
||||
$aaaa = $nameserver->getAaaa();
|
||||
$apikey = $nameserver->getApikey();
|
||||
$apikeyPrefix = $nameserver->getApikeyPrefix();
|
||||
|
||||
|
||||
$sql = "
|
||||
INSERT INTO " . DatabaseConnection::TABLE_NAMESERVERS . " (name, a, aaaa, apikey, apikey_prefix)
|
||||
VALUES (:name, :a, :aaaa, :apikey, :apikey_prefix)";
|
||||
|
||||
try {
|
||||
$statement = $this->databaseConnection->getConnection()->prepare(query: $sql);
|
||||
$statement->bindParam(param: ':name', var: $name);
|
||||
$statement->bindParam(param: ':a', var: $a);
|
||||
$statement->bindParam(param: ':aaaa', var: $aaaa);
|
||||
$statement->bindParam(param: ':apikey', var: $apikey);
|
||||
$statement->bindParam(param: ':apikey_prefix', var: $apikeyPrefix);
|
||||
$statement->execute();
|
||||
|
||||
return intval(value: $this->databaseConnection->getConnection()->lastInsertId());
|
||||
return $this->databaseConnection->getConnection()->lastInsertId();
|
||||
} catch (PDOException $e) {
|
||||
exit($e->getMessage() . PHP_EOL);
|
||||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Nameserver $nameserver
|
||||
* @param Int $id
|
||||
* @param String $name
|
||||
* @param String $a
|
||||
* @param String $aaaa
|
||||
* @param String $apikey
|
||||
*
|
||||
* @return false|int
|
||||
*/
|
||||
public function update(Nameserver $nameserver): bool|int
|
||||
public function update(int $id, string $name, string $a, string $aaaa, string $apikey): bool|int
|
||||
{
|
||||
$id = $nameserver->getId();
|
||||
$name = $nameserver->getName();
|
||||
$a = $nameserver->getA();
|
||||
$aaaa = $nameserver->getAaaa();
|
||||
$apikey = $nameserver->getApikey();
|
||||
$apikeyPrefix = $nameserver->getApikeyPrefix();
|
||||
$passphrase = $nameserver->getPassphrase();
|
||||
|
||||
$current = $this->findByID(id: $id);
|
||||
|
||||
/* doesn't work
|
||||
$statement = "
|
||||
INSERT INTO domains(id, name, a, aaaa)
|
||||
VALUES(:id, :name, :a, :aaaa)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name=COALESCE(VALUES(name), :name),
|
||||
a=COALESCE(:a, a),
|
||||
aaaa=COALESCE(:aaaa, aaaa)";
|
||||
*/
|
||||
|
||||
if (empty($name)) {
|
||||
$name = $current->getName();
|
||||
|
@ -179,20 +180,16 @@ class NameserverRepository
|
|||
if (empty($aaaa)) {
|
||||
$aaaa = $current->getAaaa();
|
||||
}
|
||||
|
||||
if (empty($passphrase)) {
|
||||
if (empty($apikey)) {
|
||||
$apikey = $current->getApikey();
|
||||
$apikeyPrefix = $current->getApikeyPrefix();
|
||||
}
|
||||
|
||||
|
||||
$sql = "
|
||||
UPDATE " . DatabaseConnection::TABLE_NAMESERVERS . " SET
|
||||
name = :name,
|
||||
a = :a,
|
||||
aaaa = :aaaa,
|
||||
apikey = :apikey,
|
||||
apikey_prefix = :apikey_prefix
|
||||
apikey = :apikey
|
||||
WHERE id = :id";
|
||||
|
||||
try {
|
||||
|
@ -202,14 +199,9 @@ class NameserverRepository
|
|||
$statement->bindParam(param: 'a', var: $a);
|
||||
$statement->bindParam(param: 'aaaa', var: $aaaa);
|
||||
$statement->bindParam(param: 'apikey', var: $apikey);
|
||||
$statement->bindParam(param: 'apikey_prefix', var: $apikeyPrefix);
|
||||
$statement->execute();
|
||||
try {
|
||||
sodium_memzero(string: $apikey);
|
||||
} catch(SodiumException $e) {
|
||||
die($e->getMessage() . PHP_EOL);
|
||||
}
|
||||
return intval(value: $statement->rowCount());
|
||||
|
||||
return $statement->rowCount();
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
return false;
|
||||
|
@ -220,9 +212,9 @@ class NameserverRepository
|
|||
/**
|
||||
* @param $id
|
||||
*
|
||||
* @return int|null
|
||||
* @return int
|
||||
*/
|
||||
public function delete($id): ?int
|
||||
public function delete($id): int
|
||||
{
|
||||
$sql = "
|
||||
DELETE FROM " . DatabaseConnection::TABLE_NAMESERVERS . "
|
||||
|
|
|
@ -257,16 +257,4 @@ class PanelRepository
|
|||
exit($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getSelf(): ?Panel
|
||||
{
|
||||
$panels = $this->findAll();
|
||||
foreach ($panels as $panel) {
|
||||
if ($panel->getSelf() === 'yes') {
|
||||
return $panel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Unit\Repository;
|
||||
|
||||
use App\Controller\ConfigController;
|
||||
use App\Controller\DomainController;
|
||||
use App\Entity\Domain;
|
||||
use App\Repository\DomainRepository;
|
||||
use DI\Container;
|
||||
use DI\ContainerBuilder;
|
||||
use Exception;
|
||||
use Monolog\Formatter\LineFormatter;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Unit\Controller\BindApiControllerTest;
|
||||
use function DI\autowire;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class DomainRepositoryTest extends BindApiControllerTest
|
||||
{
|
||||
private string $localZoneFile;
|
||||
private string $localZonesDir;
|
||||
private string $namedConfLocalFile;
|
||||
|
||||
|
||||
/**
|
||||
* @param int|string $dataName
|
||||
*
|
||||
* @throws Exception
|
||||
* @internal This method is not covered by the backward compatibility promise for PHPUnit
|
||||
*/
|
||||
public function __construct(?string $name = null, array $data = [], $dataName = '')
|
||||
{
|
||||
parent::__construct(name: $name, data: $data, dataName: $dataName);
|
||||
}
|
||||
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->logger->info(message: 'Started DomainRepositoryTest');
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
$this->logger->info(message: 'Finished DomainRepositoryTest');
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
self::assertEquals(expected: true, actual: true);
|
||||
/*
|
||||
$domain = new Domain(name: 'inserttest.org', panel: 'keyhelp.lab.24unix.net');
|
||||
$this->domainRepository->insert(domain: $domain);
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
|
||||
// now get the persisted domain with id
|
||||
$domainTest = $this->domainRepository->findByName(name: 'inserttest.org');
|
||||
|
||||
$this->assertIsNotBool(actual: $domainTest);
|
||||
$this->assertEquals(expected: 'inserttest.org', actual: $domainTest->getName());
|
||||
|
||||
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
|
||||
$this->assertStringContainsString(needle: $this->localZoneFile, haystack: $namedConfLocal);
|
||||
} else {
|
||||
$this->fail(message: 'No permissions: ' . $this->namedConfLocalFile);
|
||||
}
|
||||
|
||||
$this->assertNotFalse(condition: fileperms(filename: $this->localZoneFile));
|
||||
|
||||
$localZones = file_get_contents(filename: $this->localZoneFile);
|
||||
$this->assertStringContainsString(needle: $domainTest->getName(), haystack: $localZones);
|
||||
|
||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||
|
||||
$this->assertFileExists(filename: $zoneFile);
|
||||
|
||||
|
||||
// clean up
|
||||
$this->domainRepository->delete(domain: $domainTest);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
self::assertEquals(expected: true, actual: true);
|
||||
|
||||
/*
|
||||
$domain = new Domain(name: 'inserttest.org', panel: 'keyhelp.lab.24unix.net');
|
||||
$this->domainRepository->insert(domain: $domain);
|
||||
$this->domainController->createSlaveZoneFile(domain: $domain);
|
||||
|
||||
$domainTest = $this->domainRepository->findByName(name: 'inserttest.org');
|
||||
$this->assertIsNotBool(actual: $domainTest);
|
||||
$this->assertEquals(expected: 'inserttest.org', actual: $domainTest->getName());
|
||||
|
||||
// domain is valid and created
|
||||
|
||||
// now delete and check for cleanup
|
||||
$this->domainRepository->delete(domain: $domainTest);
|
||||
|
||||
$this->domainController->deleteZone(domain: $domainTest);
|
||||
|
||||
// check zone is removed
|
||||
|
||||
$this->assertNotFalse(condition: fileperms(filename: $this->localZoneFile));
|
||||
|
||||
$localZones = file_get_contents(filename: $this->localZoneFile);
|
||||
$this->assertStringNotContainsString(needle: $domainTest->getName(), haystack: $localZones);
|
||||
|
||||
$zoneFile = $this->localZonesDir . $domain->getName();
|
||||
|
||||
$this->assertFileDoesNotExist(filename: $zoneFile);
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Unit\Repository;
|
||||
|
||||
use App\Entity\Nameserver;
|
||||
use Unit\Controller\BindApiControllerTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class NameserverRepositoryTest extends BindApiControllerTest
|
||||
{
|
||||
/**
|
||||
*/
|
||||
public function testInsert()
|
||||
{
|
||||
$nameserver = new Nameserver(name: 'inserttest.org', a: '1.2.3.4', aaaa: '1bad::babe');
|
||||
$this->nameserverRepository->insert(nameserver: $nameserver);
|
||||
|
||||
$nameserverTest = $this->nameserverRepository->findByName(name: 'inserttest.org');
|
||||
$this->assertIsNotBool(actual: $nameserver);
|
||||
$this->assertEquals(expected: 'inserttest.org', actual: $nameserverTest->getName());
|
||||
// clean up
|
||||
$this->nameserverRepository->delete(id: $nameserverTest->getId());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Unit\Repository;
|
||||
|
||||
use App\Controller\BindApiTestController;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Unit\Controller\BindApiControllerTest;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class PanelRepositoryTest extends BindApiControllerTest
|
||||
{
|
||||
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
}
|
||||
|
||||
public function tearDown(): void
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
self::assertEquals(expected: true, actual: true);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue