dev #1

Merged
alientim merged 145 commits from dev into main 2025-10-12 13:44:14 +02:00
Showing only changes of commit 0f6b87ba1f - Show all commits

View File

@@ -1,195 +1,55 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block content %} {% block content %}
<h2>Devices</h2> <h2>Switch-Verwaltung</h2>
{% if current_user.is_admin %} <!-- Hinzufügen -->
<!-- Neues Gerät hinzufügen --> <form method="post" class="mb-3">
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#deviceModal" onclick="openDeviceModal()">Neues Gerät</button> <input type="hidden" name="add_switch" value="1">
{% endif %} <div class="row g-2">
<div class="col"><input class="form-control" name="hostname" placeholder="Hostname" required></div>
<div class="col"><input class="form-control" name="ip" placeholder="IP-Adresse" required></div>
<div class="col"><input class="form-control" name="username" placeholder="Benutzername" required></div>
<div class="col"><input class="form-control" name="password" type="password" placeholder="Passwort" required></div>
<div class="col-auto">
<button class="btn btn-primary">Hinzufügen</button>
</div>
</div>
</form>
<table class="table table-bordered"> <!-- Switch-Liste -->
<table class="table table-striped table-hover align-middle">
<thead> <thead>
<tr> <tr>
<th>Hostname</th> <th>Hostname</th>
<th>IP-Adresse</th> <th>IP-Adresse</th>
<th>MAC-Adresse</th> <th>Benutzername</th>
<th>Port</th> <th>Aktionen</th>
<th>Switch</th>
<th>Status</th>
{% if current_user.is_admin %}<th>Aktionen</th>{% endif %}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for d in devices %} {% for s in switches %}
<tr> <tr>
<td>{{ d['name'] }}</td> <form method="post">
<td>{{ d['rpi_ip'] }}</td> <input type="hidden" name="edit_switch" value="1">
<td>{{ d['mac'] }}</td> <input type="hidden" name="old_hostname" value="{{ s['hostname'] }}">
<td>{{ d['port'] }}</td> <td><input class="form-control form-control-sm" name="hostname" value="{{ s['hostname'] }}"></td>
<td>{{ d['switch_hostname'] or '-' }}</td> <td><input class="form-control form-control-sm" name="ip" value="{{ s['ip'] }}"></td>
<td><input class="form-control form-control-sm" name="username" value="{{ s['username'] }}"></td>
<td> <td>
<form method="post" action="{{ url_for('toggle_device', mac=d['mac']) }}" style="display:inline;"> <div class="d-flex gap-1">
<button class="btn btn-sm {% if d['is_active'] %}btn-success{% else %}btn-secondary{% endif %}" type="submit"> <input type="password" class="form-control form-control-sm" name="password" placeholder="Neues Passwort">
{% if d['is_active'] %}Deaktivieren{% else %}Aktivieren{% endif %} <button class="btn btn-sm btn-success">Speichern</button>
</button> </div>
</form> </form>
</td>
{% if current_user.is_admin %}
<td>
<!-- Bearbeiten Modal -->
<button class="btn btn-secondary btn-sm button login white" data-bs-toggle="modal" data-bs-target="#editDeviceModal"
onclick="openEditDeviceModal('{{ d['mac'] }}','{{ d['name'] }}','{{ d['rpi_ip'] }}','{{ d['port'] }}')">
Bearbeiten
</button>
<!-- Switch ändern Modal -->
<button class="btn btn-secondary btn-sm button login white" data-bs-toggle="modal" data-bs-target="#switchModal"
onclick="openSwitchModal('{{ d['mac'] }}','{{ d['switch_hostname'] }}')">
Switch ändern
</button>
<!-- Löschen -->
<form method="post" style="display:inline;"> <form method="post" style="display:inline;">
<input type="hidden" name="delete_device" value="{{ d['mac'] }}"> <input type="hidden" name="delete_switch" value="{{ s['hostname'] }}">
<button class="btn btn-danger btn-sm" onclick="return confirm('Willst du das Gerät wirklich löschen?');"> <button class="btn btn-sm btn-danger ms-1">Löschen</button>
Löschen
</button>
</form> </form>
</td> </td>
{% endif %}
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
<!-- Modal: Neues Gerät -->
<div class="modal fade" id="deviceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post">
<div class="modal-header">
<h5 class="modal-title black">Neues Gerät hinzufügen</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" name="add_device" value="1">
<div class="mb-3">
<label>Hostname</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="mb-3">
<label>IP-Adresse</label>
<input type="text" name="rpi_ip" class="form-control" required>
</div>
<div class="mb-3">
<label>MAC-Adresse</label>
<input type="text" name="mac" class="form-control" required>
</div>
<div class="mb-3">
<label>Port</label>
<input type="text" name="port" class="form-control" required>
</div>
<div class="mb-3">
<label>Switch</label>
<select name="switch_hostname" class="form-select" required>
{% for sw in switches %}
<option value="{{ sw['hostname'] }}">{{ sw['hostname'] }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success button login" type="submit">Hinzufügen</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal: Bearbeiten -->
<div class="modal fade" id="editDeviceModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post">
<input type="hidden" name="edit_device" value="1">
<input type="hidden" name="old_mac" id="edit_old_mac">
<div class="modal-header">
<h5 class="modal-title black">Gerät bearbeiten</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label>Hostname</label>
<input type="text" name="name" id="edit_name" class="form-control" required>
</div>
<div class="mb-3">
<label>IP-Adresse</label>
<input type="text" name="rpi_ip" id="edit_ip" class="form-control" required>
</div>
<div class="mb-3">
<label>MAC-Adresse</label>
<input type="text" name="mac" id="edit_mac" class="form-control" required>
</div>
<div class="mb-3">
<label>Port</label>
<input type="text" name="port" id="edit_port" class="form-control" required>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-primary button login" type="submit">Speichern</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
</div>
</form>
</div>
</div>
</div>
<!-- Modal: Switch ändern -->
<div class="modal fade" id="switchModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="post">
<input type="hidden" name="edit_device" value="1">
<input type="hidden" name="old_mac" id="switch_mac">
<div class="modal-header">
<h5 class="modal-title black">Switch ändern</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<select name="switch_hostname" id="switch_select" class="form-select" required>
{% for sw in switches %}
<option value="{{ sw['hostname'] }}">{{ sw['hostname'] }}</option>
{% endfor %}
</select>
</div>
<div class="modal-footer">
<button class="btn btn-primarybutton login" type="submit">Speichern</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
</div>
</form>
</div>
</div>
</div>
<script>
function openDeviceModal() {
document.querySelector("#deviceModal form").reset();
}
function openEditDeviceModal(mac, name, ip, port) {
document.getElementById("edit_old_mac").value = mac;
document.getElementById("edit_name").value = name;
document.getElementById("edit_ip").value = ip;
document.getElementById("edit_mac").value = mac;
document.getElementById("edit_port").value = port;
}
function openSwitchModal(mac, switch_hostname) {
document.getElementById("switch_mac").value = mac;
document.getElementById("switch_select").value = switch_hostname;
}
</script>
{% endblock %} {% endblock %}