MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / changeSSHPort

Method changeSSHPort

ssh/ssh.ts:940–1019  ·  view source on GitHub ↗
(msg: Api.Message, portStr: string)

Source from the content-addressed store, hash-verified

938 text: `❌ <b>请提供新密码</b>\n\n示例: <code>${mainPrefix}ssh passwd 新密码123</code>`,
939 parseMode: "html"
940 });
941 return;
942 }
943
944 // 验证密码复杂度
945 if (!validatePassword(newPassword)) {
946 await msg.edit({
947 text: `❌ <b>密码不符合要求</b>\n\n密码长度至少8位`,
948 parseMode: "html"
949 });
950 return;
951 }
952
953 await msg.edit({ text: "🔄 正在修改root密码...", parseMode: "html" });
954
955 try {
956 await runWithInput("chpasswd", [], `root:${newPassword}\n`);
957
958 // 不显示明文密码
959 await msg.edit({
960 text: `✅ <b>root密码修改成功</b>\n\n⚠️ 请妥善保管新密码`,
961 parseMode: "html"
962 });
963 } catch (error: any) {
964 throw new Error(`修改密码失败: ${error.message}`);
965 }
966 }
967
968 // 修改SSH端口
969 private async changeSSHPort(msg: Api.Message, portStr: string): Promise<void> {
970 const port = validatePort(portStr);
971
972 if (!port) {
973 await msg.edit({
974 text: `❌ <b>无效的端口号</b>\n\n端口范围: 1-65535\n示例: <code>${mainPrefix}ssh port 2222</code>`,
975 parseMode: "html"
976 });
977 return;
978 }
979
980 await msg.edit({ text: `🔄 正在检查端口 ${port} 是否可用...`, parseMode: "html" });
981
982 try {
983 // 获取当前SSH端口,用于后续关闭旧端口防火墙
984 const currentPort = await ConfigManager.get(CONFIG_KEYS.SSH_PORT, "22");
985
986 // 检查端口冲突(跳过当前SSH端口检查)
987 if (String(port) !== currentPort) {
988 const portCheck = await checkPortInUse(port);
989 if (portCheck.inUse) {
990 await msg.edit({
991 text: `❌ <b>端口冲突检测失败</b>\n\n端口 <code>${port}</code> 已被占用\n进程信息: <code>${htmlEscape(portCheck.processInfo || '未知')}</code>\n\n💡 <b>建议:</b>\n• 选择其他端口号\n• 停止占用该端口的服务\n• 使用 <code>netstat -tlnp | grep :${port}</code> 查看详情`,
992 parseMode: "html"
993 });
994 return;
995 }
996 }
997

Callers 1

handleSSHMethod · 0.95

Calls 9

validatePortFunction · 0.85
checkPortInUseFunction · 0.85
modifySSHConfigFunction · 0.85
restartSSHServiceFunction · 0.85
warnMethod · 0.80
htmlEscapeFunction · 0.70
editMethod · 0.45
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected