forked from nconf/nconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_attr.php
675 lines (593 loc) · 27.2 KB
/
modify_attr.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
<?php
require_once 'include/head.php';
set_page();
# go to show attribute page, when modify was ok
$HTTP_referer = 'show_attr.php';
$_SESSION["go_back_page_ok"] = $HTTP_referer;
message($debug, "set go_back_page_ok : ".$_SESSION["go_back_page_ok"]);
# Choose title
if(isset($_GET['id'])){
$id = $_GET['id'];
$title = "Modify attribute";
}else{
$id = "new";
$title = "Add attribute";
}
if ($id != "new"){
# get entries
$query = 'SELECT * FROM ConfigAttrs WHERE id_attr="'.$id.'"';
$attr_entry = db_handler($query, "assoc", "get entries");
}else{
# new entry does not have predefined values like the modify part
$attr_entry = array("attr_name" => "",
"friendly_name" => "",
"description" => "",
"datatype" => "text",
"max_length" => "1024",
"poss_values" => "",
"predef_value" => "",
"mandatory" => "",
"ordering" => "",
"visible" => "",
"write_to_conf" => "",
"naming_attr" => "",
"link_as_child" => "no",
"link_bidirectional" => "no",
"fk_show_class_items" => "",
"fk_id_class" => "");
}
# Check cache
if ( isset($_SESSION["cache"]["use_cache"]) ){
if ( isset($_SESSION["cache"]["modify_attr"][$id]) ){
# Cache
foreach ($_SESSION["cache"]["modify_attr"][$id] as $key => $value) {
$attr_entry[$key] = $value;
}
}
unset($_SESSION["cache"]["use_cache"]);
}
?>
<!-- jQuery part -->
<script type="text/javascript">
$(document).ready(function(){
/* both selectinos are now allowed:
$("select[name='link_as_child']").change(function() {
if (this.value == "yes"){
$("select[name='link_bidirectional'] option[value='no']").attr('selected', 'selected');
$("select[name='link_bidirectional']").attr('disabled', 'disabled');
}else{
$("select[name='link_bidirectional']").removeAttr("disabled");
}
});
$("select[name='link_bidirectional']").change(function() {
if (this.value == "yes"){
$("select[name='link_as_child'] option[value='no']").attr('selected', 'selected');
$("select[name='link_as_child']").attr('disabled', 'disabled');
}else{
$("select[name='link_as_child']").removeAttr("disabled");
}
});
*/
// autocomplete for attributes (select, assigns...)
var predef_field = $("#predef_value_autocomplete").autocomplete({
minLength: 0,
disabled: true,
}).click(function() {
// close if already visible
if ( predef_field.autocomplete( "widget" ).is( ":visible" ) ) {
predef_field.autocomplete( "close" );
return;
}
if ( $("select[name='datatype']").val() == "select"){
var availableTags = $("#poss_values_autocomplete").val().split(/::/);
$("#predef_value_autocomplete").autocomplete( "option", "source", availableTags ).autocomplete("enable");
// pass empty string as value to search for, displaying all results
predef_field.autocomplete( "search", "" );
predef_field.focus();
}else{
predef_field.autocomplete( "option", "source", "" ).autocomplete("disable");
}
});
// Adcaned linking options
$("select[name='datatype']").change(function() {
if ( this.value == "text" || this.value == "select" || this.value == "password" ){
$('#fieldset_special_links').fadeTo('slow', 0.5, function() {
// Animation complete.
});
}else{
$('#fieldset_special_links').fadeTo('slow', 1, function() {
// Animation complete.
});
}
});
// apply change events already on start
$("select[name='datatype']").change();
// nagios attribute help
$.getScript('include/js/jquery_plugins/jquery.nconf_help_nagios.js', function() {
$("input[name='attr_name']").add("select#class_name").bind('change', function(){
$.nconf_help_get_nagios_documentation($("select#class_name option:selected").text(), $("input[name='attr_name']").val());
}).change();
});
// generate the help buttons with help text
$.nconf_help_admin();
});
</script>
<!-- page content -->
<form name="form1" action="modify_attr_write2db.php" method="post">
<div style="width: 520px; position: relative;">
<?php
$detail_navigation = '<a class="button_back jQ_tooltip" title="back" href="'.$_SESSION["go_back_page_ok"].'"></a>';
echo '<div id="ui-nconf-icon-bar">'.$detail_navigation.'</div>';
echo "<h2>".$title."</h2>";
$colgroup = '<colgroup>
<col width="186">
<col width="20">
<col>
<col width="20">
</colgroup>';
?>
<!--<form name="form1" action="modify_attr_write2db.php" method="post" onclick="check_input()" onkeydown="check_input()" onreset="check_input()">-->
<input type=hidden name=attr_id value="<?php echo $id; ?>">
<fieldset id="page_content">
<legend>Main</legend>
<table width="500">
<?php echo $colgroup; ?>
<tr><td>Nagios-specific attribute name</td>
<td></td>
<td><input type=text name=attr_name maxlength=60 value="<?php echo htmlspecialchars($attr_entry["attr_name"]); ?>"></td>
<td class="attention center">*</td>
</tr>
</table>
<div>
<table width="500" id="nagios_documentation_row" style="display: none;">
<?php echo $colgroup; ?>
<tr>
<td>Nagios documentation help</td>
<td>
</td>
<td><input type="hidden" name="nagios_documentation"></td>
<td></td>
</tr>
</table>
</div>
<table width="500">
<?php echo $colgroup; ?>
<tr><td>friendly name (displayed in GUI)</td>
<td></td>
<td><input type=text name=friendly_name maxlength=80 value="<?php echo htmlspecialchars($attr_entry["friendly_name"]); ?>"></td>
<td class="attention center">*</td>
</tr>
<tr><td>description, example or help-text</td>
<td></td>
<td><input type=text name=description maxlength=250 value="<?php echo htmlspecialchars($attr_entry["description"]); ?>"></td>
<td class="attention center"></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Class and datatype</legend>
<table width="500">
<?php echo $colgroup; ?>
<tr><td>attribute belongs to class</td>
<td></td>
<td><select id="class_name" name="fk_id_class"
<?php if ($id != "new") echo "disabled"; ?>
>
<?php
$query = mysql_query("SELECT id_class,config_class FROM ConfigClasses ORDER BY config_class");
while($entry = mysql_fetch_row($query)){
echo '<option value='.$entry[0];
if ( $entry[0] == $attr_entry["fk_id_class"] ) echo " selected";
echo " >$entry[1]</option>";
}
?>
</select></td>
<td class="attention center">*</td>
</tr>
<tr><td colspan=4>
</td></tr>
<tr><td>attribute datatype</td>
<td></td>
<td><select name="datatype" onChange="check_input(document.form1.datatype.value)"
<?php if ($id != "new") echo "disabled"; ?>
>
<option value="text" <?php if($attr_entry["datatype"] == "text") echo " selected"; ?> >text</option>
<option value="password" <?php if($attr_entry["datatype"] == "password") echo " selected"; ?> >password</option>
<option value="select" <?php if($attr_entry["datatype"] == "select") echo " selected"; ?> >select</option>
<option value="assign_one" <?php if($attr_entry["datatype"] == "assign_one") echo " selected"; ?> >assign_one</option>
<option value="assign_many" <?php if($attr_entry["datatype"] == "assign_many") echo " selected"; ?> >assign_many</option>
<option value="assign_cust_order" <?php if($attr_entry["datatype"] == "assign_cust_order") echo " selected"; ?> >assign_cust_order</option>
</select></td>
<td class="attention center">*</td>
</tr>
<tr><td>item(s) to be assigned</td>
<td></td>
<td><select name="fk_show_class_items" disabled>
<?php
$query = mysql_query("SELECT id_class,config_class FROM ConfigClasses ORDER BY config_class");
while($entry = mysql_fetch_row($query)){
//echo "<option value=$entry[0]>$entry[1]</option>";
echo '<option value='.$entry[0];
if ( $entry[0] == $attr_entry["fk_show_class_items"] ) echo " selected";
echo " >$entry[1]</option>";
}
?>
</select></td>
<td class="attention center">*</td>
</tr>
<tr><td>list of possible values separated by "<b><?php echo SELECT_VALUE_SEPARATOR; ?></b>"</td>
<td></td>
<td><input type=text id=poss_values_autocomplete name=poss_values value="<?php echo htmlspecialchars($attr_entry["poss_values"]); ?>"></td>
<td class="attention center">*</td>
</tr>
<tr><td>pre-defined value(s)</td>
<td></td>
<td>
<input type=text name=predef_value id=predef_value_autocomplete class="ui-autocomplete-input" maxlength=1024 value="<?php echo htmlspecialchars($attr_entry["predef_value"]); ?>"></td>
<td class="attention center"></td>
</tr>
<tr><td>max. text-field length (chars)</td>
<td></td>
<td><input type=text name=max_length maxlength=4 style="width:60px" value="<?php echo $attr_entry["max_length"]; ?>"></td>
<td class="attention center"></td>
</tr>
</table>
</fieldset>
<fieldset id="fieldset_special_links">
<legend>Advanced linking options</legend>
<table>
<?php echo $colgroup; ?>
<tr><td>link selected item(s) as children?</td>
<td></td>
<td>
<select name="link_as_child" style="width:60px" disabled>
<option <?php if($attr_entry["link_as_child"] == "no") echo " selected"; ?> value="no">no</option>
<option <?php if($attr_entry["link_as_child"] == "yes") echo " selected"; ?> value="yes">yes</option>
</select>
</td>
<td class="attention center"></td>
</tr>
<tr><td>link selected item(s) bi-directionally?</td>
<td></td>
<td>
<select name="link_bidirectional" style="width:60px" disabled>
<option <?php if($attr_entry["link_bidirectional"] == "no") echo " selected"; ?> value="no">no</option>
<option <?php if($attr_entry["link_bidirectional"] == "yes") echo " selected"; ?> value="yes">yes</option>
</select>
</td>
<td class="attention center"></td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Display and output</legend>
<table>
<?php echo $colgroup; ?>
<tr><td>attribute is mandatory?</td>
<td></td>
<td>
<select name=mandatory style="width:60px">
<option <?php if($attr_entry["mandatory"] == "no") echo " selected"; ?> >no</option>
<option <?php if($attr_entry["mandatory"] == "yes") echo " selected"; ?> >yes</option>
</select>
<input type="hidden" name="HIDDEN_mandatory" value="<?php echo $attr_entry["mandatory"]; ?>">
</td>
<td class="attention center"></td>
</tr>
<tr><td>attribute is visible?</td>
<td></td>
<td>
<select name=visible style="width:60px">
<option <?php if($attr_entry["visible"] == "yes") echo " selected"; ?> >yes</option>
<option <?php if($attr_entry["visible"] == "no") echo " selected"; ?> >no</option>
</select>
</td>
<td class="attention center">*</td>
</tr>
<tr><td>write attribute to configuration?</td>
<td></td>
<td>
<select name=conf style="width:60px">
<option <?php if($attr_entry["write_to_conf"] == "yes") echo " selected"; ?> >yes</option>
<option <?php if($attr_entry["write_to_conf"] == "no") echo " selected"; ?> >no</option>
</select>
</td>
<td class="attention center">*</td>
</tr>
<tr><td>ordering</td>
<td></td>
<td><input type=text name=ordering maxlength=2 style="width:60px" value="<?php echo $attr_entry["ordering"]; ?>"></td>
<td class="attention center"></td>
</tr>
<tr><td>naming attribute?</td>
<td></td>
<td>
<select name=naming_attr style="width:60px" onChange="check_naming_attr()"
<?php if ($id != "new") echo "disabled"; ?>
>
<option <?php if($attr_entry["naming_attr"] == "no") echo " selected"; ?> >no</option>
<option <?php if($attr_entry["naming_attr"] == "yes") echo " selected"; ?> >yes</option>
</select>
</td>
<td class="attention center">*</td>
</tr>
</table>
</fieldset>
<table>
<?php echo $colgroup; ?>
<tr>
<td>
<br>
</td>
</tr>
<tr>
<td>
<div id=buttons>
<input type="Submit" value="Submit" name="submit" align="middle">
<?php
echo '<input type="button" value="Reset" name="submit" align="middle" onclick="location.reload(true);">';
?>
</div>
</td>
</tr>
</table>
</div>
</form>
<?php
# Script part for modify attribute
if ($id != "new"){
?>
<script type="text/javascript">
<!--
// execute once on load
//check_input();
<?php
echo 'check_input("'.$attr_entry["datatype"].'");';
?>
// also check the naming_attr
check_naming_attr();
function check_input(datatype){
if (!datatype){
datatype = "text";
}
//var datatype = "<?php echo $attr_entry["datatype"] ?>";
switch (datatype) {
//switch (document.form1.datatype.value) {
case "text":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = false;
break;
case "password":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = true;
document.form1.max_length.disabled = false;
document.form1.conf.value = "no";
break;
case "select":
document.form1.poss_values.disabled = false;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
case "assign_one":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
case "assign_many":
case "assign_cust_order":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
break;
}
}
function check_naming_attr(){
if (document.form1.naming_attr.value == "yes"){
document.form1.mandatory.value = "yes";
document.form1.mandatory.disabled = true;
}else{
document.form1.mandatory.disabled = false;
}
}
//-->
</script>
<?php
# Script part for add attribute
}else{
?>
<script type="text/javascript">
<!--
// execute once on load
//check_input();
<?php
echo 'check_input("'.$attr_entry["datatype"].'");';
?>
// also check the naming_attr
check_naming_attr();
function check_input(datatype){
if (!datatype){
datatype = "text";
}
//var datatype = "<?php echo $attr_entry["datatype"] ?>";
switch (datatype) {
//switch (document.form1.datatype.value) {
case "text":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = false;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
document.form1.link_bidirectional.disabled = true;
break;
case "password":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = true;
document.form1.max_length.disabled = false;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
document.form1.link_bidirectional.disabled = true;
document.form1.conf.value = "no";
break;
case "select":
document.form1.poss_values.disabled = false;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = true;
document.form1.link_as_child.disabled = true;
document.form1.link_bidirectional.disabled = true;
break;
case "assign_one":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = false;
document.form1.link_as_child.disabled = false;
document.form1.link_bidirectional.disabled = false;
break;
case "assign_many":
case "assign_cust_order":
document.form1.poss_values.disabled = true;
document.form1.predef_value.disabled = false;
document.form1.max_length.disabled = true;
document.form1.fk_show_class_items.disabled = false;
document.form1.link_as_child.disabled = false;
document.form1.link_bidirectional.disabled = false;
break;
}
}
function check_naming_attr(){
if (document.form1.naming_attr.value == "yes"){
document.form1.mandatory.value = "yes";
document.form1.mandatory.disabled = true;
}else{
document.form1.mandatory.disabled = false;
}
}
//-->
</script>
<?php
} // end of add or modify script path
?>
<!-- Help text content -->
<div id="help_text" style="display: none">
<div id="attr_name" title="attribute name">
<p>The attribute name as stated in the official Nagios documentation. Attribute names must be unique within their class.</p>
</div>
<div id="nagios_documentation" title="Nagios documentation help">
</div>
<div id="friendly_name" title="friendly name">
<p>The attribute name which shall be displayed within the NConf GUI.</p>
</div>
<div id="description" title="description">
<p>A short description or help text for the attribute.</p>
</div>
<div id="fk_id_class" title="attribute class">
<p>The NConf class that this attribute should belong to.</p>
</div>
<div id="fk_show_class_items" title="item assignment">
<p>A class whose items should be listed for assignment, i.e. display a drop-down menue containing items of this specific class, so they may be linked.</p>
<p>This option is only available for attributes of datatype "assign_".</p>
</div>
<div id="poss_values" title="possible values">
<p>A list of options available in a drop-down menue. Separate each option with the "<strong>::</strong>" characters.</p>
<p>This option is only available for attributes of datatype "select".</p>
</div>
<div id="datatype" title="datatypes">
<div>
<p>
The following attribute datatypes exist:
</p>
<p>
<strong>text</strong><br>
This datatype is used for simple text attributes. A maximum length may be specified.
</p>
<p>
<strong>password</strong><br>
This datatype is used for password attributes. Several encryption methods are available. Passwords will not be displayed in the GUI.
</p>
<p>
<strong>select</strong><br>
This datatype creates a drop-down menu. A list of possible values must be specified.
</p>
<p>
<strong>assign_one</strong><br>
This datatype creates a drop-down menu that allows an item of any class to be assigned to another one (the selected item will be linked as "parent item" by default).
</p>
<p>
<strong>assign_many</strong><br>
This datatype creates a menu that allows an item of any class to be assigned to one or more other items (the selected items will be linked as "parent items" by default).
</p>
<p>
<strong>assign_cust_order</strong><br>
This datatype is identical to "assign_many" but can additionally handle the order of how items are assigned.
</div>
</div>
<div id="predef_value" title="predefined value">
<p>This option allows you to predefine a default value for any attribute. Different options are available depending on the datatype of the attribute:</p>
<p>For <strong>text</strong> attributes: a predefined text value.</p>
<p>For <strong>select</strong> attributes: one of the options from the "list of possible values"</p>
<p>For <strong>assign_one</strong> attributes: an item to be pre-assigned.</p>
<p>For <strong>assign_many</strong> and <strong>assign_cust_order</strong> attributes: one or more items to be pre-assigned (multiple items separated by "<strong>::</strong>")</p>
</div>
<div id="max_length" title="max length">
<p>The character limit for an attribute within the NConf GUI.</p>
<p>Possible range: 1 - 1024</p>
<p>This option is only available for attributes of datatype "text" and "password".</p>
</div>
<div id="link_as_child" title="link as child">
<p>
This flag determines if items from another class should be linked as an item's children rather than being linked as parent items.</p>
<p>
Example: when a user adds hosts to a hostgroup, he intends the hosts to become child items of that hostgroup. By default, items that are selected in a menu will always be linked as parent items. In this specific case, the "link as child" flag needs to be set to prevent the hosts from becoming the parents of the hostgroup (here we want it the other way around).
</p>
</div>
<div id="link_bidirectional" title="link bi-directional">
<p>
This flag affects the visibility of "assign_" attributes in the NConf GUI. It is used where users wish to manage the link between two items in more than just one GUI. This flag will make the same attribute available on both sides of the assignment.
</p>
<p>
Example: a user wishes to set the link between contacts and contactgroups using both the contacts GUI and the contactgroups GUI. Setting the "link bi-directional" flag will display the same menu on both sides, even though the attribute actually only exists in one class.
</p>
</div>
<div id="mandatory" title="mandatory attribute">
<p>
Defines if this attribute should be mandatory. Users will be forced to set this attribute.
</p>
</div>
<div id="visible" title="attribute visibility">
<p>
Defines if this attribute should be visible in the NConf GUI.
</p>
<p>Note: this flag will only affect the GUI. Invisible attributes will still be stored in the background. Also, invisible attributes will be written to the Nagios configuration, as long as the "write to configuration" flag is set to "yes".
</p>
<p>
Invisible attributes can be very useful in conjunction with an attribute's "pre-defined value".
</p>
</div>
<div id="conf" title="write to configuration">
<p>
Defines if this attribute should be written to the Nagios configuration files.
</p>
<p>
This flag is most useful to distinguish NConf specific attributes from actual Nagios attributes.
</p>
</div>
<div id="ordering" title="ordering">
<p>
Defines the order in which this attribute will be displayed in the NConf GUI. If this field is left blank, NConf will automatically assign the next available order number.
</p>
</div>
<div id="naming_attr" title="naming attribute">
<p>
Defines if this attribute is the "naming attribute" of the current class. The "naming attribute" (i.e. the primary key) is used to distinctively identify an object within its class.
</p>
<p>
There can only be one "naming attribute" in each class. Likewise, there can only be one item with the same name within a class.
</p>
</div>
</div>
<?php
mysql_close($dbh);
require_once 'include/foot.php';
?>