Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ jobs:
run: |
set -euo pipefail
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y \
sudo apt-get -o Acquire::Retries=3 update
sudo apt-get -o Acquire::Retries=3 install -y \
php8.6-cli php8.6-common \
php8.6-intl php8.6-mysql php8.6-gd php8.6-ldap \
php8.6-gmp php8.6-xml php8.6-curl php8.6-mbstring \
Expand All @@ -138,7 +138,7 @@ jobs:
# setup-php normally provides Composer; it is skipped for this leg, so
# make sure a Composer binary is available for the dependency steps.
if ! command -v composer >/dev/null 2>&1; then
sudo apt-get install -y composer
sudo apt-get -o Acquire::Retries=3 install -y composer
fi
php -v
composer --version
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* issue#446: Keep MacTrack enabled when an ARP/IP, site, device, IP range, 802.1x, MAC or interface view query fails or times out; the record functions returned false from a typed array return and the resulting TypeError made Cacti disable the plugin
* issue#446: Join interfaces on site_id and device_id in the ARP/IP view so the query uses the primary key instead of scanning the interface table for every row
* issue#448: Retain failed scan loads, stop incomplete scan-date reconciliation, and restart aggregate rebuilds without replaying counts; preserve ambiguous legacy rebuild tables for recovery
* issue#453: Open the IP Addresses report from IP Ranges with the Most Recent scan selected; the link passed scan_date=3, which only the MAC Addresses report knows (Aggregated), so the report showed no rows
* issue: Add a tooltip to the interfaces 'Show Totals' control explaining what the totals columns show
* issue: Align the documented PHP floor with the PHP 8.2 CI/test contract
* issue: Call mactrack_format_mac() from the ARP export instead of a function that does not exist
Expand Down Expand Up @@ -90,6 +91,7 @@
* feature#426: Partition mac_track_ports by scan date, weekly by default, with daily and legacy per-scan or hourly sizes, so retention drops expired partitions instead of deleting rows; new installs are partitioned and existing tables can be converted between daily, weekly and unpartitioned layouts from Utilities or cli/upgrade_partitioning.php; Utilities rebuilds and analyzes only the latest populated partition (also on the legacy daily layout), maintenance keeps two days of partitions created ahead (daily slots that per-scan partitions are carved from) so scans move no rows in normal operation, and named retention settings keep their day count across DST
* feature#435: Leave MACs on ports matching a regular expression out of a scan, so uplink and trunk ports stay out of the database: a new Ports to Ignore While Scanning setting for all devices plus a regular expression on each site and device, matched without regard to case against the port name and alias. The filter runs where every scanner stores its results, an invalid expression is logged and skipped, and the device run message reports how many MACs were skipped; the regular expression fields are text areas like the device Ports to Ignore, and each line is its own expression
* feature#451: Partition the IP address table (mac_track_ips) by scan date like the port table, and replace mactrack_convert.php with cli/upgrade_partitioning.php. It checks both tables against the Port Partition Size setting (or --partition=daily|weekly|disabled, which it saves as the setting; Disabled is now a setting value), reports when there is no drift, and rebuilds each drifted table in turn: rename it to <table>_rebuild, create it again with the retention and partitioning scheme, copy each scan date, then drop the original. The run is registered in the process registry, pauses scanning and database maintenance (a maintenance window that passes meanwhile is run by the poller as soon as the rebuild ends), shows a maintenance message on the MAC and IP address views, refuses changes to the history and defers the background database upgrade until it has finished, prints progress, and resumes after an interruption; new installs partition the IP table (following the saved Port Partition Size) and its retention drops whole partitions; --keep-old is removed; the README describes setting up and maintaining partitioning
* feature#455: Add the vendor Virtual/KVM Host for the unregistered MAC prefix 52:54:00 (QEMU/KVM virtual network cards) to the OUI database when the plugin is upgraded and after every IEEE OUI import, which removes the vendors the IEEE list does not hold; a prefix the database already holds is kept
* feature: Add a Dashboard tab (the first MacTrack tab) presenting admin status cards in a draggable, add/remove
* feature: Add a root manifest.json and upgrade-time file pruning (mactrack_prune_files()) that removes tombstoned and dev-only paths
* feature: Add a status pill column to the 802.1x view after the username; clicking the pill drills down by setting the Status filter to that session status
Expand Down
29 changes: 29 additions & 0 deletions lib/mactrack_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3854,6 +3854,32 @@ function mactrack_ports_load(string $table = 'mac_track_ports', int $batch = 100
return $read;
}

