595 lines
20 KiB
HTML
595 lines
20 KiB
HTML
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Dashboard - Video Streaming Server</title>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
:root {
|
|
--primary: #667eea;
|
|
--secondary: #764ba2;
|
|
--success: #10b981;
|
|
--danger: #ef4444;
|
|
--warning: #f59e0b;
|
|
--info: #3b82f6;
|
|
--dark: #1f2937;
|
|
--light: #f9fafb;
|
|
--gray: #6b7280;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: #f3f4f6;
|
|
color: var(--dark);
|
|
}
|
|
|
|
/* Sidebar */
|
|
.sidebar {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
height: 100vh;
|
|
width: 250px;
|
|
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
|
|
color: white;
|
|
padding: 20px 0;
|
|
box-shadow: 0 0 20px rgba(0,0,0,0.1);
|
|
z-index: 1000;
|
|
}
|
|
|
|
.logo {
|
|
padding: 0 20px 30px;
|
|
border-bottom: 1px solid rgba(255,255,255,0.1);
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.logo h1 {
|
|
font-size: 24px;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.logo p {
|
|
font-size: 12px;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.nav-links {
|
|
list-style: none;
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.nav-links li {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.nav-links a {
|
|
display: flex;
|
|
align-items: center;
|
|
padding: 12px 15px;
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 5px;
|
|
transition: background 0.3s;
|
|
}
|
|
|
|
.nav-links a:hover {
|
|
background: rgba(255,255,255,0.1);
|
|
}
|
|
|
|
.nav-links a.active {
|
|
background: rgba(255,255,255,0.2);
|
|
}
|
|
|
|
.nav-links i {
|
|
margin-right: 10px;
|
|
width: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.user-info {
|
|
position: absolute;
|
|
bottom: 20px;
|
|
left: 0;
|
|
right: 0;
|
|
padding: 20px;
|
|
border-top: 1px solid rgba(255,255,255,0.1);
|
|
}
|
|
|
|
.user-info p {
|
|
margin-bottom: 10px;
|
|
font-size: 14px;
|
|
}
|
|
|
|
.logout-btn {
|
|
display: block;
|
|
width: 100%;
|
|
padding: 8px;
|
|
background: rgba(255,255,255,0.1);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
transition: background 0.3s;
|
|
}
|
|
|
|
.logout-btn:hover {
|
|
background: rgba(255,255,255,0.2);
|
|
}
|
|
|
|
/* Main Content */
|
|
.main-content {
|
|
margin-left: 250px;
|
|
padding: 30px;
|
|
}
|
|
|
|
.header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.header h2 {
|
|
font-size: 28px;
|
|
color: var(--dark);
|
|
}
|
|
|
|
.header-actions {
|
|
display: flex;
|
|
gap: 15px;
|
|
}
|
|
|
|
.btn {
|
|
padding: 10px 20px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-success {
|
|
background: var(--success);
|
|
color: white;
|
|
}
|
|
|
|
.btn-danger {
|
|
background: var(--danger);
|
|
color: white;
|
|
}
|
|
|
|
.btn:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 5px 15px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
/* Stats Cards */
|
|
.stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 20px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 5px 15px rgba(0,0,0,0.05);
|
|
border-left: 4px solid var(--primary);
|
|
}
|
|
|
|
.stat-card h3 {
|
|
font-size: 14px;
|
|
color: var(--gray);
|
|
margin-bottom: 10px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
.stat-card .value {
|
|
font-size: 32px;
|
|
font-weight: bold;
|
|
color: var(--dark);
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.stat-card .change {
|
|
font-size: 12px;
|
|
color: var(--success);
|
|
}
|
|
|
|
/* Rooms Table */
|
|
.section {
|
|
background: white;
|
|
border-radius: 10px;
|
|
padding: 25px;
|
|
margin-bottom: 30px;
|
|
box-shadow: 0 5px 15px rgba(0,0,0,0.05);
|
|
}
|
|
|
|
.section-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 20px;
|
|
color: var(--dark);
|
|
}
|
|
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
}
|
|
|
|
thead {
|
|
background: var(--light);
|
|
}
|
|
|
|
th {
|
|
padding: 15px;
|
|
text-align: left;
|
|
font-weight: 600;
|
|
color: var(--gray);
|
|
border-bottom: 2px solid #e5e7eb;
|
|
}
|
|
|
|
td {
|
|
padding: 15px;
|
|
border-bottom: 1px solid #e5e7eb;
|
|
}
|
|
|
|
tr:hover {
|
|
background: var(--light);
|
|
}
|
|
|
|
.status-badge {
|
|
display: inline-block;
|
|
padding: 5px 10px;
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.status-active {
|
|
background: #d1fae5;
|
|
color: var(--success);
|
|
}
|
|
|
|
.status-inactive {
|
|
background: #fee2e2;
|
|
color: var(--danger);
|
|
}
|
|
|
|
.action-buttons {
|
|
display: flex;
|
|
gap: 8px;
|
|
}
|
|
|
|
.btn-sm {
|
|
padding: 5px 10px;
|
|
font-size: 12px;
|
|
border-radius: 3px;
|
|
}
|
|
|
|
.btn-icon {
|
|
padding: 8px;
|
|
width: 35px;
|
|
height: 35px;
|
|
justify-content: center;
|
|
}
|
|
|
|
/* Loading */
|
|
.loading {
|
|
text-align: center;
|
|
padding: 50px;
|
|
color: var(--gray);
|
|
}
|
|
|
|
/* Responsive */
|
|
@media (max-width: 768px) {
|
|
.sidebar {
|
|
width: 70px;
|
|
}
|
|
|
|
.sidebar .logo h1,
|
|
.sidebar .logo p,
|
|
.sidebar .nav-links span,
|
|
.sidebar .user-info p {
|
|
display: none;
|
|
}
|
|
|
|
.sidebar .nav-links a {
|
|
justify-content: center;
|
|
}
|
|
|
|
.sidebar .nav-links i {
|
|
margin-right: 0;
|
|
font-size: 20px;
|
|
}
|
|
|
|
.main-content {
|
|
margin-left: 70px;
|
|
}
|
|
|
|
.stats-grid {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Sidebar -->
|
|
<div class="sidebar">
|
|
<div class="logo">
|
|
<h1>🎥 VSS</h1>
|
|
<p>Video Streaming Server</p>
|
|
</div>
|
|
|
|
<ul class="nav-links">
|
|
<li>
|
|
<a href="/dashboard" class="active">
|
|
<i class="fas fa-tachometer-alt"></i>
|
|
<span>Dashboard</span>
|
|
</a>
|
|
</li>
|
|
<li>
|
|
<a href="/create-room">
|
|
<i class="fas fa-plus-circle"></i>
|
|
<span>Create Room</span>
|
|
</a>
|
|
</li>
|
|
<li>
|
|
<a href="#">
|
|
<i class="fas fa-cog"></i>
|
|
<span>Settings</span>
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
|
|
<div class="user-info">
|
|
<p>Logged in as: <strong>{{ username }}</strong></p>
|
|
<a href="/logout">
|
|
<button class="logout-btn">
|
|
<i class="fas fa-sign-out-alt"></i> Logout
|
|
</button>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Main Content -->
|
|
<div class="main-content">
|
|
<!-- Header -->
|
|
<div class="header">
|
|
<h2>Dashboard</h2>
|
|
<div class="header-actions">
|
|
<button class="btn btn-success" onclick="refreshStats()">
|
|
<i class="fas fa-sync-alt"></i> Refresh
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Stats Cards -->
|
|
<div class="stats-grid" id="statsGrid">
|
|
<div class="stat-card">
|
|
<h3>Total Rooms</h3>
|
|
<div class="value">{{ stats.total_rooms }}</div>
|
|
<div class="change">Active: {{ total_rooms }}</div>
|
|
</div>
|
|
|
|
<div class="stat-card">
|
|
<h3>Connected Clients</h3>
|
|
<div class="value">{{ stats.total_clients }}</div>
|
|
<div class="change">Streaming: {{ stats.total_streams }}</div>
|
|
</div>
|
|
|
|
<div class="stat-card">
|
|
<h3>CPU Usage</h3>
|
|
<div class="value">{{ stats.cpu_usage }}%</div>
|
|
<div class="change">Cores: {{ stats.system.cpu_count if stats.system else 'N/A' }}</div>
|
|
</div>
|
|
|
|
<div class="stat-card">
|
|
<h3>Memory Usage</h3>
|
|
<div class="value">{{ stats.memory_usage }}%</div>
|
|
<div class="change">
|
|
{% if stats.system %}
|
|
{{ ((stats.system.memory_total - stats.system.memory_available) / 1024 / 1024 / 1024)|round(1) }} GB used
|
|
{% else %}
|
|
0 GB used
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Rooms Section -->
|
|
<div class="section">
|
|
<div class="section-header">
|
|
<h3 class="section-title">Rooms</h3>
|
|
<a href="/create-room">
|
|
<button class="btn btn-primary">
|
|
<i class="fas fa-plus"></i> Create Room
|
|
</button>
|
|
</a>
|
|
</div>
|
|
|
|
{% if rooms %}
|
|
<div class="table-responsive">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Clients</th>
|
|
<th>Max Connections</th>
|
|
<th>Created By</th>
|
|
<th>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{% for room in rooms %}
|
|
<tr>
|
|
<td><code>{{ room.id }}</code></td>
|
|
<td>{{ room.name }}</td>
|
|
<td>
|
|
<span class="value">{{ room.clients_count }}</span>
|
|
{% if room.active_streams > 0 %}
|
|
<span class="change">({{ room.active_streams }} streaming)</span>
|
|
{% endif %}
|
|
</td>
|
|
<td>{{ room.max_connections }}</td>
|
|
<td>{{ room.created_by }}</td>
|
|
<td>
|
|
<span class="status-badge status-active">Active</span>
|
|
</td>
|
|
<td>
|
|
<div class="action-buttons">
|
|
<a href="/room/{{ room.id }}">
|
|
<button class="btn btn-primary btn-sm">
|
|
<i class="fas fa-eye"></i> View
|
|
</button>
|
|
</a>
|
|
<button class="btn btn-danger btn-sm" onclick="deleteRoom('{{ room.id }}')">
|
|
<i class="fas fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
{% else %}
|
|
<div class="loading">
|
|
<p>No rooms created yet. Create your first room!</p>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<!-- System Info -->
|
|
<div class="section">
|
|
<h3 class="section-title">System Information</h3>
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<h3>Server Uptime</h3>
|
|
<div class="value" id="uptime">Loading...</div>
|
|
<div class="change">Since {{ stats.start_time }}</div>
|
|
</div>
|
|
|
|
<div class="stat-card">
|
|
<h3>Server Address</h3>
|
|
<div class="value">{{ server_host }}:{{ server_port }}</div>
|
|
<div class="change">WebSocket: ws://{{ server_host }}:{{ server_port }}</div>
|
|
</div>
|
|
|
|
<div class="stat-card">
|
|
<h3>API Status</h3>
|
|
<div class="value">Online</div>
|
|
<div class="change change-up">All systems operational</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function formatUptime(seconds) {
|
|
const days = Math.floor(seconds / 86400);
|
|
const hours = Math.floor((seconds % 86400) / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
|
|
let result = [];
|
|
if (days > 0) result.push(`${days}d`);
|
|
if (hours > 0) result.push(`${hours}h`);
|
|
if (minutes > 0) result.push(`${minutes}m`);
|
|
|
|
return result.join(' ') || 'Just started';
|
|
}
|
|
|
|
function updateUptime() {
|
|
const uptimeElement = document.getElementById('uptime');
|
|
if (uptimeElement && {{ stats.uptime }}) {
|
|
uptimeElement.textContent = formatUptime({{ stats.uptime }});
|
|
}
|
|
}
|
|
|
|
async function deleteRoom(roomId) {
|
|
if (confirm('Are you sure you want to delete this room? All clients will be disconnected.')) {
|
|
try {
|
|
const response = await fetch(`/api/delete-room/${roomId}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
alert('Room deleted successfully!');
|
|
location.reload();
|
|
} else {
|
|
alert('Error: ' + (result.error || 'Failed to delete room'));
|
|
}
|
|
} catch (error) {
|
|
alert('Error: ' + error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
async function refreshStats() {
|
|
try {
|
|
const sessionId = getCookie('session_id');
|
|
if (!sessionId) {
|
|
window.location.href = '/';
|
|
return;
|
|
}
|
|
|
|
const response = await fetch(`/api/stats?session_id=${sessionId}`);
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
location.reload();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error refreshing stats:', error);
|
|
}
|
|
}
|
|
|
|
function getCookie(name) {
|
|
const value = `; ${document.cookie}`;
|
|
const parts = value.split(`; ${name}=`);
|
|
if (parts.length === 2) return parts.pop().split(';').shift();
|
|
return null;
|
|
}
|
|
|
|
// Update uptime every minute
|
|
updateUptime();
|
|
setInterval(updateUptime, 60000);
|
|
|
|
// Auto-refresh every 30 seconds
|
|
setInterval(refreshStats, 30000);
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|