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

Method uninstall

warp/warp.ts:406–468  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

404 await SystemExecutor.runSudo("systemctl stop dnsmasq 2>/dev/null || true");
405 await SystemExecutor.runSudo("wg-quick down warp 2>/dev/null || true");
406
407 // 第二步:禁用服务(忽略错误)
408 await SystemExecutor.runSudo("systemctl disable wireproxy 2>/dev/null || true");
409 await SystemExecutor.runSudo("systemctl disable dnsmasq 2>/dev/null || true");
410 await SystemExecutor.runSudo("systemctl disable wg-quick@warp 2>/dev/null || true");
411
412 // 第三步:强制终止进程(等待一秒让进程完全退出)
413 await SystemExecutor.runSudo("pkill -9 wireproxy 2>/dev/null || true");
414 await SystemExecutor.runSudo("pkill -9 dnsmasq 2>/dev/null || true");
415 await SystemExecutor.runSudo("pkill -9 -f 'wg-quick' 2>/dev/null || true");
416 await new Promise(resolve => setTimeout(resolve, 1000));
417
418 // 第四步:清理网络配置
419 await SystemExecutor.runSudo("chattr -i /etc/resolv.conf 2>/dev/null || true");
420 await SystemExecutor.runSudo("[ -f /etc/resolv.conf.bak ] && mv /etc/resolv.conf.bak /etc/resolv.conf 2>/dev/null || true");
421 await SystemExecutor.runSudo("iptables -F 2>/dev/null || true");
422 await SystemExecutor.runSudo("iptables -X 2>/dev/null || true");
423 await SystemExecutor.runSudo("ipset flush warp 2>/dev/null || true");
424 await SystemExecutor.runSudo("ipset destroy warp 2>/dev/null || true");
425
426 // 第五步:删除服务文件
427 await SystemExecutor.runSudo("rm -f /etc/systemd/system/wireproxy.service 2>/dev/null || true");
428 await SystemExecutor.runSudo("rm -f /lib/systemd/system/wireproxy.service 2>/dev/null || true");
429 await SystemExecutor.runSudo("rm -f /etc/systemd/system/dnsmasq.service 2>/dev/null || true");
430 await SystemExecutor.runSudo("systemctl daemon-reload 2>/dev/null || true");
431
432 // 第六步:删除二进制文件和配置目录
433 await SystemExecutor.runSudo("rm -f /usr/bin/wireproxy 2>/dev/null || true");
434 await SystemExecutor.runSudo("rm -rf /etc/wireguard 2>/dev/null || true");
435
436 // 第七步:尝试卸载软件包(忽略所有错误)
437 await SystemExecutor.runSudo("apt-get remove -y --purge dnsmasq ipset wireguard-tools 2>/dev/null || yum remove -y dnsmasq ipset wireguard-tools 2>/dev/null || true");
438 await SystemExecutor.runSudo("apt-get autoremove -y 2>/dev/null || true");
439
440 // 等待文件系统同步
441 await new Promise(resolve => setTimeout(resolve, 500));
442
443 // 最终校验(更宽松的检查)
444 const [wpSvc, dnsSvc, wgDir, wpBin] = await Promise.all([
445 SystemExecutor.run("systemctl is-active wireproxy 2>/dev/null"),
446 SystemExecutor.run("systemctl is-active dnsmasq 2>/dev/null"),
447 SystemExecutor.run("[ -d /etc/wireguard ] && echo 'exists' || echo 'deleted'"),
448 SystemExecutor.run("[ -f /usr/bin/wireproxy ] && echo 'exists' || echo 'deleted'"),
449 ]);
450
451 // 只有在关键组件仍然存在时才报告残留
452 const criticalRemains = wpSvc.output === "active" || wgDir.output === 'exists' || wpBin.output === 'exists';
453
454 if (criticalRemains) {
455 return "⚠️ 卸载完成,但检测到部分关键文件残留。建议重启系统后重试,或手动删除 /etc/wireguard 目录。";
456 } else {
457 return "✅ 所有 WARP 相关组件已彻底卸载。";
458 }
459 } catch (e: any) {
460 return `❌ 卸载过程中出现错误: ${htmlEscape(e?.message || e)}。建议重启后重试。`;
461 }
462 }
463}

Callers 1

handleWarpMethod · 0.80

Calls 3

runSudoMethod · 0.80
runMethod · 0.80
htmlEscapeFunction · 0.70

Tested by

no test coverage detected