evo-cli 0.36.2__tar.gz → 0.36.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. {evo_cli-0.36.2 → evo_cli-0.36.3}/PKG-INFO +1 -1
  2. evo_cli-0.36.3/evo_cli/VERSION +1 -0
  3. evo_cli-0.36.3/evo_cli/commands/route/_dnswatch.py +6 -0
  4. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_spoofdpi.py +145 -25
  5. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/fix.py +5 -0
  6. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/status.py +2 -0
  7. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/PKG-INFO +1 -1
  8. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/SOURCES.txt +1 -0
  9. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_route.py +147 -4
  10. evo_cli-0.36.2/evo_cli/VERSION +0 -1
  11. {evo_cli-0.36.2 → evo_cli-0.36.3}/Containerfile +0 -0
  12. {evo_cli-0.36.2 → evo_cli-0.36.3}/HISTORY.md +0 -0
  13. {evo_cli-0.36.2 → evo_cli-0.36.3}/LICENSE +0 -0
  14. {evo_cli-0.36.2 → evo_cli-0.36.3}/MANIFEST.in +0 -0
  15. {evo_cli-0.36.2 → evo_cli-0.36.3}/README.md +0 -0
  16. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/__init__.py +0 -0
  17. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/__main__.py +0 -0
  18. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/base.py +0 -0
  19. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/cli.py +0 -0
  20. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/__init__.py +0 -0
  21. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/agent_toy.py +0 -0
  22. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/claude_code.py +0 -0
  23. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/cloudflare.py +0 -0
  24. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/cred.py +0 -0
  25. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/download.py +0 -0
  26. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/fix_claude.py +0 -0
  27. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/gdrive.py +0 -0
  28. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/gh.py +0 -0
  29. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/__init__.py +0 -0
  30. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_dag.py +0 -0
  31. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_git.py +0 -0
  32. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_hub.py +0 -0
  33. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_mirror.py +0 -0
  34. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_model.py +0 -0
  35. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_mutate.py +0 -0
  36. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_paths.py +0 -0
  37. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_render.py +0 -0
  38. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/_server.py +0 -0
  39. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/check.py +0 -0
  40. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/clone.py +0 -0
  41. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/edit.py +0 -0
  42. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/pull.py +0 -0
  43. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/serve.py +0 -0
  44. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/show.py +0 -0
  45. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/views.py +0 -0
  46. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/index-Cs7hXRPJ.css +0 -0
  47. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/index-CuNOlaH7.js +0 -0
  48. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-cyrillic-ext-wght-normal-BOeWTOD4.woff2 +0 -0
  49. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-cyrillic-wght-normal-DqGufNeO.woff2 +0 -0
  50. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-greek-ext-wght-normal-DlzME5K_.woff2 +0 -0
  51. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-greek-wght-normal-CkhJZR-_.woff2 +0 -0
  52. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-latin-ext-wght-normal-DO1Apj_S.woff2 +0 -0
  53. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-latin-wght-normal-Dx4kXJAl.woff2 +0 -0
  54. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/inter-vietnamese-wght-normal-CBcvBZtf.woff2 +0 -0
  55. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/jetbrains-mono-cyrillic-wght-normal-D73BlboJ.woff2 +0 -0
  56. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/jetbrains-mono-greek-wght-normal-Bw9x6K1M.woff2 +0 -0
  57. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/jetbrains-mono-latin-ext-wght-normal-DBQx-q_a.woff2 +0 -0
  58. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.woff2 +0 -0
  59. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2 +0 -0
  60. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/harness/web/index.html +0 -0
  61. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/hwid.py +0 -0
  62. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/hwid_reset.py +0 -0
  63. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/image.py +0 -0
  64. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/localproxy.py +0 -0
  65. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/mcp.py +0 -0
  66. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/miniconda.py +0 -0
  67. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/netcheck.py +0 -0
  68. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/ngrok.py +0 -0
  69. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/opencode.py +0 -0
  70. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/openvpn.py +0 -0
  71. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/plantuml.py +0 -0
  72. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/__init__.py +0 -0
  73. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_dns.py +0 -0
  74. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_dpi.py +0 -0
  75. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_hosts.py +0 -0
  76. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_page.py +0 -0
  77. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/_probe.py +0 -0
  78. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/check.py +0 -0
  79. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/route/probe.py +0 -0
  80. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/serp.py +0 -0
  81. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/site2s.py +0 -0
  82. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/ssh.py +0 -0
  83. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/storage.py +0 -0
  84. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/sysmon.py +0 -0
  85. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/tts.py +0 -0
  86. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/update.py +0 -0
  87. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/commands/wifi.py +0 -0
  88. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/console.py +0 -0
  89. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/__init__.py +0 -0
  90. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/doctor.py +0 -0
  91. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/google_oauth.py +0 -0
  92. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/migrate.py +0 -0
  93. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/oauth_flow.py +0 -0
  94. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/registry.py +0 -0
  95. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/store.py +0 -0
  96. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/credentials/sync.py +0 -0
  97. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/__init__.py +0 -0
  98. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/align.py +0 -0
  99. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/core.py +0 -0
  100. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/creds.py +0 -0
  101. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/errors.py +0 -0
  102. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/gemini.py +0 -0
  103. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/imaging/ncnn.py +0 -0
  104. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/mcp_registry.py +0 -0
  105. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/openvpn.py +0 -0
  106. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/__init__.py +0 -0
  107. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/client.py +0 -0
  108. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/creds.py +0 -0
  109. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/errors.py +0 -0
  110. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/install.py +0 -0
  111. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/serp/render.py +0 -0
  112. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/__init__.py +0 -0
  113. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/chunking.py +0 -0
  114. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/core.py +0 -0
  115. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/creds.py +0 -0
  116. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/errors.py +0 -0
  117. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/gemini.py +0 -0
  118. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/http.py +0 -0
  119. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/openai.py +0 -0
  120. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/player.py +0 -0
  121. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli/tts/vbee.py +0 -0
  122. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/dependency_links.txt +0 -0
  123. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/entry_points.txt +0 -0
  124. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/requires.txt +0 -0
  125. {evo_cli-0.36.2 → evo_cli-0.36.3}/evo_cli.egg-info/top_level.txt +0 -0
  126. {evo_cli-0.36.2 → evo_cli-0.36.3}/pyproject.toml +0 -0
  127. {evo_cli-0.36.2 → evo_cli-0.36.3}/setup.cfg +0 -0
  128. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/__init__.py +0 -0
  129. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/fake_evo_agents.py +0 -0
  130. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/fixtures/hub/contract-0.2.0.json +0 -0
  131. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/fixtures/hub/mirror-demo.yaml +0 -0
  132. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_agent_toy.py +0 -0
  133. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_claude_code.py +0 -0
  134. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_cli.py +0 -0
  135. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_console.py +0 -0
  136. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_cred.py +0 -0
  137. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_download.py +0 -0
  138. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_fix_claude.py +0 -0
  139. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_gdrive.py +0 -0
  140. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_gh.py +0 -0
  141. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_harness.py +0 -0
  142. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_harness_clone.py +0 -0
  143. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_harness_dag.py +0 -0
  144. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_harness_hub.py +0 -0
  145. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_harness_show.py +0 -0
  146. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_image.py +0 -0
  147. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_mcp.py +0 -0
  148. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_ngrok.py +0 -0
  149. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_opencode.py +0 -0
  150. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_openvpn.py +0 -0
  151. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_plantuml.py +0 -0
  152. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_serp.py +0 -0
  153. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_storage.py +0 -0
  154. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_sysmon.py +0 -0
  155. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_tts.py +0 -0
  156. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_update.py +0 -0
  157. {evo_cli-0.36.2 → evo_cli-0.36.3}/tests/test_wifi.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evo_cli
