From bef9a58fd650e845ba4dc26c5e64599369f4d2e6 Mon Sep 17 00:00:00 2001 From: xxconn Date: Thu, 8 Jan 2026 13:52:30 +0800 Subject: [PATCH 1/9] Update mactrack_cisco.php Modified --- lib/mactrack_cisco.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/mactrack_cisco.php b/lib/mactrack_cisco.php index 83e23a06..a1eeeda5 100644 --- a/lib/mactrack_cisco.php +++ b/lib/mactrack_cisco.php @@ -106,12 +106,12 @@ function get_catalyst_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $high /* calculate the number of end user ports */ if (cacti_sizeof($portTrunking)) { - foreach ($portTrunking as $portTrunk) { - if ($portTrunk == 1) { - $device['ports_trunk']++; + foreach ($portTrunking as $portTrunk) { + if ($portTrunk == 1) { + $device['ports_trunk']++; + } } } - } /* build VLAN array from results */ $i = 0; @@ -301,6 +301,16 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $device['vlans_total'] = cacti_sizeof($vlan_ids) - 4; mactrack_debug('There are ' . (cacti_sizeof($vlan_ids)-4) . ' VLANS.'); + if (cacti_sizeof($vlan_names) == 0) { + cacti_log('No VLANs Name found: ' . $device['device_name']); + return $device; + } + + if (cacti_sizeof($vlan_trunkstatus) == 0) { + cacti_log('No VLANs Trunk Status found: ' . $device['device_name']); + return $device; + } + /* get the Voice VLAN information if it exists */ $portVoiceVLANs = xform_standard_indexed_data('.1.3.6.1.4.1.9.9.87.1.4.1.1.37.0', $device); if (cacti_sizeof($portVoiceVLANs) > 0) { @@ -485,6 +495,7 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $portNumber = (isset($ifInterfaces[$ifIndex]['ifName']) ? $ifInterfaces[$ifIndex]['ifName'] : ''); $portName = (isset($ifInterfaces[$ifIndex]['ifAlias']) ? $ifInterfaces[$ifIndex]['ifAlias'] : ''); $portTrunk = (isset($portTrunking[$ifName]) ? $portTrunking[$ifName] : ''); + $portTrunkStatus = (isset($ifInterfaces[$ifIndex]['trunkPortState']) ? $ifInterfaces[$ifIndex]['trunkPortState'] : ''); if ($vvlans) { $vVlanID = (isset($portVoiceVLANs[$ifIndex]) ? $portVoiceVLANs[$ifIndex] : ''); @@ -492,12 +503,14 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $vVlanID = -1; } - $portTrunkStatus = (isset($ifInterfaces[$ifIndex]['trunkPortState']) ? $ifInterfaces[$ifIndex]['trunkPortState'] : ''); - /* only output legitimate end user ports */ + /* ifType: 6 = ethernetCsmacd + 53 = propVirtual + 161 = ieee8023adLag + */ if ($ifType == 6 || $ifType == 53 || $ifType == 161) { if (($portTrunkStatus == '2') || - (empty($portTrunkStatus)) || + //(empty($portTrunkStatus)) || (in_array($portNumber, $scan_trunk_port)) || (($vVlanID > 0) && ($vVlanID <= 1000))) { $port_array[$i]['vlan_id'] = $active_vlan['vlan_id']; From 480b747b49ac011f53ef0257bcdc5ff5baec7700 Mon Sep 17 00:00:00 2001 From: xxconn Date: Thu, 8 Jan 2026 14:16:35 +0800 Subject: [PATCH 2/9] Update mactrack_functions.php Modified --- lib/mactrack_functions.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/mactrack_functions.php b/lib/mactrack_functions.php index b327a1c5..291ad4f9 100644 --- a/lib/mactrack_functions.php +++ b/lib/mactrack_functions.php @@ -1352,9 +1352,10 @@ function get_base_dot1dTpFdbEntry_ports($site, &$device, &$ifInterfaces, $snmp_r $brPortIfType = @$ifInterfaces[$port_key['port_number']]['ifType']; } - if (($brPortIfType >= 6) && - ($brPortIfType <= 9) && - (!isset($ifInterfaces[$brPortIfIndex]['portLink']))) { + if ((($brPortIfType >= 6 && $brPortIfType <= 9) || + $brPortIfType == 53 || $brPortIfType == 161) && + (!isset($ifInterfaces[$brPortIfIndex]["portLink"]))) { + /* set some defaults */ $new_port_key_array[$i]['vlan_id'] = 'N/A'; $new_port_key_array[$i]['vlan_name'] = 'N/A'; @@ -2309,7 +2310,7 @@ function db_store_device_port_results(&$device, $port_array, $scan_date) { if ($port_value['port_number'] <> 'NOT USER' && $port_value['mac_address'] <> 'NOT USER' && $port_value['mac_address'] != '') { $mac_authorized = db_check_auth($port_value['mac_address']); - mactrack_debug('MAC Address \'' . $port_value['mac_address'] . '\' on device \'' . $device['device_name'] . '\' is ' . ($mac_authorized != '' ? '':'NOT') . ' Authorized'); + mactrack_debug('MAC Address \'' . $port_value['mac_address'] . '\' on device \'' . $device['device_name'] . '\' is ' . ($mac_authorized != '' ? '':'NOT ') . ' Authorized'); if ($mac_authorized != '') { $authorized_mac = 1; From 651bd4b61cb616676039c9bca0d56b25ed2314e0 Mon Sep 17 00:00:00 2001 From: xxconn Date: Fri, 9 Jan 2026 09:18:24 +0800 Subject: [PATCH 3/9] Update mactrack_cisco.php More detailed debug output --- lib/mactrack_cisco.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/mactrack_cisco.php b/lib/mactrack_cisco.php index a1eeeda5..d324fad4 100644 --- a/lib/mactrack_cisco.php +++ b/lib/mactrack_cisco.php @@ -522,8 +522,11 @@ function get_IOS_dot1dTpFdbEntry_ports($site, &$device, $lowPort = 0, $highPort $port_array[$i]['portTrunkStatus'] = $portTrunkStatus; $i++; - mactrack_debug('VLAN: ' . $active_vlan['vlan_id'] . ', ' . + mactrack_debug('HOST: ' . $device['hostname'] . ', ' . + 'VLAN: ' . $active_vlan['vlan_id'] . ', ' . 'NAME: ' . $active_vlan['vlan_name'] . ', ' . + 'TRUNK: ' . $portTrunkStatus . ', ' . + 'TYPE: ' . $ifType . ', ' . 'PORT: ' . $portNumber . ', ' . 'NAME: ' . $portName . ', ' . 'MAC: ' . $port_result['mac_address']); From 27ff0df4cf4c5c892597c789b7bd3b029a45bfd0 Mon Sep 17 00:00:00 2001 From: xxconn Date: Fri, 9 Jan 2026 09:34:10 +0800 Subject: [PATCH 4/9] Update poller_mactrack.php Processing one mac address with multiple IPs --- poller_mactrack.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/poller_mactrack.php b/poller_mactrack.php index f6601b62..5259b403 100644 --- a/poller_mactrack.php +++ b/poller_mactrack.php @@ -977,11 +977,15 @@ function collect_mactrack_data($start, $site_id = 0) { (site_id, device_id, hostname, device_name, vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname, port_number, port_name, date_last, first_scan_date, count_rec, active_last, authorized) - SELECT site_id, device_id, hostname, device_name, - vlan_id, vlan_name, mac_address, vendor_mac, ip_address, dns_hostname, - port_number, port_name, scan_date, scan_date, 1, 1, authorized - FROM mac_track_temp_ports - ON DUPLICATE KEY UPDATE count_rec=count_rec + 1, active_last = 1, date_last = mac_track_temp_ports.scan_date'); + SELECT t1.site_id, t1.device_id, t1.hostname, t1.device_name, + vlan_id, vlan_name, t1.mac_address, vendor_mac, t2.ip_address, t1.dns_hostname, + t1.port_number, t1.port_name, t1.scan_date, t1.scan_date, 1, 1, authorized + FROM mac_track_temp_ports t1 + INNER JOIN mac_track_ips t2 + ON (t1.mac_address=t2.mac_address + AND t1.site_id =t2.site_id + AND t2.scan_date ="' . $scan_date .'") + ON DUPLICATE KEY UPDATE count_rec=count_rec+1, active_last=1, date_last=t1.scan_date,port_name=t1.port_name'); /* purge the ip address and temp port table */ db_execute('TRUNCATE TABLE mac_track_temp_ports'); From 5955e58632fc45f719596392a355da0ebad94d73 Mon Sep 17 00:00:00 2001 From: xxconn Date: Fri, 9 Jan 2026 09:45:25 +0800 Subject: [PATCH 5/9] Update mactrack_view_macs.php Add 'Site Name' to the result. --- mactrack_view_macs.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mactrack_view_macs.php b/mactrack_view_macs.php index c6f7bf5e..debe0f85 100644 --- a/mactrack_view_macs.php +++ b/mactrack_view_macs.php @@ -404,7 +404,7 @@ function mactrack_view_macs_validate_request_vars() { ), 'sort_column' => array( 'filter' => FILTER_CALLBACK, - 'default' => 'ip_address', + 'default' => 'site_name', 'options' => array('options' => 'sanitize_search_string') ), 'sort_direction' => array( @@ -698,6 +698,10 @@ function mactrack_view_macs() { 'nosort' => array( 'display' => __('Actions', 'mactrack'), ), + 'site_name' => array( + 'display' => __('Site Name', 'mactrack'), + 'sort' => 'ASC' + ), 'device_name' => array( 'display' => __('Switch Name', 'mactrack'), 'sort' => 'ASC' @@ -800,6 +804,7 @@ function mactrack_view_macs() { form_alternate_row('line' . $key, true); form_selectable_cell(mactrack_interface_actions($port_result['device_id'], $port_result['port_number'], false), $key, '1%'); + form_selectable_cell($port_result['site_name'], $key); form_selectable_cell($port_result['device_name'], $key); form_selectable_cell($port_result['hostname'], $key); form_selectable_cell(filter_value($port_result['ip_address'], get_request_var('filter')), $key); @@ -892,6 +897,10 @@ function mactrack_view_aggregated_macs() { } $display_text = array( + 'site_name' => array( + 'display' => __('Site Name', 'mactrack'), + 'sort' => 'ASC' + ), 'device_name' => array( 'display' => __('Switch Name', 'mactrack'), 'sort' => 'ASC' From 0d79d21525fe1ddac5d0262ce81a9a4c1401e435 Mon Sep 17 00:00:00 2001 From: xxconn Date: Fri, 9 Jan 2026 14:31:20 +0800 Subject: [PATCH 6/9] Update mactrack_view_arp.php Add 'Site Name' to the results --- mactrack_view_arp.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mactrack_view_arp.php b/mactrack_view_arp.php index 2f721d12..0a0b610e 100644 --- a/mactrack_view_arp.php +++ b/mactrack_view_arp.php @@ -321,6 +321,10 @@ function mactrack_view_ips() { } $display_text1 = array( + 'site_name' => array( + 'display' => __('Site Name', 'mactrack'), + 'sort' => 'ASC' + ), 'device_name' => array( 'display' => __('Switch Name', 'mactrack'), 'sort' => 'ASC' @@ -389,7 +393,8 @@ function mactrack_view_ips() { foreach ($port_results as $port_result) { form_alternate_row('line' . $i, true); - form_selectable_cell($port_result['device_name'], $i, '1%'); + form_selectable_cell($port_result['site_name'], $i); + form_selectable_cell($port_result['device_name'], $i, '10%'); form_selectable_cell($port_result['hostname'], $i); form_selectable_cell(filter_value($port_result['ip_address'], get_request_var('filter')), $i); From 649b7b87c6753c4adb1bcdbf06240b890c52a2a1 Mon Sep 17 00:00:00 2001 From: xxconn Date: Thu, 15 Jan 2026 13:23:29 +0800 Subject: [PATCH 7/9] Update mactrack_utilities.php Adjust database maintenance time calculation, run at given time from settings and won't shift the next runtime. --- mactrack_utilities.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mactrack_utilities.php b/mactrack_utilities.php index 58c9536e..cb73b856 100644 --- a/mactrack_utilities.php +++ b/mactrack_utilities.php @@ -110,12 +110,12 @@ function mactrack_display_run_status() { if ($collection_timing != 'disabled') { $seconds_offset = $collection_timing * 60; /* find out if it's time to collect device information */ - $base_start_time = read_config_option('mt_base_time', true); - $database_maint_time = read_config_option('mt_maint_time', true); - $last_run_time = read_config_option('mt_last_run_time', true); - $last_db_maint_time = read_config_option('mt_last_db_maint_time', true); + $base_start_time = read_config_option('mt_base_time', true); + $database_maint_time = read_config_option('mt_maint_time', true); + $last_run_time = read_config_option('mt_last_run_time', true); + $last_db_maint_time = read_config_option('mt_last_db_maint_time', true); $previous_base_start_time = read_config_option('mt_prev_base_time', true); - $previous_db_maint_time = read_config_option('mt_prev_db_maint_time', true); + $previous_db_maint_time = read_config_option('mt_prev_db_maint_time', true); /* see if the user desires a new start time */ if (!empty($previous_base_start_time)) { @@ -125,11 +125,13 @@ function mactrack_display_run_status() { } /* see if the user desires a new db maintenance time */ + /* if (!empty($previous_db_maint_time)) { if ($database_maint_time <> $previous_db_maint_time) { unset($last_db_maint_time); } } + */ /* determine the next start time */ $current_time = strtotime('now'); @@ -150,6 +152,8 @@ function mactrack_display_run_status() { $next_run_time = $last_run_time + $seconds_offset; } + /* determine the next db maintenance time */ + /* if (empty($last_db_maint_time)) { if (strtotime($base_start_time) < $current_time) { $next_db_maint_time = strtotime(date('Y-m-d') . ' ' . $database_maint_time) + 3600*24; @@ -159,6 +163,14 @@ function mactrack_display_run_status() { } else { $next_db_maint_time = $last_db_maint_time + 24*3600; } + */ + + $db_maint_time = strtotime($database_maint_time); + if ($last_db_maint_time < $db_maint_time) { + $next_db_maint_time = $db_maint_time; + } else { + $next_db_maint_time = strtotime('Tomorrow '. $database_maint_time); + } $time_till_next_run = $next_run_time - $current_time; $time_till_next_db_maint = $next_db_maint_time - $current_time; @@ -247,9 +259,13 @@ function applyFilter() { form_alternate_row(); print '' . __('Poller Frequency:', 'mactrack') . '' . ($collection_timing == 'disabled' ? __('N/A', 'mactrack') : $mactrack_poller_frequencies[$collection_timing]) . ''; form_alternate_row(); - print '' . __('Approx. Next Runtime:', 'mactrack') . '' . (empty($next_run_time) ? __('N/A', 'mactrack') : date('Y-m-d G:i:s', $next_run_time)) . ''; + print '' . __('Approx. Next Runtime:', 'mactrack') . '' . (empty($next_run_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $next_run_time)) . ''; + + html_header(array(__('Database Maintenance Information', 'mactrack')), 2); + form_alternate_row(); + print '' . __('Last DB Maintenance Time:', 'mactrack') . '' . (empty($last_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $last_db_maint_time)) . ''; form_alternate_row(); - print '' . __('Approx. Next DB Maintenance:', 'mactrack') . '' . (empty($next_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d G:i:s', $next_db_maint_time)) . ''; + print '' . __('Next DB Maintenance Time:', 'mactrack') . '' . (empty($next_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $next_db_maint_time)) . ''; html_header(array(__('Run Time Details', 'mactrack')), 2); form_alternate_row(); From fe795db7b66ae3174999ada65359855795105c13 Mon Sep 17 00:00:00 2001 From: xxconn Date: Thu, 15 Jan 2026 13:37:01 +0800 Subject: [PATCH 8/9] Update mactrack_functions.php 1. Change partition name and less than value (let partition name equals data datetime (YYYYMMDD) 2. Move mac_track_ips table maintenance from poller_mactrack.php --- lib/mactrack_functions.php | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/mactrack_functions.php b/lib/mactrack_functions.php index 291ad4f9..2aed0328 100644 --- a/lib/mactrack_functions.php +++ b/lib/mactrack_functions.php @@ -2438,6 +2438,7 @@ function perform_mactrack_db_maint() { ORDER BY partition_ordinal_position', array($database_default)); + /* $time = time(); $now = date('Y-m-d', $time); $format = date('Ymd', $time); @@ -2449,12 +2450,25 @@ function perform_mactrack_db_maint() { $lformat = date('Ymd', $lday_ts); $last_day = db_fetch_row("SELECT TO_DAYS('$lnow') AS today"); $last_day = $last_day['today']; + */ + + $tday_ts = strtotime('Today'); + $tday = date('Y-m-d', $tday_ts); + $tdformat = date('Ymd', $tday_ts); + $cur_day = db_fetch_row("SELECT TO_DAYS('$tday') AS today"); + $cur_day = $cur_day['today']; + + $lday_ts = strtotime('Yesterday'); + $lday = date('Y-m-d', $lday_ts); + $ldformat = date('Ymd', $lday_ts); + $last_day = db_fetch_row("SELECT TO_DAYS('$lday') AS today"); + $last_day = $last_day['today']; mactrack_debug("There are currently '" . cacti_sizeof($number_of_partitions) . "' Mactrack Partitions, We will keep '$days' of them."); - mactrack_debug("The current day is '$cur_day', the last day is '$last_day'"); + mactrack_debug("The current day is '$tday($cur_day)', the last day is '$lday($last_day)'"); if ($cur_day != $last_day) { - set_config_option('mactrack_lastday_timestamp', $time); + //set_config_option('mactrack_lastday_timestamp', $time); //no use if ($lday_ts != '') { cacti_log("MACTRACK: Creating new partition 'd" . $lformat . "'", false, "SYSTEM"); @@ -2464,6 +2478,7 @@ function perform_mactrack_db_maint() { PARTITION dMaxValue VALUES LESS THAN MAXVALUE)"); if ($days > 0) { + /* $user_partitions = cacti_sizeof($number_of_partitions) - 1; if ($user_partitions >= $days) { $i = 0; @@ -2477,12 +2492,35 @@ function perform_mactrack_db_maint() { $mactrack_deleted++; } } + */ + + $old_day = date('Ymd', strtotime("- $days Days")); + $old_partitions = db_fetch_assoc_prepared('SELECT PARTITION_NAME + FROM `information_schema`.`partitions` + WHERE table_schema = ? + AND table_name="mac_track_ports" + AND partition_name < ? + ORDER BY partition_ordinal_position', + array($database_default, 'd' . $old_day)); + + if (cacti_sizeof($old_partitions) > 0) { + foreach ($old_partitions as $old_partition) { + cacti_log("MACTRACK: Removing old partition '" . $old_partition['PARTITION_NAME'] . "'", false, "SYSTEM"); + mactrack_debug("Removing partition '" . $old_partition['PARTITION_NAME'] . "'"); + db_execute("ALTER TABLE mac_track_ports DROP PARTITION " . $old_partition['PARTITION_NAME']); + } + } } } } } } + db_execute_prepared('DELETE FROM mac_track_ips + WHERE scan_date < DATE_FORMAT(CURDATE() - ?,"%Y-%m-%d")', + array(read_config_option('mt_data_retention_ip'))); + db_execute('OPTIMIZE TABLE mac_track_ips'); + db_execute('REPLACE INTO mac_track_scan_dates (SELECT DISTINCT scan_date FROM mac_track_ports)'); From c98abc62b5cae40cffdb87f108b12d833baf553a Mon Sep 17 00:00:00 2001 From: xxconn Date: Thu, 15 Jan 2026 13:49:32 +0800 Subject: [PATCH 9/9] Update poller_mactrack.php 1. Adjust database maintenance 2. Move the table mac_track_ips to lib/mactrack_functions.php[perform_mactrack_db_maint] --- poller_mactrack.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/poller_mactrack.php b/poller_mactrack.php index 5259b403..048b34ba 100644 --- a/poller_mactrack.php +++ b/poller_mactrack.php @@ -205,6 +205,7 @@ } /* see if the user desires a new db maintenance time */ + /* mactrack_debug('Checking if user changed the maintenance time'); if (!empty($previous_db_maint_time)) { if ($database_maint_time <> $previous_db_maint_time) { @@ -213,6 +214,7 @@ db_execute("DELETE FROM settings WHERE name='mt_last_db_maint_time'"); } } + */ /* set to detect if the user cleared the time between polling cycles */ set_config_option('mt_prev_base_time', $base_start_time); @@ -243,11 +245,20 @@ mactrack_debug("The next run time has been determined to be at '" . date('Y-m-d G:i:s', $next_run_time) . "'"); } + /* if (empty($last_db_maint_time)) { $next_db_maint_time = strtotime(date('Y-m-d') . ' ' . $database_maint_time); } else { $next_db_maint_time = $last_db_maint_time + 24*3600; } + */ + + $db_maint_time = strtotime($database_maint_time); + if ($last_db_maint_time < $db_maint_time) { + $next_db_maint_time = $db_maint_time; + } else { + $next_db_maint_time = strtotime('Tomorrow '. $database_maint_time); + } $time_till_next_db_maint = $next_db_maint_time - $current_time; if ($time_till_next_db_maint < 0) { @@ -990,11 +1001,14 @@ function collect_mactrack_data($start, $site_id = 0) { /* purge the ip address and temp port table */ db_execute('TRUNCATE TABLE mac_track_temp_ports'); + /* db_execute_prepared('DELETE FROM mac_track_ips WHERE scan_date < NOW() - interval ? DAY', array(read_config_option('mt_data_retention_ip'))); db_execute('OPTIMIZE TABLE mac_track_ips'); + */ + db_execute('TRUNCATE TABLE mac_track_scan_dates'); db_execute('REPLACE INTO mac_track_scan_dates (SELECT DISTINCT scan_date from mac_track_ports)');