scorpiox-bot-plugin-services

scorpiox-bot-plugin-services

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

plugin_services — local service status board for SCORPIOX BOT

services is a zero-dependency C99 plugin that shows every service your node's

init system manages — state, enabled flag, PID, memory and uptime — in a

responsive dark/light board inside SCORPIOX BOT, and optionally starts, stops or

restarts one.

$ ./plugin_services --meta
{"name":"services","desc":"System services"}

What it reads

Platform Source Detail
Linux systemctl list-units --type=service --all --output=json falls back to the plain table on systemd < 248, then to list-unit-files; one systemctl show … -p Id -p MainPID -p ActiveEnterTimestamp -p MemoryCurrent -p UnitFileState … pass fills PID / memory / since / enabled
Linux (no init) /proc/<pid>/{comm,stat,statm} + /proc/uptime in a container with no systemd it reports "init_system":"none" and lists the daemons that have been up ≥ 5 minutes, with their RSS and uptime
macOS launchctl list pid / status / label, with RSS and start time from one ps -o pid=,rss=,lstart= pass
Windows OpenSCManagerA + EnumServicesStatusExA + QueryServiceConfigA no shell, no popen, no service name on a command line

Nothing is written. Nothing is fetched. The binary opens no socket of any kind.

API

All actions are behind node auth — X-Bot-Password, Authorization: Bearer …,

or ?pwd= — and auth is a no-op only when BOT_PASSWORD is unset on the node.

Action Method Response
`?action=list[&filter=failed\running\inactive\all]` GET {"ok":true,"init_system":"systemd","control_enabled":false,"count":4,"summary":{"running":2,"failed":1,"inactive":1},"services":[…]}
?action=show&unit=nginx.service GET {"ok":true,…,"service":{…}} or 404
`?action=control&unit=nginx.service&op=start\stop\restart` POST {"ok":true,"unit":"…","op":"…","control_enabled":true}

Each service object is:

{"name":"nginx.service","description":"A high performance web server",
 "active":"active","sub":"running","enabled":"enabled",
 "pid":4242,"memory_bytes":10485760,"since":"Wed 2026-11-12 04:00:00 UTC",
 "failed":false}

memory_bytes is null when the platform does not report it (or when systemd

returns its 18446744073709551615 sentinel). Rows are sorted failed → running →

inactive, then by name.

Control is off unless the operator turns it on

The plugin is read-only by default. Start / stop / restart exist only when

the node sets:

SERVICES_ALLOW_CONTROL=1

Without it every control request is 403 {"error":"control_disabled"} and the

page does not render the buttons at all (it reads control_enabled from the

list response, so the UI can never show a button that would fail).

When it is enabled:

  • the unit name must match [A-Za-z0-9@._:\-]{1,160} — a;reboot, $(id), a

newline, ../../etc/passwd and -oProxyCommand=x are all a `400 invalid

unit`, before anything is executed;

  • the name is passed to execvp("systemctl", {"systemctl", op, unit, NULL}) as a

separate argv element. No shell is ever involved, on any platform;

  • on Windows it is OpenServiceA + StartServiceA / ControlService(STOP).

No command line exists to escape from;

  • on macOS it is launchctl kickstart -k <label> / launchctl stop <label>.

Every control click is behind a window.confirm() dialog that names the unit.

HTML UI

GET /plugin_services serves one self-contained page:

  • summary chips — All / Running / Failed / Inactive — that double as filters;
  • failed-first sort, plus sort by name or state, and a search box over name and

description;

  • a per-row detail drawer with state, sub-state, enabled flag, PID, memory and

since, and the control buttons when the node allows them;

  • dark + light from the bot's own theme tokens (?theme= → localStorage.bot_theme

→ prefers-color-scheme, then {type:'sx-theme'} posts from the host), so it

looks like part of SCORPIOX BOT rather than a separate app;

  • fluid at 1440 / 1024 / 390 px and inside the Chat floating window

(?embed=1 hides the back link and the theme toggle);

  • no <script src=>, no CDN, no web fonts, zero emojis — inline SVG only.

The route branching is the hub-vs-direct rule: when the page is served through

the hub (?plugin=…) it calls back through /plugins?plugin=…&action=…; opened

directly on the node it calls /plugin_services?action=…. Calling

/plugins?plugin= on the node itself returns the discovery list, not this plugin.

Build

make            # native  -> ./plugin_services
make musl       # static musl x86_64 -> ./plugin_services.musl
make arm64      # static aarch64    -> ./plugin_services.arm64
make win64      # MinGW-w64 static  -> ./plugin_services.exe  (needs -ladvapi32)
make macos      # Apple clang       -> ./plugin_services
make test       # build + tests/run.sh

plugin.json carries "ldflags_win64": ["-ladvapi32"] so the

scorpiox-cli-botplugin publisher links the Windows slice correctly.

The Windows source needs #define _WIN32_WINNT 0x0601 before any include —

MinGW defaults to 0x502 (Server 2003), which hides EnumServicesStatusExA and

QueryServiceConfigA. The macOS source needs _DARWIN_C_SOURCE. Both are set at

the top of src/plugin_services.c.

Tests

sh tests/run.sh          # 170+ offline assertions, no network, no live systemd
python3 tests/e2e.py     # Playwright at 1440 / 1024 / 390, dark + light

The offline suite drives the parsers from fixtures

(SERVICES_MOCK_SYSTEMCTL, SERVICES_MOCK_SYSTEMCTL_SHOW,

SERVICES_MOCK_LAUNCHCTL, SERVICES_MOCK_PROC_DIR) so systemd JSON, the legacy

plain table, launchctl and the no-init /proc path are all exercised on any

host. It also asserts the injection negatives, the control gating, the

_FORTIFY_SOURCE=2 build, and audits the whole git history for secrets and

internal addresses.

Permissions

capabilities: service_list, service_control_optional.

Reads: the platform service manager, /proc on Linux, launchctl list / ps

on macOS, the SCM on Windows. Writes: nothing. Network: none.

MIT License. Copyright (c) 2026 SCORPIOX INC.