Repository navigation
Expand file tree
/
Copy pathsetup.php
More file actions
2341 lines (2150 loc) · 88.2 KB
/
Copy pathsetup.php
File metadata and controls
2341 lines (2150 loc) · 88.2 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
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?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/ |
+-------------------------------------------------------------------------+
*/
/**
* Registers this plugin's hooks and permission realms with Cacti, then
* creates/verifies its database schema and default site. Cacti plugin
* API entry point invoked when the plugin is installed or
* re-registered during an upgrade.
*
* @param bool $operator_initiated Whether this install is being run by
* an operator interactively (true,
* default) versus automatically during
* an upgrade (false); affects
* default-site seeding retry-state
* handling and CLI warning output.
*
* @return bool True if a default site exists after setup completes,
* false otherwise.
*/
function plugin_mactrack_install($operator_initiated = true): bool {
api_plugin_register_hook('mactrack', 'top_header_tabs', 'mactrack_show_tab', 'setup.php');
api_plugin_register_hook('mactrack', 'top_graph_header_tabs', 'mactrack_show_tab', 'setup.php');
api_plugin_register_hook('mactrack', 'config_arrays', 'mactrack_config_arrays', 'setup.php');
api_plugin_register_hook('mactrack', 'draw_navigation_text', 'mactrack_draw_navigation_text', 'setup.php');
api_plugin_register_hook('mactrack', 'config_form', 'mactrack_config_form', 'setup.php');
api_plugin_register_hook('mactrack', 'config_settings', 'mactrack_config_settings', 'setup.php');
api_plugin_register_hook('mactrack', 'poller_bottom', 'mactrack_poller_bottom', 'setup.php');
api_plugin_register_hook('mactrack', 'page_head', 'mactrack_page_head', 'setup.php');
// device hook: intercept on device save
api_plugin_register_hook('mactrack', 'api_device_save', 'sync_cacti_to_mactrack', 'mactrack_actions.php');
// device hook: Add a new dropdown Action for Device Management
api_plugin_register_hook('mactrack', 'device_action_array', 'mactrack_device_action_array', 'mactrack_actions.php');
// device hook: Device Management Action dropdown selected: prepare the list of devices for a confirmation request
api_plugin_register_hook('mactrack', 'device_action_prepare', 'mactrack_device_action_prepare', 'mactrack_actions.php');
// device hook: Device Management Action dropdown selected: execute list of device
api_plugin_register_hook('mactrack', 'device_action_execute', 'mactrack_device_action_execute', 'mactrack_actions.php');
// Register our realms
api_plugin_register_realm('mactrack', 'mactrack_view_dashboard.php,mactrack_view_ips.php,mactrack_view_arp.php,mactrack_view_macs.php,mactrack_view_dot1x.php,mactrack_view_sites.php,mactrack_view_devices.php,mactrack_view_interfaces.php,mactrack_view_graphs.php,mactrack_ajax.php', 'Mactrack Viewer', 1);
api_plugin_register_realm('mactrack', 'mactrack_ajax_admin.php,mactrack_devices.php,mactrack_snmp.php,mactrack_sites.php,mactrack_device_types.php,mactrack_utilities.php,mactrack_macwatch.php,mactrack_macauth.php,mactrack_vendormacs.php', 'Mactrack Administrator', 1);
$site_ready = mactrack_setup_table_new($operator_initiated);
if (!$site_ready && PHP_SAPI === 'cli') {
fwrite(STDERR, "WARNING: MacTrack installed without a Default site; review the Cacti log. The poller will retry with backoff.\n");
}
return $site_ready;
}
/**
* Removes this plugin's default-site seeding retry-state settings.
* Cacti plugin API entry point invoked when the plugin is uninstalled.
*
* @return bool Always true.
*/
function plugin_mactrack_uninstall(): bool {
db_execute_prepared(
'DELETE FROM settings WHERE name IN (?, ?, ?)',
['mt_default_site_seed_pending', 'mt_default_site_seed_attempts', 'mt_default_site_seed_next_retry']
);
return true;
}
/**
* Reads this plugin's version and metadata from its INFO file. Cacti
* plugin API entry point used throughout the plugin to display version
* information.
*
* @return array The parsed INFO file's 'info' section (name, author,
* homepage, version, etc.).
*
* @global array $config Cacti global configuration array; used to
* locate the plugin's INFO file.
*/
function plugin_mactrack_version(): array {
global $config;
$info = (array) parse_ini_file($config['base_path'] . '/plugins/mactrack/INFO', true);
return $info['info'] ?? [];
}
/**
* Ensures the plugin's configuration/schema is up to date by delegating
* to mactrack_check_upgrade(). Cacti plugin API entry point invoked on
* relevant page loads to catch pending upgrades.
*
* @return bool Always true.
*/
function plugin_mactrack_check_config(): bool {
// Here we will check to ensure everything is configured
mactrack_check_upgrade();
return true;
}
/**
* Ensures the plugin's configuration/schema is up to date by delegating
* to mactrack_check_upgrade(). Cacti plugin API entry point invoked
* when the plugin is upgraded.
*
* @return bool Always false.
*/
function plugin_mactrack_upgrade(): bool {
// Here we will upgrade to the newest version
mactrack_check_upgrade();
return false;
}
/**
* Detects a version mismatch between the running plugin code and the
* version recorded in plugin_config, and when found (and only on a
* small set of pages, to limit overhead), re-registers hooks, runs the
* database upgrade, migrates legacy SNMP read strings, recreates
* missing permission realms, renames legacy realm display names,
* rebuilds cached scanning functions, and updates the stored plugin
* version metadata. Always retries any pending default-site seeding at
* the end.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* locate library files to include.
*/
function mactrack_check_upgrade(): void {
global $config;
$files = ['index.php', 'plugins.php', 'mactrack_devices.php'];
if (!in_array(get_current_page(), $files, true)) {
return;
}
require_once($config['base_path'] . '/plugins/mactrack/includes/database.php');
require_once($config['base_path'] . '/plugins/mactrack/lib/mactrack_functions.php');
$current = plugin_mactrack_version();
$current = $current['version'];
$old = (array) db_fetch_row("SELECT * FROM plugin_config WHERE directory='mactrack'");
if (!cacti_sizeof($old) || $current != $old['version']) {
// if the plugin is installed and/or active
if (!cacti_sizeof($old) || $old['status'] == 1 || $old['status'] == 4) {
// re-register the hooks
plugin_mactrack_install(false);
if (api_plugin_is_enabled('mactrack')) {
// may sound ridiculous, but enables new hooks
api_plugin_enable_hooks('mactrack');
}
// perform a database upgrade
mactrack_database_upgrade();
}
if (read_config_option('mt_convert_readstrings', true) != 'on') {
convert_readstrings();
}
// Remove files tombstoned in manifest.json plus the dev-only tests/ tree.
mactrack_prune_files();
// If are realms are not present in plugin_realms recreate them with the old realm ids (minus 100) so that upgraded installs are not broken
if (!db_fetch_cell("SELECT id FROM plugin_realms WHERE plugin = 'mactrack'")) {
db_execute("INSERT INTO plugin_realms
(id, plugin, file, display)
VALUES (2020, 'mactrack', 'mactrack_view_ips.php,mactrack_view_arp.php,mactrack_view_macs.php,mactrack_view_sites.php,mactrack_view_devices.php,mactrack_view_interfaces.php,mactrack_view_dot1x.php,mactrack_view_graphs.php,mactrack_ajax.php', 'Mactrack Viewer')");
db_execute("INSERT INTO plugin_realms
(id, plugin, file, display)
VALUES (2021, 'mactrack', 'mactrack_ajax_admin.php,mactrack_devices.php,mactrack_snmp.php,mactrack_sites.php,mactrack_device_types.php,mactrack_utilities.php,mactrack_macwatch.php,mactrack_macauth.php,mactrack_vendormacs.php', 'Mactrack Administrator')");
}
// Change old names
if (db_fetch_cell("SELECT count(*) FROM plugin_realms WHERE plugin = 'mactrack' and display='Device Tracking Viewer'")) {
db_fetch_cell("UPDATE plugin_realms set display='Mactrack Viewer' WHERE plugin = 'mactrack' and display='Device Tracking Viewer'");
}
if (db_fetch_cell("SELECT count(*) FROM plugin_realms WHERE plugin = 'mactrack' and display='Device Tracking Administrator'")) {
db_fetch_cell("UPDATE plugin_realms set display='Mactrack Administrator' WHERE plugin = 'mactrack' and display='Device Tracking Administrator'");
}
// rebuild the scanning functions
mactrack_rebuild_scanning_funcs();
// update the plugin information
$info = plugin_mactrack_version();
$id = db_fetch_cell_prepared('SELECT id FROM plugin_config WHERE directory = ?', ['mactrack']);
db_execute_prepared('UPDATE plugin_config
SET name = ?,
author = ?,
webpage = ?,
version = ?
WHERE id = ?',
[$info['longname'], $info['author'], $info['homepage'], $info['version'], $id]);
}
mactrack_retry_default_site();
}
/**
* Checks whether a database table exists.
*
* @param string $table The table name to check.
*
* @return bool True if the table exists, false otherwise.
*/
function mactrack_db_table_exists($table): bool {
return cacti_sizeof(db_fetch_assoc("SHOW TABLES LIKE '$table'")) > 0;
}
/**
* Checks whether a column exists in a database table.
*
* @param string $table The table name to check.
* @param string $column The column name to check for.
*
* @return bool True if the table exists and has the given column,
* false otherwise.
*/
function mactrack_db_column_exists($table, $column): bool {
$found = false;
if (mactrack_db_table_exists($table)) {
$columns = db_fetch_assoc("SHOW COLUMNS FROM $table");
if (cacti_sizeof($columns)) {
foreach ($columns as $row) {
if ($row['Field'] == $column) {
$found = true;
break;
}
}
}
}
return $found;
}
/**
* Checks whether a named index/key exists on a database table.
*
* @param string $table The table name to check.
* @param string $index The index/key name to check for.
*
* @return bool True if the table exists and has the given index, false
* otherwise.
*/
function mactrack_db_key_exists($table, $index): bool {
$found = false;
if (mactrack_db_table_exists($table)) {
$keys = db_fetch_assoc("SHOW INDEXES FROM $table");
if (cacti_sizeof($keys)) {
foreach ($keys as $key) {
if ($key['Key_name'] == $index) {
$found = true;
break;
}
}
}
}
return $found;
}
/**
* Executes an arbitrary SQL statement, discarding its result. Thin
* wrapper used by the schema setup routines; $message is currently
* unused but kept for call-site self-documentation.
*
* @param string $message Human-readable description of the operation
* (unused).
* @param string $syntax The SQL statement to execute.
*
* @return void
*/
function mactrack_execute_sql($message, $syntax): void {
$result = db_execute($syntax);
}
/**
* Creates a database table if it doesn't already exist.
*
* @param string $table The table name to check/create.
* @param string $syntax The CREATE TABLE SQL statement to execute if
* the table doesn't exist.
*
* @return void
*/
function mactrack_create_table($table, $syntax): void {
if (!mactrack_db_table_exists($table)) {
db_execute($syntax);
}
}
/**
* Adds a column to a database table if it doesn't already exist.
*
* @param string $table The table name to check.
* @param string $column The column name to check for.
* @param string $syntax The ALTER TABLE SQL statement to execute if the
* column doesn't exist.
*
* @return void
*/
function mactrack_add_column($table, $column, $syntax): void {
if (!mactrack_db_column_exists($table, $column)) {
db_execute($syntax);
}
}
/**
* Adds an index/key to a database table if it doesn't already exist.
*
* @param string $table The table name to check.
* @param string $index The index/key name to check for.
* @param string $syntax The ALTER TABLE SQL statement to execute if the
* index doesn't exist.
*
* @return void
*/
function mactrack_add_index($table, $index, $syntax): void {
if (!mactrack_db_key_exists($table, $index)) {
db_execute($syntax);
}
}
/**
* Modifies an existing column in a database table (e.g. changing its
* type/default), only if the column currently exists.
*
* @param string $table The table name to check.
* @param string $column The column name to check for.
* @param string $syntax The ALTER TABLE SQL statement to execute if the
* column exists.
*
* @return void
*/
function mactrack_modify_column($table, $column, $syntax): void {
if (mactrack_db_column_exists($table, $column)) {
db_execute($syntax);
}
}
/**
* Deletes a column from a database table, only if the column currently
* exists.
*
* @param string $table The table name to check.
* @param string $column The column name to check for.
* @param string $syntax The ALTER TABLE SQL statement to execute if the
* column exists.
*
* @return void
*/
function mactrack_delete_column($table, $column, $syntax): void {
if (mactrack_db_column_exists($table, $column)) {
db_execute($syntax);
}
}
/**
* Checks whether this plugin's dependencies are satisfied. Cacti
* plugin API hook point; currently always reports dependencies as
* satisfied.
*
* @return bool Always true.
*
* @global array $plugins Cacti global list of installed plugins
* (declared but not used directly here).
* @global array $config Cacti global configuration array (declared
* but not used directly here).
*/
function mactrack_check_dependencies(): bool {
global $plugins, $config;
return true;
}
/**
* Creates/updates the plugin's database tables and ensures a default
* site exists, preserving any prior default-site seeding backoff state
* across incomplete-upgrade re-entries into this hook (unless the
* install is operator-initiated).
*
* @param bool $operator_initiated Whether this call is operator-
* initiated (true, default) versus an
* automatic upgrade re-entry (false).
*
* @return bool True if a default site exists after setup completes,
* false otherwise.
*
* @global array $config Cacti global configuration array; used to
* locate the database include file.
*/
function mactrack_setup_table_new($operator_initiated = true): bool {
global $config;
require_once($config['base_path'] . '/plugins/mactrack/includes/database.php');
// Preserve a prior failed seed's backoff when an incomplete upgrade causes
// Cacti to re-enter this hook on a later request.
if ($operator_initiated || read_config_option('mt_default_site_seed_pending', true) !== 'on') {
mactrack_reset_default_site_retry();
}
return mactrack_setup_database(PHP_SAPI !== 'cli');
}
/**
* Emits this plugin's JavaScript and CSS `<script>`/`<link>` tags into
* the page head, using a theme-specific stylesheet when one exists for
* the currently selected theme. Registered as the 'page_head' Cacti
* hook.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* build asset URLs and check for a theme-specific
* stylesheet.
*/
function mactrack_page_head() {
global $config;
print get_md5_include_js('plugins/mactrack/js/mactrack.js');
print get_md5_include_js('plugins/mactrack/js/mactrack_snmp.js');
print get_md5_include_js('plugins/mactrack/js/cards.js');
print get_md5_include_css('plugins/mactrack/css/cards.css');
if (file_exists($config['base_path'] . '/plugins/mactrack/css/' . get_selected_theme() . '.css')) {
print get_md5_include_css('plugins/mactrack/css/' . get_selected_theme() . '.css');
} else {
print get_md5_include_css('plugins/mactrack/css/mactrack.css');
}
}
/**
* Launches the MacTrack poller script (poller_mactrack.php) as a
* background process. Registered as the 'poller_bottom' Cacti hook,
* invoked at the end of each Cacti poller cycle.
*
* @return void
*
* @global array $config Cacti global configuration array; used to
* build the poller script's path.
*/
function mactrack_poller_bottom() {
global $config;
$command_string = read_config_option('path_php_binary');
$extra_args = '-q ' . $config['base_path'] . '/plugins/mactrack/poller_mactrack.php';
exec_background($command_string, $extra_args);
}
/**
* Builds this plugin's Console "Settings > Mactrack" configuration
* tab's field definitions (scanning frequency, concurrent processes,
* data retention, notification policies, etc.). Registered as the
* 'config_settings' Cacti hook.
*
* @return void
*
* @global array $tabs Cacti settings tabs
* registry; a 'mactrack'
* entry is added.
* @global array $settings Cacti settings field
* registry; a 'mactrack'
* section is added.
* @global array $settings_user Reserved/declared for
* parity with other
* functions in this file;
* not used directly here.
* @global array $tabs_graphs Reserved/declared for
* parity with other
* functions in this file;
* not used directly here.
* @global array $snmp_versions SNMP version option
* list used by SNMP-
* related settings
* fields.
* @global array $mactrack_poller_frequencies Scanning frequency
* option list.
* @global array $mactrack_data_retention Data retention option
* list.
* @global array $mactrack_macauth_frequencies MAC auth report
* frequency option list.
* @global array $mactrack_update_policies Cacti/MacTrack sync
* policy option list.
*/
function mactrack_config_settings() {
global $tabs, $settings, $settings_user, $tabs_graphs, $snmp_versions, $mactrack_poller_frequencies,
$mactrack_data_retention, $mactrack_macauth_frequencies, $mactrack_update_policies;
$tabs['mactrack'] = __('Mactrack', 'mactrack');
$settings['mactrack'] = [
'mactrack_hdr_timing' => [
'friendly_name' => __('General Settings', 'mactrack'),
'method' => 'spacer',
],
'mt_collection_timing' => [
'friendly_name' => __('Scanning Frequency', 'mactrack'),
'description' => __('Choose when to collect MAC and IP Addresses and Interface statistics from your network devices.', 'mactrack'),
'method' => 'drop_array',
'default' => 'disabled',
'array' => $mactrack_poller_frequencies,
],
'mt_processes' => [
'friendly_name' => __('Concurrent Processes', 'mactrack'),
'description' => __('Specify how many devices will be polled simultaneously until all devices have been polled.', 'mactrack'),
'default' => '7',
'method' => 'textbox',
'max_length' => '10',
'size' => '4'
],
'mt_script_runtime' => [
'friendly_name' => __('Scanner Max Runtime', 'mactrack'),
'description' => __('Specify the number of minutes a device scanning function will be allowed to run prior to the system assuming it has been completed. This setting will correct for abended scanning jobs.', 'mactrack'),
'default' => '20',
'method' => 'textbox',
'max_length' => '10',
'size' => '4'
],
'mt_base_time' => [
'friendly_name' => __('Start Time for Data Collection', 'mactrack'),
'description' => __('When would you like the first data collection to take place. All future data collection times will be based upon this start time. A good example would be 12:00AM.', 'mactrack'),
'default' => '1:00am',
'method' => 'textbox',
'max_length' => '10',
'size' => '8'
],
'mt_maint_time' => [
'friendly_name' => __('Database Maintenance Time', 'mactrack'),
'description' => __('When should old database records be removed from the database. Please note that no access will be permitted to the port database while this action is taking place.', 'mactrack'),
'default' => '12:00am',
'method' => 'textbox',
'max_length' => '10',
'size' => '8'
],
'mt_maint_confirm' => [
'friendly_name' => __('Confirm Utilities Prompt', 'mactrack'),
'description' => __('When using utilities, prompt for verification', 'mactrack'),
'default' => read_config_option('deletion_verification'),
'method' => 'checkbox',
],
'mt_data_retention' => [
'friendly_name' => __('Data Retention', 'mactrack'),
'description' => __('How long should port MAC details be retained in the database.', 'mactrack'),
'method' => 'drop_array',
'default' => '14',
'array' => $mactrack_data_retention,
],
'mt_data_retention_ip' => [
'friendly_name' => __('Data Retention IPs', 'mactrack'),
'description' => __('How long should discovered IPs details be retained in the database.', 'mactrack'),
'method' => 'drop_array',
'default' => '3',
'array' => $mactrack_data_retention,
],
'mt_ignorePorts_delim' => [
'friendly_name' => __('Switch Level Ignore Ports Delimiter', 'mactrack'),
'description' => __('What delimiter should Mactrack use when parsing the Ignore Ports string for each switch.', 'mactrack'),
'method' => 'drop_array',
'default' => '-1',
'array' => [
'-1' => __('Auto Detect', 'mactrack'),
':' => __('Colon [:]', 'mactrack'),
'|' => __('Pipe [|]', 'mactrack'),
' ' => __('Space [ ]', 'mactrack')
]
],
'mt_mac_format' => [
'friendly_name' => __('Mac Address Output Format', 'mactrack'),
'description' => __('Format used for display.', 'mactrack'),
'method' => 'drop_array',
'default' => 'aa:bb:cc:dd:ee:ff',
'array' => [
'aa:bb:cc:dd:ee:ff' => 'aa:bb:cc:dd:ee:ff',
'aa-bb-cc-dd-ee-ff' => 'aa-bb-cc-dd-ee-ff',
'aabb-ccdd-eeff' => 'aabb-ccdd-eeff',
'aabbccddeeff' => 'aabbccddeeff',
'aabb.ccdd.eeff' => 'aabb.ccdd.eeff'
]
],
'mt_ignorePorts' => [
'method' => 'textbox',
'friendly_name' => __('Ports to Ignore', 'mactrack'),
'description' => __('Provide a regular expression of ifNames or ifDescriptions of ports to ignore in the interface list. For example, (Vlan|Loopback|Null).', 'mactrack'),
'class' => 'textAreaNotes',
'defaults' => '(Vlan|Loopback|Null)',
'max_length' => '255',
'size' => '80'
],
'mt_interface_high' => [
'friendly_name' => __('Bandwidth Usage Threshold', 'mactrack'),
'description' => __('When reviewing network interface statistics, what bandwidth threshold do you want to view by default.', 'mactrack'),
'method' => 'drop_array',
'default' => '70',
'array' => [
'-1' => __('N/A', 'mactrack'),
'10' => __('%d Percent', 10, 'mactrack'),
'20' => __('%d Percent', 20, 'mactrack'),
'30' => __('%d Percent', 30, 'mactrack'),
'40' => __('%d Percent', 40, 'mactrack'),
'50' => __('%d Percent', 50, 'mactrack'),
'60' => __('%d Percent', 60, 'mactrack'),
'70' => __('%d Percent', 70, 'mactrack'),
'80' => __('%d Percent', 80, 'mactrack'),
'90' => __('%d Percent', 90, 'mactrack')
]
],
'mt_hdr_rdns' => [
'friendly_name' => __('DNS Settings', 'mactrack'),
'method' => 'spacer',
],
'mt_reverse_dns' => [
'friendly_name' => __('Perform Reverse DNS Name Resolution', 'mactrack'),
'description' => __('Should Mactrack perform reverse DNS lookup of the IP addresses associated with ports. CAUTION: If DNS is not properly setup, this will slow scan time significantly.', 'mactrack'),
'default' => '',
'method' => 'checkbox'
],
'mt_dns_primary' => [
'friendly_name' => __('Primary DNS IP Address', 'mactrack'),
'description' => __('Enter the primary DNS IP Address to utilize for reverse lookups.', 'mactrack'),
'method' => 'textbox',
'default' => '',
'max_length' => '30',
'size' => '18'
],
'mt_dns_secondary' => [
'friendly_name' => __('Secondary DNS IP Address', 'mactrack'),
'description' => __('Enter the secondary DNS IP Address to utilize for reverse lookups.', 'mactrack'),
'method' => 'textbox',
'default' => '',
'max_length' => '30',
'size' => '18'
],
'mt_dns_timeout' => [
'friendly_name' => __('DNS Timeout', 'mactrack'),
'description' => __('Please enter the DNS timeout in milliseconds. Mactrack uses a PHP based DNS resolver.', 'mactrack'),
'method' => 'textbox',
'default' => '500',
'max_length' => '10',
'size' => '4'
],
'mt_dns_prime_interval' => [
'friendly_name' => __('DNS Prime Interval', 'mactrack'),
'description' => __('How often, in seconds do Mactrack scanning IP\'s need to be resolved to MAC addresses for DNS resolution. Using a larger number when you have several thousand devices will increase performance.', 'mactrack'),
'method' => 'textbox',
'default' => '120',
'max_length' => '10',
'size' => '4'
],
'mactrack_hdr_notification' => [
'friendly_name' => __('Notification Settings', 'mactrack'),
'method' => 'spacer',
],
'mt_from_email' => [
'friendly_name' => __('Source Address', 'mactrack'),
'description' => __('The source Email address for Mactrack Emails.', 'mactrack'),
'method' => 'textbox',
'default' => '',
'max_length' => '100',
'size' => '30'
],
'mt_from_name' => [
'friendly_name' => __('Source Email Name', 'mactrack'),
'description' => __('The Source Email name for Mactrack Emails.', 'mactrack'),
'method' => 'textbox',
'default' => __('MACTrack Administrator', 'mactrack'),
'max_length' => '100',
'size' => '30'
],
'mt_macwatch_description' => [
'friendly_name' => __('MacWatch Default Body', 'mactrack'),
'description' => htmlspecialchars(__('The Email body preset for Mactrack MacWatch Emails. The body can contain ' .
'any valid html tags. It also supports replacement tags that will be processed when sending an Email. ' .
'Valid tags include <IP>, <MAC>, <TICKET>, <SITENAME>, <DEVICEIP>, <PORTNAME>, <PORTNUMBER>, <DEVICENAME>.', 'mactrack')),
'method' => 'textarea',
'default' => __('Mac Address <MAC> found at IP Address <IP> for Ticket Number: <TICKET>.<br>The device is located at<br>Site: <SITENAME>, Device <DEVICENAME>, IP <DEVICEIP>, Port <PORTNUMBER>, and Port Name <PORTNAME>', 'mactrack'),
'class' => 'textAreaNotes',
'max_length' => '512',
'textarea_rows' => '5',
'textarea_cols' => '80',
],
'mt_macauth_emails' => [
'friendly_name' => __('MacAuth Report Email Addresses', 'mactrack'),
'description' => __('A comma delimited list of users to receive the MacAuth Email notifications.', 'mactrack'),
'method' => 'textarea',
'default' => '',
'class' => 'textAreaNotes',
'max_length' => '255',
'textarea_rows' => '5',
'textarea_cols' => '80',
],
'mt_macauth_email_frequency' => [
'friendly_name' => __('MacAuth Report Frequency', 'mactrack'),
'description' => __('How often will the MacAuth Reports be Emailed.', 'mactrack'),
'method' => 'drop_array',
'default' => 'disabled',
'array' => $mactrack_macauth_frequencies,
],
'mactrack_hdr_arpwatch' => [
'friendly_name' => __('Mactrack ArpWatch Settings', 'mactrack'),
'method' => 'spacer',
],
'mt_arpwatch' => [
'friendly_name' => __('Enable ArpWatch', 'mactrack'),
'description' => __('Should Mactrack also use ArpWatch data to supplement Mac to IP/DNS resolution?', 'mactrack'),
'default' => '',
'method' => 'checkbox'
],
'mt_arpwatch_path' => [
'friendly_name' => __('ArpWatch Database Path', 'mactrack'),
'description' => __('The location of the ArpWatch Database file on the Cacti server.', 'mactrack'),
'method' => 'filepath',
'default' => '',
'max_length' => '255',
'size' => '60'
],
'mactrack_hdr_general' => [
'friendly_name' => __('SNMP Presets', 'mactrack'),
'method' => 'spacer',
],
'mt_update_policy' => [
'friendly_name' => __('Update Policy for SNMP Options', 'mactrack'),
'description' => __('Policy for synchronization of SNMP Options between Cacti devices and Mactrack Devices.', 'mactrack'),
'method' => 'drop_array',
'default' => 1,
'array' => $mactrack_update_policies,
],
'mt_snmp_ver' => [
'friendly_name' => __('Version', 'mactrack'),
'description' => __('Default SNMP version for all new hosts.', 'mactrack'),
'method' => 'drop_array',
'default' => '2',
'array' => $snmp_versions,
],
'mt_snmp_community' => [
'friendly_name' => __('Community', 'mactrack'),
'description' => __('Default SNMP read community for all new hosts.', 'mactrack'),
'method' => 'textbox',
'default' => 'public',
'max_length' => '100',
'size' => '20'
],
'mt_snmp_communities' => [
'friendly_name' => __('Communities', 'mactrack'),
'description' => __('Fill in the list of available SNMP read strings to test for this device. Each read string must be separated by a colon \':\'. These read strings will be tested sequentially if the primary read string is invalid.', 'mactrack'),
'method' => 'textbox',
'default' => 'public:private:secret',
'max_length' => '255'
],
'mt_snmp_port' => [
'friendly_name' => __('Port', 'mactrack'),
'description' => __('The UDP/TCP Port to poll the SNMP agent on.', 'mactrack'),
'method' => 'textbox',
'default' => '161',
'max_length' => '10',
'size' => '4'
],
'mt_snmp_timeout' => [
'friendly_name' => __('Timeout', 'mactrack'),
'description' => __('Default SNMP timeout in milli-seconds.', 'mactrack'),
'method' => 'textbox',
'default' => '500',
'max_length' => '10',
'size' => '4'
],
'mt_snmp_retries' => [
'friendly_name' => __('Retries', 'mactrack'),
'description' => __('The number times the SNMP poller will attempt to reach the host before failing.', 'mactrack'),
'method' => 'textbox',
'default' => '3',
'max_length' => '10',
'size' => '4'
]
];
$ts = [];
foreach ($settings['path'] as $t => $ta) {
$ts[$t] = $ta;
if ($t == 'path_snmpget') {
$ts['path_snmpbulkwalk'] = [
'friendly_name' => __('snmpbulkwalk Binary Path', 'mactrack'),
'description' => __('The path to your snmpbulkwalk binary.', 'mactrack'),
'method' => 'textbox',
'max_length' => '255'
];
}
}
$settings['path'] = $ts;
$tabs_graphs += ['mactrack' => __('MacTrack Settings', 'mactrack')];
$settings_user += [
'mactrack' => [
'default_mactrack_tab' => [
'friendly_name' => __('Default Tab', 'mactrack'),
'description' => __('Which MacTrack tab would you want to be your Default tab every time you goto the MacTrack second.', 'mactrack'),
'method' => 'drop_array',
'default' => 'sites',
'array' => [
'sites' => __('Sites', 'mactrack'),
'devices' => __('Devices', 'mactrack'),
'ips' => __('IP Addresses', 'mactrack'),
'macs' => __('Mac Addresses', 'mactrack'),
'interfaces' => __('Interfaces', 'mactrack'),
'dot1x' => __('dot1x Deta', 'mactrack')
]
]
]
];
$settings['mail'] += [
'settings_proxy_header' => [
'friendly_name' => __('Internet Proxy Settings'),
'collapsible' => 'true',
'method' => 'spacer',
],
'settings_proxy_server' => [
'friendly_name' => __('Internet Proxy Address'),
'description' => __('For either core Cacti Services or Plugins that require internet access, enter the proxy server and port here in the following format IP:PORT. For example 192.168.1.1:8080.'),
'method' => 'textbox',
'default' => '',
'max_length' => '30',
'size' => '30'
],
'settings_proxy_user' => [
'friendly_name' => __('Internet Proxy User'),
'description' => __('If your Internet Proxy requires a username, enter it here.'),
'method' => 'textbox',
'default' => '',
'max_length' => '30',
'size' => '10'
],
'settings_proxy_password' => [
'friendly_name' => __('Internet Proxy Password'),
'description' => __('If your Internet Proxy requires a password, enter it here.'),
'method' => 'textbox_password',
'default' => '',
'max_length' => '30',
'size' => '10'
],
];
mactrack_check_upgrade();
}
/**
* Registers this plugin's pages (devices, SNMP options, sites, device
* types, utilities, mac watch, mac auth, vendor macs, and their
* sub-actions/edit views) into Cacti's breadcrumb navigation array.
* Registered as the 'draw_navigation_text' Cacti hook.
*
* @param array $nav The existing navigation entries array, keyed by
* "file.php:action".
*
* @return array The navigation entries array with this plugin's pages
* added.
*/
function mactrack_draw_navigation_text($nav) {
$nav['mactrack_view_dashboard.php:'] = [
'title' => __('Mactrack Dashboard', 'mactrack'),
'mapping' => '',
'url' => 'mactrack_view_dashboard.php',
'level' => '0'
];
$nav['mactrack_devices.php:'] = [
'title' => __('Mactrack Devices', 'mactrack'),
'mapping' => 'index.php:',
'url' => 'mactrack_devices.php',
'level' => '1'
];
$nav['mactrack_devices.php:edit'] = [
'title' => __('(Edit)', 'mactrack'),
'mapping' => 'index.php:,mactrack_devices.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_devices.php:import'] = [
'title' => __('(Import)', 'mactrack'),
'mapping' => 'index.php:,mactrack_devices.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_devices.php:actions'] = [
'title' => __('Actions', 'mactrack'),
'mapping' => 'index.php:,mactrack_devices.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_snmp.php:'] = [
'title' => __('Mactrack SNMP Options', 'mactrack'),
'mapping' => 'index.php:',
'url' => 'mactrack_snmp.php',
'level' => '1'
];
$nav['mactrack_snmp.php:actions'] = [
'title' => __('Actions', 'mactrack'),
'mapping' => 'index.php:,mactrack_snmp.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_snmp.php:edit'] = [
'title' => __('(Edit)', 'mactrack'),
'mapping' => 'index.php:,mactrack_snmp.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_snmp.php:item_edit'] = [
'title' => __('(Edit)', 'mactrack'),
'mapping' => 'index.php:,mactrack_snmp.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_device_types.php:'] = [
'title' => __('Mactrack Device Types', 'mactrack'),
'mapping' => 'index.php:',
'url' => 'mactrack_device_types.php',
'level' => '1'
];
$nav['mactrack_device_types.php:edit'] = [
'title' => __('(Edit)', 'mactrack'),
'mapping' => 'index.php:,mactrack_device_types.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_device_types.php:import'] = [
'title' => __('(Import)', 'mactrack'),
'mapping' => 'index.php:,mactrack_device_types.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_device_types.php:actions'] = [
'title' => __('Actions', 'mactrack'),
'mapping' => 'index.php:,mactrack_device_types.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_sites.php:'] = [
'title' => __('Mactrack Sites', 'mactrack'),
'mapping' => 'index.php:',
'url' => 'mactrack_sites.php',
'level' => '1'
];
$nav['mactrack_sites.php:edit'] = [
'title' => __('(Edit)', 'mactrack'),
'mapping' => 'index.php:,mactrack_sites.php:',
'url' => '',
'level' => '2'
];
$nav['mactrack_sites.php:actions'] = [