File size: 10,263 Bytes
84121fd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DaddyTV - Panel de Administración</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: {
500: '#3b82f6',
600: '#2563eb',
700: '#1d4ed8'
}
}
}
}
}
</script>
</head>
<body class="bg-gray-900 text-white min-h-screen">
<div class="container mx-auto px-4 py-8">
<div class="max-w-4xl mx-auto">
<h1 class="text-3xl font-bold mb-8 text-center">🔧 Panel de Administración DaddyTV</h1>
<!-- Login -->
<div id="loginSection" class="bg-gray-800 rounded-lg p-6 mb-6">
<h2 class="text-xl font-semibold mb-4">Autenticación</h2>
<div class="flex space-x-4">
<input
type="password"
id="adminCode"
placeholder="Código de administrador"
class="flex-1 bg-gray-700 border border-gray-600 rounded px-3 py-2"
>
<button
onclick="authenticate()"
class="bg-primary-600 hover:bg-primary-700 px-6 py-2 rounded font-medium"
>
Conectar
</button>
</div>
<div id="authStatus" class="mt-2 text-sm"></div>
</div>
<!-- Panel Principal -->
<div id="adminPanel" class="hidden space-y-6">
<!-- Estado del Sistema -->
<div class="bg-gray-800 rounded-lg p-6">
<h2 class="text-xl font-semibold mb-4">📊 Estado del Sistema</h2>
<div id="systemStatus" class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Se llenará dinámicamente -->
</div>
<button
onclick="refreshStatus()"
class="mt-4 bg-blue-600 hover:bg-blue-700 px-4 py-2 rounded"
>
🔄 Actualizar
</button>
</div>
<!-- Acciones -->
<div class="bg-gray-800 rounded-lg p-6">
<h2 class="text-xl font-semibold mb-4">⚡ Acciones</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<button
onclick="clearCache()"
class="bg-yellow-600 hover:bg-yellow-700 px-4 py-3 rounded font-medium"
>
🗑️ Limpiar Caché
</button>
<button
onclick="downloadLogs()"
class="bg-green-600 hover:bg-green-700 px-4 py-3 rounded font-medium"
>
📥 Descargar Logs
</button>
</div>
</div>
<!-- Configuración -->
<div class="bg-gray-800 rounded-lg p-6">
<h2 class="text-xl font-semibold mb-4">⚙️ Configuración</h2>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium mb-2">URL de Playlist M3U</label>
<input
type="url"
id="m3uUrl"
placeholder="https://ejemplo.com/playlist.m3u8"
class="w-full bg-gray-700 border border-gray-600 rounded px-3 py-2"
>
</div>
<button
onclick="updatePlaylist()"
class="bg-primary-600 hover:bg-primary-700 px-4 py-2 rounded font-medium"
>
💾 Actualizar Playlist
</button>
</div>
</div>
</div>
</div>
</div>
<script>
let adminToken = '';
const API_BASE = '/api';
async function authenticate() {
const code = document.getElementById('adminCode').value;
const statusDiv = document.getElementById('authStatus');
if (!code) {
statusDiv.innerHTML = '<span class="text-red-400">Por favor ingresa el código</span>';
return;
}
try {
const response = await fetch(`${API_BASE}/admin/status`, {
headers: {
'Authorization': `Bearer ${code}`
}
});
if (response.ok) {
adminToken = code;
statusDiv.innerHTML = '<span class="text-green-400">✅ Autenticado correctamente</span>';
document.getElementById('loginSection').classList.add('hidden');
document.getElementById('adminPanel').classList.remove('hidden');
await refreshStatus();
} else {
statusDiv.innerHTML = '<span class="text-red-400">❌ Código incorrecto</span>';
}
} catch (error) {
statusDiv.innerHTML = '<span class="text-red-400">❌ Error de conexión</span>';
}
}
async function refreshStatus() {
try {
const response = await fetch(`${API_BASE}/admin/status`, {
headers: {
'Authorization': `Bearer ${adminToken}`
}
});
if (response.ok) {
const data = await response.json();
displaySystemStatus(data);
}
} catch (error) {
console.error('Error refreshing status:', error);
}
}
function displaySystemStatus(data) {
const statusDiv = document.getElementById('systemStatus');
statusDiv.innerHTML = `
<div class="bg-gray-700 p-4 rounded">
<h3 class="font-semibold mb-2">📺 Canales</h3>
<p>Cacheados: ${data.cache_status.m3u_cached ? '✅' : '❌'}</p>
<p>Total: ${data.cache_status.channels_count}</p>
<p class="text-xs text-gray-400">Última actualización: ${data.cache_status.cache_timestamp || 'Nunca'}</p>
</div>
<div class="bg-gray-700 p-4 rounded">
<h3 class="font-semibold mb-2">👥 Visualizadores</h3>
<p>Usuarios activos: ${data.viewers_status.active_users}</p>
<p>Canales activos: ${data.viewers_status.active_channels}</p>
<p>Total viewers: ${data.viewers_status.total_viewers}</p>
</div>
<div class="bg-gray-700 p-4 rounded">
<h3 class="font-semibold mb-2">⚙️ Configuración</h3>
<p>M3U URL: ${data.config.m3u_url_configured ? '✅' : '❌'}</p>
<p>Admin Code: ${data.config.admin_code_configured ? '✅' : '❌'}</p>
<p class="text-xs text-gray-400">Base URL: ${data.config.base_url}</p>
</div>
`;
}
async function clearCache() {
try {
const response = await fetch(`${API_BASE}/admin/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({
action: 'clear_cache'
})
});
if (response.ok) {
const data = await response.json();
alert('✅ ' + data.message);
await refreshStatus();
} else {
alert('❌ Error al limpiar caché');
}
} catch (error) {
alert('❌ Error de conexión');
}
}
async function updatePlaylist() {
const url = document.getElementById('m3uUrl').value;
if (!url) {
alert('Por favor ingresa una URL válida');
return;
}
try {
const response = await fetch(`${API_BASE}/admin/update`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${adminToken}`
},
body: JSON.stringify({
action: 'update_playlist',
m3u_url: url
})
});
if (response.ok) {
const data = await response.json();
alert('✅ ' + data.message);
} else {
alert('❌ Error al actualizar playlist');
}
} catch (error) {
alert('❌ Error de conexión');
}
}
function downloadLogs() {
alert('📥 Función de descarga de logs no implementada aún');
}
// Auto-focus en el campo de código
document.getElementById('adminCode').focus();
// Enter para autenticar
document.getElementById('adminCode').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
authenticate();
}
});
</script>
</body>
</html> |