(msg: Api.Message, mode: string)
| 1020 | await msg.edit({ text: `🔄 防火墙已配置,正在重启SSH服务...`, parseMode: "html" }); |
| 1021 | |
| 1022 | // 重启SSH服务使配置生效 |
| 1023 | const restartResult = await restartSSHService(); |
| 1024 | if (!restartResult.success) { |
| 1025 | throw new Error("无法重启SSH服务"); |
| 1026 | } |
| 1027 | |
| 1028 | // 保存配置到插件数据库 |
| 1029 | await ConfigManager.set(CONFIG_KEYS.SSH_PORT, String(port)); |
| 1030 | |
| 1031 | // 提供关闭旧端口的提示 |
| 1032 | let oldPortWarning = ""; |
| 1033 | if (currentPort !== "22" && currentPort !== String(port)) { |
| 1034 | oldPortWarning = `\n\n💡 <b>提示:</b> 旧端口 ${htmlEscape(currentPort)} 的防火墙规则仍然开放\n如需关闭请执行: <code>${mainPrefix}ssh close ${htmlEscape(currentPort)}</code>`; |
| 1035 | } |
| 1036 | |
| 1037 | await msg.edit({ |
| 1038 | text: `✅ <b>SSH端口修改成功</b>\n\n🔧 新端口: <code>${port}</code>\n🛡️ 防火墙: 已自动开放 TCP/UDP ${port}\n📄 备份文件: /etc/ssh/sshd_config.backup.${htmlEscape(timestamp)}${oldPortWarning}\n\n⚠️ <b>重要:</b> 请用新端口测试连接后再断开当前会话`, |
| 1039 | parseMode: "html" |
| 1040 | }); |
| 1041 | } catch (error: any) { |
| 1042 | throw new Error(`修改SSH端口失败: ${error.message}`); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | // 开关密码登录 |
| 1047 | private async togglePasswordAuth(msg: Api.Message, mode: string): Promise<void> { |
| 1048 | const enable = mode === "on" || mode === "enable" || mode === "yes"; |
| 1049 | const disable = mode === "off" || mode === "disable" || mode === "no"; |
| 1050 | |
| 1051 | if (!enable && !disable) { |
| 1052 | await msg.edit({ |
| 1053 | text: `❌ <b>无效的参数</b>\n\n使用: <code>${mainPrefix}ssh pwauth on/off</code>`, |
| 1054 | parseMode: "html" |
| 1055 | }); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | const action = enable ? "开启" : "关闭"; |
| 1060 | await msg.edit({ text: `🔄 正在${action}密码登录...`, parseMode: "html" }); |
| 1061 | |
| 1062 | try { |
| 1063 | const authValue = enable ? "yes" : "no"; |
| 1064 | |
| 1065 | // 使用通用函数修改SSH配置 |
| 1066 | const timestamp = await modifySSHConfig("PasswordAuthentication", authValue); |
no test coverage detected