3
- Version: 0.36.2
3
+ Version: 0.36.3
4
4
  Summary: Evolution CLI - a developer toolbox for setting up dev machines
5
5
  Author: maycuatroi
6
6
  Project-URL: Homepage, https://github.com/maycuatroi/evo-cli
@@ -0,0 +1 @@
1
+ 0.36.3
@@ -0,0 +1,6 @@
1
+ """Run by the com.evo.route.dns LaunchAgent: re-pick how the opened hosts resolve after a change of network."""
2
+
3
+ from evo_cli.commands.route import _spoofdpi
4
+
5
+ if __name__ == "__main__":
6
+ _spoofdpi.refresh()
@@ -5,23 +5,32 @@ TLS ClientHello, so the filter never reads the server name in one piece. It only
5
5
  does that for the hosts `evo route open` named: every other name passes through
6
6
  untouched and resolves with the system's DNS server (SpoofDPI's own resolver,
7
7
  which does not read /etc/resolver). The named hosts resolve over DoH instead,
8
- because a name the filter blocks usually has its DNS answer poisoned too.
8
+ because a name the filter blocks usually has its DNS answer poisoned too, except
9
+ on a network where the DoH endpoint does not answer: see `dns_mode`.
9
10
  """
10
11
 
11
12
  from __future__ import annotations
12
13
 
14
+ import base64
15
+ import http.client
13
16
  import json
14
17
  import os
15
18
  import plistlib
19
+ import re
16
20
  import shutil
17
21
  import socket
22
+ import struct
18
23
  import subprocess
24
+ import sys
19
25
  import time
26
+ import urllib.request
20
27
  from pathlib import Path
21
28
 
29
+ from evo_cli.commands.route import _dns
22
30
  from evo_cli.console import info, run_command
23
31
 
24
32
  LABEL = "com.evo.route.spoofdpi"
33
+ DNS_LABEL = "com.evo.route.dns"
25
34
  LISTEN_HOST = "127.0.0.1"
26
35
  # Off 8080, where development servers live.
27
36
  LISTEN_PORT = 18080
@@ -34,7 +43,25 @@ LISTEN_PORT = 18080
34
43
  SPLIT_MODE = "chunk"
35
44
  CHUNK_SIZE = 16
36
45
 
37
- CONFIG = f"""# Written by `evo route open`; the hosts it opened are listed in hosts.txt.
46
+ # SpoofDPI asks this one DoH endpoint and has no fallback, so a network that blocks
47
+ # it (an office network that keeps DNS to its own resolver, 2026-11) fails every
48
+ # opened host with a 502. There the opened hosts use the system's resolver.
49
+ DOH_URL = "https://dns.google/dns-query"
50
+ # SpoofDPI gives a whole lookup 3 seconds.
51
+ DOH_TIMEOUT = 2.5
52
+ # Resolves on any network that is up, the way macOS checks for a captive portal.
53
+ ONLINE_PROBE = "captive.apple.com"
54
+ RESOLVERS = {"https": f"DoH ({DOH_URL})", "system": "the system resolver"}
55
+
56
+ # macOS rewrites this file on every change of network.
57
+ DNS_SETTINGS = "/var/run/resolv.conf"
58
+ # Catches a network that was not answering yet when its settings arrived.
59
+ DNS_RECHECK_SECONDS = 120
60
+
61
+
62
+ def config(dns_mode):
63
+ """SpoofDPI's config, with the opened hosts resolving by ``dns_mode``: "https" or "system"."""
64
+ return f"""# Written by `evo route open`; the hosts it opened are listed in hosts.txt.
38
65
  [dns]
39
66
  mode = "system"
40
67
 
@@ -45,10 +72,11 @@ skip = true
45
72
  name = "evo route open"
46
73
  priority = 50
47
74
  match = {{ domains = ["file:hosts.txt"] }}
48
- dns = {{ mode = "https", cache = true }}
75
+ dns = {{ mode = "{dns_mode}", https-url = "{DOH_URL}", cache = true }}
49
76
  https = {{ skip = false, split-mode = "{SPLIT_MODE}", chunk-size = {CHUNK_SIZE} }}
50
77
  """
