feat(NetworkConfigManager): implement IP suggestion feature for local and remote IPs; add functionality to generate free private IPs from defined ranges
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m39s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m39s
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
|||||||
IconCopy,
|
IconCopy,
|
||||||
IconSearch,
|
IconSearch,
|
||||||
IconRefresh,
|
IconRefresh,
|
||||||
|
IconWand,
|
||||||
IconFilter,
|
IconFilter,
|
||||||
IconX,
|
IconX,
|
||||||
IconCircleFilled,
|
IconCircleFilled,
|
||||||
@@ -473,6 +474,86 @@ function NetworkConfigManager() {
|
|||||||
return conflicts;
|
return conflicts;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// === Получение множества всех используемых IP адресов ===
|
||||||
|
const getAllUsedIpsSet = useMemo(() => {
|
||||||
|
const usedIps = new Set();
|
||||||
|
(config.tunnelInterfaces || []).forEach(iface => {
|
||||||
|
if (iface.localIp && iface.localIp.trim()) {
|
||||||
|
usedIps.add(iface.localIp.trim());
|
||||||
|
}
|
||||||
|
if (iface.remoteIp && iface.remoteIp.trim()) {
|
||||||
|
usedIps.add(iface.remoteIp.trim());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return usedIps;
|
||||||
|
}, [config.tunnelInterfaces]);
|
||||||
|
|
||||||
|
// === Генерация свободного IP адреса из приватных диапазонов ===
|
||||||
|
const generateFreePrivateIp = (excludeIp = null) => {
|
||||||
|
const usedIps = new Set(getAllUsedIpsSet);
|
||||||
|
if (excludeIp) {
|
||||||
|
usedIps.delete(excludeIp.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Приватные диапазоны для туннелей (RFC 1918)
|
||||||
|
// Начинаем с 10.10.0.0/16 для удобства
|
||||||
|
const ranges = [
|
||||||
|
{ start: [10, 10, 0, 1], end: [10, 10, 255, 254] }, // 10.10.0.0/16
|
||||||
|
{ start: [10, 0, 0, 1], end: [10, 255, 255, 254] }, // 10.0.0.0/8 (весь диапазон)
|
||||||
|
{ start: [172, 16, 0, 1], end: [172, 31, 255, 254] }, // 172.16.0.0/12
|
||||||
|
{ start: [192, 168, 0, 1], end: [192, 168, 255, 254] }, // 192.168.0.0/16
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const range of ranges) {
|
||||||
|
const [a, b, c, d] = range.start;
|
||||||
|
const [aEnd, bEnd, cEnd, dEnd] = range.end;
|
||||||
|
|
||||||
|
// Перебираем IP в диапазоне
|
||||||
|
for (let aVal = a; aVal <= aEnd; aVal++) {
|
||||||
|
const bStart = (aVal === a) ? b : 0;
|
||||||
|
const bEndVal = (aVal === aEnd) ? bEnd : 255;
|
||||||
|
for (let bVal = bStart; bVal <= bEndVal; bVal++) {
|
||||||
|
const cStart = (aVal === a && bVal === b) ? c : 0;
|
||||||
|
const cEndVal = (aVal === aEnd && bVal === bEnd) ? cEnd : 255;
|
||||||
|
for (let cVal = cStart; cVal <= cEndVal; cVal++) {
|
||||||
|
const dStart = (aVal === a && bVal === b && cVal === c) ? d : 1;
|
||||||
|
const dEndVal = (aVal === aEnd && bVal === bEnd && cVal === cEnd) ? dEnd : 254;
|
||||||
|
for (let dVal = dStart; dVal <= dEndVal; dVal++) {
|
||||||
|
const ip = `${aVal}.${bVal}.${cVal}.${dVal}`;
|
||||||
|
if (!usedIps.has(ip)) {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если все IP заняты (маловероятно), возвращаем null
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// === Подбор IP для интерфейса ===
|
||||||
|
const handleSuggestLocalIp = () => {
|
||||||
|
const freeIp = generateFreePrivateIp(editingInterface?.localIp);
|
||||||
|
if (freeIp) {
|
||||||
|
setEditingInterface({ ...editingInterface, localIp: freeIp });
|
||||||
|
notify.success(`Подобран Local IP: ${freeIp}`);
|
||||||
|
} else {
|
||||||
|
notify.error('Не удалось найти свободный IP адрес');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSuggestRemoteIp = () => {
|
||||||
|
const freeIp = generateFreePrivateIp(editingInterface?.remoteIp);
|
||||||
|
if (freeIp) {
|
||||||
|
setEditingInterface({ ...editingInterface, remoteIp: freeIp });
|
||||||
|
notify.success(`Подобран Remote IP: ${freeIp}`);
|
||||||
|
} else {
|
||||||
|
notify.error('Не удалось найти свободный IP адрес');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// === Получение реестра всех используемых IP адресов ===
|
// === Получение реестра всех используемых IP адресов ===
|
||||||
const ipRegistry = useMemo(() => {
|
const ipRegistry = useMemo(() => {
|
||||||
const registry = [];
|
const registry = [];
|
||||||
@@ -2285,13 +2366,25 @@ function NetworkConfigManager() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-4">
|
<div className="col-md-4">
|
||||||
<FormField
|
<div className="d-flex align-items-end gap-2">
|
||||||
label="Local IP"
|
<div className="flex-grow-1">
|
||||||
name="localIp"
|
<FormField
|
||||||
value={editingInterface.localIp}
|
label="Local IP"
|
||||||
onChange={(val) => setEditingInterface({ ...editingInterface, localIp: val })}
|
name="localIp"
|
||||||
placeholder="10.10.0.1"
|
value={editingInterface.localIp}
|
||||||
/>
|
onChange={(val) => setEditingInterface({ ...editingInterface, localIp: val })}
|
||||||
|
placeholder="10.10.0.1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-outline-primary"
|
||||||
|
onClick={handleSuggestLocalIp}
|
||||||
|
title="Подобрать свободный IP из приватного диапазона"
|
||||||
|
>
|
||||||
|
<IconWand size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{editingInterface.localIp && (() => {
|
{editingInterface.localIp && (() => {
|
||||||
const conflicts = checkInterfaceIpConflict(
|
const conflicts = checkInterfaceIpConflict(
|
||||||
{ localIp: editingInterface.localIp },
|
{ localIp: editingInterface.localIp },
|
||||||
@@ -2308,13 +2401,25 @@ function NetworkConfigManager() {
|
|||||||
})()}
|
})()}
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-4">
|
<div className="col-md-4">
|
||||||
<FormField
|
<div className="d-flex align-items-end gap-2">
|
||||||
label="Remote IP"
|
<div className="flex-grow-1">
|
||||||
name="remoteIp"
|
<FormField
|
||||||
value={editingInterface.remoteIp}
|
label="Remote IP"
|
||||||
onChange={(val) => setEditingInterface({ ...editingInterface, remoteIp: val })}
|
name="remoteIp"
|
||||||
placeholder="10.10.0.2"
|
value={editingInterface.remoteIp}
|
||||||
/>
|
onChange={(val) => setEditingInterface({ ...editingInterface, remoteIp: val })}
|
||||||
|
placeholder="10.10.0.2"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="btn btn-outline-primary"
|
||||||
|
onClick={handleSuggestRemoteIp}
|
||||||
|
title="Подобрать свободный IP из приватного диапазона"
|
||||||
|
>
|
||||||
|
<IconWand size={16} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{editingInterface.remoteIp && (() => {
|
{editingInterface.remoteIp && (() => {
|
||||||
const conflicts = checkInterfaceIpConflict(
|
const conflicts = checkInterfaceIpConflict(
|
||||||
{ remoteIp: editingInterface.remoteIp },
|
{ remoteIp: editingInterface.remoteIp },
|
||||||
|
|||||||
Reference in New Issue
Block a user