(msg: Api.Message)
| 1416 | parseMode: "html" |
| 1417 | }); |
| 1418 | } catch (error: any) { |
| 1419 | throw new Error(`设置目标失败: ${error.message}`); |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | // 显示配置信息 |
| 1424 | private async showInfo(msg: Api.Message): Promise<void> { |
| 1425 | await msg.edit({ text: "🔄 正在获取SSH状态信息...", parseMode: "html" }); |
| 1426 | |
| 1427 | try { |
| 1428 | // 获取插件配置 |
| 1429 | const targetChat = await ConfigManager.get(CONFIG_KEYS.TARGET_CHAT); |
| 1430 | const sshPort = await ConfigManager.get(CONFIG_KEYS.SSH_PORT); |
| 1431 | const passwordAuth = await ConfigManager.get(CONFIG_KEYS.PASSWORD_AUTH); |
| 1432 | const pubkeyAuth = await ConfigManager.get(CONFIG_KEYS.PUBKEY_AUTH); |
| 1433 | |
| 1434 | // 获取当前SSH服务状态 |
| 1435 | const sshStatus = await isSshServiceActive() ? "✅ 运行中" : "❌ 未运行"; |
| 1436 | |
| 1437 | // 从sshd_config读取实际配置 |
| 1438 | let actualPasswordAuth = "未知"; |
| 1439 | let rootLogin = "未知"; |
| 1440 | let actualPubkeyAuth = "未知"; |
| 1441 | let actualPort = "未知"; |
| 1442 | |
| 1443 | try { |
| 1444 | const configContent = fs.readFileSync("/etc/ssh/sshd_config", "utf8"); |
| 1445 | |
| 1446 | // 检查密码认证 |
| 1447 | const passwordAuthMatch = configContent.match(/^\s*PasswordAuthentication\s+(yes|no)/mi); |
| 1448 | actualPasswordAuth = passwordAuthMatch ? |
| 1449 | (passwordAuthMatch[1].toLowerCase() === "yes" ? "✅ 已开启" : "❌ 已关闭") : "🟡 默认(通常开启)"; |
| 1450 | |
| 1451 | // 检查Root登录 |
| 1452 | const rootLoginMatch = configContent.match(/^\s*PermitRootLogin\s+(yes|no|prohibit-password|forced-commands-only)/mi); |
| 1453 | if (rootLoginMatch) { |
| 1454 | const value = rootLoginMatch[1].toLowerCase(); |
| 1455 | switch (value) { |
| 1456 | case "yes": |
| 1457 | rootLogin = "✅ 允许(全权限)"; |
| 1458 | break; |
| 1459 | case "no": |
| 1460 | rootLogin = "❌ 禁止"; |
| 1461 | break; |
| 1462 | case "prohibit-password": |
| 1463 | rootLogin = "🔑 仅密钥"; |
| 1464 | break; |
| 1465 | case "forced-commands-only": |
| 1466 | rootLogin = "⚠️ 仅命令"; |
| 1467 | break; |
| 1468 | } |
| 1469 | } else { |
| 1470 | rootLogin = "🟡 默认(通常允许)"; |
| 1471 | } |
| 1472 | |
| 1473 | // 检查密钥认证 |
| 1474 | const pubkeyAuthMatch = configContent.match(/^\s*PubkeyAuthentication\s+(yes|no)/mi); |
| 1475 | actualPubkeyAuth = pubkeyAuthMatch ? |
no test coverage detected