added webmail:check

This commit is contained in:
tracer 2022-09-29 19:21:42 +02:00
parent b536316a84
commit 0268262e98
1 changed files with 269 additions and 224 deletions

View File

@ -60,159 +60,211 @@ class CLIController
private readonly EncryptionController $encryptionController,
private $logger)
{
$this->checkSetup();
$this->runCheckSetup();
$this->commandGroupContainer = (new CommandGroupContainer())
->add(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'check', description: 'health checks the system can perform'))
->addCommand(command: new Command(
name: 'permissions',
callback: function () {
$this->handleCheckPermissions();
$this->checkPermissions();
},
description: 'health checks the system can perform'))
->addCommand(command: new Command(
name: 'panels',
callback: function () {
$this->handleCheckPanels();
$this->checkPanels();
},
optionalParameters: ['ID', 'fix=xes']))
->addCommand(command: new Command(
name: 'domains',
callback: function () {
$this->handleCheckDomains();
$this->checkDomains();
}))
->addCommand(command: new Command(
name: 'mail',
callback: function () {
$this->checkMail();
}))
->addCommand(command: new Command(
name: 'showincludes',
callback: function () {
$this->handleCheckShowIncludes();
$this->checkShowIncludes();
},
description: 'Shows needed setting on panels'))
->addCommand(command: new Command(
name: 'generatekey',
callback: function () {
$this->handleCheckGenerateKey();
$this->checkGenerateKey();
},
description: 'Generates a a new key for encryption'))
->addCommand(command: new Command(
name: 'setup',
callback: function () {
$this->handleCheckSetup();
$this->checkSetup();
},
mandatoryParameters: ['username'],
description: 'Adapt filesystem permissions (requires elaborated permissions)'))
->addCommand(command: new Command(
name: 'version',
callback: function () {
$this->handleChecksVersion();
$this->checksVersion();
},
optionalParameters: ['major:minor:patch'],
description: 'Read or set the bindApi version in the database')))
->add(commandGroup: (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'panels', description: 'all KeyHelp systems configured'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->handlePanelsList();
$this->panelsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->handlePanelsCreate();
$this->panelsCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->handlePanelsUpdate();
$this->panelsUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->handlePanelsDelete();
$this->panelsDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->handleApiPing();
$this->apiPing(type: 'panel');
},
optionalParameters: ['ID'])))
->add(commandGroup: (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'nameservers', description: 'available nameservers'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->handleNameserversList();
$this->nameserversList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->handleNameserversCreate();
$this->nameserversCreate();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->handleNameserversUpdate();
$this->nameserversUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->handleNameserversDelete();
$this->nameserversDelete();
},
mandatoryParameters: ['ID']))
->addCommand(command: new Command(
name: 'apiping',
callback: function () {
$this->handleApiPing();
$this->apiPing(type: 'nameserver');
},
optionalParameters: ['ID'])))
->add(commandGroup: (new CommandGroup(name: 'domains', description: 'configured domains'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'domains', description: 'configured domains'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->handleDomainsList();
$this->domainsList();
}))
->addCommand(command: new Command(
name: 'refresh',
callback: function () {
$this->handleDomainsRefresh();
$this->domainsRefresh();
},
mandatoryParameters: ['name'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>'])))
->add(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'dyndns', description: 'handle DynDNS entries'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->handleDynDnsList();
$this->dynDnsList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->handlePanelsCreate();
$this->dynDnsCreate();
},
mandatoryParameters: ['hostname.example.com', 'password'],
optionalParameters: ['A=<IPv4>', 'AAAA=<IPv6>'],
description: 'FQDN within a domain where this server is master'))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->handlePanelsUpdate();
$this->dynDnyUpdate();
},
mandatoryParameters: ['ID'],
optionalParameters: ['name=<name>', 'A=<IPv4>', 'AAAA=<IPv6>', 'apikey=<API-Key>']))
mandatoryParameters: ['hostname.example.com',],
optionalParameters: ['password=<password>', 'A=<IPv4>', 'AAAA=<IPv6>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->handlePanelsDelete();
$this->dynDnsDelete();
},
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'apikeys', description: 'API keys to access this bindAPI'))
->addCommand(command: new Command(
name: 'list',
callback: function () {
$this->apikeysList();
}))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->apikeysCreate();
},
optionalParameters: ['name=<name>']))
->addCommand(command: new Command(
name: 'update',
callback: function () {
$this->apikeysUpdate();
},
mandatoryParameters: ['ID',],
optionalParameters: ['name=<name>']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->apikeysDelete();
},
mandatoryParameters: ['ID'])))
->addCommandGroup(commandGroup: (new CommandGroup(name: 'webmail', description: 'manage webmail setup'))
->addCommand(command: new Command(
name: 'check',
callback: function () {
$this->webmailCheck();
},
mandatoryParameters: ['example.com']
))
->addCommand(command: new Command(
name: 'create',
callback: function () {
$this->webmailCreate();
},
mandatoryParameters: ['example.com']))
->addCommand(command: new Command(
name: 'delete',
callback: function () {
$this->webmailDelete();
},
mandatoryParameters: ['ID'])));
}
function checkSetup(): void
function runCheckSetup(): void
{
if (!$this->domainController->checkPermissions(disableVerbose: true)) {
echo 'You need to setup the bindAPI first.' . PHP_EOL;
@ -284,42 +336,15 @@ class CLIController
$this->commandGroupContainer->printCommands();
echo COLOR_YELLOW . "dyndns" . COLOR_WHITE . " handle dyndns entries" . PHP_EOL;
echo COLOR_GREEN . "\t dyndns:list" . PHP_EOL;
echo COLOR_GREEN . "\t dyndns:create <hostname.example.com> <password>" . COLOR_DEFAULT . " FQDN within a domain where this server is master" . PHP_EOL;
echo COLOR_GREEN . "\t dyndns:update <hostname.example.com> <password> {A=<IPv4>} {AAAA=<IPv6>}" . PHP_EOL;
echo COLOR_GREEN . "\t dyndns:delete <ID>" . PHP_EOL;
echo COLOR_YELLOW . "apikeys" . COLOR_WHITE . "\t API keys to access this server" . PHP_EOL;
echo COLOR_GREEN . "\t apikeys:list" . PHP_EOL;
echo COLOR_GREEN . "\t apikeys:create {name=<name>}" . PHP_EOL;
echo COLOR_GREEN . "\t apikeys:update <ID> {name=<name>}" . PHP_EOL;
echo COLOR_GREEN . "\t apikeys:delete <ID>" . PHP_EOL;
echo PHP_EOL . "\033[39me.g. ./bin/console apikeys:list" . PHP_EOL;
}
function unknownCommand(string $command): void
{
echo COLOR_DEFAULT . 'Unknown command: ' . COLOR_YELLOW . $command . COLOR_DEFAULT . PHP_EOL;
}
function unknownSubcommand(string $subcommand): void
{
if ($subcommand) {
echo COLOR_DEFAULT . 'Unknown argument: ' . COLOR_YELLOW . $subcommand . COLOR_DEFAULT . PHP_EOL;
} else {
echo COLOR_DEFAULT . 'You need to supply a subcommand after a colon.' . COLOR_DEFAULT . PHP_EOL;
}
}
/**
*/
public function handleCheckPermissions(): void
public function checkPermissions(): void
{
$this->logger->debug(message: "handleCheckPermissions()");
$this->logger->debug(message: "checkPermissions()");
if (!$this->domainController->checkPermissions()) {
if ($this->configController->getConfig(configKey: 'verbose')) {
@ -333,26 +358,9 @@ class CLIController
}
/*
public function handleCheckPermissions(): void
function checkSetup(): void
{
$this->logger->debug(message: "handleCheckPermissions()");
if (!$this->domainController->checkPermissions()) {
if ($this->configController->getConfig(configKey: 'verbose')) {
echo PHP_EOL . COLOR_DEFAULT;
echo 'Missing permissions, please run ' . COLOR_YELLOW . './bin/console check:setup' . COLOR_DEFAULT . ' as root or with sudo.' . PHP_EOL;
}
exit(1);
} else {
exit(0);
}
}
*/
function handleCheckSetup(): void
{
if (count($this->arguments) < 2) {
if (empty($this->arguments[1])) {
echo 'You need to supply a username.' . PHP_EOL;
exit(1);
}
@ -434,9 +442,9 @@ class CLIController
/**
*/
function handleCheckPanels(): void
function checkPanels(): void
{
$this->logger->debug(message: "handleCheckPanels()");
$this->logger->debug(message: "checkPanels()");
$id = intval(value: $this->arguments[1] ?? 0);
@ -461,7 +469,8 @@ class CLIController
*
* @return void
*/
public function checkSinglePanel(Panel $panel): void
public
function checkSinglePanel(Panel $panel): void
{
$this->logger->debug(message: "checkSinglePanel()");
@ -654,23 +663,27 @@ class CLIController
{
$this->logger->debug(message: "checkNS()");
$nameServers = $this->nameserverRepository->findAll();
foreach ($nameServers as $nameServer) {
echo COLOR_YELLOW . ' ' . $nameServer->getName();
if (!empty($nameServer->getName())) {
$nameservers = $this->nameserverRepository->findAll();
foreach ($nameservers as $nameserver) {
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $nameserver->getApikey(), key: $encryptionKey);
echo COLOR_YELLOW . ' ' . $nameserver->getName();
if (!empty($nameserver->getName())) {
$result = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $nameServer->getName(),
serverName: $nameserver->getName(),
versionIP: 6,
apiKey: $nameServer->getApikey(),
apiKey: $decryptedKey,
command: 'domains/name/' . $domainName,
serverType: 'nameserver');
} else {
$result = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $nameServer->getName(),
serverName: $nameserver->getName(),
versionIP: 4,
apiKey: $nameServer->getApikey(),
apiKey: $decryptedKey(),
command: 'domains/name/',
serverType: 'nameserver' . $domainName);
}
@ -687,21 +700,24 @@ class CLIController
'name' => $domainName,
'panel' => $panel->getName(),
];
if (!empty($nameServer->getAaaa())) {
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $nameserver->getApikey(), key: $encryptionKey);
if (!empty($nameserver->getAaaa())) {
$create = $this->apiController->sendCommand(
requestType: 'POST',
serverName: $nameServer->getName(),
serverName: $nameserver->getName(),
versionIP: 6,
apiKey: $nameServer->getApikey(),
apiKey: $decryptedKey,
command: 'domains',
serverType: 'nameserver',
body: $body);
} else {
$create = $this->apiController->sendCommand(
requestType: 'POST',
serverName: $nameServer->getName(),
serverName: $nameserver->getName(),
versionIP: 4,
apiKey: $nameServer->getAPikey(),
apiKey: $decryptedKey(),
command: 'domains',
serverType: 'nameserver',
body: $body);
@ -726,7 +742,8 @@ class CLIController
* @param array $arguments
* @return array
*/
public function parseArguments(array $arguments): array
public
function parseArguments(array $arguments): array
{
$this->logger->debug(message: "parseArguments()");
@ -745,31 +762,13 @@ class CLIController
return $parsedArguments;
}
/**
* @param string $subcommand
*
* @return void
*/
public function handlePanels(string $subcommand): void
{
$this->logger->debug(message: "handlePanels()");
match ($subcommand) {
'create' => $this->handlePanelsCreate(),
'list' => $this->handlePanelsList(),
'update' => $this->handlePanelsUpdate(),
'delete' => $this->handlePanelsDelete(),
'apiping' => $this->handleApiPing(type: 'panel'),
default => $this->unknownSubcommand(subcommand: $subcommand)
};
}
/**
* @return void
*/
function handlePanelsCreate(): void
function panelsCreate(): void
{
$this->logger->debug(message: "handlePanelsCreate()");
$this->logger->debug(message: "panelsCreate()");
$name = $this->arguments[1] ?? '';
if (empty($name)) {
@ -809,9 +808,9 @@ class CLIController
/**
* @return void
*/
function handlePanelsList(): void
function panelsList(): void
{
$this->logger->debug(message: "handlePanelsList()");
$this->logger->debug(message: "panelsList()");
$panels = $this->panelRepository->findAll();
if (!empty($panels)) {
@ -841,9 +840,9 @@ class CLIController
/**
*/
function handlePanelsUpdate(): void
function panelsUpdate(): void
{
$this->logger->debug(message: "handlePanelsUpdate()");
$this->logger->debug(message: "panelsUpdate()");
$id = intval(value: $this->arguments[1] ?? 0);
$name = $this->arguments['name'] ?? '';
@ -874,9 +873,9 @@ class CLIController
/**
*/
function handlePanelsDelete(): void
function panelsDelete(): void
{
$this->logger->debug(message: "handlePanelsDelete()");
$this->logger->debug(message: "panelsDelete()");
if (empty($this->arguments[1])) {
echo "You need to supply an ID." . PHP_EOL;
@ -898,9 +897,9 @@ class CLIController
/**
*/
function handleApiPing(string $type): void
function apiPing(string $type): void
{
$this->logger->debug(message: "handleApiPing()");
$this->logger->debug(message: "apiPing()");
$error = false;
@ -951,7 +950,8 @@ class CLIController
/**
* @return int|void
*/
public function getId()
public
function getId()
{
if (!empty($this->arguments[1])) {
$id = intval(value: $this->arguments[1] ?? 0);
@ -972,9 +972,10 @@ class CLIController
*
* @return bool
*/
public function checkPing(Panel|Nameserver $server, string $type): bool
public
function checkPing(Panel|Nameserver $server, string $type): bool
{
$this->logger->debug(message: "handleApiPing() - server, type: " . $server->getName() . ', ' . $type);
$this->logger->debug(message: "checkPing() - server, type: " . $server->getName() . ', ' . $type);
$error = false;
@ -1061,26 +1062,11 @@ class CLIController
return !$error;
}
/**
* @param string $subcommand
*
* @return void
*/
public function handleApiKeys(string $subcommand): void
{
match ($subcommand) {
'create' => $this->handleApikeysCreate(),
'list' => $this->handleApikeysList(),
'update' => $this->handleApikeysUpdate(),
'delete' => $this->handleApikeysDelete(),
default => $this->unknownSubcommand(subcommand: $subcommand)
};
}
/**
* @return void
*/
function handleApikeysCreate(): void
function apikeysCreate(): void
{
$name = $this->arguments['name'] ?? '';
@ -1111,7 +1097,7 @@ class CLIController
/**
* @return void
*/
function handleApikeysList(): void
function apikeysList(): void
{
$keys = $this->apikeyRepository->findAll();
if (!empty($keys)) {
@ -1136,7 +1122,7 @@ class CLIController
/**
*/
function handleApikeysUpdate(): void
function apikeysUpdate(): void
{
$id = intval(value: $this->arguments[1]) ?? 0;
$name = $this->arguments['name'] ?? '';
@ -1166,7 +1152,7 @@ class CLIController
/**
* @return void
*/
function handleApikeysDelete(): void
function apikeysDelete(): void
{
$id = intval(value: $this->arguments[1] ?? 0);
if ($id == 0) {
@ -1183,26 +1169,11 @@ class CLIController
}
}
/**
* @param string $subcommand
*
* @return void
*/
public function handleDomains(string $subcommand): void
{
match ($subcommand) {
'list' => $this->handleDomainsList(),
'refresh' => $this->handleDomainsRefresh(),
'update' => $this->handleDomainsUpdate(),
'delete' => $this->handleDomainsDelete(),
default => $this->unknownSubcommand(subcommand: $subcommand)
};
}
/**
* @return void
*/
function handleDomainsList(): void
function domainsList(): void
{
$domains = $this->domainRepository->findAll();
if (!empty($domains)) {
@ -1229,7 +1200,7 @@ class CLIController
/**
* @return void
*/
function handleDynDnsList(): void
function dynDnsList(): void
{
$dyndns = $this->dynDNSRepository->findAll();
if (!empty($dyndns)) {
@ -1254,7 +1225,7 @@ class CLIController
/**
* @return void
*/
function handleDynDnsCreate(): void
function dynDnsCreate(): void
{
$name = $this->arguments[1] ?? '';
if (empty($name)) {
@ -1337,7 +1308,7 @@ class CLIController
}
}
function handleDomainsCreate(): void
function domainsCreate(): void
{
// check if we're correctly setup
if (!$this->domainController->checkPermissions()) {
@ -1384,7 +1355,7 @@ class CLIController
/**
*/
function handleDomainsUpdate(): void
function domainsUpdate(): void
{
// check if we're correctly setup
if (!$this->domainController->checkPermissions()) {
@ -1427,7 +1398,7 @@ class CLIController
/**
*/
function handleDomainsDelete(): void
function domainsDelete(): void
{
if (empty($this->arguments[1])) {
echo "You need to supply an ID." . PHP_EOL;
@ -1448,47 +1419,11 @@ class CLIController
echo "The domain with ID $id has been deleted." . PHP_EOL;
}
/**
* @param string $subcommand
*
* @return void
*/
public
function handleDynDns(string $subcommand): void
{
match ($subcommand) {
'list' => $this->handleDynDnsList(),
'create' => $this->handleDynDnsCreate(),
'update' => $this->handleDynDnsUpdate(),
'delete' => $this->handleDynDnsDelete(),
'push' => $this->handleDynDnsPush(),
default => $this->unknownSubcommand(subcommand: $subcommand)
};
}
/**
* @param string $subcommand
*
* @return void
*/
public
function handleNameservers(string $subcommand): void
{
match ($subcommand) {
'create' => $this->handleNameserversCreate(),
'list' => $this->handleNameserversList(),
'update' => $this->handleNameserversUpdate(),
'delete' => $this->handleNameserversDelete(),
'apiping' => $this->handleAPIPing(type: 'nameserver'),
default => $this->unknownSubcommand(subcommand: $subcommand)
};
}
/**
* @return void
*/
function handleNameserversCreate(): void
function nameserversCreate(): void
{
$name = $this->arguments[1] ?? '';
if (empty($name)) {
@ -1533,7 +1468,7 @@ class CLIController
/**
* @return void
*/
function handleNameserversList(): void
function nameserversList(): void
{
$nameservers = $this->nameserverRepository->findAll();
if (!empty($nameservers)) {
@ -1561,7 +1496,7 @@ class CLIController
/**
*/
function handleNameserversUpdate(): void
function nameserversUpdate(): void
{
$id = $this->arguments[1] ?? 0;
$name = $this->arguments['name'] ?? '';
@ -1594,7 +1529,7 @@ class CLIController
/**
*/
function handleNameserversDelete(): void
function nameserversDelete(): void
{
if (empty($this->arguments[1])) {
echo "You need to supply an ID." . PHP_EOL;
@ -1617,7 +1552,7 @@ class CLIController
/**
*/
function handleCheckShowIncludes(): void
function checkShowIncludes(): void
{
$nameservers = $this->nameserverRepository->findAll();
@ -1655,7 +1590,7 @@ class CLIController
/**
*/
function handleCheckDomains(): void
function checkDomains(): void
{
$this->domainController->checkDomains();
}
@ -1663,8 +1598,7 @@ class CLIController
/**
*/
private
function handleDynDnsPush(): void
private function dynDnsPush(): void
{
$hostName = $this->arguments[1] ?? '';
@ -1686,13 +1620,15 @@ class CLIController
// which NS belongs to that panel
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $panel->getApikey(), key: $encryptionKey);
if (!empty($panel->getAaaa())) {
$result = $this->apiController->sendCommand(
requestType: 'POST',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $panel->getApikey(),
apiKey: $decryptedKey,
command: 'dyndns/' . $hostName,
serverType: 'nameserver');
} else {
@ -1700,7 +1636,7 @@ class CLIController
requestType: 'POST',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $panel->getApikey(),
apiKey: $decryptedKey(),
command: 'dyndns/' . $hostName,
serverType: 'nameserver');
}
@ -1721,7 +1657,8 @@ class CLIController
/**
*/
private function handleCheckGenerateKey(): void
private
function checkGenerateKey(): void
{
echo 'This generates a fresh encryption key.' . PHP_EOL;
echo 'Copy it to config.json.' . PHP_EOL;
@ -1739,24 +1676,24 @@ class CLIController
}
private function handleDomainsRefresh(): void
private function domainsRefresh(): void
{
$this->logger->debug(message: "domainsRefresh()");
// TODO check for self in check:permissions
$this->logger->debug(message: "handleDomainsRefresh()");
// TODO create getSelf()
$panels = $this->panelRepository->findAll();
foreach ($panels as $panel) {
echo COLOR_DEFAULT . 'Checking panel ' . COLOR_YELLOW . $panel->getName() . COLOR_DEFAULT . PHP_EOL;
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $panel->getApikey(), key: $encryptionKey);
if (empty($panel->getA())) {
$result = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $panel->getApikey(),
apiKey: $decryptedKey,
command: 'domains?sort=domain&subdomains=false',
serverType: 'panel'
);
@ -1765,7 +1702,7 @@ class CLIController
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $panel->getApikey(),
apiKey: $decryptedKey,
command: 'domains?sort=domain&subdomains=false',
serverType: 'panel');
}
@ -1801,4 +1738,112 @@ class CLIController
}
$this->domainController->updateSlaveZones();
}
public function webmailCheck(): void
{
$quiet = $this->configController->getConfig(configKey: 'quiet');
$verbose = $this->configController->getConfig(configKey: 'verbose');
if (empty($this->arguments[1])) {
if (!$quiet) {
echo COLOR_DEFAULT . 'You need to supply a domain name.' . PHP_EOL;
}
exit(1);
} else {
$domainName = $this->arguments[1];
}
if (!$quiet) {
echo COLOR_DEFAULT . 'Checking domain ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . PHP_EOL;
}
if (!$domain = $this->domainRepository->findByName(name: $domainName)) {
if (!$quiet) {
echo COLOR_DEFAULT . 'Domain ' . $domainName . ' not found on this server.' . PHP_EOL;
}
exit(1);
}
if (!$this->domainController->isMasterZone(domain: $domain)) {
if (!$quiet) {
echo 'This server is not responsible for ' . COLOR_YELLOW . $domainName . COLOR_DEFAULT . '.' . PHP_EOL;
}
exit(1);
}
$panel = $this->panelRepository->getSelf();
$encryptionKey = $this->configController->getConfig(configKey: 'encryptionKey');
$decryptedKey = $this->encryptionController->safeDecrypt(encrypted: $panel->getApikey(), key: $encryptionKey);
$webmailDomain = 'webmail.' . $domainName;
if (!empty($panel->getAAAA())) {
if ($verbose) {
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . COLOR_DEFAULT . PHP_EOL;
}
$result = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 6,
apiKey: $decryptedKey,
command: 'domains/name/' . $webmailDomain,
serverType: 'panel');
} else {
if ($verbose) {
echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL;
}
$result = $this->apiController->sendCommand(
requestType: 'GET',
serverName: $panel->getName(),
versionIP: 4,
apiKey: $decryptedKey,
command: 'domains/name/' . $webmailDomain,
serverType: 'panel' );
}
if ($result['header'] === 404) {
if (!$quiet) {
echo 'The domain ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . ' doesn\'t exist.' . PHP_EOL;
}
exit(1);
} else {
if(!$quiet) {
echo 'Found ' . COLOR_YELLOW . $webmailDomain . COLOR_DEFAULT . '.' . PHP_EOL;
}
}
$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')) {
if (!$quiet) {
echo 'Generated config is missing.' . PHP_EOL;
}
exit(1);
}
}
public function webmailCreate()
{
$webmailConfig = '# bindAPI - webmailer' . PHP_EOL;
$webmailConfig .= 'SSLProxyEngine On' . PHP_EOL;
$webmailConfig .= 'ProxyPass /.well-known/ !' . PHP_EOL;
$webmailConfig .= 'ProxyPass "/" "https://' . $panel->getName() . '/webmail/"' . PHP_EOL;
$webmailConfig .= '## bindAPI - webmailer' . PHP_EOL;
echo $webmailConfig;
//$httpsDirectives += $w
}
}