Create panel.html
Browse files- panel.html +855 -396
panel.html
CHANGED
|
@@ -1,421 +1,880 @@
|
|
| 1 |
-
<!
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
-
<meta name="
|
| 6 |
-
<title>
|
| 7 |
<style>
|
| 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 |
</style>
|
| 74 |
</head>
|
| 75 |
<body>
|
| 76 |
|
| 77 |
-
<
|
| 78 |
-
|
| 79 |
-
<
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
<
|
| 83 |
-
<
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
</div>
|
| 91 |
-
<
|
| 92 |
-
</
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
<
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
<
|
| 102 |
-
|
| 103 |
-
<
|
| 104 |
-
<section class="tab active" id="tab-overview">
|
| 105 |
-
<div class="cards" id="statCards"></div>
|
| 106 |
-
</section>
|
| 107 |
-
|
| 108 |
-
<section class="tab" id="tab-searches">
|
| 109 |
-
<div class="filters">
|
| 110 |
-
<select id="fType">
|
| 111 |
-
<option value="">All types</option>
|
| 112 |
-
<option value="mobile">mobile</option>
|
| 113 |
-
<option value="aadhaar_info">aadhaar_info</option>
|
| 114 |
-
<option value="aadhaar_family">aadhaar_family</option>
|
| 115 |
-
<option value="aadhaar_ration">aadhaar_ration</option>
|
| 116 |
-
<option value="duckdb">duckdb</option>
|
| 117 |
-
<option value="api_fallback">api_fallback</option>
|
| 118 |
-
<option value="360">🎯 360</option>
|
| 119 |
-
</select>
|
| 120 |
-
<select id="fStatus">
|
| 121 |
-
<option value="">All status</option>
|
| 122 |
-
<option value="success">success</option>
|
| 123 |
-
<option value="partial">partial</option>
|
| 124 |
-
<option value="fail">fail</option>
|
| 125 |
-
</select>
|
| 126 |
-
<input id="fUser" type="text" placeholder="user_id">
|
| 127 |
-
<input id="fFrom" type="date">
|
| 128 |
-
<input id="fTo" type="date">
|
| 129 |
-
<button class="primary" onclick="loadSearches(1)">Apply</button>
|
| 130 |
-
<button onclick="resetFilters()">Reset</button>
|
| 131 |
</div>
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
<th>#</th><th>Time (UTC)</th><th>User</th><th>Type</th>
|
| 135 |
-
<th>Query</th><th>Status</th><th>HTTP</th><th>ms</th><th></th>
|
| 136 |
-
</tr></thead>
|
| 137 |
-
<tbody id="searchBody"></tbody>
|
| 138 |
-
</table>
|
| 139 |
-
<div class="pagination" id="searchPag"></div>
|
| 140 |
-
</section>
|
| 141 |
-
|
| 142 |
-
<section class="tab" id="tab-users">
|
| 143 |
-
<table>
|
| 144 |
-
<thead><tr>
|
| 145 |
-
<th>User ID</th><th>Username</th><th>First name</th>
|
| 146 |
-
<th>First seen</th><th>Last seen</th><th>Searches</th><th>Last type</th>
|
| 147 |
-
</tr></thead>
|
| 148 |
-
<tbody id="usersBody"></tbody>
|
| 149 |
-
</table>
|
| 150 |
-
<div class="pagination" id="usersPag"></div>
|
| 151 |
-
</section>
|
| 152 |
-
|
| 153 |
-
<section class="tab" id="tab-live">
|
| 154 |
-
<table>
|
| 155 |
-
<thead><tr>
|
| 156 |
-
<th>User ID</th><th>Username</th><th>First name</th><th>Last active (UTC)</th>
|
| 157 |
-
</tr></thead>
|
| 158 |
-
<tbody id="liveBody"></tbody>
|
| 159 |
-
</table>
|
| 160 |
-
<div class="pagination" id="liveInfo"></div>
|
| 161 |
-
</section>
|
| 162 |
-
|
| 163 |
-
<section class="tab" id="tab-errors">
|
| 164 |
-
<table>
|
| 165 |
-
<thead><tr>
|
| 166 |
-
<th>Time (UTC)</th><th>User</th><th>Type</th><th>Query</th><th>HTTP</th><th>ms</th>
|
| 167 |
-
</tr></thead>
|
| 168 |
-
<tbody id="errorsBody"></tbody>
|
| 169 |
-
</table>
|
| 170 |
-
</section>
|
| 171 |
-
|
| 172 |
-
<section class="tab" id="tab-audit">
|
| 173 |
-
<table>
|
| 174 |
-
<thead><tr><th>Time</th><th>User</th><th>Action</th><th>Detail</th></tr></thead>
|
| 175 |
-
<tbody id="auditBody"></tbody>
|
| 176 |
-
</table>
|
| 177 |
-
</section>
|
| 178 |
-
</main>
|
| 179 |
-
|
| 180 |
-
<footer id="foot">—</footer>
|
| 181 |
|
| 182 |
-
<
|
| 183 |
-
|
| 184 |
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
|
|
|
|
|
|
| 187 |
function esc(s) {
|
| 188 |
-
return String(s ??
|
| 189 |
-
|
| 190 |
-
}
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
}
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
state.tab = b.dataset.tab;
|
| 211 |
-
$('tab-' + state.tab).classList.add('active');
|
| 212 |
-
refreshTab();
|
| 213 |
-
};
|
| 214 |
-
});
|
| 215 |
-
|
| 216 |
-
$('dlBtn').onclick = e => { e.stopPropagation(); $('dlMenu').classList.toggle('open'); };
|
| 217 |
-
document.addEventListener('click', () => $('dlMenu').classList.remove('open'));
|
| 218 |
-
|
| 219 |
-
async function api(path) {
|
| 220 |
-
const r = await fetch(path, { credentials: 'same-origin' });
|
| 221 |
-
if (r.status === 401) { location.reload(); return null; }
|
| 222 |
-
if (!r.ok) return null;
|
| 223 |
-
return r.json();
|
| 224 |
-
}
|
| 225 |
-
|
| 226 |
-
async function loadStats() {
|
| 227 |
-
const s = await api('/api/stats');
|
| 228 |
-
if (!s) return;
|
| 229 |
-
const cards = [
|
| 230 |
-
['Total Users', s.total_users, ''],
|
| 231 |
-
['Total Searches', s.total_searches, ''],
|
| 232 |
-
['Today', s.today, ''],
|
| 233 |
-
['Last 24h', s.last_24h, ''],
|
| 234 |
-
['Dossiers', s.dossiers, ''],
|
| 235 |
-
['Errors', s.errors, s.errors ? 'warn' : ''],
|
| 236 |
-
['Live Users', s.live_users, s.live_users ? 'ok-badge' : ''],
|
| 237 |
-
['Peak', s.peak_concurrent, ''],
|
| 238 |
-
['Banned', s.banned_count, s.banned_count ? 'danger' : ''],
|
| 239 |
-
['Maintenance', s.maintenance ? 'ON' : 'OFF', s.maintenance ? 'danger' : ''],
|
| 240 |
-
['In memory', `${s.inmem_count}/${s.max_inmem}`, ''],
|
| 241 |
-
['Log file', `${s.log_file_mb} MB`, ''],
|
| 242 |
-
];
|
| 243 |
-
$('statCards').innerHTML = cards.map(([l, v, cls]) =>
|
| 244 |
-
`<div class="card ${cls}"><div class="label">${esc(l)}</div><div class="value">${esc(v)}</div></div>`
|
| 245 |
-
).join('');
|
| 246 |
-
$('meta').textContent = `since ${fmtTs(s.since)}`;
|
| 247 |
-
$('foot').textContent = `In-memory: ${s.inmem_count}/${s.max_inmem} · File: ${s.log_file_mb} MB · Started: ${fmtTs(s.since)}`;
|
| 248 |
-
}
|
| 249 |
-
|
| 250 |
-
async function loadSearches(page = 1) {
|
| 251 |
-
state.searchPage = page;
|
| 252 |
-
const q = new URLSearchParams({
|
| 253 |
-
page, type: $('fType').value, status: $('fStatus').value,
|
| 254 |
-
user: $('fUser').value.trim(), from: $('fFrom').value, to: $('fTo').value,
|
| 255 |
-
});
|
| 256 |
-
const d = await api('/api/searches?' + q);
|
| 257 |
-
if (!d) return;
|
| 258 |
-
$('searchBody').innerHTML = d.rows.map((r, i) => {
|
| 259 |
-
const idx = (d.page - 1) * d.per_page + i + 1;
|
| 260 |
-
return `<tr data-id="${esc(r.id)}">
|
| 261 |
-
<td class="mono">${idx}</td>
|
| 262 |
-
<td class="mono">${esc(fmtTs(r.ts_utc))}</td>
|
| 263 |
-
<td>${esc(r.username || '@' + r.user_id)}</td>
|
| 264 |
-
<td>${typePill(r.type)}</td>
|
| 265 |
-
<td class="mono">${esc(r.query)}</td>
|
| 266 |
-
<td>${statusPill(r.status)}</td>
|
| 267 |
-
<td class="mono">${esc(r.http_code)}</td>
|
| 268 |
-
<td class="mono">${esc(r.elapsed_ms)}</td>
|
| 269 |
-
<td><button onclick="toggleRow('${esc(r.id)}', this)">Open</button></td>
|
| 270 |
-
</tr>`;
|
| 271 |
-
}).join('') || `<tr><td colspan="9" class="empty">no records</td></tr>`;
|
| 272 |
-
|
| 273 |
-
const totalPages = Math.max(1, Math.ceil(d.total / d.per_page));
|
| 274 |
-
$('searchPag').innerHTML =
|
| 275 |
-
`<button ${page<=1?'disabled':''} onclick="loadSearches(${page-1})">‹ prev</button>
|
| 276 |
-
<span>page ${d.page} / ${totalPages} — ${d.total} records</span>
|
| 277 |
-
<button ${page>=totalPages?'disabled':''} onclick="loadSearches(${page+1})">next ›</button>`;
|
| 278 |
-
}
|
| 279 |
-
|
| 280 |
-
async function toggleRow(id, btn) {
|
| 281 |
-
const tr = btn.closest('tr');
|
| 282 |
-
const next = tr.nextElementSibling;
|
| 283 |
-
if (next && next.classList.contains('row-expand')) { next.remove(); btn.textContent = 'Open'; return; }
|
| 284 |
-
btn.textContent = '…';
|
| 285 |
-
const r = await api('/api/search/' + encodeURIComponent(id));
|
| 286 |
-
if (!r) { btn.textContent = 'Open'; return; }
|
| 287 |
-
|
| 288 |
-
const bodyJson = JSON.stringify(r.resp_body, null, 2);
|
| 289 |
-
const replyHtml = r.bot_reply_html || '';
|
| 290 |
-
const is360 = r.type === '360';
|
| 291 |
-
const dossierBlock = is360 && r.resp_body ? renderDossierBlock(r.resp_body) : '';
|
| 292 |
-
|
| 293 |
-
const expand = document.createElement('tr');
|
| 294 |
-
expand.className = 'row-expand';
|
| 295 |
-
expand.innerHTML = `<td colspan="9">
|
| 296 |
-
<div class="kv">
|
| 297 |
-
<div class="k">Timestamp</div>
|
| 298 |
-
<div class="mono">UTC: ${esc(r.ts_utc)}<br>Local: ${esc(r.ts_local || '')}</div>
|
| 299 |
-
<div class="k">User</div>
|
| 300 |
-
<div>${esc(r.username || '—')} (<code>${esc(r.user_id)}</code>)</div>
|
| 301 |
-
<div class="k">Type</div>
|
| 302 |
-
<div>${typePill(r.type)}</div>
|
| 303 |
-
${r.aadhaar_used ? `<div class="k">Aadhaar used</div><div class="mono"><code>${esc(r.aadhaar_used)}</code></div>` : ''}
|
| 304 |
-
${r.sections_present ? `<div class="k">Sections</div><div>${r.sections_present.map(s=>`<span class="pill type">${esc(s)}</span>`).join(' ')}</div>` : ''}
|
| 305 |
-
<div class="k">Request URL</div>
|
| 306 |
-
<div class="mono">${esc(r.req_url_redacted || '—')}</div>
|
| 307 |
-
<div class="k">Request params</div>
|
| 308 |
-
<div class="mono">${esc(JSON.stringify(r.req_params || {}))}</div>
|
| 309 |
-
<div class="k">HTTP / Status</div>
|
| 310 |
-
<div>${esc(r.http_code)} · ${statusPill(r.status)} · ${esc(r.elapsed_ms)} ms</div>
|
| 311 |
-
</div>
|
| 312 |
-
${dossierBlock}
|
| 313 |
-
<details><summary>Raw JSON response</summary><pre>${esc(bodyJson)}</pre></details>
|
| 314 |
-
<details><summary>Bot reply (rendered)</summary>
|
| 315 |
-
<iframe class="reply" sandbox srcdoc="<html><body style='color:#e6e6e6;font-family:system-ui;font-size:13px;padding:8px;'>${esc(replyHtml).replace(/\n/g,'<br>')}</body></html>"></iframe>
|
| 316 |
-
</details>
|
| 317 |
-
<div style="margin-top:.5rem;display:flex;gap:.4rem">
|
| 318 |
-
<button onclick='navigator.clipboard.writeText(${JSON.stringify(bodyJson)})'>📋 Copy JSON</button>
|
| 319 |
-
</div>
|
| 320 |
-
</td>`;
|
| 321 |
-
tr.after(expand);
|
| 322 |
-
btn.textContent = 'Close';
|
| 323 |
-
}
|
| 324 |
-
|
| 325 |
-
function renderDossierBlock(raw) {
|
| 326 |
-
const secs = raw.sections_ok || {};
|
| 327 |
-
const keys = Object.keys(secs);
|
| 328 |
-
return `<div class="dossier">
|
| 329 |
-
<h4>🎯 360° Dossier — ${esc(raw.phone)} · Aadhaar ${esc(raw.aadhaar_used || '')}</h4>
|
| 330 |
-
<div>${keys.map(k=>`<span class="pill ${secs[k]?'success':'fail'}">${esc(k)}</span>`).join(' ')}</div>
|
| 331 |
-
<details><summary>Mobile rows (${(raw.mobile_rows||[]).length})</summary><pre>${esc(JSON.stringify(raw.mobile_rows, null, 2))}</pre></details>
|
| 332 |
-
<details><summary>Aadhaar info</summary><pre>${esc(JSON.stringify(raw.aadhaar_info, null, 2))}</pre></details>
|
| 333 |
-
<details><summary>Family</summary><pre>${esc(JSON.stringify(raw.family, null, 2))}</pre></details>
|
| 334 |
-
<details><summary>Ration</summary><pre>${esc(JSON.stringify(raw.ration, null, 2))}</pre></details>
|
| 335 |
-
</div>`;
|
| 336 |
-
}
|
| 337 |
-
|
| 338 |
-
async function loadUsers(page = 1) {
|
| 339 |
-
state.userPage = page;
|
| 340 |
-
const d = await api('/api/users?page=' + page);
|
| 341 |
-
if (!d) return;
|
| 342 |
-
$('usersBody').innerHTML = d.rows.map(u => `<tr>
|
| 343 |
-
<td class="mono">${esc(u.user_id)}</td>
|
| 344 |
-
<td>${u.username ? '@' + esc(u.username) : '—'}</td>
|
| 345 |
-
<td>${esc(u.first_name || '')}</td>
|
| 346 |
-
<td class="mono">${esc(fmtTs(u.first_seen))}</td>
|
| 347 |
-
<td class="mono">${esc(fmtTs(u.last_seen))}</td>
|
| 348 |
-
<td>${esc(u.total_searches)}</td>
|
| 349 |
-
<td>${typePill(u.last_query_type || '—')}</td>
|
| 350 |
-
</tr>`).join('') || `<tr><td colspan="7" class="empty">no users</td></tr>`;
|
| 351 |
-
const totalPages = Math.max(1, Math.ceil(d.total / d.per_page));
|
| 352 |
-
$('usersPag').innerHTML =
|
| 353 |
-
`<button ${page<=1?'disabled':''} onclick="loadUsers(${page-1})">‹ prev</button>
|
| 354 |
-
<span>page ${d.page} / ${totalPages} — ${d.total} users</span>
|
| 355 |
-
<button ${page>=totalPages?'disabled':''} onclick="loadUsers(${page+1})">next ›</button>`;
|
| 356 |
-
}
|
| 357 |
-
|
| 358 |
-
async function loadLive() {
|
| 359 |
-
const d = await api('/api/live');
|
| 360 |
-
if (!d) return;
|
| 361 |
-
$('liveBody').innerHTML = d.rows.map(u => `<tr>
|
| 362 |
-
<td class="mono">${esc(u.user_id)}</td>
|
| 363 |
-
<td>${u.username ? '@' + esc(u.username) : '—'}</td>
|
| 364 |
-
<td>${esc(u.first_name || '')}</td>
|
| 365 |
-
<td class="mono">${esc(fmtTs(u.last_active))}</td>
|
| 366 |
-
</tr>`).join('') || `<tr><td colspan="4" class="empty">no live users</td></tr>`;
|
| 367 |
-
$('liveInfo').innerHTML = `<span><span class="ok-badge"></span>${d.count} user(s) in last 5 min</span>`;
|
| 368 |
-
}
|
| 369 |
-
|
| 370 |
-
async function loadErrors() {
|
| 371 |
-
const d = await api('/api/searches?status=fail&per_page=100&page=1');
|
| 372 |
-
if (!d) return;
|
| 373 |
-
$('errorsBody').innerHTML = d.rows.map(r => `<tr>
|
| 374 |
-
<td class="mono">${esc(fmtTs(r.ts_utc))}</td>
|
| 375 |
-
<td>${esc(r.username || r.user_id)}</td>
|
| 376 |
-
<td>${typePill(r.type)}</td>
|
| 377 |
-
<td class="mono">${esc(r.query)}</td>
|
| 378 |
-
<td class="mono">${esc(r.http_code)}</td>
|
| 379 |
-
<td class="mono">${esc(r.elapsed_ms)}</td>
|
| 380 |
-
</tr>`).join('') || `<tr><td colspan="6" class="empty">no errors 🎉</td></tr>`;
|
| 381 |
}
|
| 382 |
|
| 383 |
-
async function
|
| 384 |
-
const
|
| 385 |
-
if (
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
$('fUser').value = ''; $('fFrom').value = ''; $('fTo').value = '';
|
| 397 |
-
loadSearches(1);
|
| 398 |
-
}
|
| 399 |
-
|
| 400 |
-
function refreshTab() {
|
| 401 |
-
switch (state.tab) {
|
| 402 |
-
case 'overview': loadStats(); break;
|
| 403 |
-
case 'searches': loadSearches(state.searchPage); break;
|
| 404 |
-
case 'users': loadUsers(state.userPage); break;
|
| 405 |
-
case 'live': loadLive(); break;
|
| 406 |
-
case 'errors': loadErrors(); break;
|
| 407 |
-
case 'audit': loadAudit(); break;
|
| 408 |
}
|
|
|
|
| 409 |
}
|
| 410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 411 |
function logout() {
|
| 412 |
-
|
| 413 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 414 |
}
|
| 415 |
|
| 416 |
-
|
| 417 |
-
setInterval(() => { if (
|
| 418 |
-
setInterval(() => { if (state.tab === 'live') loadLive(); }, 15000);
|
| 419 |
</script>
|
| 420 |
</body>
|
| 421 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>Bot Admin</title>
|
| 7 |
<style>
|
| 8 |
+
:root {
|
| 9 |
+
--bg:#0d0f15; --bg2:#141720; --bg3:#1c2030; --bg4:#252a3d;
|
| 10 |
+
--border:#2a2f42; --border2:#353c54;
|
| 11 |
+
--text:#e8eaf2; --text2:#8a91a8; --text3:#5c637a;
|
| 12 |
+
--accent:#6366f1; --accent2:#818cf8;
|
| 13 |
+
--success:#22c55e; --warn:#f59e0b; --error:#ef4444; --info:#3b82f6;
|
| 14 |
+
--radius:8px;
|
| 15 |
+
}
|
| 16 |
+
* { box-sizing:border-box; margin:0; padding:0; }
|
| 17 |
+
body {
|
| 18 |
+
font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;
|
| 19 |
+
background:var(--bg); color:var(--text); font-size:14px; line-height:1.5;
|
| 20 |
+
}
|
| 21 |
+
button {
|
| 22 |
+
cursor:pointer; border:none; border-radius:var(--radius);
|
| 23 |
+
font-family:inherit; font-size:13px; font-weight:500;
|
| 24 |
+
padding:8px 14px; transition:all .15s;
|
| 25 |
+
}
|
| 26 |
+
button:hover { opacity:.85; }
|
| 27 |
+
button:disabled { opacity:.4; cursor:not-allowed; }
|
| 28 |
+
input, select, textarea {
|
| 29 |
+
background:var(--bg3); border:1px solid var(--border);
|
| 30 |
+
color:var(--text); padding:8px 12px; border-radius:var(--radius);
|
| 31 |
+
font-family:inherit; font-size:13px; width:100%;
|
| 32 |
+
}
|
| 33 |
+
input:focus, select:focus, textarea:focus {
|
| 34 |
+
outline:none; border-color:var(--accent);
|
| 35 |
+
}
|
| 36 |
+
.hidden { display:none !important; }
|
| 37 |
+
.badge {
|
| 38 |
+
display:inline-block; padding:2px 8px; border-radius:4px;
|
| 39 |
+
font-size:11px; font-weight:600; text-transform:uppercase; letter-spacing:.03em;
|
| 40 |
+
}
|
| 41 |
+
.badge.info { background:rgba(59,130,246,.15); color:#60a5fa; }
|
| 42 |
+
.badge.warn { background:rgba(245,158,11,.15); color:#fbbf24; }
|
| 43 |
+
.badge.error { background:rgba(239,68,68,.15); color:#f87171; }
|
| 44 |
+
.badge.critical { background:rgba(239,68,68,.3); color:#fca5a5; }
|
| 45 |
+
.badge.audit { background:rgba(99,102,241,.15); color:#a5b4fc; }
|
| 46 |
+
.badge.on { background:rgba(34,197,94,.15); color:#4ade80; }
|
| 47 |
+
.badge.off { background:rgba(107,114,128,.15); color:#9ca3af; }
|
| 48 |
+
|
| 49 |
+
/* ---------- Login ---------- */
|
| 50 |
+
.login {
|
| 51 |
+
min-height:100vh; display:flex; align-items:center; justify-content:center;
|
| 52 |
+
background:radial-gradient(circle at 50% 30%, rgba(99,102,241,.12), transparent 60%);
|
| 53 |
+
}
|
| 54 |
+
.login-box {
|
| 55 |
+
background:var(--bg2); border:1px solid var(--border); border-radius:12px;
|
| 56 |
+
padding:36px; width:100%; max-width:380px; text-align:center;
|
| 57 |
+
}
|
| 58 |
+
.login-box h1 { font-size:22px; margin-bottom:6px; }
|
| 59 |
+
.login-box p { color:var(--text2); font-size:12px; margin-bottom:22px; }
|
| 60 |
+
.login-box input { margin-bottom:12px; text-align:center; }
|
| 61 |
+
.login-box button { width:100%; background:var(--accent); color:#fff; padding:10px; font-size:14px; }
|
| 62 |
+
.err { color:var(--error); font-size:12px; min-height:16px; margin-top:8px; }
|
| 63 |
+
|
| 64 |
+
/* ---------- Layout ---------- */
|
| 65 |
+
.app { display:flex; min-height:100vh; }
|
| 66 |
+
.sidebar {
|
| 67 |
+
width:220px; background:var(--bg2); border-right:1px solid var(--border);
|
| 68 |
+
padding:20px 0; position:fixed; top:0; bottom:0; overflow-y:auto;
|
| 69 |
+
display:flex; flex-direction:column;
|
| 70 |
+
}
|
| 71 |
+
.brand { padding:0 20px 20px; font-size:16px; font-weight:700; border-bottom:1px solid var(--border); margin-bottom:12px; }
|
| 72 |
+
.nav { flex:1; }
|
| 73 |
+
.nav a {
|
| 74 |
+
display:flex; align-items:center; gap:10px; padding:10px 20px;
|
| 75 |
+
color:var(--text2); text-decoration:none; font-size:13px; cursor:pointer;
|
| 76 |
+
border-left:3px solid transparent; transition:all .15s;
|
| 77 |
+
}
|
| 78 |
+
.nav a:hover { background:var(--bg3); color:var(--text); }
|
| 79 |
+
.nav a.active { background:var(--bg3); color:var(--accent2); border-left-color:var(--accent); }
|
| 80 |
+
.logout-btn { margin:12px 20px 0; background:var(--bg4); color:var(--text); }
|
| 81 |
+
.main { flex:1; margin-left:220px; padding:20px 28px; max-width:calc(100vw - 220px); }
|
| 82 |
+
header {
|
| 83 |
+
display:flex; justify-content:space-between; align-items:center;
|
| 84 |
+
padding-bottom:16px; margin-bottom:20px; border-bottom:1px solid var(--border);
|
| 85 |
+
}
|
| 86 |
+
header h1 { font-size:20px; }
|
| 87 |
+
.header-actions { display:flex; gap:10px; align-items:center; }
|
| 88 |
+
|
| 89 |
+
/* ---------- Cards ---------- */
|
| 90 |
+
.cards { display:grid; grid-template-columns:repeat(auto-fit, minmax(160px,1fr)); gap:14px; margin-bottom:24px; }
|
| 91 |
+
.card {
|
| 92 |
+
background:var(--bg2); border:1px solid var(--border);
|
| 93 |
+
border-radius:var(--radius); padding:16px;
|
| 94 |
+
}
|
| 95 |
+
.card .label { color:var(--text2); font-size:11px; text-transform:uppercase; letter-spacing:.05em; margin-bottom:6px; }
|
| 96 |
+
.card .value { font-size:24px; font-weight:700; }
|
| 97 |
+
.card .value.sm { font-size:18px; }
|
| 98 |
+
|
| 99 |
+
/* ---------- Charts ---------- */
|
| 100 |
+
.chart-row { display:grid; grid-template-columns:2fr 1fr; gap:16px; margin-bottom:20px; }
|
| 101 |
+
.chart-box { background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius); padding:16px; }
|
| 102 |
+
.chart-box h3 { font-size:13px; color:var(--text2); margin-bottom:12px; text-transform:uppercase; letter-spacing:.05em; }
|
| 103 |
+
.bars { display:flex; align-items:flex-end; gap:6px; height:140px; }
|
| 104 |
+
.bar-wrap { flex:1; display:flex; flex-direction:column; justify-content:flex-end; align-items:center; height:100%; }
|
| 105 |
+
.bar { width:100%; background:linear-gradient(to top, var(--accent), var(--accent2)); border-radius:3px 3px 0 0; min-height:2px; }
|
| 106 |
+
.bar-label { font-size:10px; color:var(--text3); margin-top:6px; }
|
| 107 |
+
.target-list .row { display:flex; justify-content:space-between; padding:6px 0; border-bottom:1px solid var(--border); font-size:12px; }
|
| 108 |
+
.target-list .row:last-child { border-bottom:none; }
|
| 109 |
+
.target-list .target { font-family:monospace; color:var(--text); }
|
| 110 |
+
.target-list .count { color:var(--accent2); font-weight:600; }
|
| 111 |
+
|
| 112 |
+
/* ---------- Tables ---------- */
|
| 113 |
+
table { width:100%; border-collapse:collapse; background:var(--bg2); border-radius:var(--radius); overflow:hidden; }
|
| 114 |
+
th, td { padding:10px 12px; text-align:left; font-size:13px; border-bottom:1px solid var(--border); }
|
| 115 |
+
th { background:var(--bg3); color:var(--text2); font-weight:600; font-size:11px; text-transform:uppercase; letter-spacing:.05em; }
|
| 116 |
+
tr:hover td { background:var(--bg3); }
|
| 117 |
+
tr.user-row { cursor:pointer; }
|
| 118 |
+
td.mono, .mono { font-family:'SF Mono', Menlo, monospace; font-size:12px; }
|
| 119 |
+
.actions-cell { display:flex; gap:4px; flex-wrap:wrap; }
|
| 120 |
+
.btn-sm { padding:4px 8px; font-size:11px; }
|
| 121 |
+
.btn-primary { background:var(--accent); color:#fff; }
|
| 122 |
+
.btn-danger { background:var(--error); color:#fff; }
|
| 123 |
+
.btn-warn { background:var(--warn); color:#000; }
|
| 124 |
+
.btn-success { background:var(--success); color:#000; }
|
| 125 |
+
.btn-ghost { background:var(--bg3); color:var(--text); }
|
| 126 |
+
|
| 127 |
+
/* ---------- Forms ---------- */
|
| 128 |
+
.form-row { display:flex; gap:10px; margin-bottom:14px; align-items:center; flex-wrap:wrap; }
|
| 129 |
+
.form-row label { color:var(--text2); font-size:12px; min-width:80px; }
|
| 130 |
+
.form-row input, .form-row select { flex:1; min-width:120px; }
|
| 131 |
+
textarea { resize:vertical; min-height:100px; }
|
| 132 |
+
|
| 133 |
+
/* ---------- Logs ---------- */
|
| 134 |
+
.log-controls { display:flex; gap:10px; margin-bottom:14px; flex-wrap:wrap; align-items:center; }
|
| 135 |
+
.log-controls input, .log-controls select { flex:1; min-width:120px; }
|
| 136 |
+
.log-table-wrap { max-height:calc(100vh - 280px); overflow-y:auto; border:1px solid var(--border); border-radius:var(--radius); }
|
| 137 |
+
.log-table { font-size:12px; }
|
| 138 |
+
.log-table td { padding:6px 10px; }
|
| 139 |
+
.log-table .level-cell { text-align:center; }
|
| 140 |
+
.log-row.info { }
|
| 141 |
+
.log-row.warn td { background:rgba(245,158,11,.04); }
|
| 142 |
+
.log-row.error td, .log-row.critical td { background:rgba(239,68,68,.06); }
|
| 143 |
+
.log-row.audit td { background:rgba(99,102,241,.05); }
|
| 144 |
+
|
| 145 |
+
/* ---------- Drawer ---------- */
|
| 146 |
+
.drawer-bg {
|
| 147 |
+
position:fixed; inset:0; background:rgba(0,0,0,.6); z-index:100;
|
| 148 |
+
display:none;
|
| 149 |
+
}
|
| 150 |
+
.drawer-bg.open { display:block; }
|
| 151 |
+
.drawer {
|
| 152 |
+
position:fixed; top:0; right:0; bottom:0; width:min(560px, 100vw);
|
| 153 |
+
background:var(--bg2); border-left:1px solid var(--border);
|
| 154 |
+
z-index:101; display:flex; flex-direction:column;
|
| 155 |
+
transform:translateX(100%); transition:transform .2s;
|
| 156 |
+
}
|
| 157 |
+
.drawer.open { transform:translateX(0); }
|
| 158 |
+
.drawer-head { padding:20px; border-bottom:1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }
|
| 159 |
+
.drawer-body { flex:1; overflow-y:auto; padding:20px; }
|
| 160 |
+
.drawer-foot { padding:16px 20px; border-top:1px solid var(--border); background:var(--bg3); }
|
| 161 |
+
.sec-title { font-size:11px; color:var(--text2); text-transform:uppercase; letter-spacing:.05em; margin:20px 0 10px; }
|
| 162 |
+
.sec-title:first-child { margin-top:0; }
|
| 163 |
+
.kv { display:grid; grid-template-columns:120px 1fr; gap:6px 12px; font-size:13px; }
|
| 164 |
+
.kv dt { color:var(--text2); }
|
| 165 |
+
.kv dd { color:var(--text); }
|
| 166 |
+
|
| 167 |
+
/* ---------- Toast ---------- */
|
| 168 |
+
#toast {
|
| 169 |
+
position:fixed; bottom:24px; right:24px; padding:12px 20px;
|
| 170 |
+
background:var(--bg4); border:1px solid var(--border2); border-radius:var(--radius);
|
| 171 |
+
color:var(--text); font-size:13px; z-index:200;
|
| 172 |
+
opacity:0; transform:translateY(10px); transition:all .2s;
|
| 173 |
+
pointer-events:none; max-width:320px;
|
| 174 |
+
}
|
| 175 |
+
#toast.show { opacity:1; transform:translateY(0); }
|
| 176 |
+
#toast.ok { border-color:var(--success); }
|
| 177 |
+
#toast.err { border-color:var(--error); }
|
| 178 |
+
|
| 179 |
+
/* ---------- Modal ---------- */
|
| 180 |
+
.modal-bg {
|
| 181 |
+
position:fixed; inset:0; background:rgba(0,0,0,.7); z-index:300;
|
| 182 |
+
display:none; align-items:center; justify-content:center;
|
| 183 |
+
}
|
| 184 |
+
.modal-bg.open { display:flex; }
|
| 185 |
+
.modal {
|
| 186 |
+
background:var(--bg2); border:1px solid var(--border2); border-radius:12px;
|
| 187 |
+
padding:24px; width:100%; max-width:440px;
|
| 188 |
+
}
|
| 189 |
+
.modal h3 { margin-bottom:8px; }
|
| 190 |
+
.modal p { color:var(--text2); font-size:13px; margin-bottom:18px; }
|
| 191 |
+
.modal input { margin-bottom:12px; }
|
| 192 |
+
.modal-actions { display:flex; gap:10px; justify-content:flex-end; margin-top:16px; }
|
| 193 |
+
|
| 194 |
+
@media (max-width:800px) {
|
| 195 |
+
.sidebar { width:60px; }
|
| 196 |
+
.brand, .nav a span:not(.nav-icon) { display:none; }
|
| 197 |
+
.nav a { justify-content:center; padding:12px 0; }
|
| 198 |
+
.main { margin-left:60px; max-width:calc(100vw - 60px); padding:16px; }
|
| 199 |
+
.chart-row { grid-template-columns:1fr; }
|
| 200 |
+
}
|
| 201 |
</style>
|
| 202 |
</head>
|
| 203 |
<body>
|
| 204 |
|
| 205 |
+
<!-- ============ LOGIN ============ -->
|
| 206 |
+
<div id="login" class="login">
|
| 207 |
+
<div class="login-box">
|
| 208 |
+
<h1>🤖 Bot Admin</h1>
|
| 209 |
+
<p>Enter your admin password</p>
|
| 210 |
+
<input id="pwd" type="password" placeholder="Password" onkeydown="if(event.key==='Enter')doLogin()">
|
| 211 |
+
<button onclick="doLogin()">Login</button>
|
| 212 |
+
<div id="loginErr" class="err"></div>
|
| 213 |
+
</div>
|
| 214 |
+
</div>
|
| 215 |
+
|
| 216 |
+
<!-- ============ APP ============ -->
|
| 217 |
+
<div id="app" class="app hidden">
|
| 218 |
+
<aside class="sidebar">
|
| 219 |
+
<div class="brand">🤖 Bot Admin</div>
|
| 220 |
+
<nav class="nav">
|
| 221 |
+
<a onclick="showTab('dashboard')" class="active" data-tab="dashboard"><span class="nav-icon">📊</span><span>Dashboard</span></a>
|
| 222 |
+
<a onclick="showTab('users')" data-tab="users"><span class="nav-icon">👥</span><span>Users</span></a>
|
| 223 |
+
<a onclick="showTab('logs')" data-tab="logs"><span class="nav-icon">📜</span><span>Live Logs</span></a>
|
| 224 |
+
<a onclick="showTab('audit')" data-tab="audit"><span class="nav-icon">🔍</span><span>Audit</span></a>
|
| 225 |
+
<a onclick="showTab('broadcast')" data-tab="broadcast"><span class="nav-icon">📢</span><span>Broadcast</span></a>
|
| 226 |
+
<a onclick="showTab('system')" data-tab="system"><span class="nav-icon">⚙️</span><span>System</span></a>
|
| 227 |
+
</nav>
|
| 228 |
+
<button class="logout-btn" onclick="logout()">Logout</button>
|
| 229 |
+
</aside>
|
| 230 |
+
|
| 231 |
+
<main class="main">
|
| 232 |
+
<header>
|
| 233 |
+
<h1 id="pageTitle">Dashboard</h1>
|
| 234 |
+
<div class="header-actions">
|
| 235 |
+
<span id="maintBadge" class="badge off">Maintenance: ?</span>
|
| 236 |
+
<span id="meBadge" class="badge info">admin</span>
|
| 237 |
+
</div>
|
| 238 |
+
</header>
|
| 239 |
+
|
| 240 |
+
<!-- DASHBOARD -->
|
| 241 |
+
<section id="tab-dashboard" class="tab">
|
| 242 |
+
<div class="cards" id="statCards"></div>
|
| 243 |
+
<div class="chart-row">
|
| 244 |
+
<div class="chart-box">
|
| 245 |
+
<h3>Attacks · last 7 days</h3>
|
| 246 |
+
<div id="tsChart" class="bars"></div>
|
| 247 |
+
</div>
|
| 248 |
+
<div class="chart-box">
|
| 249 |
+
<h3>Top targets</h3>
|
| 250 |
+
<div id="targetsList" class="target-list"></div>
|
| 251 |
+
</div>
|
| 252 |
+
</div>
|
| 253 |
+
</section>
|
| 254 |
+
|
| 255 |
+
<!-- USERS -->
|
| 256 |
+
<section id="tab-users" class="tab hidden">
|
| 257 |
+
<div class="form-row">
|
| 258 |
+
<input id="userSearch" placeholder="Search ID or username..." oninput="loadUsers()">
|
| 259 |
+
<select id="userFilter" onchange="loadUsers()">
|
| 260 |
+
<option value="">All users</option>
|
| 261 |
+
<option value="banned=1">Banned only</option>
|
| 262 |
+
<option value="vip=1">VIP only</option>
|
| 263 |
+
</select>
|
| 264 |
+
<button class="btn-ghost" onclick="loadUsers()">Refresh</button>
|
| 265 |
+
</div>
|
| 266 |
+
<div class="log-table-wrap">
|
| 267 |
+
<table class="log-table">
|
| 268 |
+
<thead><tr>
|
| 269 |
+
<th>ID</th><th>Username</th><th>Status</th><th>Daily</th>
|
| 270 |
+
<th>Attacks</th><th>Last seen</th><th>Actions</th>
|
| 271 |
+
</tr></thead>
|
| 272 |
+
<tbody id="usersTbody"></tbody>
|
| 273 |
+
</table>
|
| 274 |
+
</div>
|
| 275 |
+
</section>
|
| 276 |
+
|
| 277 |
+
<!-- LOGS -->
|
| 278 |
+
<section id="tab-logs" class="tab hidden">
|
| 279 |
+
<div class="log-controls">
|
| 280 |
+
<input id="logSearch" placeholder="Search data..." oninput="resetLogs(); startLogPolling()">
|
| 281 |
+
<select id="logLevel" onchange="resetLogs(); startLogPolling()">
|
| 282 |
+
<option value="">All levels</option>
|
| 283 |
+
<option value="info">info</option>
|
| 284 |
+
<option value="warn">warn</option>
|
| 285 |
+
<option value="error">error</option>
|
| 286 |
+
<option value="critical">critical</option>
|
| 287 |
+
<option value="audit">audit</option>
|
| 288 |
+
</select>
|
| 289 |
+
<select id="logEvent" onchange="resetLogs(); startLogPolling()">
|
| 290 |
+
<option value="">All events</option>
|
| 291 |
+
<option value="attack_start">attack_start</option>
|
| 292 |
+
<option value="attack_ok">attack_ok</option>
|
| 293 |
+
<option value="attack_fail">attack_fail</option>
|
| 294 |
+
<option value="command">command</option>
|
| 295 |
+
<option value="callback">callback</option>
|
| 296 |
+
<option value="new_user">new_user</option>
|
| 297 |
+
<option value="ban">ban</option>
|
| 298 |
+
<option value="warn">warn</option>
|
| 299 |
+
<option value="admin_login">admin_login</option>
|
| 300 |
+
</select>
|
| 301 |
+
<button id="logPauseBtn" class="btn-ghost" onclick="toggleLogPause()">⏸ Pause</button>
|
| 302 |
+
<button class="btn-ghost" onclick="exportLogs()">⬇ Export CSV</button>
|
| 303 |
+
</div>
|
| 304 |
+
<div class="log-table-wrap">
|
| 305 |
+
<table class="log-table">
|
| 306 |
+
<thead><tr>
|
| 307 |
+
<th style="width:80px">Time</th>
|
| 308 |
+
<th style="width:80px">User</th>
|
| 309 |
+
<th style="width:130px">Event</th>
|
| 310 |
+
<th style="width:80px">Level</th>
|
| 311 |
+
<th>Data</th>
|
| 312 |
+
</tr></thead>
|
| 313 |
+
<tbody id="logsTbody"></tbody>
|
| 314 |
+
</table>
|
| 315 |
+
</div>
|
| 316 |
+
</section>
|
| 317 |
+
|
| 318 |
+
<!-- AUDIT -->
|
| 319 |
+
<section id="tab-audit" class="tab hidden">
|
| 320 |
+
<div class="log-controls">
|
| 321 |
+
<button class="btn-ghost" onclick="loadAudit()">Refresh</button>
|
| 322 |
+
<span style="color:var(--text2); font-size:12px">All admin actions (bans, toggles, broadcasts, logins)</span>
|
| 323 |
+
</div>
|
| 324 |
+
<div class="log-table-wrap">
|
| 325 |
+
<table class="log-table">
|
| 326 |
+
<thead><tr>
|
| 327 |
+
<th style="width:80px">Time</th>
|
| 328 |
+
<th style="width:80px">Admin</th>
|
| 329 |
+
<th style="width:140px">Action</th>
|
| 330 |
+
<th>Details</th>
|
| 331 |
+
</tr></thead>
|
| 332 |
+
<tbody id="auditTbody"></tbody>
|
| 333 |
+
</table>
|
| 334 |
+
</div>
|
| 335 |
+
</section>
|
| 336 |
+
|
| 337 |
+
<!-- BROADCAST -->
|
| 338 |
+
<section id="tab-broadcast" class="tab hidden">
|
| 339 |
+
<div class="chart-box" style="max-width:640px">
|
| 340 |
+
<h3>Send broadcast</h3>
|
| 341 |
+
<textarea id="bcText" placeholder="Message text (HTML allowed)" style="min-height:140px; margin-bottom:14px"></textarea>
|
| 342 |
+
<div class="form-row">
|
| 343 |
+
<label>Filter</label>
|
| 344 |
+
<select id="bcFilter">
|
| 345 |
+
<option value="all">All users</option>
|
| 346 |
+
<option value="nonbanned">Non-banned</option>
|
| 347 |
+
<option value="vip">VIP only</option>
|
| 348 |
+
</select>
|
| 349 |
+
</div>
|
| 350 |
+
<button class="btn-primary" onclick="doBroadcast()" style="width:100%; margin-top:8px">📢 Send Broadcast</button>
|
| 351 |
+
<p id="bcStatus" style="color:var(--text2); font-size:12px; margin-top:10px"></p>
|
| 352 |
+
</div>
|
| 353 |
+
</section>
|
| 354 |
+
|
| 355 |
+
<!-- SYSTEM -->
|
| 356 |
+
<section id="tab-system" class="tab hidden">
|
| 357 |
+
<div class="chart-row" style="grid-template-columns:1fr 1fr">
|
| 358 |
+
<div class="chart-box">
|
| 359 |
+
<h3>Health</h3>
|
| 360 |
+
<div id="sysHealth">Loading...</div>
|
| 361 |
+
<button class="btn-ghost" onclick="loadHealth()" style="margin-top:12px">Refresh</button>
|
| 362 |
+
</div>
|
| 363 |
+
<div class="chart-box">
|
| 364 |
+
<h3>Webhook</h3>
|
| 365 |
+
<div id="sysWebhook">Loading...</div>
|
| 366 |
+
<div class="form-row" style="margin-top:12px">
|
| 367 |
+
<input id="whUrl" placeholder="https://.../webhook">
|
| 368 |
+
<button class="btn-ghost" onclick="setWebhook()">Set</button>
|
| 369 |
+
</div>
|
| 370 |
+
</div>
|
| 371 |
+
</div>
|
| 372 |
+
<div class="chart-box" style="margin-top:16px">
|
| 373 |
+
<h3>Actions</h3>
|
| 374 |
+
<div class="actions-cell">
|
| 375 |
+
<button class="btn-ghost" onclick="testLog()">🧪 Test Log Channel</button>
|
| 376 |
+
<button class="btn-ghost" onclick="exportUsers()">⬇ Export Users</button>
|
| 377 |
+
</div>
|
| 378 |
+
</div>
|
| 379 |
+
</section>
|
| 380 |
+
</main>
|
| 381 |
+
</div>
|
| 382 |
+
|
| 383 |
+
<!-- Drawer -->
|
| 384 |
+
<div id="drawerBg" class="drawer-bg" onclick="closeDrawer()"></div>
|
| 385 |
+
<div id="drawer" class="drawer">
|
| 386 |
+
<div class="drawer-head">
|
| 387 |
+
<h2 id="drawerTitle">User</h2>
|
| 388 |
+
<button class="btn-ghost btn-sm" onclick="closeDrawer()">✕</button>
|
| 389 |
</div>
|
| 390 |
+
<div class="drawer-body" id="drawerBody"></div>
|
| 391 |
+
<div class="drawer-foot" id="drawerFoot"></div>
|
| 392 |
+
</div>
|
| 393 |
+
|
| 394 |
+
<!-- Modal -->
|
| 395 |
+
<div id="modalBg" class="modal-bg">
|
| 396 |
+
<div class="modal">
|
| 397 |
+
<h3 id="modalTitle">Confirm</h3>
|
| 398 |
+
<p id="modalText"></p>
|
| 399 |
+
<input id="modalInput" placeholder="" class="hidden">
|
| 400 |
+
<div class="modal-actions">
|
| 401 |
+
<button class="btn-ghost" onclick="closeModal()">Cancel</button>
|
| 402 |
+
<button id="modalConfirm" class="btn-primary" onclick="modalOK()">Confirm</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
</div>
|
| 404 |
+
</div>
|
| 405 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
|
| 407 |
+
<!-- Toast -->
|
| 408 |
+
<div id="toast"></div>
|
| 409 |
|
| 410 |
+
<script>
|
| 411 |
+
// ==================== CONFIG ====================
|
| 412 |
+
const API = "/api/admin";
|
| 413 |
+
let TOKEN = localStorage.getItem("adminToken") || "";
|
| 414 |
+
let _modalResolve = null;
|
| 415 |
|
| 416 |
+
// ==================== HELPERS ====================
|
| 417 |
+
function $(id) { return document.getElementById(id); }
|
| 418 |
function esc(s) {
|
| 419 |
+
return String(s ?? "").replace(/[&<>"']/g, c => ({
|
| 420 |
+
'&':'&','<':'<','>':'>','"':'"',"'":'''
|
| 421 |
+
}[c]));
|
| 422 |
+
}
|
| 423 |
+
function fmtTime(ts) {
|
| 424 |
+
if (!ts) return '—';
|
| 425 |
+
const d = new Date(ts * 1000);
|
| 426 |
+
return d.toLocaleString('en-US', {month:'short', day:'2-digit', hour:'2-digit', minute:'2-digit', second:'2-digit'});
|
| 427 |
+
}
|
| 428 |
+
function relTime(ts) {
|
| 429 |
+
if (!ts) return 'never';
|
| 430 |
+
const s = Math.floor(Date.now()/1000 - ts);
|
| 431 |
+
if (s < 60) return s + 's ago';
|
| 432 |
+
if (s < 3600) return Math.floor(s/60) + 'm ago';
|
| 433 |
+
if (s < 86400) return Math.floor(s/3600) + 'h ago';
|
| 434 |
+
return Math.floor(s/86400) + 'd ago';
|
| 435 |
+
}
|
| 436 |
+
function toast(msg, type='') {
|
| 437 |
+
const el = $('toast');
|
| 438 |
+
el.textContent = msg;
|
| 439 |
+
el.className = 'show ' + type;
|
| 440 |
+
setTimeout(() => el.className = '', 2600);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
}
|
| 442 |
|
| 443 |
+
async function api(path, opts={}) {
|
| 444 |
+
const headers = { "Content-Type": "application/json", ...(opts.headers||{}) };
|
| 445 |
+
if (TOKEN) headers["Authorization"] = "Bearer " + TOKEN;
|
| 446 |
+
const res = await fetch(API + path, {
|
| 447 |
+
method: opts.method || "GET",
|
| 448 |
+
headers,
|
| 449 |
+
body: opts.body ? JSON.stringify(opts.body) : undefined,
|
| 450 |
+
});
|
| 451 |
+
if (res.status === 401) { logout(); throw new Error("unauthorized"); }
|
| 452 |
+
if (!res.ok) {
|
| 453 |
+
let msg = await res.text();
|
| 454 |
+
try { msg = JSON.parse(msg).detail || msg; } catch {}
|
| 455 |
+
throw new Error(msg);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
}
|
| 457 |
+
return res.json();
|
| 458 |
}
|
| 459 |
|
| 460 |
+
// ==================== AUTH ====================
|
| 461 |
+
async function doLogin() {
|
| 462 |
+
const pw = $('pwd').value;
|
| 463 |
+
$('loginErr').textContent = '';
|
| 464 |
+
if (!pw) return;
|
| 465 |
+
try {
|
| 466 |
+
const r = await api('/login', {method:'POST', body:{password:pw}});
|
| 467 |
+
TOKEN = r.token;
|
| 468 |
+
localStorage.setItem('adminToken', TOKEN);
|
| 469 |
+
startApp();
|
| 470 |
+
} catch(e) {
|
| 471 |
+
$('loginErr').textContent = e.message;
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
function logout() {
|
| 475 |
+
TOKEN = '';
|
| 476 |
+
localStorage.removeItem('adminToken');
|
| 477 |
+
$('app').classList.add('hidden');
|
| 478 |
+
$('login').classList.remove('hidden');
|
| 479 |
+
}
|
| 480 |
+
function startApp() {
|
| 481 |
+
$('login').classList.add('hidden');
|
| 482 |
+
$('app').classList.remove('hidden');
|
| 483 |
+
showTab('dashboard');
|
| 484 |
+
refreshMaint();
|
| 485 |
+
setInterval(refreshMaint, 20000);
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
// Token from URL ?t=
|
| 489 |
+
(function checkUrlToken() {
|
| 490 |
+
const url = new URL(location.href);
|
| 491 |
+
const t = url.searchParams.get('t');
|
| 492 |
+
if (t) {
|
| 493 |
+
TOKEN = t;
|
| 494 |
+
localStorage.setItem('adminToken', TOKEN);
|
| 495 |
+
url.searchParams.delete('t');
|
| 496 |
+
history.replaceState(null, '', url);
|
| 497 |
+
}
|
| 498 |
+
})();
|
| 499 |
+
|
| 500 |
+
// Try to start
|
| 501 |
+
(async function boot() {
|
| 502 |
+
if (!TOKEN) return;
|
| 503 |
+
try {
|
| 504 |
+
await api('/me');
|
| 505 |
+
startApp();
|
| 506 |
+
} catch { /* show login */ }
|
| 507 |
+
})();
|
| 508 |
+
|
| 509 |
+
// ==================== TABS ====================
|
| 510 |
+
const TITLES = {dashboard:'Dashboard', users:'Users', logs:'Live Logs', audit:'Audit Log', broadcast:'Broadcast', system:'System'};
|
| 511 |
+
let currentTab = 'dashboard';
|
| 512 |
+
function showTab(name) {
|
| 513 |
+
currentTab = name;
|
| 514 |
+
document.querySelectorAll('.tab').forEach(t => t.classList.add('hidden'));
|
| 515 |
+
document.querySelectorAll('.nav a').forEach(a => a.classList.toggle('active', a.dataset.tab === name));
|
| 516 |
+
$('tab-' + name).classList.remove('hidden');
|
| 517 |
+
$('pageTitle').textContent = TITLES[name] || name;
|
| 518 |
+
if (name === 'dashboard') loadDashboard();
|
| 519 |
+
if (name === 'users') loadUsers();
|
| 520 |
+
if (name === 'logs') { resetLogs(); startLogPolling(); } else stopLogPolling();
|
| 521 |
+
if (name === 'audit') loadAudit();
|
| 522 |
+
if (name === 'system') { loadHealth(); loadWebhookInfo(); }
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
// ==================== MAINT ====================
|
| 526 |
+
async function refreshMaint() {
|
| 527 |
+
try {
|
| 528 |
+
const r = await api('/maintenance');
|
| 529 |
+
const b = $('maintBadge');
|
| 530 |
+
b.textContent = r.maintenance ? "Maintenance: ON" : "Maintenance: OFF";
|
| 531 |
+
b.className = 'badge ' + (r.maintenance ? 'warn' : 'off');
|
| 532 |
+
b.style.cursor = 'pointer';
|
| 533 |
+
b.onclick = () => toggleMaintenance(!r.maintenance);
|
| 534 |
+
} catch {}
|
| 535 |
+
}
|
| 536 |
+
async function toggleMaintenance(v) {
|
| 537 |
+
try {
|
| 538 |
+
await api('/maintenance', {method:'POST', body:{value: v}});
|
| 539 |
+
toast("Maintenance " + (v ? "ON" : "OFF"), "ok");
|
| 540 |
+
refreshMaint();
|
| 541 |
+
} catch(e) { toast(e.message, "err"); }
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// ==================== DASHBOARD ====================
|
| 545 |
+
async function loadDashboard() {
|
| 546 |
+
try {
|
| 547 |
+
const [stats, ts, targets] = await Promise.all([
|
| 548 |
+
api('/stats'), api('/stats/timeseries?days=7'), api('/stats/targets?limit=5')
|
| 549 |
+
]);
|
| 550 |
+
$('statCards').innerHTML = [
|
| 551 |
+
['Users', stats.users_total, ''],
|
| 552 |
+
['Active 24h', stats.active_24h, ''],
|
| 553 |
+
['Banned', stats.banned, ''],
|
| 554 |
+
['VIP', stats.vip, ''],
|
| 555 |
+
['Attacks 24h', stats.attacks_24h, ''],
|
| 556 |
+
['Msgs 24h', stats.msgs_24h, ''],
|
| 557 |
+
].map(([l, v]) => `<div class="card"><div class="label">${l}</div><div class="value">${v}</div></div>`).join('');
|
| 558 |
+
|
| 559 |
+
const max = Math.max(1, ...ts.map(t => t.count));
|
| 560 |
+
$('tsChart').innerHTML = ts.length
|
| 561 |
+
? ts.map(t => {
|
| 562 |
+
const h = Math.max(4, (t.count / max) * 100);
|
| 563 |
+
const lbl = new Date(t.date).toLocaleDateString('en-US', {month:'short', day:'numeric'});
|
| 564 |
+
return `<div class="bar-wrap" title="${lbl}: ${t.count}">
|
| 565 |
+
<div class="bar" style="height:${h}%"></div>
|
| 566 |
+
<div class="bar-label">${lbl}</div>
|
| 567 |
+
</div>`;
|
| 568 |
+
}).join('')
|
| 569 |
+
: '<div style="color:var(--text2); align-self:center; width:100%; text-align:center">No data yet</div>';
|
| 570 |
+
|
| 571 |
+
$('targetsList').innerHTML = targets.length
|
| 572 |
+
? targets.map(t => `<div class="row"><span class="target">${esc(t.target || '?')}</span><span class="count">${t.count}</span></div>`).join('')
|
| 573 |
+
: '<div style="color:var(--text2); font-size:12px">No attacks yet</div>';
|
| 574 |
+
} catch(e) { toast(e.message, "err"); }
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
// ==================== USERS ====================
|
| 578 |
+
async function loadUsers() {
|
| 579 |
+
const q = $('userSearch').value.trim();
|
| 580 |
+
const filter = $('userFilter').value;
|
| 581 |
+
try {
|
| 582 |
+
const r = await api(`/users?q=${encodeURIComponent(q)}&${filter}`);
|
| 583 |
+
const tb = $('usersTbody');
|
| 584 |
+
if (!r.users.length) {
|
| 585 |
+
tb.innerHTML = '<tr><td colspan="7" style="text-align:center; color:var(--text2); padding:30px">No users</td></tr>';
|
| 586 |
+
return;
|
| 587 |
+
}
|
| 588 |
+
tb.innerHTML = r.users.map(u => {
|
| 589 |
+
const status = u.banned ? '<span class="badge error">Banned</span>'
|
| 590 |
+
: u.is_vip ? '<span class="badge warn">VIP</span>'
|
| 591 |
+
: '<span class="badge info">User</span>';
|
| 592 |
+
return `<tr class="user-row" onclick="openUser(${u.id})">
|
| 593 |
+
<td class="mono">${u.id}</td>
|
| 594 |
+
<td>${esc(u.username || '—')}</td>
|
| 595 |
+
<td>${status}</td>
|
| 596 |
+
<td>${u.daily_requests}/5</td>
|
| 597 |
+
<td>${u.stats?.requests ?? 0}</td>
|
| 598 |
+
<td>${relTime(u.last_attack_time)}</td>
|
| 599 |
+
<td class="actions-cell" onclick="event.stopPropagation()">
|
| 600 |
+
${u.banned
|
| 601 |
+
? `<button class="btn-sm btn-success" onclick="userAction(${u.id}, 'unban', {})">Unban</button>`
|
| 602 |
+
: `<button class="btn-sm btn-danger" onclick="userAction(${u.id}, 'ban', {reason: prompt('Reason')})">Ban</button>`}
|
| 603 |
+
<button class="btn-sm btn-ghost" onclick="openUser(${u.id})">Open</button>
|
| 604 |
+
</td>
|
| 605 |
+
</tr>`;
|
| 606 |
+
}).join('');
|
| 607 |
+
} catch(e) { toast(e.message, "err"); }
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
async function openUser(uid) {
|
| 611 |
+
try {
|
| 612 |
+
const r = await api('/users/' + uid);
|
| 613 |
+
const u = r.user;
|
| 614 |
+
$('drawerTitle').textContent = `User ${uid}`;
|
| 615 |
+
const recs = r.recent.slice(0, 40).map(x => `
|
| 616 |
+
<div style="padding:6px 0; border-bottom:1px solid var(--border); font-size:12px">
|
| 617 |
+
<span style="color:var(--text3); font-family:monospace">${new Date(x.ts*1000).toLocaleTimeString()}</span>
|
| 618 |
+
<span class="badge ${x.level}" style="margin:0 6px">${x.event}</span>
|
| 619 |
+
<span style="color:var(--text2)">${esc(JSON.stringify(x.data).slice(0,120))}</span>
|
| 620 |
+
</div>`).join('');
|
| 621 |
+
$('drawerBody').innerHTML = `
|
| 622 |
+
<dl class="kv">
|
| 623 |
+
<dt>Username</dt><dd>${esc(u.username || '—')}</dd>
|
| 624 |
+
<dt>Status</dt><dd>${u.banned ? '🚫 Banned — ' + esc(u.ban_reason||'') : u.is_vip ? '👑 VIP' : '👤 Standard'}</dd>
|
| 625 |
+
<dt>Warnings</dt><dd>${u.warnings}/3</dd>
|
| 626 |
+
<dt>Attacks</dt><dd>${u.stats?.requests ?? 0}</dd>
|
| 627 |
+
<dt>Messages</dt><dd>${u.stats?.sent ?? 0}</dd>
|
| 628 |
+
<dt>Daily</dt><dd>${u.daily_requests}/5</dd>
|
| 629 |
+
<dt>Last attack</dt><dd>${relTime(u.last_attack_time)}</dd>
|
| 630 |
+
<dt>Last claim</dt><dd>${relTime(u.claim_time)}</dd>
|
| 631 |
+
<dt>Admin</dt><dd>${u.is_admin ? 'yes' : 'no'}</dd>
|
| 632 |
+
</dl>
|
| 633 |
+
<div class="sec-title">Recent activity</div>
|
| 634 |
+
<div>${recs || '<div style="color:var(--text2)">No activity</div>'}</div>
|
| 635 |
+
`;
|
| 636 |
+
$('drawerFoot').innerHTML = `
|
| 637 |
+
<div class="actions-cell">
|
| 638 |
+
<button class="btn-sm btn-ghost" onclick="userAction(${uid}, 'vip', {value: ${!u.is_vip}})">
|
| 639 |
+
${u.is_vip ? '❌ Remove VIP' : '👑 Make VIP'}
|
| 640 |
+
</button>
|
| 641 |
+
<button class="btn-sm btn-warn" onclick="userAction(${uid}, 'warn', {reason: prompt('Reason') || 'No reason'})">⚠ Warn</button>
|
| 642 |
+
<button class="btn-sm btn-ghost" onclick="userAction(${uid}, 'message', {text: prompt('Message to user')})">💬 DM</button>
|
| 643 |
+
<button class="btn-sm btn-ghost" onclick="userAction(${uid}, 'reset-cooldown', {})">Reset CD</button>
|
| 644 |
+
<button class="btn-sm btn-ghost" onclick="userAction(${uid}, 'reset-daily', {})">Reset daily</button>
|
| 645 |
+
<button class="btn-sm btn-ghost" onclick="userAction(${uid}, 'clear-state', {})">Clear state</button>
|
| 646 |
+
${u.banned
|
| 647 |
+
? `<button class="btn-sm btn-success" onclick="userAction(${uid}, 'unban', {})">Unban</button>`
|
| 648 |
+
: `<button class="btn-sm btn-danger" onclick="userAction(${uid}, 'ban', {reason: prompt('Reason') || 'No reason'})">Ban</button>`}
|
| 649 |
+
<button class="btn-sm btn-danger" onclick="deleteUser(${uid})">Delete</button>
|
| 650 |
+
</div>`;
|
| 651 |
+
$('drawerBg').classList.add('open');
|
| 652 |
+
$('drawer').classList.add('open');
|
| 653 |
+
} catch(e) { toast(e.message, "err"); }
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
function closeDrawer() {
|
| 657 |
+
$('drawerBg').classList.remove('open');
|
| 658 |
+
$('drawer').classList.remove('open');
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
async function userAction(uid, action, body) {
|
| 662 |
+
if (action === 'message' && (!body.text)) return;
|
| 663 |
+
if (action === 'warn' && !body.reason) return;
|
| 664 |
+
try {
|
| 665 |
+
await api(`/users/${uid}/${action}`, {method:'POST', body});
|
| 666 |
+
toast('✓ ' + action, 'ok');
|
| 667 |
+
loadUsers();
|
| 668 |
+
if ($('drawer').classList.contains('open')) openUser(uid);
|
| 669 |
+
} catch(e) { toast(e.message, 'err'); }
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
async function deleteUser(uid) {
|
| 673 |
+
const ok = await confirmModal("Delete user?", "This cannot be undone. Type DELETE to confirm.", "DELETE");
|
| 674 |
+
if (!ok) return;
|
| 675 |
+
try {
|
| 676 |
+
await api('/users/' + uid, {method:'DELETE', body:{confirm:'DELETE'}});
|
| 677 |
+
toast('✓ deleted', 'ok');
|
| 678 |
+
closeDrawer(); loadUsers();
|
| 679 |
+
} catch(e) { toast(e.message, 'err'); }
|
| 680 |
+
}
|
| 681 |
+
|
| 682 |
+
// ==================== LOGS ====================
|
| 683 |
+
let lastLogId = 0;
|
| 684 |
+
let logPaused = false;
|
| 685 |
+
let logTimer = null;
|
| 686 |
+
|
| 687 |
+
function resetLogs() {
|
| 688 |
+
lastLogId = 0;
|
| 689 |
+
$('logsTbody').innerHTML = '';
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
function stopLogPolling() {
|
| 693 |
+
if (logTimer) { clearTimeout(logTimer); logTimer = null; }
|
| 694 |
+
}
|
| 695 |
+
|
| 696 |
+
function startLogPolling() {
|
| 697 |
+
stopLogPolling();
|
| 698 |
+
if (logPaused) return;
|
| 699 |
+
pollLogs();
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
async function pollLogs() {
|
| 703 |
+
if (currentTab !== 'logs') return;
|
| 704 |
+
try {
|
| 705 |
+
const q = $('logSearch').value.trim();
|
| 706 |
+
const lvl = $('logLevel').value;
|
| 707 |
+
const ev = $('logEvent').value;
|
| 708 |
+
const params = new URLSearchParams();
|
| 709 |
+
if (lastLogId === 0) {
|
| 710 |
+
// first load: get recent 100
|
| 711 |
+
if (lvl) params.set('level', lvl);
|
| 712 |
+
if (ev) params.set('event', ev);
|
| 713 |
+
if (q) params.set('q', q);
|
| 714 |
+
params.set('per_page', 100);
|
| 715 |
+
const rows = await api('/logs?' + params);
|
| 716 |
+
rows.reverse().forEach(appendLogRow);
|
| 717 |
+
if (rows.length) lastLogId = Math.max(...rows.map(r => r.id));
|
| 718 |
+
} else {
|
| 719 |
+
const rows = await api('/logs/stream?since_id=' + lastLogId);
|
| 720 |
+
const filtered = rows.filter(r => {
|
| 721 |
+
if (lvl && r.level !== lvl) return false;
|
| 722 |
+
if (ev && r.event !== ev) return false;
|
| 723 |
+
if (q && !JSON.stringify(r.data).toLowerCase().includes(q.toLowerCase())) return false;
|
| 724 |
+
return true;
|
| 725 |
+
});
|
| 726 |
+
filtered.forEach(appendLogRow);
|
| 727 |
+
if (rows.length) lastLogId = Math.max(lastLogId, ...rows.map(r => r.id));
|
| 728 |
+
}
|
| 729 |
+
} catch(e) { console.error(e); }
|
| 730 |
+
logTimer = setTimeout(pollLogs, 3000);
|
| 731 |
+
}
|
| 732 |
+
|
| 733 |
+
function appendLogRow(r) {
|
| 734 |
+
const tb = $('logsTbody');
|
| 735 |
+
const tr = document.createElement('tr');
|
| 736 |
+
tr.className = 'log-row ' + r.level;
|
| 737 |
+
const data = JSON.stringify(r.data).slice(0, 220);
|
| 738 |
+
tr.innerHTML = `
|
| 739 |
+
<td class="mono" style="color:var(--text3)">${new Date(r.ts*1000).toLocaleTimeString()}</td>
|
| 740 |
+
<td class="mono">${r.user_id || '—'}</td>
|
| 741 |
+
<td>${esc(r.event)}</td>
|
| 742 |
+
<td><span class="badge ${r.level}">${r.level}</span></td>
|
| 743 |
+
<td class="mono" style="color:var(--text2)">${esc(data)}</td>
|
| 744 |
+
`;
|
| 745 |
+
tb.insertBefore(tr, tb.firstChild);
|
| 746 |
+
// cap rows
|
| 747 |
+
while (tb.children.length > 300) tb.removeChild(tb.lastChild);
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
function toggleLogPause() {
|
| 751 |
+
logPaused = !logPaused;
|
| 752 |
+
$('logPauseBtn').textContent = logPaused ? '▶ Resume' : '⏸ Pause';
|
| 753 |
+
if (logPaused) stopLogPolling(); else startLogPolling();
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
async function exportLogs() {
|
| 757 |
+
const w = window.open('about:blank');
|
| 758 |
+
const res = await fetch(API + '/logs/export', {headers:{Authorization:'Bearer '+TOKEN}});
|
| 759 |
+
const blob = await res.blob();
|
| 760 |
+
const url = URL.createObjectURL(blob);
|
| 761 |
+
const a = document.createElement('a');
|
| 762 |
+
a.href = url; a.download = 'logs.csv'; a.click();
|
| 763 |
+
URL.revokeObjectURL(url);
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
// ==================== AUDIT ====================
|
| 767 |
+
async function loadAudit() {
|
| 768 |
+
try {
|
| 769 |
+
const rows = await api('/audit');
|
| 770 |
+
const tb = $('auditTbody');
|
| 771 |
+
if (!rows.length) {
|
| 772 |
+
tb.innerHTML = '<tr><td colspan="4" style="text-align:center; color:var(--text2); padding:30px">No admin actions yet</td></tr>';
|
| 773 |
+
return;
|
| 774 |
+
}
|
| 775 |
+
tb.innerHTML = rows.map(r => `
|
| 776 |
+
<tr class="log-row audit">
|
| 777 |
+
<td class="mono" style="color:var(--text3)">${new Date(r.ts*1000).toLocaleTimeString()}</td>
|
| 778 |
+
<td class="mono">${r.admin_id || '—'}</td>
|
| 779 |
+
<td><b>${esc(r.event)}</b></td>
|
| 780 |
+
<td class="mono" style="color:var(--text2)">${esc(JSON.stringify(r.data).slice(0, 200))}</td>
|
| 781 |
+
</tr>`).join('');
|
| 782 |
+
} catch(e) { toast(e.message, 'err'); }
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
// ==================== BROADCAST ====================
|
| 786 |
+
async function doBroadcast() {
|
| 787 |
+
const text = $('bcText').value.trim();
|
| 788 |
+
if (!text) { toast('Empty message', 'err'); return; }
|
| 789 |
+
const filter = $('bcFilter').value;
|
| 790 |
+
const ok = await confirmModal('Send broadcast?', `This will message users matching filter "${filter}". Continue?`);
|
| 791 |
+
if (!ok) return;
|
| 792 |
+
$('bcStatus').textContent = 'Sending...';
|
| 793 |
+
try {
|
| 794 |
+
const r = await api('/broadcast', {method:'POST', body:{text, filter}});
|
| 795 |
+
$('bcStatus').textContent = `✓ Sent to ${r.sent} / ${r.targeted}`;
|
| 796 |
+
toast('Broadcast sent', 'ok');
|
| 797 |
+
} catch(e) { toast(e.message, 'err'); $('bcStatus').textContent = ''; }
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
// ==================== SYSTEM ====================
|
| 801 |
+
async function loadHealth() {
|
| 802 |
+
try {
|
| 803 |
+
const r = await api('/health');
|
| 804 |
+
$('sysHealth').innerHTML = r.ok
|
| 805 |
+
? `<span class="badge on">online</span><pre class="mono" style="font-size:11px; margin-top:8px; color:var(--text2); overflow:auto">${esc(JSON.stringify(r.data, null, 2))}</pre>`
|
| 806 |
+
: `<span class="badge error">offline</span><div style="color:var(--error); font-size:12px; margin-top:6px">${esc(r.error)}</div>`;
|
| 807 |
+
} catch(e) { $('sysHealth').innerHTML = '<span class="badge error">error</span>'; }
|
| 808 |
+
}
|
| 809 |
+
|
| 810 |
+
async function loadWebhookInfo() {
|
| 811 |
+
try {
|
| 812 |
+
const r = await api('/bot/webhook-info');
|
| 813 |
+
$('sysWebhook').innerHTML = `
|
| 814 |
+
<dl class="kv" style="font-size:12px">
|
| 815 |
+
<dt>URL</dt><dd class="mono">${esc(r.url || '(none)')}</dd>
|
| 816 |
+
<dt>Pending</dt><dd>${r.pending_update_count}</dd>
|
| 817 |
+
<dt>Last error</dt><dd>${r.last_error_message ? esc(r.last_error_message) : '—'}</dd>
|
| 818 |
+
</dl>`;
|
| 819 |
+
$('whUrl').value = r.url || '';
|
| 820 |
+
} catch(e) { $('sysWebhook').innerHTML = '<span class="badge error">error</span>'; }
|
| 821 |
+
}
|
| 822 |
+
|
| 823 |
+
async function setWebhook() {
|
| 824 |
+
const url = $('whUrl').value.trim();
|
| 825 |
+
if (!url) return;
|
| 826 |
+
try {
|
| 827 |
+
await api('/bot/set-webhook', {method:'POST', body:{url}});
|
| 828 |
+
toast('Webhook set', 'ok');
|
| 829 |
+
loadWebhookInfo();
|
| 830 |
+
} catch(e) { toast(e.message, 'err'); }
|
| 831 |
+
}
|
| 832 |
+
|
| 833 |
+
async function testLog() {
|
| 834 |
+
try {
|
| 835 |
+
await api('/bot/test-log', {method:'POST'});
|
| 836 |
+
toast('Sent to log channel', 'ok');
|
| 837 |
+
} catch(e) { toast(e.message, 'err'); }
|
| 838 |
+
}
|
| 839 |
+
|
| 840 |
+
async function exportUsers() {
|
| 841 |
+
const res = await fetch(API + '/users?per_page=10000', {headers:{Authorization:'Bearer '+TOKEN}});
|
| 842 |
+
const data = await res.json();
|
| 843 |
+
const blob = new Blob([JSON.stringify(data, null, 2)], {type:'application/json'});
|
| 844 |
+
const url = URL.createObjectURL(blob);
|
| 845 |
+
const a = document.createElement('a'); a.href = url; a.download = 'users.json'; a.click();
|
| 846 |
+
URL.revokeObjectURL(url);
|
| 847 |
+
}
|
| 848 |
+
|
| 849 |
+
// ==================== MODAL ====================
|
| 850 |
+
function confirmModal(title, text, requireInput = null) {
|
| 851 |
+
return new Promise(resolve => {
|
| 852 |
+
$('modalTitle').textContent = title;
|
| 853 |
+
$('modalText').textContent = text;
|
| 854 |
+
const inp = $('modalInput');
|
| 855 |
+
if (requireInput) {
|
| 856 |
+
inp.classList.remove('hidden');
|
| 857 |
+
inp.value = '';
|
| 858 |
+
inp.placeholder = `Type "${requireInput}" to confirm`;
|
| 859 |
+
} else {
|
| 860 |
+
inp.classList.add('hidden');
|
| 861 |
+
}
|
| 862 |
+
$('modalBg').classList.add('open');
|
| 863 |
+
_modalResolve = (val) => {
|
| 864 |
+
if (requireInput && inp.value !== requireInput) return;
|
| 865 |
+
resolve(val);
|
| 866 |
+
closeModal();
|
| 867 |
+
};
|
| 868 |
+
});
|
| 869 |
+
}
|
| 870 |
+
function modalOK() { if (_modalResolve) _modalResolve(true); }
|
| 871 |
+
function closeModal() {
|
| 872 |
+
$('modalBg').classList.remove('open');
|
| 873 |
+
_modalResolve = null;
|
| 874 |
}
|
| 875 |
|
| 876 |
+
// auto-refresh dashboard every 30s
|
| 877 |
+
setInterval(() => { if (currentTab === 'dashboard' && TOKEN) loadDashboard(); }, 30000);
|
|
|
|
| 878 |
</script>
|
| 879 |
</body>
|
| 880 |
</html>
|