From 795e078a0d5dfdecdea0ab8db3e8e76c30de6e80 Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Tue, 14 May 2024 02:15:19 +0100 Subject: [PATCH] Begin --- src/caddy-log-parser/index.html | 23 ++++++++++++++ src/caddy-log-parser/script.js | 54 +++++++++++++++++++++++++++++++++ src/caddy-log-parser/style.css | 0 src/faq.css | 23 -------------- src/index.css | 22 ++++++++++++++ 5 files changed, 99 insertions(+), 23 deletions(-) create mode 100644 src/caddy-log-parser/index.html create mode 100644 src/caddy-log-parser/script.js create mode 100644 src/caddy-log-parser/style.css diff --git a/src/caddy-log-parser/index.html b/src/caddy-log-parser/index.html new file mode 100644 index 0000000..e15b32a --- /dev/null +++ b/src/caddy-log-parser/index.html @@ -0,0 +1,23 @@ + + + + + + Caddy log parser | nexy7574.co.uk + + + + + +
+

Caddy log parser

+
+ + + +
+
+
+
+ + \ No newline at end of file diff --git a/src/caddy-log-parser/script.js b/src/caddy-log-parser/script.js new file mode 100644 index 0000000..0118833 --- /dev/null +++ b/src/caddy-log-parser/script.js @@ -0,0 +1,54 @@ +function createAccessLogSection(json) { + const section = document.createElement('section'); + section.classList.add('access-log'); + section.innerHTML = ` +
${JSON.stringify(json, null, 2)}
+ `; + 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); diff --git a/src/caddy-log-parser/style.css b/src/caddy-log-parser/style.css new file mode 100644 index 0000000..e69de29 diff --git a/src/faq.css b/src/faq.css index eda2aba..88c0893 100644 --- a/src/faq.css +++ b/src/faq.css @@ -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; -} diff --git a/src/index.css b/src/index.css index ee49567..22f629e 100644 --- a/src/index.css +++ b/src/index.css @@ -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; +}