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
2 changes: 1 addition & 1 deletion .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: sudo apt-get update

- name: Install System Dependencies
run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping libapache2-mod-php${{ matrix.php }}
run: sudo apt-get install -y apache2 snmp snmpd rrdtool fping

- name: Start SNMPD Agent and Test
run: |
Expand Down
1 change: 0 additions & 1 deletion lib/mactrack_enterasys.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function get_enterasys_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
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
18 changes: 11 additions & 7 deletions lib/mactrack_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2127,17 +2127,21 @@ function xform_net_address($ip_address) {
* @param mixed $mac_address
*/
function xform_mac_address($mac_address) {
$max_address = trim($mac_address);
$mac_address = trim((string) $mac_address);

if ($mac_address == '') {
$mac_address = 'NOT USER';
} elseif (strlen($mac_address) > 10) { // return is in ascii
$max_address = str_replace(
if ($mac_address === '') {
return 'NOT USER';
}

if (strlen($mac_address) > 10) {
// ASCII / HEX- form (e.g. "HEX-00:aa:bb:...", "aa-bb-cc-dd-ee-ff")
$mac_address = str_replace(
['HEX-00:', 'HEX-:', 'HEX-', '"', ' ', '-'],
['', '', '', '', ':', ':'],
$mac_address
);
} else { // return is hex
} else {
// Binary hex bytes from SNMP
$mac = '';

for ($j = 0; $j < strlen($mac_address); $j++) {
Expand All @@ -2147,7 +2151,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: 0 additions & 2 deletions lib/mactrack_norbay.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ function get_norbay_accelar_switch_ports($site, &$device, $lowPort = 0, $highPor
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 Expand Up @@ -199,7 +198,6 @@ function get_norbay_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
1 change: 0 additions & 1 deletion lib/mactrack_norbay_ng.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ function get_norbay_ng_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
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
15 changes: 12 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,10 @@ 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()) ||
$last_macauth_time = (int) $last_macauth_time;
$mac_auth_frequency = (int) $mac_auth_frequency;

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 Expand Up @@ -1106,6 +1109,11 @@ function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_tim
// email the report
mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');
mactrack_debug('MACAUTH Report eMail sent.');

// Persist last-run so the schedule gate does not re-fire every poll.
if ($mac_auth_frequency > 0) {
set_config_option('mt_last_macauth_time', (string) time());
}
} else {
// email the report

Expand All @@ -1120,6 +1128,7 @@ function mactrack_process_mac_auth_report($mac_auth_frequency, $last_macauth_tim
// email the report
mactrack_mail($to, $from, $fromname, $subject, $message, $headers = '');
mactrack_debug('MACAUTH Report empty eMail sent.');
set_config_option('mt_last_macauth_time', (string) time());
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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 = [
'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"
);
}
});
});
Loading
Loading