diff --git a/.relay.laantungir.net.keys b/.relay.laantungir.net.keys new file mode 100644 index 0000000..457824b --- /dev/null +++ b/.relay.laantungir.net.keys @@ -0,0 +1,2 @@ +ADMIN_PUBKEY='6a04ab98d9e4774ad806e302dddeb63bea16b5cb5f223ee77478e861bb583eb3' +SERVER_PRIVKEY='1111111111111111111111111111111111111111111111111111111111111111' diff --git a/=4 b/=4 deleted file mode 100644 index e69de29..0000000 diff --git a/plans/relay_admin_migration_plan.md b/plans/relay_admin_migration_plan.md new file mode 100644 index 0000000..3568508 --- /dev/null +++ b/plans/relay_admin_migration_plan.md @@ -0,0 +1,297 @@ +# Relay Admin Page Migration Plan + +## Goal + +Migrate the relay admin functionality from the internally-served `api/index.html` + `api/index.js` (served by the C relay binary) to an externally-hosted `relay-admin.html` page in the `client-ndk` project. This page uses the NDK SharedWorker architecture (template.html pattern) and communicates with the relay via kind 23456/23457/24567 Nostr events. + +## Current State + +### Working Reference: [`c-relay-pg.html`](/home/user/lt/client-ndk/www/c-relay-pg.html) +- Successfully receives kind 24567 monitoring events +- Has `SUBSCRIPTION_ONLY_MODE = true` — admin UI actions are disabled +- Contains all admin section HTML (Statistics, Subscriptions, Configuration, Authorization, IP Bans, Relay Events, DM, Database Query) +- Has sidenav with admin page links +- Has `sendAdminCommand()`, `encryptForRelay()`, `decryptFromRelay()`, `fetchRelayInfo()` functions +- Has `handleMonitoringEvent()` and `handleAdminResponse()` event handlers + +### Target File: [`relay-admin.html`](/home/user/lt/client-ndk/www/relay-admin.html) +- Currently an exact copy of `template.html` +- Has full template infrastructure: hamburger menu, sidenav, footer, auth system, relay-ui, blossom-ui, ai-ui +- Has the newer `injectHeaderLoginButton` import (slightly newer than c-relay-pg.html) +- Empty `divBody` — ready for admin content + +### Legacy Internal Pages: [`api/index.html`](api/index.html) + [`api/index.js`](api/index.js) +- 6,779 lines of JavaScript — the full admin UI +- Uses `nostr-tools SimplePool` directly (not NDK) +- Uses `NOSTR_LOGIN_LITE` for auth (not NDK SharedWorker) +- Has rich UI: config tables with inline editing, IP ban management with filters, SQL query console with history, WoT management, relay event forms +- All admin commands go through `sendAdminCommand()` → kind 23456 with NIP-44 encryption +- Responses come back as kind 23457 events, decrypted and routed to handlers + +## Architecture Comparison + +```mermaid +graph TD + subgraph Legacy - api/index.html + A1[NOSTR_LOGIN_LITE auth] --> A2[SimplePool direct WS] + A2 --> A3[Kind 23456 admin commands] + A2 --> A4[Kind 24567 monitoring sub] + A3 --> A5[Kind 23457 responses] + end + + subgraph New - relay-admin.html + B1[NDK SharedWorker auth] --> B2[NDK subscribe/publishEvent] + B2 --> B3[Kind 23456 admin commands] + B2 --> B4[Kind 24567 monitoring sub] + B3 --> B5[Kind 23457 responses] + end +``` + +### Key Difference: NDK vs SimplePool + +| Aspect | Legacy api/index.js | New relay-admin.html | +|--------|-------------------|---------------------| +| Auth | `NOSTR_LOGIN_LITE` direct | `initNDKPage()` via SharedWorker | +| Subscriptions | `SimplePool.subscribeMany()` | `subscribe()` from init-ndk.mjs | +| Publishing | `SimplePool.publish()` + manual signing | `publishEvent()` — auto-signed by worker | +| Encryption | `window.nostr.nip44.encrypt/decrypt` | Same — `window.nostr.nip44.encrypt/decrypt` | +| Event listening | SimplePool callbacks | `window.addEventListener('ndkEvent', ...)` | +| Relay URL | Auto-derived from page URL | Configurable constant `ADMIN_RELAY_WS_URL` | + +## Migration Strategy + +The approach is to merge the admin functionality from `c-relay-pg.html` into `relay-admin.html`, removing the `SUBSCRIPTION_ONLY_MODE` restriction and enabling full admin UI. We use the NDK `publishEvent()` and `subscribe()` APIs instead of SimplePool. + +### What stays from template (relay-admin.html already has) +- Full hamburger menu + sidenav infrastructure +- Footer with relay status animations +- Auth system with required/optional/none modes +- Relay-ui, blossom-ui, ai-ui sidenav sections +- Theme toggle, logout, version display + +### What gets added from c-relay-pg.html +- Admin nav items in sidenav +- Admin section HTML panels in divBody +- Admin-specific CSS styles +- Relay pubkey fetch via NIP-11 +- NIP-44 encrypt/decrypt helpers +- `sendAdminCommand()` for kind 23456 +- Kind 24567 monitoring subscription +- Kind 23457 response handling with per-section routing +- All admin UI button handlers +- Boot diagnostics panel +- System info panel + +## Detailed Implementation Steps + +### Step 1: Add Admin Nav Links to Sidenav + +The admin links go directly inside `divSideNavBody` as simple styled items — **not** inside a collapsible `.sidenavSection` container. They should be always-visible, non-collapsible links that match the font/styling of the sidenav sections but remain in the open body area. Place them before `divFiles`: + +```html +
+ +
+
Statistics
+
Subscriptions
+
Configuration
+
Authorization
+
IP Bans
+
Relay Events
+
DM
+
Database Query
+
+
+
+``` + +The `.adminNavItem` styling uses the same font-family and sizing as sidenav section content (`font-size: 70%`, `font-family: var(--font-family)`) with a simple border-bottom separator, hover accent color, and bold+background for the active state. No section title header, no collapse toggle icon. + +### Step 2: Add Admin Section HTML Panels + +Port the section HTML from `c-relay-pg.html` into `divBody`. Each section follows the pattern: + +```html +
+
{Title}
+ +
+``` + +Sections to port: +1. **Statistics** — CPU metrics, time stats, top pubkeys, event kinds cards +2. **Subscriptions** — Subscription details log +3. **Configuration** — Config key/value inputs, fetch/set buttons, log +4. **Authorization** — Pubkey input, whitelist/blacklist/query buttons, log +5. **IP Bans** — IP input, duration, ban/query buttons, log +6. **Relay Events** — Kind 0 metadata form, live event feed +7. **DM** — Message textarea, send button, log +8. **Database Query** — SQL textarea, run button, log +9. **System** (always visible) — Relay WS/HTTP URLs, relay/user pubkeys +10. **Boot Diagnostics** (always visible) — Boot log + +### Step 3: Add Admin CSS + +Port the admin-specific styles from `c-relay-pg.html` `