git add templatesgit add templates OBSLUGA DEMONAgit add templates

This commit is contained in:
Mateusz Gruszczyński
2025-03-06 23:52:44 +01:00
parent cae5ed787d
commit aa0a0a0025
6 changed files with 710 additions and 134 deletions

View File

@ -1,14 +1,23 @@
{% extends "base.html" %}
{% block title %}Dodaj serwer - /etc/hosts Manager{% endblock %}
{% block extra_css %}
{{ super() }}
<style>
.tooltip-inner {
max-width: 300px;
text-align: left;
}
</style>
{{ super() }}
<style>
.tooltip-inner {
max-width: 300px;
text-align: left;
}
/* Kontenery domyślnie ukryte; pokażemy je przez JavaScript. */
#hostPortFields,
#userPassFields,
#sshKeyFields,
#daemonFields {
display: none;
}
</style>
{% endblock %}
{% block content %}
<div class="card mb-4">
<div class="card-header">
@ -16,44 +25,93 @@
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('add_server') }}">
<!-- 1) Wybór platformy (Linux / Mikrotik) -->
<div class="mb-3">
<label for="hostname" class="form-label">Nazwa hosta (IP lub domena)</label>
<input type="text" name="hostname" id="hostname" class="form-control" required>
</div>
<div class="mb-3">
<label for="username" class="form-label">Użytkownik SSH</label>
<input type="text" name="username" id="username" class="form-control" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Hasło SSH</label>
<input type="password" name="password" id="password" class="form-control">
</div>
<div class="mb-3">
<label for="port" class="form-label">Port SSH</label>
<input type="text" name="port" id="port" class="form-control" value="22">
</div>
<div class="mb-3">
<label for="host_type" class="form-label">Typ</label>
<select name="host_type" id="host_type" class="form-select" required>
<label for="host_type" class="form-label">Platforma (system)</label>
<select name="host_type" id="host_type" class="form-select" required onchange="toggleSystemOptions()">
<option value="linux">Linux</option>
<option value="mikrotik">Mikrotik</option>
</select>
</div>
<!-- 2) Wybór metody uwierzytelniania -->
<div class="mb-3">
<label for="auth_method" class="form-label">Metoda uwierzytelniania</label>
<select name="auth_method" id="auth_method" class="form-select">
<select name="auth_method" id="auth_method" class="form-select" onchange="toggleAuthFields()">
<option value="password">Hasło</option>
<option value="ssh_key">Klucz SSH</option>
<option value="global_key">Globalny klucz SSH</option>
<option value="daemon">Demon (Linux)</option>
</select>
</div>
<div class="mb-3">
<label for="private_key" class="form-label">Klucz prywatny (jeśli używasz klucza SSH)</label>
<textarea name="private_key" id="private_key" rows="4" class="form-control"></textarea>
<!-- Pola nazwy hosta i portu -->
<div id="hostPortFields">
<div class="mb-3">
<label for="hostname" class="form-label">Nazwa hosta (IP lub domena)</label>
<input type="text" name="hostname" id="hostname" class="form-control">
</div>
<div class="mb-3">
<label for="port" class="form-label">Port</label>
<input type="text" name="port" id="port" class="form-control" value="22">
</div>
</div>
<div class="mb-3">
<label for="key_passphrase" class="form-label">Hasło do klucza (jeśli klucz jest zaszyfrowany)</label>
<input type="password" name="key_passphrase" id="key_passphrase" class="form-control">
<!-- Pola user + hasło (dla password / ssh_key / global_key) -->
<div id="userPassFields">
<div class="mb-3">
<label for="username" class="form-label">Użytkownik</label>
<input type="text" name="username" id="username" class="form-control">
</div>
<div class="mb-3" id="passwordField">
<label for="password" class="form-label">Hasło</label>
<input type="password" name="password" id="password" class="form-control">
</div>
</div>
<!-- Pola klucza prywatnego (dla ssh_key) -->
<div id="sshKeyFields">
<div class="mb-3">
<label for="private_key" class="form-label">Klucz prywatny</label>
<textarea name="private_key" id="private_key" rows="4" class="form-control"></textarea>
</div>
<div class="mb-3">
<label for="key_passphrase" class="form-label">Hasło do klucza</label>
<input type="password" name="key_passphrase" id="key_passphrase" class="form-control">
</div>
</div>
<!-- Pola dla demona (tylko jeśli auth_method=daemon i platforma=linux) -->
<div id="daemonFields">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="use_daemon" id="use_daemon" value="1">
<label class="form-check-label" for="use_daemon">
Korzystaj z demona (zamiast SSH) [Tylko Linux]
</label>
</div>
<div class="mb-3">
<label for="daemon_url" class="form-label">URL demona</label>
<input type="text" name="daemon_url" id="daemon_url" class="form-control">
</div>
<div class="mb-3">
<label for="daemon_token" class="form-label">Token autoryzacyjny demona</label>
<input type="text" name="daemon_token" id="daemon_token" class="form-control">
</div>
</div>
<!-- Nowe: wybór preferowanego pliku /etc/hosts -->
<div class="mb-3">
<label for="preferred_hostfile_id" class="form-label">Domyślny plik /etc/hosts</label>
<select name="preferred_hostfile_id" id="preferred_hostfile_id" class="form-select">
<!-- Opcja pusta => None => "Default" -->
<option value="">(Default - brak)</option>
{% for hf in user_hostfiles %}
<option value="{{ hf.id }}">{{ hf.title }}</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-primary">Dodaj serwer</button>
</form>
</div>
@ -61,6 +119,89 @@
<div class="mt-3 text-center">
<a href="{{ url_for('server_list') }}" class="btn btn-secondary">Lista serwerów</a>
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj serwery z CSV</a>
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj z CSV</a>
</div>
{% endblock %}
{% block extra_js %}
{{ super() }}
<script>
function toggleSystemOptions() {
const hostType = document.getElementById('host_type').value;
const authMethodSelect = document.getElementById('auth_method');
// Znajdź opcję 'daemon':
const daemonOption = Array.from(authMethodSelect.options).find(opt => opt.value === 'daemon');
// Jeśli to Mikrotik, ukrywamy opcję demona
if (hostType === 'mikrotik') {
if (daemonOption) {
daemonOption.style.display = 'none';
if (authMethodSelect.value === 'daemon') {
authMethodSelect.value = 'password';
}
}
} else {
// Linux -> z powrotem pokazujemy 'daemon'
if (daemonOption) {
daemonOption.style.display = 'block';
}
}
toggleAuthFields();
}
function toggleAuthFields() {
const hostType = document.getElementById('host_type').value;
const authMethod = document.getElementById('auth_method').value;
// Kontenery:
const hostPortFields = document.getElementById('hostPortFields');
const userPassFields = document.getElementById('userPassFields');
const passwordField = document.getElementById('passwordField');
const sshKeyFields = document.getElementById('sshKeyFields');
const daemonFields = document.getElementById('daemonFields');
const useDaemon = document.getElementById('use_daemon');
// Ukrywamy wszystkie na start
hostPortFields.style.display = 'none';
userPassFields.style.display = 'none';
passwordField.style.display = 'none';
sshKeyFields.style.display = 'none';
daemonFields.style.display = 'none';
if (useDaemon) {
useDaemon.checked = false;
}
// Jeżeli authMethod != 'daemon', to normalnie pokazujemy host/port
if (authMethod !== 'daemon') {
hostPortFields.style.display = 'block';
}
// W zależności od authMethod
if (authMethod === 'password') {
userPassFields.style.display = 'block';
passwordField.style.display = 'block';
} else if (authMethod === 'ssh_key') {
userPassFields.style.display = 'block';
sshKeyFields.style.display = 'block';
} else if (authMethod === 'global_key') {
userPassFields.style.display = 'block';
} else if (authMethod === 'daemon') {
// Tylko Linux
if (hostType === 'linux') {
daemonFields.style.display = 'block';
if (useDaemon) {
useDaemon.checked = true;
}
}
}
}
document.addEventListener('DOMContentLoaded', function() {
toggleSystemOptions();
});
</script>
{% endblock %}

