Files
Aruba-PoE/srv/poe_manager/templates/devices.html

196 lines
7.5 KiB
HTML

{% extends "base.html" %}
{% block content %}
<h2>Devices</h2>
{% if current_user.is_admin %}
<!-- Neues Gerät hinzufügen -->
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#deviceModal" onclick="openDeviceModal()">Neues Gerät</button>
{% endif %}
<table class="table table-bordered">
<thead>
<tr>
<th>Hostname</th>
<th>IP-Adresse</th>
<th>MAC-Adresse</th>
<th>Port</th>
<th>Switch</th>
<th>Status</th>
{% if current_user.is_admin %}<th>Aktionen</th>{% endif %}
</tr>
</thead>
<tbody>
{% for d in devices %}
<tr>
<td>{{ d['name'] }}</td>
<td>{{ d['rpi_ip'] }}</td>
<td>{{ d['mac'] }}</td>
<td>{{ d['port'] }}</td>
<td>{{ d['switch_hostname'] or '-' }}</td>
<td>
<form method="post" action="{{ url_for('toggle_device', mac=d['mac']) }}" style="display:inline;">
<button class="btn btn-sm {% if d['is_active'] %}btn-success{% else %}btn-secondary{% endif %}" type="submit">
{% if d['is_active'] %}Deaktivieren{% else %}Aktivieren{% endif %}
</button>
</form>
</td>
{% if current_user.is_admin %}
<td>
<!-- Bearbeiten Modal -->
<button class="btn btn-primary btn-sm" 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-info btn-sm button login" 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;">
<input type="hidden" name="delete_device" value="{{ d['mac'] }}">
<button class="btn btn-danger btn-sm" onclick="return confirm('Willst du das Gerät wirklich löschen?');">
Löschen
</button>
</form>
</td>
{% endif %}
</tr>
{% endfor %}
</tbody>
</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 %}