51
78
 
79
+
52
80
  # networksetup names both proxies by these words: -getwebproxy, -setsecurewebproxystate, ...
53
81
  PROXY_KINDS = ("webproxy", "securewebproxy")
54
82
 
@@ -69,14 +97,18 @@ def hosts_path():
69
97
  return home() / "hosts.txt"
70
98
 
71
99
 
72
- def agent_path():
73
- return Path.home() / "Library" / "LaunchAgents" / f"{LABEL}.plist"
100
+ def agent_path(label=LABEL):
101
+ return Path.home() / "Library" / "LaunchAgents" / f"{label}.plist"
74
102
 
75
103
 
76
104
  def log_path():
77
105
  return Path.home() / "Library" / "Logs" / "evo-route-spoofdpi.log"
78
106
 
79
107
 
108
+ def dns_log_path():
109
+ return Path.home() / "Library" / "Logs" / "evo-route-dns.log"
110
+
111
+
80
112
  def listen():
81
113
  return f"{LISTEN_HOST}:{LISTEN_PORT}"
82
114
 
@@ -126,27 +158,33 @@ def _program(exe):
126
158
  return [exe, "--config", str(config_path()), "--no-tui", "--listen-addr", listen()]
127
159
 
128
160
 
129
- def _write_agent(exe):
130
- """Write the LaunchAgent; True when its content changed."""
131
- plist = plistlib.dumps(
132
- {
133
- "Label": LABEL,
134
- "ProgramArguments": _program(exe),
135
- "RunAtLoad": True,
136
- "KeepAlive": True,
137
- "StandardOutPath": str(log_path()),
138
- "StandardErrorPath": str(log_path()),
139
- }
140
- )
141
- path = agent_path()
161
+ def _write_plist(label, job, log):
162
+ """Write a LaunchAgent; True when its content changed."""
163
+ plist = plistlib.dumps({"Label": label, **job, "StandardOutPath": str(log), "StandardErrorPath": str(log)})
164
+ path = agent_path(label)
142
165
  if path.exists() and path.read_bytes() == plist:
