dev #1

Merged
alientim merged 145 commits from dev into main 2025-10-12 13:44:14 +02:00
6 changed files with 62 additions and 31 deletions
Showing only changes of commit a10343d37e - Show all commits

View File

@@ -86,7 +86,8 @@ def logout():
def index():
conn = sqlite3.connect("sqlite.db")
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()
conn.close()

Binary file not shown.

View File

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

View File

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

View File

@@ -7,20 +7,21 @@
<h4>Neuen Switch hinzufügen</h4>
<form method="post" class="row g-2 mb-4">
<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"><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="hostname" placeholder="Hostname" 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 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"><button class="btn btn-success w-100">Hinzufügen</button></div>
</form>
{% endif %}
<table class="table table-bordered">
<table class="table table-bordered custom-table">
<thead>
<tr>
<th>Hostname</th>
<th>IP-Adresse</th>
<th>Username</th>
<th class="col-small">Hostname</th>
<th class="col-ip">IP-Adresse</th>
<th class="col-small">Username</th>
<th>Password</th>
{% if current_user.is_admin %}<th>Aktionen</th>{% endif %}
</tr>
</thead>
@@ -28,26 +29,46 @@
{% for s in switches %}
<tr>
{% if current_user.is_admin %}
<form method="post">
<td class="col-small"><input name="hostname" value="{{ s['hostname'] }}" class="form-control" required disabled></td>
<td class="col-ip"><input name="ip" value="{{ s['ip'] }}" class="form-control" required disabled></td>
<td class="col-small"><input name="username" value="{{ s['username'] }}" class="form-control" required disabled></td>
<td><input name="password" value="{{ s['password'] }}" type="password" class="form-control" disabled></td>
<td class="custom-actions d-flex gap-1 align-items-center">
<!-- Bearbeiten Button -->
<button type="button" class="btn btn-warning btn-sm" onclick="enableSwitchEdit(this)">Bearbeiten</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'] }}">
<td><input name="hostname" value="{{ s['hostname'] }}" class="form-control" required></td>
<td><input name="ip" value="{{ s['ip'] }}" class="form-control" required></td>
<td><input name="username" value="{{ s['username'] }}" class="form-control" required></td>
<td class="d-flex gap-1">
<button class="btn btn-primary btn-sm">Speichern</button>
<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"
onclick="return confirm('Willst du den Switch wirklich löschen?');">Löschen</button>
</td>
</form>
</td>
{% else %}
<td>{{ s['hostname'] }}</td>
<td>{{ s['ip'] }}</td>
<td>{{ s['username'] }}</td>
<td>******</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</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 %}

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