IPAM: VLAN-duplikaattivaroitus "jatketaanko silti" -dialogilla
API palauttaa 409 kun VLAN-numero on jo olemassa, frontend näyttää confirm-dialogin. Käyttäjä voi valita jatkaako vai ei. IP/verkko-duplikaatti estää edelleen kokonaan (400). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
19
api.php
19
api.php
@@ -1836,9 +1836,12 @@ switch ($action) {
|
||||
'muokattu' => date('Y-m-d H:i:s'),
|
||||
'muokkaaja' => currentUser(),
|
||||
];
|
||||
// Duplikaatti-tarkistus: sama verkko/IP ei saa olla jo olemassa
|
||||
if ($entry['verkko'] !== '' && $entry['tyyppi'] !== 'vlan') {
|
||||
// Duplikaatti-tarkistus
|
||||
$skipDuplicateCheck = !empty($input['force']);
|
||||
if (!$skipDuplicateCheck) {
|
||||
$existingAll = dbLoadIpam($companyId);
|
||||
// Verkko/IP duplikaatti — estä kokonaan
|
||||
if ($entry['verkko'] !== '' && $entry['tyyppi'] !== 'vlan') {
|
||||
foreach ($existingAll as $ex) {
|
||||
if ($ex['verkko'] === $entry['verkko'] && $ex['id'] !== $entry['id'] && $ex['tyyppi'] !== 'vlan') {
|
||||
http_response_code(400);
|
||||
@@ -1847,6 +1850,18 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// VLAN duplikaatti — varoitus (409 = confirm)
|
||||
if ($entry['tyyppi'] === 'vlan' && !empty($entry['vlan_id'])) {
|
||||
$vlanNum = (int)$entry['vlan_id'];
|
||||
foreach ($existingAll as $ex) {
|
||||
if ($ex['tyyppi'] === 'vlan' && (int)$ex['vlan_id'] === $vlanNum && $ex['id'] !== $entry['id']) {
|
||||
http_response_code(409);
|
||||
echo json_encode(['warning' => 'VLAN ' . $vlanNum . ' on jo olemassa (' . ($ex['nimi'] ?: 'nimetön') . '). Lisätäänkö silti?']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dbSaveIpam($companyId, $entry);
|
||||
// Auto-VLAN: jos subnet/ip:llä on vlan_id, luo VLAN automaattisesti jos ei vielä ole
|
||||
if ($entry['tyyppi'] !== 'vlan' && !empty($entry['vlan_id'])) {
|
||||
|
||||
15
script.js
15
script.js
@@ -3470,7 +3470,22 @@ document.getElementById('ipam-form')?.addEventListener('submit', async (e) => {
|
||||
};
|
||||
if (id) data.id = id;
|
||||
try {
|
||||
const res = await fetch(`${API}?action=ipam_save`, {
|
||||
method: 'POST', credentials: 'include',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
const result = await res.json();
|
||||
if (res.status === 409 && result.warning) {
|
||||
if (confirm(result.warning)) {
|
||||
data.force = true;
|
||||
await apiCall('ipam_save', 'POST', data);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (!res.ok) {
|
||||
throw new Error(result.error || 'Virhe');
|
||||
}
|
||||
document.getElementById('ipam-modal').style.display = 'none';
|
||||
loadIpam();
|
||||
} catch (e) { alert(e.message); }
|
||||
|
||||
Reference in New Issue
Block a user