diff --git a/html/includes/print-map.inc.php b/html/includes/print-map.inc.php index c8fcf1249b..6902db4b19 100644 --- a/html/includes/print-map.inc.php +++ b/html/includes/print-map.inc.php @@ -36,13 +36,66 @@ foreach (dbFetchRows("SELECT DISTINCT least(`devices`.`device_id`, `remote_devic array_push($tmp_ids,$link_devices['remote_device_id']); } -$tmp_ids = implode(',',$tmp_ids); - -$nodes = json_encode($tmp_devices); +$tmp_exp_ids = implode(',',$tmp_ids); + +$port_ids = array(); +foreach (dbFetchRows("SELECT DISTINCT LEAST(`M`.`port_id`, `P`.`port_id`) AS `remote_port_id`, GREATEST(`P`.`port_id`,`M`.`port_id`) AS `local_port_id` FROM `ipv4_mac` AS `M` LEFT JOIN `ports` AS `P` ON `M`.`mac_address` = `P`.`ifPhysAddress` WHERE `P`.`port_id` IS NOT NULL AND `M`.`port_id` IS NOT NULL", array()) as $macs) { + if (!in_array($macs['local_port_id'], $port_ids) && port_permitted($macs['local_port_id'])) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['local_port_id'])); + $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['local_port_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids)) { + $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); + array_push($port_ids, $port_dev['device_id']); + $port_data = $port_det; + $from = $port_dev['device_id']; + $port = shorten_interface_type($port_det['ifName']); + $speed = $port_det['ifSpeed']/1000/1000; + if ($speed == 100) { + $width = 3; + } elseif ($speed == 1000) { + $width = 5; + } elseif ($speed == 10000) { + $width = 10; + } elseif ($speed == 40000) { + $width = 15; + } elseif ($speed == 100000) { + $width = 20; + } else { + $width = 1; + } + $link_in_used = ($port_det['ifInOctets_rate'] * 8) / $port_det['ifSpeed'] * 100; + $link_out_used = ($port_det['ifOutOctets_rate'] * 8) / $port_det['ifSpeed'] * 100; + if ($link_in_used > $link_out_used) { + $link_used = $link_in_used; + } else { + $link_used = $link_out_used; + } + $link_used = round($link_used, -1); + if ($link_used > 100) { + $link_used = 100; + } + $link_color = $config['map_legend'][$link_used]; + } + } + if (!in_array($macs['remote_port_id'], $port_ids) && port_permitted($macs['remote_port_id'])) { + $port_dev = dbFetchRow("SELECT * FROM `devices` WHERE `device_id`=?", array($macs['remote_port_id'])); + $port_det = dbFetchRow("SELECT * FROM `ports` WHERE `port_id`=?", array($macs['remote_port_id'])); + if (!in_array($port_dev['device_id'],$tmp_ids)) { + $mac_devices[] = array('id'=>$port_dev['device_id'], 'label'=>$port_dev['hostname'], 'title'=>generate_device_link($port_dev,'',array(),'','','',0),'group'=>$port_dev['location'], 'shape'=>'box'); + array_push($port_ids, $port_dev['device_id']); + $to = $port_dev['device_id']; + $port .= ' > ' . shorten_interface_type($port_det['ifName']); + } + } + $tmp_links[] = array('from'=>$from,'to'=>$to,'label'=>$port,'title'=>generate_port_link($port_data, "",'',0,1),'width'=>$width,'color'=>$link_color); +} + +$node_devices = array_merge($tmp_devices,$mac_devices); +$nodes = json_encode($node_devices); if (is_array($tmp_devices[0])) { $tmp_links = array(); - foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_ids) AND `remote_device_id` IN ($tmp_ids))") as $link_devices) { + foreach (dbFetchRows("SELECT local_device_id, remote_device_id, `remote_hostname`,`ports`.*, `remote_port` FROM `links` LEFT JOIN `ports` ON `local_port_id`=`ports`.`port_id` LEFT JOIN `devices` ON `ports`.`device_id`=`devices`.`device_id` WHERE (`local_device_id` IN ($tmp_exp_ids) AND `remote_device_id` IN ($tmp_exp_ids))") as $link_devices) { foreach ($tmp_devices as $k=>$v) { if ($v['id'] == $link_devices['local_device_id']) { $from = $v['id']; @@ -85,6 +138,8 @@ if (is_array($tmp_devices[0])) { } $edges = json_encode($tmp_links); +} + ?> @@ -147,7 +202,6 @@ network.redraw();