382 lines
No EOL
16 KiB
HTML
382 lines
No EOL
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{ title|default('Network Infrastructure Management') }}</title>
|
|
<!-- Bootstrap CSS -->
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<!-- Tabler Icons -->
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@2.22.0/tabler-icons.min.css">
|
|
<!-- Font Awesome -->
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
<!-- Google Fonts -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
|
|
<!-- Custom CSS -->
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/app.css') }}">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/tabler.min.css') }}">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='libs/tabler-icons/tabler-icons.min.css') }}">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/custom.css') }}">
|
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/markdown.css') }}">
|
|
<!-- Favicon -->
|
|
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/favicon.png') }}">
|
|
{% block styles %}{% endblock %}
|
|
<script>
|
|
// Check for saved theme preference or respect OS preference
|
|
function initTheme() {
|
|
const storedTheme = localStorage.getItem('theme');
|
|
if (storedTheme) {
|
|
document.documentElement.setAttribute('data-bs-theme', storedTheme);
|
|
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
|
document.documentElement.setAttribute('data-bs-theme', 'dark');
|
|
localStorage.setItem('theme', 'dark');
|
|
}
|
|
}
|
|
|
|
// Run before page load to prevent flash
|
|
initTheme();
|
|
</script>
|
|
<style>
|
|
.sidebar-item-parent {
|
|
position: relative;
|
|
}
|
|
|
|
.sidebar-submenu {
|
|
display: none;
|
|
padding-left: 20px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.sidebar-item-parent.expanded .sidebar-submenu {
|
|
display: block;
|
|
}
|
|
|
|
.sidebar-item-parent.expanded .toggle-icon {
|
|
transform: rotate(180deg);
|
|
}
|
|
|
|
.subnet-item,
|
|
.server-item {
|
|
padding: 5px 10px;
|
|
margin: 2px 0;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
text-decoration: none;
|
|
color: inherit;
|
|
}
|
|
|
|
.subnet-item:hover,
|
|
.server-item:hover {
|
|
background-color: rgba(0, 0, 0, 0.05);
|
|
}
|
|
|
|
.subnet-item.active,
|
|
.server-item.active {
|
|
background-color: rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.subnet-servers {
|
|
margin-left: 15px;
|
|
display: none;
|
|
}
|
|
|
|
.subnet-item-expanded .subnet-servers {
|
|
display: block;
|
|
}
|
|
|
|
.subnet-item-expanded .subnet-toggle-icon {
|
|
transform: rotate(90deg);
|
|
}
|
|
|
|
.subnet-toggle-icon {
|
|
transition: transform 0.2s ease;
|
|
margin-right: 5px;
|
|
}
|
|
|
|
.loading-placeholder {
|
|
color: #888;
|
|
font-style: italic;
|
|
padding: 5px 15px;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body class="{{ 'auth-page' if not current_user.is_authenticated else '' }}">
|
|
<!-- Notification Area -->
|
|
<div id="notification-area"></div>
|
|
|
|
{% if current_user.is_authenticated %}
|
|
<!-- Sidebar for authenticated users -->
|
|
<aside class="sidebar">
|
|
<div class="sidebar-brand">
|
|
<span class="ti ti-network"></span>
|
|
<span class="sidebar-brand-text">NetDocs</span>
|
|
</div>
|
|
|
|
<div class="sidebar-nav">
|
|
<div class="sidebar-heading">Main</div>
|
|
<a href="{{ url_for('dashboard.dashboard_home') }}"
|
|
class="sidebar-item {{ 'active' if request.endpoint == 'dashboard.dashboard_home' }}">
|
|
<span class="ti ti-dashboard me-2"></span> Dashboard
|
|
</a>
|
|
<a href="{{ url_for('dashboard.server_list') }}"
|
|
class="sidebar-item {{ 'active' if request.endpoint and request.endpoint.startswith('dashboard.server') }}">
|
|
<span class="ti ti-server me-2"></span> Servers
|
|
</a>
|
|
|
|
<!-- IPAM with Subnet Tree -->
|
|
<div class="sidebar-item-parent">
|
|
<a href="{{ url_for('ipam.ipam_home') }}"
|
|
class="sidebar-item {{ 'active' if request.endpoint and request.endpoint.startswith('ipam.') }}">
|
|
<span class="ti ti-network me-2"></span> IPAM
|
|
<span class="ti ti-chevron-down ms-auto toggle-icon"></span>
|
|
</a>
|
|
<div class="sidebar-submenu">
|
|
<div id="subnet-tree-container">
|
|
<!-- Subnets will be loaded here -->
|
|
<div class="text-center py-2 d-none" id="subnet-loader">
|
|
<div class="spinner-border spinner-border-sm" role="status">
|
|
<span class="visually-hidden">Loading...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-heading">Management</div>
|
|
<a href="{{ url_for('dashboard.server_new') }}" class="sidebar-item">
|
|
<span class="ti ti-plus me-2"></span> Add Server
|
|
</a>
|
|
<a href="{{ url_for('ipam.subnet_new') }}" class="sidebar-item">
|
|
<span class="ti ti-plus me-2"></span> Add Subnet
|
|
</a>
|
|
|
|
<div class="sidebar-heading">User</div>
|
|
<a href="{{ url_for('dashboard.settings') }}"
|
|
class="sidebar-item {{ 'active' if request.endpoint == 'dashboard.settings' }}">
|
|
<span class="ti ti-settings me-2"></span> Settings
|
|
</a>
|
|
<a href="{{ url_for('auth.logout') }}" class="sidebar-item">
|
|
<span class="ti ti-logout me-2"></span> Logout
|
|
</a>
|
|
</div>
|
|
</aside>
|
|
|
|
<!-- Main Content for authenticated users -->
|
|
<div class="main-content">
|
|
<!-- Top Navbar -->
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white border-bottom mb-4">
|
|
<div class="container-fluid">
|
|
<button class="sidebar-toggler btn btn-outline-secondary d-lg-none me-2">
|
|
<span class="ti ti-menu-2"></span>
|
|
</button>
|
|
|
|
<span class="navbar-brand d-none d-lg-block">
|
|
{{ title if title else 'Network Documentation' }}
|
|
</span>
|
|
|
|
<div class="d-flex align-items-center">
|
|
<div class="dropdown">
|
|
<a href="#" class="d-flex align-items-center text-decoration-none dropdown-toggle"
|
|
id="user-dropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
|
<span class="d-none d-md-inline me-2">{{ current_user.email }}</span>
|
|
<span class="ti ti-user"></span>
|
|
</a>
|
|
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="user-dropdown">
|
|
<li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="ms-auto me-3">
|
|
<button class="btn btn-icon" id="theme-toggle" aria-label="Toggle theme">
|
|
<span class="ti ti-moon theme-icon-light"></span>
|
|
<span class="ti ti-sun theme-icon-dark"></span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Flash Messages -->
|
|
<div class="container-fluid mt-3">
|
|
{% 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" aria-label="Close"></button>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endwith %}
|
|
</div>
|
|
{% else %}
|
|
<!-- Simple flash message container for non-authenticated users -->
|
|
<div class="container mt-3">
|
|
{% 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" aria-label="Close"></button>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endwith %}
|
|
</div>
|
|
{% endif %}
|
|
|
|
<!-- ONLY ONE CONTENT BLOCK FOR BOTH AUTHENTICATED AND NON-AUTHENTICATED STATES -->
|
|
<div class="{{ 'py-4' if current_user.is_authenticated else '' }}">
|
|
{% block content %}{% endblock %}
|
|
</div>
|
|
|
|
{% if current_user.is_authenticated %}
|
|
</div> <!-- End of main-content div that was opened for authenticated users -->
|
|
{% endif %}
|
|
|
|
<!-- Bootstrap JS -->
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
<!-- HTMX for dynamic content -->
|
|
<script src="https://unpkg.com/htmx.org@1.9.2"></script>
|
|
<!-- Custom JS -->
|
|
<script src="{{ url_for('static', filename='js/app.js') }}"></script>
|
|
<script>
|
|
// Sidebar toggle for mobile - using modern event listener approach
|
|
const sidebarToggler = document.querySelector('.sidebar-toggler');
|
|
if (sidebarToggler) {
|
|
sidebarToggler.addEventListener('click', () => {
|
|
document.querySelector('.sidebar').classList.toggle('show');
|
|
});
|
|
}
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Toggle sidebar submenus
|
|
document.querySelectorAll('.sidebar-item-parent > a').forEach(item => {
|
|
item.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
const parent = this.parentElement;
|
|
parent.classList.toggle('expanded');
|
|
|
|
// Load subnet data when IPAM is expanded
|
|
if (parent.classList.contains('expanded') && this.textContent.includes('IPAM')) {
|
|
loadSubnets();
|
|
}
|
|
});
|
|
});
|
|
|
|
function loadSubnets() {
|
|
const subnetContainer = document.getElementById('subnet-tree-container');
|
|
const loader = document.getElementById('subnet-loader');
|
|
|
|
if (!loader || !subnetContainer) return;
|
|
|
|
// Show loader
|
|
loader.classList.remove('d-none');
|
|
|
|
// Fetch subnets
|
|
fetch('/api/subnets')
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(subnets => {
|
|
loader.classList.add('d-none');
|
|
|
|
if (subnets.length === 0) {
|
|
subnetContainer.innerHTML = '<div class="text-muted px-3 py-2">No subnets found</div>';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
subnets.forEach(subnet => {
|
|
html += `
|
|
<div class="subnet-item-container">
|
|
<div class="subnet-item" data-subnet-id="${subnet.id}">
|
|
<span class="ti ti-chevron-right subnet-toggle-icon me-1"></span>
|
|
<a href="/ipam/subnet/${subnet.id}" class="text-reset text-decoration-none flex-grow-1">
|
|
${subnet.cidr} (${subnet.location})
|
|
</a>
|
|
</div>
|
|
<div class="subnet-servers d-none" id="subnet-servers-${subnet.id}">
|
|
<div class="text-muted px-3 py-2">Loading servers...</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
});
|
|
|
|
subnetContainer.innerHTML = html;
|
|
|
|
// Add click handlers to subnet items
|
|
document.querySelectorAll('.subnet-item').forEach(item => {
|
|
item.querySelector('.subnet-toggle-icon').addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
|
|
const subnetId = item.dataset.subnetId;
|
|
const serversContainer = document.getElementById(`subnet-servers-${subnetId}`);
|
|
serversContainer.classList.toggle('d-none');
|
|
|
|
if (!serversContainer.classList.contains('d-none') &&
|
|
serversContainer.querySelector('.text-muted')) {
|
|
loadServersForSubnet(subnetId);
|
|
}
|
|
|
|
// Toggle icon
|
|
this.classList.toggle('ti-chevron-right');
|
|
this.classList.toggle('ti-chevron-down');
|
|
});
|
|
});
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading subnets:', error);
|
|
loader.classList.add('d-none');
|
|
subnetContainer.innerHTML = '<div class="text-danger px-3 py-2">Error loading subnets</div>';
|
|
});
|
|
}
|
|
|
|
function loadServersForSubnet(subnetId) {
|
|
const serversContainer = document.getElementById(`subnet-servers-${subnetId}`);
|
|
|
|
// Fetch servers for this subnet
|
|
fetch(`/api/subnets/${subnetId}/servers`)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(servers => {
|
|
if (servers.length === 0) {
|
|
serversContainer.innerHTML = '<div class="text-muted px-3 py-2">No servers in this subnet</div>';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
servers.forEach(server => {
|
|
html += `
|
|
<a href="/dashboard/server/${server.id}" class="server-item d-block ps-4 py-1">
|
|
<span class="ti ti-server me-1 small"></span>
|
|
${server.hostname} (${server.ip_address})
|
|
</a>
|
|
`;
|
|
});
|
|
|
|
serversContainer.innerHTML = html;
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading servers:', error);
|
|
serversContainer.innerHTML = '<div class="text-danger px-3 py-2">Error loading servers</div>';
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
{% block scripts %}{% endblock %}
|
|
</body>
|
|
|
|
</html> |