omar 72416d2584
CI / validate (push) Successful in 32s
CI / gateway-contract (push) Successful in 1m56s
CI / images (deploy/Dockerfile.api, api) (push) Successful in 56s
CI / images (deploy/Dockerfile.web, web) (push) Successful in 53s
CI / images (deploy/Dockerfile.checker, checker) (push) Successful in 1m2s
CI / images (deploy/Dockerfile.http-gateway, http-gateway) (push) Successful in 1m3s
Continue checking when individual sources fail to load
2026-11-28 09:24:01 +03:00

zhguchiy_perchik

Proxy checker panel with its own subscription system. It continuously pulls proxy configs (vless / vmess / trojan / ss) from source lists, checks each for validity by its exit IP, keeps only working ones, and serves them to clients as subscriptions (plain / base64 / Clash / sing-box).

See ARCHITECTURE.md for the design and TODO.md for the full feature wishlist.

Stack

Service Stack Role
postgres PostgreSQL 16 Database
checker Go (cmd/checker) Worker: fetch → canonicalize/dedup → check → geo → write sessions
api Go (cmd/api) REST panel API + public subscription endpoints
web React + Vite + TS + Tailwind + nginx SPA panel (Dashboard / Proxies / Subscriptions / Settings), also routes /api + /sub
http-gateway Go (cmd/http-gateway), optional gateway profile Private HTTP/CONNECT and SOCKS5 proxies with a filtered catalog API

The vless/vmess/trojan/ss dialers, upstream parser, geoip and fetcher are reused from tessero-checker; the canonicalization, session model, DB layer, subscription conversion and API/UI are new.

Quick start

Images are built and pushed to the Gitea container registry by CI, so the default compose pulls them:

cp .env.example .env
# edit .env: set ADMIN_PASSWORD and SESSION_SECRET (long random)
docker compose pull
docker compose up -d

To build the images locally from source instead of pulling, add the build override:

docker compose -f docker-compose.yml -f docker-compose.build.yml up -d --build

Open http://localhost:8088 and sign in with ADMIN_USER / ADMIN_PASSWORD.

Then in the panel:

  1. Settings → Sources: add one or more list URLs and pick the type (auto tries base64 then plain, or force plain / base64). See TODO.md for example lists.
  2. Run check (top bar) or wait for the scheduled interval.
  3. Working proxies appear in Proxies; build client feeds in Subscriptions.

Model — "only working / last completed session"

The panel and subscriptions always serve the last completed check session; a running or crashed session never affects output. When a session completes, one transaction flips the is_current pointer. Per-canonical history (uptime, consecutive failures) is kept even while a proxy is currently invalid, but only working proxies from the current session are ever shown or served.

Private HTTP gateway

By default the optional gateway Compose profile runs the full gateway, with three separate private ports:

  • 8081 for plain HTTP and HTTPS through HTTP CONNECT.
  • 8082 for the catalog and status API.
  • 1080 for authenticated SOCKS5 TCP CONNECT.

All three publish to host loopback by default. GATEWAY_BIND_IP controls the HTTP and SOCKS5 proxy ports; GATEWAY_API_BIND_IP independently controls the API port. For remote forwarding clients, publish only on a private VPN interface and restrict ingress to authorized VPN clients with the host firewall. Never expose the forwarding ports on a wildcard or on the WAN: proxy credentials are cleartext on the hop to the gateway. Public nginx does not route these ports. The normal stack does not require any GATEWAY_* variables.

Catalog-only mode

Set GATEWAY_MODE=catalog-only to run just the API. Provision the real PostgreSQL database, API token, node secret, and advertised proxy addresses as described in provisioning steps 3 and 4 below. Leave GATEWAY_PROBE_URL, GATEWAY_ALLOWED_DESTINATIONS, and GATEWAY_UPSTREAM_NETWORKS empty if forwarding is not configured. An empty or unset GATEWAY_MODE still means the full gateway, which refuses to start without complete forwarding configuration.

In catalog-only mode the process listens only on :8082; it does not open HTTP or SOCKS5 forwarding listeners or run probes, regardless of which Compose ports are mapped. Requests to GET /v1/proxies and GET /v1/status still require Authorization: Bearer <GATEWAY_API_TOKEN>. The API reads the same PostgreSQL catalog and status as full mode; /readyz indicates database/schema readiness, not forwarding availability. Previously successful checks still expire, so a catalog with no fresh checks is empty. Exported proxy URLs do not enable forwarding on this instance.

