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

Method togglePasswordAuth

ssh/ssh.ts:1022–1063  ·  view source on GitHub ↗
(msg: Api.Message, mode: string)

Source from the content-addressed store, hash-verified

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

Callers 1

handleSSHMethod · 0.95

Calls 4

modifySSHConfigFunction · 0.85
restartSSHServiceFunction · 0.85
editMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected