fix: harden mx helper and cleanup flow

This commit is contained in:
Marek Miklewicz
2026-06-30 11:37:27 +02:00
parent ed6146c0d8
commit ad95ecdacb
8 changed files with 252 additions and 43 deletions
+6
View File
@@ -7,6 +7,12 @@ return static function (): void {
}
$settings = Settings::load(Settings::EXTERNAL_SETTINGS);
if (!$settings->defaultEnable()) {
Http::errorPage('Plugin nie jest włączony dla tego serwera.', 403);
}
if ($settings->method() !== 'login_url') {
Http::errorPage('Metoda logowania nie jest obsługiwana.', 500);
}
$ctx = DirectAdminContext::fromServer($_SERVER, $settings);
SourceAuthorizer::assertAllowed($ctx->sourceHost(), $settings);
+16
View File
@@ -105,6 +105,16 @@ final class Settings
return rtrim($this->getString('MAIL_LOGIN_TARGET_BASE_URL'), '/');
}
public function defaultEnable(): bool
{
return in_array(strtolower($this->getString('DEFAULT_ENABLE', 'true')), ['1', 'true', 'yes', 'on'], true);
}
public function method(): string
{
return $this->getString('MAIL_LOGIN_METHOD', 'login_url');
}
public function redirectUrl(): string
{
return $this->getString('MAIL_LOGIN_REDIRECT_URL', '/');
@@ -229,6 +239,12 @@ final class Settings
if (!in_array($this->getString('USER_IP_BOUND', ''), ['0', '1'], true)) {
throw new InvalidArgumentException('USER_IP_BOUND must be 0 or 1');
}
if (!in_array(strtolower($this->getString('DEFAULT_ENABLE', 'true')), ['0', '1', 'true', 'false', 'yes', 'no', 'on', 'off'], true)) {
throw new InvalidArgumentException('DEFAULT_ENABLE must be a boolean value');
}
if ($this->method() !== 'login_url') {
throw new InvalidArgumentException('MAIL_LOGIN_METHOD must be login_url');
}
if (!in_array($this->clientIpMode(), ['direct', 'trusted_proxy'], true)) {
throw new InvalidArgumentException('MAIL_LOGIN_CLIENT_IP_MODE must be direct or trusted_proxy');
}