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

Method openPort

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

Source from the content-addressed store, hash-verified

1291 if (!restartResult.success) {
1292 throw new Error("无法重启SSH服务,请检查系统类型");
1293 }
1294
1295 // 验证SSH服务状态
1296 const sshStatus = await isSshServiceActive() ? "✅ 运行中" : "❌ 未运行";
1297
1298 await msg.edit({
1299 text: `✅ <b>SSH服务重启成功</b>\n\n重启命令: <code>${htmlEscape(restartResult.command || "未知")}</code>\n服务状态: ${sshStatus}\n\n💡 建议重启后验证SSH连接`,
1300 parseMode: "html"
1301 });
1302 } catch (error: any) {
1303 throw new Error(`重启SSH服务失败: ${error.message}`);
1304 }
1305 }
1306
1307 // 开放防火墙端口
1308 private async openPort(msg: Api.Message, portStr: string): Promise<void> {
1309 const port = validatePort(portStr);
1310
1311 if (!port) {
1312 await msg.edit({
1313 text: `❌ <b>无效的端口号</b>\n\n端口范围: 1-65535\n示例: <code>${mainPrefix}ssh open 80</code>`,
1314 parseMode: "html"
1315 });
1316 return;
1317 }
1318
1319 await msg.edit({ text: `🔄 正在开放端口 ${port}...`, parseMode: "html" });
1320
1321 try {
1322 // 使用iptables开放端口
1323 await execFileAsync("iptables", ["-I", "INPUT", "-p", "tcp", "--dport", String(port), "-j", "ACCEPT"]);
1324 await execFileAsync("iptables", ["-I", "INPUT", "-p", "udp", "--dport", String(port), "-j", "ACCEPT"]);
1325
1326 // 尝试保存iptables规则
1327 try {
1328 await saveIptablesRules();
1329 } catch {
1330 console.log("[sshkey] 无法持久化iptables规则");
1331 }
1332
1333 await msg.edit({

Callers 1

handleSSHMethod · 0.95

Calls 2

validatePortFunction · 0.85
editMethod · 0.45

Tested by

no test coverage detected