-
Notifications
You must be signed in to change notification settings - Fork 6
/
hmib_types.php
1028 lines (860 loc) · 32.1 KB
/
hmib_types.php
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-2024 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/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include('./include/auth.php');
include_once('./lib/snmp.php');
$host_types_actions = array(
1 => __('Delete', 'hmib'),
2 => __('Duplicate', 'hmib')
);
/* set default action */
set_default_action('');
switch (get_nfilter_request_var('action')) {
case 'save':
form_save();
break;
case 'actions':
form_actions();
break;
case 'edit':
top_header();
hmib_host_type_edit();
bottom_footer();
break;
case 'import':
top_header();
hmib_host_type_import();
bottom_footer();
break;
default:
if (isset_request_var('scan')) {
rescan_types();
header('Location: hmib_types.php?header=false');
exit;
} elseif (isset_request_var('import')) {
header('Location: hmib_types.php?action=import');
exit;
} elseif (isset_request_var('export')) {
hmib_host_type_export();
exit;
} else {
top_header();
hmib_host_type();
bottom_footer();
}
break;
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
if ((isset_request_var('save_component_host_type')) && (isempty_request_var('add_dq_y'))) {
$host_type_id = hmib_host_type_save(get_filter_request_var('id'), get_nfilter_request_var('name'),
get_nfilter_request_var('version'), get_nfilter_request_var('sysDescrMatch'), get_nfilter_request_var('sysObjectID'));
header('Location: hmib_types.php?header=false&action=edit&id=' . (empty($host_type_id) ? get_request_var('id') : $host_type_id));
exit;
}
if (isset_request_var('save_component_import')) {
if (($_FILES['import_file']['tmp_name'] != 'none') && ($_FILES['import_file']['tmp_name'] != '')) {
/* file upload */
$csv_data = file($_FILES['import_file']['tmp_name']);
/* obtain debug information if it's set */
$debug_data = hmib_host_type_import_processor($csv_data);
if (cacti_sizeof($debug_data) > 0) {
$_SESSION['import_debug_info'] = $debug_data;
}
} else {
header('Location: hmib_types.php?action=import');
exit;
}
header('Location: hmib_types.php?action=import');
}
}
function api_hmib_host_type_remove($host_type_id) {
db_execute_prepared('DELETE FROM plugin_hmib_hrSystemTypes
WHERE id = ?',
array($host_type_id));
db_execute_prepared('UPDATE plugin_hmib_hrSystem
SET host_type=0
WHERE host_type = ?',
array($host_type_id));
}
function hmib_host_type_save($host_type_id, $name, $version, $sysDescrMatch, $sysObjectID) {
if (empty($host_type_id)) {
$save['id'] = $host_type_id;
$save['name'] = form_input_validate($name, 'name', '', false, 3);
$save['version'] = $version;
$save['sysDescrMatch'] = form_input_validate($sysDescrMatch, 'sysDescrMatch', '', true, 3);
$save['sysObjectID'] = form_input_validate($sysObjectID, 'sysObjectID', '', true, 3);
$host_type_id = 0;
if (!is_error_message()) {
$host_type_id = sql_save($save, 'plugin_hmib_hrSystemTypes');
if ($host_type_id) {
raise_message(1);
} else {
raise_message(2);
}
}
} else {
db_execute_prepared('UPDATE plugin_hmib_hrSystemTypes
SET name = ?, version = ?, sysDescrMatch = ?, sysObjectID = ?
WHERE id = ?',
array($name, $version, $sysDescrMatch, $sysObjectID, $host_type_id));
raise_message(1);
}
return $host_type_id;
}
function hmib_duplicate_host_type($host_type_id, $dup_id, $host_type_title) {
if (!empty($host_type_id)) {
$host_type = db_fetch_row_prepared('SELECT *
FROM plugin_hmib_hrSystemTypes
WHERE id = ?',
array($host_type_id));
/* create new entry: graph_local */
$save['id'] = 0;
if (substr_count($host_type_title, '<description>')) {
/* substitute the title variable */
$save['name'] = str_replace('<description>', $host_type['name'], $host_type_title);
} else {
$save['name'] = $host_type_title . '(' . $dup_id . ')';
}
$save['version'] = $host_type['version'];
$save['sysDescrMatch'] = '--dup--' . $host_type['sysDescrMatch'];
$save['sysObjectID'] = '--dup--' . $host_type['sysObjectID'];
$host_type_id = sql_save($save, 'plugin_hmib_hrSystemTypes');
}
}
/* ------------------------
The 'actions' function
------------------------ */
function form_actions() {
global $config, $host_types_actions, $fields_hmib_host_types_edit;
/* ================= input validation ================= */
get_filter_request_var('drp_action');
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_request_var('drp_action') == '1') { /* delete */
foreach($selected_items as $item) {
api_hmib_host_type_remove($item);
}
} elseif (get_request_var('drp_action') == '2') { /* duplicate */
$i = 0;
foreach($selected_items as $item) {
hmib_duplicate_host_type($item, $i, get_request_var('title_format'));
$i++;
}
}
}
header('Location: hmib_types.php?header=false');
exit;
}
/* setup some variables */
$host_types_list = ''; $i = 0;
/* loop through each of the device types selected on the previous page and get more info about them */
if (cacti_sizeof($_POST)) {
foreach($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$host_types_info = db_fetch_row_prepared('SELECT name
FROM plugin_hmib_hrSystemTypes
WHERE id = ?',
array($matches[1]));
$host_types_list .= '<li>' . html_escape($host_types_info['name']) . '</li>';
$host_types_array[$i] = $matches[1];
}
$i++;
}
}
top_header();
form_start('hmib_types.php');
html_start_box($host_types_actions[get_request_var('drp_action')], '60%', '', '3', 'center', '');
if (cacti_sizeof($host_types_array)) {
if (get_filter_request_var('drp_action') == '1') { /* delete */
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to Delete the following Host Type(s)', 'hmib') . "</p>
<ul class='itemList'>$host_types_list</ul>
</td>
</tr>";
$save_html = "<input type='button' value='" . __('Cancel', 'hmib') . "' onClick='cactiReturnTo()'> <input type='submit' value='" . __('Continue', 'hmib') . "' title='" . __('Delete Host Type(s)', 'hmib') . "'>";
} elseif (get_filter_request_var('drp_action') == '2') { /* duplicate */
print "<tr>
<td class='textArea'>
<p>" . __('Click \'Continue\' to Duplicate the following Host Type(s). You may optionally change the description for the new Host Type(s). Otherwise, do not change value below and the original name will be replicated with a new suffix.', 'hmib') . "</p>
<ul class='itemList'>$host_types_list</ul>
<p><strong>" . __('Host Type Prefix:', 'hmib') . "</strong><br>"; form_text_box('title_format', '<description> (1)', '', '255', '30', 'text'); print "</p>
</td>
</tr>";
$save_html = "<input type='button' value='" . __('Cancel', 'hmib') . "' onClick='cactiReturnTo()'> <input type='submit' value='" . __('Continue', 'hmib') . "' title='" . __('Duplicate Host Type(s)', 'hmib') . "'>";
}
} else {
raise_message(40);
header('Location: hmib_types.php?header=false');
exit;
}
print "<tr class='even'>
<td colspan='2' class='saveRow'>
<input type='hidden' name='action' value='actions'>
<input type='hidden' name='selected_items' value='" . (isset($host_types_array) ? serialize($host_types_array) : '') . "'>
<input type='hidden' name='drp_action' value='" . get_request_var('drp_action') . "'>
$save_html
</td>
</tr>";
html_end_box();
form_end();
bottom_footer();
}
/* ---------------------
HMIB Device Type Functions
--------------------- */
function hmib_validate_request_vars() {
/* ================= input validation and session storage ================= */
$filters = array(
'rows' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
'filter' => array(
'filter' => FILTER_DEFAULT,
'pageset' => true,
'default' => ''
),
'version' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => 'All',
'options' => array('options' => 'sanitize_search_string')
),
'vendor' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '',
'options' => array('options' => 'sanitize_search_string')
),
'sort_column' => array(
'filter' => FILTER_CALLBACK,
'default' => 'name',
'options' => array('options' => 'sanitize_search_string')
),
'sort_direction' => array(
'filter' => FILTER_CALLBACK,
'default' => 'ASC',
'options' => array('options' => 'sanitize_search_string')
)
);
validate_store_request_vars($filters, 'sess_hmib_ht');
/* ================= input validation ================= */
}
function hmib_host_type_export() {
global $device_actions, $hmib_host_types, $config;
hmib_validate_request_vars();
$sql_where = '';
$host_types = hmib_get_host_types($sql_where, 0, false);
$xport_array = array();
array_push($xport_array, '"id","name","version",' .
'"sysDescrMatch","sysObjectID"');
if (cacti_sizeof($host_types)) {
foreach($host_types as $host_type) {
array_push($xport_array,'"' .
$host_type['id'] . '","' .
$host_type['name'] . '","' .
$host_type['version'] . '","' .
$host_type['sysDescrMatch'] . '","' .
$host_type['sysObjectID'] . '"');
}
}
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename=cacti_host_type_xport.csv');
foreach($xport_array as $xport_line) {
print $xport_line . "\n";
}
}
function rescan_types() {
global $cnn_id;
/* let's allocate an array for results */
$insert_array = array();
$new_name = __('New Type', 'hmib');
$new_version = __('Unknown', 'hmib');
/* get all the various device types from the database */
$unknown_host_types = db_fetch_assoc("SELECT DISTINCT sysObjectID, sysDescr, host_type
FROM plugin_hmib_hrSystem
WHERE sysObjectID!='' AND sysDescr!='' AND host_type=0");
/* delete all unknown entries */
db_execute("DELETE FROM plugin_hmib_hrSystemTypes
WHERE name='" . $new_name . "'
AND version='" . $new_version . "'");
/* get all known devices types from the device type database */
$known_types = db_fetch_assoc('SELECT id, sysDescrMatch, sysObjectID FROM plugin_hmib_hrSystemTypes');
/* loop through all device rows and look for a matching type */
if (cacti_sizeof($unknown_host_types)) {
foreach($unknown_host_types as $type) {
$found = false;
if (cacti_sizeof($known_types)) {
foreach($known_types as $known) {
db_execute('UPDATE plugin_hmib_hrSystem SET host_type=' . $known['id'] . "
WHERE host_type=0 AND (sysObjectID LIKE '%" . $known['sysObjectID'] . "%' AND
sysDescr LIKE '%" . $known['sysDescrMatch'] . "%')
OR (sysObjectID RLIKE '" . $known['sysObjectID'] . "' AND
sysDescr RLIKE '" . $known['sysDescrMatch'] . "')");
if (db_affected_rows() > 0) {
$found = true;
break;
}
}
}
}
}
/* update the host types from unknown_host_types that have a value of 0 */
db_execute("INSERT INTO plugin_hmib_hrSystemTypes
(name, version, sysDescrMatch, sysObjectID)
SELECT '$new_name', '$new_version', sysDescr, sysObjectID FROM plugin_hmib_hrSystem WHERE host_type=0");
$new_types = db_affected_rows();
if ($new_types > 0) {
$_SESSION['hmib_message'] = __('There were %d Device Types Added!', $new_types, 'hmib');
raise_message('hmib_message');
} else {
$_SESSION['hmib_message'] = __('No New Host Types Found!', 'hmib');
raise_message('hmib_message');
}
}
function hmib_host_type_import() {
global $config;
?><form method='post' action='hmib_types.php?action=import' enctype='multipart/form-data'><?php
if ((isset($_SESSION['import_debug_info'])) && (is_array($_SESSION['import_debug_info']))) {
html_start_box(__('Import Results', 'hmib'), '100%', '', '3', 'center', '');
print "<tr class='odd'><td><p class='textArea'>" . __('Cacti has imported the following items:', 'hmib') . "</p>";
foreach($_SESSION['import_debug_info'] as $import_result) {
form_alternate_row();
print '<td>' . $import_result . '</td>';
print "</tr>";
}
html_end_box();
kill_session_var('import_debug_info');
}
html_start_box(__('Import Host MIB OS Types', 'hmib'), '100%', '', '3', 'center', '');
form_alternate_row();?>
<td width='50%'><font class='textEditTitle'><?php print __('Import Device Types from Local File', 'hmib');?></font><br>
<?php print __('Please specify the location of the CSV file containing your device type information.', 'hmib');?>
</td>
<td align='left'>
<input type='file' name='import_file'>
</td>
</tr><?php
form_alternate_row();?>
<td width='50%'><font class='textEditTitle'><?php print __('Overwrite Existing Data?', 'hmib');?></font><br>
<?php print __('Should the import process be allowed to overwrite existing data? Please note, this does not mean delete old row, only replace duplicate rows.', 'hmib');?>
</td>
<td align='left'>
<input type='checkbox' name='allow_update' id='allow_update'><?php print __('Allow Existing Rows to be Updated?', 'hmib');?>
</td><?php
html_end_box(false);
html_start_box(__('Required File Format Notes', 'hmib'), '100%', '', '3', 'center', '');
form_alternate_row();?>
<td><strong><?php print __('The file must contain a header row with the following column headings.', 'hmib');?></strong>
<br><br>
<strong>name</strong> - <?php print __('A common name for the Host Type. For example, Windows 7', 'hmib');?><br>
<strong>version</strong> - <?php print __('The OS version for the Host Type', 'hmib');?><br>
<strong>sysDescrMatch</strong> - <?php print __('A unique set of characters from the snmp sysDescr that uniquely identify this device', 'hmib');?><br>
<strong>sysObjectID</strong> - <?php print __('The vendor specific snmp sysObjectID that distinguishes this device from the next', 'hmib');?><br>
<br>
<strong><?php print __('The primary key for this table is a combination of the following two fields:', 'hmib');?></strong>
<br><br>
sysDescrMatch, sysObjectID
<br><br>
<strong><?php print __('Therefore, if you attempt to import duplicate device types, the existing data will be updated with the new information.', 'hmib');?></strong>
<br><br>
<strong><?php print __('The Host Type is determined by scanning its snmp agent for the sysObjectID and sysDescription and comparing it against values in the Host Types database. The first match that is found in the database is used aggregate Host data. Therefore, it is very important that you select valid sysObjectID, sysDescrMatch for your Hosts.', 'hmib');?></strong>
<br>
</td>
</tr><?php
form_hidden_box('save_component_import','1','');
html_end_box();
form_save_button('return', 'import');
}
function hmib_host_type_import_processor(&$host_types) {
$i = 0;
$sysDescrMatch_id = -1;
$sysObjectID_id = -1;
$host_type_id = -1;
$save_vendor_id = -1;
$save_description_id = -1;
$save_version_id = -1;
$save_name_id = -1;
$save_order = '';
$update_suffix = '';
$return_array = array();
$insert_columns = array();
foreach($host_types as $host_type) {
/* parse line */
$line_array = str_getcsv($host_type);
//$line_array = explode(',', $host_type);
/* header row */
if ($i == 0) {
$save_order = '(';
$j = 0;
$first_column = true;
$update_suffix = '';
$required = 0;
foreach($line_array as $line_item) {
switch ($line_item) {
case 'id':
if (!$first_column) {
$save_order .= ', ';
}
$host_type_id = $j;
$required++;
$save_order .= $line_item;
$insert_columns[] = $j;
$first_column = false;
if (strlen($update_suffix)) {
$update_suffix .= ", $line_item=VALUES($line_item)";
} else {
$update_suffix .= " ON DUPLICATE KEY UPDATE $line_item=VALUES($line_item)";
}
break;
case 'sysDescrMatch':
if (!$first_column) {
$save_order .= ', ';
}
$sysDescrMatch_id = $j;
$required++;
$save_order .= $line_item;
$insert_columns[] = $j;
$first_column = false;
if (strlen($update_suffix)) {
$update_suffix .= ", $line_item=VALUES($line_item)";
} else {
$update_suffix .= " ON DUPLICATE KEY UPDATE $line_item=VALUES($line_item)";
}
break;
case 'sysObjectID':
if (!$first_column) {
$save_order .= ', ';
}
$sysObjectID_id = $j;
$required++;
$save_order .= $line_item;
$insert_columns[] = $j;
$first_column = false;
if (strlen($update_suffix)) {
$update_suffix .= ", $line_item=VALUES($line_item)";
} else {
$update_suffix .= " ON DUPLICATE KEY UPDATE $line_item=VALUES($line_item)";
}
break;
case 'version':
if (!$first_column) {
$save_order .= ', ';
}
$save_order .= $line_item;
$insert_columns[] = $j;
$save_vendor_id = $j;
$first_column = false;
if (strlen($update_suffix)) {
$update_suffix .= ", $line_item=VALUES($line_item)";
} else {
$update_suffix .= " ON DUPLICATE KEY UPDATE $line_item=VALUES($line_item)";
}
break;
case 'name':
if (!$first_column) {
$save_order .= ', ';
}
$save_order .= $line_item;
$insert_columns[] = $j;
$save_description_id = $j;
$first_column = false;
if (strlen($update_suffix)) {
$update_suffix .= ", $line_item=VALUES($line_item)";
} else {
$update_suffix .= " ON DUPLICATE KEY UPDATE $line_item=VALUES($line_item)";
}
break;
default:
/* ignore unknown columns */
}
$j++;
}
$save_order .= ')';
if ($required >= 3) {
array_push($return_array, '<strong>HEADER LINE PROCESSED OK</strong>: <br>Columns found where: ' . $save_order . '<br>');
} else {
array_push($return_array, '<strong>HEADER LINE PROCESSING ERROR</strong>: Missing required field <br>Columns found where:' . $save_order . '<br>');
break;
}
} else {
$save_value = '(';
$j = 0;
$first_column = true;
$sql_where = '';
foreach($line_array as $line_item) {
if (in_array($j, $insert_columns)) {
if (!$first_column) {
$save_value .= ',';
} else {
$first_column = false;
}
if ($j == $host_type_id || $j == $sysDescrMatch_id || $j == $sysObjectID_id ) {
if (strlen($sql_where)) {
switch($j) {
case $host_type_id:
$sql_where .= " AND id=" . db_qstr($line_item);
break;
case $sysDescrMatch_id:
$sql_where .= " AND sysDescrMatch=" . db_qstr($line_item);
break;
case $sysObjectID_id:
$sql_where .= " AND sysObjectID=" . db_qstr($line_item);
break;
default:
/* do nothing */
}
} else {
switch($j) {
case $host_type_id:
$sql_where .= "WHERE id=" . db_qstr($line_item);
break;
case $sysDescrMatch_id:
$sql_where .= "WHERE sysDescrMatch=" . db_qstr($line_item);
break;
case $sysObjectID_id:
$sql_where .= "WHERE sysObjectID=" . db_qstr($line_item);
break;
default:
/* do nothing */
}
}
}
if ($j == $sysDescrMatch_id) {
$sysDescrMatch = $line_item;
}
if ($j == $sysObjectID_id) {
$sysObjectID = $line_item;
}
if ($j == $save_vendor_id) {
$vendor = $line_item;
}
if ($j == $save_description_id) {
$description = $line_item;
}
$save_value .= db_qstr($line_item);
}
$j++;
}
$save_value .= ')';
if ($j > 0) {
if (isset_request_var('allow_update')) {
$sql_execute = 'INSERT INTO mac_track_device_types ' . $save_order .
' VALUES' . $save_value . $update_suffix;
if (db_execute($sql_execute)) {
array_push($return_array,"INSERT SUCCEEDED: Name: $name, Version: $version, sysDescr: $sysDescrMatch, sysObjectID: $sysObjectID");
} else {
array_push($return_array,"<strong>INSERT FAILED:</strong> Name: $name, Version: $version, sysDescr: $sysDescrMatch, sysObjectID: $sysObjectID");
}
} else {
/* perform check to see if the row exists */
$existing_row = db_fetch_row("SELECT * FROM plugin_hmib_hrSystemTypes $sql_where");
if (cacti_sizeof($existing_row)) {
array_push($return_array,"<strong>INSERT SKIPPED, EXISTING:</strong> Name: $name, Vendor: $vendor, sysDescr: $sysDescrMatch, sysObjectID: $sysObjectID");
} else {
$sql_execute = 'INSERT INTO plugin_hmib_hrSystemTypes ' . $save_order .
' VALUES' . $save_value;
if (db_execute($sql_execute)) {
array_push($return_array,"INSERT SUCCEEDED: Name: $name, Version: $version, sysDescr: $sysDescrMatch, sysObjectID: $sysObjectID");
} else {
array_push($return_array,"<strong>INSERT FAILED:</strong> Name: $name, Version: $version, sysDescr: $sysDescrMatch, sysObjectID: $sysObjectID");
}
}
}
}
}
$i++;
}
return $return_array;
}
function hmib_host_type_edit() {
global $config;
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('id'));
/* ==================================================== */
/* file: mactrack_device_types.php, action: edit */
$fields_host_type_edit = array(
'spacer0' => array(
'method' => 'spacer',
'friendly_name' => __('Device Scanning Function Options', 'hmib')
),
'name' => array(
'method' => 'textbox',
'friendly_name' => __('Name', 'hmib'),
'description' => __('Give this Host Type a meaningful name.', 'hmib'),
'value' => '|arg1:name|',
'max_length' => '250'
),
'version' => array(
'method' => 'textbox',
'friendly_name' => __('Version', 'hmib'),
'description' => __('Fill in the name for the version of this Host Type.', 'hmib'),
'value' => '|arg1:version|',
'max_length' => '10',
'size' => '10'
),
'sysDescrMatch' => array(
'method' => 'textbox',
'friendly_name' => __('System Description Match', 'hmib'),
'description' => __('Provide key information to help HMIB detect the type of Host. SQL Where expressions are supported. SQL Where wildcard character is the \'%\' sign. Regular Expressions have been removed due to compatibility issues.', 'hmib'),
'value' => '|arg1:sysDescrMatch|',
'max_length' => '250'
),
'sysObjectID' => array(
'method' => 'textbox',
'friendly_name' => __('Vendor snmp Object ID', 'hmib'),
'description' => __('Provide key information to help HMIB detect the type of Host. SQL Where expressions are supported. SQL Where wildcard character is the \'%\' sign. Regular Expressions have been removed due to compatibility issues.', 'hmib'),
'value' => '|arg1:sysObjectID|',
'max_length' => '250'
),
'id' => array(
'method' => 'hidden_zero',
'value' => '|arg1:id|'
),
'_id' => array(
'method' => 'hidden_zero',
'value' => '|arg1:id|'
),
'save_component_host_type' => array(
'method' => 'hidden',
'value' => '1'
)
);
if (!isempty_request_var('id')) {
$host_type = db_fetch_row('SELECT * FROM plugin_hmib_hrSystemTypes WHERE id=' . get_filter_request_var('id'));
$header_label = __esc('Host MIB OS Types [edit: %s]', $host_type['name'], 'hmib');
} else {
$header_label = __('Host MIB OS Types [new]', 'hmib');
}
form_start('hmib_types.php');
html_start_box($header_label, '100%', '', '3', 'center', '');
draw_edit_form(
array(
'config' => array('form_name' => 'chk'),
'fields' => inject_form_variables($fields_host_type_edit, (isset($host_type) ? $host_type : array()))
)
);
html_end_box();
if (isset($host_type)) {
form_save_button('hmib_types.php', 'save', '', 'id');
} else {
form_save_button('cancel', 'save', '', 'id');
}
}
function hmib_get_host_types(&$sql_where, $rows, $apply_limits = true) {
if (get_request_var('filter') != '') {
$sql_where = ' WHERE (
plugin_hmib_hrSystemTypes.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR plugin_hmib_hrSystemTypes.version LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR plugin_hmib_hrSystemTypes.sysObjectID LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . '
OR plugin_hmib_hrSystemTypes.sysDescrMatch LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')';
}
$sql_order = get_order_string();
if ($apply_limits) {
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ',' . $rows;
} else {
$sql_limit = '';
}
$query_string = "SELECT plugin_hmib_hrSystemTypes.*, count(host_type) AS totals
FROM plugin_hmib_hrSystemTypes
LEFT JOIN plugin_hmib_hrSystem
ON plugin_hmib_hrSystemTypes.id=plugin_hmib_hrSystem.host_type
$sql_where
GROUP BY plugin_hmib_hrSystemTypes.id
$sql_order
$sql_limit";
//print $query_string;
return db_fetch_assoc($query_string);
}
function hmib_host_type() {
global $host_types_actions, $hmib_host_types, $config, $item_rows;
hmib_validate_request_vars();
if (get_request_var('rows') == -1) {
$row_limit = read_config_option('num_rows_table');
} elseif (get_request_var('rows') == -2) {
$row_limit = 999999;
} else {
$row_limit = get_request_var('rows');
}
html_start_box(__('Host MIB OS Type Filters', 'hmib'), '100%', '', '3', 'center', 'hmib_types.php?action=edit');
hmib_host_type_filter();
html_end_box();
$sql_where = '';
$host_types = hmib_get_host_types($sql_where, $row_limit);
$total_rows = db_fetch_cell('SELECT
COUNT(*)
FROM plugin_hmib_hrSystemTypes' . $sql_where);
$nav = html_nav_bar('hmib_types.php', MAX_DISPLAY_PAGES, get_request_var('page'), $row_limit, $total_rows, 9, __('OS Types', 'hmib'), 'page', 'main');
form_start('hmib_types.php');
print $nav;
html_start_box('', '100%', '', '3', 'center', '');
$display_text = array(
'name' => array(__('Host Type Name', 'hmib'), 'ASC'),
'version' => array(__('OS Version', 'hmib'), 'DESC'),
'totals' => array(__('Hosts', 'hmib'), 'DESC'),
'sysObjectID' => array(__('SNMP ObjectID', 'hmib'), 'DESC'),
'sysDescrMatch' => array(__('SNMP Sys Description Match', 'hmib'), 'ASC')
);
html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'));
if (cacti_sizeof($host_types)) {
foreach ($host_types as $host_type) {
form_alternate_row('line' . $host_type['id'], true);
form_selectable_cell('<a class="linkEditMain" href="' . htmlspecialchars('hmib_types.php?action=edit&id=' . $host_type['id']) . '">' . $host_type['name'] . '</a>', $host_type['id']);
form_selectable_cell($host_type['version'], $host_type['id']);
form_selectable_cell($host_type['totals'], $host_type['id']);
form_selectable_cell($host_type['sysObjectID'], $host_type['id']);
form_selectable_cell($host_type['sysDescrMatch'], $host_type['id']);
form_checkbox_cell($host_type['name'], $host_type['id']);
form_end_row();
}
} else {
print "<tr><td colspan='10'><em>" . __('No Host Types Found', 'hmib') . "</em></td></tr>";
}
html_end_box(false);
if (cacti_sizeof($host_types)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($host_types_actions);
form_end();
}
/* hmib_draw_actions_dropdown - draws a table the allows the user to select an action to perform
on one or more data elements
@arg $actions_array - an array that contains a list of possible actions. this array should
be compatible with the form_dropdown() function */
function hmib_draw_actions_dropdown($actions_array, $include_form_end = true) {
global $config;
?>
<table align='center' width='100%'>
<tr>
<td width='1' valign='top'>
<img src='<?php print $config['url_path']; ?>images/arrow.gif' alt='' align='middle'>
</td>
<td align='right'>
<?php print __('Choose an action:', 'hmib');?>
<?php form_dropdown('drp_action',$actions_array,'','','1','','');?>
</td>
<td width='1' align='right'>
<input type='submit' name='go' value='<?php print __('Go', 'hmib');?>'>
</td>
</tr>
</table>
<input type='hidden' name='action' value='actions'>
<?php
if ($include_form_end) {
print '</form>';
}
}
function hmib_host_type_filter() {
global $item_rows;
?>
<script type='text/javascript'>
$(function() {
$('#types').submit(function(event) {
event.preventDefault();
applyFilter();
});
});
function applyFilter() {
strURL = '?rows=' + $('#rows').val();
strURL += '&filter=' + $('#filter').val();
strURL += '&header=false';
loadPageNoHeader(strURL);
}
function clearFilter() {
strURL = '?clear=true&header=false';
loadPageNoHeader(strURL);
}
function rescanTypes() {
strURL = '?scan=true';
loadPageNoHeader(strURL);
}
function importTypes() {
strURL = '?action=import&header=false';
loadPageNoHeader(strURL);
}
function exportTypes() {
strURL = '?export=true&header=false';
document.location = strURL;
}
</script>
<tr class='even'>
<td>
<form id='types'>
<table class='filterTable'>
<tr>
</td>
<td>
<?php print __('Search', 'hmib');?>
</td>
<td>
<input type='text' id='filter' size='25' value='<?php print html_escape_request_var('filter');?>'>
</td>
<td>
<?php print __('OS Type', 'hmib');?>
</td>
<td>
<select id='rows' onChange='applyFilter()'>