Skip to content

Commit 1cd6d84

Browse files
authored
Merge pull request #16 from TimInTech/fix/remove-unused-time
Fix/remove unused time
2 parents 553c185 + d1f6a3c commit 1cd6d84

6 files changed

Lines changed: 72 additions & 95 deletions

File tree

FETCH_HEAD

Whitespace-only changes.

README.de.md

Lines changed: 68 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222

2323
## ✨ Features
2424

25-
**Ein-Klick-Installation** - Setup mit einem Befehl
26-
**DNS-Sicherheit** - Pi-hole + Unbound mit DNSSEC
27-
**Netzwerk-Monitoring** - NetAlertX Geräte-Tracking
28-
**API-Monitoring** - Python FastAPI + SQLite
29-
**Produktionsbereit** - Systemd-Hardening & Auto-Restart
30-
**Idempotent** - Sicher mehrfach ausführbar
25+
**Ein-Klick-Installation** Setup mit einem Befehl
26+
**DNS-Sicherheit** Pi-hole + Unbound mit DNSSEC
27+
**Netzwerk-Monitoring** NetAlertX Geräte-Tracking
28+
**API-Monitoring** Python FastAPI + SQLite
29+
**Produktionsbereit** Systemd-Hardening & Auto-Restart
30+
**Idempotent** Sicher mehrfach ausführbar
3131

3232
---
3333

@@ -38,20 +38,20 @@ git clone https://github.com/TimInTech/Pi-hole-Unbound-PiAlert-Setup.git
3838
cd Pi-hole-Unbound-PiAlert-Setup
3939
chmod +x install.sh
4040
sudo ./install.sh
41-
```
41+
````
4242

4343
**Fertig!** 🎉 Ihr kompletter DNS-Sicherheits-Stack läuft jetzt.
4444

4545
---
4646

4747
## 🧰 Was installiert wird
4848

49-
| Komponente | Zweck | Zugriff |
50-
|------------|-------|---------|
51-
| **🕳️ Pi-hole** | DNS-Werbeblocker & Web-UI | `http://[ihre-ip]/admin` |
52-
| **🔐 Unbound** | Rekursiver DNS + DNSSEC | `127.0.0.1:5335` |
53-
| **📡 NetAlertX** | Netzwerkgeräte-Monitoring | `http://[ihre-ip]:20211` |
54-
| **🐍 Python API** | Monitoring & Statistik-API | `http://127.0.0.1:8090` |
49+
| Komponente | Zweck | Zugriff |
50+
| ----------------- | --------------------------------- | ------------------------ |
51+
| **🕳️ Pi-hole** | DNS-Werbeblocker & Web-Oberfläche | `http://[ihre-ip]/admin` |
52+
| **🔐 Unbound** | Rekursiver DNS + DNSSEC | `127.0.0.1:5335` |
53+
| **📡 NetAlertX** | Netzwerkgeräte-Monitoring | `http://[ihre-ip]:20211` |
54+
| **🐍 Python API** | Monitoring- & Statistik-API | `http://127.0.0.1:8090` |
5555

5656
---
5757

