| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * LibreNMS | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify it | 
					
						
							|  |  |  |  * under the terms of the GNU General Public License as published by the | 
					
						
							|  |  |  |  * Free Software Foundation, either version 3 of the License, or (at your | 
					
						
							|  |  |  |  * option) any later version.  Please see LICENSE.txt at the top level of | 
					
						
							|  |  |  |  * the source code distribution for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 16:31:26 +02:00
										 |  |  | //Don't know where this should come from, but it is used later, so I just define it here.
 | 
					
						
							| 
									
										
										
										
											2018-09-11 07:51:35 -05:00
										 |  |  | use LibreNMS\Authentication\LegacyAuth; | 
					
						
							| 
									
										
										
										
											2018-04-07 15:55:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-18 16:31:26 +02:00
										 |  |  | $row_colour="#ffffff"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $sql_array= array(); | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | if (!empty($device['hostname'])) { | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |     $sql = ' AND (`D1`.`hostname`=? OR `D2`.`hostname`=?)'; | 
					
						
							|  |  |  |     $sql_array = array($device['hostname'], $device['hostname']); | 
					
						
							| 
									
										
										
										
											2015-06-02 00:03:06 +01:00
										 |  |  |     $mac_sql = ' AND `D`.`hostname` = ?'; | 
					
						
							|  |  |  |     $mac_array = array($device['hostname']); | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2015-07-14 12:15:05 +01:00
										 |  |  |     $sql = ' '; | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-28 00:53:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 07:51:35 -05:00
										 |  |  | if (!LegacyAuth::user()->hasGlobalRead()) { | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |     $join_sql    .= ' LEFT JOIN `devices_perms` AS `DP` ON `D1`.`device_id` = `DP`.`device_id`'; | 
					
						
							|  |  |  |     $sql  .= ' AND `DP`.`user_id`=?'; | 
					
						
							| 
									
										
										
										
											2018-09-11 07:51:35 -05:00
										 |  |  |     $sql_array[] = LegacyAuth::id(); | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-03-28 00:53:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | $devices_by_id = array(); | 
					
						
							|  |  |  | $links = array(); | 
					
						
							|  |  |  | $link_assoc_seen = array(); | 
					
						
							|  |  |  | $device_assoc_seen = array(); | 
					
						
							| 
									
										
										
										
											2015-07-19 21:45:56 +01:00
										 |  |  | $ports = array(); | 
					
						
							|  |  |  | $devices = array(); | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-16 17:14:58 -07:00
										 |  |  | $where = ""; | 
					
						
							|  |  |  | if (is_numeric($vars['group'])) { | 
					
						
							| 
									
										
										
										
											2016-09-18 19:08:33 -05:00
										 |  |  |     $where .= " AND D1.device_id IN (SELECT `device_id` FROM `device_group_device` WHERE `device_group_id` = ?)"; | 
					
						
							|  |  |  |     $sql_array[] = $vars['group']; | 
					
						
							|  |  |  |     $where .= " OR D2.device_id IN (SELECT `device_id` FROM `device_group_device` WHERE `device_group_id` = ?)"; | 
					
						
							|  |  |  |     $sql_array[] = $vars['group']; | 
					
						
							| 
									
										
										
										
											2016-02-16 17:14:58 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | if (in_array('mac', $config['network_map_items'])) { | 
					
						
							| 
									
										
										
										
											2015-07-18 15:59:19 +01:00
										 |  |  |     $ports = dbFetchRows("SELECT
 | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D1`.`status` AS `local_status`, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `D1`.`device_id` AS `local_device_id`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D1`.`disabled` AS `local_disabled`, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `D1`.`os` AS `local_os`, | 
					
						
							|  |  |  |                              `D1`.`hostname` AS `local_hostname`, | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |                              `D1`.`sysName` AS `local_sysName`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D2`.`status` AS `remote_status`, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `D2`.`device_id` AS `remote_device_id`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D2`.`disabled` AS `remote_disabled`, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `D2`.`os` AS `remote_os`, | 
					
						
							|  |  |  |                              `D2`.`hostname` AS `remote_hostname`, | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |                              `D2`.`sysName` AS `remote_sysName`, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `P1`.`port_id` AS `local_port_id`, | 
					
						
							|  |  |  |                              `P1`.`device_id` AS `local_port_device_id`, | 
					
						
							|  |  |  |                              `P1`.`ifName` AS `local_ifname`, | 
					
						
							|  |  |  |                              `P1`.`ifSpeed` AS `local_ifspeed`, | 
					
						
							|  |  |  |                              `P1`.`ifOperStatus` AS `local_ifoperstatus`, | 
					
						
							|  |  |  |                              `P1`.`ifAdminStatus` AS `local_ifadminstatus`, | 
					
						
							|  |  |  |                              `P1`.`ifInOctets_rate` AS `local_ifinoctets_rate`, | 
					
						
							|  |  |  |                              `P1`.`ifOutOctets_rate` AS `local_ifoutoctets_rate`, | 
					
						
							|  |  |  |                              `P2`.`port_id` AS `remote_port_id`, | 
					
						
							|  |  |  |                              `P2`.`device_id` AS `remote_port_device_id`, | 
					
						
							|  |  |  |                              `P2`.`ifName` AS `remote_ifname`, | 
					
						
							|  |  |  |                              `P2`.`ifSpeed` AS `remote_ifspeed`, | 
					
						
							|  |  |  |                              `P2`.`ifOperStatus` AS `remote_ifoperstatus`, | 
					
						
							|  |  |  |                              `P2`.`ifAdminStatus` AS `remote_ifadminstatus`, | 
					
						
							|  |  |  |                              `P2`.`ifInOctets_rate` AS `remote_ifinoctets_rate`, | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |                              `P2`.`ifOutOctets_rate` AS `remote_ifoutoctets_rate`, | 
					
						
							|  |  |  |                              SUM(IF(`P2_ip`.`ipv4_address` = `M`.`ipv4_address`, 1, 0)) | 
					
						
							|  |  |  |                                  AS `remote_matching_ips` | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                       FROM `ipv4_mac` AS `M` | 
					
						
							| 
									
										
										
										
											2016-06-23 22:45:41 -07:00
										 |  |  |                              INNER JOIN `ports` AS `P1` ON `P1`.`port_id`=`M`.`port_id` | 
					
						
							|  |  |  |                              INNER JOIN `ports` AS `P2` ON `P2`.`ifPhysAddress`=`M`.`mac_address` | 
					
						
							|  |  |  |                              INNER JOIN `devices` AS `D1` ON `P1`.`device_id`=`D1`.`device_id` | 
					
						
							|  |  |  |                              INNER JOIN `devices` AS `D2` ON `P2`.`device_id`=`D2`.`device_id` | 
					
						
							|  |  |  |                              INNER JOIN `ipv4_addresses` AS `P2_ip` ON `P2_ip`.`port_id` = `P2`.`port_id` | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              $join_sql | 
					
						
							|  |  |  |                       WHERE | 
					
						
							| 
									
										
										
										
											2015-07-19 22:52:44 +02:00
										 |  |  |                              `M`.`mac_address` NOT IN ('000000000000','ffffffffffff') AND | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `D1`.`device_id` != `D2`.`device_id` | 
					
						
							| 
									
										
										
										
											2016-02-16 17:14:58 -07:00
										 |  |  |                              $where | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              $sql | 
					
						
							| 
									
										
										
										
											2017-01-07 17:32:38 +00:00
										 |  |  |                       GROUP BY `P1`.`port_id`,`P2`.`port_id`,`D1`.`device_id`, `D1`.`os`, `D1`.`hostname`, `D2`.`device_id`, `D2`.`os`, `D2`.`hostname`, `P1`.`port_id`, `P1`.`device_id`, `P1`.`ifName`, `P1`.`ifSpeed`, `P1`.`ifOperStatus`, `P1`.`ifAdminStatus`, `P1`.`ifInOctets_rate`, `P1`.`ifOutOctets_rate`, `P2`.`port_id`, `P2`.`device_id`, `P2`.`ifName`, `P2`.`ifSpeed`, `P2`.`ifOperStatus`, `P2`.`ifAdminStatus`, `P2`.`ifInOctets_rate`, `P2`.`ifOutOctets_rate` | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |                       ORDER BY `remote_matching_ips` DESC, `local_ifname`, `remote_ifname` | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                      ", $sql_array);
 | 
					
						
							| 
									
										
										
										
											2015-07-18 15:59:19 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-18 16:15:57 +01:00
										 |  |  | if (in_array('xdp', $config['network_map_items'])) { | 
					
						
							| 
									
										
										
										
											2015-07-18 15:59:19 +01:00
										 |  |  |     $devices = dbFetchRows("SELECT
 | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D1`.`status` AS `local_status`, | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                              `D1`.`device_id` AS `local_device_id`, | 
					
						
							|  |  |  |                              `D1`.`os` AS `local_os`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D1`.`disabled` AS `local_disabled`, | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                              `D1`.`hostname` AS `local_hostname`, | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |                              `D1`.`sysName` AS `local_sysName`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D2`.`status` AS `remote_status`, | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                              `D2`.`device_id` AS `remote_device_id`, | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |                              `D2`.`disabled` AS `remote_disabled`, | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                              `D2`.`os` AS `remote_os`, | 
					
						
							|  |  |  |                              `D2`.`hostname` AS `remote_hostname`, | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |                              `D2`.`sysName` AS `remote_sysName`, | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                              `P1`.`port_id` AS `local_port_id`, | 
					
						
							|  |  |  |                              `P1`.`device_id` AS `local_port_device_id`, | 
					
						
							|  |  |  |                              `P1`.`ifName` AS `local_ifname`, | 
					
						
							|  |  |  |                              `P1`.`ifSpeed` AS `local_ifspeed`, | 
					
						
							|  |  |  |                              `P1`.`ifOperStatus` AS `local_ifoperstatus`, | 
					
						
							|  |  |  |                              `P1`.`ifAdminStatus` AS `local_ifadminstatus`, | 
					
						
							|  |  |  |                              `P1`.`ifInOctets_rate` AS `local_ifinoctets_rate`, | 
					
						
							|  |  |  |                              `P1`.`ifOutOctets_rate` AS `local_ifoutoctets_rate`, | 
					
						
							|  |  |  |                              `P2`.`port_id` AS `remote_port_id`, | 
					
						
							|  |  |  |                              `P2`.`device_id` AS `remote_port_device_id`, | 
					
						
							|  |  |  |                              `P2`.`ifName` AS `remote_ifname`, | 
					
						
							|  |  |  |                              `P2`.`ifSpeed` AS `remote_ifspeed`, | 
					
						
							|  |  |  |                              `P2`.`ifOperStatus` AS `remote_ifoperstatus`, | 
					
						
							|  |  |  |                              `P2`.`ifAdminStatus` AS `remote_ifadminstatus`, | 
					
						
							|  |  |  |                              `P2`.`ifInOctets_rate` AS `remote_ifinoctets_rate`, | 
					
						
							|  |  |  |                              `P2`.`ifOutOctets_rate` AS `remote_ifoutoctets_rate` | 
					
						
							|  |  |  |                       FROM `links` | 
					
						
							| 
									
										
										
										
											2016-06-23 22:45:41 -07:00
										 |  |  |                              INNER JOIN `devices` AS `D1` ON `D1`.`device_id`=`links`.`local_device_id` | 
					
						
							|  |  |  |                              INNER JOIN `devices` AS `D2` ON `D2`.`device_id`=`links`.`remote_device_id` | 
					
						
							|  |  |  |                              INNER JOIN `ports` AS `P1` ON `P1`.`port_id`=`links`.`local_port_id` | 
					
						
							|  |  |  |                              INNER JOIN `ports` AS `P2` ON `P2`.`port_id`=`links`.`remote_port_id` | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              $join_sql | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |                       WHERE | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                              `active`=1 AND | 
					
						
							|  |  |  |                              `local_device_id` != 0 AND | 
					
						
							| 
									
										
										
										
											2016-06-28 11:40:24 +02:00
										 |  |  |                              `remote_device_id` != 0 | 
					
						
							| 
									
										
										
										
											2016-02-16 17:14:58 -07:00
										 |  |  |                              $where | 
					
						
							| 
									
										
										
										
											2015-07-14 12:13:17 +01:00
										 |  |  |                              $sql | 
					
						
							| 
									
										
										
										
											2017-01-07 17:32:38 +00:00
										 |  |  |                       GROUP BY `P1`.`port_id`,`P2`.`port_id`,`D1`.`device_id`, `D1`.`os`, `D1`.`hostname`, `D2`.`device_id`, `D2`.`os`, `D2`.`hostname`, `P1`.`port_id`, `P1`.`device_id`, `P1`.`ifName`, `P1`.`ifSpeed`, `P1`.`ifOperStatus`, `P1`.`ifAdminStatus`, `P1`.`ifInOctets_rate`, `P1`.`ifOutOctets_rate`, `P2`.`port_id`, `P2`.`device_id`, `P2`.`ifName`, `P2`.`ifSpeed`, `P2`.`ifOperStatus`, `P2`.`ifAdminStatus`, `P2`.`ifInOctets_rate`, `P2`.`ifOutOctets_rate` | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |                       ORDER BY `local_ifname`, `remote_ifname` | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |                       ", $sql_array);
 | 
					
						
							| 
									
										
										
										
											2015-07-18 15:59:19 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | $list = array_merge($ports, $devices); | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  | // Build the style variables we need
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $node_disabled_style = array( | 
					
						
							|  |  |  |     'color' => array( | 
					
						
							|  |  |  |         'highlight' => array( | 
					
						
							|  |  |  |             'background' => $config['network_map_legend']['di.node'], | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         'border' => $config['network_map_legend']['di.border'], | 
					
						
							|  |  |  |         'background' => $config['network_map_legend']['di.node'], | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | $node_down_style = array( | 
					
						
							|  |  |  |     'color' => array( | 
					
						
							|  |  |  |         'highlight' => array( | 
					
						
							|  |  |  |             'background' => $config['network_map_legend']['dn.node'], | 
					
						
							|  |  |  |             'border' => $config['network_map_legend']['dn.border'], | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |         'border' => $config['network_map_legend']['dn.border'], | 
					
						
							|  |  |  |         'background' => $config['network_map_legend']['dn.node'], | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | $edge_disabled_style = array( | 
					
						
							|  |  |  |     'dashes' => array(8,12), | 
					
						
							|  |  |  |     'color' => array( | 
					
						
							|  |  |  |         'color' => $config['network_map_legend']['di.edge'], | 
					
						
							|  |  |  |         'highlight' => $config['network_map_legend']['di.edge'], | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | $edge_down_style = array( | 
					
						
							|  |  |  |     'dashes' => array(8,12), | 
					
						
							|  |  |  |     'color' => array( | 
					
						
							|  |  |  |         'border' => $config['network_map_legend']['dn.border'], | 
					
						
							|  |  |  |         'highlight' => $config['network_map_legend']['dn.edge'], | 
					
						
							|  |  |  |         'color' => $config['network_map_legend']['dn.edge'], | 
					
						
							|  |  |  |     ), | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | // Iterate though ports and links, generating a set of devices (nodes)
 | 
					
						
							|  |  |  | // and links (edges) that make up the topology graph.
 | 
					
						
							| 
									
										
										
										
											2015-03-28 00:53:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  | foreach ($list as $items) { | 
					
						
							|  |  |  |     $local_device = array( | 
					
						
							|  |  |  |         'device_id'=>$items['local_device_id'], | 
					
						
							|  |  |  |         'os'=>$items['local_os'], | 
					
						
							|  |  |  |         'hostname'=>$items['local_hostname'], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     $remote_device = array( | 
					
						
							|  |  |  |         'device_id'=>$items['remote_device_id'], | 
					
						
							|  |  |  |         'os'=>$items['remote_os'], | 
					
						
							|  |  |  |         'hostname'=>$items['remote_hostname'], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     $local_port = array( | 
					
						
							|  |  |  |         'port_id'=>$items['local_port_id'], | 
					
						
							|  |  |  |         'device_id'=>$items['local_port_device_id'], | 
					
						
							|  |  |  |         'ifName'=>$items['local_ifname'], | 
					
						
							|  |  |  |         'ifSpeed'=>$items['local_ifspeed'], | 
					
						
							|  |  |  |         'ifOperStatus'=>$items['local_ifoperstatus'], | 
					
						
							|  |  |  |         'ifAdminStatus'=>$items['local_adminstatus'], | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     $remote_port = array( | 
					
						
							|  |  |  |         'port_id'=>$items['remote_port_id'], | 
					
						
							|  |  |  |         'device_id'=>$items['remote_port_device_id'], | 
					
						
							|  |  |  |         'ifName'=>$items['remote_ifname'], | 
					
						
							|  |  |  |         'ifSpeed'=>$items['remote_ifspeed'], | 
					
						
							|  |  |  |         'ifOperStatus'=>$items['remote_ifoperstatus'], | 
					
						
							|  |  |  |         'ifAdminStatus'=>$items['remote_adminstatus'], | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-06-01 23:27:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |     $local_device_id = $items['local_device_id']; | 
					
						
							|  |  |  |     if (!array_key_exists($local_device_id, $devices_by_id)) { | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |         $items['sysName'] = $items['local_sysName']; | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |         $devices_by_id[$local_device_id] = array( | 
					
						
							|  |  |  |             'id'=>$local_device_id, | 
					
						
							|  |  |  |             'label'=>shorthost(format_hostname($items, $items['local_hostname']), 1), | 
					
						
							|  |  |  |             'title'=>generate_device_link($local_device, '', array(), '', '', '', 0), | 
					
						
							|  |  |  |             'shape'=>'box', | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         if ($items['local_disabled'] != '0') { | 
					
						
							|  |  |  |             $devices_by_id[$local_device_id] = array_merge($devices_by_id[$local_device_id], $node_disabled_style); | 
					
						
							|  |  |  |         } elseif ($items['local_status'] == '0') { | 
					
						
							|  |  |  |             $devices_by_id[$local_device_id] = array_merge($devices_by_id[$local_device_id], $node_down_style); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-01 23:27:41 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | 
 | 
					
						
							|  |  |  |     $remote_device_id = $items['remote_device_id']; | 
					
						
							|  |  |  |     if (!array_key_exists($remote_device_id, $devices_by_id)) { | 
					
						
							| 
									
										
										
										
											2017-02-21 02:04:18 -06:00
										 |  |  |         $items['sysName'] = $items['remote_sysName']; | 
					
						
							| 
									
										
										
										
											2017-05-05 12:25:58 +01:00
										 |  |  |         $devices_by_id[$remote_device_id] = array('id'=>$remote_device_id,'label'=>shorthost(format_hostname($items, $items['remote_hostname']), 1),'title'=>generate_device_link($remote_device, '', array(), '', '', '', 0),'shape'=>'box'); | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |         if ($items['remote_disabled'] != '0') { | 
					
						
							|  |  |  |             $devices_by_id[$remote_device_id] = array_merge($devices_by_id[$remote_device_id], $node_disabled_style); | 
					
						
							|  |  |  |         } elseif ($items['remote_status'] == '0') { | 
					
						
							|  |  |  |             $devices_by_id[$remote_device_id] = array_merge($devices_by_id[$remote_device_id], $node_down_style); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-06-01 23:27:41 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |     $speed = $items['local_ifspeed']/1000/1000; | 
					
						
							| 
									
										
										
										
											2017-11-02 04:14:03 +00:00
										 |  |  |     if ($speed > 500000) { | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |         $width = 20; | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-11-02 04:14:03 +00:00
										 |  |  |         $width = round(0.77 * pow($speed, 0.25)); | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |     } | 
					
						
							|  |  |  |     $link_in_used = ($items['local_ifinoctets_rate'] * 8) / $items['local_ifspeed'] * 100; | 
					
						
							|  |  |  |     $link_out_used = ($items['local_ifoutoctets_rate'] * 8) / $items['local_ifspeed'] * 100; | 
					
						
							|  |  |  |     if ($link_in_used > $link_out_used) { | 
					
						
							|  |  |  |         $link_used = $link_in_used; | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |         $link_used = $link_out_used; | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |     $link_used = round(2 * $link_used, -1) / 2; | 
					
						
							| 
									
										
										
										
											2015-07-14 11:47:42 +01:00
										 |  |  |     if ($link_used > 100) { | 
					
						
							|  |  |  |         $link_used = 100; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $link_style = array('color' => array('border' => $config['network_map_legend'][$link_used], 'highlight' => $config['network_map_legend'][$link_used], 'color' => $config['network_map_legend'][$link_used])); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (($items['remote_ifoperstatus'] == 'down') || ($items['local_ifoperstatus'] == 'down')) { | 
					
						
							|  |  |  |         $link_style = $edge_down_style; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (($items['remote_disabled'] != '0') && ($items['local_disabled'] != '0')) { | 
					
						
							|  |  |  |         $link_style = $edge_disabled_style; | 
					
						
							|  |  |  |     } elseif (($items['remote_status'] == '0') && ($items['local_status'] == '0')) { | 
					
						
							|  |  |  |         $link_style = $edge_down_style; | 
					
						
							|  |  |  |     } elseif (($items['remote_status'] == '1' && $items['remote_ifoperstatus'] == 'down') || ($items['local_status'] == '1' && $items['local_ifoperstatus'] == 'down')) { | 
					
						
							|  |  |  |         $link_style = $edge_down_style; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |     $link_id1 = $items['local_port_id'].':'.$items['remote_port_id']; | 
					
						
							|  |  |  |     $link_id2 = $items['remote_port_id'].':'.$items['local_port_id']; | 
					
						
							|  |  |  |     $device_id1 = $items['local_device_id'].':'.$items['remote_device_id']; | 
					
						
							|  |  |  |     $device_id2 = $items['remote_device_id'].':'.$items['local_device_id']; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Ensure only one link exists between any two ports, or any two devices.
 | 
					
						
							|  |  |  |     if (!array_key_exists($link_id1, $link_assoc_seen) && | 
					
						
							|  |  |  |         !array_key_exists($link_id2, $link_assoc_seen) && | 
					
						
							|  |  |  |         !array_key_exists($device_id1, $device_assoc_seen) && | 
					
						
							|  |  |  |         !array_key_exists($device_id2, $device_assoc_seen)) { | 
					
						
							| 
									
										
										
										
											2017-04-04 08:08:23 +01:00
										 |  |  |         $local_port = cleanPort($local_port); | 
					
						
							|  |  |  |         $remote_port = cleanPort($remote_port); | 
					
						
							| 
									
										
										
										
											2018-08-04 23:05:15 +02:00
										 |  |  |         $links[] = array_merge( | 
					
						
							|  |  |  |             array( | 
					
						
							|  |  |  |                 'from'=>$items['local_device_id'], | 
					
						
							|  |  |  |                 'to'=>$items['remote_device_id'], | 
					
						
							|  |  |  |                 'label'=>shorten_interface_type($local_port['ifName']) . ' > ' . shorten_interface_type($remote_port['ifName']), | 
					
						
							|  |  |  |                 'title'=>generate_port_link($local_port, "<img src='graph.php?type=port_bits&id=".$items['local_port_id']."&from=".$config['time']['day']."&to=".$config['time']['now']."&width=100&height=20&legend=no&bg=".str_replace("#", "", $row_colour)."'>\n", '', 0, 1), | 
					
						
							|  |  |  |                 'width'=>$width, | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             $link_style | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2015-07-15 20:09:20 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  |     $link_assoc_seen[$link_id1] = 1; | 
					
						
							|  |  |  |     $link_assoc_seen[$link_id2] = 1; | 
					
						
							|  |  |  |     $device_assoc_seen[$device_id1] = 1; | 
					
						
							|  |  |  |     $device_assoc_seen[$device_id2] = 1; | 
					
						
							| 
									
										
										
										
											2015-06-01 23:27:41 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | $nodes = json_encode(array_values($devices_by_id)); | 
					
						
							|  |  |  | $edges = json_encode($links); | 
					
						
							| 
									
										
										
										
											2015-06-02 00:37:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-05 21:45:46 +09:30
										 |  |  | if (count($devices_by_id) > 1 && count($links) > 0) { | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | ?>
 | 
					
						
							| 
									
										
										
										
											2018-04-07 15:55:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | <div id="visualization"></div> | 
					
						
							| 
									
										
										
										
											2015-03-29 02:11:55 +01:00
										 |  |  | <script src="js/vis.min.js"></script> | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | <script type="text/javascript"> | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  | var height = $(window).height() - 100; | 
					
						
							|  |  |  | $('#visualization').height(height + 'px'); | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |     // create an array with nodes
 | 
					
						
							|  |  |  |     var nodes = | 
					
						
							|  |  |  | <?php | 
					
						
							|  |  |  | echo $nodes; | 
					
						
							|  |  |  | ?>
 | 
					
						
							|  |  |  |     ; | 
					
						
							| 
									
										
										
										
											2018-04-07 15:55:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |     // create an array with edges
 | 
					
						
							|  |  |  |     var edges = | 
					
						
							|  |  |  | <?php | 
					
						
							|  |  |  | echo $edges; | 
					
						
							|  |  |  | ?>
 | 
					
						
							|  |  |  |     ; | 
					
						
							| 
									
										
										
										
											2018-04-07 15:55:28 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |     // create a network
 | 
					
						
							|  |  |  |     var container = document.getElementById('visualization'); | 
					
						
							|  |  |  |     var data = { | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |         nodes: nodes, | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |         edges: edges, | 
					
						
							| 
									
										
										
										
											2015-07-14 13:11:54 +01:00
										 |  |  |         stabilize: true | 
					
						
							| 
									
										
										
										
											2015-04-17 19:56:46 +01:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2015-07-29 01:17:08 +02:00
										 |  |  |     var options =  <?php echo $config['network_map_vis_options']; ?>;
 | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  |     var network = new vis.Network(container, data, options); | 
					
						
							| 
									
										
										
										
											2015-03-28 00:53:35 +00:00
										 |  |  |     network.on('click', function (properties) { | 
					
						
							|  |  |  |         if (properties.nodes > 0) { | 
					
						
							| 
									
										
										
										
											2017-10-15 16:26:01 +02:00
										 |  |  |             window.location.href = "device/device="+properties.nodes+"/tab=neighbours/selection=map/" | 
					
						
							| 
									
										
										
										
											2015-03-28 00:53:35 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | </script> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | <?php | 
					
						
							| 
									
										
										
										
											2016-08-18 20:28:22 -05:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2015-06-02 00:37:34 +01:00
										 |  |  |     print_message("No map to display, this may be because you aren't running autodiscovery or no devices are linked by mac address."); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-28 13:59:23 +00:00
										 |  |  | $pagetitle[] = "Map"; |