/**
* Well known MAC prefixes that no vendor has registered with the IEEE, so no
* OUI download holds them, keyed by the prefix as the OUI table stores it.
* 52:54:00 is the prefix QEMU/KVM gives its virtual network cards.
*/
const MACTRACK_KNOWN_VENDOR_MACS = [
'525400' => 'Virtual/KVM Host',
];

/**
* Adds the well known unregistered MAC prefixes to the OUI table. A prefix
* the table already holds, such as one the IEEE registers later, is kept. The
* upgrade runs this, and so does every OUI import, because a full import
* deletes the vendors the IEEE list does not hold.
*
* @return void
*/
function mactrack_ensure_known_vendor_macs(): void {
foreach (MACTRACK_KNOWN_VENDOR_MACS as $vendor_mac => $vendor_name) {
db_execute_prepared('INSERT IGNORE INTO mac_track_oui_database
(vendor_mac, vendor_name, vendor_address, present)
VALUES (?, ?, ?, 1)',
[(string) $vendor_mac, $vendor_name, '']);
}
}

/**
* Downloads the IEEE OUI (vendor MAC prefix) database text file and
* imports its vendor/MAC-prefix/address records into the
Expand Down Expand Up @@ -3990,6 +4016,9 @@ function import_oui_database($type = 'ui', $oui_file = 'https://standards-oui.ie
// set correct format
db_execute("UPDATE mac_track_oui_database SET vendor_mac = REPLACE(vendor_mac, ':', '')");

// the import retires vendors the IEEE list does not hold
mactrack_ensure_known_vendor_macs();

// report some information
if ($type != 'ui') {
print '<tr><td>';
Expand Down
2 changes: 1 addition & 1 deletion mactrack_view_ips.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function mactrack_view_ip_ranges(): void {
'&ip_filter_type_id=3' .
'&ip_filter=' . $ip_range['ip_range'] . '.' .
'&device_id=-1' .
'&scan_date=3' .
'&scan_date=2' .
'&site_id=' . $ip_range['site_id']) . '" title="' . __esc('View IP Addresses', 'mactrack') . '"><i class="mtPorts fas fa-desktop"></i></a>';

form_alternate_row('line' . $i, true);
Expand Down
3 changes: 3 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ function mactrack_perform_upgrade(): bool {
[$info['longname'], $info['author'], $info['homepage'], $info['version'], $id]);
}

// the IEEE list has no record of these well known prefixes
mactrack_ensure_known_vendor_macs();

mactrack_retry_default_site();

return true;
Expand Down
252 changes: 126 additions & 126 deletions tests/Unit/DeviceTypeSqlSafetyTest.php
Original file line number Diff line number Diff line change
@@ -1,126 +1,126 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/
/*
* Converted from the standalone tests/Unit/test_device_type_sql_safety.php
* script. Guards against regressing the SQL-injection, XSS, command-injection,
* path-traversal, and dependency-verification fixes applied across mactrack.
*/
it('quotes the device-type vendor filter instead of concatenating request input', function () {
$source = plugin_test_read_source('mactrack_device_types.php');
expect($source)->not->toContain("(mtdt.vendor='\" . get_request_var('vendor')");
expect($source)->toContain("mtdt.vendor = ' . db_qstr(get_request_var('vendor'))");
});
it('normalizes IDs and uses prepared SQL for aggregated MAC deletion', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');
expect($source)->toContain('function mactrack_normalize_ids(array $ids): array');
expect($source)->toContain("db_execute_prepared('DELETE FROM mac_track_aggregated_ports WHERE row_id IN('");
});
it('uses escaped JSON instead of request deserialization for MAC authorization actions', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');
expect($source)->not->toContain("unserialize(get_nfilter_request_var('selected_items')");
expect($source)->toContain("json_decode(get_nfilter_request_var('selected_items'), true)");
expect($source)->toContain('html_escape(json_encode($mac_address_array))');
});
it('uses escaped JSON and contextual output encoding for MAC action form values', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');
expect($source)->not->toContain("sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'))");
expect($source)->toContain('html_escape(json_encode($row_array))');
expect($source)->toContain("html_escape((string) get_request_var('drp_action'))");
});
it('escapes the executable and script paths used by rescan commands', function () {
$source = plugin_test_read_source('lib/mactrack_functions.php');
expect($source)->toContain("cacti_escapeshellcmd(read_config_option('path_php_binary'))");
expect($source)->toContain('cacti_escapeshellarg($command_string)');
});
it('parameterizes site IDs and normalizes PIDs during poller process cleanup', function () {
$source = plugin_test_read_source('poller_mactrack.php');
expect($source)->toContain('site_id = ?');
expect($source)->toContain("intval(\$p['process_id'])");
});
it('escapes the executable and device endpoint values in the Cabletron SNMP command', function () {
$source = plugin_test_read_source('lib/mactrack_cabletron.php');
expect($source)->toContain("cacti_escapeshellcmd(read_config_option('path_snmpgetnext'))");
expect($source)->toContain('cacti_escapeshellarg($device[\'hostname\'] . \':\' . intval($device[\'snmp_port\']))');
});
it('uses safe RLIKE quoting and normalized numeric values for interface filters', function () {
$source = plugin_test_read_source('mactrack_view_interfaces.php');
expect($source)->toContain('mactrack_get_ignore_ports_predicate($sql_params)');
expect($source)->toContain('db_fetch_assoc_prepared($sql_query, $sql_params)');
expect($source)->toContain('db_fetch_cell_prepared($rows_query_string, $sql_params)');
expect($source)->not->toContain('db_qstr($match)');
expect($source)->not->toContain('db_qstr_rlike');
expect($source)->toContain("intval(get_filter_request_var('bwusage'))");
});
it('normalizes numeric values in the device report SQL filters', function () {
$source = plugin_test_read_source('mactrack_view_devices.php');
expect($source)->toContain("intval(get_filter_request_var('status'))");
expect($source)->toContain("intval(get_filter_request_var('site_id'))");
});
it('normalizes numeric values in the administrative device SQL filters', function () {
$source = plugin_test_read_source('mactrack_devices.php');
expect($source)->toContain("intval(get_filter_request_var('status'))");
expect($source)->toContain("intval(get_filter_request_var('site_id'))");
});
it('validates canonical regular-file paths before importing an OUI database', function () {
$source = plugin_test_read_source('mactrack_import_ouidb.php');
expect($source)->toContain('function mactrack_validate_oui_file(string $path): string');
expect($source)->toContain('is_file($resolved)');
expect($source)->toContain('is_readable($resolved)');
});
it('preserves PHP 8 compatible argument order for the 1.2.31 signatures', function () {
$arpSource = plugin_test_read_source('mactrack_view_arp.php');
$dot1xSource = plugin_test_read_source('mactrack_view_dot1x.php');
$ajaxSource = plugin_test_read_source('mactrack_ajax.php');
expect($arpSource)->toContain('function mactrack_view_get_ip_records(&$sql_where, $rows, $apply_limits = true)');
expect($dot1xSource)->toContain('function mactrack_view_get_dot1x_records(&$sql_where, &$sql_params, $rows, $apply_limits = true)');
expect($arpSource)->toContain('mactrack_format_mac(');
expect($arpSource)->not->toContain('format_mac_address(');
expect($ajaxSource)->not->toContain('mactrack_save_graph_settings');
});
it('loads Net_DNS2 from the bundled Net/ directory and reports rather than fatals when missing', function () {
$source = plugin_test_read_source('mactrack_resolver.php');
expect($source)->toContain("'/plugins/mactrack' . PATH_SEPARATOR . get_include_path()");
expect($source)->toContain('if (is_file($dns2))');
expect($source)->toContain("class_exists('Net_DNS2_Resolver')");
});
it('never gates plugin enablement on the optional DNS library', function () {
$source = plugin_test_read_source('setup.php');
expect($source)->not->toContain('Net_DNS2');
expect($source)->not->toContain('Net/DNS2.php');
});
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
* Converted from the standalone tests/Unit/test_device_type_sql_safety.php
* script. Guards against regressing the SQL-injection, XSS, command-injection,
* path-traversal, and dependency-verification fixes applied across mactrack.
*/

