feat: implement mail-login directadmin plugin
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
final class DirectAdminContext
|
||||
{
|
||||
private function __construct(
|
||||
private string $username,
|
||||
private string $sourceHost,
|
||||
private string $serverName,
|
||||
private string $method
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $server
|
||||
*/
|
||||
public static function fromServer(array $server, Settings $settings): self
|
||||
{
|
||||
$username = trim((string)($server['USERNAME'] ?? $server['USER'] ?? ''));
|
||||
if (!preg_match('/^[A-Za-z0-9][A-Za-z0-9._-]{0,31}$/', $username)) {
|
||||
throw new InvalidArgumentException('Invalid DirectAdmin username');
|
||||
}
|
||||
$host = Settings::normalizeHost((string)($server['HTTP_HOST'] ?? $server['SERVER_NAME'] ?? ''));
|
||||
if ($host === '') {
|
||||
throw new InvalidArgumentException('Missing source host');
|
||||
}
|
||||
$serverName = $settings->sourceServerName();
|
||||
if ($serverName === '') {
|
||||
$serverName = $settings->sanitizeServerName(explode('.', $host)[0] ?? '');
|
||||
}
|
||||
if ($serverName === '') {
|
||||
throw new InvalidArgumentException('Invalid source server name');
|
||||
}
|
||||
return new self($username, $host, $serverName, strtoupper((string)($server['REQUEST_METHOD'] ?? 'GET')));
|
||||
}
|
||||
|
||||
public function username(): string
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
public function sourceHost(): string
|
||||
{
|
||||
return $this->sourceHost;
|
||||
}
|
||||
|
||||
public function serverName(): string
|
||||
{
|
||||
return $this->serverName;
|
||||
}
|
||||
|
||||
public function method(): string
|
||||
{
|
||||
return $this->method;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user