improves checkWebmail

This commit is contained in:
tracer 2022-10-08 10:54:55 +02:00
parent 2e1f1ac8b1
commit 91ea53275e
1 changed files with 90 additions and 15 deletions

View File

@ -1745,7 +1745,7 @@ class CLIController
$quiet = $this->configController->getConfig(configKey: 'quiet');
$verbose = $this->configController->getConfig(configKey: 'verbose');
if (empty($this->arguments[1])) {
if (empty($this->arguments[1])) {
if (!$quiet) {
echo COLOR_DEFAULT . 'You need to supply a domain name.' . PHP_EOL;
}
@ -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 ($verbose) {
echo 'Check using IPv6: ' . COLOR_YELLOW . $panel->getAaaa() . COLOR_DEFAULT . PHP_EOL;
if (!$quiet && $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 ($verbose) {
if (!$quiet && $verbose) {
echo 'Check using IPv4: ' . COLOR_YELLOW . $panel->getA() . COLOR_DEFAULT . PHP_EOL;
}
$result = $this->apiController->sendCommand(
@ -1800,24 +1800,70 @@ 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')) {
@ -1825,25 +1871,54 @@ class CLIController
echo 'Generated config is missing.' . PHP_EOL;
}
exit(1);
} else {
if (!$quiet) {
echo 'Generated config is valid.' . PHP_EOL;
}
exit(0);
}
}
public function webmailCreate()
/**
* @return void
*/
public function webmailCreate(): bool
{
// TODO
/*
$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 .= 'ProxyPass "/" "https://webmail' . $panel->getName() . '"' . 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
{
}
}