# plugin_logs — SCORPIOX BOT local log viewer A read-only local **log tail and search** viewer for SCORPIOX BOT nodes, in one zero-dependency C99 binary. It reads an explicit allowlist of local log files and the local system journal, renders a responsive dark/light panel with severity colouring and hit highlighting, and never writes anything or opens a network socket. ``` ┌──────────────────────── plugin_logs ────────────────────────┐ ?action= │ sources list what can be read (journal / *.log / eventlog) │ JSON API │ tail last N entries of one source │ │ search case-insensitive substring search over one source │ │ units systemd units that have journal entries │ │ info plugin info, caps, auth state │ └─────────────────────────────────────────────────────────────┘ GET → HTML viewer (?embed=1 for the Chat floating window) ``` ## What it reads | Platform | Sources | |---|---| | Linux | `journalctl -o json` (system journal and `journal:`); `*.log` directly under `/var/log`, plus `syslog`, `messages`, `kern.log`, `auth.log`; `$HOME/.scorpiox/**/*.log` and `/workspace/**/*.log` to depth 4 | | macOS | `log show --style compact --last ` (bounded to 60 min); `*.log` directly under `/var/log`, `system.log`; `~/Library/Logs/**/*.log` to depth 3 | | Windows | `wevtutil qe System\|Application /f:text` (fixed argv); `%LOCALAPPDATA%\scorpiox\**\*.log` to depth 4 | Nothing else is readable. A request for `file:/etc/passwd`, a directory, or an id that is not in the current `action=sources` answer is refused with `source_not_allowed` — the allowlist is the return value of the same walk the UI is given, so there is no second path to a file. Every walk has **its own** entry budget. `/workspace` being enormous cannot consume the allowance that `$HOME/.scorpiox` needs, and `action=sources` reports `truncated: true` instead of pretending the short list is complete. Symlinks are never followed. ## What it never does * **No writes.** Files are opened `rb`. Nothing is rotated, truncated or created. * **No sockets.** No `curl`, no HTTP client, no listening socket. The plugin is a CGI-style executable; the node's server owns the socket. * **No user-controlled shell.** Only `journalctl` and `wevtutil` are invoked, from fixed `snprintf` format strings. A systemd unit name must pass `[A-Za-z0-9@._-]{1,128}` and may not start with `-`, so it can never become an option or a shell word. * **No whole-file reads.** A tail starts at most 4 MB before EOF and drops the first partial line; searches stop after 8 000 lines and 500 hits. ## Build ```sh make # native -> ./plugin_logs make musl # static musl x86_64 (the universal Linux artifact) make arm64 # static aarch64 (Pi 5 / ARM64 servers) make win64 # static PE via MinGW-w64 -> plugin_logs.exe make macos # Apple clang, run this on the Mac make test # build + offline checks ``` On Windows, `build.ps1` wraps the MinGW build and verifies the `MZ` header. ## Deploy Copy the binary into the node's plugin dir and it is live immediately — no server restart: ```sh install -m 0755 plugin_logs ~/.scorpiox/plugins/plugin_logs ``` The plugin appears in the Plugins list and is served at `/plugin_logs` (GET for the viewer, `?action=…` for JSON). One-click install from the market writes a `plugin_logs.manifest.json` sidecar with the source commit and the artifact SHA-256. ## Node API All actions except `--meta` require the node password when `BOT_PASSWORD` is set — `X-Bot-Password`, `Authorization: Bearer `, or `?pwd=` (what the plugin iframe appends). With no `BOT_PASSWORD` the plugin is a deliberate no-op so it can be run from a shell. ``` ?action=sources { "ok":true, "journal_available":true, "count":5, "truncated":false, "sources":[ {"id":"journal","label":"System journal","kind":"journal","size":0,"mtime":0}, {"id":"file:/var/log/dpkg.log","label":"dpkg.log","kind":"file", "size":958818,"mtime":1773629060} ] } ?action=tail&src=journal&lines=200 { "ok":true, "src":"journal", "count":2, "entries":[ {"ts":"11-12 04:50:01","unit":"nginx.service","sev":"err", "text":"upstream timed out"} ] } ?action=search&src=file:/var/log/dpkg.log&q=install { "ok":true, "scanned":8000, "count":500, "max":500, "truncated":true, "hits":[ … ] } ?action=units { "ok":true, "available":true, "count":3, "units":[ {"name":"nginx.service","src":"journal:nginx.service"} ] } ``` `sev` is `info`, `warn` or `err`. On Linux it comes from the journal `PRIORITY` field; everywhere it falls back to a keyword heuristic over the message text (`panic`, `fatal`, `error`, `failed`, `denied` → err; `warn`, `deprecated`, `timeout`, `retry` → warn). ## UI * Source picker grouped by kind, with file sizes. * Line count 100 / 200 / 500 / 2000. * **Follow** polls every 3 s and pauses while the tab is hidden. * Search box with inline `` highlighting of every hit. * **Wrap** for long stack traces, **Copy** to copy the visible entries, **Reload** to re-walk the source list. * Severity colouring: left border and text tint for `err` / `warn`. * Dark and light from the shared SCORPIOX BOT theme tokens, so it matches the bot in a hub modal, a session card and the Chat floating window. `?theme=` decides before first paint; a `{type:'sx-theme'}` post from the host is followed without a reload. * Fluid at 1440 / 1024 / 390 px and inside the Chat floating window, no `