143
166
  return False
144
167
  path.parent.mkdir(parents=True, exist_ok=True)
145
- log_path().parent.mkdir(parents=True, exist_ok=True)
168
+ log.parent.mkdir(parents=True, exist_ok=True)
146
169
  path.write_bytes(plist)
147
170
  return True
148
171
 
149
172
 
173
+ def _write_agent(exe):
174
+ return _write_plist(LABEL, {"ProgramArguments": _program(exe), "RunAtLoad": True, "KeepAlive": True}, log_path())
175
+
176
+
177
+ def _write_dns_agent():
178
+ """The agent that runs `refresh` with this Python whenever the network changes, and every few minutes."""
179
+ job = {
180
+ "ProgramArguments": [sys.executable, "-m", "evo_cli.commands.route._dnswatch"],
181
+ "RunAtLoad": True,
182
+ "WatchPaths": [DNS_SETTINGS],
183
+ "StartInterval": DNS_RECHECK_SECONDS,
184
+ }
185
+ return _write_plist(DNS_LABEL, job, dns_log_path())
186
+
187
+
150
188
  def _launchctl(*args):
151
189
  return subprocess.run(["launchctl", *args], capture_output=True, text=True, stdin=subprocess.DEVNULL, check=False)
152
190
 
@@ -155,8 +193,8 @@ def _domain():
155
193
  return f"gui/{os.getuid()}"
156
194
 
157
195
 
158
- def _loaded():
159
- return _launchctl("print", f"{_domain()}/{LABEL}").returncode == 0
196
+ def _loaded(label=LABEL):
197
+ return _launchctl("print", f"{_domain()}/{label}").returncode == 0
160
198
 
161
199
 
162
200
  def _listening(timeout=0.5):
@@ -302,6 +340,86 @@ def browser_overrides(support=None):
302
340
  return found
303
341
 
304
342
 
