Compare commits
36 Commits
5b33e2d656
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| dc6dfc38ad | |||
| 7561791a0b | |||
| c7266f73f3 | |||
| 1a742c56c9 | |||
| 9cdcc59038 | |||
| 6523fdf675 | |||
| d846856cb4 | |||
| 94142f9ead | |||
| 8c93eab3a5 | |||
| ab6ecd773d | |||
| 970f7dbeb5 | |||
| 19f6390e22 | |||
| 268800d31a | |||
| 7b0c847e67 | |||
| 007d9f919f | |||
| 7c045a65b2 | |||
| 98023092a2 | |||
| 28fa9087a4 | |||
| 804753dde8 | |||
| eaf2e2f78e | |||
| 50d5f58af4 | |||
| 12d2511695 | |||
| 3bd2aca4f5 | |||
| b6e9ff3f98 | |||
| 398629eaaa | |||
| 3eb78b46a7 | |||
| 681888a36a | |||
| e8df4f937b | |||
| 29823bb4ef | |||
| a2920a98bd | |||
| 7f0871fa64 | |||
| 5ae38a9e20 | |||
| de23b132ed | |||
| 746972e321 | |||
| dfba8789a7 | |||
| 194e3cfbf9 |
@@ -4,6 +4,7 @@ from flask_login import LoginManager, login_user, login_required, logout_user, U
|
||||
from flask_bcrypt import Bcrypt
|
||||
from cryptography.fernet import Fernet
|
||||
from datetime import datetime
|
||||
from collections import defaultdict
|
||||
import sqlite3, glob, os, re
|
||||
|
||||
app = Flask(__name__)
|
||||
@@ -104,9 +105,8 @@ def get_last_seen(dev_name: str):
|
||||
continue
|
||||
|
||||
if latest_time:
|
||||
date_str = latest_time.strftime("Zuletzt Online am %d.%m.%Y")
|
||||
time_str = latest_time.strftime("um %H:%M Uhr")
|
||||
return f"{date_str}\n{time_str}"
|
||||
datetime_str = latest_time.strftime("Zuletzt Online am %d.%m.%Y um %H:%M Uhr")
|
||||
return f"{datetime_str}"
|
||||
|
||||
return None
|
||||
|
||||
@@ -119,6 +119,13 @@ def index():
|
||||
c.execute("SELECT mac, name, is_active FROM devices ORDER BY name ASC")
|
||||
devices = c.fetchall()
|
||||
|
||||
devices = sorted(devices, key=lambda d: d[1][0].upper())
|
||||
|
||||
grouped_devices = defaultdict(list)
|
||||
for d in devices:
|
||||
first_letter = d[1][:2].upper()
|
||||
grouped_devices[first_letter].append(d)
|
||||
|
||||
# Intervall aus DB laden
|
||||
c.execute("SELECT value FROM settings WHERE key='interval'")
|
||||
row = c.fetchone()
|
||||
@@ -152,7 +159,7 @@ def index():
|
||||
else:
|
||||
status_dict[dev[0]] = "unbekannt"
|
||||
|
||||
return render_template("index.html", devices=devices, status=status_dict, last_seen=last_seen_dict, interval=interval)
|
||||
return render_template("index.html", grouped_devices=grouped_devices, devices=devices, status=status_dict, last_seen=last_seen_dict, interval=interval)
|
||||
|
||||
@app.route("/settings", methods=["GET", "POST"])
|
||||
@login_required
|
||||
|
||||
Binary file not shown.
@@ -87,25 +87,33 @@ pre {
|
||||
|
||||
#log-container {
|
||||
position: relative;
|
||||
height: calc(100vh - 150px); /* Füllt die Seite minus Header */
|
||||
height: calc(100vh - 252px); /* Füllt die Seite minus Header */
|
||||
padding: 1rem; /* optional, Abstand innen */
|
||||
box-sizing: border-box; /* damit Padding nicht die Höhe sprengt */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#log-box {
|
||||
height: 97%;
|
||||
flex: 1 1 auto; /* füllt den Container, berücksichtigt Header/Padding */
|
||||
overflow: auto;
|
||||
white-space: pre-wrap;
|
||||
font-family: monospace;
|
||||
border: 1px solid #dee2e6; /* Bootstrap-like border */
|
||||
padding: 1rem;
|
||||
border: 1px solid #dee2e6;
|
||||
background-color: #f8f9fa;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
#refresh-timer {
|
||||
position: absolute;
|
||||
bottom: 10px;
|
||||
right: 10px;
|
||||
bottom: 18px;
|
||||
right: 30px;
|
||||
font-size: 0.9em;
|
||||
color: gray;
|
||||
background-color: rgba(255,255,255,0.7); /* optional, besser lesbar */
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
pointer-events: none; /* damit Scrollbar nicht blockiert wird */
|
||||
}
|
||||
|
||||
/* Tabelle anpassen */
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#deviceModal" onclick="openDeviceModal()">Neues Gerät hinzufügen</button>
|
||||
{% endif %}
|
||||
|
||||
<table class="table table-bordered">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hostname</th>
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
Nächste Prüfung in -- Sekunden
|
||||
</span>
|
||||
</h2>
|
||||
<div class="row row-cols-1 row-cols-md-6 g-3">
|
||||
{% for d in devices %}
|
||||
<div class="col">
|
||||
<div class="row g-3">
|
||||
{% for letter, group in grouped_devices.items() %}
|
||||
<div class="row g-3">
|
||||
{% for d in group %}
|
||||
<div class="col-6 col-md-4 col-lg-3 col-xl-2">
|
||||
<div class="card text-center p-2"
|
||||
{% if last_seen[d[0]] %} title="{{ last_seen[d[0]][0] }} {{ last_seen[d[0]][1] }}" {% elif status[d[0]] == 'offline' %} title="Noch nie online" {% endif %}>
|
||||
{% if last_seen.get(d[0]) %}
|
||||
title="{{ last_seen[d[0]] }}"
|
||||
{% elif status[d[0]] == 'offline' %}
|
||||
title="Noch nie online"
|
||||
{% endif %}>
|
||||
<div class="card-header">{{ d[1] }}</div>
|
||||
<div class="card-body">
|
||||
<span class="fw-bold" style="color:
|
||||
@@ -29,6 +35,8 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<!-- Button zum Hinzufügen -->
|
||||
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#addSwitchModal">Neuen Switch hinzufügen</button>
|
||||
|
||||
<table class="table table-bordered">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Hostname</th>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#userModal" onclick="openUserModal()">Neuen Benutzer</button>
|
||||
{% endif %}
|
||||
|
||||
<table class="table table-bordered">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-ip">Username</th>
|
||||
|
||||
@@ -87,15 +87,26 @@ EOF
|
||||
|
||||
echo "" > "$LOGFILE"
|
||||
|
||||
MAX_PARALLEL=10 # maximal gleichzeitig laufende Geräte
|
||||
|
||||
while true; do
|
||||
echo "--------------------------------------------------------------------" >> "$LOGFILE"
|
||||
python3 /srv/poe_manager/generate_ips.py | while IFS=: read -r rpi_ip dev_name switch_ip switch_hostname switch_port switch_user switch_pass; do
|
||||
if ping -c 1 -W 2 "$rpi_ip" &> /dev/null; then
|
||||
# Funktion für ein Gerät
|
||||
check_device() {
|
||||
local rpi_ip="$1"
|
||||
local dev_name="$2"
|
||||
local switch_ip="$3"
|
||||
local switch_hostname="$4"
|
||||
local switch_port="$5"
|
||||
local switch_user="$6"
|
||||
local switch_pass="$7"
|
||||
|
||||
if ping -c 4 -W 1 "$rpi_ip" &> /dev/null; then
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist erreichbar!" >> "$LOGFILE"
|
||||
else
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name ist nicht erreichbar!" >> "$LOGFILE"
|
||||
|
||||
# Nur PoE neu starten, wenn Port vorhanden ist
|
||||
if [ -n "$switch_port" ] && [ "$switch_port" != "None" ]; then
|
||||
disable_poe "$switch_ip" "$switch_port" "$switch_user" "$switch_pass"
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname deaktiviert." >> "$LOGFILE"
|
||||
@@ -104,6 +115,17 @@ while true; do
|
||||
echo "$(date '+%Y-%m-%d %H:%M:%S') $dev_name PoE auf Port $switch_port am Switch $switch_hostname aktiviert." >> "$LOGFILE"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Job in Hintergrund starten
|
||||
check_device "$rpi_ip" "$dev_name" "$switch_ip" "$switch_hostname" "$switch_port" "$switch_user" "$switch_pass" &
|
||||
|
||||
# Limit auf MAX_PARALLEL Jobs
|
||||
while [ "$(jobs -rp | wc -l)" -ge "$MAX_PARALLEL" ]; do
|
||||
sleep 0.2
|
||||
done
|
||||
done
|
||||
|
||||
wait # alle Hintergrundjobs beenden, bevor sleep
|
||||
sleep "$SLEEP"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user