End-to-end shared buckets between relay tenants. Bucket metadata + members sync through new relay routes (collab-buckets, collab-cards, collab-locks); card content rides the existing inter-tenant encryption hop. Edit locks, ownership transfer, LWW conflict stashing, undo for local-bucket destructive actions, "Make collaborative…" upgrade path, and a resilient outbox for relay-down create attempts. See plugins/collab-buckets/README.md and TODO.md for the full picture. Core hooks added so the plugin can integrate without monkey-patching: - buckets.js context menu: collab-aware rename/color/delete + Members & owner / Make collaborative entries - editor.js dispatches hyprcrd:editor-open / hyprcrd:editor-close for the per-card edit-lock heartbeat - app.js exposes window.state for the plugin's MutationObserver - index.php POST/PATCH/DELETE on /api/buckets refuse to mutate collab buckets directly (must go through the relay) - Database.php adds buckets.collab_uid column + unique partial index - import handler now restores color and collab_uid (was silently dropping color, which caused the test runner's auto-restore to wipe custom bucket colors) - relay bootstrap creates collab_buckets, collab_bucket_members, collab_cards, collab_card_locks tables and prunes tombstones / expired locks on every request Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
75 lines
3.4 KiB
PHP
75 lines
3.4 KiB
PHP
<?php
|
|
// ── hyprcrd Relay — Multi-tenant ──
|
|
//
|
|
// Entry point. Loads bootstrap + helpers, dispatches API routes,
|
|
// renders the UI layout. The actual logic lives in inc/ and ui/.
|
|
//
|
|
// Architecture (encryption flow for cross-tenant messages):
|
|
// 1. Client A encrypts a message with A's tenant secret
|
|
// 2. POST /api/messages, server authenticates A, decrypts with A's secret
|
|
// 3. Server re-encrypts with the inter-tenant key (relay-wide shared
|
|
// key, generated at install, stored encrypted with the master key)
|
|
// 4. Stored in messages table with recipient_id = B's tenant id
|
|
// 5. B fetches /api/messages, server decrypts with inter-tenant key,
|
|
// re-encrypts with B's tenant secret, returns to client B
|
|
// 6. Client B decrypts with its own secret
|
|
//
|
|
// The relay sees plaintext briefly during the cross-tenant hop. This
|
|
// is not strict end-to-end — that requires per-pair key exchange and
|
|
// is on the roadmap for the planned encrypted chat feature. See
|
|
// README.md.
|
|
|
|
define('RELAY_BOOTSTRAPPED', true);
|
|
|
|
require_once __DIR__ . '/inc/bootstrap.php';
|
|
require_once __DIR__ . '/inc/crypto.php';
|
|
require_once __DIR__ . '/inc/tenants.php';
|
|
require_once __DIR__ . '/inc/auth.php';
|
|
|
|
// ── Routing ────────────────────────────────────────────────────────
|
|
|
|
$route = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
$base = dirname($_SERVER['SCRIPT_NAME']);
|
|
if ($base !== '/') $route = substr($route, strlen($base));
|
|
$route = '/' . ltrim($route ?: '/', '/');
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
|
|
$isSetup = tenantCount($db) === 0;
|
|
|
|
// ── API ────────────────────────────────────────────────────────────
|
|
|
|
if (str_starts_with($route, '/api/')) {
|
|
header('Content-Type: application/json');
|
|
$origin = $_SERVER['HTTP_ORIGIN'] ?? '';
|
|
if ($origin) {
|
|
header('Access-Control-Allow-Origin: ' . $origin);
|
|
header('Access-Control-Allow-Credentials: true');
|
|
header('Vary: Origin');
|
|
}
|
|
header('Access-Control-Allow-Headers: Content-Type, X-Relay-User, X-Relay-Key');
|
|
header('Access-Control-Allow-Methods: GET, POST, PATCH, DELETE, OPTIONS');
|
|
if ($method === 'OPTIONS') exit;
|
|
|
|
$contentLength = (int)($_SERVER['CONTENT_LENGTH'] ?? 0);
|
|
$sizeLimit = ($route === '/api/attachments') ? 15728640 : 262144;
|
|
if ($contentLength > $sizeLimit) jsonResponse(['error' => 'payload too large'], 413);
|
|
|
|
// Each route file contains its handlers as if-blocks that exit on
|
|
// match. Order matters: public.php sets up $sessionTenant which
|
|
// admin.php and messages.php use later in the chain.
|
|
require __DIR__ . '/inc/routes/public.php';
|
|
require __DIR__ . '/inc/routes/account.php';
|
|
require __DIR__ . '/inc/routes/admin.php';
|
|
require __DIR__ . '/inc/routes/messages.php';
|
|
require __DIR__ . '/inc/routes/chat.php';
|
|
require __DIR__ . '/inc/routes/collab-buckets.php';
|
|
require __DIR__ . '/inc/routes/collab-cards.php';
|
|
require __DIR__ . '/inc/routes/collab-locks.php';
|
|
|
|
jsonResponse(['error' => 'not found'], 404);
|
|
}
|
|
|
|
// ── UI ─────────────────────────────────────────────────────────────
|
|
|
|
require __DIR__ . '/ui/layout.php';
|