Devices is_active + Table

This commit is contained in:
2025-09-29 18:17:58 +00:00
parent b465bd9c54
commit a10343d37e
6 changed files with 62 additions and 31 deletions

View File

@@ -86,7 +86,8 @@ def logout():
def index(): def index():
conn = sqlite3.connect("sqlite.db") conn = sqlite3.connect("sqlite.db")
c = conn.cursor() c = conn.cursor()
c.execute("SELECT mac, name FROM devices") # is_active mit abfragen
c.execute("SELECT mac, name, is_active FROM devices")
devices = c.fetchall() devices = c.fetchall()
conn.close() conn.close()

Binary file not shown.

View File

@@ -117,13 +117,14 @@ pre {
} }
.custom-table .col-ip { .custom-table .col-ip {
width: 120px; /* IP-Adresse schmaler */ width: 140px; /* IP-Adresse schmaler */
} }
.custom-table .col-mac { .custom-table .col-mac {
width: 120px; /* MAC-Adresse schmaler */ width: 140px; /* MAC-Adresse schmaler */
} }
/* Checkbox sichtbar auch bei disabled */ /* Checkbox sichtbar auch bei disabled */
.checkbox-visible:disabled { .checkbox-visible:disabled {
opacity: 1; /* nicht ausgegraut */ opacity: 1; /* nicht ausgegraut */
@@ -145,7 +146,7 @@ label.text-white {
} }
.custom-actions { .custom-actions {
gap: 0.5rem; /* horizontaler Abstand zwischen Buttons */ margin: auto 0;
margin: auto 0;
background: #fff; background: #fff;
} }

View File

@@ -8,8 +8,16 @@
<div class="card text-center p-2"> <div class="card text-center p-2">
<div class="card-header">{{ d[1] }}</div> <div class="card-header">{{ d[1] }}</div>
<div class="card-body"> <div class="card-body">
<span class="fw-bold" style="color: {% if status[d[0]]=='online' %}green{% else %}red{% endif %};"> <span class="fw-bold" style="color:
{% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}unbekannt{% endif %} {% if d[2] == 0 %}gray
{% elif status[d[0]]=='online' %}green
{% else %}red
{% endif %};">
{% if d[2] == 0 %}
Deaktiviert
{% else %}
{% if status[d[0]] %}{{ status[d[0]]|capitalize }}{% else %}Unbekannt{% endif %}
{% endif %}
</span> </span>
</div> </div>
</div> </div>

View File

@@ -7,20 +7,21 @@
<h4>Neuen Switch hinzufügen</h4> <h4>Neuen Switch hinzufügen</h4>
<form method="post" class="row g-2 mb-4"> <form method="post" class="row g-2 mb-4">
<input type="hidden" name="add_switch" value="1"> <input type="hidden" name="add_switch" value="1">
<div class="col"><input type="text" name="hostname" placeholder="Hostname" class="form-control" required></div> <div class="col col-small"><input type="text" name="hostname" placeholder="Hostname" class="form-control" required></div>
<div class="col"><input type="text" name="ip" placeholder="IP-Adresse" class="form-control" required></div> <div class="col col-ip"><input type="text" name="ip" placeholder="IP-Adresse" class="form-control" required></div>
<div class="col"><input type="text" name="username" placeholder="Username" class="form-control" required></div> <div class="col col-small"><input type="text" name="username" placeholder="Username" class="form-control" required></div>
<div class="col"><input type="password" name="password" placeholder="Password" class="form-control" required></div> <div class="col"><input type="password" name="password" placeholder="Password" class="form-control" required></div>
<div class="col"><button class="btn btn-success w-100">Hinzufügen</button></div> <div class="col"><button class="btn btn-success w-100">Hinzufügen</button></div>
</form> </form>
{% endif %} {% endif %}
<table class="table table-bordered"> <table class="table table-bordered custom-table">
<thead> <thead>
<tr> <tr>
<th>Hostname</th> <th class="col-small">Hostname</th>
<th>IP-Adresse</th> <th class="col-ip">IP-Adresse</th>
<th>Username</th> <th class="col-small">Username</th>
<th>Password</th>
{% if current_user.is_admin %}<th>Aktionen</th>{% endif %} {% if current_user.is_admin %}<th>Aktionen</th>{% endif %}
</tr> </tr>
</thead> </thead>
@@ -28,26 +29,46 @@
{% for s in switches %} {% for s in switches %}
<tr> <tr>
{% if current_user.is_admin %} {% if current_user.is_admin %}
<form method="post"> <td class="col-small"><input name="hostname" value="{{ s['hostname'] }}" class="form-control" required disabled></td>
<input type="hidden" name="edit_switch" value="1"> <td class="col-ip"><input name="ip" value="{{ s['ip'] }}" class="form-control" required disabled></td>
<input type="hidden" name="old_hostname" value="{{ s['hostname'] }}"> <td class="col-small"><input name="username" value="{{ s['username'] }}" class="form-control" required disabled></td>
<td><input name="hostname" value="{{ s['hostname'] }}" class="form-control" required></td> <td><input name="password" value="{{ s['password'] }}" type="password" class="form-control" disabled></td>
<td><input name="ip" value="{{ s['ip'] }}" class="form-control" required></td> <td class="custom-actions d-flex gap-1 align-items-center">
<td><input name="username" value="{{ s['username'] }}" class="form-control" required></td> <!-- Bearbeiten Button -->
<td class="d-flex gap-1"> <button type="button" class="btn btn-warning btn-sm" onclick="enableSwitchEdit(this)">Bearbeiten</button>
<button class="btn btn-primary btn-sm">Speichern</button>
<!-- Speichern Button -->
<form method="post" style="display:inline;">
<input type="hidden" name="edit_switch" value="1">
<input type="hidden" name="old_hostname" value="{{ s['hostname'] }}">
<button class="btn btn-primary btn-sm d-none" type="submit">Speichern</button>
</form>
<!-- Löschen Button -->
<form method="post" style="display:inline;">
<button name="delete_switch" value="{{ s['hostname'] }}" class="btn btn-danger btn-sm" <button name="delete_switch" value="{{ s['hostname'] }}" class="btn btn-danger btn-sm"
onclick="return confirm('Willst du den Switch wirklich löschen?');">Löschen</button> onclick="return confirm('Willst du den Switch wirklich löschen?');">Löschen</button>
</td> </form>
</form> </td>
{% else %} {% else %}
<td>{{ s['hostname'] }}</td> <td>{{ s['hostname'] }}</td>
<td>{{ s['ip'] }}</td> <td>{{ s['ip'] }}</td>
<td>{{ s['username'] }}</td> <td>{{ s['username'] }}</td>
<td>******</td>
{% endif %} {% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<script>
function enableSwitchEdit(btn) {
const row = btn.closest('tr');
// Inputs aktivieren
row.querySelectorAll('input').forEach(el => el.disabled = false);
row.querySelector('.btn-primary').classList.remove('d-none'); // Speichern sichtbar
btn.classList.add('d-none'); // Bearbeiten ausblenden
}
</script>
{% endblock %} {% endblock %}

View File

@@ -8,21 +8,21 @@
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#userModal" onclick="openUserModal()">Neuen Benutzer</button> <button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#userModal" onclick="openUserModal()">Neuen Benutzer</button>
{% endif %} {% endif %}
<table class="table table-bordered"> <table class="table table-bordered custom-table">
<thead> <thead>
<tr> <tr>
<th>Username</th> <th class="col-small">Username</th>
<th>Rolle</th> <th class="col-small">Rolle</th>
{% if current_user.is_admin %}<th>Aktionen</th>{% endif %} {% if current_user.is_admin %}<th>Aktionen</th>{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for u in users %} {% for u in users %}
<tr> <tr>
<td>{{ u['username'] }}</td> <td class="col-small">{{ u['username'] }}</td>
<td>{% if u['is_admin'] %}Admin{% else %}User{% endif %}</td> <td class="col-small">{% if u['is_admin'] %}Admin{% else %}User{% endif %}</td>
{% if current_user.is_admin %} {% if current_user.is_admin %}
<td> <td class="custom-actions d-flex gap-1 align-items-center">
<!-- Rolle ändern --> <!-- Rolle ändern -->
<button class="btn btn-primary btn-sm" data-bs-toggle="modal" <button class="btn btn-primary btn-sm" data-bs-toggle="modal"
data-bs-target="#roleModal" data-bs-target="#roleModal"
@@ -49,6 +49,7 @@
</tbody> </tbody>
</table> </table>
<!-- Modals bleiben unverändert -->
<!-- Modal für neuen Benutzer --> <!-- Modal für neuen Benutzer -->
<div class="modal fade" id="userModal" tabindex="-1" aria-hidden="true"> <div class="modal fade" id="userModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
@@ -159,7 +160,6 @@ function openRoleModal(user_id, username, is_admin) {
function openPasswordModal(user_id, username) { function openPasswordModal(user_id, username) {
document.getElementById('password_user_id').value = user_id; document.getElementById('password_user_id').value = user_id;
document.getElementById('password_username').value = username; document.getElementById('password_username').value = username;
// Nur das Passwort-Feld zurücksetzen
document.querySelector("#passwordForm input[name='new_password']").value = ""; document.querySelector("#passwordForm input[name='new_password']").value = "";
} }
</script> </script>