feat: remove mx helper mode
This commit is contained in:
@@ -61,33 +61,19 @@ final class RemoteLoginUrlClient
|
||||
$settings->sshUser() . '@' . $settings->sshHost(),
|
||||
];
|
||||
|
||||
if ($settings->mxLoginMode() === 1) {
|
||||
$command = array_merge($base, [
|
||||
'/usr/bin/da',
|
||||
'login-url',
|
||||
'--user=' . $request->username,
|
||||
'--redirect-url=' . $request->redirectPath,
|
||||
]);
|
||||
if ($request->ttl > 0) {
|
||||
$command[] = '--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,
|
||||
$request->serverName,
|
||||
(string)$request->ttl,
|
||||
$request->userIpBound ? '1' : '0',
|
||||
$request->clientIp,
|
||||
$request->redirectPath,
|
||||
(string)$request->createdAt,
|
||||
$command = array_merge($base, [
|
||||
'/usr/bin/da',
|
||||
'login-url',
|
||||
'--user=' . $request->username,
|
||||
'--redirect-url=' . $request->redirectPath,
|
||||
]);
|
||||
if ($request->ttl > 0) {
|
||||
$command[] = '--expiry=' . $request->ttl . 's';
|
||||
}
|
||||
if ($request->userIpBound) {
|
||||
$command[] = '--ip=' . $request->clientIp;
|
||||
}
|
||||
return $command;
|
||||
}
|
||||
|
||||
public function create(Settings $settings, LoginUrlRequest $request): string
|
||||
@@ -101,7 +87,7 @@ final class RemoteLoginUrlClient
|
||||
throw new RuntimeException(self::failureMessage($settings, $result));
|
||||
}
|
||||
if (!preg_match('/https:\/\/\S+/', $result->stdout, $match)) {
|
||||
throw new RuntimeException('MX helper did not return a login URL');
|
||||
throw new RuntimeException('MX direct SSH command did not return a login URL');
|
||||
}
|
||||
try {
|
||||
return UrlValidator::assertGeneratedLoginUrl(trim($match[0]), $settings);
|
||||
@@ -112,8 +98,7 @@ final class RemoteLoginUrlClient
|
||||
|
||||
private static function failureMessage(Settings $settings, ProcessResult $result): string
|
||||
{
|
||||
$message = $settings->mxLoginMode() === 1 ? 'MX direct SSH command failed' : 'MX helper failed';
|
||||
$message .= ' (exit ' . $result->exitCode . ')';
|
||||
$message = 'MX direct SSH command failed (exit ' . $result->exitCode . ')';
|
||||
$detail = self::safeDiagnostic($result->stderr);
|
||||
if ($detail !== '') {
|
||||
$message .= ': ' . $detail;
|
||||
@@ -140,7 +125,7 @@ final class RemoteLoginUrlClient
|
||||
];
|
||||
$process = proc_open($command, $descriptors, $pipes);
|
||||
if (!is_resource($process)) {
|
||||
throw new RuntimeException('Cannot start MX helper');
|
||||
throw new RuntimeException('Cannot start MX direct SSH command');
|
||||
}
|
||||
fclose($pipes[0]);
|
||||
stream_set_blocking($pipes[1], false);
|
||||
@@ -161,7 +146,7 @@ final class RemoteLoginUrlClient
|
||||
fclose($pipe);
|
||||
}
|
||||
proc_close($process);
|
||||
throw new RuntimeException('MX helper timed out');
|
||||
throw new RuntimeException('MX direct SSH command timed out');
|
||||
}
|
||||
usleep(100000);
|
||||
} while (true);
|
||||
|
||||
@@ -58,7 +58,6 @@ 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' => '/',
|
||||
@@ -116,11 +115,6 @@ 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', '/');
|
||||
@@ -267,9 +261,6 @@ 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