From 897c82ab88fda02e17d9ffb27b764033d4683f67 Mon Sep 17 00:00:00 2001 From: ayurishchev Date: Wed, 7 Oct 2026 13:10:41 +0300 Subject: [PATCH] UI review, stage 3: cleanup, shared chart code, confirmations, routing useTrafficChart composable replaces the duplicated chart code in Analytics and HistoryModal; theme observer is released on unmount; blob URLs are revoked. ConfirmModal gets a unique id; confirm() in Server/PKI and SweetAlert2 in Account are replaced by ConfirmModal and toasts, sweetalert2 and sass removed. Separate authApiClient for /api/auth. 404 redirect, lazy Clients, token-based isAuthenticated, theme from prefers-color-scheme set before mount. BaseModal reactive size, NewClientModal name check and focus on opened, HistoryModal ignores stale answers. Login.vue.bak, the dead global axios interceptor and empty

removed. Co-Authored-By: Claude Sonnet 5.5 --- APP_UI/package-lock.json | 76 +++++-- APP_UI/package.json | 2 - APP_UI/src/App.vue | 33 +-- APP_UI/src/assets/main.css | 5 + APP_UI/src/components/BaseModal.vue | 7 +- APP_UI/src/components/ConfirmModal.vue | 6 +- APP_UI/src/components/HistoryModal.vue | 164 +++----------- APP_UI/src/components/NewClientModal.vue | 21 +- APP_UI/src/composables/useApi.js | 25 ++- APP_UI/src/composables/useApi.test.js | 11 +- APP_UI/src/composables/useTheme.js | 43 ++++ APP_UI/src/composables/useTrafficChart.js | 133 ++++++++++++ APP_UI/src/main.js | 19 +- APP_UI/src/router/index.js | 8 +- APP_UI/src/views/Account.vue | 111 ++-------- APP_UI/src/views/Analytics.vue | 164 +++----------- APP_UI/src/views/Certificates.vue | 2 + APP_UI/src/views/Clients.vue | 2 +- APP_UI/src/views/Login.vue | 8 +- APP_UI/src/views/Login.vue.bak | 251 ---------------------- APP_UI/src/views/PKIConfig.vue | 29 ++- APP_UI/src/views/ServerManagement.vue | 18 +- APP_UI/vite.config.js | 2 +- 23 files changed, 430 insertions(+), 710 deletions(-) create mode 100644 APP_UI/src/composables/useTheme.js create mode 100644 APP_UI/src/composables/useTrafficChart.js delete mode 100644 APP_UI/src/views/Login.vue.bak diff --git a/APP_UI/package-lock.json b/APP_UI/package-lock.json index 7bcd138..93e886c 100644 --- a/APP_UI/package-lock.json +++ b/APP_UI/package-lock.json @@ -13,8 +13,6 @@ "bootstrap": "^5.3.8", "chart.js": "^4.5.1", "qrcode.vue": "^3.6.0", - "sass": "^1.97.2", - "sweetalert2": "^11.26.17", "vue": "^3.5.24", "vue-router": "^4.6.4" }, @@ -537,9 +535,11 @@ "version": "2.5.1", "resolved": "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.5.1.tgz", "integrity": "sha512-dfUnCxiN9H4ap84DvD2ubjw+3vUNpstxa0TneY/Paat8a3R4uQZDLSvWjmznAY/DoahqTHl9V46HF/Zs3F29pg==", + "dev": true, "hasInstallScript": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "detect-libc": "^1.0.3", "is-glob": "^4.0.3", @@ -576,11 +576,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "android" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -596,11 +598,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -616,11 +620,13 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "darwin" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -636,11 +642,13 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "freebsd" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -656,11 +664,13 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -676,11 +686,13 @@ "cpu": [ "arm" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -696,11 +708,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -716,11 +730,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -736,11 +752,13 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -756,11 +774,13 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "linux" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -776,11 +796,13 @@ "cpu": [ "arm64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -796,11 +818,13 @@ "cpu": [ "ia32" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -816,11 +840,13 @@ "cpu": [ "x64" ], + "dev": true, "license": "MIT", "optional": true, "os": [ "win32" ], + "peer": true, "engines": { "node": ">= 10.0.0" }, @@ -1520,8 +1546,10 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "fill-range": "^7.1.1" }, @@ -1595,7 +1623,10 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz", "integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==", + "dev": true, "license": "MIT", + "optional": true, + "peer": true, "dependencies": { "readdirp": "^4.0.1" }, @@ -1665,8 +1696,10 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "integrity": "sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg==", + "dev": true, "license": "Apache-2.0", "optional": true, + "peer": true, "bin": { "detect-libc": "bin/detect-libc.js" }, @@ -1832,8 +1865,10 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "to-regex-range": "^5.0.1" }, @@ -1993,14 +2028,19 @@ "version": "5.1.4", "resolved": "https://registry.npmjs.org/immutable/-/immutable-5.1.4.tgz", "integrity": "sha512-p6u1bG3YSnINT5RQmx/yRZBpenIl30kVxkTLDyHLIMk0gict704Q9n+thfDI7lTRm9vXdDYutVzXhzcThxTnXA==", - "license": "MIT" + "dev": true, + "license": "MIT", + "optional": true, + "peer": true }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=0.10.0" } @@ -2009,8 +2049,10 @@ "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "is-extglob": "^2.1.1" }, @@ -2022,8 +2064,10 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=0.12.0" } @@ -2064,8 +2108,10 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" @@ -2078,8 +2124,10 @@ "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=8.6" }, @@ -2137,8 +2185,10 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-7.1.1.tgz", "integrity": "sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==", + "dev": true, "license": "MIT", - "optional": true + "optional": true, + "peer": true }, "node_modules/pathe": { "version": "2.0.3", @@ -2223,7 +2273,10 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz", "integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==", + "dev": true, "license": "MIT", + "optional": true, + "peer": true, "engines": { "node": ">= 14.18.0" }, @@ -2281,7 +2334,10 @@ "version": "1.97.2", "resolved": "https://registry.npmjs.org/sass/-/sass-1.97.2.tgz", "integrity": "sha512-y5LWb0IlbO4e97Zr7c3mlpabcbBtS+ieiZ9iwDooShpFKWXf62zz5pEPdwrLYm+Bxn1fnbwFGzHuCLSA9tBmrw==", + "dev": true, "license": "MIT", + "optional": true, + "peer": true, "dependencies": { "chokidar": "^4.0.0", "immutable": "^5.0.2", @@ -2340,16 +2396,6 @@ "url": "https://github.com/sponsors/antfu" } }, - "node_modules/sweetalert2": { - "version": "11.26.17", - "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.26.17.tgz", - "integrity": "sha512-kkaySn1IRfwNlf9AkZVqDmBINDWw9NRR6Ij0O5dBRBOD1+mbtZJWxxR9/pA90nce9E5tIIkJ7SWij4rMWXtA1g==", - "license": "MIT", - "funding": { - "type": "individual", - "url": "https://github.com/sponsors/limonte" - } - }, "node_modules/tinybench": { "version": "2.9.0", "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", @@ -2415,8 +2461,10 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, "license": "MIT", "optional": true, + "peer": true, "dependencies": { "is-number": "^7.0.0" }, diff --git a/APP_UI/package.json b/APP_UI/package.json index 5b95f2c..12350b3 100644 --- a/APP_UI/package.json +++ b/APP_UI/package.json @@ -15,8 +15,6 @@ "bootstrap": "^5.3.8", "chart.js": "^4.5.1", "qrcode.vue": "^3.6.0", - "sass": "^1.97.2", - "sweetalert2": "^11.26.17", "vue": "^3.5.24", "vue-router": "^4.6.4" }, diff --git a/APP_UI/src/App.vue b/APP_UI/src/App.vue index 9dfe7d2..337970e 100644 --- a/APP_UI/src/App.vue +++ b/APP_UI/src/App.vue @@ -24,7 +24,6 @@