View File

@ -1,5 +1,5 @@
{% extends "base.html" %}
{% block title %}Edytuj server - /etc/hosts Manager{% endblock %}
{% block title %}Edytuj serwer - /etc/hosts Manager{% endblock %}
{% block extra_css %}
{{ super() }}
<style>
@ -7,8 +7,17 @@
max-width: 300px;
text-align: left;
}
/* Domyślnie ukrywamy te kontenery. JS je włącza zależnie od opcji. */
#hostPortFields,
#userPassFields,
#sshKeyFields,
#daemonFields {
display: none;
}
</style>
{% endblock %}
{% block content %}
<div class="card mb-4">
<div class="card-header">
@ -16,44 +25,100 @@
</div>
<div class="card-body">
<form method="POST" action="{{ url_for('edit_server', id=host.id) }}">
<!-- 1) Platforma (Linux / Mikrotik) -->
<div class="mb-3">
<label for="hostname" class="form-label">Nazwa hosta (IP lub domena)</label>
<input type="text" name="hostname" id="hostname" class="form-control" value="{{ host.hostname }}" required>
</div>
<div class="mb-3">
<label for="username" class="form-label">Użytkownik SSH</label>
<input type="text" name="username" id="username" class="form-control" value="{{ host.username }}" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Hasło (pozostaw puste, aby nie zmieniać)</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Wprowadź nowe hasło">
</div>
<div class="mb-3">
<label for="port" class="form-label">Port SSH</label>
<input type="text" name="port" id="port" class="form-control" value="{{ host.port }}">
</div>
<div class="mb-3">
<label for="host_type" class="form-label">Typ</label>
<select name="host_type" id="host_type" class="form-select" required>
<label for="host_type" class="form-label">Platforma (system)</label>
<select name="host_type" id="host_type" class="form-select" required onchange="toggleSystemOptions()">
<option value="linux" {% if host.type == 'linux' %}selected{% endif %}>Linux</option>
<option value="mikrotik" {% if host.type == 'mikrotik' %}selected{% endif %}>Mikrotik</option>
</select>
</div>
<!-- 2) Metoda uwierzytelniania -->
<div class="mb-3">
<label for="auth_method" class="form-label">Metoda uwierzytelniania</label>
<select name="auth_method" id="auth_method" class="form-select">
<option value="password" {% if host.auth_method == 'password' %}selected{% endif %}>Hasło</option>
<option value="ssh_key" {% if host.auth_method == 'ssh_key' %}selected{% endif %}>Klucz SSH</option>
<select name="auth_method" id="auth_method" class="form-select" onchange="toggleAuthFields()">
<option value="password" {% if host.auth_method == 'password' %}selected{% endif %}>Hasło</option>
<option value="ssh_key" {% if host.auth_method == 'ssh_key' %}selected{% endif %}>Klucz SSH</option>
<option value="global_key" {% if host.auth_method == 'global_key' %}selected{% endif %}>Globalny klucz SSH</option>
<option value="daemon" {% if host.use_daemon and host.type == 'linux' %}selected{% endif %}>Demon (Linux)</option>
</select>
</div>
<div class="mb-3">
<label for="private_key" class="form-label">Klucz prywatny (jeśli używasz klucza SSH)</label>
<textarea name="private_key" id="private_key" rows="4" class="form-control">{{ host.private_key }}</textarea>
<!-- Kontener host + port -->
<div id="hostPortFields">
<div class="mb-3">
<label for="hostname" class="form-label">Nazwa hosta (IP lub domena)</label>
<input type="text" name="hostname" id="hostname" class="form-control" value="{{ host.hostname }}">
</div>
<div class="mb-3">
<label for="port" class="form-label">Port</label>
<input type="text" name="port" id="port" class="form-control" value="{{ host.port }}">
</div>
</div>
<div class="mb-3">
<label for="key_passphrase" class="form-label">Hasło do klucza (jeśli klucz jest zaszyfrowany)</label>
<input type="password" name="key_passphrase" id="key_passphrase" class="form-control" value="{{ host.key_passphrase }}">
<!-- Kontener user + hasło -->
<div id="userPassFields">
<div class="mb-3">
<label for="username" class="form-label">Użytkownik</label>
<input type="text" name="username" id="username" class="form-control" value="{{ host.username }}">
</div>
<div class="mb-3" id="passwordField">
<label for="password" class="form-label">Hasło (pozostaw puste, aby nie zmieniać)</label>
<input type="password" name="password" id="password" class="form-control" placeholder="Wprowadź nowe hasło">
</div>
</div>
<!-- Kontener klucza SSH (ssh_key) -->
<div id="sshKeyFields">
<div class="mb-3">
<label for="private_key" class="form-label">Klucz prywatny</label>
<textarea name="private_key" id="private_key" rows="4" class="form-control">{{ host.private_key }}</textarea>
</div>
<div class="mb-3">
<label for="key_passphrase" class="form-label">Hasło do klucza</label>
<input type="password" name="key_passphrase" id="key_passphrase" class="form-control" value="{{ host.key_passphrase }}">
</div>
</div>
<!-- Kontener demona -->
<div id="daemonFields">
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="use_daemon" id="use_daemon" value="1"
{% if host.use_daemon %}checked{% endif %}>
<label class="form-check-label" for="use_daemon">
Korzystaj z demona (zamiast SSH) [Tylko Linux]
</label>
</div>
<div class="mb-3">
<label for="daemon_url" class="form-label">URL demona</label>
<input type="text" name="daemon_url" id="daemon_url" class="form-control" value="{{ host.daemon_url }}">
</div>
<div class="mb-3">
<label for="daemon_token" class="form-label">Token autoryzacyjny demona</label>
<input type="text" name="daemon_token" id="daemon_token" class="form-control" value="{{ host.daemon_token }}">
</div>
</div>
<!-- Nowe: wybór pliku /etc/hosts (preferred_hostfile_id) -->
<div class="mb-3">
<label for="preferred_hostfile_id" class="form-label">Domyślny plik /etc/hosts dla tego serwera</label>
<select name="preferred_hostfile_id" id="preferred_hostfile_id" class="form-select">
<!-- pusta wartość => None => "Default" -->
<option value=""
{% if not host.preferred_hostfile_id %}selected{% endif %}>
(Default - brak)
</option>
{% for hf in user_hostfiles %}
<option value="{{ hf.id }}"
{% if host.preferred_hostfile_id == hf.id %}selected{% endif %}>
{{ hf.title }}
</option>
{% endfor %}
</select>
</div>
<button type="submit" class="btn btn-primary">Zapisz zmiany</button>
</form>
</div>
@ -61,7 +126,84 @@
<div class="mt-3 text-center">
<a href="{{ url_for('server_list') }}" class="btn btn-secondary">Lista serwerów</a>
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj serwery z CSV</a>
<a href="{{ url_for('export_servers_to_csv') }}" class="btn btn-secondary">Eksportuj serwery do CSV</a>
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj z CSV</a>
<a href="{{ url_for('export_servers_to_csv') }}" class="btn btn-secondary">Eksportuj do CSV</a>
</div>
{% endblock %}
{% block extra_js %}
{{ super() }}
<script>
function toggleSystemOptions() {
const hostType = document.getElementById('host_type').value;
const authMethodSelect = document.getElementById('auth_method');
const daemonOption = Array.from(authMethodSelect.options).find(opt => opt.value === 'daemon');
// Mikrotik -> chowamy daemon
if (hostType === 'mikrotik') {
if (daemonOption) {
daemonOption.style.display = 'none';
if (authMethodSelect.value === 'daemon') {
authMethodSelect.value = 'password';
}
}
} else {
// Linux -> pokazujemy
if (daemonOption) {
daemonOption.style.display = 'block';
}
}
toggleAuthFields();
}
function toggleAuthFields() {
const hostType = document.getElementById('host_type').value;
const authMethod = document.getElementById('auth_method').value;
const hostPortFields = document.getElementById('hostPortFields');
const userPassFields = document.getElementById('userPassFields');
const passwordField = document.getElementById('passwordField');
const sshKeyFields = document.getElementById('sshKeyFields');
const daemonFields = document.getElementById('daemonFields');
const useDaemon = document.getElementById('use_daemon');
// Najpierw wszystko chowamy
hostPortFields.style.display = 'none';
userPassFields.style.display = 'none';
passwordField.style.display = 'none';
sshKeyFields.style.display = 'none';
daemonFields.style.display = 'none';
if (useDaemon) {
useDaemon.checked = false;
}
// Gdy authMethod != 'daemon', włącz hostPort
if (authMethod !== 'daemon') {
hostPortFields.style.display = 'block';
}
// Szczegółowe reguły
if (authMethod === 'password') {
userPassFields.style.display = 'block';
passwordField.style.display = 'block';
} else if (authMethod === 'ssh_key') {
userPassFields.style.display = 'block';
sshKeyFields.style.display = 'block';
} else if (authMethod === 'global_key') {
userPassFields.style.display = 'block';
} else if (authMethod === 'daemon') {
if (hostType === 'linux') {
daemonFields.style.display = 'block';
if (useDaemon) {
useDaemon.checked = true;
}
}
}
}
// Uruchamiamy przy ładowaniu
document.addEventListener('DOMContentLoaded', function() {
toggleSystemOptions();
});
</script>
{% endblock %}

