''"); while ($row = mysqli_fetch_assoc($sql)) { $address = trim($row['network']); $subnet = trim($row['network_subnet']); $bin = @inet_pton($address); if ($bin === false) { continue; } $prefix = null; if (ctype_digit($subnet) && intval($subnet) <= strlen($bin) * 8) { $prefix = intval($subnet); } elseif (strlen($bin) === 4 && ($mask = @inet_pton($subnet)) !== false && strlen($mask) === 4) { $bits = ''; foreach (str_split($mask) as $byte) { $bits .= str_pad(decbin(ord($byte)), 8, '0', STR_PAD_LEFT); } if (preg_match('/^(1*)0*$/', $bits, $match)) { $prefix = strlen($match[1]); } } if ($prefix !== null) { $cidr = mysqli_real_escape_string($mysqli, inet_ntop($bin) . '/' . $prefix); mysqli_query($mysqli, "UPDATE networks SET network = '$cidr' WHERE network_id = " . intval($row['network_id'])); } } // A documented address can be a fixed one, a DHCP reservation (with the MAC // it is reserved for), held back, or a virtual / floating address mysqli_query($mysqli, "ALTER TABLE `network_ips` ADD COLUMN `ip_type` varchar(30) NOT NULL DEFAULT 'Static' AFTER `ip_address`"); mysqli_query($mysqli, "ALTER TABLE `network_ips` ADD COLUMN `ip_mac` varchar(200) DEFAULT NULL AFTER `ip_hostname`"); // The VLANs on a port - "20", or "Trunk 1,10,20" - and the network page // finds the interfaces on a network by it mysqli_query($mysqli, "ALTER TABLE `asset_interfaces` ADD COLUMN `interface_vlans` varchar(200) DEFAULT NULL AFTER `interface_ipv6`"); mysqli_query($mysqli, "ALTER TABLE `asset_interfaces` ADD INDEX `interface_network_id` (`interface_network_id`)");