Files
ip-manager/webapp/index.php
2026-01-16 20:56:25 +00:00

1871 lines
66 KiB
PHP

<?php require_once __DIR__ . '/config.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Geofeed Manager | Purple Computing</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
:root {
/* Purple Computing Brand Colors */
--purple-primary: #6B2D7B;
--purple-dark: #4A1F55;
--purple-light: #8B4D9B;
--purple-lighter: #F5EDF7;
--purple-gradient: linear-gradient(135deg, #6B2D7B 0%, #8B4D9B 100%);
/* UI Colors */
--bg-primary: #f8f9fa;
--bg-secondary: #ffffff;
--bg-tertiary: #f1f3f4;
--text-primary: #1a1a2e;
--text-secondary: #6c757d;
--text-tertiary: #868e96;
--border: rgba(0, 0, 0, 0.08);
--border-strong: rgba(0, 0, 0, 0.12);
/* Shadows */
--shadow-sm: 0 1px 3px rgba(107, 45, 123, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
--shadow-md: 0 4px 12px rgba(107, 45, 123, 0.1), 0 2px 4px rgba(0, 0, 0, 0.04);
--shadow-lg: 0 10px 40px rgba(107, 45, 123, 0.15), 0 4px 12px rgba(0, 0, 0, 0.05);
--shadow-xl: 0 25px 50px -12px rgba(107, 45, 123, 0.2);
/* Radii */
--radius-sm: 8px;
--radius-md: 12px;
--radius-lg: 16px;
--radius-xl: 20px;
/* Status Colors */
--success: #28a745;
--warning: #ffc107;
--error: #dc3545;
--info: #17a2b8;
/* Transitions */
--transition: all 0.2s ease;
--transition-slow: all 0.3s ease;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.5;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
min-height: 100vh;
}
/* Header */
.header {
background: var(--purple-gradient);
color: white;
position: sticky;
top: 0;
z-index: 100;
box-shadow: var(--shadow-md);
}
.header-content {
max-width: 1280px;
margin: 0 auto;
padding: 16px 24px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
}
.logo {
display: flex;
align-items: center;
gap: 14px;
}
.logo-icon {
width: 42px;
height: 42px;
background: rgba(255, 255, 255, 0.2);
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(10px);
}
.logo-icon svg {
width: 24px;
height: 24px;
}
.logo-text {
display: flex;
flex-direction: column;
}
.logo-title {
font-size: 18px;
font-weight: 600;
letter-spacing: -0.02em;
}
.logo-subtitle {
font-size: 11px;
opacity: 0.85;
font-weight: 500;
letter-spacing: 0.02em;
}
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
/* Buttons */
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 10px 20px;
font-size: 14px;
font-weight: 500;
border-radius: var(--radius-md);
border: none;
cursor: pointer;
transition: var(--transition);
text-decoration: none;
white-space: nowrap;
font-family: inherit;
}
.btn-primary {
background: var(--purple-primary);
color: white;
}
.btn-primary:hover {
background: var(--purple-dark);
transform: translateY(-1px);
box-shadow: var(--shadow-md);
}
.btn-secondary {
background: var(--bg-secondary);
color: var(--text-primary);
border: 1px solid var(--border-strong);
}
.btn-secondary:hover {
background: var(--bg-tertiary);
border-color: var(--purple-light);
}
.btn-white {
background: white;
color: var(--purple-primary);
}
.btn-white:hover {
background: var(--purple-lighter);
transform: translateY(-1px);
}
.btn-ghost {
background: transparent;
color: var(--purple-primary);
padding: 8px 16px;
}
.btn-ghost:hover {
background: var(--purple-lighter);
}
.btn-danger {
background: var(--error);
color: white;
}
.btn-danger:hover {
background: #c82333;
}
.btn-sm {
padding: 6px 14px;
font-size: 13px;
}
.btn-icon {
width: 36px;
height: 36px;
padding: 0;
border-radius: var(--radius-sm);
}
.btn:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none !important;
}
/* Main Content */
.main {
max-width: 1280px;
margin: 0 auto;
padding: 32px 24px;
}
/* Tabs */
.tabs {
display: flex;
gap: 4px;
background: var(--bg-secondary);
padding: 6px;
border-radius: var(--radius-lg);
margin-bottom: 24px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--border);
width: fit-content;
}
.tab {
padding: 10px 24px;
font-size: 14px;
font-weight: 500;
color: var(--text-secondary);
background: transparent;
border: none;
border-radius: var(--radius-md);
cursor: pointer;
transition: var(--transition);
display: flex;
align-items: center;
gap: 8px;
}
.tab:hover {
color: var(--text-primary);
background: var(--bg-tertiary);
}
.tab.active {
background: var(--purple-primary);
color: white;
box-shadow: var(--shadow-sm);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
/* Stats Cards */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
margin-bottom: 24px;
}
.stat-card {
background: var(--bg-secondary);
border-radius: var(--radius-lg);
padding: 20px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--border);
transition: var(--transition);
}
.stat-card:hover {
box-shadow: var(--shadow-md);
border-color: var(--purple-light);
}
.stat-label {
font-size: 12px;
color: var(--text-secondary);
text-transform: uppercase;
letter-spacing: 0.05em;
font-weight: 600;
margin-bottom: 8px;
}
.stat-value {
font-size: 28px;
font-weight: 700;
letter-spacing: -0.02em;
color: var(--purple-primary);
}
/* Search Bar */
.search-container {
margin-bottom: 24px;
}
.search-bar {
display: flex;
align-items: center;
gap: 12px;
background: var(--bg-secondary);
border: 2px solid var(--border);
border-radius: var(--radius-lg);
padding: 12px 20px;
transition: var(--transition);
}
.search-bar:focus-within {
border-color: var(--purple-primary);
box-shadow: 0 0 0 4px rgba(107, 45, 123, 0.1);
}
.search-icon {
color: var(--text-secondary);
flex-shrink: 0;
}
.search-input {
flex: 1;
border: none;
background: transparent;
font-size: 15px;
color: var(--text-primary);
outline: none;
font-family: inherit;
}
.search-input::placeholder {
color: var(--text-tertiary);
}
/* Table */
.table-container {
background: var(--bg-secondary);
border-radius: var(--radius-xl);
box-shadow: var(--shadow-md);
border: 1px solid var(--border);
overflow: hidden;
}
.table-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 20px 24px;
border-bottom: 1px solid var(--border);
background: var(--bg-tertiary);
}
.table-title {
font-size: 16px;
font-weight: 600;
color: var(--text-primary);
}
.table-actions {
display: flex;
gap: 8px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
text-align: left;
padding: 14px 20px;
}
th {
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--text-secondary);
background: var(--bg-tertiary);
border-bottom: 1px solid var(--border);
}
td {
font-size: 14px;
border-bottom: 1px solid var(--border);
vertical-align: middle;
}
tr:last-child td {
border-bottom: none;
}
tbody tr {
transition: var(--transition);
}
tbody tr:hover {
background: var(--purple-lighter);
}
.ip-prefix {
font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Monaco, monospace;
font-size: 13px;
font-weight: 600;
color: var(--purple-primary);
background: var(--purple-lighter);
padding: 4px 10px;
border-radius: 6px;
display: inline-block;
}
.country-badge {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 13px;
font-weight: 500;
}
.country-flag {
font-size: 16px;
}
.row-actions {
display: flex;
gap: 4px;
opacity: 0;
transition: var(--transition);
}
tr:hover .row-actions {
opacity: 1;
}
/* Pagination */
.pagination {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 20px;
border-top: 1px solid var(--border);
background: var(--bg-tertiary);
}
.pagination-btn {
width: 36px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
border: none;
background: var(--bg-secondary);
color: var(--text-secondary);
border-radius: var(--radius-sm);
cursor: pointer;
font-size: 14px;
font-weight: 500;
transition: var(--transition);
border: 1px solid var(--border);
}
.pagination-btn:hover:not(:disabled) {
background: var(--purple-lighter);
color: var(--purple-primary);
border-color: var(--purple-light);
}
.pagination-btn.active {
background: var(--purple-primary);
color: white;
border-color: var(--purple-primary);
}
.pagination-btn:disabled {
opacity: 0.3;
cursor: not-allowed;
}
.pagination-info {
color: var(--text-secondary);
font-size: 13px;
margin: 0 16px;
}
/* Modal */
.modal-overlay {
position: fixed;
inset: 0;
background: rgba(26, 26, 46, 0.6);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
display: flex;
align-items: center;
justify-content: center;
z-index: 1000;
opacity: 0;
visibility: hidden;
transition: var(--transition);
padding: 24px;
}
.modal-overlay.active {
opacity: 1;
visibility: visible;
}
.modal {
background: var(--bg-secondary);
border-radius: var(--radius-xl);
box-shadow: var(--shadow-xl);
width: 100%;
max-width: 520px;
max-height: 90vh;
overflow-y: auto;
transform: scale(0.95) translateY(20px);
transition: var(--transition-slow);
}
.modal-overlay.active .modal {
transform: scale(1) translateY(0);
}
.modal-header {
padding: 24px 24px 0;
}
.modal-title {
font-size: 22px;
font-weight: 700;
letter-spacing: -0.02em;
margin-bottom: 6px;
color: var(--purple-primary);
}
.modal-subtitle {
font-size: 14px;
color: var(--text-secondary);
}
.modal-body {
padding: 24px;
}
.modal-footer {
padding: 0 24px 24px;
display: flex;
justify-content: flex-end;
gap: 12px;
}
/* Form */
.form-group {
margin-bottom: 20px;
}
.form-label {
display: block;
font-size: 13px;
font-weight: 600;
color: var(--text-primary);
margin-bottom: 8px;
}
.form-label .required {
color: var(--error);
}
.form-input {
width: 100%;
padding: 12px 16px;
font-size: 15px;
border: 2px solid var(--border-strong);
border-radius: var(--radius-md);
background: var(--bg-tertiary);
color: var(--text-primary);
transition: var(--transition);
font-family: inherit;
}
.form-input:focus {
outline: none;
border-color: var(--purple-primary);
box-shadow: 0 0 0 4px rgba(107, 45, 123, 0.1);
background: var(--bg-secondary);
}
.form-input::placeholder {
color: var(--text-tertiary);
}
.form-hint {
font-size: 12px;
color: var(--text-secondary);
margin-top: 6px;
}
.form-error {
font-size: 12px;
color: var(--error);
margin-top: 6px;
}
.form-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 16px;
}
/* Advanced Tab Styles */
.advanced-section {
background: var(--bg-secondary);
border-radius: var(--radius-xl);
padding: 32px;
margin-bottom: 24px;
box-shadow: var(--shadow-sm);
border: 1px solid var(--border);
}
.advanced-section-title {
font-size: 18px;
font-weight: 700;
margin-bottom: 8px;
color: var(--purple-primary);
}
.advanced-section-desc {
font-size: 14px;
color: var(--text-secondary);
margin-bottom: 24px;
}
.import-options {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.import-card {
background: var(--bg-tertiary);
border: 2px solid var(--border);
border-radius: var(--radius-lg);
padding: 24px;
transition: var(--transition);
}
.import-card:hover {
border-color: var(--purple-light);
}
.import-card-icon {
width: 48px;
height: 48px;
background: var(--purple-lighter);
border-radius: var(--radius-md);
display: flex;
align-items: center;
justify-content: center;
color: var(--purple-primary);
margin-bottom: 16px;
}
.import-card-title {
font-size: 16px;
font-weight: 600;
margin-bottom: 8px;
}
.import-card-desc {
font-size: 13px;
color: var(--text-secondary);
margin-bottom: 16px;
}
.file-input-wrapper {
position: relative;
}
.file-input {
position: absolute;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.file-input-label {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
padding: 12px 20px;
background: var(--bg-secondary);
border: 2px dashed var(--border-strong);
border-radius: var(--radius-md);
cursor: pointer;
transition: var(--transition);
font-size: 14px;
color: var(--text-secondary);
}
.file-input-label:hover {
border-color: var(--purple-primary);
background: var(--purple-lighter);
color: var(--purple-primary);
}
.file-name {
font-size: 13px;
color: var(--purple-primary);
margin-top: 8px;
font-weight: 500;
}
/* Progress Bar */
.progress-container {
margin-top: 16px;
display: none;
}
.progress-container.active {
display: block;
}
.progress-bar {
height: 8px;
background: var(--bg-tertiary);
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: var(--purple-gradient);
border-radius: 4px;
transition: width 0.3s ease;
width: 0%;
}
.progress-text {
font-size: 13px;
color: var(--text-secondary);
margin-top: 8px;
text-align: center;
}
/* Import Results */
.import-results {
margin-top: 20px;
padding: 16px;
border-radius: var(--radius-md);
display: none;
}
.import-results.active {
display: block;
}
.import-results.success {
background: rgba(40, 167, 69, 0.1);
border: 1px solid rgba(40, 167, 69, 0.3);
}
.import-results.error {
background: rgba(220, 53, 69, 0.1);
border: 1px solid rgba(220, 53, 69, 0.3);
}
.import-results-title {
font-weight: 600;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.import-results.success .import-results-title {
color: var(--success);
}
.import-results.error .import-results-title {
color: var(--error);
}
.import-results-text {
font-size: 14px;
color: var(--text-secondary);
}
/* Toast */
.toast-container {
position: fixed;
top: 24px;
right: 24px;
z-index: 2000;
display: flex;
flex-direction: column;
gap: 12px;
}
.toast {
background: var(--bg-secondary);
border-radius: var(--radius-md);
padding: 16px 20px;
box-shadow: var(--shadow-lg);
border: 1px solid var(--border);
display: flex;
align-items: center;
gap: 12px;
min-width: 320px;
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(100%);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.toast-icon {
width: 28px;
height: 28px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.toast.success .toast-icon {
background: rgba(40, 167, 69, 0.15);
color: var(--success);
}
.toast.error .toast-icon {
background: rgba(220, 53, 69, 0.15);
color: var(--error);
}
.toast-message {
flex: 1;
font-size: 14px;
font-weight: 500;
}
.toast-close {
background: none;
border: none;
cursor: pointer;
color: var(--text-secondary);
padding: 4px;
transition: var(--transition);
}
.toast-close:hover {
color: var(--text-primary);
}
/* Empty State */
.empty-state {
text-align: center;
padding: 60px 24px;
}
.empty-icon {
width: 72px;
height: 72px;
background: var(--purple-lighter);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin: 0 auto 24px;
color: var(--purple-primary);
}
.empty-title {
font-size: 18px;
font-weight: 600;
margin-bottom: 8px;
}
.empty-text {
font-size: 14px;
color: var(--text-secondary);
max-width: 400px;
margin: 0 auto 24px;
}
/* Loading */
.loading {
display: flex;
align-items: center;
justify-content: center;
padding: 60px;
}
.spinner {
width: 36px;
height: 36px;
border: 3px solid var(--purple-lighter);
border-top-color: var(--purple-primary);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
/* Confirm Delete */
.confirm-delete-text {
font-size: 15px;
line-height: 1.6;
color: var(--text-primary);
}
.confirm-delete-prefix {
font-family: 'SF Mono', monospace;
background: rgba(220, 53, 69, 0.1);
padding: 2px 8px;
border-radius: 4px;
color: var(--error);
font-weight: 600;
}
/* Responsive */
@media (max-width: 768px) {
.header-content {
flex-wrap: wrap;
}
.form-row {
grid-template-columns: 1fr;
}
.stats-grid {
grid-template-columns: repeat(2, 1fr);
}
table {
font-size: 13px;
}
th, td {
padding: 12px;
}
.modal {
margin: 16px;
max-width: none;
}
.tabs {
width: 100%;
}
.tab {
flex: 1;
justify-content: center;
}
.import-options {
grid-template-columns: 1fr;
}
}
/* Footer */
.footer {
text-align: center;
padding: 24px;
color: var(--text-secondary);
font-size: 13px;
}
.footer a {
color: var(--purple-primary);
text-decoration: none;
}
.footer a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<header class="header">
<div class="header-content">
<div class="logo">
<div class="logo-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="2" y1="12" x2="22" y2="12"/>
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>
</svg>
</div>
<div class="logo-text">
<span class="logo-title">Geofeed Manager</span>
<span class="logo-subtitle">PURPLE COMPUTING</span>
</div>
</div>
<div class="header-actions">
<button class="btn btn-white" onclick="exportCSV()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="7 10 12 15 17 10"/>
<line x1="12" y1="15" x2="12" y2="3"/>
</svg>
Export CSV
</button>
<button class="btn btn-white" onclick="openModal()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="12" y1="5" x2="12" y2="19"/>
<line x1="5" y1="12" x2="19" y2="12"/>
</svg>
Add Entry
</button>
</div>
</div>
</header>
<main class="main">
<!-- Tabs -->
<div class="tabs">
<button class="tab active" onclick="switchTab('entries')">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
</svg>
Entries
</button>
<button class="tab" onclick="switchTab('advanced')">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
</svg>
Advanced
</button>
</div>
<!-- Entries Tab -->
<div class="tab-content active" id="tab-entries">
<!-- Stats -->
<div class="stats-grid" id="statsGrid">
<div class="stat-card">
<div class="stat-label">Total Entries</div>
<div class="stat-value" id="statTotal">-</div>
</div>
<div class="stat-card">
<div class="stat-label">IPv4 Prefixes</div>
<div class="stat-value" id="statIPv4">-</div>
</div>
<div class="stat-card">
<div class="stat-label">IPv6 Prefixes</div>
<div class="stat-value" id="statIPv6">-</div>
</div>
<div class="stat-card">
<div class="stat-label">Countries</div>
<div class="stat-value" id="statCountries">-</div>
</div>
</div>
<!-- Search -->
<div class="search-container">
<div class="search-bar">
<svg class="search-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"/>
<line x1="21" y1="21" x2="16.65" y2="16.65"/>
</svg>
<input type="text" class="search-input" id="searchInput" placeholder="Search IP prefixes, cities, regions..." oninput="debounceSearch()">
</div>
</div>
<!-- Table -->
<div class="table-container">
<div class="table-header">
<h2 class="table-title">Geofeed Entries</h2>
<div class="table-actions">
<button class="btn btn-ghost btn-sm" onclick="loadEntries()">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"/>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
</svg>
Refresh
</button>
</div>
</div>
<div id="tableContent">
<div class="loading">
<div class="spinner"></div>
</div>
</div>
</div>
</div>
<!-- Advanced Tab -->
<div class="tab-content" id="tab-advanced">
<div class="advanced-section">
<h2 class="advanced-section-title">Import Geofeed Data</h2>
<p class="advanced-section-desc">Import geofeed entries from a CSV file or a remote URL. The data should follow RFC 8805 format: <code>ip_prefix,country_code,region_code,city,postal_code</code></p>
<div class="import-options">
<!-- File Upload -->
<div class="import-card">
<div class="import-card-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
</div>
<h3 class="import-card-title">Upload CSV File</h3>
<p class="import-card-desc">Upload a geofeed CSV file from your computer</p>
<div class="file-input-wrapper">
<input type="file" class="file-input" id="csvFileInput" accept=".csv,.txt" onchange="handleFileSelect(this)">
<label class="file-input-label" for="csvFileInput">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
<polyline points="17 8 12 3 7 8"/>
<line x1="12" y1="3" x2="12" y2="15"/>
</svg>
Choose file or drag here
</label>
</div>
<div class="file-name" id="fileName"></div>
<div class="progress-container" id="fileProgress">
<div class="progress-bar">
<div class="progress-fill" id="fileProgressFill"></div>
</div>
<div class="progress-text" id="fileProgressText">Processing...</div>
</div>
<button class="btn btn-primary" style="width: 100%; margin-top: 16px;" id="uploadBtn" onclick="importFromFile()" disabled>
Import from File
</button>
<div class="import-results" id="fileResults">
<div class="import-results-title">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
Import Complete
</div>
<div class="import-results-text" id="fileResultsText"></div>
</div>
</div>
<!-- URL Import -->
<div class="import-card">
<div class="import-card-icon">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="2" y1="12" x2="22" y2="12"/>
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>
</svg>
</div>
<h3 class="import-card-title">Import from URL</h3>
<p class="import-card-desc">Fetch and import a geofeed from a remote URL</p>
<div class="form-group" style="margin-bottom: 0;">
<input type="url" class="form-input" id="importUrl" placeholder="https://example.com/geofeed.csv" value="https://store.prpl.uk/geofeed.csv">
</div>
<div class="progress-container" id="urlProgress">
<div class="progress-bar">
<div class="progress-fill" id="urlProgressFill"></div>
</div>
<div class="progress-text" id="urlProgressText">Fetching...</div>
</div>
<button class="btn btn-primary" style="width: 100%; margin-top: 16px;" id="urlImportBtn" onclick="importFromUrl()">
Import from URL
</button>
<div class="import-results" id="urlResults">
<div class="import-results-title">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="20 6 9 17 4 12"/>
</svg>
Import Complete
</div>
<div class="import-results-text" id="urlResultsText"></div>
</div>
</div>
</div>
</div>
<div class="advanced-section">
<h2 class="advanced-section-title">Danger Zone</h2>
<p class="advanced-section-desc">Irreversible actions - please proceed with caution.</p>
<button class="btn btn-danger" onclick="confirmClearAll()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
</svg>
Clear All Entries
</button>
</div>
</div>
</main>
<footer class="footer">
<p>Geofeed Manager &copy; 2025 <a href="https://purplecomputing.com" target="_blank">Purple Computing</a> &middot; RFC 8805 Compliant</p>
</footer>
<!-- Add/Edit Modal -->
<div class="modal-overlay" id="entryModal">
<div class="modal">
<div class="modal-header">
<h2 class="modal-title" id="modalTitle">Add Entry</h2>
<p class="modal-subtitle">Enter the geofeed entry details below</p>
</div>
<form id="entryForm" onsubmit="saveEntry(event)">
<input type="hidden" id="entryId" name="id">
<div class="modal-body">
<div class="form-group">
<label class="form-label">IP Prefix <span class="required">*</span></label>
<input type="text" class="form-input" id="ipPrefix" name="ip_prefix" placeholder="e.g., 192.168.1.0/24 or 2001:db8::/32" required>
<div class="form-hint">IPv4 or IPv6 address in CIDR notation</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">Country Code</label>
<input type="text" class="form-input" id="countryCode" name="country_code" placeholder="e.g., GB" maxlength="2" style="text-transform: uppercase;">
<div class="form-hint">ISO 3166-1 alpha-2 code</div>
</div>
<div class="form-group">
<label class="form-label">Region Code</label>
<input type="text" class="form-input" id="regionCode" name="region_code" placeholder="e.g., GB-ENG" style="text-transform: uppercase;">
<div class="form-hint">ISO 3166-2 code</div>
</div>
</div>
<div class="form-row">
<div class="form-group">
<label class="form-label">City</label>
<input type="text" class="form-input" id="city" name="city" placeholder="e.g., London">
</div>
<div class="form-group">
<label class="form-label">Postal Code</label>
<input type="text" class="form-input" id="postalCode" name="postal_code" placeholder="e.g., EC1A 1BB">
</div>
</div>
<div class="form-group">
<label class="form-label">Notes</label>
<input type="text" class="form-input" id="notes" name="notes" placeholder="Optional notes for internal use">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeModal()">Cancel</button>
<button type="submit" class="btn btn-primary" id="saveBtn">Save Entry</button>
</div>
</form>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div class="modal-overlay" id="deleteModal">
<div class="modal" style="max-width: 420px;">
<div class="modal-header">
<h2 class="modal-title">Delete Entry</h2>
</div>
<div class="modal-body">
<p class="confirm-delete-text">
Are you sure you want to delete the entry for <span class="confirm-delete-prefix" id="deletePrefix"></span>? This action cannot be undone.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeDeleteModal()">Cancel</button>
<button type="button" class="btn btn-danger" onclick="confirmDelete()">Delete</button>
</div>
</div>
</div>
<!-- Clear All Confirmation Modal -->
<div class="modal-overlay" id="clearAllModal">
<div class="modal" style="max-width: 420px;">
<div class="modal-header">
<h2 class="modal-title">Clear All Entries</h2>
</div>
<div class="modal-body">
<p class="confirm-delete-text">
Are you sure you want to delete <strong>ALL</strong> geofeed entries? This action cannot be undone.
</p>
<div class="form-group" style="margin-top: 16px; margin-bottom: 0;">
<label class="form-label">Type "DELETE" to confirm</label>
<input type="text" class="form-input" id="confirmClearInput" placeholder="DELETE">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" onclick="closeClearAllModal()">Cancel</button>
<button type="button" class="btn btn-danger" id="confirmClearBtn" onclick="executeClearAll()" disabled>Clear All</button>
</div>
</div>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script>
// State
let currentPage = 1;
let totalPages = 1;
let searchTimeout = null;
let deleteEntryId = null;
let selectedFile = null;
const csrfToken = '<?php echo generateCSRFToken(); ?>';
// Initialize
document.addEventListener('DOMContentLoaded', () => {
loadEntries();
loadStats();
// Enable clear all button when "DELETE" is typed
document.getElementById('confirmClearInput').addEventListener('input', (e) => {
document.getElementById('confirmClearBtn').disabled = e.target.value !== 'DELETE';
});
});
// Tab switching
function switchTab(tab) {
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
document.querySelector(`.tab[onclick="switchTab('${tab}')"]`).classList.add('active');
document.getElementById(`tab-${tab}`).classList.add('active');
}
// API Helper
async function api(action, params = {}, method = 'GET', body = null) {
const url = new URL('api.php', window.location.href);
url.searchParams.set('action', action);
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
const options = { method };
if (body) {
options.headers = { 'Content-Type': 'application/json' };
options.body = JSON.stringify({ ...body, csrf_token: csrfToken });
}
const response = await fetch(url, options);
return response.json();
}
// Load entries
async function loadEntries(page = 1) {
currentPage = page;
const searchQuery = document.getElementById('searchInput').value;
document.getElementById('tableContent').innerHTML = '<div class="loading"><div class="spinner"></div></div>';
try {
const result = await api('list', { page, search: searchQuery });
if (result.success) {
renderTable(result.data, result.pagination);
} else {
showToast(result.error || 'Failed to load entries', 'error');
}
} catch (error) {
showToast('Network error', 'error');
}
}
// Render table
function renderTable(entries, pagination) {
totalPages = pagination.pages;
if (entries.length === 0) {
document.getElementById('tableContent').innerHTML = `
<div class="empty-state">
<div class="empty-icon">
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<line x1="2" y1="12" x2="22" y2="12"/>
<path d="M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"/>
</svg>
</div>
<h3 class="empty-title">No entries found</h3>
<p class="empty-text">Get started by adding your first geofeed entry or import from the Advanced tab.</p>
<button class="btn btn-primary" onclick="openModal()">Add Entry</button>
</div>
`;
return;
}
const tableHTML = `
<table>
<thead>
<tr>
<th>IP Prefix</th>
<th>Country</th>
<th>Region</th>
<th>City</th>
<th>Postal</th>
<th style="width: 100px;">Actions</th>
</tr>
</thead>
<tbody>
${entries.map(entry => `
<tr>
<td><span class="ip-prefix">${escapeHtml(entry.ip_prefix)}</span></td>
<td>
${entry.country_code ? `
<span class="country-badge">
<span class="country-flag">${getFlagEmoji(entry.country_code)}</span>
${escapeHtml(entry.country_code)}
</span>
` : '<span style="color: var(--text-tertiary)">—</span>'}
</td>
<td>${entry.region_code ? escapeHtml(entry.region_code) : '<span style="color: var(--text-tertiary)">—</span>'}</td>
<td>${entry.city ? escapeHtml(entry.city) : '<span style="color: var(--text-tertiary)">—</span>'}</td>
<td>${entry.postal_code ? escapeHtml(entry.postal_code) : '<span style="color: var(--text-tertiary)">—</span>'}</td>
<td>
<div class="row-actions">
<button class="btn btn-ghost btn-icon" onclick="editEntry(${entry.id})" title="Edit">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</button>
<button class="btn btn-ghost btn-icon" onclick="deleteEntry(${entry.id}, '${escapeHtml(entry.ip_prefix)}')" title="Delete" style="color: var(--error);">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="3 6 5 6 21 6"/>
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>
</svg>
</button>
</div>
</td>
</tr>
`).join('')}
</tbody>
</table>
<div class="pagination">
<button class="pagination-btn" onclick="loadEntries(1)" ${currentPage === 1 ? 'disabled' : ''}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="11 17 6 12 11 7"/>
<polyline points="18 17 13 12 18 7"/>
</svg>
</button>
<button class="pagination-btn" onclick="loadEntries(${currentPage - 1})" ${currentPage === 1 ? 'disabled' : ''}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="15 18 9 12 15 6"/>
</svg>
</button>
<span class="pagination-info">Page ${currentPage} of ${totalPages || 1} (${pagination.total} entries)</span>
<button class="pagination-btn" onclick="loadEntries(${currentPage + 1})" ${currentPage >= totalPages ? 'disabled' : ''}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="9 18 15 12 9 6"/>
</svg>
</button>
<button class="pagination-btn" onclick="loadEntries(${totalPages})" ${currentPage >= totalPages ? 'disabled' : ''}>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="13 17 18 12 13 7"/>
<polyline points="6 17 11 12 6 7"/>
</svg>
</button>
</div>
`;
document.getElementById('tableContent').innerHTML = tableHTML;
}
// Load stats
async function loadStats() {
try {
const result = await api('stats');
if (result.success) {
document.getElementById('statTotal').textContent = result.data.total_entries.toLocaleString();
document.getElementById('statIPv4').textContent = (result.data.ip_versions?.ipv4 || 0).toLocaleString();
document.getElementById('statIPv6').textContent = (result.data.ip_versions?.ipv6 || 0).toLocaleString();
document.getElementById('statCountries').textContent = result.data.by_country?.length || 0;
}
} catch (error) {
console.error('Failed to load stats:', error);
}
}
// Search with debounce
function debounceSearch() {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => loadEntries(1), 300);
}
// Modal functions
function openModal(entry = null) {
const modal = document.getElementById('entryModal');
const form = document.getElementById('entryForm');
const title = document.getElementById('modalTitle');
form.reset();
if (entry) {
title.textContent = 'Edit Entry';
document.getElementById('entryId').value = entry.id;
document.getElementById('ipPrefix').value = entry.ip_prefix || '';
document.getElementById('countryCode').value = entry.country_code || '';
document.getElementById('regionCode').value = entry.region_code || '';
document.getElementById('city').value = entry.city || '';
document.getElementById('postalCode').value = entry.postal_code || '';
document.getElementById('notes').value = entry.notes || '';
} else {
title.textContent = 'Add Entry';
document.getElementById('entryId').value = '';
}
modal.classList.add('active');
document.getElementById('ipPrefix').focus();
}
function closeModal() {
document.getElementById('entryModal').classList.remove('active');
}
// Edit entry
async function editEntry(id) {
try {
const result = await api('get', { id });
if (result.success) {
openModal(result.data);
} else {
showToast(result.error || 'Failed to load entry', 'error');
}
} catch (error) {
showToast('Network error', 'error');
}
}
// Save entry
async function saveEntry(event) {
event.preventDefault();
const id = document.getElementById('entryId').value;
const action = id ? 'update' : 'create';
const data = {
id: id || undefined,
ip_prefix: document.getElementById('ipPrefix').value,
country_code: document.getElementById('countryCode').value.toUpperCase(),
region_code: document.getElementById('regionCode').value.toUpperCase(),
city: document.getElementById('city').value,
postal_code: document.getElementById('postalCode').value,
notes: document.getElementById('notes').value
};
try {
const result = await api(action, {}, 'POST', data);
if (result.success) {
showToast(result.message || 'Entry saved successfully', 'success');
closeModal();
loadEntries(currentPage);
loadStats();
} else {
showToast(result.error || 'Failed to save entry', 'error');
}
} catch (error) {
showToast('Network error', 'error');
}
}
// Delete entry
function deleteEntry(id, prefix) {
deleteEntryId = id;
document.getElementById('deletePrefix').textContent = prefix;
document.getElementById('deleteModal').classList.add('active');
}
function closeDeleteModal() {
document.getElementById('deleteModal').classList.remove('active');
deleteEntryId = null;
}
async function confirmDelete() {
if (!deleteEntryId) return;
try {
const result = await api('delete', {}, 'POST', { id: deleteEntryId });
if (result.success) {
showToast('Entry deleted successfully', 'success');
closeDeleteModal();
loadEntries(currentPage);
loadStats();
} else {
showToast(result.error || 'Failed to delete entry', 'error');
}
} catch (error) {
showToast('Network error', 'error');
}
}
// Export CSV
function exportCSV() {
window.location.href = 'api.php?action=export&format=download';
}
// File handling
function handleFileSelect(input) {
if (input.files && input.files[0]) {
selectedFile = input.files[0];
document.getElementById('fileName').textContent = selectedFile.name;
document.getElementById('uploadBtn').disabled = false;
// Reset results
document.getElementById('fileResults').classList.remove('active', 'success', 'error');
}
}
// Import from file
async function importFromFile() {
if (!selectedFile) return;
const btn = document.getElementById('uploadBtn');
const progress = document.getElementById('fileProgress');
const progressFill = document.getElementById('fileProgressFill');
const progressText = document.getElementById('fileProgressText');
const results = document.getElementById('fileResults');
btn.disabled = true;
progress.classList.add('active');
results.classList.remove('active', 'success', 'error');
try {
progressText.textContent = 'Reading file...';
progressFill.style.width = '20%';
const text = await selectedFile.text();
progressText.textContent = 'Parsing CSV...';
progressFill.style.width = '40%';
const entries = parseCSV(text);
progressText.textContent = `Importing ${entries.length} entries...`;
progressFill.style.width = '60%';
const result = await api('import', {}, 'POST', { entries, csrf_token: csrfToken });
progressFill.style.width = '100%';
if (result.success) {
results.classList.add('active', 'success');
document.getElementById('fileResultsText').textContent =
`Successfully imported ${result.inserted} new entries, updated ${result.updated} existing entries.`;
showToast('Import completed successfully', 'success');
loadEntries();
loadStats();
} else {
results.classList.add('active', 'error');
document.getElementById('fileResultsText').textContent = result.error || 'Import failed';
showToast(result.error || 'Import failed', 'error');
}
} catch (error) {
results.classList.add('active', 'error');
document.getElementById('fileResultsText').textContent = error.message;
showToast('Import failed: ' + error.message, 'error');
} finally {
btn.disabled = false;
setTimeout(() => {
progress.classList.remove('active');
progressFill.style.width = '0%';
}, 1000);
}
}
// Import from URL
async function importFromUrl() {
const url = document.getElementById('importUrl').value.trim();
if (!url) {
showToast('Please enter a URL', 'error');
return;
}
const btn = document.getElementById('urlImportBtn');
const progress = document.getElementById('urlProgress');
const progressFill = document.getElementById('urlProgressFill');
const progressText = document.getElementById('urlProgressText');
const results = document.getElementById('urlResults');
btn.disabled = true;
progress.classList.add('active');
results.classList.remove('active', 'success', 'error');
try {
progressText.textContent = 'Fetching data...';
progressFill.style.width = '30%';
const result = await api('import_url', {}, 'POST', { url, csrf_token: csrfToken });
progressFill.style.width = '100%';
if (result.success) {
results.classList.add('active', 'success');
document.getElementById('urlResultsText').textContent =
`Successfully imported ${result.inserted} new entries, updated ${result.updated} existing entries.`;
showToast('Import completed successfully', 'success');
loadEntries();
loadStats();
} else {
results.classList.add('active', 'error');
document.getElementById('urlResultsText').textContent = result.error || 'Import failed';
showToast(result.error || 'Import failed', 'error');
}
} catch (error) {
results.classList.add('active', 'error');
document.getElementById('urlResultsText').textContent = error.message;
showToast('Import failed: ' + error.message, 'error');
} finally {
btn.disabled = false;
setTimeout(() => {
progress.classList.remove('active');
progressFill.style.width = '0%';
}, 1000);
}
}
// Parse CSV
function parseCSV(text) {
const lines = text.split(/\r?\n/);
const entries = [];
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const parts = trimmed.split(',');
if (parts.length < 1 || !parts[0].trim()) continue;
entries.push({
ip_prefix: parts[0]?.trim() || '',
country_code: parts[1]?.trim().toUpperCase() || '',
region_code: parts[2]?.trim().toUpperCase() || '',
city: parts[3]?.trim() || '',
postal_code: parts[4]?.trim() || ''
});
}
return entries;
}
// Clear all
function confirmClearAll() {
document.getElementById('confirmClearInput').value = '';
document.getElementById('confirmClearBtn').disabled = true;
document.getElementById('clearAllModal').classList.add('active');
}
function closeClearAllModal() {
document.getElementById('clearAllModal').classList.remove('active');
}
async function executeClearAll() {
if (document.getElementById('confirmClearInput').value !== 'DELETE') return;
try {
const result = await api('clear_all', {}, 'POST', { csrf_token: csrfToken });
if (result.success) {
showToast('All entries cleared successfully', 'success');
closeClearAllModal();
loadEntries();
loadStats();
} else {
showToast(result.error || 'Failed to clear entries', 'error');
}
} catch (error) {
showToast('Network error', 'error');
}
}
// Toast notifications
function showToast(message, type = 'success') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
const icon = type === 'success'
? '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"/></svg>'
: '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>';
toast.innerHTML = `
<div class="toast-icon">${icon}</div>
<span class="toast-message">${escapeHtml(message)}</span>
<button class="toast-close" onclick="this.parentElement.remove()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<line x1="18" y1="6" x2="6" y2="18"/>
<line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
`;
container.appendChild(toast);
setTimeout(() => {
toast.style.animation = 'slideIn 0.3s ease reverse';
setTimeout(() => toast.remove(), 300);
}, 4000);
}
// Helpers
function escapeHtml(text) {
if (!text) return '';
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
function getFlagEmoji(countryCode) {
if (!countryCode || countryCode.length !== 2) return '';
const codePoints = countryCode
.toUpperCase()
.split('')
.map(char => 127397 + char.charCodeAt());
return String.fromCodePoint(...codePoints);
}
// Close modals on escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeModal();
closeDeleteModal();
closeClearAllModal();
}
});
// Close modals on overlay click
document.querySelectorAll('.modal-overlay').forEach(overlay => {
overlay.addEventListener('click', (e) => {
if (e.target === overlay) {
closeModal();
closeDeleteModal();
closeClearAllModal();
}
});
});
</script>
</body>
</html>