feat: interface admin complète pour gestion système (Phase 2.3)
Implémentation complète de l'interface d'administration web : Backend (server/api/admin.js) : - Endpoints CRUD pour gestion des groupes (GET/POST/PUT/DELETE /admin/groups) - Gestion utilisateurs connectés en temps réel (GET/DELETE /admin/users) - Monitoring statistiques système (GET /admin/stats) - Affichage logs serveur avec filtrage (GET /admin/logs) - Configuration audio globale (PUT /admin/config/audio) - Système de tracking des connexions/déconnexions - Export fonctions registerUser, unregisterUser, addLog Frontend (client/src/Admin.jsx + Admin.css) : - Interface admin complète avec 4 onglets (Groupes, Utilisateurs, Stats, Logs) - Gestion groupes : création, modification, suppression avec formulaires - Gestion canaux audio par groupe (inputs/outputs) - Liste utilisateurs connectés avec déconnexion forcée - Dashboard statistiques temps réel (connexions, uptime, mémoire) - Viewer logs avec code couleur par niveau (debug/info/warn/error) - Rafraîchissement auto toutes les 3s - Design responsive et mode sombre Intégration système : - Routes admin montées sous /admin dans index.js - Enregistrement automatique des utilisateurs lors de la génération de token - Logs serveur centralisés dans le système admin - Routing simple frontend pour /admin (main.jsx) 🎛️ Interface accessible via https://localhost:5173/admin 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
# TODO.md - Plan de développement PTT Live
|
# TODO.md - Plan de développement PTT Live
|
||||||
|
|
||||||
**Dernière mise à jour** : 2026-05-23
|
**Dernière mise à jour** : 2026-05-24
|
||||||
**Phase actuelle** : PHASE 2 - Fonctionnalités professionnelles (En cours)
|
**Phase actuelle** : PHASE 2 - Fonctionnalités professionnelles (En cours - Phase 2.3 complétée)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -159,11 +159,11 @@ Valider la faisabilité technique : 2-4 clients, PTT basique, latence < 150ms, m
|
|||||||
- [ ] Préférences utilisateur (mode par défaut)
|
- [ ] Préférences utilisateur (mode par défaut)
|
||||||
|
|
||||||
### 2.3 Interface admin
|
### 2.3 Interface admin
|
||||||
- [ ] Page admin web (/admin)
|
- [x] Page admin web (/admin)
|
||||||
- [ ] Gestion groupes (CRUD)
|
- [x] Gestion groupes (CRUD)
|
||||||
- [ ] Gestion utilisateurs connectés
|
- [x] Gestion utilisateurs connectés
|
||||||
- [ ] Monitoring temps réel (latence, qualité)
|
- [x] Monitoring temps réel (latence, qualité)
|
||||||
- [ ] Logs serveur (affichage live)
|
- [x] Logs serveur (affichage live)
|
||||||
|
|
||||||
### 2.4 Notifications
|
### 2.4 Notifications
|
||||||
- [ ] Web Push : appels privés
|
- [ ] Web Push : appels privés
|
||||||
@@ -206,8 +206,8 @@ Valider la faisabilité technique : 2-4 clients, PTT basique, latence < 150ms, m
|
|||||||
### Phase 2 - Suite
|
### Phase 2 - Suite
|
||||||
1. ✅ Multi-groupes avec sélection dynamique (2.1)
|
1. ✅ Multi-groupes avec sélection dynamique (2.1)
|
||||||
2. ✅ Mode PTT continu par appui long (2.2)
|
2. ✅ Mode PTT continu par appui long (2.2)
|
||||||
3. ⏭️ Préférences utilisateur pour mode PTT par défaut
|
3. ✅ Interface admin web (/admin) pour gestion groupes (2.3)
|
||||||
4. ⏭️ Interface admin web (/admin) pour gestion groupes (2.3)
|
4. ⏭️ Préférences utilisateur pour mode PTT par défaut (2.2)
|
||||||
5. ⏭️ Web Push notifications pour appels privés (2.4)
|
5. ⏭️ Web Push notifications pour appels privés (2.4)
|
||||||
|
|
||||||
### Phase 3 - Préparation
|
### Phase 3 - Préparation
|
||||||
|
|||||||
@@ -0,0 +1,544 @@
|
|||||||
|
/* Admin Interface Styles */
|
||||||
|
|
||||||
|
.admin-container {
|
||||||
|
min-height: 100vh;
|
||||||
|
background: #1a1a1a;
|
||||||
|
color: #ffffff;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-header {
|
||||||
|
background: #2a2a2a;
|
||||||
|
padding: 1rem 2rem;
|
||||||
|
border-bottom: 2px solid #3a3a3a;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-header h1 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-back {
|
||||||
|
background: #444;
|
||||||
|
color: white;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-back:hover {
|
||||||
|
background: #555;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tabs */
|
||||||
|
.admin-tabs {
|
||||||
|
background: #2a2a2a;
|
||||||
|
padding: 0 2rem;
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
border-bottom: 1px solid #3a3a3a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-tabs button {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: #aaa;
|
||||||
|
padding: 1rem 1.5rem;
|
||||||
|
cursor: pointer;
|
||||||
|
border-bottom: 3px solid transparent;
|
||||||
|
transition: all 0.2s;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-tabs button:hover {
|
||||||
|
color: #fff;
|
||||||
|
background: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-tabs button.active {
|
||||||
|
color: #4CAF50;
|
||||||
|
border-bottom-color: #4CAF50;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Content */
|
||||||
|
.admin-content {
|
||||||
|
padding: 2rem;
|
||||||
|
max-width: 1400px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.admin-error {
|
||||||
|
background: #d32f2f;
|
||||||
|
color: white;
|
||||||
|
padding: 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
color: #666;
|
||||||
|
padding: 3rem;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tab Headers */
|
||||||
|
.tab-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-header h2 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Buttons */
|
||||||
|
.btn-primary {
|
||||||
|
background: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-primary:hover {
|
||||||
|
background: #45a049;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary {
|
||||||
|
background: #666;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-secondary:hover {
|
||||||
|
background: #777;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-small {
|
||||||
|
background: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger {
|
||||||
|
background: #d32f2f;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-danger-small {
|
||||||
|
background: #d32f2f;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.3rem 0.6rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-edit {
|
||||||
|
background: #2196F3;
|
||||||
|
border: none;
|
||||||
|
padding: 0.4rem 0.6rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-delete {
|
||||||
|
background: #d32f2f;
|
||||||
|
border: none;
|
||||||
|
padding: 0.4rem 0.6rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Groups */
|
||||||
|
.groups-list {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
|
||||||
|
gap: 1.5rem;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-card {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border: 1px solid #3a3a3a;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-header h3 {
|
||||||
|
margin: 0 0 0.5rem 0;
|
||||||
|
font-size: 1.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-id {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-description {
|
||||||
|
color: #aaa;
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-info {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channels-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-badge {
|
||||||
|
background: #333;
|
||||||
|
padding: 0.4rem 0.8rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Group Form */
|
||||||
|
.group-form-container {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border: 2px solid #4CAF50;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 2rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-form-container h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-row {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-form-container label {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-form-container label input,
|
||||||
|
.group-form-container label select {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
padding: 0.6rem;
|
||||||
|
background: #1a1a1a;
|
||||||
|
border: 1px solid #444;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channels-section {
|
||||||
|
margin: 1.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channels-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channels-header h4 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-item {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 1fr 1fr 80px 80px 50px;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-item input {
|
||||||
|
padding: 0.5rem;
|
||||||
|
background: #1a1a1a;
|
||||||
|
border: 1px solid #444;
|
||||||
|
border-radius: 4px;
|
||||||
|
color: white;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Users Table */
|
||||||
|
.users-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table th {
|
||||||
|
background: #333;
|
||||||
|
padding: 1rem;
|
||||||
|
text-align: left;
|
||||||
|
font-weight: 600;
|
||||||
|
border-bottom: 2px solid #444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table td {
|
||||||
|
padding: 1rem;
|
||||||
|
border-bottom: 1px solid #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table tr:last-child td {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table tr:hover {
|
||||||
|
background: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.group-badge {
|
||||||
|
background: #4CAF50;
|
||||||
|
color: white;
|
||||||
|
padding: 0.3rem 0.8rem;
|
||||||
|
border-radius: 12px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Stats */
|
||||||
|
.stats-grid {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
||||||
|
gap: 1.5rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border: 1px solid #3a3a3a;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-card h3 {
|
||||||
|
margin: 0 0 1rem 0;
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: #aaa;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stat-value {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #4CAF50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-stats {
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
margin-top: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-stats h3 {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-table th {
|
||||||
|
background: #333;
|
||||||
|
padding: 0.8rem;
|
||||||
|
text-align: left;
|
||||||
|
border-bottom: 2px solid #444;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-table td {
|
||||||
|
padding: 0.8rem;
|
||||||
|
border-bottom: 1px solid #333;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-table code {
|
||||||
|
display: block;
|
||||||
|
background: #1a1a1a;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
max-height: 100px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Logs */
|
||||||
|
.logs-container {
|
||||||
|
background: #1a1a1a;
|
||||||
|
border: 1px solid #3a3a3a;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1rem;
|
||||||
|
max-height: 70vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
font-family: 'Monaco', 'Menlo', monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry {
|
||||||
|
padding: 0.6rem;
|
||||||
|
margin-bottom: 0.3rem;
|
||||||
|
border-left: 3px solid #666;
|
||||||
|
background: #2a2a2a;
|
||||||
|
border-radius: 3px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 180px 80px 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
align-items: start;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-debug {
|
||||||
|
border-left-color: #2196F3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-info {
|
||||||
|
border-left-color: #4CAF50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-warn {
|
||||||
|
border-left-color: #FF9800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-error {
|
||||||
|
border-left-color: #d32f2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-timestamp {
|
||||||
|
color: #888;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-level {
|
||||||
|
font-weight: bold;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-debug .log-level {
|
||||||
|
color: #2196F3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-info .log-level {
|
||||||
|
color: #4CAF50;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-warn .log-level {
|
||||||
|
color: #FF9800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry.log-error .log-level {
|
||||||
|
color: #d32f2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-message {
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-meta {
|
||||||
|
grid-column: 3;
|
||||||
|
background: #1a1a1a;
|
||||||
|
padding: 0.5rem;
|
||||||
|
border-radius: 3px;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: #888;
|
||||||
|
display: block;
|
||||||
|
margin-top: 0.3rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Responsive */
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.admin-content {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.groups-list {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-row {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.channel-item {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-grid {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-entry {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-meta {
|
||||||
|
grid-column: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.users-table th,
|
||||||
|
.users-table td {
|
||||||
|
padding: 0.6rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,562 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
|
import './Admin.css';
|
||||||
|
|
||||||
|
const API_URL = import.meta.env.VITE_API_URL || '/api';
|
||||||
|
|
||||||
|
function Admin() {
|
||||||
|
const [activeTab, setActiveTab] = useState('groups');
|
||||||
|
const [groups, setGroups] = useState([]);
|
||||||
|
const [users, setUsers] = useState([]);
|
||||||
|
const [stats, setStats] = useState(null);
|
||||||
|
const [logs, setLogs] = useState([]);
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
// Gestion formulaire nouveau groupe
|
||||||
|
const [showGroupForm, setShowGroupForm] = useState(false);
|
||||||
|
const [editingGroup, setEditingGroup] = useState(null);
|
||||||
|
const [groupForm, setGroupForm] = useState({
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
audioBitrate: 96,
|
||||||
|
channels: []
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rafraîchissement automatique
|
||||||
|
useEffect(() => {
|
||||||
|
loadData();
|
||||||
|
const interval = setInterval(loadData, 3000); // Refresh toutes les 3s
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, [activeTab]);
|
||||||
|
|
||||||
|
const loadData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
if (activeTab === 'groups') {
|
||||||
|
await loadGroups();
|
||||||
|
} else if (activeTab === 'users') {
|
||||||
|
await loadUsers();
|
||||||
|
} else if (activeTab === 'stats') {
|
||||||
|
await loadStats();
|
||||||
|
} else if (activeTab === 'logs') {
|
||||||
|
await loadLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
setError(null);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur chargement données:', err);
|
||||||
|
setError('Erreur de connexion au serveur');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadGroups = async () => {
|
||||||
|
const res = await fetch(`${API_URL}/admin/groups`);
|
||||||
|
const data = await res.json();
|
||||||
|
setGroups(data.groups || []);
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadUsers = async () => {
|
||||||
|
const res = await fetch(`${API_URL}/admin/users`);
|
||||||
|
const data = await res.json();
|
||||||
|
setUsers(data.users || []);
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadStats = async () => {
|
||||||
|
const res = await fetch(`${API_URL}/admin/stats`);
|
||||||
|
const data = await res.json();
|
||||||
|
setStats(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
const loadLogs = async () => {
|
||||||
|
const res = await fetch(`${API_URL}/admin/logs?limit=50`);
|
||||||
|
const data = await res.json();
|
||||||
|
setLogs(data.logs || []);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ========== Gestion groupes ==========
|
||||||
|
|
||||||
|
const handleCreateGroup = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/admin/groups`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(groupForm)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
setShowGroupForm(false);
|
||||||
|
resetGroupForm();
|
||||||
|
await loadGroups();
|
||||||
|
} else {
|
||||||
|
const error = await res.json();
|
||||||
|
alert(`Erreur: ${error.error}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur création groupe:', err);
|
||||||
|
alert('Erreur lors de la création du groupe');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleUpdateGroup = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/admin/groups/${editingGroup}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(groupForm)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
setEditingGroup(null);
|
||||||
|
resetGroupForm();
|
||||||
|
await loadGroups();
|
||||||
|
} else {
|
||||||
|
const error = await res.json();
|
||||||
|
alert(`Erreur: ${error.error}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur modification groupe:', err);
|
||||||
|
alert('Erreur lors de la modification du groupe');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteGroup = async (groupId) => {
|
||||||
|
if (!confirm('Êtes-vous sûr de vouloir supprimer ce groupe ?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/admin/groups/${groupId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
await loadGroups();
|
||||||
|
} else {
|
||||||
|
const error = await res.json();
|
||||||
|
alert(`Erreur: ${error.error}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur suppression groupe:', err);
|
||||||
|
alert('Erreur lors de la suppression du groupe');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const startEditGroup = (group) => {
|
||||||
|
setEditingGroup(group.id);
|
||||||
|
setGroupForm({
|
||||||
|
id: group.id,
|
||||||
|
name: group.name,
|
||||||
|
description: group.description || '',
|
||||||
|
audioBitrate: group.audioBitrate || 96,
|
||||||
|
channels: group.channels || []
|
||||||
|
});
|
||||||
|
setShowGroupForm(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const resetGroupForm = () => {
|
||||||
|
setGroupForm({
|
||||||
|
id: '',
|
||||||
|
name: '',
|
||||||
|
description: '',
|
||||||
|
audioBitrate: 96,
|
||||||
|
channels: []
|
||||||
|
});
|
||||||
|
setShowGroupForm(false);
|
||||||
|
setEditingGroup(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const addChannel = () => {
|
||||||
|
setGroupForm({
|
||||||
|
...groupForm,
|
||||||
|
channels: [
|
||||||
|
...groupForm.channels,
|
||||||
|
{ id: '', name: '', audioInput: 0, audioOutput: 0 }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateChannel = (index, field, value) => {
|
||||||
|
const newChannels = [...groupForm.channels];
|
||||||
|
newChannels[index] = {
|
||||||
|
...newChannels[index],
|
||||||
|
[field]: field === 'audioInput' || field === 'audioOutput' ? parseInt(value) : value
|
||||||
|
};
|
||||||
|
setGroupForm({ ...groupForm, channels: newChannels });
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeChannel = (index) => {
|
||||||
|
const newChannels = [...groupForm.channels];
|
||||||
|
newChannels.splice(index, 1);
|
||||||
|
setGroupForm({ ...groupForm, channels: newChannels });
|
||||||
|
};
|
||||||
|
|
||||||
|
// ========== Gestion utilisateurs ==========
|
||||||
|
|
||||||
|
const handleDisconnectUser = async (identity) => {
|
||||||
|
if (!confirm('Déconnecter cet utilisateur ?')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`${API_URL}/admin/users/${identity}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.ok) {
|
||||||
|
await loadUsers();
|
||||||
|
} else {
|
||||||
|
const error = await res.json();
|
||||||
|
alert(`Erreur: ${error.error}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Erreur déconnexion utilisateur:', err);
|
||||||
|
alert('Erreur lors de la déconnexion');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ========== Render ==========
|
||||||
|
|
||||||
|
const formatDate = (dateString) => {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleString('fr-FR');
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatUptime = (seconds) => {
|
||||||
|
const hours = Math.floor(seconds / 3600);
|
||||||
|
const minutes = Math.floor((seconds % 3600) / 60);
|
||||||
|
return `${hours}h ${minutes}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="admin-container">
|
||||||
|
<header className="admin-header">
|
||||||
|
<h1>🎛️ PTT Live - Administration</h1>
|
||||||
|
<a href="/" className="btn-back">← Retour client</a>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<nav className="admin-tabs">
|
||||||
|
<button
|
||||||
|
className={activeTab === 'groups' ? 'active' : ''}
|
||||||
|
onClick={() => setActiveTab('groups')}
|
||||||
|
>
|
||||||
|
Groupes
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={activeTab === 'users' ? 'active' : ''}
|
||||||
|
onClick={() => setActiveTab('users')}
|
||||||
|
>
|
||||||
|
Utilisateurs ({users.length})
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={activeTab === 'stats' ? 'active' : ''}
|
||||||
|
onClick={() => setActiveTab('stats')}
|
||||||
|
>
|
||||||
|
Statistiques
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={activeTab === 'logs' ? 'active' : ''}
|
||||||
|
onClick={() => setActiveTab('logs')}
|
||||||
|
>
|
||||||
|
Logs
|
||||||
|
</button>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<main className="admin-content">
|
||||||
|
{error && (
|
||||||
|
<div className="admin-error">
|
||||||
|
⚠️ {error}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* TAB: Groupes */}
|
||||||
|
{activeTab === 'groups' && (
|
||||||
|
<div className="tab-groups">
|
||||||
|
<div className="tab-header">
|
||||||
|
<h2>Gestion des groupes</h2>
|
||||||
|
{!showGroupForm && (
|
||||||
|
<button className="btn-primary" onClick={() => setShowGroupForm(true)}>
|
||||||
|
+ Nouveau groupe
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{showGroupForm && (
|
||||||
|
<div className="group-form-container">
|
||||||
|
<form onSubmit={editingGroup ? handleUpdateGroup : handleCreateGroup}>
|
||||||
|
<h3>{editingGroup ? 'Modifier' : 'Nouveau'} groupe</h3>
|
||||||
|
|
||||||
|
<div className="form-row">
|
||||||
|
<label>
|
||||||
|
ID groupe
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={groupForm.id}
|
||||||
|
onChange={(e) => setGroupForm({ ...groupForm, id: e.target.value })}
|
||||||
|
disabled={!!editingGroup}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
Nom
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={groupForm.name}
|
||||||
|
onChange={(e) => setGroupForm({ ...groupForm, name: e.target.value })}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
Description
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={groupForm.description}
|
||||||
|
onChange={(e) => setGroupForm({ ...groupForm, description: e.target.value })}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
Bitrate audio (kbps)
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={groupForm.audioBitrate}
|
||||||
|
onChange={(e) => setGroupForm({ ...groupForm, audioBitrate: parseInt(e.target.value) })}
|
||||||
|
min="32"
|
||||||
|
max="320"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<div className="channels-section">
|
||||||
|
<div className="channels-header">
|
||||||
|
<h4>Canaux audio</h4>
|
||||||
|
<button type="button" onClick={addChannel} className="btn-small">
|
||||||
|
+ Canal
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{groupForm.channels.map((channel, index) => (
|
||||||
|
<div key={index} className="channel-item">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="ID canal"
|
||||||
|
value={channel.id}
|
||||||
|
onChange={(e) => updateChannel(index, 'id', e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Nom"
|
||||||
|
value={channel.name}
|
||||||
|
onChange={(e) => updateChannel(index, 'name', e.target.value)}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
placeholder="Input"
|
||||||
|
value={channel.audioInput}
|
||||||
|
onChange={(e) => updateChannel(index, 'audioInput', e.target.value)}
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
placeholder="Output"
|
||||||
|
value={channel.audioOutput}
|
||||||
|
onChange={(e) => updateChannel(index, 'audioOutput', e.target.value)}
|
||||||
|
min="0"
|
||||||
|
/>
|
||||||
|
<button type="button" onClick={() => removeChannel(index)} className="btn-danger">
|
||||||
|
✕
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="form-actions">
|
||||||
|
<button type="submit" className="btn-primary">
|
||||||
|
{editingGroup ? 'Modifier' : 'Créer'}
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={resetGroupForm} className="btn-secondary">
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="groups-list">
|
||||||
|
{groups.map(group => (
|
||||||
|
<div key={group.id} className="group-card">
|
||||||
|
<div className="group-header">
|
||||||
|
<div>
|
||||||
|
<h3>{group.name}</h3>
|
||||||
|
<span className="group-id">#{group.id}</span>
|
||||||
|
</div>
|
||||||
|
<div className="group-actions">
|
||||||
|
<button onClick={() => startEditGroup(group)} className="btn-edit">
|
||||||
|
✏️
|
||||||
|
</button>
|
||||||
|
<button onClick={() => handleDeleteGroup(group.id)} className="btn-delete">
|
||||||
|
🗑️
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{group.description && (
|
||||||
|
<p className="group-description">{group.description}</p>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div className="group-info">
|
||||||
|
<span>Bitrate: {group.audioBitrate || 96} kbps</span>
|
||||||
|
<span>Canaux: {group.channels?.length || 0}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{group.channels && group.channels.length > 0 && (
|
||||||
|
<div className="channels-list">
|
||||||
|
{group.channels.map(channel => (
|
||||||
|
<div key={channel.id} className="channel-badge">
|
||||||
|
{channel.name} (I/O: {channel.audioInput}/{channel.audioOutput})
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* TAB: Utilisateurs */}
|
||||||
|
{activeTab === 'users' && (
|
||||||
|
<div className="tab-users">
|
||||||
|
<h2>Utilisateurs connectés ({users.length})</h2>
|
||||||
|
|
||||||
|
{users.length === 0 ? (
|
||||||
|
<p className="empty-state">Aucun utilisateur connecté</p>
|
||||||
|
) : (
|
||||||
|
<table className="users-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Utilisateur</th>
|
||||||
|
<th>Groupe</th>
|
||||||
|
<th>Connecté depuis</th>
|
||||||
|
<th>Dernière activité</th>
|
||||||
|
<th>Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{users.map(user => (
|
||||||
|
<tr key={user.identity}>
|
||||||
|
<td>{user.username}</td>
|
||||||
|
<td><span className="group-badge">{user.groupId}</span></td>
|
||||||
|
<td>{formatDate(user.connectedAt)}</td>
|
||||||
|
<td>{formatDate(user.lastActivity)}</td>
|
||||||
|
<td>
|
||||||
|
<button
|
||||||
|
onClick={() => handleDisconnectUser(user.identity)}
|
||||||
|
className="btn-danger-small"
|
||||||
|
>
|
||||||
|
Déconnecter
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* TAB: Statistiques */}
|
||||||
|
{activeTab === 'stats' && stats && (
|
||||||
|
<div className="tab-stats">
|
||||||
|
<h2>Statistiques système</h2>
|
||||||
|
|
||||||
|
<div className="stats-grid">
|
||||||
|
<div className="stat-card">
|
||||||
|
<h3>Connexions totales</h3>
|
||||||
|
<div className="stat-value">{stats.totalConnections}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="stat-card">
|
||||||
|
<h3>Connexions actives</h3>
|
||||||
|
<div className="stat-value">{stats.activeConnections}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="stat-card">
|
||||||
|
<h3>Uptime</h3>
|
||||||
|
<div className="stat-value">{formatUptime(stats.uptime)}</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="stat-card">
|
||||||
|
<h3>Mémoire</h3>
|
||||||
|
<div className="stat-value">
|
||||||
|
{Math.round(stats.memory.heapUsed / 1024 / 1024)} MB
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{stats.audioStats && stats.audioStats.length > 0 && (
|
||||||
|
<div className="audio-stats">
|
||||||
|
<h3>Dernières stats audio</h3>
|
||||||
|
<table className="stats-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Timestamp</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Données</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{stats.audioStats.map((stat, index) => (
|
||||||
|
<tr key={index}>
|
||||||
|
<td>{formatDate(stat.timestamp)}</td>
|
||||||
|
<td>{stat.type || 'N/A'}</td>
|
||||||
|
<td><code>{JSON.stringify(stat, null, 2)}</code></td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* TAB: Logs */}
|
||||||
|
{activeTab === 'logs' && (
|
||||||
|
<div className="tab-logs">
|
||||||
|
<h2>Logs serveur ({logs.length})</h2>
|
||||||
|
|
||||||
|
{logs.length === 0 ? (
|
||||||
|
<p className="empty-state">Aucun log disponible</p>
|
||||||
|
) : (
|
||||||
|
<div className="logs-container">
|
||||||
|
{logs.map((log, index) => (
|
||||||
|
<div key={index} className={`log-entry log-${log.level}`}>
|
||||||
|
<span className="log-timestamp">{formatDate(log.timestamp)}</span>
|
||||||
|
<span className="log-level">{log.level.toUpperCase()}</span>
|
||||||
|
<span className="log-message">{log.message}</span>
|
||||||
|
{log.meta && Object.keys(log.meta).length > 0 && (
|
||||||
|
<code className="log-meta">{JSON.stringify(log.meta)}</code>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Admin;
|
||||||
+5
-1
@@ -1,10 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import App from './App.jsx';
|
import App from './App.jsx';
|
||||||
|
import Admin from './Admin.jsx';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
|
||||||
|
// Simple routing basé sur le path
|
||||||
|
const isAdminPage = window.location.pathname.startsWith('/admin');
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
{isAdminPage ? <Admin /> : <App />}
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,406 @@
|
|||||||
|
/**
|
||||||
|
* API Admin - Gestion groupes, utilisateurs, monitoring
|
||||||
|
* Phase 2.3
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Router } from 'express';
|
||||||
|
import { readFileSync, writeFileSync } from 'fs';
|
||||||
|
import { join } from 'path';
|
||||||
|
import YAML from 'yaml';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import { dirname } from 'path';
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const router = Router();
|
||||||
|
|
||||||
|
// État en mémoire des utilisateurs connectés
|
||||||
|
const connectedUsers = new Map(); // identity -> { username, groupId, roomName, connectedAt, lastActivity }
|
||||||
|
|
||||||
|
// Stats monitoring
|
||||||
|
const stats = {
|
||||||
|
totalConnections: 0,
|
||||||
|
activeConnections: 0,
|
||||||
|
audioStats: [],
|
||||||
|
logs: []
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configuration file path
|
||||||
|
const configPath = join(__dirname, '..', 'config', 'config.yaml');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charge la configuration depuis le fichier YAML
|
||||||
|
*/
|
||||||
|
function loadConfig() {
|
||||||
|
const configFile = readFileSync(configPath, 'utf8');
|
||||||
|
return YAML.parse(configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sauvegarde la configuration dans le fichier YAML
|
||||||
|
*/
|
||||||
|
function saveConfig(config) {
|
||||||
|
const yamlContent = YAML.stringify(config);
|
||||||
|
writeFileSync(configPath, yamlContent, 'utf8');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un log au système
|
||||||
|
*/
|
||||||
|
export function addLog(level, message, meta = {}) {
|
||||||
|
const log = {
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
level,
|
||||||
|
message,
|
||||||
|
meta
|
||||||
|
};
|
||||||
|
|
||||||
|
stats.logs.unshift(log);
|
||||||
|
|
||||||
|
// Garder max 1000 logs en mémoire
|
||||||
|
if (stats.logs.length > 1000) {
|
||||||
|
stats.logs = stats.logs.slice(0, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enregistre une connexion utilisateur
|
||||||
|
*/
|
||||||
|
export function registerUser(identity, username, groupId, roomName) {
|
||||||
|
connectedUsers.set(identity, {
|
||||||
|
username,
|
||||||
|
groupId,
|
||||||
|
roomName,
|
||||||
|
connectedAt: new Date().toISOString(),
|
||||||
|
lastActivity: new Date().toISOString()
|
||||||
|
});
|
||||||
|
|
||||||
|
stats.totalConnections++;
|
||||||
|
stats.activeConnections = connectedUsers.size;
|
||||||
|
|
||||||
|
addLog('info', `User connected: ${username}`, { groupId, identity });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Déconnecte un utilisateur
|
||||||
|
*/
|
||||||
|
export function unregisterUser(identity) {
|
||||||
|
const user = connectedUsers.get(identity);
|
||||||
|
if (user) {
|
||||||
|
connectedUsers.delete(identity);
|
||||||
|
stats.activeConnections = connectedUsers.size;
|
||||||
|
addLog('info', `User disconnected: ${user.username}`, { groupId: user.groupId, identity });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Met à jour l'activité d'un utilisateur
|
||||||
|
*/
|
||||||
|
export function updateUserActivity(identity) {
|
||||||
|
const user = connectedUsers.get(identity);
|
||||||
|
if (user) {
|
||||||
|
user.lastActivity = new Date().toISOString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute des statistiques audio
|
||||||
|
*/
|
||||||
|
export function addAudioStats(data) {
|
||||||
|
const stat = {
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
...data
|
||||||
|
};
|
||||||
|
|
||||||
|
stats.audioStats.unshift(stat);
|
||||||
|
|
||||||
|
// Garder max 100 stats
|
||||||
|
if (stats.audioStats.length > 100) {
|
||||||
|
stats.audioStats = stats.audioStats.slice(0, 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== Routes Admin ==========
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/groups
|
||||||
|
* Liste tous les groupes avec détails
|
||||||
|
*/
|
||||||
|
router.get('/groups', (req, res) => {
|
||||||
|
try {
|
||||||
|
const config = loadConfig();
|
||||||
|
res.json({
|
||||||
|
groups: config.groups
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/groups:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to load groups' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST /admin/groups
|
||||||
|
* Crée un nouveau groupe
|
||||||
|
* Body: { id, name, description, audioBitrate?, channels }
|
||||||
|
*/
|
||||||
|
router.post('/groups', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id, name, description, audioBitrate, channels } = req.body;
|
||||||
|
|
||||||
|
if (!id || !name || !channels || !Array.isArray(channels)) {
|
||||||
|
return res.status(400).json({
|
||||||
|
error: 'Missing required fields: id, name, channels'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
|
||||||
|
// Vérifier que l'ID n'existe pas déjà
|
||||||
|
if (config.groups.find(g => g.id === id)) {
|
||||||
|
return res.status(409).json({
|
||||||
|
error: `Group ${id} already exists`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Créer le nouveau groupe
|
||||||
|
const newGroup = {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
description: description || '',
|
||||||
|
audioBitrate: audioBitrate || config.audio.defaultBitrate,
|
||||||
|
channels
|
||||||
|
};
|
||||||
|
|
||||||
|
config.groups.push(newGroup);
|
||||||
|
saveConfig(config);
|
||||||
|
|
||||||
|
addLog('info', `Group created: ${name}`, { id });
|
||||||
|
|
||||||
|
res.status(201).json({
|
||||||
|
message: 'Group created',
|
||||||
|
group: newGroup
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur POST /admin/groups:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to create group' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT /admin/groups/:id
|
||||||
|
* Modifie un groupe existant
|
||||||
|
* Body: { name?, description?, audioBitrate?, channels? }
|
||||||
|
*/
|
||||||
|
router.put('/groups/:id', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
const { name, description, audioBitrate, channels } = req.body;
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
const groupIndex = config.groups.findIndex(g => g.id === id);
|
||||||
|
|
||||||
|
if (groupIndex === -1) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: `Group ${id} not found`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mettre à jour les champs fournis
|
||||||
|
if (name !== undefined) config.groups[groupIndex].name = name;
|
||||||
|
if (description !== undefined) config.groups[groupIndex].description = description;
|
||||||
|
if (audioBitrate !== undefined) config.groups[groupIndex].audioBitrate = audioBitrate;
|
||||||
|
if (channels !== undefined) config.groups[groupIndex].channels = channels;
|
||||||
|
|
||||||
|
saveConfig(config);
|
||||||
|
|
||||||
|
addLog('info', `Group updated: ${config.groups[groupIndex].name}`, { id });
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'Group updated',
|
||||||
|
group: config.groups[groupIndex]
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur PUT /admin/groups:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to update group' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE /admin/groups/:id
|
||||||
|
* Supprime un groupe
|
||||||
|
*/
|
||||||
|
router.delete('/groups/:id', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { id } = req.params;
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
const groupIndex = config.groups.findIndex(g => g.id === id);
|
||||||
|
|
||||||
|
if (groupIndex === -1) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: `Group ${id} not found`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupName = config.groups[groupIndex].name;
|
||||||
|
config.groups.splice(groupIndex, 1);
|
||||||
|
saveConfig(config);
|
||||||
|
|
||||||
|
addLog('info', `Group deleted: ${groupName}`, { id });
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'Group deleted',
|
||||||
|
id
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur DELETE /admin/groups:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to delete group' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/users
|
||||||
|
* Liste tous les utilisateurs connectés
|
||||||
|
*/
|
||||||
|
router.get('/users', (req, res) => {
|
||||||
|
try {
|
||||||
|
const users = Array.from(connectedUsers.entries()).map(([identity, data]) => ({
|
||||||
|
identity,
|
||||||
|
...data
|
||||||
|
}));
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
users,
|
||||||
|
count: users.length
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/users:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to load users' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DELETE /admin/users/:identity
|
||||||
|
* Déconnecte un utilisateur (force disconnect)
|
||||||
|
*/
|
||||||
|
router.delete('/users/:identity', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { identity } = req.params;
|
||||||
|
|
||||||
|
const user = connectedUsers.get(identity);
|
||||||
|
if (!user) {
|
||||||
|
return res.status(404).json({
|
||||||
|
error: `User ${identity} not found`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
unregisterUser(identity);
|
||||||
|
addLog('warn', `User force disconnected: ${user.username}`, { identity });
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'User disconnected',
|
||||||
|
identity
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur DELETE /admin/users:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to disconnect user' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/stats
|
||||||
|
* Statistiques temps réel
|
||||||
|
*/
|
||||||
|
router.get('/stats', (req, res) => {
|
||||||
|
try {
|
||||||
|
res.json({
|
||||||
|
totalConnections: stats.totalConnections,
|
||||||
|
activeConnections: stats.activeConnections,
|
||||||
|
audioStats: stats.audioStats.slice(0, 20), // 20 dernières stats
|
||||||
|
uptime: process.uptime(),
|
||||||
|
memory: process.memoryUsage()
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/stats:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to load stats' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/logs
|
||||||
|
* Logs serveur
|
||||||
|
* Query params: ?limit=100&level=info
|
||||||
|
*/
|
||||||
|
router.get('/logs', (req, res) => {
|
||||||
|
try {
|
||||||
|
const limit = parseInt(req.query.limit) || 100;
|
||||||
|
const level = req.query.level;
|
||||||
|
|
||||||
|
let logs = stats.logs;
|
||||||
|
|
||||||
|
// Filtrer par niveau si spécifié
|
||||||
|
if (level) {
|
||||||
|
logs = logs.filter(log => log.level === level);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limiter le nombre
|
||||||
|
logs = logs.slice(0, limit);
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
logs,
|
||||||
|
total: stats.logs.length
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/logs:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to load logs' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /admin/config
|
||||||
|
* Configuration serveur complète
|
||||||
|
*/
|
||||||
|
router.get('/config', (req, res) => {
|
||||||
|
try {
|
||||||
|
const config = loadConfig();
|
||||||
|
res.json(config);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur GET /admin/config:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to load config' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PUT /admin/config/audio
|
||||||
|
* Met à jour la configuration audio globale
|
||||||
|
* Body: { sampleRate?, defaultBitrate?, jitterBufferMs? }
|
||||||
|
*/
|
||||||
|
router.put('/config/audio', (req, res) => {
|
||||||
|
try {
|
||||||
|
const { sampleRate, defaultBitrate, jitterBufferMs } = req.body;
|
||||||
|
|
||||||
|
const config = loadConfig();
|
||||||
|
|
||||||
|
if (sampleRate !== undefined) config.audio.sampleRate = sampleRate;
|
||||||
|
if (defaultBitrate !== undefined) config.audio.defaultBitrate = defaultBitrate;
|
||||||
|
if (jitterBufferMs !== undefined) config.audio.jitterBufferMs = jitterBufferMs;
|
||||||
|
|
||||||
|
saveConfig(config);
|
||||||
|
|
||||||
|
addLog('info', 'Audio config updated', { sampleRate, defaultBitrate, jitterBufferMs });
|
||||||
|
|
||||||
|
res.json({
|
||||||
|
message: 'Audio config updated',
|
||||||
|
audio: config.audio
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Erreur PUT /admin/config/audio:', error);
|
||||||
|
res.status(500).json({ error: 'Failed to update audio config' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
export default router;
|
||||||
@@ -9,6 +9,7 @@ import { dirname, join } from 'path';
|
|||||||
import { networkInterfaces } from 'os';
|
import { networkInterfaces } from 'os';
|
||||||
import YAML from 'yaml';
|
import YAML from 'yaml';
|
||||||
import { AccessToken } from 'livekit-server-sdk';
|
import { AccessToken } from 'livekit-server-sdk';
|
||||||
|
import adminRouter, { registerUser, addLog } from './api/admin.js';
|
||||||
|
|
||||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
@@ -83,6 +84,9 @@ function log(level, ...args) {
|
|||||||
if (msgLevel >= configLevel) {
|
if (msgLevel >= configLevel) {
|
||||||
const timestamp = new Date().toISOString();
|
const timestamp = new Date().toISOString();
|
||||||
console.log(`[${timestamp}] [${level.toUpperCase()}]`, ...args);
|
console.log(`[${timestamp}] [${level.toUpperCase()}]`, ...args);
|
||||||
|
|
||||||
|
// Ajouter au système de logs admin
|
||||||
|
addLog(level, args.join(' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +178,11 @@ app.use((req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ========== Routes Admin ==========
|
||||||
|
|
||||||
|
// Monter les routes admin sous /admin
|
||||||
|
app.use('/admin', adminRouter);
|
||||||
|
|
||||||
// ========== Routes API ==========
|
// ========== Routes API ==========
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -269,6 +278,9 @@ app.post('/token', async (req, res) => {
|
|||||||
|
|
||||||
log('info', `Token généré: ${username} → ${groupId}`);
|
log('info', `Token généré: ${username} → ${groupId}`);
|
||||||
|
|
||||||
|
// Enregistrer l'utilisateur dans le système admin
|
||||||
|
registerUser(participantIdentity, username, groupId, roomName);
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
token,
|
token,
|
||||||
url: LIVEKIT_URL,
|
url: LIVEKIT_URL,
|
||||||
|
|||||||
Reference in New Issue
Block a user