@@ -77,6 +77,7 @@ sudo ./install.sh
7777
```
7878
7979
**Datenfluss:**
80+
8081
1. **Clients** → Pi-hole (DNS-Filterung)
8182
2. **Pi-hole** → Unbound (rekursive Auflösung)
8283
3. **Unbound** → Root-Server (DNSSEC-Validierung)
@@ -87,15 +88,32 @@ sudo ./install.sh
8788
8889
## 🔌 API-Referenz
8990
91+
#### `GET /leases`
92+
93+
```json
94+
[
95+
{
96+
"ip": "192.168.1.101",
97+
"mac": "aa:bb:cc:dd:ee:ff",
98+
"hostname": "drucker",
99+
"lease_start": "2024-12-21 10:00:00",
100+
"lease_end": "2024-12-21 12:00:00"
101+
}
102+
]
103+
```
104+
90105
### Authentifizierung
91-
Alle Endpunkte benötigen `X-API-Key`-Header:
106+
107+
Alle Endpunkte benötigen den `X-API-Key`-Header:
108+
92109
```bash
93-
curl -H "X-API-Key: ihr-api-key" http://127.0.0.1:8090/endpoint
110+
curl -H "X-API-Key: $SUITE_API_KEY" http://127.0.0.1:8090/endpoint
94111
```
95112

96113
### Endpunkte
97114

98115
#### `GET /health`
116+
99117
```json
100118
{
101119
"ok": true,
@@ -105,6 +123,7 @@ curl -H "X-API-Key: ihr-api-key" http://127.0.0.1:8090/endpoint
105123
```
106124

107125
#### `GET /dns?limit=50`
126+
108127
```json
109128
[
110129
{
@@ -117,6 +136,7 @@ curl -H "X-API-Key: ihr-api-key" http://127.0.0.1:8090/endpoint
117136
```
118137

119138
#### `GET /devices`
139+
120140
```json
121141
[
122142
{
@@ -130,6 +150,7 @@ curl -H "X-API-Key: ihr-api-key" http://127.0.0.1:8090/endpoint
130150
```
131151

132152
#### `GET /stats`
153+
133154
```json
134155
{
135156
"total_dns_logs": 1250,
@@ -143,21 +164,24 @@ curl -H "X-API-Key: ihr-api-key" http://127.0.0.1:8090/endpoint
143164
## 🛠️ Manuelle Schritte (Optional)
144165

145166
### Pi-hole-Konfiguration
146-
1. Admin-Interface aufrufen: `http://[ihre-ip]/admin`
167+
168+
1. Admin-Oberfläche aufrufen: `http://[ihre-ip]/admin`
147169
2. **Einstellungen → DNS** navigieren
148-
3. **Custom upstream** prüfen: `127.0.0.1#5335`
149-
4. Geräte konfigurieren, um Pi-hole als DNS-Server zu verwenden
170+
3. **Custom Upstream** setzen: `127.0.0.1#5335`
171+
4. Geräte im Netzwerk konfigurieren, um Pi-hole als DNS-Server zu nutzen
150172

151173
### NetAlertX-Setup
152-
- Dashboard aufrufen: `http://[ihre-ip]:20211`
153-
- Scan-Zeitpläne und Benachrichtigungen konfigurieren
154-
- Netzwerk-Topologie und Geräteliste überprüfen
174+
175+
* Dashboard aufrufen: `http://[ihre-ip]:20211`
176+
* Scan-Zeitpläne und Benachrichtigungen konfigurieren
177+
* Netzwerk-Topologie und Geräteliste prüfen
155178

156179
---
157180

158181
## 🧪 Gesundheitschecks & Problembehandlung
159182

160183
### Schneller Gesundheitscheck
184+
161185
```bash
162186
# Unbound testen
163187
dig @127.0.0.1 -p 5335 example.com
@@ -173,6 +197,7 @@ curl -H "X-API-Key: $SUITE_API_KEY" http://127.0.0.1:8090/health
173197
```
174198

175199
### Service-Verwaltung
200+
176201
```bash
177202
# Services prüfen
178203
systemctl status pihole-suite unbound pihole-FTL
@@ -190,32 +215,35 @@ docker restart netalertx
190215

191216
### Häufige Probleme
192217

193-
| Problem | Lösung |
194-
|---------|--------|
195-
| **Port 53 belegt** | `sudo systemctl stop systemd-resolved` |
196-
| **API-Key fehlt** | `.env`-Datei prüfen oder mit Installer neu generieren |
197-
| **Datenbankfehler** | `python scripts/bootstrap.py` ausführen |
198-
| **Unbound startet nicht** | `/etc/unbound/unbound.conf.d/pi-hole.conf` prüfen |
218+
| Problem | Lösung |
219+
| ------------------------- | -------------------------------------------------------------------------------------------- |
220+
| **Port 53 belegt** | `sudo systemctl stop systemd-resolved` *(ggf. dauerhaft: disable + /etc/resolv.conf prüfen)* |
221+
| **API-Key fehlt** | `.env`-Datei prüfen oder mit Installer neu generieren |
222+
| **Datenbankfehler** | `python scripts/bootstrap.py` ausführen |
223+
| **Unbound startet nicht** | `/etc/unbound/unbound.conf.d/pi-hole.conf` prüfen |
199224

200225
---
201226

202227
## 🧯 Sicherheitshinweise
203228

204229
### 🔐 API-Sicherheit
205-
- **API-Keys** werden automatisch generiert (16-Byte Hex)
206-
- **CORS** nur für localhost aktiviert
207-
- **Authentifizierung** für alle Endpunkte erforderlich
230+
231+
* **API-Keys** werden automatisch generiert (16-Byte Hex)
232+
* **CORS** nur für localhost aktiviert
233+
* **Authentifizierung** für alle Endpunkte erforderlich
208234

209235
### 🛡️ Systemd-Hardening
210-
- **NoNewPrivileges** verhindert Rechte-Eskalation
211-
- **ProtectSystem=strict** Schreibschutz für Dateisystem
212-
- **PrivateTmp** isolierte temporäre Verzeichnisse
213-
- **Memory-Limits** verhindern Ressourcen-Erschöpfung
236+
237+
* `NoNewPrivileges` verhindert Rechte-Eskalation
238+
* `ProtectSystem=strict` schützt das Dateisystem
239+
* `PrivateTmp` isoliert temporäre Verzeichnisse
240+
* Speicherlimits verhindern Ressourcenüberlastung
214241

215242
### 🔒 Netzwerk-Sicherheit
216-
- **Unbound** nur auf localhost (nicht exponiert)
217-
- **DNS über TLS** zu Upstream-Resolvern
218-
- **DNSSEC**-Validierung aktiviert
243+
244+
* **Unbound** lauscht nur auf `localhost`
245+
* DNS über TLS zu Upstream-Resolvern
246+
* DNSSEC-Validierung ist aktiviert
219247

220248
---
221249

@@ -231,19 +259,19 @@ docker restart netalertx
231259

232260
## 📜 Lizenz
233261

234-
Dieses Projekt ist unter der **MIT-Lizenz** lizenziert - siehe [LICENSE](LICENSE)-Datei.
262+
Dieses Projekt ist unter der **MIT-Lizenz** lizenziert siehe [LICENSE](LICENSE)-Datei.
235263

236264
---
237265

238266
## 📈 Changelog
239267

240-
Siehe [CHANGELOG.md](CHANGELOG.md) für Versionshistorie und Updates.
268+
Siehe [CHANGELOG.md](CHANGELOG.md) für Versionsverlauf und Updates.
241269

242270
---
243271

244272
<div align="center">
245273

246-
**Mit ❤️ für die Pi-hole-Community erstellt**
274+
**Mit ❤️ für die Pi-hole-Community entwickelt**
247275

248276
[🐛 Bug melden](https://github.com/TimInTech/Pi-hole-Unbound-PiAlert-Setup/issues)
249277
[✨ Feature anfordern](https://github.com/TimInTech/Pi-hole-Unbound-PiAlert-Setup/issues)

install.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ set -euo pipefail
99
readonly UNBOUND_PORT=5335
1010
readonly NETALERTX_PORT=20211
1111
readonly PYTHON_SUITE_PORT=8090
12-
readonly NETALERTX_IMAGE="techxartisan/netalertx:latest"
13-
readonly SUITE_API_KEY=${SUITE_API_KEY:-$(openssl rand -hex 16)}
14-
readonly INSTALL_USER=${SUDO_USER:-$(whoami)}
15-
readonly INSTALL_HOME=$(getent passwd "$INSTALL_USER" | cut -d: -f6)
1612
readonly PROJECT_DIR="$(pwd)"
1713

1814
# 🎨 Colors
@@ -38,7 +34,6 @@ check_system() {
3834
success "System checks passed"
3935
}
4036

41-
# 🔌 Port conflicts
4237
check_ports() {
4338
step "Checking ports"
4439
local ports=($UNBOUND_PORT $NETALERTX_PORT $PYTHON_SUITE_PORT 53)
@@ -53,7 +48,6 @@ check_ports() {
5348
install_packages() {
5449
step "Installing system packages"
5550
apt-get update -qq
56-
apt-get install -y unbound unbound-anchor ca-certificates curl dnsutils \
5751
python3 python3-venv python3-pip git docker.io openssl systemd sqlite3
5852
success "System packages installed"
5953
}
@@ -87,6 +81,7 @@ forward-zone:
8781
forward-tls-upstream: yes
8882
forward-addr: 9.9.9.9@853#dns.quad9.net
8983
forward-addr: 149.112.112.112@853#dns.quad9.net
84+
# NOTE: This is DoT forwarding to Quad9 (not full recursion to the root); intended.
9085
EOF
9186

9287
unbound-anchor -a /var/lib/unbound/root.key || true
@@ -174,7 +169,6 @@ ENV
174169
run_health_checks() {
175170
step "Running health checks"
176171
dig +short @127.0.0.1 -p $UNBOUND_PORT example.com | grep -q "." && success "Unbound OK" || error "Unbound FAIL"
177-
pihole status | grep -q "blocking is enabled" && success "Pi-hole OK" || warn "Pi-hole status unclear"
178172
docker ps | grep -q netalertx && success "NetAlertX OK" || warn "NetAlertX missing"
179173
systemctl is-active --quiet pihole-suite && success "Python suite OK" || warn "Python suite not active"
180174
}
@@ -195,6 +189,7 @@ main() {
195189
check_ports
196190
install_packages
197191
configure_unbound
192+
handle_systemd_resolved
198193
install_pihole
199194
install_netalertx
200195
setup_python_suite

pyalloc/allocator.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import logging
55
import threading
66
from typing import Set
7-
"""Simple IP pool allocator."""
8-
import ipaddress
9-
import logging
10-
import threading
117

128
logger = logging.getLogger(__name__)
139

@@ -31,16 +27,10 @@ def allocate(self) -> str:
3127
3228
Returns:
3329
String IP address
34-
30+
3531
Raises:
3632
RuntimeError: If no IPs available
3733
"""
38-
def __init__(self, network: str):
39-
self.network = ipaddress.ip_network(network)
40-
self.lock = threading.Lock()
41-
self.allocated = set()
42-
43-
def allocate(self) -> str:
4434
with self.lock:
4535
for ip in self.network.hosts():
4636
ip_str = str(ip)
@@ -95,12 +85,3 @@ def get_stats(self) -> dict:
9585
"available": total_hosts - allocated_count,
9686
"utilization_percent": (allocated_count / total_hosts) * 100 if total_hosts > 0 else 0
9787
}
98-
logger.info("Allocated IP %s", ip_str)
99-
return ip_str
100-
raise RuntimeError("No free IP addresses")
101-
102-
def release(self, ip: str) -> None:
103-
with self.lock:
104-
if ip in self.allocated:
105-
self.allocated.remove(ip)
106-
logger.info("Released IP %s", ip)

pyalloc/main.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
import logging
44
import sqlite3
55
import threading
6-
from typing import Optional
7-
"""Placeholder IP allocator worker."""
8-
import logging
9-
import threading
106
import time
7+
from typing import Optional
118

129
from .allocator import IPPool
1310

@@ -101,25 +98,3 @@ def stop() -> None:
10198
def get_pool() -> Optional[IPPool]:
10299
"""Get the current IP pool instance (for demo/testing)."""
103100
return _pool
104-
_pool = None
105-
_stop_event = threading.Event()
106-
107-
108-
def start(conn, network: str = "192.168.0.0/24"):
109-
del conn # not used yet
110-
global _pool
111-
_pool = IPPool(network)
112-
logger.info("Starting IP allocator for %s", network)
113-
_stop_event.clear()
114-
thread = threading.Thread(target=_run, daemon=True)
115-
thread.start()
116-
return thread
117-
118-
119-
def _run() -> None:
120-
while not _stop_event.is_set():
121-
time.sleep(60)
122-
123-
124-
def stop() -> None:
125-
_stop_event.set()

shared/shared_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Shared configuration for the Pi-hole suite."""
2-
3-
"""
42
import logging
53
import os
64
from pathlib import Path

0 commit comments

Comments
 (0)