Forum teuk.org

πŸͺ„ Protego Mbweb: Runtime Partyline, Diagnostics, and Safer Web Console Magic

in Mediabot Β· started by TeuK Β· 5d ago

TeuK Β· 5d ago

Overview

This update continues the hardening and modernization work around Mediabot v3 and its companion web console, mbweb.

The main goal was to make mbweb more useful as a real operational console, while keeping it safer, cleaner, and easier to maintain. The focus was on runtime visibility, better diagnostics, safer session/user payloads, stricter input handling, and reducing confusion between database state and the live Perl bot process.

In short: mbweb now sees more clearly, leaks less, and no longer mistakes shadows in the Pensieve for real Partyline ghosts.


πŸ§™ Major Highlights

1. Real Partyline runtime visibility

The biggest improvement is the new Partyline runtime snapshot.

Previously, the Partyline page could show a runtime count through Prometheus metrics, but it could not list the actual live telnet/DCC sessions. It also risked confusing two different concepts:

  • live Partyline sessions inside the Perl bot process;
  • database-authenticated IRC users based on USER.auth = 1.

That distinction is now explicit.

The Perl bot now writes a runtime JSON snapshot containing only safe operational data:

  • login nickname;
  • level and level description;
  • session type, such as telnet or dcc;
  • console level;
  • peer host;
  • connection/authentication timestamps;
  • session age.

No passwords, no command history, no private command content.

The JSON snapshot was initially tested through /tmp, but systemd isolation made that unreliable for mbweb. The runtime file now lives in:

/run/mediabot/partyline_sessions.json

This is a much cleaner place for inter-service runtime data.

2. mbweb Partyline page now shows real sessions

The Partyline page now reads the runtime JSON snapshot and can display live sessions directly.

It now distinguishes clearly between:

  • Runtime Partyline Sessions β€” live telnet/DCC sessions from the bot process;
  • Metrics fallback β€” Prometheus count, when available;
  • IRC / DB Authenticated Users β€” database authentication state, not live Partyline sessions;
  • Recent Channel Bans β€” recent ban activity from the database.

This fixes the earlier misleading situation where mbweb could show 1 runtime from Prometheus while still showing no session details.

3. Shared runtime path fixed

The runtime snapshot path was moved from:

/tmp/mediabot_partyline_sessions.json

to:

/run/mediabot/partyline_sessions.json

This avoids PrivateTmp issues under systemd and makes the runtime exchange between the Perl bot and mbweb predictable.

The directory is created as:

/run/mediabot

with ownership suitable for the mediabot service user.


πŸ›‘οΈ Security and Safety Improvements

Sanitized authentication logs

The mbweb login logs were cleaned up to avoid writing unnecessary sensitive or personally identifying data.

The logs no longer expose:

  • raw login values;
  • password length;
  • source IP address in normal login traces;
  • internal user IDs;
  • nicknames inside auth result/success logs.

The logs still remain useful for debugging, but now report safer fields such as:

{
  "loginProvided": true,
  "passwordProvided": true
}

and:

{
  "ok": true,
  "method": "mysql-password"
}

Cleaner /api/me and dashboard user payloads

The API responses were adjusted to avoid returning the full session user object.

Instead, mbweb now uses a public session user shape containing only safe UI-level data:

  • nickname;
  • username when available;
  • global level;
  • global role;
  • channel count.

This reduces accidental data exposure if new API endpoints are added later.

Stricter route ID parsing

A new route helper was added for strict route IDs.

Instead of loose parsing like:

Number(req.params.id)

routes can now use strict validation that rejects ambiguous values such as:

1.0
abc
0
-1

This makes URL parameter handling cleaner and more predictable.

Strict environment integer parsing

Configuration parsing was hardened.

The previous parseInt() behavior could accept values such as:

4002abc

as 4002.

mbweb now uses strict integer parsing for important settings such as ports. Invalid values fail loudly at startup instead of silently producing weird behavior.


πŸ“Š Diagnostics and Observability

New Owner-only Diagnostics page

A new /diagnostics page was added for Owner-level users.

It provides quick health checks for:

  • MariaDB connectivity;
  • Prometheus metrics availability;
  • Icecast radio status;
  • integration cache state.

The page intentionally avoids displaying secrets.

Integration cache for metrics and radio

A small runtime cache was added to reduce repeated external calls.

This helps when several pages call the same integrations repeatedly, such as:

  • /partyline;
  • /diagnostics;
  • /radio;
  • /api/radio/status.

The cache is intentionally short-lived, so the UI remains fresh without hammering Prometheus or Icecast.

New cache-related endpoints were also added for Owner-level users:

/api/cache/status
/api/cache/clear

Better metrics diagnostics

Metrics fetch failures now include the target URL and useful network cause information, without exposing secrets.

This makes it much easier to distinguish between:

  • wrong URL;
  • connection refused;
  • timeout;
  • unreachable endpoint;
  • invalid metrics response.

πŸ“» Radio and Icecast Improvements

Radio handling was made stricter and safer.

Improvements include:

  • safer public listen URL generation;
  • validation of http:// and https:// bases;
  • normalized mount paths;
  • response size limits;
  • clearer handling of empty or invalid JSON responses;
  • less leakage of raw exception messages to API clients.

The radio API now behaves more like an operational endpoint rather than a raw proxy.


🧩 Code Organization Improvements

Public session user helper

A shared publicSessionUser() helper was added so routes do not reinvent their own session payload shape.

This helps prevent future accidental exposure of internal session fields.

Runtime and integration cache helpers

New helper modules were added:

lib/runtimeCache.js
lib/integrationCache.js
lib/partylineRuntime.js

Their purpose is simple:

  • runtimeCache.js provides a small generic TTL cache;
  • integrationCache.js wraps cached metrics/radio access;
  • partylineRuntime.js reads and sanitizes the Partyline runtime JSON snapshot.

Partyline runtime export in Perl

Mediabot::Partyline now has helper methods for runtime export:

  • runtime status path resolution;
  • payload construction;
  • atomic JSON write;
  • write after authentication;
  • write after session close.

This gives mbweb a proper bridge to the bot runtime without scraping logs or touching process memory.


πŸ§ͺ Validation

The work was validated through several layers:

  • Node syntax checks on all mbweb JavaScript files;
  • Perl syntax checks on modified Mediabot modules;
  • direct runtime reader checks from mbweb;
  • browser validation of the Partyline page;
  • service restarts through systemd;
  • real telnet Partyline login checks;
  • verification that the runtime JSON snapshot is written and readable.

Example runtime snapshot:

{
  "ok": 1,
  "count": 1,
  "sessions": [
    {
      "login": "teuk",
      "level_desc": "Owner",
      "session_type": "telnet",
      "peer_host": "localhost"
    }
  ]
}

πŸͺ„ Commit Theme

Suggested commit message:

πŸͺ„ Revelio Partyline: teach mbweb to see live sessions and guard its secrets

Alternative:

πŸ§™ Mischief managed: mbweb now sees Partyline ghosts through the proper portal

Final Notes

This update turns mbweb into a more serious operational companion for Mediabot v3.

The web console now has better runtime awareness, cleaner diagnostics, safer logs, stricter inputs, and a clearer separation between database state and live bot state.

Most importantly, the Partyline page now tells the truth: a live telnet session is no longer just a metric shadow β€” it can be seen directly through the runtime snapshot.

Mischief managed.

You must be logged in to reply.