it('quotes the device-type vendor filter instead of concatenating request input', function () {
$source = plugin_test_read_source('mactrack_device_types.php');

expect($source)->not->toContain("(mtdt.vendor='\" . get_request_var('vendor')");
expect($source)->toContain("mtdt.vendor = ' . db_qstr(get_request_var('vendor'))");
});

it('normalizes IDs and uses prepared SQL for aggregated MAC deletion', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');

expect($source)->toContain('function mactrack_normalize_ids(array $ids): array');
expect($source)->toContain("db_execute_prepared('DELETE FROM mac_track_aggregated_ports WHERE row_id IN('");
});

it('uses escaped JSON instead of request deserialization for MAC authorization actions', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');

expect($source)->not->toContain("unserialize(get_nfilter_request_var('selected_items')");
expect($source)->toContain("json_decode(get_nfilter_request_var('selected_items'), true)");
expect($source)->toContain('html_escape(json_encode($mac_address_array))');
});

it('uses escaped JSON and contextual output encoding for MAC action form values', function () {
$source = plugin_test_read_source('mactrack_view_macs.php');

expect($source)->not->toContain("sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'))");
expect($source)->toContain('html_escape(json_encode($row_array))');
expect($source)->toContain("html_escape((string) get_request_var('drp_action'))");
});

