NEW MODAL informacje o serwerze
This commit is contained in:
parent
985d3465c8
commit
942ce73975
30
app.py
30
app.py
@ -1621,6 +1621,36 @@ def scheduled_deployments():
|
||||
setting.last_deploy_time = now
|
||||
db.session.commit()
|
||||
|
||||
@app.route('/server-info/<int:id>', methods=['GET'])
|
||||
def server_info(id):
|
||||
if 'user_id' not in session:
|
||||
return {"error": "Unauthorized"}, 401
|
||||
host = db.session.get(Host, id)
|
||||
if not host or host.user_id != session['user_id']:
|
||||
return {"error": "Host not found or unauthorized"}, 404
|
||||
|
||||
if host.use_daemon and host.type == 'linux':
|
||||
import requests
|
||||
headers = {"Authorization": host.daemon_token}
|
||||
sysinfo_url = host.daemon_url.rstrip('/') + '/system-info'
|
||||
try:
|
||||
resp = requests.get(sysinfo_url, headers=headers, verify=False, timeout=5)
|
||||
if resp.status_code == 200:
|
||||
data = resp.json()
|
||||
return {
|
||||
"hostname": format_host(host),
|
||||
"ip": host.raw_ip,
|
||||
"cpu": data.get('cpu_percent'),
|
||||
"mem": data.get('memory_percent'),
|
||||
"disk": data.get('disk_percent'),
|
||||
"uptime_seconds": data.get('uptime_seconds')
|
||||
}
|
||||
else:
|
||||
return {"error": f"Błąd demona: {resp.status_code}"}, 500
|
||||
except Exception as e:
|
||||
return {"error": str(e)}, 500
|
||||
else:
|
||||
return {"error": "This server does not use daemon."}, 400
|
||||
|
||||
@app.errorhandler(404)
|
||||
def page_not_found(error):
|
||||
|
@ -74,4 +74,49 @@
|
||||
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 %}
|
||||
|
@ -109,17 +109,26 @@
|
||||
<input type="checkbox" name="enabled" value="1"
|
||||
onchange="this.form.submit()" {% if h.disable_regex_deploy %}checked{% endif %}>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
<a href="{{ url_for('edit_server', id=h.id) }}" class="btn btn-primary btn-sm">Edytuj</a>
|
||||
<a href="{{ url_for('test_server_connection', id=h.id) }}" class="btn btn-info btn-sm">Testuj</a>
|
||||
<a href="{{ url_for('server_backup', host_id=h.id) }}" class="btn btn-success btn-sm">Backup</a>
|
||||
<form method="GET" action="{{ url_for('delete_server', id=h.id) }}" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger btn-sm">Usuń</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
<a href="{{ url_for('edit_server', id=h.id) }}" class="btn btn-primary btn-sm">Edytuj</a>
|
||||
|
||||
{% if h.use_daemon and h.type == 'linux' %}
|
||||
<!-- Serwery z demonem – nowy sposób -->
|
||||
<button class="btn btn-info btn-sm test-daemon-btn" data-host-id="{{ h.id }}">
|
||||
Testuj
|
||||
</button>
|
||||
{% else %}
|
||||
<!-- Dotychczasowy sposób dla SSH/Mikrotik -->
|
||||
<a href="{{ url_for('test_server_connection', id=h.id) }}" class="btn btn-info btn-sm">Testuj</a>
|
||||
{% endif %}
|
||||
|
||||
<a href="{{ url_for('server_backup', host_id=h.id) }}" class="btn btn-success btn-sm">Backup</a>
|
||||
<form method="GET" action="{{ url_for('delete_server', id=h.id) }}" style="display:inline;">
|
||||
<button type="submit" class="btn btn-danger btn-sm">Usuń</button>
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@ -128,6 +137,42 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modal z informacjami -->
|
||||
<div class="modal fade" id="serverInfoModal" tabindex="-1" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Informacje o serwerze</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p><strong>Host:</strong> <span id="modal-hostname"></span> (<span id="modal-ip"></span>)</p>
|
||||
|
||||
<label><strong>CPU:</strong></label>
|
||||
<div class="progress mb-3">
|
||||
<div id="modal-cpu" class="progress-bar" role="progressbar"></div>
|
||||
</div>
|
||||
|
||||
<label><strong>Pamięć:</strong></label>
|
||||
<div class="progress mb-3">
|
||||
<div id="modal-mem" class="progress-bar bg-warning" role="progressbar"></div>
|
||||
</div>
|
||||
|
||||
<label><strong>Dysk:</strong></label>
|
||||
<div class="progress mb-3">
|
||||
<div id="modal-disk" class="progress-bar bg-success" role="progressbar"></div>
|
||||
</div>
|
||||
|
||||
<p><strong>Czas działania:</strong> <span id="modal-uptime"></span></p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Zamknij</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="mt-3 text-center">
|
||||
<a href="{{ url_for('add_server') }}" class="btn btn-secondary">Dodaj nowy serwer</a>
|
||||
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj z CSV</a>
|
||||
|
Loading…
x
Reference in New Issue
Block a user