feat: add mx login mode selection
This commit is contained in:
@@ -44,7 +44,7 @@ final class RemoteLoginUrlClient
|
||||
*/
|
||||
public static function buildCommand(Settings $settings, LoginUrlRequest $request): array
|
||||
{
|
||||
return [
|
||||
$base = [
|
||||
'ssh',
|
||||
'-o',
|
||||
'BatchMode=yes',
|
||||
@@ -59,6 +59,23 @@ final class RemoteLoginUrlClient
|
||||
'-p',
|
||||
(string)$settings->sshPort(),
|
||||
$settings->sshUser() . '@' . $settings->sshHost(),
|
||||
];
|
||||
|
||||
if ($settings->mxLoginMode() === 1) {
|
||||
$command = array_merge($base, [
|
||||
'/usr/bin/da',
|
||||
'login-url',
|
||||
'--user=' . $request->username,
|
||||
'--redirect-url=' . $request->redirectPath,
|
||||
'--expiry=' . $request->ttl . 's',
|
||||
]);
|
||||
if ($request->userIpBound) {
|
||||
$command[] = '--ip=' . $request->clientIp;
|
||||
}
|
||||
return $command;
|
||||
}
|
||||
|
||||
return array_merge($base, [
|
||||
'mail-login-create-url',
|
||||
$request->username,
|
||||
$request->sourceHost,
|
||||
@@ -68,7 +85,7 @@ final class RemoteLoginUrlClient
|
||||
$request->clientIp,
|
||||
$request->redirectPath,
|
||||
(string)$request->createdAt,
|
||||
];
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(Settings $settings, LoginUrlRequest $request): string
|
||||
|
||||
@@ -58,6 +58,7 @@ final class Settings
|
||||
return [
|
||||
'DEFAULT_ENABLE' => 'true',
|
||||
'MAIL_LOGIN_METHOD' => 'login_url',
|
||||
'MX_LOGIN_MODE' => '1',
|
||||
'MAIL_LOGIN_TARGET_NAME' => 'mx1',
|
||||
'MAIL_LOGIN_TARGET_BASE_URL' => 'https://mx1.mojserwer.pl:2222',
|
||||
'MAIL_LOGIN_REDIRECT_URL' => '/',
|
||||
@@ -115,6 +116,11 @@ final class Settings
|
||||
return $this->getString('MAIL_LOGIN_METHOD', 'login_url');
|
||||
}
|
||||
|
||||
public function mxLoginMode(): int
|
||||
{
|
||||
return (int)$this->getString('MX_LOGIN_MODE', '1');
|
||||
}
|
||||
|
||||
public function redirectUrl(): string
|
||||
{
|
||||
return $this->getString('MAIL_LOGIN_REDIRECT_URL', '/');
|
||||
@@ -275,6 +281,9 @@ final class Settings
|
||||
if ($this->method() !== 'login_url') {
|
||||
throw new InvalidArgumentException('MAIL_LOGIN_METHOD must be login_url');
|
||||
}
|
||||
if (!in_array($this->getString('MX_LOGIN_MODE', '1'), ['1', '2'], true)) {
|
||||
throw new InvalidArgumentException('MX_LOGIN_MODE must be 1 or 2');
|
||||
}
|
||||
if (!in_array($this->clientIpMode(), ['direct', 'trusted_proxy'], true)) {
|
||||
throw new InvalidArgumentException('MAIL_LOGIN_CLIENT_IP_MODE must be direct or trusted_proxy');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user