Repository navigation
Expand file tree
/
Copy pathadmin.html
More file actions
316 lines (277 loc) · 14.4 KB
/
Copy pathadmin.html
File metadata and controls
316 lines (277 loc) · 14.4 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vibe DevOps Admin</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
[x-cloak] { display: none !important; }
.table-container { max-height: calc(100vh - 300px); overflow-y: auto; }
.json-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.json-cell:hover { white-space: pre-wrap; overflow: visible; position: relative; z-index: 10; background: #1f2937; padding: 8px; border-radius: 4px; }
</style>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen">
<div id="app" class="container mx-auto px-4 py-8">
<!-- Header -->
<div class="mb-8">
<h1 class="text-3xl font-bold text-white">🚀 Vibe DevOps Admin</h1>
<p class="text-gray-400 mt-1">Database administration panel</p>
</div>
<!-- Stats Dashboard -->
<div id="dashboard" class="grid grid-cols-2 md:grid-cols-5 gap-4 mb-8">
<!-- Stats cards will be populated by JS -->
</div>
<!-- Navigation -->
<div class="flex flex-wrap gap-2 mb-6">
<button onclick="loadTable('users')" class="nav-btn px-4 py-2 rounded-lg bg-gray-700 hover:bg-blue-600 transition-colors" data-table="users">
👤 Users
</button>
<button onclick="loadTable('social-identifiers')" class="nav-btn px-4 py-2 rounded-lg bg-gray-700 hover:bg-blue-600 transition-colors" data-table="social-identifiers">
🔗 Social Identifiers
</button>
<button onclick="loadTable('user-passwords')" class="nav-btn px-4 py-2 rounded-lg bg-gray-700 hover:bg-blue-600 transition-colors" data-table="user-passwords">
🔐 Passwords
</button>
<button onclick="loadTable('session-tokens')" class="nav-btn px-4 py-2 rounded-lg bg-gray-700 hover:bg-blue-600 transition-colors" data-table="session-tokens">
🎫 Sessions
</button>
<button onclick="loadTable('refresh-tokens')" class="nav-btn px-4 py-2 rounded-lg bg-gray-700 hover:bg-blue-600 transition-colors" data-table="refresh-tokens">
🔄 Refresh Tokens
</button>
</div>
<!-- Table Section -->
<div id="table-section" class="bg-gray-800 rounded-lg p-6 hidden">
<div class="flex justify-between items-center mb-4">
<h2 id="table-title" class="text-xl font-semibold"></h2>
<div class="flex items-center gap-4">
<label class="text-sm text-gray-400">
Per page:
<select id="per-page" onchange="changePage(1)" class="ml-2 bg-gray-700 rounded px-2 py-1">
<option value="10">10</option>
<option value="25" selected>25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
</label>
</div>
</div>
<!-- Table Container -->
<div class="table-container overflow-x-auto">
<table id="data-table" class="w-full text-sm">
<thead id="table-head" class="bg-gray-700 sticky top-0">
<!-- Headers populated by JS -->
</thead>
<tbody id="table-body" class="divide-y divide-gray-700">
<!-- Data populated by JS -->
</tbody>
</table>
</div>
<!-- Pagination -->
<div id="pagination" class="flex justify-between items-center mt-4 pt-4 border-t border-gray-700">
<div id="pagination-info" class="text-sm text-gray-400"></div>
<div class="flex gap-2">
<button onclick="prevPage()" id="prev-btn" class="px-3 py-1 rounded bg-gray-700 hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed">
← Prev
</button>
<span id="page-indicator" class="px-3 py-1 text-gray-400"></span>
<button onclick="nextPage()" id="next-btn" class="px-3 py-1 rounded bg-gray-700 hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed">
Next →
</button>
</div>
</div>
</div>
<!-- Loading State -->
<div id="loading" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div class="bg-gray-800 rounded-lg p-6 flex items-center gap-3">
<svg class="animate-spin h-6 w-6 text-blue-500" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
</svg>
<span>Loading...</span>
</div>
</div>
</div>
<script>
// State
let currentTable = null;
let currentPage = 1;
let pagination = null;
// Table configurations
const tableConfigs = {
'users': {
title: '👤 Users',
endpoint: '/api/admin/users',
columns: ['id', 'display_name', 'avatar_url', 'status', 'metadata', 'created_at', 'updated_at', 'deleted_at']
},
'social-identifiers': {
title: '🔗 Social Identifiers',
endpoint: '/api/admin/social-identifiers',
columns: ['id', 'user_id', 'identifier_type', 'identifier_value', 'verified', 'is_primary', 'metadata', 'created_at']
},
'user-passwords': {
title: '🔐 User Passwords',
endpoint: '/api/admin/user-passwords',
columns: ['user_id', 'password_hash', 'created_at', 'updated_at']
},
'session-tokens': {
title: '🎫 Session Tokens',
endpoint: '/api/admin/session-tokens',
columns: ['id', 'user_id', 'token_hash', 'device_info', 'ip_address', 'user_agent', 'expires_at', 'revoked_at', 'last_used_at', 'created_at']
},
'refresh-tokens': {
title: '🔄 Refresh Tokens',
endpoint: '/api/admin/refresh-tokens',
columns: ['id', 'user_id', 'token_hash', 'session_id', 'family_id', 'generation', 'ip_address', 'expires_at', 'revoked_at', 'created_at']
}
};
// Load dashboard stats
async function loadStats() {
try {
const response = await fetch('/api/admin/stats');
const stats = await response.json();
const dashboard = document.getElementById('dashboard');
dashboard.innerHTML = `
<div class="bg-gray-800 rounded-lg p-4 cursor-pointer hover:bg-gray-700 transition-colors" onclick="loadTable('users')">
<div class="text-2xl font-bold text-blue-400">${stats.users.toLocaleString()}</div>
<div class="text-sm text-gray-400">Users</div>
</div>
<div class="bg-gray-800 rounded-lg p-4 cursor-pointer hover:bg-gray-700 transition-colors" onclick="loadTable('social-identifiers')">
<div class="text-2xl font-bold text-green-400">${stats.social_identifiers.toLocaleString()}</div>
<div class="text-sm text-gray-400">Identifiers</div>
</div>
<div class="bg-gray-800 rounded-lg p-4 cursor-pointer hover:bg-gray-700 transition-colors" onclick="loadTable('user-passwords')">
<div class="text-2xl font-bold text-yellow-400">${stats.user_passwords.toLocaleString()}</div>
<div class="text-sm text-gray-400">Passwords</div>
</div>
<div class="bg-gray-800 rounded-lg p-4 cursor-pointer hover:bg-gray-700 transition-colors" onclick="loadTable('session-tokens')">
<div class="text-2xl font-bold text-purple-400">${stats.session_tokens.toLocaleString()}</div>
<div class="text-sm text-gray-400">Sessions</div>
</div>
<div class="bg-gray-800 rounded-lg p-4 cursor-pointer hover:bg-gray-700 transition-colors" onclick="loadTable('refresh-tokens')">
<div class="text-2xl font-bold text-pink-400">${stats.refresh_tokens.toLocaleString()}</div>
<div class="text-sm text-gray-400">Refresh Tokens</div>
</div>
`;
} catch (error) {
console.error('Failed to load stats:', error);
}
}
// Load table data
async function loadTable(tableName) {
currentTable = tableName;
currentPage = 1;
await fetchTableData();
// Update nav button styles
document.querySelectorAll('.nav-btn').forEach(btn => {
btn.classList.remove('bg-blue-600');
btn.classList.add('bg-gray-700');
});
document.querySelector(`[data-table="${tableName}"]`)?.classList.add('bg-blue-600');
document.querySelector(`[data-table="${tableName}"]`)?.classList.remove('bg-gray-700');
}
async function fetchTableData() {
if (!currentTable) return;
const config = tableConfigs[currentTable];
const perPage = document.getElementById('per-page').value;
showLoading(true);
try {
const response = await fetch(`${config.endpoint}?page=${currentPage}&per_page=${perPage}`);
const result = await response.json();
pagination = result.pagination;
renderTable(config, result.data);
updatePagination();
document.getElementById('table-section').classList.remove('hidden');
} catch (error) {
console.error('Failed to load table:', error);
} finally {
showLoading(false);
}
}
function renderTable(config, data) {
document.getElementById('table-title').textContent = config.title;
// Render headers
const thead = document.getElementById('table-head');
thead.innerHTML = `<tr>${config.columns.map(col =>
`<th class="px-4 py-3 text-left text-xs font-medium text-gray-300 uppercase tracking-wider">${col.replace(/_/g, ' ')}</th>`
).join('')}</tr>`;
// Render body
const tbody = document.getElementById('table-body');
if (data.length === 0) {
tbody.innerHTML = `<tr><td colspan="${config.columns.length}" class="px-4 py-8 text-center text-gray-500">No data found</td></tr>`;
return;
}
tbody.innerHTML = data.map(row => `
<tr class="hover:bg-gray-750">
${config.columns.map(col => `<td class="px-4 py-3 ${isJsonColumn(col) ? 'json-cell' : ''}">${formatValue(row[col], col)}</td>`).join('')}
</tr>
`).join('');
}
function isJsonColumn(col) {
return ['metadata', 'device_info'].includes(col);
}
function formatValue(value, column) {
if (value === null || value === undefined) {
return '<span class="text-gray-500">null</span>';
}
if (typeof value === 'boolean') {
return value
? '<span class="text-green-400">✓</span>'
: '<span class="text-red-400">✗</span>';
}
if (typeof value === 'object') {
return `<code class="text-xs text-gray-400">${JSON.stringify(value)}</code>`;
}
// Truncate long strings
if (typeof value === 'string') {
// Format dates
if (column.includes('_at') && value.includes('T')) {
const date = new Date(value);
return `<span class="text-gray-300">${date.toLocaleString()}</span>`;
}
// Truncate hashes
if (column.includes('hash') || column.includes('_id')) {
if (value.length > 20) {
return `<span class="font-mono text-xs" title="${value}">${value.substring(0, 8)}...${value.substring(value.length - 4)}</span>`;
}
}
if (value.length > 50) {
return `<span title="${value}">${value.substring(0, 47)}...</span>`;
}
}
return value;
}
function updatePagination() {
if (!pagination) return;
document.getElementById('pagination-info').textContent =
`Showing ${((pagination.page - 1) * pagination.per_page) + 1} - ${Math.min(pagination.page * pagination.per_page, pagination.total_items)} of ${pagination.total_items.toLocaleString()}`;
document.getElementById('page-indicator').textContent =
`Page ${pagination.page} of ${pagination.total_pages}`;
document.getElementById('prev-btn').disabled = !pagination.has_prev;
document.getElementById('next-btn').disabled = !pagination.has_next;
}
function prevPage() {
if (pagination?.has_prev) {
currentPage--;
fetchTableData();
}
}
function nextPage() {
if (pagination?.has_next) {
currentPage++;
fetchTableData();
}
}
function changePage(page) {
currentPage = page;
fetchTableData();
}
function showLoading(show) {
document.getElementById('loading').classList.toggle('hidden', !show);
}
// Initialize
loadStats();
</script>
</body>
</html>