Repository navigation
Expand file tree
/
Copy pathmactrack_view_dot1x.php
More file actions
854 lines (760 loc) · 30 KB
/
Copy pathmactrack_view_dot1x.php
File metadata and controls
854 lines (760 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDTool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
$guest_account = true;
chdir('../../');
require('./include/auth.php');
require_once('./include/global_arrays.php');
require_once('./plugins/mactrack/lib/mactrack_functions.php');
$title = __('Mactrack - 802.1x View', 'mactrack');
set_default_action();
if (isset_request_var('export')) {
mactrack_view_export_dot1x();
} else {
general_header();
mactrack_view_dot1x_validate_request_vars();
if (isset_request_var('scan_date')) {
mactrack_view_dot1x();
}
bottom_footer();
}
/**
* Validates and stores this view's filter request variables (rows,
* page, site id, device id, status, MAC/port-name/IP filter type and
* text, domain, scan date, sort column/direction) into the session for
* the 802.1x list view.
*
* @return void
*/
function mactrack_view_dot1x_validate_request_vars(): void {
// ================= input validation and session storage =================
$filters = [
'rows' => [
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
],
'page' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
],
'site_id' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '-1'
],
'device_id' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '-1'
],
'status' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '0'
],
'mac_filter_type_id' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
],
'port_name_filter_type_id' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
],
'ip_filter_type_id' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
],
'domain' => [
'filter' => FILTER_VALIDATE_INT,
'default' => '-1',
'pageset' => true
],
'filter' => [
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => ['options' => 'sanitize_search_string']
],
'ip_filter' => [
'filter' => FILTER_CALLBACK,
'default' => '',
'options' => ['options' => 'sanitize_search_string']
],
'mac_filter' => [
'filter' => FILTER_CALLBACK,
'default' => '',
'options' => ['options' => 'sanitize_search_string']
],
'port_name_filter' => [
'filter' => FILTER_CALLBACK,
'default' => '',
'options' => ['options' => 'mactrack_sanitize_port_name_filter']
],
'scan_date' => [
'filter' => FILTER_CALLBACK,
'default' => '2',
'options' => ['options' => 'sanitize_search_string']
],
'sort_column' => [
'filter' => FILTER_CALLBACK,
'default' => 'device_name',
'options' => ['options' => 'sanitize_search_string']
],
'sort_direction' => [
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => ['options' => 'sanitize_search_string']
]
];
validate_store_request_vars($filters, 'sess_mtv_dot1x');
// ================= input validation =================
}
/**
* Exports the current filtered 802.1x authentication results (site,
* hostname, device, domain, status, MAC, IP, DNS hostname, port,
* interface, username, scan date) as a downloaded CSV file. Called
* from this script's main request-dispatch switch when action=export.
*
* @return void
*/
function mactrack_view_export_dot1x(): void {
mactrack_view_dot1x_validate_request_vars();
$sql_where = '';
$sql_params = [];
$port_results = mactrack_view_get_dot1x_records($sql_where, $sql_params, 0, false);
$xport_array = [];
array_push($xport_array, '"site_name","hostname","device_name",' .
'"domain","status","mac_address",' .
'"ip_address","dns_hostname","port_number","ifName","username","scan_date"');
if (cacti_sizeof($port_results)) {
foreach ($port_results as $port_result) {
if (get_request_var('scan_date') == 1) {
$scan_date = $port_result['scan_date'];
} else {
$scan_date = $port_result['max_scan_date'];
}
array_push($xport_array,'"' . $port_result['site_name'] . '","' .
$port_result['hostname'] . '","' . $port_result['device_name'] . '","' .
$port_result['domain'] . '","' . $port_result['status'] . '","' .
mactrack_format_mac($port_result['mac_address']) . '","' . $port_result['ip_address'] . '","' .
$port_result['dns_hostname'] . '","' . $port_result['port_number'] . '","' .
$port_result['ifName'] . '","' . $port_result['username'] . '","' .
$scan_date . '"');
}
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=mactrack_dot1x_xport.csv');
foreach ($xport_array as $xport_line) {
print $xport_line . "\n";
}
}
/**
* Builds and executes the prepared SQL query for the 802.1x list view,
* applying the current status, MAC/port-name/IP filters, domain, site,
* device, and scan date request variables, sort order, and optional
* row limits. Returns an empty result set if no WHERE clause could be
* constructed (avoiding an unfiltered full table scan).
*
* @param string &$sql_where Receives the generated SQL WHERE clause.
* @param array &$sql_params Receives the bound parameter values for
* the prepared statement.
* @param int $rows Number of rows per page, used to compute
* the SQL LIMIT clause when $apply_limits
* is true.
* @param bool $apply_limits Whether to apply a SQL LIMIT clause
* (default true).
*
* @return array The matching 802.1x authentication records.
*/
function mactrack_view_get_dot1x_records(&$sql_where, &$sql_params, $rows, $apply_limits = true): array {
$sql_params = [];
// status sql where
if (get_request_var('status') == '1') { // Idle
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 1';
} elseif (get_request_var('status') == '2') { // Running
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 2';
} elseif (get_request_var('status') == '3') { // No Method
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 3';
} elseif (get_request_var('status') == '4') { // Authentication Success
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 4';
} elseif (get_request_var('status') == '5') { // Authentication Failed
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 5';
} elseif (get_request_var('status') == '6') { // Authorization Success
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 6';
} elseif (get_request_var('status') == '7') { // Authorization Failed
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . 'mtd.status = 7';
}
// form the 'where' clause for our main sql query
if (get_request_var('mac_filter') != '') {
$mac_filter = str_replace(':', '', (string) get_request_var('mac_filter'));
$mac_filter = str_replace('-', '', $mac_filter);
$mac_filter = str_replace('.', '', $mac_filter);
switch (get_request_var('mac_filter_type_id')) {
case '1': // do not filter
break;
case '2': // matches
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.mac_address = ' . db_qstr($mac_filter);
break;
case '3': // contains
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.mac_address LIKE ' . db_qstr('%' . $mac_filter . '%');
break;
case '4': // begins with
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.mac_address LIKE ' . db_qstr($mac_filter . '%');
break;
case '5': // does not contain
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.mac_address NOT LIKE ' . db_qstr('%' . $mac_filter . '%');
break;
case '6': // does not begin with
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.mac_address NOT LIKE ' . db_qstr($mac_filter . '%');
break;
}
}
if ((get_request_var('ip_filter') != '') || (get_request_var('ip_filter_type_id') > 6)) {
switch (get_request_var('ip_filter_type_id')) {
case '1': // do not filter
break;
case '2': // matches
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address = ' . db_qstr(get_request_var('ip_filter'));
break;
case '3': // contains
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address LIKE ' . db_qstr('%' . get_request_var('ip_filter') . '%');
break;
case '4': // begins with
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address LIKE ' . db_qstr(get_request_var('ip_filter') . '%');
break;
case '5': // does not contain
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address NOT LIKE ' . db_qstr('%' . get_request_var('ip_filter') . '%');
break;
case '6': // does not begin with
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address NOT LIKE ' . db_qstr(get_request_var('ip_filter') . '%');
break;
case '7': // is null
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address = ""';
break;
case '8': // is not null
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.ip_address != ""';
break;
}
}
if ((get_request_var('port_name_filter') != '') || (get_request_var('port_name_filter_type_id') > 6)) {
[$port_clause, $port_params] = mactrack_port_name_filter_clause(
'mti.ifName',
get_request_var('port_name_filter_type_id'),
get_request_var('port_name_filter')
);
if ($port_clause !== '') {
$sql_where .= ($sql_where != '' ? ' AND ' : 'WHERE ') . $port_clause;
$sql_params = array_merge($sql_params, $port_params);
}
}
if (get_request_var('filter') != '') {
if (read_config_option('mt_reverse_dns') != '') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (mtd.dns_hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mti.ifName LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.device_name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.username LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.ip_address LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.mac_address LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
} else {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') .
' (mtd.dns_hostname LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mti.ifName LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.device_name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.username LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.ip_address LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ' OR ' .
'mtd.mac_address LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
}
}
if (get_request_var('domain') != '-1') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.domain = ' . db_qstr(get_request_var('domain'));
}
if (get_request_var('site_id') != '-1') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.site_id = ' . get_filter_request_var('site_id');
}
if (get_request_var('status') != '0') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.status = ' . get_filter_request_var('status');
}
if (get_request_var('device_id') != '-1') {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.device_id = ' . get_filter_request_var('device_id');
}
if ((get_request_var('scan_date') != '1') && (get_request_var('scan_date') != '2')) {
$sql_where .= ($sql_where != '' ? ' AND' : 'WHERE') . ' mtd.scan_date =' . db_qstr(get_request_var('scan_date'));
}
// prevent table scans, either a device or site must be selected
if (get_request_var('site_id') == -1 && get_request_var('device_id') == -1) {
if ($sql_where == '') {
return [];
}
}
$sql_order = get_order_string();
if ($apply_limits && $rows != 999999) {
$sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows;
} else {
$sql_limit = '';
}
if ((get_request_var('scan_date') != 2)) {
$query_string = "SELECT mts.site_name, mtd.device_id, mtd.device_name, mtd.hostname,
mtd.mac_address, mtd.username, mtd.ip_address, mtd.dns_hostname, mtd.port_number,
mti.ifName, mti.ifDescr, mtd.domain, mtd.status, mtd.scan_date
FROM mac_track_dot1x AS mtd
LEFT JOIN mac_track_sites AS mts
ON mtd.site_id = mts.site_id
LEFT JOIN mac_track_interfaces AS mti
ON mtd.port_number = mti.ifIndex
AND mtd.device_id = mti.device_id
$sql_where
$sql_order
$sql_limit";
} else {
$query_string = "SELECT mts.site_name, mtd.device_id, mtd.device_name, mtd.hostname,
mtd.mac_address, mtd.username, mtd.ip_address, mtd.dns_hostname, mtd.port_number,
mti.ifName, mti.ifDescr, mtd.domain, mtd.status, MAX(mtd.scan_date) AS scan_date
FROM mac_track_dot1x AS mtd
LEFT JOIN mac_track_sites AS mts
ON (mtd.site_id = mts.site_id)
LEFT JOIN mac_track_interfaces AS mti
ON mtd.port_number = mti.ifIndex
AND mtd.device_id = mti.device_id
$sql_where
GROUP BY device_id, mac_address, port_number, ip_address
$sql_order
$sql_limit";
}
if ($sql_where == '') {
return [];
} else {
return db_fetch_assoc_prepared($query_string, $sql_params);
}
}
/**
* Renders the main 802.1x authentication results list page: displays
* the tab bar and 802.1x filter form, then displays a filtered,
* sorted, paginated table of 802.1x records with a modal response area
* for scan actions. Called from this script's main request-dispatch
* switch as the default view.
*
* @return void
*
* @global string $title The page title, set for the
* surrounding page chrome.
* @global string $report Reserved/declared for parity
* with other functions in this
* file; not used directly here.
* @global array $mactrack_search_types Filter-type option list used
* by the 802.1x filter form.
* @global array $rows_selector Reserved/declared for parity
* with other functions in this
* file; not used directly here.
* @global array $config Cacti global configuration
* array.
* @global array $item_rows Default number of rows per
* page from Cacti settings.
*/
function mactrack_view_dot1x(): void {
global $title, $report, $mactrack_search_types, $rows_selector, $config;
global $item_rows;
mactrack_tabs();
html_start_box($title, '100%', '', '3', 'center', '');
mactrack_dot1x_filter();
html_end_box();
$sql_where = '';
$sql_params = [];
$rows = plugin_get_rows_per_page();
$port_results = mactrack_view_get_dot1x_records($sql_where, $sql_params, $rows, true);
// prevent table scans, either a device or site must be selected
if ($sql_where == '') {
$total_rows = 0;
} elseif (get_request_var('scan_date') != 3) {
$rows_query_string = "SELECT
COUNT(mtd.device_id)
FROM mac_track_dot1x AS mtd
LEFT JOIN mac_track_sites AS mts
ON mtd.site_id = mts.site_id
LEFT JOIN mac_track_interfaces AS mti
ON mtd.port_number = mti.ifIndex
AND mtd.device_id = mti.device_id
$sql_where";
$total_rows = db_fetch_cell_prepared($rows_query_string, $sql_params);
} else {
$rows_query_string = "SELECT
COUNT(DISTINCT device_id, mac_address, port_number, ip_address)
FROM mac_track_dot1x AS mtd
LEFT JOIN mac_track_sites AS mts
ON mtd.site_id = mts.site_id
LEFT JOIN mac_track_interfaces AS mti
ON mtd.port_number = mti.ifIndex
AND mtd.device_id = mti.device_id
$sql_where";
$total_rows = db_fetch_cell_prepared($rows_query_string, $sql_params);
}
if (read_config_option('mt_reverse_dns') != '') {
$display_text = [
'nosort' => [__('Actions', 'mactrack'), ''],
'device_name' => [__('Switch Name', 'mactrack'), 'ASC'],
'hostname' => [__('Switch Hostname', 'mactrack'), 'ASC'],
'username' => [__('Username', 'mactrack'), 'ASC'],
'status' => [__('Status', 'mactrack'), 'ASC'],
'ip_address' => [__('ED IP Address', 'mactrack'), 'ASC'],
'dns_hostname' => [__('ED DNS Hostname', 'mactrack'), 'ASC'],
'mac_address' => [__('ED MAC Address', 'mactrack'), 'ASC'],
'ifName' => [__('Port Name', 'mactrack'), 'ASC'],
'domain' => [__('Domain', 'mactrack'), 'DESC'],
'scan_date' => [__('Last Scan Date', 'mactrack'), 'DESC']
];
} else {
$display_text = [
'nosort' => [__('Actions', 'mactrack'), ''],
'device_name' => [__('Switch Name', 'mactrack'), 'ASC'],
'hostname' => [__('Switch Hostname', 'mactrack'), 'ASC'],
'username' => [__('Username', 'mactrack'), 'ASC'],
'status' => [__('Status', 'mactrack'), 'ASC'],
'ip_address' => [__('ED IP Address', 'mactrack'), 'ASC'],
'mac_address' => [__('ED MAC Address', 'mactrack'), 'ASC'],
'ifName' => [__('Port Name', 'mactrack'), 'ASC'],
'domain' => [__('Domain', 'mactrack'), 'DESC'],
'scan_date' => [__('Last Scan Date', 'mactrack'), 'DESC']
];
}
if (api_plugin_user_realm_auth('mactrack_macauth.php')) {
$columns = cacti_sizeof($display_text) + 1;
} else {
$columns = cacti_sizeof($display_text);
}
$nav = html_nav_bar('mactrack_view_dot1x.php?report=dot1x', MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, $columns, __('802.1x Sessions', 'mactrack'), 'page', 'main');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
if (api_plugin_user_realm_auth('mactrack_macauth.php')) {
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
} else {
html_header_sort($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
}
$i = 0;
if (cacti_sizeof($port_results)) {
foreach ($port_results as $port_result) {
// find the background color and enclose it
$class = mactrack_dot1x_row_class($port_result);
if ($class) {
print "<tr id='row_" . $port_result['device_id'] . '_' . $port_result['port_number'] . "' class='tableRow $class'>\n";
$i++;
} else {
if (($i % 2) == 1) {
$class = 'odd';
} else {
$class = 'even';
}
print "<tr id='row_" . $port_result['device_id'] . "' class='tableRow $class'>\n";
$i++;
}
print mactrack_format_dot1x_row($port_result);
}
} else {
print '<tr><td colspan="7"><em>' . __('No Mactrack 802.1x Sessions Found', 'mactrack') . '</em></td></tr>';
}
html_end_box(false);
if (cacti_sizeof($port_results)) {
print $nav;
}
print '<div class="center mactrackLegendFooter">';
mactrack_legend([
'authn_success' => __('Authorization Success', 'mactrack'),
'auth_success' => __('Authentication Success', 'mactrack'),
'authn_failed' => __('Authorization Failed', 'mactrack'),
'auth_failed' => __('Authentication Failed', 'mactrack'),
'running' => __('Running', 'mactrack'),
'idle' => __('Idle', 'mactrack'),
]);
print '</div>';
print '<div id="response" title="' . __esc('Dot1x Scan Results', 'mactrack') . '"></div>';
bottom_footer();
}
/**
* Renders the search/status/site/device/domain/MAC/port-name/IP/
* scan-date filter form controls for the 802.1x list view.
*
* @return void
*
* @global array $item_rows Rows-per-page option list used
* to populate the rows dropdown.
* @global array $rows_selector Reserved/declared for parity
* with other functions in this
* file; not used directly here.
* @global array $mactrack_search_types Filter-type option list (e.g.
* matches/contains/begins with)
* used to populate the MAC/port
* name/IP filter type dropdowns.
*/
function mactrack_dot1x_filter(): void {
global $item_rows, $rows_selector, $mactrack_search_types;
?>
<tr class='even'>
<td>
<form id='mactrack'>
<table class='filterTable'>
<tr>
<td>
<?php print __('Search', 'mactrack'); ?>
</td>
<td>
<input type='text' id='filter' size='25' value='<?php print html_escape_request_var('filter'); ?>'>
</td>
<td>
<?php print __('Site', 'mactrack'); ?>
</td>
<td>
<select id='site_id'>
<option value='-1'<?php if (get_request_var('site_id') == '-1') {?> selected<?php }?>><?php print __('N/A', 'mactrack'); ?></option>
<?php
$sites = db_fetch_assoc('SELECT site_id, site_name
FROM mac_track_sites
ORDER BY site_name');
if (cacti_sizeof($sites)) {
foreach ($sites as $site) {
print '<option value="' . $site['site_id'] . '"';
if (get_request_var('site_id') == $site['site_id']) {
print ' selected';
} print '>' . html_escape($site['site_name']) . '</option>';
}
}
?>
</select>
</td>
<td>
<?php print __('Device', 'mactrack'); ?>
</td>
<td>
<select id='device_id'>
<option value='-1'<?php if (get_request_var('device_id') == '-1') {?> selected<?php }?>><?php print __('All', 'mactrack'); ?></option>
<?php
if (get_request_var('site_id') == -1) {
$filter_devices = db_fetch_assoc('SELECT DISTINCT device_id, device_name, hostname
FROM mac_track_devices
WHERE device_type_id
IN (SELECT device_type_id from mac_track_device_types
WHERE dot1x_scanning_function="get_cisco_dot1x_table")
ORDER BY device_name');
} else {
$filter_devices = db_fetch_assoc_prepared('SELECT device_id, device_name, hostname
FROM mac_track_devices
WHERE (site_id = ? )
AND (device_type_id IN
(SELECT device_type_id from mac_track_device_types
WHERE dot1x_scanning_function="get_cisco_dot1x_table"))
ORDER BY device_name',
[get_request_var('site_id')]);
}
if (cacti_sizeof($filter_devices)) {
foreach ($filter_devices as $filter_device) {
print '<option value="' . $filter_device['device_id'] . '"' . (get_request_var('device_id') == $filter_device['device_id'] ? ' selected' : '') . '>' . html_escape($filter_device['device_name'] . '(' . $filter_device['hostname'] . ')') . '</option>';
}
}
?>
</select>
</td>
<td>
<?php print __('Sessions', 'mactrack'); ?>
</td>
<td>
<select id='rows'>
<?php
if (cacti_sizeof($rows_selector)) {
foreach ($rows_selector as $key => $value) {
print '<option value="' . $key . '"' . (get_request_var('rows') == $key ? ' selected' : '') . '>' . $value . '</option>';
}
}
?>
</select>
</td>
<td>
<span>
<button type='submit' id='go' class='ui-button ui-corner-all ui-widget ui-state-active'><?php print __esc('Go', 'mactrack'); ?></button>
<button type='button' id='clear' class='ui-button ui-corner-all ui-widget'><?php print __esc('Clear', 'mactrack'); ?></button>
<button type='button' id='export' class='ui-button ui-corner-all ui-widget'><?php print __esc('Export', 'mactrack'); ?></button>
</span>
</td>
</tr>
</table>
<table class='filterTable'>
<tr>
<td>
<?php print __('IP', 'mactrack'); ?>
</td>
<td>
<select id='ip_filter_type_id'>
<?php
foreach ($mactrack_search_types as $i => $type) {
print "<option value='$i'" . (get_request_var('ip_filter_type_id') == $i ? ' selected' : '') . '>' . $type . '</option>';
}
?>
</select>
</td>
<td>
<input type='text' id='ip_filter' size='25' value='<?php print html_escape_request_var('ip_filter'); ?>'>
</td>
<td>
<?php print __('Status', 'mactrack'); ?>
</td>
<td>
<select id='status'>
<?php
$all_status = [
0 => __esc('Any Status', 'mactrack'),
1 => __esc('Idle', 'mactrack'),
2 => __esc('Running', 'mactrack'),
3 => __esc('No Method', 'mactrack'),
4 => __esc('Authentication Success', 'mactrack'),
5 => __esc('Authentication Failed', 'mactrack'),
6 => __esc('Authorization Success', 'mactrack'),
7 => __esc('Authorization Failed', 'mactrack'),
];
foreach ($all_status as $i => $status) {
print "<option value='$i'" . (get_request_var('status') == $i ? ' selected' : '') . '>' . $status . '</option>';
}
?>
</select>
</td>
<td>
<?php print __('Show', 'mactrack'); ?>
</td>
<td>
<select id='scan_date'>
<option value='1'<?php if (get_request_var('scan_date') == '1') {?> selected<?php }?>><?php print __('All', 'mactrack'); ?></option>
<option value='2'<?php if (get_request_var('scan_date') == '2') {?> selected<?php }?>><?php print __('Most Recent', 'mactrack'); ?></option>
<?php
$scan_dates = db_fetch_assoc('SELECT DISTINCT scan_date
FROM mac_track_dot1x
ORDER BY scan_date
DESC LIMIT 10');
if (cacti_sizeof($scan_dates)) {
foreach ($scan_dates as $scan_date) {
print '<option value="' . $scan_date['scan_date'] . '"' . (get_request_var('scan_date') == $scan_date['scan_date'] ? ' selected' : '') . '>' . $scan_date['scan_date'] . '</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<td>
<?php print __('MAC', 'mactrack'); ?>
</td>
<td>
<select id='mac_filter_type_id'>
<?php
foreach ($mactrack_search_types as $i => $type) {
print "<option value='$i'" . (get_request_var('mac_filter_type_id') == $i ? ' selected' : '') . '>' . $type . '</option>';
}
?>
</select>
</td>
<td>
<input type='text' id='mac_filter' size='25' value='<?php print html_escape_request_var('mac_filter'); ?>'>
</td>
<td>
<?php print __('Domain', 'mactrack'); ?>
</td>
<td>
<select id='domain'>
<option value='-1'<?php if (get_request_var('domain') == '-1') {?> selected<?php }?>><?php print __('All', 'mactrack'); ?></option>
<option value='2'<?php if (get_request_var('domain') == '2') {?> selected<?php }?>><?php print __('DATA', 'mactrack'); ?></option>
<option value='3'<?php if (get_request_var('domain') == '3') {?> selected<?php }?>><?php print __('VOICE', 'mactrack'); ?></option>
</select>
</td>
</tr>
<tr>
<td>
<?php print __('Portname', 'mactrack'); ?>
</td>
<td>
<select id='port_name_filter_type_id'>
<?php
foreach ($mactrack_search_types as $i => $type) {
print "<option value='$i'" . (get_request_var('port_name_filter_type_id') == $i ? ' selected' : '') . '>' . $type . '</option>';
}
?>
</select>
</td>
<td>
<input type='text' id='port_name_filter' size='25' value='<?php print html_escape_request_var('port_name_filter'); ?>'>
</td>
<td colspan='2'>
</td>
</tr>
</table>
</form>
<script type='text/javascript' <?php print plugin_mactrack_csp_nonce(); ?>>
function applyFilter() {
strURL = urlPath+'plugins/mactrack/mactrack_view_dot1x.php?report=dot1x&header=false';
strURL += '&site_id=' + $('#site_id').val();
strURL += '&device_id=' + $('#device_id').val();
strURL += '&rows=' + $('#rows').val();
strURL += '&mac_filter_type_id=' + $('#mac_filter_type_id').val();
strURL += '&mac_filter=' + $('#mac_filter').val();
strURL += '&filter=' + $('#filter').val();
strURL += '&ip_filter_type_id=' + $('#ip_filter_type_id').val();
strURL += '&ip_filter=' + $('#ip_filter').val();
strURL += '&port_name_filter_type_id=' + $('#port_name_filter_type_id').val();
// Port descriptions carry '#' and '&', which truncate or extend the query
// string when concatenated raw.
strURL += '&port_name_filter=' + encodeURIComponent($('#port_name_filter').val());
strURL += '&scan_date=' + $('#scan_date').val();
strURL += '&domain=' + $('#domain').val();
strURL += '&status=' + $('#status').val();
loadPageNoHeader(strURL);
}
function clearFilter() {
strURL = urlPath+'plugins/mactrack/mactrack_view_dot1x.php?report=dot1x&header=false&clear=true';
loadPageNoHeader(strURL);
}
function exportRows() {
strURL = urlPath+'plugins/mactrack/mactrack_view_dot1x.php?report=dot1x&export=true';
document.location = strURL;
}
$(function() {
$('#site_id, #device_id, #rows, #status, #scan_date, #domain').on('change', function() {
applyFilter();
});
$('#mactrack').on('submit', function(event) {
event.preventDefault();
applyFilter();
});
$('#clear').on('click', function() {
clearFilter();
});
$('#export').on('click', function() {
exportRows();
});
// Status pill drill-down: set the Status filter to the
// clicked session status, then re-apply the filter.
$('.mactrackPill').off('click').on('click', function() {
var status = $(this).attr('data-dot1x-status');
if (status === undefined || !$('#status').length) {
return;
}
$('#status').val(status);
applyFilter();
});
});
</script>
</td>
</tr>
<?php
}