From c94063d45940e2026e27b68369ba98fbec1cd7a0 Mon Sep 17 00:00:00 2001 From: hstyi Date: Tue, 29 Jul 2025 17:45:59 +0800 Subject: [PATCH] fix: SSH timeout is always 30 seconds --- .../termora/plugin/internal/BasicTerminalOption.kt | 11 ++++++++--- .../termora/plugin/internal/ssh/SSHHostOptionsPane.kt | 6 ++++++ .../app/termora/plugin/internal/ssh/SshClients.kt | 4 +++- src/main/resources/i18n/messages.properties | 1 + src/main/resources/i18n/messages_ru_RU.properties | 1 + src/main/resources/i18n/messages_zh_CN.properties | 1 + src/main/resources/i18n/messages_zh_TW.properties | 1 + 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/app/termora/plugin/internal/BasicTerminalOption.kt b/src/main/kotlin/app/termora/plugin/internal/BasicTerminalOption.kt index 26e3453..23bdfe5 100644 --- a/src/main/kotlin/app/termora/plugin/internal/BasicTerminalOption.kt +++ b/src/main/kotlin/app/termora/plugin/internal/BasicTerminalOption.kt @@ -23,6 +23,7 @@ open class BasicTerminalOption() : JPanel(BorderLayout()), Option { var showCharsetComboBox: Boolean = false var showStartupCommandTextField: Boolean = false var showHeartbeatIntervalTextField: Boolean = false + var showTimeoutTextField: Boolean = false var showEnvironmentTextArea: Boolean = false var showLoginScripts: Boolean = false var showBackspaceComboBox: Boolean = false @@ -34,6 +35,7 @@ open class BasicTerminalOption() : JPanel(BorderLayout()), Option { val charsetComboBox = JComboBox() val startupCommandTextField = OutlineTextField() val heartbeatIntervalTextField = IntSpinner(60, minimum = 3, maximum = Int.MAX_VALUE) + val timeoutTextField = IntSpinner(60, minimum = 10, maximum = Int.MAX_VALUE) val environmentTextArea = FixedLengthTextArea(2048) val loginScripts = mutableListOf() val backspaceComboBox = JComboBox() @@ -173,7 +175,7 @@ open class BasicTerminalOption() : JPanel(BorderLayout()), Option { private fun getCenterComponent(): JComponent { val layout = FormLayout( "left:pref, $FORM_MARGIN, default:grow", - "pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref" + "pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref, $FORM_MARGIN, pref" ) val accountOwner = this.accountOwner @@ -210,6 +212,11 @@ open class BasicTerminalOption() : JPanel(BorderLayout()), Option { .add(characterAtATimeTextField).xy(3, rows).apply { rows += step } } + if (showTimeoutTextField) { + builder.add("${I18n.getString("termora.new-host.terminal.timeout")}:").xy(1, rows) + .add(timeoutTextField).xy(3, rows).apply { rows += step } + } + if (showHeartbeatIntervalTextField) { builder.add("${I18n.getString("termora.new-host.terminal.heartbeat-interval")}:").xy(1, rows) .add(heartbeatIntervalTextField).xy(3, rows).apply { rows += step } @@ -220,14 +227,12 @@ open class BasicTerminalOption() : JPanel(BorderLayout()), Option { .add(startupCommandTextField).xy(3, rows).apply { rows += step } } - if (showEnvironmentTextArea) { builder.add("${I18n.getString("termora.new-host.terminal.env")}:").xy(1, rows) .add(JScrollPane(environmentTextArea).apply { border = FlatTextBorder() }).xy(3, rows) .apply { rows += step } } - return builder.build() } diff --git a/src/main/kotlin/app/termora/plugin/internal/ssh/SSHHostOptionsPane.kt b/src/main/kotlin/app/termora/plugin/internal/ssh/SSHHostOptionsPane.kt index 2d3e476..aa04582 100644 --- a/src/main/kotlin/app/termora/plugin/internal/ssh/SSHHostOptionsPane.kt +++ b/src/main/kotlin/app/termora/plugin/internal/ssh/SSHHostOptionsPane.kt @@ -38,6 +38,7 @@ internal class SSHHostOptionsPane(private val accountOwner: AccountOwner) : Opti showEnvironmentTextArea = true showStartupCommandTextField = true showHeartbeatIntervalTextField = true + showTimeoutTextField = true showHighlightSet = true accountOwner = this@SSHHostOptionsPane.accountOwner init() @@ -113,6 +114,7 @@ internal class SSHHostOptionsPane(private val accountOwner: AccountOwner) : Opti ?: AltKeyModifier.EightBit.name), "keywordHighlightSetId" to ((terminalOption.highlightSetComboBox.selectedItem as? KeywordHighlight)?.id ?: "-1"), + "timeout" to (terminalOption.timeoutTextField.value ?: 60).toString() ) ) @@ -163,6 +165,10 @@ internal class SSHHostOptionsPane(private val accountOwner: AccountOwner) : Opti .getOrNull() ?: AltKeyModifier.EightBit + val timeout = host.options.extras["timeout"] ?: "60" + terminalOption.timeoutTextField.value = timeout.toIntOrNull() ?: 60 + + val keywordHighlightSetId = host.options.extras["keywordHighlightSetId"] for (i in 0 until terminalOption.highlightSetComboBox.itemCount) { val item = terminalOption.highlightSetComboBox.getItemAt(i) diff --git a/src/main/kotlin/app/termora/plugin/internal/ssh/SshClients.kt b/src/main/kotlin/app/termora/plugin/internal/ssh/SshClients.kt index 1f7c5e6..1cab829 100644 --- a/src/main/kotlin/app/termora/plugin/internal/ssh/SshClients.kt +++ b/src/main/kotlin/app/termora/plugin/internal/ssh/SshClients.kt @@ -88,7 +88,6 @@ object SshClients { val HOST_KEY = AttributeRepository.AttributeKey() - private val timeout = Duration.ofSeconds(30) private val hostManager get() = HostManager.Companion.getInstance() private val log by lazy { LoggerFactory.getLogger(SshClients::class.java) } @@ -101,6 +100,7 @@ object SshClients { session: ClientSession, ): ChannelShell { + val timeout = Duration.ofSeconds(host.options.extras["timeout"]?.toLongOrNull() ?: 60) val configuration = PtyChannelConfiguration() configuration.ptyColumns = size.cols @@ -136,6 +136,7 @@ object SshClients { command: String ): Pair { + val timeout = Duration.ofSeconds(60) val baos = ByteArrayOutputStream() val channel = session.createExecChannel(command) channel.out = baos @@ -248,6 +249,7 @@ object SshClients { } } + val timeout = Duration.ofSeconds(host.options.extras["timeout"]?.toLongOrNull() ?: 60) val session = client.connect(entry).verify(timeout).session if (host.authentication.type == AuthenticationType.Password) { if (StringUtils.isNotBlank(host.authentication.password)) diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index a5bff40..18037ed 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -183,6 +183,7 @@ termora.new-host.terminal.encoding=Encoding termora.new-host.terminal.backspace=Backspace termora.new-host.terminal.character-mode=Character-at-a-time termora.new-host.terminal.heartbeat-interval=Heartbeat Interval +termora.new-host.terminal.timeout=Timeout termora.new-host.terminal.startup-commands=Startup Command termora.new-host.terminal.alt-modifier=Alt modifier termora.new-host.terminal.alt-modifier.eight-bit=8-bit characters diff --git a/src/main/resources/i18n/messages_ru_RU.properties b/src/main/resources/i18n/messages_ru_RU.properties index 1de9451..ad07054 100644 --- a/src/main/resources/i18n/messages_ru_RU.properties +++ b/src/main/resources/i18n/messages_ru_RU.properties @@ -163,6 +163,7 @@ termora.new-host.proxy=Прокси termora.new-host.terminal=${termora.settings.terminal} termora.new-host.terminal.encoding=Кодировка termora.new-host.terminal.heartbeat-interval=Интервал опроса +termora.new-host.terminal.timeout=Тайм-аут termora.new-host.terminal.startup-commands=Команда запуска termora.new-host.terminal.env=переменные diff --git a/src/main/resources/i18n/messages_zh_CN.properties b/src/main/resources/i18n/messages_zh_CN.properties index edcf845..65e78cd 100644 --- a/src/main/resources/i18n/messages_zh_CN.properties +++ b/src/main/resources/i18n/messages_zh_CN.properties @@ -176,6 +176,7 @@ termora.new-host.terminal.encoding=编码 termora.new-host.terminal.backspace=退格键 termora.new-host.terminal.character-mode=单字符模式 termora.new-host.terminal.heartbeat-interval=心跳间隔 +termora.new-host.terminal.timeout=超时时间 termora.new-host.terminal.startup-commands=启动命令 termora.new-host.terminal.alt-modifier=Alt 键修饰 termora.new-host.terminal.alt-modifier.eight-bit=8 位字符 diff --git a/src/main/resources/i18n/messages_zh_TW.properties b/src/main/resources/i18n/messages_zh_TW.properties index 4f3113d..0edd9ab 100644 --- a/src/main/resources/i18n/messages_zh_TW.properties +++ b/src/main/resources/i18n/messages_zh_TW.properties @@ -179,6 +179,7 @@ termora.new-host.terminal.alt-modifier=Alt 鍵修飾 termora.new-host.terminal.alt-modifier.eight-bit=8 位元字符 termora.new-host.terminal.alt-modifier.by-esc=ESC 鍵作為前綴 termora.new-host.terminal.heartbeat-interval=心跳間隔 +termora.new-host.terminal.timeout=超時時間 termora.new-host.terminal.env=環境 termora.new-host.terminal.login-scripts=登入腳本 termora.new-host.terminal.expect=預期