hosts_app/templates/clear_servers.html
2025-03-09 14:17:17 +01:00

123 lines
4.1 KiB
HTML

{% extends "base.html" %}
{% block title %}Czyszczenie /etc/hosts - /etc/hosts Manager{% endblock %}
{% block extra_css %}
{{ super() }}
<style>
.section {
margin-bottom: 2rem;
}
.tooltip-inner {
max-width: 300px;
text-align: left;
}
</style>
{% endblock %}
{% block content %}
<div class="section">
<div class="card">
<div class="card-header">
<h2>Grupowe czyszczenie /etc/hosts</h2>
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('clear_all_server') }}">
<div class="mb-3">
<label class="form-label">Wybierz typy hostów do czyszczenia:</label>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="linux" id="linux_group">
<label class="form-check-label" for="linux_group">Wyczyść Linux</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" name="mikrotik" id="mikrotik_group">
<label class="form-check-label" for="mikrotik_group">Wyczyść Mikrotik</label>
</div>
</div>
<button type="submit" class="btn btn-danger">Wyczyść dla wszystkich hostów</button>
</form>
</div>
</div>
</div>
<div class="section">
<div class="card">
<div class="card-header">
<h2>Czyszczenie pojedynczego serwera</h2>
</div>
<div class="card-body">
<form id="clear-single-form" method="POST">
<div class="mb-3">
<label for="host_id" class="form-label">Wybierz serwer:</label>
<select class="form-select" id="host_id" name="host_id">
{% for host in hosts %}
<option value="{{ host.id }}">{{ format_host(host) }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-warning">Czyszczenie pojedynczego serwera</button>
</form>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
{{ super() }}
<script>
// Ustaw dynamicznie action formularza dla czyszczenia pojedynczego serwera
document.getElementById('clear-single-form').addEventListener('submit', function(e) {
e.preventDefault();
var hostId = document.getElementById('host_id').value;
if(!hostId) {
alert("Proszę wybrać serwer!");
return;
}
// Skonstruuj URL bez użycia url_for
this.action = "/clear-single-server/" + hostId;
this.submit();
});
</script>
<script>
function secondsToDhms(seconds) {
seconds = Number(seconds);
const d = Math.floor(seconds / (3600*24));
const h = Math.floor(seconds % (3600*24) / 3600);
const m = Math.floor(seconds % 3600 / 60);
const s = Math.floor(seconds % 60);
return `${d} dni, ${h} godz, ${m} min, ${s} sek`;
}
document.querySelectorAll('.test-daemon-btn').forEach(btn => {
btn.addEventListener('click', function() {
const hostId = this.dataset.hostId;
fetch(`/server-info/${hostId}`)
.then(res => res.json())
.then(data => {
if (data.error) {
alert(`Błąd: ${data.error}`);
return;
}
document.querySelector('#modal-hostname').textContent = data.hostname;
document.querySelector('#modal-ip').textContent = data.ip;
const cpu = document.querySelector('#modal-cpu');
cpu.style.width = `${data.cpu}%`;
cpu.textContent = `${data.cpu}%`;
const mem = document.querySelector('#modal-mem');
mem.style.width = `${data.mem}%`;
mem.textContent = `${data.mem}%`;
const disk = document.querySelector('#modal-disk');
disk.style.width = `${data.disk}%`;
disk.textContent = `${data.disk}%`;
document.querySelector('#modal-uptime').textContent = secondsToDhms(data.uptime_seconds);
new bootstrap.Modal(document.getElementById('serverInfoModal')).show();
})
.catch(() => alert('Błąd podczas pobierania danych.'));
});
});
</script>
{% endblock %}