-

Analytics @@ -34,7 +33,6 @@ -

PKI @@ -48,7 +46,6 @@ -

Certificates @@ -61,7 +58,6 @@ -

Account Settings @@ -96,10 +92,10 @@ {{ timezoneAbbr }}
@@ -138,11 +134,12 @@ import { useRoute, useRouter } from 'vue-router'; import ToastContainer from './components/ToastContainer.vue'; import { usePkiStatus } from './composables/usePkiStatus'; import { useToast } from './composables/useToast'; +import { useTheme } from './composables/useTheme'; const { loadConfig, isLoaded } = useAppConfig(); const { apiClient } = useApi(); const timezoneAbbr = ref(new Date().toLocaleTimeString('en-us',{timeZoneName:'short'}).split(' ')[2] || 'UTC'); -const isDark = ref(false); +const { isDark, toggleTheme } = useTheme(); const refreshKey = ref(0); const isSidebarOpen = ref(false); const isCompact = ref(false); @@ -151,7 +148,11 @@ const router = useRouter(); const { status: pkiStatus, refresh: refreshPkiStatus } = usePkiStatus(); const toast = useToast(); -const isAuthenticated = computed(() => route.name !== 'Login'); +// Signed in: a stored token on a non-public page (the token is not reactive: it is re-read on every navigation) +const isAuthenticated = computed(() => { + void route.fullPath; + return !route.meta.public && !!localStorage.getItem('ovpmon_token'); +}); const username = ref(localStorage.getItem('ovpmon_user') || ''); // Keep the header name in sync with the server (login, rename, stale session) @@ -183,13 +184,6 @@ const handleLogout = () => { router.push('/login'); }; -const toggleTheme = () => { - isDark.value = !isDark.value; - const theme = isDark.value ? 'dark' : 'light'; - document.documentElement.setAttribute('data-theme', theme); - localStorage.setItem('theme', theme); -}; - const toggleSidebar = () => { isCompact.value = !isCompact.value; localStorage.setItem('sidebarCompact', isCompact.value); @@ -202,7 +196,7 @@ const refreshPage = () => { // Close sidebar on route change watch(() => route.path, () => { isSidebarOpen.value = false; - if (route.name !== 'Login') { + if (isAuthenticated.value) { syncUsername(); refreshPkiStatus(); } @@ -211,15 +205,10 @@ watch(() => route.path, () => { onMounted(async () => { await loadConfig(); window.addEventListener('ovpmon-user-changed', onUserChanged); - if (route.name !== 'Login') { + if (isAuthenticated.value) { syncUsername(); refreshPkiStatus(); } - - // Init Theme - const savedTheme = localStorage.getItem('theme') || 'light'; - isDark.value = savedTheme === 'dark'; - document.documentElement.setAttribute('data-theme', savedTheme); // Init Sidebar const savedCompact = localStorage.getItem('sidebarCompact'); diff --git a/APP_UI/src/assets/main.css b/APP_UI/src/assets/main.css index 5ec50a4..f58db6b 100644 --- a/APP_UI/src/assets/main.css +++ b/APP_UI/src/assets/main.css @@ -272,6 +272,11 @@ body { text-transform: uppercase; } +/* Space between a section header and its first link (also kept when the header is hidden in compact mode) */ +.nav-section-header + .nav-link { + margin-top: 1rem; +} + /* Compact Mode Styles */ .sidebar.compact { width: 64px; diff --git a/APP_UI/src/components/BaseModal.vue b/APP_UI/src/components/BaseModal.vue index 9786114..2854b28 100644 --- a/APP_UI/src/components/BaseModal.vue +++ b/APP_UI/src/components/BaseModal.vue @@ -22,7 +22,7 @@ diff --git a/APP_UI/src/views/Analytics.vue b/APP_UI/src/views/Analytics.vue index d270fb8..c53fc5b 100644 --- a/APP_UI/src/views/Analytics.vue +++ b/APP_UI/src/views/Analytics.vue @@ -151,16 +151,18 @@ import Chart from 'chart.js/auto'; import { useApi } from '../composables/useApi'; import { useFormatters } from '../composables/useFormatters'; import { useAppConfig } from '../composables/useAppConfig'; +import { useThemeObserver } from '../composables/useTheme'; +import { useTrafficChart, getThemeColors, COLOR_RX, COLOR_TX } from '../composables/useTrafficChart'; const { fetchAnalytics, fetchCertificates } = useApi(); -const { formatBytes, parseServerDate } = useFormatters(); +const { formatBytes } = useFormatters(); const { config } = useAppConfig(); // Refs const mainChartRef = ref(null); const pieChartRef = ref(null); -let mainChartInstance = null; let pieChartInstance = null; +const mainChart = useTrafficChart(mainChartRef, { maxPoints: 96 }); // State const loading = reactive({ analytics: true, certs: true }); @@ -179,17 +181,14 @@ const kpi = reactive({ const topClients = ref([]); const expiringCertsList = ref([]); -let cachedHistory = null; - -// Helpers -const MAX_CHART_POINTS = 96; +let cachedHistory = []; const loadAnalytics = async () => { loading.analytics = true; try { const res = await fetchAnalytics(range.value); if (res.success) { - proccessData(res.data); + processData(res.data); } } catch (e) { console.error(e); @@ -218,7 +217,7 @@ const loadCerts = async () => { } }; -const proccessData = (data) => { +const processData = (data) => { kpi.concurrentUsers = data.max_concurrent_24h || 0; // Traffic Distribution @@ -237,87 +236,21 @@ const proccessData = (data) => { percent: kpi.totalTraffic > 0 ? ((Number(c.total_traffic) / kpi.totalTraffic) * 100).toFixed(1) : 0 })); - cachedHistory = data.global_history_24h || []; + // Map the raw fields to the point format of useTrafficChart + cachedHistory = (data.global_history_24h || []).map(p => ({ + timestamp: p.timestamp, + bytes_received: p.total_rx, + bytes_sent: p.total_tx, + rx_rate_mbps: p.total_rx_rate, + tx_rate_mbps: p.total_tx_rate + })); renderMainChart(); renderPieChart(); }; const renderMainChart = () => { - if (!mainChartRef.value) return; - if (mainChartInstance) mainChartInstance.destroy(); - - const downsampled = downsampleData(cachedHistory, MAX_CHART_POINTS); - const labels = []; - const dataRx = []; - const dataTx = []; - - downsampled.forEach(point => { - const d = parseServerDate(point.timestamp); - let label = ''; - if(range.value.includes('h') || range.value === '1d') { - label = d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - } else { - label = d.toLocaleDateString([], { month: 'short', day: 'numeric' }) + ' ' + - d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); - } - labels.push(label); - - if (!isSpeedMode.value) { - dataRx.push(point.bytes_received / (1024 * 1024)); // MB - dataTx.push(point.bytes_sent / (1024 * 1024)); // MB - } else { - dataRx.push(point.rx_rate_mbps || 0); - dataTx.push(point.tx_rate_mbps || 0); - } - }); - - const isDark = document.documentElement.getAttribute('data-theme') === 'dark'; - const gridColor = isDark ? 'rgba(240, 246, 252, 0.1)' : 'rgba(0,0,0,0.05)'; - const textColor = isDark ? '#8b949e' : '#6c757d'; - - const ctx = mainChartRef.value.getContext('2d'); - mainChartInstance = new Chart(ctx, { - type: 'line', - data: { - labels, - datasets: [ - - { - label: !isSpeedMode.value ? 'Received (MB)' : 'RX Mbps', - data: dataRx, - borderColor: '#1652B8', // OpenVPN Blue - backgroundColor: 'rgba(22, 82, 184, 0.15)', - borderWidth: 2, - fill: true, - tension: 0.3, - pointRadius: 3, - pointHoverRadius: 4 - }, - { - label: !isSpeedMode.value ? 'Sent (MB)' : 'TX Mbps', - data: dataTx, - borderColor: '#EC7C31', // Brand Orange - backgroundColor: 'rgba(236, 124, 49, 0.15)', - borderWidth: 2, - fill: true, - tension: 0.3, - pointRadius: 3, - pointHoverRadius: 4 - } - ] - }, - options: { - responsive: true, - maintainAspectRatio: false, - interaction: { mode: 'index', intersect: false }, - plugins: { legend: { labels: { color: textColor } } }, - scales: { - x: { ticks: { color: textColor, maxTicksLimit: 8 }, grid: { color: gridColor } }, - y: { beginAtZero: true, ticks: { color: textColor }, grid: { color: gridColor } } - } - } - }); + mainChart.render(cachedHistory, { range: range.value, speedMode: isSpeedMode.value }); }; const renderPieChart = () => { @@ -325,8 +258,7 @@ const renderPieChart = () => { if (pieChartInstance) pieChartInstance.destroy(); const ctx = pieChartRef.value.getContext('2d'); - const isDark = document.documentElement.getAttribute('data-theme') === 'dark'; - const bgColor = isDark ? '#161b22' : '#ffffff'; + const bgColor = getThemeColors().isDark ? '#161b22' : '#ffffff'; pieChartInstance = new Chart(ctx, { type: 'doughnut', @@ -334,7 +266,7 @@ const renderPieChart = () => { labels: ['Received', 'Sent'], datasets: [{ data: [kpi.totalReceived, kpi.totalSent], - backgroundColor: ['#1652B8', '#EC7C31'], + backgroundColor: [COLOR_RX, COLOR_TX], borderColor: bgColor, borderWidth: 2, hoverOffset: 4 @@ -349,65 +281,18 @@ const renderPieChart = () => { }); }; -const downsampleData = (data, maxPoints) => { - if (!data || data.length === 0) return []; - if (data.length <= maxPoints) { - // Map raw fields to internal standardized names - return data.map(p => ({ - timestamp: p.timestamp, - bytes_received: p.total_rx, - bytes_sent: p.total_tx, - rx_rate_mbps: p.total_rx_rate, - tx_rate_mbps: p.total_tx_rate - })); - } - - const blockSize = Math.ceil(data.length / maxPoints); - const result = []; - - for (let i = 0; i < data.length; i += blockSize) { - const chunk = data.slice(i, i + blockSize); - if (chunk.length === 0) continue; - - let sumRx = 0, sumTx = 0; - let maxRxR = 0, maxTxR = 0; - - chunk.forEach(pt => { - sumRx += (pt.total_rx || 0); - sumTx += (pt.total_tx || 0); - maxRxR = Math.max(maxRxR, pt.total_rx_rate || 0); - maxTxR = Math.max(maxTxR, pt.total_tx_rate || 0); - }); - - result.push({ - timestamp: chunk[0].timestamp, - bytes_received: sumRx, - bytes_sent: sumTx, - rx_rate_mbps: maxRxR, - tx_rate_mbps: maxTxR - }); - } - return result; -}; - // Lifecycle let intervalId; +// Redraw the charts when the theme is toggled +useThemeObserver(() => { + renderMainChart(); + renderPieChart(); +}); + onMounted(() => { loadAnalytics(); loadCerts(); - - // Support Theme Toggle re-render like in Clients - // We observe the attribute on html - const observer = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - if (mutation.type === 'attributes' && mutation.attributeName === 'data-theme') { - renderMainChart(); - renderPieChart(); - } - }); - }); - observer.observe(document.documentElement, { attributes: true }); const refreshTime = config.value?.refresh_interval || 30000; intervalId = setInterval(() => { @@ -418,7 +303,6 @@ onMounted(() => { onUnmounted(() => { if (intervalId) clearInterval(intervalId); - if (mainChartInstance) mainChartInstance.destroy(); if (pieChartInstance) pieChartInstance.destroy(); }); diff --git a/APP_UI/src/views/Certificates.vue b/APP_UI/src/views/Certificates.vue index d2c33df..1ba8d77 100644 --- a/APP_UI/src/views/Certificates.vue +++ b/APP_UI/src/views/Certificates.vue @@ -296,6 +296,8 @@ const downloadConfig = async (cert) => { document.body.appendChild(link); link.click(); document.body.removeChild(link); + // Release the blob after the browser has started the download + setTimeout(() => window.URL.revokeObjectURL(url), 1000); } catch(e) { showToast('Could not download config: ' + (e.response?.data?.detail || e.message), 'error'); } diff --git a/APP_UI/src/views/Clients.vue b/APP_UI/src/views/Clients.vue index ba5fd9d..43ce78c 100644 --- a/APP_UI/src/views/Clients.vue +++ b/APP_UI/src/views/Clients.vue @@ -126,7 +126,7 @@ import { useFormatters } from '../composables/useFormatters'; import HistoryModal from '../components/HistoryModal.vue'; import { useAppConfig } from '../composables/useAppConfig'; -const { fetchStats, apiClient } = useApi(); +const { fetchStats } = useApi(); const { formatBytes, formatRate, parseServerDate } = useFormatters(); const { config } = useAppConfig(); diff --git a/APP_UI/src/views/Login.vue b/APP_UI/src/views/Login.vue index 3be4cdc..d466d3b 100644 --- a/APP_UI/src/views/Login.vue +++ b/APP_UI/src/views/Login.vue @@ -98,7 +98,7 @@ import { useRouter } from 'vue-router'; import { useApi } from '../composables/useApi'; const router = useRouter(); -const { apiClient } = useApi(); +const { authApiClient } = useApi(); const loading = ref(false); const error = ref(''); const requires2FA = ref(false); @@ -114,9 +114,7 @@ const handleLogin = async () => { loading.value = true; error.value = ''; try { - // Auth routes are under /api/auth, while apiClient defaults to /api/v1 - // We use a relative path with '..' to go up to /api - const response = await apiClient.post('../auth/login', form); + const response = await authApiClient.post('/login', form); if (response.data.requires_2fa) { requires2FA.value = true; tempToken.value = response.data.temp_token; @@ -137,7 +135,7 @@ const handleVerify2FA = async () => { loading.value = true; error.value = ''; try { - const response = await apiClient.post('../auth/verify-2fa', { + const response = await authApiClient.post('/verify-2fa', { temp_token: tempToken.value, otp: otp.value }); diff --git a/APP_UI/src/views/Login.vue.bak b/APP_UI/src/views/Login.vue.bak deleted file mode 100644 index cb985d3..0000000 --- a/APP_UI/src/views/Login.vue.bak +++ /dev/null @@ -1,251 +0,0 @@ - - - - - diff --git a/APP_UI/src/views/PKIConfig.vue b/APP_UI/src/views/PKIConfig.vue index 70366e0..11750ec 100644 --- a/APP_UI/src/views/PKIConfig.vue +++ b/APP_UI/src/views/PKIConfig.vue @@ -165,6 +165,8 @@ + + @@ -174,6 +176,7 @@ import { ref, computed, onMounted, onUnmounted, reactive } from 'vue'; import { useApi } from '../composables/useApi'; import { useToast } from '../composables/useToast'; import { usePkiStatus } from '../composables/usePkiStatus'; +import ConfirmModal from '../components/ConfirmModal.vue'; const { profilesApiClient } = useApi(); const toast = useToast(); @@ -198,6 +201,8 @@ const form = reactive({ easyrsa_batch: true }); +const initModal = ref(null); +const clearModal = ref(null); const isLoading = ref(false); const action = ref(''); // 'save', 'init', 'clear' @@ -290,9 +295,16 @@ const handleSave = async () => { } }; -const handleInit = async () => { - if (!confirm('Are you sure you want to Initialize system? This will start the PKI initialization process.')) return; - +const handleInit = () => { + initModal.value.open({ + title: 'Initialize PKI?', + message: 'Are you sure you want to initialize the system? This will start the PKI initialization process.', + confirmText: 'Yes, initialize', + confirmBtnClass: 'btn-action-primary' + }); +}; + +const runInit = async () => { isLoading.value = true; action.value = 'init'; // locks the button until the server confirms the job state try { @@ -312,9 +324,16 @@ const handleInit = async () => { } }; -const handleClear = async () => { - if (!confirm('Are you sure you want to CLEAR PKI? This will delete all certificates and cannot be undone.')) return; +const handleClear = () => { + clearModal.value.open({ + title: 'Clear PKI?', + message: 'Are you sure you want to CLEAR the PKI? This will delete all certificates and cannot be undone.', + confirmText: 'Yes, clear', + confirmBtnClass: 'btn-action-danger' + }); +}; +const runClear = async () => { isLoading.value = true; action.value = 'clear'; try { diff --git a/APP_UI/src/views/ServerManagement.vue b/APP_UI/src/views/ServerManagement.vue index bbc10e1..213a3b2 100644 --- a/APP_UI/src/views/ServerManagement.vue +++ b/APP_UI/src/views/ServerManagement.vue @@ -84,6 +84,8 @@ + + @@ -92,6 +94,7 @@ import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'; import { useApi } from '../composables/useApi'; import { useToast } from '../composables/useToast'; import { usePkiStatus } from '../composables/usePkiStatus'; +import ConfirmModal from '../components/ConfirmModal.vue'; const { profilesApiClient } = useApi(); const toast = useToast(); @@ -114,6 +117,7 @@ const stats = reactive({ uptime: null }); +const confirmModal = ref(null); const isLoading = ref(false); const action = ref(''); // 'start', 'stop', 'restart' let pollInterval = null; @@ -131,9 +135,19 @@ const fetchStats = async () => { } }; -const handleControl = async (cmd) => { - if (!confirm(`Are you sure you want to ${cmd.toUpperCase()} the OpenVPN service?`)) return; +const CONFIRM_CLASSES = { start: 'btn-action-primary', restart: 'btn-action-save', stop: 'btn-action-danger' }; +const handleControl = (cmd) => { + confirmModal.value.open({ + title: `${cmd.charAt(0).toUpperCase()}${cmd.slice(1)} the service?`, + message: `Are you sure you want to ${cmd.toUpperCase()} the OpenVPN service?`, + confirmText: `Yes, ${cmd}`, + confirmBtnClass: CONFIRM_CLASSES[cmd], + data: cmd + }); +}; + +const runControl = async (cmd) => { isLoading.value = true; action.value = cmd; diff --git a/APP_UI/vite.config.js b/APP_UI/vite.config.js index 33b7854..1bee784 100644 --- a/APP_UI/vite.config.js +++ b/APP_UI/vite.config.js @@ -9,7 +9,7 @@ export default defineConfig({ output: { manualChunks: { 'vendor-charts': ['chart.js'], - 'vendor-ui': ['bootstrap', 'sweetalert2'] + 'vendor-ui': ['bootstrap'] } } }