UI review, stage 1: 401 on /auth/*, expiring certs, VPN netmask, formatBytes

401 from change-password/change-username no longer logs the user out;
Analytics reads the plain /profiles array; VPN settings send vpn_netmask
with vpn_network (the API reset it to 255.255.255.0); formatBytes guards
null/NaN/negative; Certificates sorts 0 days correctly. Vitest added for
formatters, CIDR parsing and the 401 interceptor.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-07 13:05:55 +03:00
1 parent 3fac8d70d8
commit b78de98f26
11 files changed
+672 -57

No files matched your search

+17 -17
View File
@@ -264,6 +264,7 @@ import { ref, onMounted, reactive, watch } from 'vue';
import { useApi } from '../composables/useApi';
import { useToast } from '../composables/useToast';
import { usePkiStatus } from '../composables/usePkiStatus';
import { maskToCidr, parseCidr } from '../utils/cidr';
const { profilesApiClient } = useApi();
const toast = useToast();
@@ -302,15 +303,8 @@ watch(isSplitTunnel, (val) => {
form.tunnel_type = val ? 'SPLIT' : 'FULL';
});
// Helpers
function maskToCidr(mask) {
if (!mask) return '';
const parts = mask.split('.');
let bits = 0;
const map = {255:8, 254:7, 252:6, 248:5, 240:4, 224:3, 192:2, 128:1, 0:0};
for(let p of parts) bits += map[parseInt(p)] || 0;
return bits;
}
// Netmask received from the server: used when the subnet is typed without a /nn suffix
let currentNetmask = '';
// Methods
const showMessage = (text, type = 'success') => toast.show(text, type);
@@ -337,9 +331,10 @@ const loadConfig = async () => {
}
});
currentNetmask = data.vpn_netmask || '';
if (data.vpn_network && data.vpn_netmask) {
const cidrSuffix = maskToCidr(data.vpn_netmask);
if (cidrSuffix) {
if (cidrSuffix !== null) {
form.vpn_network = `${data.vpn_network}/${cidrSuffix}`;
}
}
@@ -351,20 +346,25 @@ const loadConfig = async () => {
};
const handleSave = async () => {
// The API takes the address and the netmask separately: without vpn_netmask it resets the mask to 255.255.255.0
const subnet = parseCidr(form.vpn_network);
if (!subnet) {
showMessage('VPN subnet must be an IPv4 network in CIDR format, e.g. 172.20.1.0/24', 'error');
return;
}
isLoading.value = true;
action.value = 'save';
const payload = { ...form };
payload.split_routes = payload.split_routes.filter(r => r && r.trim() !== '');
payload.dns_servers = payload.dns_servers.filter(d => d && d.trim() !== '');
if (payload.vpn_network.includes('/')) {
const [ip, suffix] = payload.vpn_network.split('/');
payload.vpn_network = ip;
}
payload.vpn_network = subnet.network;
payload.vpn_netmask = subnet.netmask || currentNetmask || '255.255.255.0';
try {
await profilesApiClient.put('/config/server', payload);
currentNetmask = payload.vpn_netmask;
showMessage('Server configuration saved!', 'success');
} catch (err) {
showMessage(`Error saving: ${err.response?.data?.detail || err.message}`, 'error');