Auto-VLAN: verkon/IP:n VLAN-numero luo VLANin automaattisesti
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 <noreply@anthropic.com>
This commit is contained in:
29
api.php
29
api.php
@@ -1837,6 +1837,35 @@ switch ($action) {
|
|||||||
'muokkaaja' => currentUser(),
|
'muokkaaja' => currentUser(),
|
||||||
];
|
];
|
||||||
dbSaveIpam($companyId, $entry);
|
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';
|
$action_label = isset($input['id']) && !empty($input['id']) ? 'ipam_update' : 'ipam_create';
|
||||||
$desc = ($entry['tyyppi'] === 'vlan' ? 'VLAN ' . ($entry['vlan_id'] ?? '') : $entry['verkko']) . ' ' . $entry['nimi'];
|
$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ää');
|
dbAddLog($companyId, currentUser(), $action_label, $entry['id'], $desc, $action_label === 'ipam_create' ? 'Lisäsi IPAM-merkinnän' : 'Muokkasi IPAM-merkintää');
|
||||||
|
|||||||
Reference in New Issue
Block a user