Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions lib/mactrack_cisco.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -485,19 +495,22 @@ 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] : '');
} else {
$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'];
Expand All @@ -509,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']);
Expand Down
51 changes: 45 additions & 6 deletions lib/mactrack_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2437,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);
Expand All @@ -2448,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");
Expand All @@ -2463,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;
Expand All @@ -2476,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)');

Expand Down
30 changes: 23 additions & 7 deletions mactrack_utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -247,9 +259,13 @@ function applyFilter() {
form_alternate_row();
print '<td width=200>' . __('Poller Frequency:', 'mactrack') . '</td><td>' . ($collection_timing == 'disabled' ? __('N/A', 'mactrack') : $mactrack_poller_frequencies[$collection_timing]) . '</td>';
form_alternate_row();
print '<td width=200>' . __('Approx. Next Runtime:', 'mactrack') . '</td><td>' . (empty($next_run_time) ? __('N/A', 'mactrack') : date('Y-m-d G:i:s', $next_run_time)) . '</td>';
print '<td width=200>' . __('Approx. Next Runtime:', 'mactrack') . '</td><td>' . (empty($next_run_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $next_run_time)) . '</td>';

html_header(array(__('Database Maintenance Information', 'mactrack')), 2);
form_alternate_row();
print '<td width=200>' . __('Last DB Maintenance Time:', 'mactrack') . '</td><td>' . (empty($last_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $last_db_maint_time)) . '</td>';
form_alternate_row();
print '<td width=200>' . __('Approx. Next DB Maintenance:', 'mactrack') . '</td><td>' . (empty($next_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d G:i:s', $next_db_maint_time)) . '</td>';
print '<td width=200>' . __('Next DB Maintenance Time:', 'mactrack') . '</td><td>' . (empty($next_db_maint_time) ? __('N/A', 'mactrack') : date('Y-m-d H:i:s', $next_db_maint_time)) . '</td>';

html_header(array(__('Run Time Details', 'mactrack')), 2);
form_alternate_row();
Expand Down
7 changes: 6 additions & 1 deletion mactrack_view_arp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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);

Expand Down
11 changes: 10 additions & 1 deletion mactrack_view_macs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
Expand Down
28 changes: 23 additions & 5 deletions poller_mactrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -977,20 +988,27 @@ 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');

/*
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)');

Expand Down