Check-Gui added
All checks were successful
release-tag / release-image (push) Successful in 1m49s

This commit is contained in:
2025-11-12 03:33:16 +01:00
parent 2cf8c4204d
commit 2eea551964

207
main.go
View File

@@ -248,7 +248,8 @@ func main() {
}
// Server
http.Handle("/", instrumentFunc("gui", handleGUI))
http.Handle("/", instrumentFunc("gui", checkhtml))
http.Handle("/admin", instrumentFunc("admin", handleGUI))
http.Handle("/download/", instrumentFunc("download", handleDownload))
http.Handle("/whitelist", instrumentFunc("whitelist", handleWhitelist))
http.Handle("/check/", instrumentFunc("check", handleCheck))
@@ -826,6 +827,210 @@ func handleGUI(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(html))
}
func checkhtml(w http.ResponseWriter, r *http.Request) {
html := `<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>FLODP IP Check</title>
<style>
:root{
--bg:#f6f7f9;--text:#1f2937;--muted:#6b7280;--card:#ffffff;
--success:#22c55e;--danger:#ef4444;--accent:#2563eb;--border:#e5e7eb;
}
*{box-sizing:border-box}
html,body{height:100%}
body{margin:0;background:var(--bg);color:var(--text);font:16px/1.5 system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,"Helvetica Neue",Arial}
.wrap{max-width:980px;margin:0 auto;padding:40px 16px 64px}
header{display:flex;align-items:center;gap:12px;flex-wrap:wrap;}
h1{font-size:clamp(24px,4vw,38px);font-weight:700;margin:0}
.pill{display:inline-flex;align-items:center;gap:8px;padding:6px 10px;border-radius:999px;border:1px solid var(--border);background:#fff;font-weight:600;font-size:14px;color:#111}
.pill small{font-weight:500;color:var(--muted)}
p.lead{margin:12px 0 24px;color:var(--muted)}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:18px;margin-top:16px}
.node{background:var(--card);border:1px solid var(--border);border-radius:14px;padding:18px;display:flex;flex-direction:column;gap:12px;box-shadow:0 6px 18px rgba(0,0,0,.04)}
.node h3{margin:0 0 4px;font-size:16px}
.sub{margin:0;color:var(--muted);font-size:14px}
.status-badge{display:inline-flex;align-items:center;gap:8px;padding:6px 10px;border-radius:999px;border:1px solid var(--border);background:#fff;font-weight:700;width:max-content}
.status-badge.ok{color:var(--success);border-color:#bbf7d0;background:#f0fdf4}
.status-badge.err{color:var(--danger);border-color:#fecaca;background:#fef2f2}
.row{display:flex;gap:12px;flex-wrap:wrap}
.field{display:flex;flex-direction:column;gap:6px;flex:1;min-width:220px}
label{font-weight:600}
input[type="text"]{
padding:12px;border-radius:10px;border:1px solid var(--border);outline:none;background:#fff;
}
input[type="text"]:focus{border-color:var(--accent);box-shadow:0 0 0 3px rgba(37,99,235,.15)}
.btn{border:1px solid var(--border);background:#fff;font-weight:600;padding:10px 14px;border-radius:10px;cursor:pointer}
.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn:disabled{opacity:.6;cursor:not-allowed}
.muted{color:var(--muted)}
.code{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;white-space:pre-wrap;background:#f8fafc;border:1px solid var(--border);padding:12px;border-radius:10px}
.chip{display:inline-block;margin:4px 6px 0 0;padding:4px 8px;border-radius:999px;background:#eef2ff;border:1px solid #c7d2fe;color:#3730a3;font-weight:600;font-size:12px}
footer{margin-top:40px;color:var(--muted);font-size:13px;text-align:center}
.hint{font-size:13px;color:var(--muted)}
</style>
</head>
<body>
<div class="wrap">
<header>
<h1>IP Check</h1>
<span class="pill">FLODP <small>Security Utility</small></span>
</header>
<p class="lead">Prüfe schnell, ob eine IP in den Blocklisten gelistet ist. Die Abfrage nutzt den Endpunkt <code>/check/&lt;ip&gt;</code>.</p>
<section class="grid" aria-label="IP-Check">
<!-- Formular -->
<article class="node">
<h3>Anfrage</h3>
<p class="sub">Sende eine Abfrage an <code>/check/&lt;ip&gt;</code></p>
<form id="checkForm" class="row" novalidate>
<div class="field">
<label for="ip">IP-Adresse</label>
<input id="ip" name="ip" type="text" placeholder="z. B. 203.0.113.42 oder 2001:db8::1" autocomplete="off" required>
<small class="hint">IPv4 oder IPv6. Es erfolgt eine leichte Client-Validierung.</small>
</div>
<div class="row" style="align-items:flex-end">
<button id="btnCheck" class="btn primary" type="submit">Check ausführen</button>
<button id="btnClear" class="btn" type="button">Zurücksetzen</button>
</div>
</form>
</article>
<!-- Ergebnis -->
<article class="node" id="resultCard" aria-live="polite">
<h3>Ergebnis</h3>
<div id="statusBadge" class="status-badge" style="display:none"></div>
<div id="summary" class="muted">Noch keine Abfrage durchgeführt.</div>
<div id="catsWrap" style="display:none">
<strong>Kategorien:</strong>
<div id="cats"></div>
</div>
<details id="rawWrap" style="margin-top:8px; display:none">
<summary><strong>Rohdaten (Response JSON)</strong></summary>
<pre id="raw" class="code"></pre>
</details>
</article>
</section>
<footer>
<span>© First-Line-Of-Defense-Project</span>
</footer>
</div>
<script>
const form = document.getElementById('checkForm');
const ipInput = document.getElementById('ip');
const btnCheck = document.getElementById('btnCheck');
const btnClear = document.getElementById('btnClear');
const statusBadge = document.getElementById('statusBadge');
const summary = document.getElementById('summary');
const catsWrap = document.getElementById('catsWrap');
const cats = document.getElementById('cats');
const rawWrap = document.getElementById('rawWrap');
const raw = document.getElementById('raw');
// Simple IPv4/IPv6 Check (nicht perfekt, aber hilfreich)
function looksLikeIP(value){
const v = value.trim();
const ipv4 = /^(25[0-5]|2[0-4]\d|[01]?\d\d?)(\.(25[0-5]|2[0-4]\d|[01]?\d\d?)){3}$/;
const ipv6 = /^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$/i; // sehr tolerant
return ipv4.test(v) || ipv6.test(v);
}
function setLoading(loading){
btnCheck.disabled = loading;
btnCheck.textContent = loading ? 'Wird geprüft…' : 'Check ausführen';
ipInput.disabled = loading;
}
function setStatus(ok, text){
statusBadge.style.display = 'inline-flex';
statusBadge.className = 'status-badge ' + (ok ? 'ok' : 'err');
statusBadge.textContent = ok ? 'OK • not listed' : 'BLOCKED • listed';
summary.textContent = text;
}
function resetUI(){
statusBadge.style.display = 'none';
statusBadge.className = 'status-badge';
summary.textContent = 'Noch keine Abfrage durchgeführt.';
catsWrap.style.display = 'none';
cats.innerHTML = '';
rawWrap.style.display = 'none';
raw.textContent = '';
}
btnClear.addEventListener('click', () => {
form.reset();
resetUI();
ipInput.focus();
});
form.addEventListener('submit', async (e) => {
e.preventDefault();
const ip = ipInput.value.trim();
if(!looksLikeIP(ip)){
ipInput.focus();
ipInput.select();
summary.textContent = 'Bitte eine gültige IPv4- oder IPv6-Adresse eingeben.';
statusBadge.style.display = 'inline-flex';
statusBadge.className = 'status-badge err';
statusBadge.textContent = 'Ungültige IP';
catsWrap.style.display = 'none';
rawWrap.style.display = 'none';
return;
}
setLoading(true);
try{
const res = await fetch('/check/' + encodeURIComponent(ip));
const data = await res.json();
// Erwartete Struktur: { ip: "...", blocked: bool, categories: [] }
const ok = data && data.blocked === false;
setStatus(ok, ok
? 'Die IP ' + data.ip + ' ist nicht gelistet.'
: 'Die IP ' + data.ip + ' ist gelistet.');
// Kategorien
const list = Array.isArray(data.categories) ? data.categories : [];
if(!ok && list.length > 0){
catsWrap.style.display = 'block';
cats.innerHTML = list.map(function(c){ return '<span class="chip">' + c + '</span>'; }).join('');
}else{
catsWrap.style.display = 'none';
cats.innerHTML = '';
}
// Rohdaten anzeigen
rawWrap.style.display = 'block';
raw.textContent = JSON.stringify(data, null, 2);
}catch(err){
setStatus(false, 'Fehler bei der Abfrage. Details siehe Konsole.');
console.error(err);
rawWrap.style.display = 'none';
}finally{
setLoading(false);
}
});
</script>
</body>
</html>`
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(html))
}
func errorhtml(w http.ResponseWriter, r *http.Request) {
html := `<!doctype html>
<html lang="de">