Keep GATEWAY_API_BIND_IP=127.0.0.1 for local access or a local TLS reverse proxy. For LAN access, preferably bind to the VPN interface. To publish the API on all host IPv4 interfaces, set GATEWAY_API_BIND_IP=0.0.0.0, restrict ingress to trusted clients, and use a VPN or a private HTTPS reverse proxy; do not send bearer tokens or catalog exports over unprotected LAN or WAN links.

Provisioning

  1. Choose an upstream policy (full gateway only). The gateway considers every member of the last completed, current checker session across all its sources. Use only operator-owned peers or peers whose operator has explicitly authorized relay use. If the snapshot mixes authorized and unauthorized peers, use a separate checker/database; do not enable the gateway on that snapshot.

    Set GATEWAY_UPSTREAM_NETWORKS=any to allow public upstream addresses from the published snapshot without maintaining a manual IP list. The gateway still rejects non-public addresses, its own IP and local interface addresses, and DNS responses that mix permitted and forbidden addresses. Destination checks and client authentication are unchanged.

    For stricter filtering, set GATEWAY_UPSTREAM_NETWORKS to a comma-separated list of 1-32 unique public peer IPs or canonical CIDRs, IPv4 /24 or narrower and IPv6 /64 or narrower. Prefer individual IPs (/32 or /128). This list restricts the actual upstream TCP peer, not its exit IP or the destination.

  2. Configure the destination allowlist and probe (full gateway only). Set GATEWAY_ALLOWED_DESTINATIONS to exact comma-separated DNS names with ports, for example origin.example:80,origin.example:443,probe.example:443. Include the probe authority in the list even if it uses a port other than 443. GATEWAY_PROBE_URL is the only direct control destination: a fixed HTTPS URL without credentials, query, or fragment. Keep the configured Cloudflare probe when changing the destination policy. The endpoint must return exactly 204 without a redirect, have a trusted TLS certificate, and be reachable directly from the gateway and through each permitted peer. HTTP CONNECT and SOCKS5 CONNECT restrict the TCP destination, not URL paths inside TLS; the gateway does not decrypt the connection.

  3. Provision a restricted database login. Start the updated checker to apply its schema during an approved maintenance window; the gateway does not run migrations. As a PostgreSQL role administrator on the same database, create a dedicated non-owner login with no role memberships. Use \password in an interactive psql session so the password does not appear in SQL history. With the default Compose DB name and owner, open it with docker compose exec postgres psql -U perchik -d perchik:

    CREATE ROLE perchik_gateway LOGIN NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOREPLICATION NOBYPASSRLS;
    GRANT CONNECT ON DATABASE perchik TO perchik_gateway;
    \password perchik_gateway
    

    Adjust perchik to the configured database name. Then run the checked-in grants as the schema/object owner (for a non-default schema, pass -v gateway_schema=<schema> and configure the login's search_path):

    docker compose exec -T postgres psql -U perchik -d perchik \
      -v gateway_role=perchik_gateway < deploy/gateway-grants.sql
    

    Keep schema creation and access to checker tables, subscriptions and other settings off this role, including access inherited through PUBLIC or existing ACLs. The grant script does not revoke preexisting privileges. Set GATEWAY_DB_DSN to this login's connection string, not the checker or admin API DSN. For Compose the database host is postgres:5432; for a database outside the isolated Compose network use TLS with sslmode=verify-full.

  4. Set the address and secrets. Set GATEWAY_PUBLIC_PROXY_ADDR to the client-reachable host:port, for example 127.0.0.1:8081 for local clients or [fd12:3456::9]:8081 on a private VPN. HTTP exports use this address; SOCKS5 exports use its host with GATEWAY_SOCKS_PORT (default 1080). GATEWAY_BIND_IP, GATEWAY_API_BIND_IP, GATEWAY_PROXY_PORT, GATEWAY_API_PORT, and GATEWAY_SOCKS_PORT control host publication (bracket an IPv6 bind IP). Generate two independent 32-byte random base64url strings without padding for GATEWAY_API_TOKEN and GATEWAY_NODE_SECRET:

    openssl rand -base64 32 | tr '/+' '_-' | tr -d '=\n'
    

    Run the generator twice in a private session. Keep values in a restricted env file or secret manager, not in Git, shell arguments or shared logs. Use docker compose config --quiet for Compose syntax checks; rendered config and container inspection can expose the environment. Keep the node secret and DB's store_uuid across restarts to preserve existing passwords. Rotating the API token revokes catalog access only; rotating the node secret revokes all issued proxy passwords. Recreate only the gateway container after updating its secrets and re-export credentials for affected clients.

Start and observe

Once the schema, grants, and gateway environment are provisioned:

docker compose --profile gateway pull http-gateway
docker compose --profile gateway up -d --no-deps http-gateway

For a local build, include -f docker-compose.yml -f docker-compose.build.yml and add --build to up. For a standalone binary, build with go build -o http-gateway ./cmd/http-gateway and set the required environment from .env.example. In full mode the binary listens on ports 8081, 8082, and 1080 on all interfaces; the Compose host bind settings do not change these sockets. Keep the host private and restrict all listening ports at the firewall if running without Compose.

Check both unauthenticated health endpoints on the private API port (GET, not HEAD): /healthz means the process can answer. In full mode, /readyz means the HTTP, SOCKS5, and API listeners, DB/schema and the single-instance advisory lock are usable. Readiness can be 503 during initialization or on DB/lease failure. It does not require a session or any working peers. Use authenticated GET /v1/status or Settings → HTTP gateway for monitor state, ready/candidate counts and last successful and next scheduled checks. The panel does not receive client secrets. Set the interval to 15-30 whole minutes (default 20), independent of the main checker. Periodic availability and latency checks still use the HTTP proxy listener, not SOCKS5. Country and speed remain in the last completed checker snapshot. Removed nodes are unavailable immediately for new connections and requests; successful gateway checks expire after twice the effective interval.

When a local CONNECT setup problem aborts a monitor pass, status stays degraded with last_error_code=probe and the pass publishes no measurements. Look for the gateway probe infrastructure failure warning in the gateway log. Its category distinguishes ticket issuance (ticket), no parsed loopback response (no_connect_response), invalid, denied or unauthenticated CONNECT (connect_invalid, connect_denied, connect_auth), and an unexpected response (connect_unexpected). A 503 with the local Retry-After marker is connect_capacity; a 503 without it is connect_unavailable and does not identify a specific cause. The warning includes no node or request details.

In Settings → HTTP gateway, Allow all public websites is off by default: only the configured allowlist is permitted. Turning it on also allows public DNS names and public IP literals via HTTP on port 80, HTTP CONNECT on port 443, or SOCKS5 CONNECT on either port. All DNS answers and IP literals still pass the same public-address and local-interface checks; the exact allowlist, configured upstream policy, and proxy authentication remain in effect. The switch is saved in the database as gateway_allow_all_sites; no environment variable enables or overrides it.

Catalog and proxy clients

Send Authorization: Bearer … to GET /v1/proxies on port 8082. The API always returns Cache-Control: no-store. The same query selects the same rows for any format:

Query parameter Meaning
country Country codes such as DE,NL; XX means unknown.
protocol vless, vmess, trojan or ss.
min_speed_mbps, max_latency_ms Inclusive thresholds; missing speed does not match a specified minimum. Latency is the latest gateway probe; maximum latency is an integer.
sort id (default), speed (descending, unmeasured last), latency or country. Ties use ascending proxy ID.
limit, offset Positive limit and nonnegative offset; default is all matching ready rows.
proxy_type http (default) or socks5; selects the client-facing proxy address and URL scheme, not the upstream protocol.
format json (default), csv, txt, or proxy-url-list-txt.

Both country and protocol support comma-separated or repeated values (OR within a field, AND across fields). JSON includes total before pagination, session_finished_at for the main snapshot, and checked_at for each gateway check. No matching nodes yields an empty successful response; an unavailable gateway or DB yields 503, not a successful empty list. JSON and CSV include the stable node-<proxy_id> username and derived password. txt uses host:port:username:password (brackets around IPv6), and proxy-url-list-txt emits http:// or socks5h:// gateway links, not upstream provider links. SOCKS5 uses the same node username and password as HTTP. It requires username/password authentication and supports only TCP CONNECT, not no-auth mode, UDP ASSOCIATE, or BIND. The socks5h:// scheme makes the client send the destination hostname to the gateway for resolution.

For example, prepare $gateway_headers in a private directory with one Authorization: Bearer <catalog token> line and mode 0600. Keep every export private, including TXT and CSV. Use a separate curl config at $proxy_client with a line proxy = "<exported proxy URL>" for a selected node. Add proxy_type=socks5 to the catalog query to use the SOCKS5 listener with the same credentials:

umask 077
curl --disable --fail --silent --show-error --noproxy '*' \
  --header "@$gateway_headers" --output "$gateway_export" \
  'http://127.0.0.1:8082/v1/proxies?country=DE,NL&min_speed_mbps=5&sort=latency&format=proxy-url-list-txt'
curl --disable --fail --silent --show-error --noproxy '' \
  --config "$proxy_client" 'http://origin.example/check'
curl --disable --fail --silent --show-error --noproxy '' \
  --config "$proxy_client" 'https://origin.example/check'

Replace the illustrative .example names with your configured operator-owned origins. Never use verbose wire traces or print export contents in shared logs.

Isolated canary and rollback

Run the local contract gate (bash tests/gateway/verify.sh) before a live canary. For the canary, use the same pinned gateway image you intend to deploy, a unique Compose project and database/volume, and a separate protected CANARY_ENV_FILE outside the checkout. Set unused loopback ports (for example 18081/18082/11080), adjust the advertised HTTP port, and use one-off DB credentials and gateway secrets. In a clean shell (no inherited production env overrides), start only the canary database, apply the current schema and grants there, and publish a snapshot containing only your canary peers. The usual checker may publish it on the canary database using a controlled source and probe setup; do not copy a production snapshot or trigger a production checker run.

docker compose --env-file "$CANARY_ENV_FILE" -p gateway-canary up -d postgres
# After the canary DB is healthy, initialize its schema, role and snapshot.
docker compose --env-file "$CANARY_ENV_FILE" -p gateway-canary --profile gateway \
  up -d --no-deps http-gateway

Verify all three listeners and each of SS, Trojan, VMess and VLESS with a dedicated authorized peer. On each route, compare all four filtered export formats, use an exported credential for HTTP and HTTPS via each client-facing proxy type, and match a one-off request nonce to the expected route at your own origin/peer. A 200 or an exit IP alone does not prove routing. Recreate only the gateway and verify the same login still works with the unchanged canary database and node secret. Keep only safe IDs, timings, formats and outcomes in the report. Mark scenarios blocked if an authorized peer or operator-owned origin is unavailable; do not substitute public proxies.

If the gate or canary fails, leave the production profile off. To roll back an enabled gateway, stop just that service (docker compose --profile gateway stop http-gateway, using the same project and env file as the instance) and remove gateway from any startup profile selection. Omitting the profile alone does not stop an existing container. Leave the additive schema and data intact; do not run down -v or restart the checker, API or web to disable this profile.

Operations

Check failures. A failed or cancelled check session does not replace the current snapshot. A proxy is not marked working if its exit IP cannot be verified or it fails a configured latency or speed check. Subscription PATCHes preserve omitted fields, including disabled state, expiry and filters. Send an explicit null to clear an expiry or other nullable limit.

A full cycle skips an unavailable source after recording its fetch or decoding error. If at least one source loads, only candidates from successful sources are checked; nodes exclusive to skipped sources are absent from the new snapshot. If every active source fails to load, the cycle fails without replacing the previous snapshot.

HTTPS probes. Exit IP and speed probes use certificate-verified HTTPS and do not follow redirects. Exit IP discovery requires a successful response containing a single public IP. The speed test requires HTTP 200 with a complete, uncompressed body between 256 KiB and 10 MiB. The old default HTTP speed URL is migrated to the HTTPS Selectel endpoint, with Cloudflare as a fallback. Other HTTP or malformed overrides are ignored; replace them in Settings → Speed test with a working HTTPS endpoint.

Logging and rotation. Treat /sub/<token> URLs like passwords. Serve the panel and feeds over HTTPS outside local development. The API logs registered route templates, not request paths. The bundled nginx access log omits request targets and headers (including Referer), and its error log is discarded. Apply the same policy to any outer reverse proxy, CDN or collector. Updating the application does not sanitize historical logs. If a secret may have appeared in them, restrict access to those logs and rotate it:

  • Subscription URL: revoke a leaked link by disabling or deleting its subscription. Create a replacement with the same filters and update clients.
  • Source or Telegram token: revoke it with its issuer and update the source URL or Telegram notifications token in Settings.
  • Admin credentials: set a new ADMIN_PASSWORD and random SESSION_SECRET in .env, then run docker compose up -d --force-recreate api. Rotating the signing secret invalidates existing sessions.

Development

Backend:

go test ./...
go vet ./...
go run ./cmd/api      # needs DB_DSN, ADMIN_PASSWORD, SESSION_SECRET
go run ./cmd/checker  # needs DB_DSN

Frontend (proxies /api + /sub to localhost:8080):

cd frontend
npm install
npm run dev

CI

.gitea/workflows/ci.yml runs Go validation, the frontend build and the gateway-contract job. Both validation jobs must pass before release builds publish the four service images to the Gitea container registry.

S
Description
No description provided
Readme
1 MiB
0 Stars 1 Watchers 0 Forks
Languages
Go 82.7%
TypeScript 12.2%
PLpgSQL 2.8%
Shell 1.9%
JavaScript 0.2%
Other 0.1%