scorpiox-bot-plugin-netcheck

scorpiox-bot-plugin-netcheck

main1 branch · 0 tags
VS Code
HTTPS
ForkDelete
Recent Commits
README

netcheck — Network Diagnostics From This Node

Binary: plugin_netcheck · Slug: netcheck · Category: network · License: MIT

A zero-dependency, single-binary SCORPIOX BOT plugin that runs network

diagnostics on the node it is installed on and shows the result in a dark /

light panel that looks like part of SCORPIOX BOT.

Action Query What it does
ifaces ?action=ifaces Lists every interface with its address, netmask, broadcast, family and up/down state, plus the configured DNS servers.
dns ?action=dns&host=example.com Resolves a name through the node's resolver with a 3 s deadline and reports every address.
tcp ?action=tcp&host=example.com&port=443 Three non-blocking connects, reported as samples plus min / avg / max.
http ?action=http&url=http://example.com/ One HEAD request over plain TCP. Status line and header count only — the body is never read and redirects are never followed.
info ?action=info Plugin identity, the action list and the configured deadlines.

GET with no action serves the HTML panel.

Why this plugin

When a node is unreachable from the bot, the useful question is never "is the

bot down" but "what does this node see": which interfaces are up, what the

resolver returns, whether a port is actually accepting, and whether a URL

answers. netcheck answers all four from inside the node, in one binary, with no

curl, no dig, no ping, no ss, and no TLS library.

The no-TLS contract

There is no TLS library anywhere in the binary, so an https:// target cannot

be handshaken. netcheck does the only thing it honestly can — a TCP connect to

port 443 — and reports "tls":"not_checked" with a note saying the handshake

was not attempted. It never pretends to have validated a certificate.

Security model

netcheck is a node-owner's tool, and it is the plugin that makes connections,

so the surface is deliberately small:

  • Node auth required. Every action sits behind require_node_auth(), which

accepts X-Bot-Password, Authorization: Bearer <pwd>, or ?pwd= and is a

no-op only when BOT_PASSWORD is unset. --meta stays unauthenticated so

discovery still works. An unauthenticated curl to /plugin_netcheck must

return 401.

  • Host validation. A typed host is accepted only as a DNS hostname label

sequence or a literal IPv4 / IPv6 address (inet_pton). Shell

metacharacters, slashes, spaces and punctuation are refused with 400.

  • Port validation. 1–65535, digits only.
  • URL validation. http:// or https:// only; the scheme, host, port, path

and query are parsed by hand, userinfo is stripped, and the path must begin

with /.

  • Hard deadlines. 3 s for resolution, 3 s per connect, 2 s for the HTTP read.

A typed host cannot make the plugin hang.

  • Body never read. The HTTP probe sends HEAD and stops reading at the end

of the header block, so a 50 GB page costs the same as a 1 KB one.

  • No redirects. A 3xx is reported with "redirect":"not_followed".
  • One request per call. No retries on the HTTP path; the TCP path takes

exactly three samples of the same target.

The trust notice on the card and in plugin.json says it plainly: this plugin

opens exactly the outbound connections you ask for.

Build

make            native build        -> ./plugin_netcheck
make musl       static musl x86_64  -> ./plugin_netcheck.musl
make arm64      static aarch64      -> ./plugin_netcheck.arm64
make win64      MinGW-w64 static    -> ./plugin_netcheck.exe
make macos      Apple clang         -> ./plugin_netcheck   (run on macOS)
make ui         regenerate src/ui_html.h from src/ui.html
make test       build + tests/run.sh
make e2e        build + tests/e2e.py (Playwright)
make clean

On Windows use powershell -ExecutionPolicy Bypass -File build.ps1; it

regenerates the page header, compiles a static PE, and refuses to emit anything

that is not a real MZ executable.

The resolver deadline runs in a worker thread, so every POSIX leg links

-lpthread (musl and macOS carry pthread inside libc). Windows links

-lws2_32 -liphlpapi.

The page

src/ui.html is the readable source of the panel; tools/gen_ui.py compiles it

into src/ui_html.h with two control-byte placeholders that expand into the

bot's theme macros, so the page can never drift from the palette SCORPIOX BOT

actually uses. The theme is decided before first paint in the order

?theme= → localStorage.bot_theme → prefers-color-scheme, and the page

follows the bot's sx-theme postMessage without a reload. Its own toggle is

hidden under ?embed=1.

No <script src=>, no CDN, no emoji, no web fonts. The latency sparkline is a

hand-drawn SVG polyline built from the TCP samples in the page — no chart

library, no network request.

Tests

tests/run.sh is fully offline: the resolver, the interface table and the

outbound connect are replaced by three environment hooks the plugin exposes for

exactly this purpose, and the TCP/HTTP legs talk to throwaway listeners started

by tests/mockd.py on 127.0.0.1.

NETCHECK_MOCK_IFACES  "lo|127.0.0.1|255.0.0.0|127.0.0.1|4|1,eth0|..."
                      name|address|netmask|broadcast|family|up
NETCHECK_MOCK_DNS     "host=addr,addr;host2=addr"
NETCHECK_MOCK_TIMEOUT 1        -> every resolution reports a deadline miss

On a real node none of these are set, so the hooks are never consulted.

tests/e2e.py drives the page with Playwright at 1440 / 1024 / 390 CSS pixels

in both themes and asserts there is no horizontal overflow and no console error.

Screenshots

docs/ holds the panel at 1440, 1024 and 390 px in dark and light.

netcheck at 1440 dark

Sibling plugins

netcheck is part of the SCORPIOX BOT open-source plugin family published to

https://dist.scorpiox.net/bot-plugins/ and mirrored to

https://plugingit.scorpiox.net/. See release-dist.sh for the six-target

release recipe (linux x86_64 glibc + musl, arm64 musl, macOS arm64 + x86_64,

Windows x86_64) plus source.tar.gz.