343
+ def _doh_answers():
344
+ """Whether DOH_URL answers from this network, asked as SpoofDPI asks it: straight, never through a proxy."""
345
+ question = struct.pack(">HHHHHH", 0, 0x0100, 1, 0, 0, 0) + _dns._encode_qname(ONLINE_PROBE)
346
+ question += struct.pack(">HH", 1, 1)
347
+ query = base64.urlsafe_b64encode(question).rstrip(b"=").decode()
348
+ request = urllib.request.Request(f"{DOH_URL}?dns={query}", headers={"accept": "application/dns-message"})
349
+ opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
350
+ try:
351
+ with opener.open(request, timeout=DOH_TIMEOUT) as response:
352
+ reply = response.read()
353
+ except (OSError, ValueError, http.client.HTTPException):
354
+ return False
355
+ # RCODE 0: the endpoint read the question and answered it.
356
+ return len(reply) >= 12 and reply[3] & 0x0F == 0
357
+
358
+
359
+ def _online():
360
+ try:
361
+ socket.getaddrinfo(ONLINE_PROBE, 80, type=socket.SOCK_STREAM)
362
+ except OSError:
363
+ return False
364
+ return True
365
+
366
+
367
+ def dns_mode():
368
+ """How the opened hosts should resolve on the network the Mac is on now.
369
+
370
+ Over DoH where its endpoint answers, since a blocked name is often a poisoned one too. With the system
371
+ resolver where it does not, which is the resolver such a network means to be used. None while nothing
372
+ answers at all, offline or before the network is up, when there is nothing to choose between.
373
+ """
374
+ if _doh_answers():
375
+ return "https"
376
+ return "system" if _online() else None
377
+
378
+
379
+ def current_dns_mode():
380
+ """How the opened hosts resolve in the config SpoofDPI runs with; None before evo wrote one."""
381
+ try:
382
+ text = config_path().read_text(encoding="utf-8")
383
+ except FileNotFoundError:
384
+ return None
385
+ found = re.search(r'^dns = \{ mode = "(\w+)"', text, re.MULTILINE)
386
+ return found.group(1) if found else None
387
+
388
+
389
+ def _write_config(dns_mode):
390
+ """Write SpoofDPI's config; True when its content changed."""
391
+ text = config(dns_mode)
392
+ path = config_path()
393
+ if path.exists() and path.read_text(encoding="utf-8") == text:
394
+ return False
395
+ home().mkdir(parents=True, exist_ok=True)
396
+ path.write_text(text, encoding="utf-8")
397
+ return True
398
+
399
+
400
+ def refresh():
401
+ """Resolve the opened hosts the way the current network allows; restart SpoofDPI only when that changes.
402
+
403
+ The DNS agent runs this on every change of network. Returns the mode in use, None while the bypass is off.
404
+ """
405
+ if not opened() or not _loaded():
406
+ return None
407
+ mode = dns_mode()
408
+ if mode is None:
409
+ return current_dns_mode()
410
+ if _write_config(mode):
411
+ _start(reload=False)
412
+ print(f"{time.strftime('%Y-%m-%d %H:%M:%S')} opened hosts now resolve with {RESOLVERS[mode]}", flush=True)
413
+ return mode
414
+
415
+
416
+ def _watch_network():
417
+ """(Re)load the DNS agent; launchd runs it once on load, then on every change of network."""
418
+ if _write_dns_agent() or not _loaded(DNS_LABEL):
419
+ _launchctl("bootout", f"{_domain()}/{DNS_LABEL}")
420
+ _launchctl("bootstrap", _domain(), str(agent_path(DNS_LABEL)))
421
+
422
+
305
423
  def service_state():
306
424
  exe = executable()
307
425
  return {
@@ -311,6 +429,7 @@ def service_state():
311
429
  "reason": None,
312
430
  "hosts": opened(),
313
431
  "proxy": proxied_services(),
432
+ "dns": current_dns_mode(),
314
433
  }
315
434
 
316
435
 
@@ -320,11 +439,11 @@ def ensure(*hosts):
320
439
  if conflicts:
321
440
  raise RuntimeError(f"A proxy is already set on {', '.join(conflicts)}; evo will not replace it.")
322
441
  exe = executable() or install()
