-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
173 lines (164 loc) · 5.97 KB
/
index.html
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Panel Administrativo</title>
<!-- Primero cargamos todas las dependencias de Firebase -->
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore-compat.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
th {
background-color: #f8f9fa;
}
tr:nth-child(even) {
background-color: #f8f9fa;
}
.login-container {
max-width: 400px;
margin: 100px auto;
padding: 20px;
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.login-container input {
width: 100%;
padding: 8px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
.login-container button {
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
.login-container button:hover {
background-color: #0056b3;
}
#errorMessage {
color: red;
margin-top: 10px;
text-align: center;
}
</style>
</head>
<body>
<div id="loginForm" class="login-container">
<h2>Iniciar Sesión</h2>
<input type="email" id="email" placeholder="Email">
<input type="password" id="password" placeholder="Contraseña">
<button onclick="login()">Entrar</button>
<div id="errorMessage"></div>
</div>
<div id="dashboard" class="container" style="display: none;">
<h1>Panel de Control - Registro de Visitas</h1>
<table id="visitsTable">
<thead>
<tr>
<th>Fecha y Hora</th>
<th>IP</th>
<th>País</th>
<th>Ciudad</th>
<th>Coordenadas</th>
<th>Navegador</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
<script>
// Inicialización de Firebase
const firebaseConfig = {
apiKey: "AIzaSyAgdHco56N5t1YZdyt4i1yeO6fOpcO8giI",
authDomain: "paneladm-88aa4.firebaseapp.com",
projectId: "paneladm-88aa4",
storageBucket: "paneladm-88aa4.firebasestorage.app",
messagingSenderId: "979848933656",
appId: "1:979848933656:web:d8220a1371efbb13932e6d",
measurementId: "G-N13T2X5MGV"
};
// Inicializamos Firebase antes de cualquier otra operación
firebase.initializeApp(firebaseConfig);
// Luego inicializamos los servicios
const auth = firebase.auth();
const db = firebase.firestore();
async function login() {
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const errorMessage = document.getElementById('errorMessage');
try {
await auth.signInWithEmailAndPassword(email, password);
errorMessage.textContent = '';
document.getElementById('loginForm').style.display = 'none';
document.getElementById('dashboard').style.display = 'block';
loadVisits();
} catch (error) {
errorMessage.textContent = 'Error al iniciar sesión: ' + error.message;
}
}
function loadVisits() {
const tbody = document.querySelector('#visitsTable tbody');
db.collection('visits')
.orderBy('timestamp', 'desc')
.onSnapshot((snapshot) => {
tbody.innerHTML = '';
snapshot.forEach((doc) => {
const data = doc.data();
const row = document.createElement('tr');
row.innerHTML = `
<td>${data.timestamp ? new Date(data.timestamp.toDate()).toLocaleString() : 'N/A'}</td>
<td>${data.ip || 'N/A'}</td>
<td>${data.country || 'N/A'}</td>
<td>${data.city || 'N/A'}</td>
<td>${data.latitude ? `${data.latitude}, ${data.longitude}` : 'N/A'}</td>
<td>${data.userAgent || 'N/A'}</td>
`;
tbody.appendChild(row);
});
});
}
// Verificar estado de autenticación
auth.onAuthStateChanged((user) => {
if (user) {
document.getElementById('loginForm').style.display = 'none';
document.getElementById('dashboard').style.display = 'block';
loadVisits();
} else {
document.getElementById('loginForm').style.display = 'block';
document.getElementById('dashboard').style.display = 'none';
}
});
</script>
</body>
</html>