Console d'administration séparée, joignable seulement par Tailscale
deploy / deploy (push) Successful in 48s
deploy / deploy (push) Successful in 48s
- Site à part (admin/, build:admin → dist-admin/), jamais dans l'app publique : tableau de bord, membres (suspendre / réactiver), avis (retirer), commentaires (supprimer), journal. Motif obligatoire. Session en mémoire seulement, 1 h maximum, déconnexion après 15 min d'inactivité. - Connexion : mot de passe + code de double authentification obligatoire (jeton aal2). - Fonction Edge « admin » : secret X-Admin-Gate (ajouté par nginx sur le VPS, sinon 404), jeton aal2, liste admin.admins ; accès à la base par connexion directe. Alertes e-mail si SMTP_PASSWORD est configuré. - Schéma « admin » (20261130150000, appliqué) non exposé par l'API : admins, journal en ajout seulement (modification, suppression et vidage refusés), fonctions de la console. - nginx : admin.conf sur 127.0.0.1:8081 (CSP stricte, sans cache, noindex), relais vers la fonction avec le secret lu dans /etc/nginx/bobinoo-admin-gate.conf (hors dépôt). Publié par « tailscale serve ». - Déploiement : build de la console et copie dans chaque release. Guide : docs/admin.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
21 files changed
+1372
-8
No files matched your search
@@ -0,0 +1,90 @@
|
||||
/** Appels à la fonction serveur « admin », par le relais nginx du VPS (qui ajoute le secret). */
|
||||
export class ApiError extends Error {
|
||||
constructor(
|
||||
public status: number,
|
||||
message: string,
|
||||
) {
|
||||
super(message)
|
||||
}
|
||||
}
|
||||
|
||||
const MESSAGES: Record<string, string> = {
|
||||
session: 'Session expirée : reconnecte-toi.',
|
||||
mfa: 'Code de double authentification requis : reconnecte-toi.',
|
||||
interdit: "Ce compte n'est pas administrateur.",
|
||||
'trop de requêtes': 'Trop de requêtes, patiente une minute.',
|
||||
}
|
||||
|
||||
export async function call<T>(token: string, action: string, params: Record<string, unknown> = {}): Promise<T> {
|
||||
let res: Response
|
||||
try {
|
||||
res = await fetch('/api/admin', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
||||
body: JSON.stringify({ action, ...params }),
|
||||
credentials: 'omit',
|
||||
cache: 'no-store',
|
||||
})
|
||||
} catch {
|
||||
throw new ApiError(0, 'Serveur injoignable (VPN Tailscale activé ?).')
|
||||
}
|
||||
if (res.status === 404) throw new ApiError(404, 'La console n\'est pas reliée au serveur (secret du VPS absent ou différent).')
|
||||
const body = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
if (!res.ok) throw new ApiError(res.status, MESSAGES[body.error ?? ''] ?? body.error ?? `Erreur ${res.status}`)
|
||||
return body as T
|
||||
}
|
||||
|
||||
export interface Card {
|
||||
id: string
|
||||
username: string
|
||||
display_name: string
|
||||
avatar_url?: string | null
|
||||
suspended: boolean
|
||||
}
|
||||
export interface Overview {
|
||||
members: number
|
||||
members_week: number
|
||||
active_week: number
|
||||
suspended: number
|
||||
private: number
|
||||
items: number
|
||||
reviews: number
|
||||
comments: number
|
||||
follows: number
|
||||
shared_lists: number
|
||||
latest: (Card & { created_at: string })[]
|
||||
}
|
||||
export interface Member extends Card {
|
||||
email: string
|
||||
created_at: string
|
||||
last_sign_in_at?: string | null
|
||||
items: number
|
||||
mfa: boolean
|
||||
is_admin: boolean
|
||||
}
|
||||
export interface Review {
|
||||
user: Card
|
||||
item_id: string
|
||||
title: string
|
||||
rating?: number | null
|
||||
spoiler: boolean
|
||||
notes: string
|
||||
updated_at: string
|
||||
comments: number
|
||||
}
|
||||
export interface Comment {
|
||||
id: number
|
||||
body: string
|
||||
created_at: string
|
||||
user: Card
|
||||
author: Card
|
||||
title?: string | null
|
||||
}
|
||||
export interface JournalEntry {
|
||||
id: number
|
||||
at: string
|
||||
action: string
|
||||
target?: string | null
|
||||
details: Record<string, unknown>
|
||||
admin?: string | null
|
||||
}
|
||||
Reference in new issue
Block a user