323
- home().mkdir(parents=True, exist_ok=True)
324
- config_path().write_text(CONFIG, encoding="utf-8")
442
+ _write_config(dns_mode() or current_dns_mode() or "https")
325
443
  _write_hosts([*opened(), *hosts])
326
444
  if not _start(reload=_write_agent(exe)):
327
445
  return service_state()
446
+ _watch_network()
328
447
  set_system_proxy()
329
448
  return service_state()
330
449
 
@@ -342,7 +461,8 @@ def forget(host):
342
461
  def remove():
343
462
  """Clear the system proxy first, so nothing points at a proxy that is gone, then stop and drop the agent."""
344
463
  clear_system_proxy()
345
- _launchctl("bootout", f"{_domain()}/{LABEL}")
346
- agent_path().unlink(missing_ok=True)
464
+ for label in (DNS_LABEL, LABEL):
465
+ _launchctl("bootout", f"{_domain()}/{label}")
466
+ agent_path(label).unlink(missing_ok=True)
347
467
  hosts_path().unlink(missing_ok=True)
348
468
  return True
@@ -76,6 +76,11 @@ def _apply_spoofdpi(host, dry_run):
76
76
  error(f"SpoofDPI would not start - see {_spoofdpi.log_path()}")
77
77
  sys.exit(1)
78
78
  success(f"DPI bypass is running on {_spoofdpi.listen()}, system proxy set on {', '.join(state['proxy'])}")
79
+ if state.get("dns") == "system":
80
+ info(
81
+ f"{_spoofdpi.DOH_URL} does not answer on this network, so the opened hosts resolve with the system "
82
+ "resolver; evo switches them back to DoH on a network where it answers"
83
+ )
79
84
  return state
80
85
 
81
86
 
@@ -70,6 +70,8 @@ def status(as_json):
70
70
  console.print(f" [dim]{dpi['args']}[/dim]")
71
71
  if dpi.get("hosts"):
72
72
  info(f"Hosts: {', '.join(dpi['hosts'])} - remove with `evo route close <host>`")
73
+ if dpi.get("hosts") and dpi.get("dns") in _spoofdpi.RESOLVERS:
74
+ info(f"They resolve with {_spoofdpi.RESOLVERS[dpi['dns']]}, re-picked on every change of network")
73
75
  if dpi.get("proxy"):
74
76
  info(f"System proxy set on {', '.join(dpi['proxy'])}")
75
77
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: evo_cli
3
- Version: 0.36.2
3
+ Version: 0.36.3
4
4
  Summary: Evolution CLI - a developer toolbox for setting up dev machines
5
5
  Author: maycuatroi
6
6
  Project-URL: Homepage, https://github.com/maycuatroi/evo-cli
@@ -80,6 +80,7 @@ evo_cli/commands/harness/web/assets/jetbrains-mono-latin-wght-normal-B9CIFXIH.wo
80
80
  evo_cli/commands/harness/web/assets/jetbrains-mono-vietnamese-wght-normal-Bt-aOZkq.woff2
81
81
  evo_cli/commands/route/__init__.py
82
82
  evo_cli/commands/route/_dns.py
83
+ evo_cli/commands/route/_dnswatch.py
83
84
  evo_cli/commands/route/_dpi.py
84
85
  evo_cli/commands/route/_hosts.py
85
86
  evo_cli/commands/route/_page.py
