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

Method handleSSH

ssh/ssh.ts:309–442  ·  view source on GitHub ↗
(msg: Api.Message)

Source from the content-addressed store, hash-verified

307
308<b>管理命令:</b>
309• <code>${mainPrefix}ssh set @username</code> - 设置发送到指定用户
310• <code>${mainPrefix}ssh set me</code> - 重置为默认发送到收藏夹
311• <code>${mainPrefix}ssh info</code> - 查看SSH状态和配置
312
313<b>示例:</b>
314<code>${mainPrefix}ssh gen replace</code> - 生成新密钥并清空旧密钥
315<code>${mainPrefix}ssh keys export</code> - 导出所有密钥到文件`;
316
317class SSHPlugin extends Plugin {
318 cleanup(): void {
319 ConfigManager.cleanup();
320 }
321
322 async setup(): Promise<void> {
323 // Re-initialize ConfigManager after cleanup/reload
324 await ConfigManager.get(CONFIG_KEYS.TARGET_CHAT);
325 }
326
327 description: string = `SSH管理和服务器配置\n\n${help_text}`;
328
329 cmdHandlers = {
330 ssh: async (msg: Api.Message) => {
331 await this.handleSSH(msg);
332 }
333 };
334
335 // 主命令处理器
336 private async handleSSH(msg: Api.Message): Promise<void> {
337 const client = await getGlobalClient();
338 if (!client) {
339 await msg.edit({ text: "❌ 客户端未初始化", parseMode: "html" });
340 return;
341 }
342
343 // 检查执行权限 - 只能在收藏夹或指定会话执行
344 const isPrivate = msg.isPrivate;
345 const chatId = msg.chatId?.toString();
346 const userId = msg.senderId?.toString();
347 const targetChat = await ConfigManager.get(CONFIG_KEYS.TARGET_CHAT);
348
349 // 检查是否在允许的位置执行
350 let canExecute = false;
351
352 if (isPrivate && chatId === userId) {
353 // 收藏夹
354 canExecute = true;
355 } else if (targetChat !== "me" && chatId === targetChat) {
356 // 指定的目标会话
357 canExecute = true;
358 }
359
360 if (!canExecute) {
361 await msg.edit({
362 text: "🔒 <b>权限限制</b>\n\n此SSH管理插件只能在以下位置执行:\n• 收藏夹\n• 已设置的目标会话\n\n💡 当前目标: <code>" + htmlEscape(targetChat === "me" ? "收藏夹" : targetChat) + "</code>\n⚠️ 请在允许的位置使用此插件",
363 parseMode: "html"
364 });
365 return;
366 }

Callers 1

SSHPluginClass · 0.95

Calls 15

generateSSHKeysMethod · 0.95
clearAuthorizedKeysMethod · 0.95
exportAuthorizedKeysMethod · 0.95
listAuthorizedKeysMethod · 0.95
changePasswordMethod · 0.95
changeSSHPortMethod · 0.95
togglePasswordAuthMethod · 0.95
toggleKeyAuthMethod · 0.95
toggleRootLoginMethod · 0.95
enableRootAccountMethod · 0.95
openPortMethod · 0.95
closePortMethod · 0.95

Tested by

no test coverage detected