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
1 change: 0 additions & 1 deletion lib/mactrack_extreme.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function get_extreme_switch_ports($site, &$device, $lowPort = 0, $highPort = 0,
foreach ($vlan_ids as $vlan_index => $vlan_id) {
$active_vlans[$i]['vlan_id'] = $vlan_id;
$active_vlans[$i]['vlan_name'] = $vlan_names[$vlan_index];
$active_vlans++;
mactrack_debug('VLAN ID = ' . $active_vlans[$i]['vlan_id'] . ' VLAN Name = ' . $active_vlans[$i]['vlan_name']);
$i++;
}
Expand Down
1 change: 0 additions & 1 deletion lib/mactrack_foundry.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ function get_foundry_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
foreach ($vlan_ids as $vlan_id => $vlan_name) {
$active_vlans[$i]['vlan_id'] = $vlan_id;
$active_vlans[$i]['vlan_name'] = $vlan_name;
$active_vlans++;
mactrack_debug('VLAN ID = ' . $active_vlans[$i]['vlan_id'] . ' VLAN Name = ' . $active_vlans[$i]['vlan_name']);
$i++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mactrack_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2147,7 +2147,7 @@ function xform_mac_address($mac_address) {
$mac_address = $mac;
}

$mac_address = str_replace(':', '', $max_address);
$mac_address = str_replace(':', '', $mac_address);

return strtoupper($mac_address);
}
Expand Down
1 change: 0 additions & 1 deletion lib/mactrack_hp.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function get_procurve_switch_ports($site, &$device, $lowPort = 0, $highPort = 0)
foreach ($vlan_ids as $vlan_id => $vlan_name) {
$active_vlans[$i]['vlan_id'] = $vlan_id;
$active_vlans[$i]['vlan_name'] = $vlan_name;
$active_vlans++;

$i++;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/mactrack_hp_ng.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function get_procurve_ng_switch_ports($site, &$device, $lowPort = 0, $highPort =
foreach ($vlan_ids as $vlan_id => $vlan_name) {
$active_vlans[$i]['vlan_id'] = $vlan_id;
$active_vlans[$i]['vlan_name'] = $vlan_name;
$active_vlans++;

$i++;
}
Expand All @@ -91,7 +90,7 @@ function get_procurve_ng_switch_ports($site, &$device, $lowPort = 0, $highPort =
foreach ($port_results as $port_result) {
$ifIndex = $port_result['port_number'];
$ifType = isset($ifInterfaces[$ifIndex]['ifType']) ? $ifInterfaces[$ifIndex]['ifType'] : '';
$ifName = isset($ifInterfaces['ifAlias'][$ifIndex]) ? $ifInterfaces['ifAlias'][$ifIndex] : '';
$ifName = isset($ifInterfaces[$ifIndex]['ifAlias']) ? $ifInterfaces[$ifIndex]['ifAlias'] : '';
$portName = $ifName;
$portTrunkStatus = isset($ifInterfaces[$ifIndex]['trunkPortState']) ? $ifInterfaces[$ifIndex]['trunkPortState'] : '';

Expand Down
1 change: 0 additions & 1 deletion lib/mactrack_hp_ngi.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function get_procurve_ngi_switch_ports($site, &$device, $lowPort = 0, $highPort
foreach ($vlan_ids as $vlan_id => $vlan_name) {
$active_vlans[$i]['vlan_id'] = $vlan_id;
$active_vlans[$i]['vlan_name'] = $vlan_name;
$active_vlans++;

$i++;
}
Expand Down
1 change: 0 additions & 1 deletion lib/mactrack_juniper.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function get_JEX_switch_ports($site, &$device, $lowPort = 0, $highPort = 0) {
foreach ($vlan_ids as $vlan_id => $vlan_num) {
$active_vlans[$vlan_id]['vlan_id'] = $vlan_num;
$active_vlans[$vlan_id]['vlan_name'] = mactrack_arr_key($vlan_names, $vlan_id);
$active_vlans++;

$i++;
}
Expand Down
2 changes: 1 addition & 1 deletion mactrack_devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function form_mactrack_actions() {
if (isset_request_var("t_$field_name") && preg_match('/^ignorePorts/', $field_name)) {
db_execute_prepared("UPDATE mac_track_devices
SET $field_name = ?
WHERE id = ?",
WHERE device_id = ?",
[get_request_var($field_name), $selected_items[$i]]);
}
}
Expand Down
8 changes: 4 additions & 4 deletions mactrack_resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

if (cacti_sizeof($parms)) {
foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
if (strpos($parameter, '=') !== false) {
[$arg, $value] = explode('=', $parameter);
} else {
$arg = $parameter;
Expand Down Expand Up @@ -153,11 +153,11 @@
}

if (cacti_sizeof($nameservers)) {
$use_resolver = false;
$resolver = false;
} else {
$use_resolver = true;
$resolver = new Net_DNS2_Resolver(['nameservers' => $nameservers]);
} else {
$use_resolver = false;
$resolver = false;
}

// if more than 15 second is nothing to do, ending
Expand Down
2 changes: 1 addition & 1 deletion mactrack_scanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

if (cacti_sizeof($parms)) {
foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
if (strpos($parameter, '=') !== false) {
[$arg, $value] = explode('=', $parameter);
} else {
$arg = $parameter;
Expand Down
6 changes: 3 additions & 3 deletions poller_mactrack.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@

if (cacti_sizeof($parms)) {
foreach ($parms as $parameter) {
if (strpos($parameter, '=')) {
if (strpos($parameter, '=') !== false) {
[$arg, $value] = explode('=', $parameter);
} else {
$arg = $parameter;
Expand Down Expand Up @@ -720,7 +720,7 @@ function collect_mactrack_data($start, $site_id = 0) {
WHERE site_id = ?
AND device_id = ?
AND mac_address = ?',
[$macs['ip_address'], $port['site_id'], $port['device_id'] . $port['mac_address']]);
[$macs['ip_address'], $port['site_id'], $port['device_id'], $port['mac_address']]);
}
}
}
Expand Down Expand Up @@ -998,7 +998,7 @@ function collect_mactrack_data($start, $site_id = 0) {
$last_macauth_time = read_config_option('mt_last_macauth_time');

// if it's time to e-mail
if (($last_macauth_time + ($mac_auth_frequency * 60) > time()) ||
if (($last_macauth_time + ($mac_auth_frequency * 60) < time()) ||
($mac_auth_frequency == 0)) {
mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_time);
}
Expand Down
14 changes: 14 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
* Pest configuration file.
*/

require_once __DIR__ . '/bootstrap.php';
108 changes: 108 additions & 0 deletions tests/Security/Php74CompatibilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
* Verify plugin source files do not use PHP 8.0+ syntax.
* Cacti 1.2.x plugins must remain compatible with PHP 7.4.
*/

describe('PHP 7.4 compatibility in mactrack', function () {
$files = array(
'mactrack_devices.php',
'mactrack_device_types.php',
'mactrack_interfaces.php',
'mactrack_sites.php',
'mactrack_snmp.php',
'mactrack_utilities.php',
'mactrack_view_arp.php',
'mactrack_view_macs.php',
'mactrack_view_sites.php',
'setup.php',
);

it('does not use str_contains (PHP 8.0)', function () use ($files) {
foreach ($files as $relativeFile) {
$path = realpath(__DIR__ . '/../../' . $relativeFile);

if ($path === false) {
continue;
}

$contents = file_get_contents($path);

if ($contents === false) {
continue;
}

expect(preg_match('/\bstr_contains\s*\(/', $contents))->toBe(0,
"{$relativeFile} uses str_contains() which requires PHP 8.0"
);
}
});

it('does not use str_starts_with (PHP 8.0)', function () use ($files) {
foreach ($files as $relativeFile) {
$path = realpath(__DIR__ . '/../../' . $relativeFile);

if ($path === false) {
continue;
}

$contents = file_get_contents($path);

if ($contents === false) {
continue;
}

expect(preg_match('/\bstr_starts_with\s*\(/', $contents))->toBe(0,
"{$relativeFile} uses str_starts_with() which requires PHP 8.0"
);
}
});

it('does not use str_ends_with (PHP 8.0)', function () use ($files) {
foreach ($files as $relativeFile) {
$path = realpath(__DIR__ . '/../../' . $relativeFile);

if ($path === false) {
continue;
}

$contents = file_get_contents($path);

if ($contents === false) {
continue;
}

expect(preg_match('/\bstr_ends_with\s*\(/', $contents))->toBe(0,
"{$relativeFile} uses str_ends_with() which requires PHP 8.0"
);
}
});

it('does not use nullsafe operator (PHP 8.0)', function () use ($files) {
foreach ($files as $relativeFile) {
$path = realpath(__DIR__ . '/../../' . $relativeFile);

if ($path === false) {
continue;
}

$contents = file_get_contents($path);

if ($contents === false) {
continue;
}

expect(preg_match('/\?->/', $contents))->toBe(0,
"{$relativeFile} uses nullsafe operator which requires PHP 8.0"
);
}
});
});
66 changes: 66 additions & 0 deletions tests/Security/PreparedStatementConsistencyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
* Verify migrated files use prepared DB helpers exclusively.
* Catches regressions where raw db_execute/db_fetch_* calls creep back in.
*/

describe('prepared statement consistency in mactrack', function () {
it('uses prepared DB helpers in all plugin files', function () {
$targetFiles = array(
'mactrack_devices.php',
'mactrack_device_types.php',
'mactrack_interfaces.php',
'mactrack_sites.php',
'mactrack_snmp.php',
'mactrack_utilities.php',
'mactrack_view_arp.php',
'mactrack_view_macs.php',
'mactrack_view_sites.php',
'setup.php',
);

$rawPattern = '/\bdb_(?:execute|fetch_row|fetch_assoc|fetch_cell)\s*\(/';
$preparedPattern = '/\bdb_(?:execute|fetch_row|fetch_assoc|fetch_cell)_prepared\s*\(/';

foreach ($targetFiles as $relativeFile) {
$path = realpath(__DIR__ . '/../../' . $relativeFile);

if ($path === false) {
continue;
}

$contents = file_get_contents($path);

if ($contents === false) {
continue;
}

$lines = explode("\n", $contents);
$rawCallsOutsideComments = 0;

foreach ($lines as $line) {
$trimmed = ltrim($line);

if (strpos($trimmed, '//') === 0 || strpos($trimmed, '*') === 0 || strpos($trimmed, '#') === 0) {
continue;
}

if (preg_match($rawPattern, $line) && !preg_match($preparedPattern, $line)) {
$rawCallsOutsideComments++;
}
}

expect($rawCallsOutsideComments)->toBe(0,
"File {$relativeFile} contains raw (unprepared) DB calls"
);
}
});
});
36 changes: 36 additions & 0 deletions tests/Security/SetupStructureTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
*/

/*
* Verify setup.php defines required plugin hooks and info function.
*/

describe('mactrack setup.php structure', function () {
$source = file_get_contents(realpath(__DIR__ . '/../../setup.php'));

it('defines plugin_mactrack_install function', function () use ($source) {
expect($source)->toContain('function plugin_mactrack_install');
});

it('defines plugin_mactrack_version function', function () use ($source) {
expect($source)->toContain('function plugin_mactrack_version');
});

it('defines plugin_mactrack_uninstall function', function () use ($source) {
expect($source)->toContain('function plugin_mactrack_uninstall');
});

it('returns version array with name key', function () use ($source) {
expect($source)->toMatch('/[\'\""]name[\'\""]\s*=>/');
});

it('returns version array with version key', function () use ($source) {
expect($source)->toMatch('/[\'\""]version[\'\""]\s*=>/');
});
});
Loading
Loading