@@ -269,10 +269,153 @@ def test_spoofdpi_reads_a_host_list_from_before_the_double_star(tmp_path, monkey
269
269
 
270
270
  def test_spoofdpi_config_bypasses_only_the_opened_hosts():
271
271
  """Every other name goes straight through, so names only a VPN resolves keep working."""
272
- assert 'mode = "system"' in _spoofdpi.CONFIG
273
- assert "skip = true" in _spoofdpi.CONFIG
274
- assert '"file:hosts.txt"' in _spoofdpi.CONFIG
275
- assert 'split-mode = "chunk", chunk-size = 16' in _spoofdpi.CONFIG
272
+ config = _spoofdpi.config("https")
273
+ assert '[dns]\nmode = "system"' in config
274
+ assert "skip = true" in config
275
+ assert '"file:hosts.txt"' in config
276
+ assert 'split-mode = "chunk", chunk-size = 16' in config
277
+
278
+
279
+ @pytest.mark.parametrize("mode", ["https", "system"])
280
+ def test_spoofdpi_config_round_trips_how_the_opened_hosts_resolve(tmp_path, monkeypatch, mode):
281
+ monkeypatch.setenv("EVO_ROUTE_HOME", str(tmp_path))
282
+ assert _spoofdpi.current_dns_mode() is None
283
+ assert _spoofdpi._write_config(mode)
284
+ assert f'https-url = "{_spoofdpi.DOH_URL}"' in (tmp_path / "spoofdpi.toml").read_text()
285
+ assert _spoofdpi.current_dns_mode() == mode
286
+ assert not _spoofdpi._write_config(mode)
287
+
288
+
289
+ def test_spoofdpi_reads_the_dns_mode_of_a_config_from_before_the_fallback(tmp_path, monkeypatch):
290
+ monkeypatch.setenv("EVO_ROUTE_HOME", str(tmp_path))
291
+ (tmp_path / "spoofdpi.toml").write_text(
292
+ '[dns]\nmode = "system"\n\n[[rules]]\ndns = { mode = "https", cache = true }\n'
293
+ )
294
+ assert _spoofdpi.current_dns_mode() == "https"
295
+
296
+
297
+ class _Reply:
298
+ def __init__(self, body):
299
+ self.body = body
300
+
301
+ def __enter__(self):
302
+ return self
303
+
304
+ def __exit__(self, *exc):
305
+ return False
306
+
307
+ def read(self):
308
+ return self.body
309
+
310
+
311
+ def _fake_opener(monkeypatch, outcome, seen):
312
+ class Opener:
313
+ def open(self, request, timeout):
314
+ seen.append((request.full_url, request.get_header("Accept"), timeout))
315
+ if isinstance(outcome, Exception):
316
+ raise outcome
317
+ return _Reply(outcome)
318
+
319
+ def build_opener(*handlers):
320
+ seen.append([type(handler).__name__ for handler in handlers])
321
+ return Opener()
322
+
323
+ monkeypatch.setattr(_spoofdpi.urllib.request, "build_opener", build_opener)
324
+
325
+
326
+ @pytest.mark.parametrize(
327
+ ("outcome", "answers"),
328
+ [
329
+ (struct.pack(">HHHHHH", 0, 0x8180, 1, 1, 0, 0), True),
330
+ (struct.pack(">HHHHHH", 0, 0x8185, 1, 0, 0, 0), False),
331
+ (b"<html>blocked</html>", False),
332
+ (TimeoutError("timed out"), False),
333
+ ],
334
+ )
335
+ def test_doh_probe_asks_straight_and_wants_a_dns_answer(monkeypatch, outcome, answers):
336
+ seen = []
337
+ _fake_opener(monkeypatch, outcome, seen)
338
+ assert _spoofdpi._doh_answers() is answers
339
+ assert seen[0] == ["ProxyHandler"]
340
+ url, accept, timeout = seen[1]
341
+ assert url.startswith(f"{_spoofdpi.DOH_URL}?dns=")
342
+ assert accept == "application/dns-message"
343
+ assert timeout < 3
344
+
345
+
346
+ @pytest.mark.parametrize(
347
+ ("doh", "online", "mode"),
348
+ [(True, True, "https"), (True, False, "https"), (False, True, "system"), (False, False, None)],
349
+ )
350
+ def test_dns_mode_falls_back_to_the_system_resolver_only_while_online(monkeypatch, doh, online, mode):
351
+ monkeypatch.setattr(_spoofdpi, "_doh_answers", lambda: doh)
352
+ monkeypatch.setattr(_spoofdpi, "_online", lambda: online)
353
+ assert _spoofdpi.dns_mode() == mode
354
+
355
+
356
+ def _bypass_running(tmp_path, monkeypatch, mode, starts):
357
+ monkeypatch.setenv("EVO_ROUTE_HOME", str(tmp_path))
358
+ _spoofdpi._write_hosts(["youtube.com"])
359
+ _spoofdpi._write_config("https")
360
+ monkeypatch.setattr(_spoofdpi, "_loaded", lambda label=_spoofdpi.LABEL: True)
361
+ monkeypatch.setattr(_spoofdpi, "_start", lambda reload: starts.append(reload) or True)
362
+ monkeypatch.setattr(_spoofdpi, "dns_mode", lambda: mode)
363
+
364
+
365
+ def test_refresh_switches_to_the_system_resolver_where_doh_is_blocked(tmp_path, monkeypatch, capsys):
366
+ starts = []
367
+ _bypass_running(tmp_path, monkeypatch, "system", starts)
368
+ assert _spoofdpi.refresh() == "system"
369
+ assert _spoofdpi.current_dns_mode() == "system"
370
+ assert starts == [False]
371
+ assert "the system resolver" in capsys.readouterr().out
372
+
373
+
374
+ def test_refresh_leaves_spoofdpi_alone_when_nothing_changed(tmp_path, monkeypatch):
375
+ starts = []
376
+ _bypass_running(tmp_path, monkeypatch, "https", starts)
377
+ assert _spoofdpi.refresh() == "https"
378
+ assert starts == []
379
+
380
+
381
+ def test_refresh_keeps_the_config_while_offline(tmp_path, monkeypatch):
382
+ starts = []
383
+ _bypass_running(tmp_path, monkeypatch, None, starts)
384
+ assert _spoofdpi.refresh() == "https"
385
+ assert starts == []
386
+
387
+
388
+ def test_refresh_does_nothing_while_the_bypass_is_off(tmp_path, monkeypatch):
389
+ monkeypatch.setenv("EVO_ROUTE_HOME", str(tmp_path))
390
+ monkeypatch.setattr(_spoofdpi, "dns_mode", lambda: pytest.fail("probed with the bypass off"))
391
+ assert _spoofdpi.refresh() is None
392
+
393
+
394
+ def test_dns_agent_runs_the_watch_module_on_every_network_change(tmp_path, monkeypatch):
395
+ import importlib.util
396
+ import plistlib
397
+
398
+ monkeypatch.setattr(_spoofdpi.Path, "home", lambda: tmp_path)
399
+ assert _spoofdpi._write_dns_agent()
400
+ job = plistlib.loads(_spoofdpi.agent_path(_spoofdpi.DNS_LABEL).read_bytes())
401
+ assert job["Label"] == _spoofdpi.DNS_LABEL
402
+ assert job["ProgramArguments"][1:] == ["-m", "evo_cli.commands.route._dnswatch"]
403
+ assert importlib.util.find_spec(job["ProgramArguments"][2]) is not None
404
+ assert job["WatchPaths"] == ["/var/run/resolv.conf"]
405
+ assert "KeepAlive" not in job
406
+ assert not _spoofdpi._write_dns_agent()
407
+
408
+
409
+ def test_remove_drops_the_dns_agent_too(tmp_path, monkeypatch):
410
+ monkeypatch.setenv("EVO_ROUTE_HOME", str(tmp_path))
411
+ monkeypatch.setattr(_spoofdpi.Path, "home", lambda: tmp_path)
412
+ monkeypatch.setattr(_spoofdpi, "clear_system_proxy", list)
413
+ calls = []
414
+ monkeypatch.setattr(_spoofdpi, "_launchctl", lambda *args: calls.append(args))
415
+ _spoofdpi._write_dns_agent()
416
+ _spoofdpi.remove()
417
+ assert [call[1].rsplit("/", 1)[1] for call in calls] == [_spoofdpi.DNS_LABEL, _spoofdpi.LABEL]
418
+ assert not _spoofdpi.agent_path(_spoofdpi.DNS_LABEL).exists()
276
419
 
277
420
 
278
421
  def test_network_services_skip_the_header_and_disabled_ones(monkeypatch):
@@ -1 +0,0 @@
1
- 0.36.2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes