This commit is contained in:
Mateusz Gruszczyński
2025-11-04 09:56:37 +01:00
parent 32ef62e4ac
commit addb21bc3e
34 changed files with 3864 additions and 367 deletions

16
templates/403.html Normal file
View File

@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Access Denied{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="text-center">
<h1 style="font-size: 72px; color: #dc3545;">403</h1>
<h2>Access Denied</h2>
<p class="text-muted">You don't have permission to access this resource.</p>
<a href="{{ url_for('main.index') }}" class="btn btn-primary">
<i class="bi bi-house"></i> Go Home
</a>
</div>
</div>
{% endblock %}

16
templates/404.html Normal file
View File

@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Page Not Found{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="text-center">
<h1 style="font-size: 72px; color: #dc3545;">404</h1>
<h2>Page Not Found</h2>
<p class="text-muted">The page you're looking for doesn't exist.</p>
<a href="{{ url_for('main.index') }}" class="btn btn-primary">
<i class="bi bi-house"></i> Go Home
</a>
</div>
</div>
{% endblock %}

16
templates/500.html Normal file
View File

@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% block title %}Server Error{% endblock %}
{% block content %}
<div class="container mt-5">
<div class="text-center">
<h1 style="font-size: 72px; color: #dc3545;">500</h1>
<h2>Internal Server Error</h2>
<p class="text-muted">Something went wrong on our end.</p>
<a href="{{ url_for('main.index') }}" class="btn btn-primary">
<i class="bi bi-house"></i> Go Home
</a>
</div>
</div>
{% endblock %}

View File

@@ -1,6 +1,6 @@
{% set active_page = active_page|default('') %}
<!doctype html>
<html lang="pl" data-bs-theme="dark">
<html lang="en" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -15,46 +15,180 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" rel="stylesheet">
<style>
.navbar-brand {
font-weight: 700;
font-size: 1.25rem;
}
.user-menu {
min-width: 200px;
}
.menu-divider {
margin: 0.5rem 0;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
</style>
</head>
<body class="bg-body">
<header class="header1" id="header1">
<div class="container d-flex align-items-center justify-content-between flex-wrap gap-2 py-2">
<a href="{{ url_for('home') }}" class="d-flex align-items-center text-decoration-none logo text-reset">
<h3 class="m-0 d-flex align-items-center gap-2">
<i class="fas fa-globe"></i><span>HAProxy Configurator</span>
</h3>
</a>
<nav class="menu d-flex align-items-center gap-1 flex-wrap">
<a href="{{ url_for('home') }}" class="menu-link {{ 'active' if request.path.startswith('/home') else '' }}"><i class="bi bi-speedometer"></i> Dashboard</a>
<a href="{{ url_for('main.index') }}" class="menu-link {{ 'active' if request.path == '/' else '' }}"><i class="bi bi-plus-circle"></i> Add FE/BE</a>
<a href="{{ url_for('edit.edit_haproxy_config') }}" class="menu-link {{ 'active' if request.path.startswith('/edit') else '' }}"><i class="bi bi-pencil-square"></i> Edit Configuration</a>
<a href="{{ url_for('display_logs') }}" class="menu-link {{ 'active' if request.path.startswith('/logs') else '' }}"><i class="bi bi-shield-lock"></i> Logs</a>
<a href="{{ url_for('display_haproxy_stats') }}" class="menu-link {{ 'active' if request.path.startswith('/statistics') else '' }}"><i class="bi bi-graph-up-arrow"></i> Stats</a>
<a href="http://{{ request.host.split(':')[0] }}:8404/stats" class="menu-link" target="_blank" rel="noopener"><i class="bi bi-box-arrow-up-right"></i> HAProxy Stats</a>
</nav>
</div>
</header>
<!-- NAVBAR -->
<header class="navbar navbar-expand-lg navbar-dark bg-dark border-bottom border-secondary">
<div class="container-fluid px-4">
<!-- Logo -->
<a href="{% if session.get('user_id') %}{{ url_for('main.index') }}{% else %}{{ url_for('auth.login') }}{% endif %}" class="navbar-brand d-flex align-items-center gap-2">
<i class="fas fa-globe"></i>
<span>HAProxy Manager</span>
</a>
<main class="container py-4">
{% with messages = get_flashed_messages() %}{% if messages %}<div id="_flash_msgs" data-msgs="{{ messages|tojson }}"></div>{% endif %}{% endwith %}
{% block breadcrumb %}{% endblock %}
<div id="toast-stack" class="toast-container position-fixed top-0 end-0 p-3"></div>
{% block content %}{% endblock %}
</main>
<!-- Toggle Button (Mobile) -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<footer class="app-footer border-top">
<div class="container d-flex flex-wrap justify-content-between align-items-center py-3 small text-muted">
<span>© 2025 HAProxy Configurator</span>
<span class="d-flex align-items-center gap-2">
<i class="bi bi-code-slash"></i>
<span>Based on: <a href="https://github.com/alonz22/haproxy-dashboard">This project</a> | by @linuxiarz.pl </span>
</span>
</div>
</footer>
<!-- Navigation Menu -->
<div class="collapse navbar-collapse" id="navbarNav">
{% if session.get('user_id') %}
<nav class="navbar-nav ms-auto d-flex align-items-center gap-3">
<!-- Menu Links -->
<a href="{{ url_for('main.index') }}" class="nav-link {{ 'active' if request.path == '/' or request.path.startswith('/home') else '' }}">
<i class="bi bi-speedometer2"></i> Dashboard
</a>
<a href="{{ url_for('main.index') }}" class="nav-link {{ 'active' if request.path.startswith('/add') else '' }}">
<i class="bi bi-plus-circle"></i> Add VHost
</a>
<a href="{{ url_for('edit.edit_haproxy_config') }}" class="nav-link {{ 'active' if request.path.startswith('/edit') else '' }}">
<i class="bi bi-pencil-square"></i> Edit Config
</a>
<a href="{{ url_for('display_logs') }}" class="nav-link {{ 'active' if request.path.startswith('/logs') else '' }}">
<i class="bi bi-shield-lock"></i> Logs
</a>
<a href="{{ url_for('display_haproxy_stats') }}" class="nav-link {{ 'active' if request.path.startswith('/statistics') else '' }}">
<i class="bi bi-graph-up-arrow"></i> Stats
</a>
<a href="http://{{ request.host.split(':')[0] }}:8404/stats" class="nav-link" target="_blank" rel="noopener">
<i class="bi bi-box-arrow-up-right"></i> HAProxy Stats
</a>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
{% block scripts %}{% endblock %}
{% block page_js %}{% endblock %}
</body>
<!-- User Dropdown Menu -->
<div class="nav-item dropdown">
<button class="nav-link dropdown-toggle btn btn-link text-decoration-none d-flex align-items-center gap-2" id="userMenu" type="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-person-circle"></i>
<span class="d-none d-lg-inline">{{ session.get('username', 'User') }}</span>
</button>
<ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end user-menu" aria-labelledby="userMenu">
<li>
<a class="dropdown-item" href="#" disabled>
<i class="bi bi-person"></i> {{ session.get('username', 'User') }}
</a>
</li>
<li><hr class="dropdown-divider"></li>
<!-- Admin Only Menu Items -->
{% if session.get('is_admin') %}
<li>
<a class="dropdown-item" href="{{ url_for('main.index') }}">
<i class="bi bi-people"></i> User Management
</a>
</li>
<li>
<a class="dropdown-item" href="{{ url_for('main.index') }}">
<i class="bi bi-shield-check"></i> Certificates
</a>
</li>
<li><hr class="dropdown-divider"></li>
{% endif %}
<li>
<a class="dropdown-item text-warning" href="{{ url_for('auth.logout') }}">
<i class="bi bi-box-arrow-right"></i> Logout
</a>
</li>
</ul>
</div>
</nav>
{% else %}
<!-- Login Link (when not authenticated) -->
<nav class="navbar-nav ms-auto">
<a href="{{ url_for('auth.login') }}" class="nav-link">
<i class="bi bi-box-arrow-in-right"></i> Login
</a>
</nav>
{% endif %}
</div>
</div>
</header>
<!-- MAIN CONTENT -->
<main class="container-fluid py-4">
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
<i class="bi bi-{{ 'check-circle' if category == 'success' else 'exclamation-circle' if category == 'danger' else 'info-circle' }}"></i>
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<!-- Breadcrumb -->
{% block breadcrumb %}{% endblock %}
<!-- Toast Container -->
<div id="toast-stack" class="toast-container position-fixed top-0 end-0 p-3"></div>
<!-- Page Content -->
{% block content %}{% endblock %}
</main>
<!-- FOOTER -->
<footer class="app-footer border-top border-secondary bg-dark mt-5">
<div class="container-fluid px-4 py-3">
<div class="row align-items-center">
<div class="col-md-6 small text-muted">
<p class="mb-2">
© 2025 <strong>HAProxy Configurator & Manager</strong>
</p>
<p class="mb-0">
<i class="bi bi-info-circle"></i>
Powerful web-based HAProxy configuration management system
</p>
</div>
<div class="col-md-6 text-md-end small text-muted text-start">
<p class="mb-2">
<i class="bi bi-code-slash"></i>
Built with <strong>Flask</strong> + <strong>SQLAlchemy</strong> + <strong>Bootstrap 5</strong>
</p>
<p class="mb-0">
Based on: <a href="https://github.com/alonz22/haproxy-dashboard" target="_blank" class="text-decoration-none" rel="noopener">Original Project</a>
| Maintained by <strong>@linuxiarz.pl</strong>
</p>
</div>
</div>
</div>
</footer>
<!-- SCRIPTS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
{% block scripts %}{% endblock %}
{% block page_js %}{% endblock %}
<script>
/**
* Auto-dismiss alerts after 5 seconds
*/
document.addEventListener('DOMContentLoaded', function() {
const alerts = document.querySelectorAll('.alert:not(.alert-permanent)');
alerts.forEach(alert => {
setTimeout(() => {
const bsAlert = new bootstrap.Alert(alert);
bsAlert.close();
}, 5000);
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,115 @@
{% extends "base.html" %}
{% block title %}HAProxy • Certificate Manager{% endblock %}
{% block breadcrumb %}
<nav aria-label="breadcrumb" class="mb-3">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="{{ url_for('main.index') }}"><i class="bi bi-house"></i></a></li>
<li class="breadcrumb-item active">SSL Certificates</li>
</ol>
</nav>
{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h2><i class="bi bi-shield-lock"></i> SSL Certificates</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#uploadModal">
<i class="bi bi-cloud-upload"></i> Upload Certificate
</button>
</div>
<!-- Certificates Table -->
<div class="card">
<div class="card-header bg-dark">
<h5 class="mb-0"><i class="bi bi-list-check"></i> Certificates List</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover" id="certsTable">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Common Name (CN)</th>
<th>Expires</th>
<th>Used By</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="certsList">
<tr><td colspan="6" class="text-center text-muted py-4">Loading...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- Upload Modal -->
<div class="modal fade" id="uploadModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title">Upload SSL Certificate</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="uploadForm" enctype="multipart/form-data">
<div class="mb-3">
<label class="form-label">Certificate Name *</label>
<input type="text" class="form-control" id="cert_name" required>
<small class="text-muted">e.g., example-com-2025</small>
</div>
<div class="mb-3">
<label class="form-label">PEM Certificate File * <i class="bi bi-info-circle" title="Combined certificate + key in PEM format"></i></label>
<input type="file" class="form-control" id="cert_file" accept=".pem,.crt,.cert,.key" required>
<small class="text-muted">
Supported formats: PEM (combined cert+key), .crt, .cert, .key
</small>
</div>
<div class="alert alert-info">
<i class="bi bi-info-circle"></i>
<strong>Supported Formats:</strong>
<ul class="mb-0 mt-2">
<li>Single file with both certificate and private key (PEM)</li>
<li>PKCS#12 (.p12) - will be converted</li>
<li>Separate .crt and .key files - upload combined</li>
</ul>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="uploadBtn">Upload</button>
</div>
</div>
</div>
</div>
<!-- Certificate Details Modal -->
<div class="modal fade" id="detailsModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-info text-white">
<h5 class="modal-title">Certificate Details: <span id="detailsName"></span></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div id="detailsContent"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" id="exportBtn">
<i class="bi bi-download"></i> Export PEM
</button>
</div>
</div>
</div>
</div>
<script src="{{ url_for('static', filename='js/cert_manager.js') }}"></script>
{% endblock %}

191
templates/dashboard.html Normal file
View File

@@ -0,0 +1,191 @@
{% extends "base.html" %}
{% block title %}HAProxy • Dashboard{% endblock %}
{% block breadcrumb %}
<nav aria-label="breadcrumb" class="mb-3">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="{{ url_for('main.index') }}"><i class="bi bi-house"></i></a></li>
<li class="breadcrumb-item active">VHosts</li>
</ol>
</nav>
{% endblock %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h2><i class="bi bi-server"></i> Virtual Hosts</h2>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#newVHostModal">
<i class="bi bi-plus-lg"></i> Create VHost
</button>
</div>
<!-- Stats Cards -->
<div class="row mb-4">
<div class="col-md-3">
<div class="card bg-primary text-white">
<div class="card-body">
<h5 class="card-title">Total VHosts</h5>
<h3 id="total_vhosts">0</h3>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-success text-white">
<div class="card-body">
<h5 class="card-title">Enabled</h5>
<h3 id="enabled_vhosts">0</h3>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-warning text-dark">
<div class="card-body">
<h5 class="card-title">Disabled</h5>
<h3 id="disabled_vhosts">0</h3>
</div>
</div>
</div>
<div class="col-md-3">
<div class="card bg-info text-white">
<div class="card-body">
<h5 class="card-title">SSL Enabled</h5>
<h3 id="ssl_vhosts">0</h3>
</div>
</div>
</div>
</div>
<!-- VHosts Table -->
<div class="card">
<div class="card-header bg-dark">
<h5 class="mb-0"><i class="bi bi-list-check"></i> VHosts List</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover" id="vhostsTable">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Hostname</th>
<th>Bind</th>
<th>Protocol</th>
<th>Servers</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="vhostsList">
<tr><td colspan="7" class="text-center text-muted py-4">Loading...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- New VHost Modal -->
<div class="modal fade" id="newVHostModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title">Create New VHost</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="newVHostForm">
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">VHost Name *</label>
<input type="text" class="form-control" id="vhost_name" required>
<small class="text-muted">e.g., web-app-01</small>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Hostname *</label>
<input type="text" class="form-control" id="vhost_hostname" required>
<small class="text-muted">e.g., example.com</small>
</div>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label class="form-label">Frontend Port *</label>
<input type="number" class="form-control" id="vhost_port" value="443" required>
</div>
<div class="col-md-6 mb-3">
<label class="form-label">Protocol</label>
<select class="form-select" id="vhost_protocol">
<option value="http">HTTP</option>
<option value="tcp">TCP</option>
</select>
</div>
</div>
<div class="mb-3">
<label class="form-label">Load Balancing Method</label>
<select class="form-select" id="vhost_lb_method">
<option value="roundrobin">Round Robin</option>
<option value="leastconn">Least Connections</option>
<option value="source">Source IP Hash</option>
<option value="uri">URI Hash</option>
</select>
</div>
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input" id="vhost_ssl">
<label class="form-check-label" for="vhost_ssl">
Enable SSL
</label>
</div>
<hr>
<h6>Backend Servers</h6>
<div id="backendServersContainer">
<div class="backend-server mb-3 p-3 border rounded">
<div class="row">
<div class="col-md-6 mb-2">
<input type="text" class="form-control backend-ip" placeholder="IP Address" required>
</div>
<div class="col-md-6 mb-2">
<input type="number" class="form-control backend-port" placeholder="Port" value="80" required>
</div>
</div>
<button type="button" class="btn btn-sm btn-danger remove-server">Remove</button>
</div>
</div>
<button type="button" class="btn btn-sm btn-outline-secondary" id="addServerBtn">
<i class="bi bi-plus"></i> Add Server
</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="createVHostBtn">Create VHost</button>
</div>
</div>
</div>
</div>
<!-- Edit VHost Modal -->
<div class="modal fade" id="editVHostModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header bg-primary text-white">
<h5 class="modal-title">Edit VHost: <span id="editVHostName"></span></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="editVHostForm">
<div id="editFormContent"></div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="updateVHostBtn">Update VHost</button>
</div>
</div>
</div>
</div>
<script src="{{ url_for('static', filename='js/vhost_manager.js') }}"></script>
{% endblock %}

132
templates/login.html Normal file
View File

@@ -0,0 +1,132 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HAProxy Configurator - Login</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-container {
width: 100%;
max-width: 400px;
background: white;
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
padding: 40px;
}
.login-header {
text-align: center;
margin-bottom: 30px;
}
.login-header i {
font-size: 48px;
color: #667eea;
margin-bottom: 10px;
}
.login-header h1 {
font-size: 28px;
color: #333;
margin: 10px 0 5px;
}
.login-header p {
color: #666;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
.form-control {
border: 1px solid #ddd;
padding: 10px 15px;
border-radius: 5px;
font-size: 14px;
}
.form-control:focus {
border-color: #667eea;
box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}
.btn-login {
width: 100%;
padding: 10px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 5px;
font-weight: 600;
cursor: pointer;
margin-top: 10px;
}
.btn-login:hover {
opacity: 0.95;
}
.alert {
font-size: 14px;
margin-bottom: 20px;
}
.default-creds {
background: #f8f9fa;
border-left: 4px solid #ffc107;
padding: 10px 15px;
border-radius: 4px;
margin-top: 20px;
font-size: 12px;
}
.default-creds strong {
color: #ff6b6b;
}
</style>
</head>
<body>
<div class="login-container">
<div class="login-header">
<i class="bi bi-shield-lock"></i>
<h1>HAProxy</h1>
<p>Configurator & Manager</p>
</div>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert alert-{{ category }} alert-dismissible fade show" role="alert">
{{ message }}
<button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div>
{% endfor %}
{% endif %}
{% endwith %}
<form method="POST" action="{{ url_for('auth.login') }}">
<div class="form-group">
<label class="form-label">Username</label>
<input type="text" class="form-control" name="username" required autofocus>
</div>
<div class="form-group">
<label class="form-label">Password</label>
<input type="password" class="form-control" name="password" required>
</div>
<button type="submit" class="btn btn-login">
<i class="bi bi-box-arrow-in-right me-2"></i>Sign In
</button>
</form>
<div class="default-creds">
<i class="bi bi-info-circle me-1"></i>
<strong>Default credentials:</strong><br>
Username: <code>admin</code><br>
Password: <code>admin123</code>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -0,0 +1,115 @@
{% extends "base.html" %}
{% set active_page = "users" %}
{% block title %}HAProxy • User Management{% endblock %}
{% block breadcrumb %}
<nav aria-label="breadcrumb" class="mb-3">
<ol class="breadcrumb mb-0">
<li class="breadcrumb-item"><a href="{{ url_for('main.index') }}"><i class="bi bi-house"></i></a></li>
<li class="breadcrumb-item active">Users</li>
</ol>
</nav>
{% endblock %}
{% block content %}
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h5 class="mb-0"><i class="bi bi-people me-2"></i>User Management</h5>
</div>
<div class="card-body">
<!-- New User Button -->
<button class="btn btn-success mb-3" data-bs-toggle="modal" data-bs-target="#newUserModal">
<i class="bi bi-person-plus me-1"></i>Add New User
</button>
<!-- Users Table -->
<div class="table-responsive">
<table class="table table-hover" id="usersTable">
<thead class="table-light">
<tr>
<th>Username</th>
<th>Role</th>
<th>Created</th>
<th>Last Login</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="usersList">
<tr><td colspan="5" class="text-center text-muted py-4">Loading...</td></tr>
</tbody>
</table>
</div>
</div>
</div>
<!-- New User Modal -->
<div class="modal fade" id="newUserModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add New User</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="newUserForm">
<div class="mb-3">
<label class="form-label">Username</label>
<input type="text" class="form-control" id="newUsername" required minlength="3">
</div>
<div class="mb-3">
<label class="form-label">Password</label>
<input type="password" class="form-control" id="newPassword" required minlength="6">
</div>
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input" id="newIsAdmin">
<label class="form-check-label" for="newIsAdmin">
Admin privileges
</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="createUserBtn">Create</button>
</div>
</div>
</div>
</div>
<!-- Edit User Modal -->
<div class="modal fade" id="editUserModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit User: <span id="editUsername"></span></h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="editUserForm">
<div class="mb-3">
<label class="form-label">New Password (leave blank to keep current)</label>
<input type="password" class="form-control" id="editPassword" minlength="6">
</div>
<div class="form-check mb-3">
<input type="checkbox" class="form-check-input" id="editIsAdmin">
<label class="form-check-label" for="editIsAdmin">
Admin privileges
</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="updateUserBtn">Update</button>
</div>
</div>
</div>
</div>
<script src="{{ url_for('static', filename='js/user_manager.js') }}"></script>
{% endblock %}