Commit 85e86860 authored by Vitaly Lipatov's avatar Vitaly Lipatov

route-web-api: add direct (no proxy) check to /api/check

Shows what users actually get from the office via policy routing, without going through any SOCKS5 proxy. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 44b22a63
...@@ -42,6 +42,7 @@ MAX_ENTRIES = 500 ...@@ -42,6 +42,7 @@ MAX_ENTRIES = 500
UPDATE_INTERVAL = 300 # route-update.sh cycle, seconds UPDATE_INTERVAL = 300 # route-update.sh cycle, seconds
CHECK_GATEWAYS = [ CHECK_GATEWAYS = [
("direct", None), # direct from igw, uses policy routing
("dgw", "socks5h://91.232.225.12:1080"), ("dgw", "socks5h://91.232.225.12:1080"),
("igw", "socks5h://91.232.225.13:1080"), ("igw", "socks5h://91.232.225.13:1080"),
("warp", "socks5h://91.232.225.134:1080"), ("warp", "socks5h://91.232.225.134:1080"),
...@@ -60,9 +61,13 @@ _list_lock = threading.Lock() ...@@ -60,9 +61,13 @@ _list_lock = threading.Lock()
def _check_one(name, proxy, url, ipver="-4"): def _check_one(name, proxy, url, ipver="-4"):
"""Check a single gateway, return (name, ipver, status, http_code).""" """Check a single gateway, return (name, ipver, status, http_code)."""
try: try:
cmd = ["curl", ipver]
if proxy:
cmd.extend(["--proxy", proxy])
cmd.extend(["-o", "/dev/null", "-s",
"-w", "%{http_code}", "-m", str(CHECK_TIMEOUT), "-L", url])
result = subprocess.run( result = subprocess.run(
["curl", ipver, "--proxy", proxy, "-o", "/dev/null", "-s", cmd,
"-w", "%{http_code}", "-m", str(CHECK_TIMEOUT), "-L", url],
capture_output=True, text=True, timeout=CHECK_TIMEOUT + 5, capture_output=True, text=True, timeout=CHECK_TIMEOUT + 5,
) )
code = int(result.stdout.strip()) if result.stdout.strip() else 0 code = int(result.stdout.strip()) if result.stdout.strip() else 0
...@@ -199,8 +204,12 @@ THROTTLE_SIZE_LIMIT = 32768 # 32KB — above typical TCP initial window ...@@ -199,8 +204,12 @@ THROTTLE_SIZE_LIMIT = 32768 # 32KB — above typical TCP initial window
def _find_assets(proxy, base_url): def _find_assets(proxy, base_url):
"""Download HTML page via proxy and extract CSS/JS asset URLs.""" """Download HTML page via proxy and extract CSS/JS asset URLs."""
try: try:
cmd = ["curl", "-4"]
if proxy:
cmd.extend(["--proxy", proxy])
cmd.extend(["-s", "-m", "10", "-L", base_url])
result = subprocess.run( result = subprocess.run(
["curl", "-4", "--proxy", proxy, "-s", "-m", "10", "-L", base_url], cmd,
capture_output=True, timeout=15, capture_output=True, timeout=15,
) )
if result.returncode != 0: if result.returncode != 0:
...@@ -235,10 +244,14 @@ def _check_throttle(name, proxy, asset_url): ...@@ -235,10 +244,14 @@ def _check_throttle(name, proxy, asset_url):
Returns (name, result_dict) or (name, None). Returns (name, result_dict) or (name, None).
""" """
try: try:
result = subprocess.run( cmd = ["curl", "-4"]
["curl", "-4", "--proxy", proxy, "-o", "/dev/null", "-s", if proxy:
cmd.extend(["--proxy", proxy])
cmd.extend(["-o", "/dev/null", "-s",
"-w", "%{size_download} %{time_total}", "-w", "%{size_download} %{time_total}",
"-m", str(THROTTLE_TIMEOUT), "-L", asset_url], "-m", str(THROTTLE_TIMEOUT), "-L", asset_url])
result = subprocess.run(
cmd,
capture_output=True, text=True, timeout=THROTTLE_TIMEOUT + 5, capture_output=True, text=True, timeout=THROTTLE_TIMEOUT + 5,
) )
parts = result.stdout.strip().split() parts = result.stdout.strip().split()
...@@ -910,7 +923,7 @@ function renderCheck(data) { ...@@ -910,7 +923,7 @@ function renderCheck(data) {
const gsec = mkDiv('check-section'); const gsec = mkDiv('check-section');
gsec.appendChild(mkDiv('check-section-title', '\\u0414\\u043e\\u0441\\u0442\\u0443\\u043f\\u043d\\u043e\\u0441\\u0442\\u044c \\u0447\\u0435\\u0440\\u0435\\u0437 \\u0448\\u043b\\u044e\\u0437\\u044b')); gsec.appendChild(mkDiv('check-section-title', '\\u0414\\u043e\\u0441\\u0442\\u0443\\u043f\\u043d\\u043e\\u0441\\u0442\\u044c \\u0447\\u0435\\u0440\\u0435\\u0437 \\u0448\\u043b\\u044e\\u0437\\u044b'));
const gwrap = document.createElement('div'); const gwrap = document.createElement('div');
const order = ['dgw', 'igw', 'warp', 'gre.hetzner', 'ikev2.hetzner', 'gre.vdska', 'gre.beget.ogw', 'ikev2.beget.ogw']; const order = ['direct', 'dgw', 'igw', 'warp', 'gre.hetzner', 'ikev2.hetzner', 'gre.vdska', 'gre.beget.ogw', 'ikev2.beget.ogw'];
for (const name of order) { for (const name of order) {
const info = data.checks[name]; const info = data.checks[name];
if (!info) continue; if (!info) continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment