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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* issue: Decode MAC/IP OIDs as hex in the Extreme scanner by correcting a misplaced xform_stripped_oid() argument
* issue: Fix an undefined $ifindex reference (should be $ifIndex) in the Nortel Bay scanner
* issue: Fix a misplaced parenthesis in the running-process stats parser
* security: Move every inline `onClick`/`onChange` handler (filter selects, Return/Cancel buttons, the device rescan icon, the utilities refresh controls) into `$(function() {})` handlers, using delegated handlers in `js/mactrack.js` for markup rendered by shared or AJAX-refreshed code, so pages work under a Content-Security-Policy that blocks inline event-handler attributes; all inline `<script>` tags already carry the version-safe nonce, and a regression test now enforces both
* security: Add a version-safe CSP nonce (`plugin_mactrack_csp_nonce()`) to every inline `<script>` tag, and emit external JavaScript includes through Cacti's `get_md5_include_js()` helper so they carry the request nonce automatically; pages stay compatible with Cacti's Content-Security-Policy nonce enforcement while falling back cleanly on older Cacti releases that lack the `CactiSecureHeaders` class
* issue#349: Keep punctuation in the port name filter
* issue#350: Leave an empty hardware address empty
Expand Down
11 changes: 11 additions & 0 deletions js/mactrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,14 @@ function enable_device(device_id) {
$('#line_' + device_id).html(content);
});
}

/* Delegated handlers survive AJAX page loads and rows re-rendered by enable/disable */
$(function() {
$(document).on('click', '.mactrackRescanDevice', function() {
scan_device($(this).attr('data-device-id'));
});

$(document).on('click', '.mactrackReturn', function() {
cactiReturnTo();
});
});
18 changes: 13 additions & 5 deletions lib/mactrack_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4229,7 +4229,7 @@ function mactrack_format_device_row($device, $actions = false): void {
// admin level
if (api_user_realm_auth('mactrack_sites.php')) {
if ($device['disabled'] == '') {
$row .= "<img id='r_" . $device['device_id'] . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_device.gif' alt='' onClick='scan_device(" . $device['device_id'] . ")' title='" . __('Rescan Device', 'mactrack') . "'>";
$row .= "<img id='r_" . $device['device_id'] . "' src='" . $config['url_path'] . "plugins/mactrack/images/rescan_device.gif' alt='' class='mactrackRescanDevice' data-device-id='" . html_escape($device['device_id']) . "' title='" . __('Rescan Device', 'mactrack') . "'>";
} else {
$row .= "<img src='" . $config['url_path'] . "plugins/mactrack/images/view_none.gif' alt=''>";
}
Expand Down Expand Up @@ -4420,7 +4420,7 @@ function mactrack_site_filter($page = 'mactrack_sites.php'): void {
<?php print __('Sites', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
Expand All @@ -4438,7 +4438,7 @@ function mactrack_site_filter($page = 'mactrack_sites.php'): void {
<td>
<input type='checkbox' id='detail' <?php if (get_request_var('detail') == 'true') {
print ' checked="true"';
}?> onClick='applyFilter()'>
}?>>
</td>
<td>
<label for='detail'><?php print __('Show Device Details', 'mactrack'); ?></label>
Expand All @@ -4460,7 +4460,7 @@ function mactrack_site_filter($page = 'mactrack_sites.php'): void {
<?php print __('Site', 'mactrack'); ?>
</td>
<td>
<select id='site_id' onChange='applyFilter()'>
<select id='site_id'>
<option value='-1'<?php if (get_request_var('site_id') == '-1') {?> selected<?php }?>><?php print __('Any', 'mactrack'); ?></option>
<?php
$sites = db_fetch_assoc('SELECT * FROM mac_track_sites ORDER BY site_name');
Expand All @@ -4481,7 +4481,7 @@ function mactrack_site_filter($page = 'mactrack_sites.php'): void {
<?php print __('SubType', 'mactrack'); ?>
</td>
<td>
<select id='device_type_id' onChange='applyFilter()'>
<select id='device_type_id'>
<option value='-1'<?php if (get_request_var('device_type_id') == '-1') {?> selected<?php }?>><?php print __('Any', 'mactrack'); ?></option>
<?php
$device_types = db_fetch_assoc('SELECT DISTINCT mac_track_device_types.device_type_id,
Expand Down Expand Up @@ -4541,6 +4541,14 @@ function exportRows() {
applyFilter();
});

$('#rows, #site_id, #device_type_id').on('change', function() {
applyFilter();
});

$('#detail').on('click', function() {
applyFilter();
});

$('#clear').on('click', function() {
clearFilter();
});
Expand Down
16 changes: 10 additions & 6 deletions mactrack_device_types.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ function form_actions(): void {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($device_types_array) ? serialize($device_types_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . get_nfilter_request_var('drp_action') . "'>" . ($save_html != '' ? "
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()' name='cancel'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()' name='cancel'>" . __esc('Return') . '</button>') . '
<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn' name='cancel'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn' name='cancel'>" . __esc('Return') . '</button>') . '
</td>
</tr>';

Expand Down Expand Up @@ -1295,7 +1295,7 @@ function mactrack_device_type_filter(): void {
<?php print __('Device Types', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
Expand Down Expand Up @@ -1330,7 +1330,7 @@ function mactrack_device_type_filter(): void {
<?php print __('Vendor', 'mactrack'); ?>
</td>
<td>
<select id='vendor' onChange='applyFilter()'>
<select id='vendor'>
<option value='All'<?php if (get_request_var('vendor') == 'All') {
print ' selected';
}?>><?php print __('All', 'mactrack'); ?></option>
Expand All @@ -1353,7 +1353,7 @@ function mactrack_device_type_filter(): void {
<?php print __('Type', 'mactrack'); ?>
</td>
<td>
<select id='type_id' onChange='applyFilter()'>
<select id='type_id'>
<option value='-1'<?php if (get_request_var('type_id') == '-1') {
print ' selected';
}?>><?php print __('All', 'mactrack'); ?></option>
Expand All @@ -1372,7 +1372,7 @@ function mactrack_device_type_filter(): void {
<?php print __('Enabled', 'mactrack'); ?>
</td>
<td>
<select id='enabled' onChange='applyFilter()'>
<select id='enabled'>
<option value='-1'<?php if (get_request_var('enabled') == '-1') {
print ' selected';
}?>><?php print __('All', 'mactrack'); ?></option>
Expand Down Expand Up @@ -1423,6 +1423,10 @@ function scanDeviceType() {
}

$(function() {
$('#rows, #vendor, #type_id, #enabled').on('change', function() {
applyFilter();
});

$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
Expand Down
18 changes: 11 additions & 7 deletions mactrack_devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ function form_mactrack_actions(): void {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . serialize($device_array) . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . ($save_html != '' ? "
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Return', 'mactrack') . "'>") . '</button>
<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Return', 'mactrack')) . '</button>
</td>
</tr>';

Expand Down Expand Up @@ -1331,7 +1331,7 @@ function mactrack_device_filter(): void {
<?php print __('Site', 'mactrack'); ?>
</td>
<td>
<select id='site_id' onChange='applyFilter()'>
<select id='site_id'>
<option value='-1'<?php if (get_request_var('site_id') == '-1') {?> selected<?php }?>><?php print __('All', 'mactrack'); ?></option>
<option value='-2'<?php if (get_request_var('site_id') == '-2') {?> selected<?php }?>><?php print __('None', 'mactrack'); ?></option>
<?php
Expand Down Expand Up @@ -1365,7 +1365,7 @@ function mactrack_device_filter(): void {
<?php print __('Type', 'mactrack'); ?>
</td>
<td>
<select id='type_id' onChange='applyFilter()'>
<select id='type_id'>
<option value='-1'<?php if (get_request_var('type_id') == '-1') {?> selected<?php }?>><?php print __('Any', 'mactrack'); ?></option>
<option value='1'<?php if (get_request_var('type_id') == '1') {?> selected<?php }?>><?php print __('Switch/Hub', 'mactrack'); ?></option>
<option value='2'<?php if (get_request_var('type_id') == '2') {?> selected<?php }?>><?php print __('Switch/Router', 'mactrack'); ?></option>
Expand All @@ -1376,7 +1376,7 @@ function mactrack_device_filter(): void {
<?php print __('SubType', 'mactrack'); ?>
</td>
<td>
<select id='device_type_id' onChange='applyFilter()'>
<select id='device_type_id'>
<option value='-1'<?php if (get_request_var('device_type_id') == '-1') {?> selected<?php }?>><?php print __('Any', 'mactrack'); ?></option>
<option value='-2'<?php if (get_request_var('device_type_id') == '-2') {?> selected<?php }?>><?php print __('Not Detected', 'mactrack'); ?></option>
<?php
Expand Down Expand Up @@ -1426,7 +1426,7 @@ function mactrack_device_filter(): void {
<?php print __('Status', 'mactrack'); ?>
</td>
<td>
<select id='status' onChange='applyFilter()'>
<select id='status'>
<option value='-1'<?php if (get_request_var('status') == '-1') {?> selected<?php }?>><?php print __('Any', 'mactrack'); ?></option>
<option value='3'<?php if (get_request_var('status') == '3') {?> selected<?php }?>><?php print __('Up', 'mactrack'); ?></option>
<option value='-2'<?php if (get_request_var('status') == '-2') {?> selected<?php }?>><?php print __('Disabled', 'mactrack'); ?></option>
Expand All @@ -1440,7 +1440,7 @@ function mactrack_device_filter(): void {
<?php print __('Devices', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
Expand Down Expand Up @@ -1487,6 +1487,10 @@ function importRows() {
}

$(function() {
$('#site_id, #type_id, #device_type_id, #status, #rows').on('change', function() {
applyFilter();
});

$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
Expand Down
10 changes: 7 additions & 3 deletions mactrack_macauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ function form_actions(): void {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($maca_array) ? serialize($maca_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . ($save_html != '' ? "
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Return', 'mactrack') . '</button>') . '
<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Return', 'mactrack') . '</button>') . '
</td>
</tr>';

Expand Down Expand Up @@ -490,7 +490,7 @@ function mactrack_maca_filter(): void {
<?php print __('MAC\'s', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
Expand Down Expand Up @@ -530,6 +530,10 @@ function clearFilter() {
}

$(function() {
$('#rows').on('change', function() {
applyFilter();
});

$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
Expand Down
10 changes: 7 additions & 3 deletions mactrack_macwatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ function form_actions(): void {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . serialize($macw_array) . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . ($save_html != '' ? "
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget' onClick='cactiReturnTo()'>" . __esc('Return', 'mactrack') . '</button>') . '
<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Return', 'mactrack') . '</button>') . '
</td>
</tr>';

Expand Down Expand Up @@ -499,7 +499,7 @@ function mactrack_macw_filter(): void {
<?php print __('Watches', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows)) {
Expand Down Expand Up @@ -539,6 +539,10 @@ function clearFilter() {
}

$(function() {
$('#rows').on('change', function() {
applyFilter();
});

$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
Expand Down
4 changes: 2 additions & 2 deletions mactrack_sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ function form_actions(): void {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($site_array) ? serialize($site_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>" . ($save_html != '' ? "
<button type='button' onClick='cactiReturnTo()' class='ui-button ui-corner-all ui-widget'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' onClick='cactiReturnTo()' class='ui-button ui-corner-all ui-widget'>" . __esc('Return', 'mactrack') . '</button>') . '
<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Cancel', 'mactrack') . "</button>
$save_html" : "<button type='button' class='ui-button ui-corner-all ui-widget mactrackReturn'>" . __esc('Return', 'mactrack') . '</button>') . '
</td>
</tr>';

Expand Down
14 changes: 12 additions & 2 deletions mactrack_snmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ function form_mactrack_snmp_actions(): void {
function goTo(strURL) {
loadPageNoHeader(strURL);
}

$(function() {
$('.mactrackSnmpReturn').on('click', function() {
goTo('mactrack_snmp.php');
});
});
</script>
<?php

Expand Down Expand Up @@ -315,7 +321,7 @@ function goTo(strURL) {
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($mactrack_array) ? serialize($mactrack_array) : '') . "'>
<input type='hidden' name='drp_action' class='ui-button ui-corner-all ui-widget' value='" . get_nfilter_request_var('drp_action') . "'>
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='goTo(\"" . 'mactrack_snmp.php' . "\")'>" . ($save_html == '' ? __esc('Return', 'mactrack') : __esc('Cancel', 'mactrack')) . "</button>
<button type='button' class='ui-button ui-corner-all ui-widget mactrackSnmpReturn'>" . ($save_html == '' ? __esc('Return', 'mactrack') : __esc('Cancel', 'mactrack')) . "</button>
$save_html
</td>
</tr>";
Expand Down Expand Up @@ -726,7 +732,7 @@ function snmp_options_filter(): void {
<?php print __('Options', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php print(get_request_var('rows') == '-1' ? ' selected' : ''); ?>><?php print __('Default', 'mactrack'); ?></option>
<?php if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
Expand Down Expand Up @@ -766,6 +772,10 @@ function clearFilter() {
}

$(function() {
$('#rows').on('change', function() {
applyFilter();
});

$('#go').on('click', function() {
applyFilter();
});
Expand Down
10 changes: 7 additions & 3 deletions mactrack_utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ function applyFilter() {
}

$(function() {
$('#refresh').on('click', function() {
$('#refresh').on('change', function() {
applyFilter();
});

$('#refreshButton').on('click', function() {
applyFilter();
});
});
Expand All @@ -229,7 +233,7 @@ function applyFilter() {
<?php print __('Refresh', 'mactrack'); ?>
</td>
<td>
<select id='refresh' onChange='applyFilter()'>
<select id='refresh'>
<?php
if (cacti_sizeof($refresh_interval)) {
foreach ($refresh_interval as $key => $interval) {
Expand All @@ -243,7 +247,7 @@ function applyFilter() {
?>
</td>
<td>
<button type='button' class='ui-button ui-corner-all ui-widget' onClick='applyFilter()'><?php print __esc('Refresh', 'mactrack'); ?></button>
<button type='button' id='refreshButton' class='ui-button ui-corner-all ui-widget'><?php print __esc('Refresh', 'mactrack'); ?></button>
</td>
</tr>
</table>
Expand Down
6 changes: 5 additions & 1 deletion mactrack_vendormacs.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ function mactrack_vmac_filter(): void {
<?php print __('MAC\'s', 'mactrack'); ?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>
<select id='rows'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mactrack'); ?></option>
<?php
if (cacti_sizeof($item_rows) > 0) {
Expand Down Expand Up @@ -308,6 +308,10 @@ function exportRows() {
}

$(function() {
$('#rows').on('change', function() {
applyFilter();
});

$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
Expand Down
Loading
Loading