This commit is contained in:
Nexus 2024-05-14 02:15:19 +01:00
parent f6330f9f6d
commit 795e078a0d
Signed by: nex
GPG key ID: 0FA334385D0B689F
5 changed files with 99 additions and 23 deletions

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Caddy log parser | nexy7574.co.uk</title>
<script src="script.js" defer></script>
<link rel="stylesheet" href="../index.css">
<link rel="stylesheet" href="../responsive.css"/>
</head>
<body>
<main>
<h1>Caddy log parser</h1>
<form enctype="multipart/form-data">
<label for="file">Select log file</label>
<input type="file" name="file" id="file" required>
<button type="submit">Parse</button>
</form>
<hr/>
<div id="output"></div>
</main>
</body>
</html>

View file

@ -0,0 +1,54 @@
function createAccessLogSection(json) {
const section = document.createElement('section');
section.classList.add('access-log');
section.innerHTML = `
<code class="block"><pre>${JSON.stringify(json, null, 2)}</pre></code>
`;
return section;
}
function onSubmit(event) {
event.preventDefault();
const fileInput = document.getElementById('file');
const file = fileInput.files[0];
const reader = new FileReader();
const output = document.getElementById('output');
reader.onload = function(e) {
const contents = e.target.result;
const lines = contents.split('\n');
output.innerHTML = '';
for (let line of lines) {
let json;
try {
json = JSON.parse(line);
} catch (e) {
console.error('Error parsing line: ', line);
console.error(e);
continue;
}
console.debug(json);
if(json.logger.includes("http.log.access")) {
const section = createAccessLogSection(json);
output.appendChild(section);
}
};
fileInput.value = null;
};
reader.readAsText(file);
}
function addListener() {
const form = document.getElementsByTagName('form')[0];
form.addEventListener(
"submit",
onSubmit
)
}
document.addEventListener("DOMContentLoaded", addListener);

View file

View file

@ -10,26 +10,3 @@
.question p {
font-size: large
}
code.block {
display: block;
padding: 1em;
margin: 1em 0;
background-color: #1f1f1f;
color: #dcdcdc;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 14px;
line-height: 1.5;
border-radius: 5px;
overflow-x: auto;
}
code.inline {
background-color: #1f1f1f;
color: #dcdcdc;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: initial;
line-height: 1.2;
border-radius: 3px;
padding: 0.4em 0.6em;
}

View file

@ -108,3 +108,25 @@ table tr:hover {
font-weight: bold;
}
code.block {
display: block;
padding: 1em;
margin: 1em 0;
background-color: #1f1f1f;
color: #dcdcdc;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: 14px;
line-height: 1.5;
border-radius: 5px;
overflow-x: auto;
}
code.inline {
background-color: #1f1f1f;
color: #dcdcdc;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
font-size: initial;
line-height: 1.2;
border-radius: 3px;
padding: 0.4em 0.6em;
}