From 2686377fe221067152eb3465209c991471900014 Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Wed, 11 Mar 2026 09:31:54 +0200 Subject: [PATCH] Auto-VLAN: verkon/IP:n VLAN-numero luo VLANin automaattisesti MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Kun tallennetaan subnet tai IP jossa on VLAN-numero, tarkistetaan löytyykö kyseinen VLAN jo listalta. Jos ei, luodaan se automaattisesti VLAN-luetteloon. Co-Authored-By: Claude Opus 4.6 --- api.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/api.php b/api.php index 091d85b..8292136 100644 --- a/api.php +++ b/api.php @@ -1837,6 +1837,35 @@ switch ($action) { 'muokkaaja' => currentUser(), ]; 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'])) { + $vlanNum = (int)$entry['vlan_id']; + $existingIpam = dbLoadIpam($companyId); + $vlanExists = false; + foreach ($existingIpam as $ie) { + if ($ie['tyyppi'] === 'vlan' && (int)$ie['vlan_id'] === $vlanNum) { + $vlanExists = true; + break; + } + } + if (!$vlanExists) { + $newVlan = [ + 'id' => generateId(), + 'tyyppi' => 'vlan', + 'nimi' => 'VLAN ' . $vlanNum, + 'verkko' => '', + 'vlan_id' => $vlanNum, + 'site_id' => $entry['site_id'], + 'tila' => 'varattu', + 'asiakas' => '', + 'lisatiedot' => 'Luotu automaattisesti', + 'luotu' => date('Y-m-d H:i:s'), + 'muokattu' => null, + 'muokkaaja' => currentUser(), + ]; + dbSaveIpam($companyId, $newVlan); + } + } $action_label = isset($input['id']) && !empty($input['id']) ? 'ipam_update' : 'ipam_create'; $desc = ($entry['tyyppi'] === 'vlan' ? 'VLAN ' . ($entry['vlan_id'] ?? '') : $entry['verkko']) . ' ' . $entry['nimi']; dbAddLog($companyId, currentUser(), $action_label, $entry['id'], $desc, $action_label === 'ipam_create' ? 'Lisäsi IPAM-merkinnän' : 'Muokkasi IPAM-merkintää');