SPB Git

Repository Public

main.tsx 7.2 KB 131 lines tsx

1/**2 * =============================================================================3 *                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : MacLustr SMS Gateway8 * File             : dashboard/src/main.tsx9 * Module           : dashboard10 * Repository       : https://git.spboucher.ai/maclustr-sms11 * Project Website  : https://sms.spboucher.ai12 * Created          : 2026-11-3013 * Last Modified    : 2026-11-3014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { startAuthentication, startRegistration } from "@simplewebauthn/browser"43import { StrictMode, useEffect, useState } from "react"44import { createRoot } from "react-dom/client"45import { closeStream, get, post, useData } from "./api.ts"46import { Analytics, AuditLogs, Documentation } from "./pages/insight.tsx"47import { AndroidDownload, ApiKeys, Settings, Webhooks } from "./pages/manage.tsx"48import { Conversations, Messages, Queue } from "./pages/messages.tsx"49import { Devices, Overview, SimCards } from "./pages/network.tsx"50import "./styles.css"51import { Link, useAction } from "./ui.tsx"5253const NAV: [string, string, () => React.JSX.Element][] = [54  ["/", "Overview", Overview], ["/messages", "Messages", Messages], ["/conversations", "Conversations", Conversations], ["/devices", "Devices", Devices],55  ["/sims", "SIM Cards", SimCards], ["/queue", "Queue", Queue], ["/api-keys", "API Keys", ApiKeys], ["/webhooks", "Webhooks", Webhooks], ["/analytics", "Analytics", Analytics],56  ["/audit", "Audit Logs", AuditLogs], ["/settings", "Settings", Settings], ["/docs", "Documentation", Documentation], ["/apps", "Android Download", AndroidDownload],57]58const ALIAS: Record<string, string> = { "/android": "/apps", "/app": "/apps" }5960function usePath() {61  const [p, setP] = useState(location.pathname)62  useEffect(() => { const f = () => setP(location.pathname); window.addEventListener("popstate", f); return () => window.removeEventListener("popstate", f) }, [])63  return ALIAS[p] ?? p64}6566function Login({ onDone }: { onDone: () => void }) {67  const a = useAction()68  const login = () => a.run(async () => {69    const o = await post("/api/auth/login/options")70    await post("/api/auth/login/verify", { challenge_id: o.challenge_id, response: await startAuthentication({ optionsJSON: o.options }) })71    onDone()72  })73  return <div className="center"><div className="panel">74    <img src="/icon.svg" width={48} height={48} alt="" />75    <h1 style={{ margin: "14px 0 4px" }}>MacLustr SMS</h1>76    <p className="muted" style={{ margin: "0 0 22px" }}>Passerelle SMS privée — accès réservé</p>77    <button className="primary" disabled={a.busy} onClick={login} style={{ width: "100%", padding: "10px" }}>Se connecter avec une clé d'accès</button>78    {a.error && <p className="err">{a.error}</p>}79  </div></div>80}8182/** Enrôlement : lien à usage unique émis par la CLI opérateur (jeton dans le fragment d'URL, jamais envoyé dans une URL). */83function Enroll({ onDone }: { onDone: () => void }) {84  const a = useAction()85  const token = location.hash.slice(1)86  const go = () => a.run(async () => {87    const o = await post("/api/auth/enroll/options", { token })88    const response = await startRegistration({ optionsJSON: o.options })89    await post("/api/auth/enroll/verify", { token, challenge_id: o.challenge_id, response, label: navigator.platform || "Clé d'accès" })90    history.replaceState(null, "", "/"); onDone()91  })92  return <div className="center"><div className="panel">93    <img src="/icon.svg" width={48} height={48} alt="" />94    <h1 style={{ margin: "14px 0 4px" }}>Enregistrer une clé d'accès</h1>95    <p className="muted" style={{ margin: "0 0 22px" }}>Ce lien ne fonctionne qu'une fois. La clé d'accès (Touch ID, Face ID, clé de sécurité) remplacera tout mot de passe.</p>96    <button className="primary" disabled={a.busy || !token} onClick={go} style={{ width: "100%", padding: "10px" }}>Créer ma clé d'accès</button>97    {!token && <p className="err">Lien incomplet.</p>}{a.error && <p className="err">{a.error}</p>}98  </div></div>99}100101function Shell({ me, onLogout }: { me: any; onLogout: () => void }) {102  const path = usePath()103  const { data: o } = useData<any>("/api/admin/overview", ["messages", "devices", "queue", "settings"])104  const current = NAV.find(([p]) => p === path) ?? NAV.find(([p]) => p !== "/" && path.startsWith(p + "/"))105  const View = current?.[2]106  const counts: Record<string, number> = { "/queue": (o?.queue.pending ?? 0) + (o?.queue.in_flight ?? 0) + (o?.queue.held ?? 0) }107  return <div className="shell">108    <aside className="side">109      <div className="brand"><img src="/icon.svg" alt="" /><div>MacLustr SMS<small>sms.spboucher.ai</small></div></div>110      <nav className="nav">{NAV.map(([p, label]) => <Link key={p} to={p} className={current?.[0] === p ? "on" : ""}><span>{label}</span>{counts[p] ? <span className="count">{counts[p]}</span> : null}</Link>)}</nav>111      <div className="foot">{me.user.display_name}<br /><a href="#" onClick={e => { e.preventDefault(); onLogout() }}>Se déconnecter</a>{o && <><br /><span className="mono">v{o.version}</span></>}</div>112    </aside>113    <main className="main">114      {o?.kill_switch && <div className="banner"><span><strong>Arrêt d'urgence actif.</strong> Aucun SMS n'est accepté ni transmis.</span><Link to="/settings" className="btn">Réglages</Link></div>}115      {View ? <View /> : <div className="empty">Page introuvable.</div>}116    </main>117  </div>118}119120function App() {121  const [me, setMe] = useState<any | null | undefined>(undefined)122  const load = () => get("/api/auth/me").then(setMe).catch(() => setMe(null))123  useEffect(() => { void load(); const f = () => { closeStream(); setMe(null) }; window.addEventListener("mlsms:unauthenticated", f); return () => window.removeEventListener("mlsms:unauthenticated", f) }, [])124  if (me === undefined) return null125  if (location.pathname === "/enroll" && !me) return <Enroll onDone={load} />126  if (!me) return <Login onDone={load} />127  return <Shell me={me} onLogout={async () => { await post("/api/auth/logout"); closeStream(); setMe(null) }} />128}129130createRoot(document.getElementById("root")!).render(<StrictMode><App /></StrictMode>)131
Files main
Menu

Theme