Skip to content

Commit c0da311

Browse files
committed
Remove Clash support, only use Mihomo
1 parent 2e4bb88 commit c0da311

4 files changed

Lines changed: 23 additions & 28 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
- 教师端通常无需管理员权限(但需放行监听端口入站)。
3131
- 学生端执行改名 / 改 IP / 网络限制时必须管理员权限。
3232
- 可选组件(仅学生端网络限制需要):
33-
- `mihomo.exe``clash.exe`,推荐用 `mihomo.exe` 命名
33+
- `mihomo.exe`必须与 [mihomo](https://github.com/MetaCubeX/mihomo) 发行版一致
3434

3535
---
3636

3737
## 项目结构
3838

3939
- `teacher/`:教师端入口、UI、TCP 服务。
4040
- `agent/`:学生端入口、机器标识、改名、网络控制逻辑。
41-
- `common/`:通信协议、配置路径、Clash 配置构建
41+
- `common/`:通信协议、配置路径、mihomo 规则 YAML 构建
4242
- `configs/`:示例配置(`teacher.json``agent.json`)。
4343
- `package/`:PyInstaller 构建脚本与 `.spec`
4444

@@ -131,8 +131,8 @@ python -m agent.main --config configs\agent.json
131131
- `disable`:解除限制并删除本地覆盖配置。
132132
- 二进制查找顺序(学生端):
133133
- 项目根目录 `mihomo.exe`(开发运行)
134-
- 程序同目录 `mihomo.exe` / `clash.exe`(打包运行)
135-
- 系统 `PATH` `mihomo` / `clash`
134+
- 程序同目录 `mihomo.exe`(打包运行)
135+
- 系统 `PATH` 中的 `mihomo`
136136
- 需要管理员权限,否则会返回“需要管理员权限”。
137137

138138
---

agent/firewall_manager.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Clash-based network access restriction for student agents."""
1+
"""Mihomo-based network access restriction for student agents."""
22

33
from __future__ import annotations
44

@@ -39,20 +39,15 @@ def _get_clash_binary_path() -> Tuple[bool, str]:
3939
project_root = os.path.dirname(script_dir)
4040
exe_dir = os.path.dirname(os.path.abspath(sys.executable)) if getattr(sys, "frozen", False) else script_dir
4141

42-
clash_path = os.path.join(project_root, "mihomo.exe")
43-
if os.path.isfile(clash_path):
44-
return True, clash_path
45-
clash_path = os.path.join(exe_dir, "mihomo.exe")
46-
if os.path.isfile(clash_path):
47-
return True, clash_path
48-
clash_path = os.path.join(exe_dir, "clash.exe")
49-
if os.path.isfile(clash_path):
50-
return True, clash_path
42+
mihomo_path = os.path.join(project_root, "mihomo.exe")
43+
if os.path.isfile(mihomo_path):
44+
return True, mihomo_path
45+
mihomo_path = os.path.join(exe_dir, "mihomo.exe")
46+
if os.path.isfile(mihomo_path):
47+
return True, mihomo_path
5148
if shutil.which("mihomo"):
5249
return True, "mihomo"
53-
if shutil.which("clash"):
54-
return True, "clash"
55-
return False, "Clash binary not found"
50+
return False, "mihomo 可执行文件未找到"
5651

5752

5853
def _ensure_config_dir() -> None:
@@ -248,10 +243,10 @@ def _start_clash_process(clash_path: str) -> Tuple[bool, str]:
248243
)
249244
time.sleep(1.5)
250245
if _clash_process.poll() is not None:
251-
return False, "Clash process exited immediately"
252-
return True, "Clash started"
246+
return False, "mihomo 进程立即退出"
247+
return True, "mihomo 已启动"
253248
except Exception as e:
254-
return False, f"Failed to start Clash: {e}"
249+
return False, f"启动 mihomo 失败: {e}"
255250

256251

257252
def _is_clash_running() -> bool:
@@ -278,7 +273,7 @@ def apply_blacklist(rules: List[Dict[str, str]]) -> Tuple[bool, str]:
278273

279274
ok, msg = _start_clash_process(clash_path)
280275
if not ok:
281-
return False, f"启动 Clash 失败: {msg}"
276+
return False, f"启动 mihomo 失败: {msg}"
282277

283278
return True, f"已添加 {len(rules)} 条黑名单规则"
284279

@@ -298,7 +293,7 @@ def apply_whitelist(rules: List[Dict[str, str]]) -> Tuple[bool, str]:
298293

299294
ok, msg = _start_clash_process(clash_path)
300295
if not ok:
301-
return False, f"启动 Clash 失败: {msg}"
296+
return False, f"启动 mihomo 失败: {msg}"
302297

303298
return True, f"已启用白名单模式,允许 {len(rules)} 个目标"
304299

@@ -318,7 +313,7 @@ def block_all_network() -> Tuple[bool, str]:
318313

319314
ok, msg = _start_clash_process(clash_path)
320315
if not ok:
321-
return False, f"启动 Clash 失败: {msg}"
316+
return False, f"启动 mihomo 失败: {msg}"
322317

323318
return True, "已启用完全断网模式"
324319

@@ -346,13 +341,13 @@ def start_clash_if_config_exists() -> Tuple[bool, str]:
346341
return False, clash_path
347342

348343
if _is_clash_running():
349-
return True, "Clash 已在运行"
344+
return True, "mihomo 已在运行"
350345

351346
ok, msg = _start_clash_process(clash_path)
352347
if not ok:
353-
return False, f"启动 Clash 失败: {msg}"
348+
return False, f"启动 mihomo 失败: {msg}"
354349

355-
return True, "Clash 已启动"
350+
return True, "mihomo 已启动"
356351

357352

358353
def get_current_restriction_status() -> Dict[str, Any]:

common/clash_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Clash config builder - shared between teacher and agent."""
1+
"""Mihomo-compatible rule YAML builder - shared between teacher and agent."""
22

33
from __future__ import annotations
44

teacher/ui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def _dlg_network_restrict(self) -> None:
727727
"DOMAIN": "匹配完整域名。",
728728
"DOMAIN-SUFFIX": "匹配域名后缀,如 google.com 可匹配 www.google.com。",
729729
"DOMAIN-KEYWORD": "匹配域名关键字。",
730-
"DOMAIN-WILDCARD": "域名通配符匹配,仅支持 * 和 ?(与 Clash 其他通配符语法不同)。",
730+
"DOMAIN-WILDCARD": "域名通配符匹配,仅支持 * 和 ?(与 Clash 规则里其它通配符写法不同)。",
731731
"DOMAIN-REGEX": "域名正则表达式匹配。",
732732
"GEOSITE": "匹配 Geosite 内域名分组。",
733733
"IP-CIDR": "匹配目标 IP 地址范围(CIDR)。",

0 commit comments

Comments
 (0)