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:
@@ -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 ReactDOM from 'react-dom/client';
|
||||
import App from './App.jsx';
|
||||
import Admin from './Admin.jsx';
|
||||
import './index.css';
|
||||
|
||||
// Simple routing basé sur le path
|
||||
const isAdminPage = window.location.pathname.startsWith('/admin');
|
||||
|
||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
{isAdminPage ? <Admin /> : <App />}
|
||||
</React.StrictMode>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user