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

Method configureProxy

warp/warp.ts:558–619  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

556 return `❌ WireProxy 未运行。请先使用 <code>${htmlEscape(mainPrefix)}warp w</code> 启动 WireProxy。`;
557 }
558
559 // 获取当前端口
560 const socksCheck = await SystemExecutor.run("ss -tlnp | grep -i wireproxy | head -1");
561 const portMatch = socksCheck.success ? socksCheck.output.match(/:(\d+)\b/) : null;
562 const port = portMatch ? parseInt(portMatch[1], 10) : 40000;
563
564 // 获取程序目录并构建配置文件路径
565 const pwdResult = await SystemExecutor.run("pwd");
566 if (!pwdResult.success) {
567 return "❌ 无法获取当前工作目录。";
568 }
569
570 const programDir = pwdResult.output.trim();
571 const configPath = `${programDir}/config.json`;
572
573 // 检查配置文件是否存在
574 const configCheck = await SystemExecutor.run(`test -f ${configPath}`);
575 if (!configCheck.success) {
576 return `❌ 找不到配置文件: ${htmlEscape(configPath)}`;
577 }
578
579 // 读取配置文件
580 const readResult = await SystemExecutor.run(`cat ${configPath}`);
581 if (!readResult.success) {
582 return "❌ 无法读取 config.json 文件。";
583 }
584
585 let config;
586 try {
587 config = JSON.parse(readResult.output);
588 } catch {
589 return "❌ config.json 文件格式错误。";
590 }
591
592 // 设置代理配置
593 config.proxy = {
594 ip: "127.0.0.1",
595 port: port,
596 socksType: 5
597 };
598
599 // 写回配置文件
600 const configJson = JSON.stringify(config, null, 2);
601 const writeCmd = `cat > ${configPath} << 'EOF'\n${configJson}\nEOF`;
602 const writeResult = await SystemExecutor.runSudo(writeCmd);
603
604 if (!writeResult.success) {
605 return "❌ 无法写入配置文件。";
606 }
607
608 return `✅ 代理配置已更新\n\n📋 <b>配置详情</b>\n- 代理类型: SOCKS5\n- 地址: 127.0.0.1\n- 端口: ${port}\n\n⚠️ <b>注意</b>: 需要重启 TeleBox 生效`;
609 } catch (e: any) {
610 return `❌ 配置代理失败: ${htmlEscape(e?.message || e)}`;
611 }
612 }
613
614 // 关闭代理设置
615 private async removeProxy(): Promise<string> {

Callers 1

handleWarpMethod · 0.95

Calls 3

runMethod · 0.80
runSudoMethod · 0.80
htmlEscapeFunction · 0.70

Tested by

no test coverage detected