it('escapes the executable and script paths used by rescan commands', function () {
$source = plugin_test_read_source('lib/mactrack_functions.php');

expect($source)->toContain("cacti_escapeshellcmd(read_config_option('path_php_binary'))");
expect($source)->toContain('cacti_escapeshellarg($command_string)');
});

it('parameterizes site IDs and normalizes PIDs during poller process cleanup', function () {
$source = plugin_test_read_source('poller_mactrack.php');

expect($source)->toContain('site_id = ?');
expect($source)->toContain("intval(\$p['process_id'])");
});

it('escapes the executable and device endpoint values in the Cabletron SNMP command', function () {
$source = plugin_test_read_source('lib/mactrack_cabletron.php');

expect($source)->toContain("cacti_escapeshellcmd(read_config_option('path_snmpgetnext'))");
expect($source)->toContain('cacti_escapeshellarg($device[\'hostname\'] . \':\' . intval($device[\'snmp_port\']))');
});

it('uses safe RLIKE quoting and normalized numeric values for interface filters', function () {
$source = plugin_test_read_source('mactrack_view_interfaces.php');

expect($source)->toContain('mactrack_get_ignore_ports_predicate($sql_params)');
expect($source)->toContain('db_fetch_assoc_prepared($sql_query, $sql_params)');
expect($source)->toContain('db_fetch_cell_prepared($rows_query_string, $sql_params)');
expect($source)->not->toContain('db_qstr($match)');
expect($source)->not->toContain('db_qstr_rlike');
expect($source)->toContain("intval(get_filter_request_var('bwusage'))");
});

it('normalizes numeric values in the device report SQL filters', function () {
$source = plugin_test_read_source('mactrack_view_devices.php');

expect($source)->toContain("intval(get_filter_request_var('status'))");
expect($source)->toContain("intval(get_filter_request_var('site_id'))");
});

it('normalizes numeric values in the administrative device SQL filters', function () {
$source = plugin_test_read_source('mactrack_devices.php');

expect($source)->toContain("intval(get_filter_request_var('status'))");
expect($source)->toContain("intval(get_filter_request_var('site_id'))");
});

it('validates canonical regular-file paths before importing an OUI database', function () {
$source = plugin_test_read_source('mactrack_import_ouidb.php');

expect($source)->toContain('function mactrack_validate_oui_file(string $path): string');
expect($source)->toContain('is_file($resolved)');
expect($source)->toContain('is_readable($resolved)');
});

it('preserves PHP 8 compatible argument order for the 1.2.31 signatures', function () {
$arpSource = plugin_test_read_source('mactrack_view_arp.php');
$dot1xSource = plugin_test_read_source('mactrack_view_dot1x.php');
$ajaxSource = plugin_test_read_source('mactrack_ajax.php');

expect($arpSource)->toContain('function mactrack_view_get_ip_records(&$sql_where, $rows, $apply_limits = true)');
expect($dot1xSource)->toContain('function mactrack_view_get_dot1x_records(&$sql_where, &$sql_params, $rows, $apply_limits = true)');

expect($arpSource)->toContain('mactrack_format_mac(');
expect($arpSource)->not->toContain('format_mac_address(');
expect($ajaxSource)->not->toContain('mactrack_save_graph_settings');
});

it('loads Net_DNS2 from the bundled Net/ directory and reports rather than fatals when missing', function () {
$source = plugin_test_read_source('mactrack_resolver.php');

expect($source)->toContain("'/plugins/mactrack' . PATH_SEPARATOR . get_include_path()");
expect($source)->toContain('if (is_file($dns2))');
expect($source)->toContain("class_exists('Net_DNS2_Resolver')");
});

it('never gates plugin enablement on the optional DNS library', function () {
$source = plugin_test_read_source('setup.php');

expect($source)->not->toContain('Net_DNS2');
expect($source)->not->toContain('Net/DNS2.php');
});
Loading
Loading