Update index.php

This commit is contained in:
SubleXBle
2025-07-28 00:57:15 +02:00
committed by GitHub
parent 534a29731f
commit 77cba3d6ec

View File

@@ -54,93 +54,5 @@ $filesJson = json_encode($files);
<tbody></tbody>
</table>
<script>
// Files from PHP
const availableFiles = <?php echo $filesJson; ?>;
const jsonDirectory = './archive/';
function formatDateFromFilename(filename) {
const dateStr = filename.match(/(\d{4})(\d{2})(\d{2})/);
if (!dateStr) return filename;
const date = new Date(`${dateStr[1]}-${dateStr[2]}-${dateStr[3]}`);
return date.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
}
async function populateDateDropdown() {
const select = document.getElementById('dateSelect');
select.innerHTML = '';
availableFiles.forEach(file => {
const option = document.createElement('option');
option.value = file;
option.textContent = formatDateFromFilename(file);
select.appendChild(option);
});
if (availableFiles.length) loadAndRender(availableFiles[0]);
}
async function loadAndRender(filename) {
try {
const response = await fetch(jsonDirectory + filename);
if (!response.ok) throw new Error('Could not load the file');
const data = await response.json();
renderTable(data);
} catch (err) {
alert('Error loading data: ' + err.message);
}
}
function renderTable(data) {
const tbody = document.querySelector('#resultTable tbody');
const actionFilter = document.getElementById('actionFilter').value;
const jailFilter = document.getElementById('jailFilter').value;
const ipFilter = document.getElementById('ipFilter').value.trim();
const filtered = data.filter(entry => {
return (!actionFilter || entry.action === actionFilter) &&
(!jailFilter || entry.jail === jailFilter) &&
(!ipFilter || entry.ip.includes(ipFilter));
});
// Populate jail filter only once
const jails = [...new Set(data.map(e => e.jail))].sort();
const jailSelect = document.getElementById('jailFilter');
if (!jailSelect.dataset.populated) {
// Empty option for "all"
const emptyOption = document.createElement('option');
emptyOption.value = "";
emptyOption.textContent = "All";
jailSelect.appendChild(emptyOption);
jails.forEach(j => {
const o = document.createElement('option');
o.value = j;
o.textContent = j;
jailSelect.appendChild(o);
});
jailSelect.dataset.populated = true;
}
tbody.innerHTML = '';
filtered.forEach(entry => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${entry.timestamp}</td>
<td>${entry.action}</td>
<td>${entry.ip}</td>
<td>${entry.jail}</td>
`;
tbody.appendChild(row);
});
}
// Event listeners
document.getElementById('dateSelect').addEventListener('change', e => loadAndRender(e.target.value));
document.getElementById('actionFilter').addEventListener('change', () => loadAndRender(document.getElementById('dateSelect').value));
document.getElementById('jailFilter').addEventListener('change', () => loadAndRender(document.getElementById('dateSelect').value));
document.getElementById('ipFilter').addEventListener('input', () => loadAndRender(document.getElementById('dateSelect').value));
// Initialize
populateDateDropdown();
</script>
</body>
</html>