View File

@ -1,29 +1,32 @@
{% extends "base.html" %}
{% block title %}Lista serwerów - /etc/hosts Manager{% endblock %}
{% block extra_css %}
{{ super() }}
<style>
.tooltip-inner {
max-width: 300px;
text-align: left;
}
</style>
{{ super() }}
<style>
.tooltip-inner {
max-width: 300px;
text-align: left;
}
</style>
{% endblock %}
{% block content %}
<div class="card">
<div class="card-header">
<h2>Lista serwerów</h2>
</div>
<div class="card-body table-responsive">
<table class="table table-striped">
<table class="table table-striped align-middle">
<thead>
<tr>
<th>ID</th>
<th>Nazwa hosta</th>
<th>Użytkownik SSH</th>
<th>Użytkownik</th>
<th>Port</th>
<th>Typ</th>
<th>Metoda uwierzytelniania</th>
<th>Uwierzytelnianie</th>
<th>Wybrany plik /etc/hosts</th> <!-- Nowa kolumna -->
<th>Auto Deploy</th>
<th>Auto Backup</th>
<th>Akcje</th>
@ -38,20 +41,50 @@
</td>
<td>{{ h.username }}</td>
<td>{{ h.port }}</td>
<td>{{ h.type }}</td>
<td>{{ h.auth_method }}</td>
<!-- Formularz aktualizujący automatyczny deploy dla serwera -->
<td>
{% if h.type == 'linux' %}
Linux{% if h.use_daemon %} (Demon){% endif %}
{% else %}
Mikrotik
{% endif %}
</td>
<td>
{% if h.use_daemon and h.type == 'linux' %}
<em>- używa Demona -</em>
{% else %}
{% if h.auth_method == 'password' %}
Hasło
{% elif h.auth_method == 'ssh_key' %}
Klucz SSH
{% elif h.auth_method == 'global_key' %}
Globalny klucz
{% else %}
{{ h.auth_method }}
{% endif %}
{% endif %}
</td>
<!-- Nowa kolumna: preferowany plik hosts -->
<td>
{% if h.preferred_hostfile %}
{{ h.preferred_hostfile.title }}
{% else %}
(Default)
{% endif %}
</td>
<!-- Formularz aktualizujący auto_deploy -->
<td>
<form method="POST" action="{{ url_for('update_host_automation', id=h.id) }}" style="display:inline;">
<input type="hidden" name="setting" value="auto_deploy">
<input type="checkbox" name="enabled" value="1" onchange="this.form.submit()" {% if h.auto_deploy_enabled %}checked{% endif %}>
<input type="checkbox" name="enabled" value="1"
onchange="this.form.submit()" {% if h.auto_deploy_enabled %}checked{% endif %}>
</form>
</td>
<!-- Formularz aktualizujący automatyczny backup dla serwera -->
<!-- Formularz aktualizujący auto_backup -->
<td>
<form method="POST" action="{{ url_for('update_host_automation', id=h.id) }}" style="display:inline;">
<input type="hidden" name="setting" value="auto_backup">
<input type="checkbox" name="enabled" value="1" onchange="this.form.submit()" {% if h.auto_backup_enabled %}checked{% endif %}>
<input type="checkbox" name="enabled" value="1"
onchange="this.form.submit()" {% if h.auto_backup_enabled %}checked{% endif %}>
</form>
</td>
<td>
@ -71,7 +104,7 @@
<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 serwery z CSV</a>
<a href="{{ url_for('export_servers_to_csv') }}" class="btn btn-secondary">Eksportuj serwery do CSV</a>
<a href="{{ url_for('import_servers') }}" class="btn btn-secondary">Importuj z CSV</a>
<a href="{{ url_for('export_servers_to_csv') }}" class="btn btn-secondary">Eksportuj do CSV</a>
</div>
{% endblock %}