1 /**************************************************************************
2 *
3 * CMD.C - Nagios Command CGI
4 *
5 * Copyright (c) 1999-2010 Ethan Galstad (egalstad@nagios.org)
6 * Last Modified: 08-28-2010
7 *
8 * License:
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *************************************************************************/
23
24 #include "../include/config.h"
25 #include "../include/common.h"
26 #include "../include/objects.h"
27 #include "../include/comments.h"
28 #include "../include/downtime.h"
29
30 #include "../include/cgiutils.h"
31 #include "../include/cgiauth.h"
32 #include "../include/getcgi.h"
33
34 extern const char *extcmd_get_name(int id);
35
36 extern char main_config_file[MAX_FILENAME_LENGTH];
37 extern char url_html_path[MAX_FILENAME_LENGTH];
38 extern char url_images_path[MAX_FILENAME_LENGTH];
39 extern char command_file[MAX_FILENAME_LENGTH];
40 extern char comment_file[MAX_FILENAME_LENGTH];
41
42 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
43
44 extern int nagios_process_state;
45
46 extern int check_external_commands;
47
48 extern int use_authentication;
49
50 extern int lock_author_names;
51
52 extern scheduled_downtime *scheduled_downtime_list;
53 extern comment *comment_list;
54
55 extern int date_format;
56
57
58 #define MAX_AUTHOR_LENGTH 64
59 #define MAX_COMMENT_LENGTH 1024
60
61 #define HTML_CONTENT 0
62 #define WML_CONTENT 1
63
64
65 char *host_name = "";
66 char *hostgroup_name = "";
67 char *servicegroup_name = "";
68 char *service_desc = "";
69 char *comment_author = "";
70 char *comment_data = "";
71 char *start_time_string = "";
72 char *end_time_string = "";
73
74 unsigned long comment_id = 0;
75 unsigned long downtime_id = 0;
76 int notification_delay = 0;
77 int schedule_delay = 0;
78 int persistent_comment = FALSE;
79 int sticky_ack = FALSE;
80 int send_notification = FALSE;
81 int force_check = FALSE;
82 int plugin_state = STATE_OK;
83 char plugin_output[MAX_INPUT_BUFFER] = "";
84 char performance_data[MAX_INPUT_BUFFER] = "";
85 time_t start_time = 0L;
86 time_t end_time = 0L;
87 int affect_host_and_services = FALSE;
88 int propagate_to_children = FALSE;
89 int fixed = FALSE;
90 unsigned long duration = 0L;
91 unsigned long triggered_by = 0L;
92 int child_options = 0;
93 int force_notification = 0;
94 int broadcast_notification = 0;
95
96 int command_type = CMD_NONE;
97 int command_mode = CMDMODE_REQUEST;
98
99 int content_type = HTML_CONTENT;
100
101 int display_header = TRUE;
102
103 authdata current_authdata;
104
105 void show_command_help(int);
106 void request_command_data(int);
107 void commit_command_data(int);
108 int commit_command(int);
109 int write_command_to_file(char *);
110 void clean_comment_data(char *);
111
112 void document_header(int);
113 void document_footer(void);
114 int process_cgivars(void);
115
116 int string_to_time(char *, time_t *);
117
118
119
main(void)120 int main(void) {
121 int result = OK;
122
123 /* get the arguments passed in the URL */
124 process_cgivars();
125
126 /* reset internal variables */
127 reset_cgi_vars();
128
129 /* read the CGI configuration file */
130 result = read_cgi_config_file(get_cgi_config_location());
131 if(result == ERROR) {
132 document_header(FALSE);
133 if(content_type == WML_CONTENT)
134 printf("<p>Error: Could not open CGI config file!</p>\n");
135 else
136 cgi_config_file_error(get_cgi_config_location());
137 document_footer();
138 return ERROR;
139 }
140
141 /* read the main configuration file */
142 result = read_main_config_file(main_config_file);
143 if(result == ERROR) {
144 document_header(FALSE);
145 if(content_type == WML_CONTENT)
146 printf("<p>Error: Could not open main config file!</p>\n");
147 else
148 main_config_file_error(main_config_file);
149 document_footer();
150 return ERROR;
151 }
152
153 /* This requires the date_format parameter in the main config file */
154 if(strcmp(start_time_string, ""))
155 string_to_time(start_time_string, &start_time);
156
157 if(strcmp(end_time_string, ""))
158 string_to_time(end_time_string, &end_time);
159
160
161 /* read all object configuration data */
162 result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
163 if(result == ERROR) {
164 document_header(FALSE);
165 if(content_type == WML_CONTENT)
166 printf("<p>Error: Could not read object config data!</p>\n");
167 else
168 object_data_error();
169 document_footer();
170 return ERROR;
171 }
172
173 document_header(TRUE);
174
175 /* get authentication information */
176 get_authentication_information(¤t_authdata);
177
178 if(display_header == TRUE) {
179
180 /* begin top table */
181 printf("<table border=0 width=100%%>\n");
182 printf("<tr>\n");
183
184 /* left column of the first row */
185 printf("<td align=left valign=top width=33%%>\n");
186 display_info_table("External Command Interface", FALSE, ¤t_authdata);
187 printf("</td>\n");
188
189 /* center column of the first row */
190 printf("<td align=center valign=top width=33%%>\n");
191 printf("</td>\n");
192
193 /* right column of the first row */
194 printf("<td align=right valign=bottom width=33%%>\n");
195
196 /* display context-sensitive help */
197 if(command_mode == CMDMODE_COMMIT)
198 display_context_help(CONTEXTHELP_CMD_COMMIT);
199 else
200 display_context_help(CONTEXTHELP_CMD_INPUT);
201
202 printf("</td>\n");
203
204 /* end of top table */
205 printf("</tr>\n");
206 printf("</table>\n");
207 }
208
209 /* authorized_for_read_only should take priority */
210 if(is_authorized_for_read_only(¤t_authdata) == TRUE) {
211 printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to submit the command you requested...</DIV></P>\n");
212 printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
213 printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
214
215 document_footer();
216
217 /* free allocated memory */
218 free_memory();
219 free_object_data();
220
221 return OK;
222 }
223
224 /* if no command was specified... */
225 if(command_type == CMD_NONE) {
226 if(content_type == WML_CONTENT)
227 printf("<p>Error: No command specified!</p>\n");
228 else
229 printf("<P><DIV CLASS='errorMessage'>Error: No command was specified</DIV></P>\n");
230 }
231
232 /* if this is the first request for a command, present option */
233 else if(command_mode == CMDMODE_REQUEST)
234 request_command_data(command_type);
235
236 /* the user wants to commit the command */
237 else if(command_mode == CMDMODE_COMMIT)
238 commit_command_data(command_type);
239
240 document_footer();
241
242 /* free allocated memory */
243 free_memory();
244 free_object_data();
245
246 return OK;
247 }
248
249
250
document_header(int use_stylesheet)251 void document_header(int use_stylesheet) {
252
253 if(content_type == WML_CONTENT) {
254
255 printf("Content-type: text/vnd.wap.wml\r\n\r\n");
256
257 printf("<?xml version=\"1.0\"?>\n");
258 printf("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
259
260 printf("<wml>\n");
261
262 printf("<card id='card1' title='Command Results'>\n");
263 }
264
265 else {
266
267 printf("Content-type: text/html\r\n\r\n");
268
269 printf("<html>\n");
270 printf("<head>\n");
271 printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
272 printf("<title>\n");
273 printf("External Command Interface\n");
274 printf("</title>\n");
275
276 if(use_stylesheet == TRUE) {
277 printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMON_CSS);
278 printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>\n", url_stylesheets_path, COMMAND_CSS);
279 }
280
281 printf("</head>\n");
282
283 printf("<body CLASS='cmd'>\n");
284
285 /* include user SSI header */
286 include_ssi_files(COMMAND_CGI, SSI_HEADER);
287 }
288
289 return;
290 }
291
292
document_footer(void)293 void document_footer(void) {
294
295 if(content_type == WML_CONTENT) {
296 printf("</card>\n");
297 printf("</wml>\n");
298 }
299
300 else {
301
302 /* include user SSI footer */
303 include_ssi_files(COMMAND_CGI, SSI_FOOTER);
304
305 printf("</body>\n");
306 printf("</html>\n");
307 }
308
309 return;
310 }
311
312
process_cgivars(void)313 int process_cgivars(void) {
314 char **variables;
315 int error = FALSE;
316 int x;
317
318 variables = getcgivars();
319
320 for(x = 0; variables[x] != NULL; x++) {
321
322 /* do some basic length checking on the variable identifier to prevent buffer overflows */
323 if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
324 continue;
325 }
326
327 /* we found the command type */
328 else if(!strcmp(variables[x], "cmd_typ")) {
329 x++;
330 if(variables[x] == NULL) {
331 error = TRUE;
332 break;
333 }
334
335 command_type = atoi(variables[x]);
336 }
337
338 /* we found the command mode */
339 else if(!strcmp(variables[x], "cmd_mod")) {
340 x++;
341 if(variables[x] == NULL) {
342 error = TRUE;
343 break;
344 }
345
346 command_mode = atoi(variables[x]);
347 }
348
349 /* we found the comment id */
350 else if(!strcmp(variables[x], "com_id")) {
351 x++;
352 if(variables[x] == NULL) {
353 error = TRUE;
354 break;
355 }
356
357 comment_id = strtoul(variables[x], NULL, 10);
358 }
359
360 /* we found the downtime id */
361 else if(!strcmp(variables[x], "down_id")) {
362 x++;
363 if(variables[x] == NULL) {
364 error = TRUE;
365 break;
366 }
367
368 downtime_id = strtoul(variables[x], NULL, 10);
369 }
370
371 /* we found the notification delay */
372 else if(!strcmp(variables[x], "not_dly")) {
373 x++;
374 if(variables[x] == NULL) {
375 error = TRUE;
376 break;
377 }
378
379 notification_delay = atoi(variables[x]);
380 }
381
382 /* we found the schedule delay */
383 else if(!strcmp(variables[x], "sched_dly")) {
384 x++;
385 if(variables[x] == NULL) {
386 error = TRUE;
387 break;
388 }
389
390 schedule_delay = atoi(variables[x]);
391 }
392
393 /* we found the comment author */
394 else if(!strcmp(variables[x], "com_author")) {
395 x++;
396 if(variables[x] == NULL) {
397 error = TRUE;
398 break;
399 }
400
401 if((comment_author = (char *)strdup(variables[x])) == NULL)
402 comment_author = "";
403 strip_html_brackets(comment_author);
404 }
405
406 /* we found the comment data */
407 else if(!strcmp(variables[x], "com_data")) {
408 x++;
409 if(variables[x] == NULL) {
410 error = TRUE;
411 break;
412 }
413
414 if((comment_data = (char *)strdup(variables[x])) == NULL)
415 comment_data = "";
416 strip_html_brackets(comment_data);
417 }
418
419 /* we found the host name */
420 else if(!strcmp(variables[x], "host")) {
421 x++;
422 if(variables[x] == NULL) {
423 error = TRUE;
424 break;
425 }
426
427 if((host_name = (char *)strdup(variables[x])) == NULL)
428 host_name = "";
429 strip_html_brackets(host_name);
430 }
431
432 /* we found the hostgroup name */
433 else if(!strcmp(variables[x], "hostgroup")) {
434 x++;
435 if(variables[x] == NULL) {
436 error = TRUE;
437 break;
438 }
439
440 if((hostgroup_name = (char *)strdup(variables[x])) == NULL)
441 hostgroup_name = "";
442 strip_html_brackets(hostgroup_name);
443 }
444
445 /* we found the service name */
446 else if(!strcmp(variables[x], "service")) {
447 x++;
448 if(variables[x] == NULL) {
449 error = TRUE;
450 break;
451 }
452
453 if((service_desc = (char *)strdup(variables[x])) == NULL)
454 service_desc = "";
455 strip_html_brackets(service_desc);
456 }
457
458 /* we found the servicegroup name */
459 else if(!strcmp(variables[x], "servicegroup")) {
460 x++;
461 if(variables[x] == NULL) {
462 error = TRUE;
463 break;
464 }
465
466 if((servicegroup_name = (char *)strdup(variables[x])) == NULL)
467 servicegroup_name = "";
468 strip_html_brackets(servicegroup_name);
469 }
470
471 /* we got the persistence option for a comment */
472 else if(!strcmp(variables[x], "persistent"))
473 persistent_comment = TRUE;
474
475 /* we got the notification option for an acknowledgement */
476 else if(!strcmp(variables[x], "send_notification"))
477 send_notification = TRUE;
478
479 /* we got the acknowledgement type */
480 else if(!strcmp(variables[x], "sticky_ack"))
481 sticky_ack = TRUE;
482
483 /* we got the service check force option */
484 else if(!strcmp(variables[x], "force_check"))
485 force_check = TRUE;
486
487 /* we got the option to affect host and all its services */
488 else if(!strcmp(variables[x], "ahas"))
489 affect_host_and_services = TRUE;
490
491 /* we got the option to propagate to child hosts */
492 else if(!strcmp(variables[x], "ptc"))
493 propagate_to_children = TRUE;
494
495 /* we got the option for fixed downtime */
496 else if(!strcmp(variables[x], "fixed")) {
497 x++;
498 if(variables[x] == NULL) {
499 error = TRUE;
500 break;
501 }
502
503 fixed = (atoi(variables[x]) > 0) ? TRUE : FALSE;
504 }
505
506 /* we got the triggered by downtime option */
507 else if(!strcmp(variables[x], "trigger")) {
508 x++;
509 if(variables[x] == NULL) {
510 error = TRUE;
511 break;
512 }
513
514 triggered_by = strtoul(variables[x], NULL, 10);
515 }
516
517 /* we got the child options */
518 else if(!strcmp(variables[x], "childoptions")) {
519 x++;
520 if(variables[x] == NULL) {
521 error = TRUE;
522 break;
523 }
524
525 child_options = atoi(variables[x]);
526 }
527
528 /* we found the plugin output */
529 else if(!strcmp(variables[x], "plugin_output")) {
530 x++;
531 if(variables[x] == NULL) {
532 error = TRUE;
533 break;
534 }
535
536 /* protect against buffer overflows */
537 if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
538 error = TRUE;
539 break;
540 }
541 else
542 strcpy(plugin_output, variables[x]);
543 }
544
545 /* we found the performance data */
546 else if(!strcmp(variables[x], "performance_data")) {
547 x++;
548 if(variables[x] == NULL) {
549 error = TRUE;
550 break;
551 }
552
553 /* protect against buffer overflows */
554 if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
555 error = TRUE;
556 break;
557 }
558 else
559 strcpy(performance_data, variables[x]);
560 }
561
562 /* we found the plugin state */
563 else if(!strcmp(variables[x], "plugin_state")) {
564 x++;
565 if(variables[x] == NULL) {
566 error = TRUE;
567 break;
568 }
569
570 plugin_state = atoi(variables[x]);
571 }
572
573 /* we found the hour duration */
574 else if(!strcmp(variables[x], "hours")) {
575 x++;
576 if(variables[x] == NULL) {
577 error = TRUE;
578 break;
579 }
580
581 if(atoi(variables[x]) < 0) {
582 error = TRUE;
583 break;
584 }
585 duration += (unsigned long)(atoi(variables[x]) * 3600);
586 }
587
588 /* we found the minute duration */
589 else if(!strcmp(variables[x], "minutes")) {
590 x++;
591 if(variables[x] == NULL) {
592 error = TRUE;
593 break;
594 }
595
596 if(atoi(variables[x]) < 0) {
597 error = TRUE;
598 break;
599 }
600 duration += (unsigned long)(atoi(variables[x]) * 60);
601 }
602
603 /* we found the start time */
604 else if(!strcmp(variables[x], "start_time")) {
605 x++;
606 if(variables[x] == NULL) {
607 error = TRUE;
608 break;
609 }
610
611 start_time_string = (char *)malloc(strlen(variables[x]) + 1);
612 if(start_time_string == NULL)
613 start_time_string = "";
614 else
615 strcpy(start_time_string, variables[x]);
616 }
617
618 /* we found the end time */
619 else if(!strcmp(variables[x], "end_time")) {
620 x++;
621 if(variables[x] == NULL) {
622 error = TRUE;
623 break;
624 }
625
626 end_time_string = (char *)malloc(strlen(variables[x]) + 1);
627 if(end_time_string == NULL)
628 end_time_string = "";
629 else
630 strcpy(end_time_string, variables[x]);
631 }
632
633 /* we found the content type argument */
634 else if(!strcmp(variables[x], "content")) {
635 x++;
636 if(variables[x] == NULL) {
637 error = TRUE;
638 break;
639 }
640 if(!strcmp(variables[x], "wml")) {
641 content_type = WML_CONTENT;
642 display_header = FALSE;
643 }
644 else
645 content_type = HTML_CONTENT;
646 }
647
648 /* we found the forced notification option */
649 else if(!strcmp(variables[x], "force_notification"))
650 force_notification = NOTIFICATION_OPTION_FORCED;
651
652 /* we found the broadcast notification option */
653 else if(!strcmp(variables[x], "broadcast_notification"))
654 broadcast_notification = NOTIFICATION_OPTION_BROADCAST;
655
656 }
657
658 /* free memory allocated to the CGI variables */
659 free_cgivars(variables);
660
661 return error;
662 }
663
664
665
request_command_data(int cmd)666 void request_command_data(int cmd) {
667 time_t t;
668 char start_time[MAX_DATETIME_LENGTH];
669 char buffer[MAX_INPUT_BUFFER];
670 contact *temp_contact;
671 scheduled_downtime *temp_downtime;
672
673
674 /* get default name to use for comment author */
675 temp_contact = find_contact(current_authdata.username);
676 if(temp_contact != NULL && temp_contact->alias != NULL)
677 comment_author = temp_contact->alias;
678 else
679 comment_author = current_authdata.username;
680
681
682 printf("<P><DIV ALIGN=CENTER CLASS='cmdType'>You are requesting to ");
683
684 switch(cmd) {
685
686 case CMD_ADD_HOST_COMMENT:
687 case CMD_ADD_SVC_COMMENT:
688 printf("add a %s comment", (cmd == CMD_ADD_HOST_COMMENT) ? "host" : "service");
689 break;
690
691 case CMD_DEL_HOST_COMMENT:
692 case CMD_DEL_SVC_COMMENT:
693 printf("delete a %s comment", (cmd == CMD_DEL_HOST_COMMENT) ? "host" : "service");
694 break;
695
696 case CMD_DELAY_HOST_NOTIFICATION:
697 case CMD_DELAY_SVC_NOTIFICATION:
698 printf("delay a %s notification", (cmd == CMD_DELAY_HOST_NOTIFICATION) ? "host" : "service");
699 break;
700
701 case CMD_SCHEDULE_SVC_CHECK:
702 printf("schedule a service check");
703 break;
704
705 case CMD_ENABLE_SVC_CHECK:
706 case CMD_DISABLE_SVC_CHECK:
707 printf("%s active checks of a particular service", (cmd == CMD_ENABLE_SVC_CHECK) ? "enable" : "disable");
708 break;
709
710 case CMD_ENABLE_NOTIFICATIONS:
711 case CMD_DISABLE_NOTIFICATIONS:
712 printf("%s notifications", (cmd == CMD_ENABLE_NOTIFICATIONS) ? "enable" : "disable");
713 break;
714
715 case CMD_SHUTDOWN_PROCESS:
716 case CMD_RESTART_PROCESS:
717 printf("%s the Nagios process", (cmd == CMD_SHUTDOWN_PROCESS) ? "shutdown" : "restart");
718 break;
719
720 case CMD_ENABLE_HOST_SVC_CHECKS:
721 case CMD_DISABLE_HOST_SVC_CHECKS:
722 printf("%s active checks of all services on a host", (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? "enable" : "disable");
723 break;
724
725 case CMD_SCHEDULE_HOST_SVC_CHECKS:
726 printf("schedule a check of all services for a host");
727 break;
728
729 case CMD_DEL_ALL_HOST_COMMENTS:
730 case CMD_DEL_ALL_SVC_COMMENTS:
731 printf("delete all comments for a %s", (cmd == CMD_DEL_ALL_HOST_COMMENTS) ? "host" : "service");
732 break;
733
734 case CMD_ENABLE_SVC_NOTIFICATIONS:
735 case CMD_DISABLE_SVC_NOTIFICATIONS:
736 printf("%s notifications for a service", (cmd == CMD_ENABLE_SVC_NOTIFICATIONS) ? "enable" : "disable");
737 break;
738
739 case CMD_ENABLE_HOST_NOTIFICATIONS:
740 case CMD_DISABLE_HOST_NOTIFICATIONS:
741 printf("%s notifications for a host", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "enable" : "disable");
742 break;
743
744 case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
745 case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
746 printf("%s notifications for all hosts and services beyond a host", (cmd == CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST) ? "enable" : "disable");
747 break;
748
749 case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
750 case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
751 printf("%s notifications for all services on a host", (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "enable" : "disable");
752 break;
753
754 case CMD_ACKNOWLEDGE_HOST_PROBLEM:
755 case CMD_ACKNOWLEDGE_SVC_PROBLEM:
756 printf("acknowledge a %s problem", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? "host" : "service");
757 break;
758
759 case CMD_START_EXECUTING_SVC_CHECKS:
760 case CMD_STOP_EXECUTING_SVC_CHECKS:
761 printf("%s executing active service checks", (cmd == CMD_START_EXECUTING_SVC_CHECKS) ? "start" : "stop");
762 break;
763
764 case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
765 case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
766 printf("%s accepting passive service checks", (cmd == CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS) ? "start" : "stop");
767 break;
768
769 case CMD_ENABLE_PASSIVE_SVC_CHECKS:
770 case CMD_DISABLE_PASSIVE_SVC_CHECKS:
771 printf("%s accepting passive service checks for a particular service", (cmd == CMD_ENABLE_PASSIVE_SVC_CHECKS) ? "start" : "stop");
772 break;
773
774 case CMD_ENABLE_EVENT_HANDLERS:
775 case CMD_DISABLE_EVENT_HANDLERS:
776 printf("%s event handlers", (cmd == CMD_ENABLE_EVENT_HANDLERS) ? "enable" : "disable");
777 break;
778
779 case CMD_ENABLE_HOST_EVENT_HANDLER:
780 case CMD_DISABLE_HOST_EVENT_HANDLER:
781 printf("%s the event handler for a particular host", (cmd == CMD_ENABLE_HOST_EVENT_HANDLER) ? "enable" : "disable");
782 break;
783
784 case CMD_ENABLE_SVC_EVENT_HANDLER:
785 case CMD_DISABLE_SVC_EVENT_HANDLER:
786 printf("%s the event handler for a particular service", (cmd == CMD_ENABLE_SVC_EVENT_HANDLER) ? "enable" : "disable");
787 break;
788
789 case CMD_ENABLE_HOST_CHECK:
790 case CMD_DISABLE_HOST_CHECK:
791 printf("%s active checks of a particular host", (cmd == CMD_ENABLE_HOST_CHECK) ? "enable" : "disable");
792 break;
793
794 case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
795 case CMD_START_OBSESSING_OVER_SVC_CHECKS:
796 printf("%s obsessing over service checks", (cmd == CMD_STOP_OBSESSING_OVER_SVC_CHECKS) ? "stop" : "start");
797 break;
798
799 case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
800 case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
801 printf("remove a %s acknowledgement", (cmd == CMD_REMOVE_HOST_ACKNOWLEDGEMENT) ? "host" : "service");
802 break;
803
804 case CMD_SCHEDULE_HOST_DOWNTIME:
805 case CMD_SCHEDULE_SVC_DOWNTIME:
806 printf("schedule downtime for a particular %s", (cmd == CMD_SCHEDULE_HOST_DOWNTIME) ? "host" : "service");
807 break;
808
809 case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
810 printf("schedule downtime for all services for a particular host");
811 break;
812
813 case CMD_PROCESS_HOST_CHECK_RESULT:
814 case CMD_PROCESS_SERVICE_CHECK_RESULT:
815 printf("submit a passive check result for a particular %s", (cmd == CMD_PROCESS_HOST_CHECK_RESULT) ? "host" : "service");
816 break;
817
818 case CMD_ENABLE_HOST_FLAP_DETECTION:
819 case CMD_DISABLE_HOST_FLAP_DETECTION:
820 printf("%s flap detection for a particular host", (cmd == CMD_ENABLE_HOST_FLAP_DETECTION) ? "enable" : "disable");
821 break;
822
823 case CMD_ENABLE_SVC_FLAP_DETECTION:
824 case CMD_DISABLE_SVC_FLAP_DETECTION:
825 printf("%s flap detection for a particular service", (cmd == CMD_ENABLE_SVC_FLAP_DETECTION) ? "enable" : "disable");
826 break;
827
828 case CMD_ENABLE_FLAP_DETECTION:
829 case CMD_DISABLE_FLAP_DETECTION:
830 printf("%s flap detection for hosts and services", (cmd == CMD_ENABLE_FLAP_DETECTION) ? "enable" : "disable");
831 break;
832
833 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
834 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
835 printf("%s notifications for all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "enable" : "disable");
836 break;
837
838 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
839 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
840 printf("%s notifications for all hosts in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS) ? "enable" : "disable");
841 break;
842
843 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
844 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
845 printf("%s active checks of all services in a particular hostgroup", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? "enable" : "disable");
846 break;
847
848 case CMD_DEL_HOST_DOWNTIME:
849 case CMD_DEL_SVC_DOWNTIME:
850 printf("cancel scheduled downtime for a particular %s", (cmd == CMD_DEL_HOST_DOWNTIME) ? "host" : "service");
851 break;
852
853 case CMD_ENABLE_FAILURE_PREDICTION:
854 case CMD_DISABLE_FAILURE_PREDICTION:
855 printf("%s failure prediction for hosts and service", (cmd == CMD_ENABLE_FAILURE_PREDICTION) ? "enable" : "disable");
856 break;
857
858 case CMD_ENABLE_PERFORMANCE_DATA:
859 case CMD_DISABLE_PERFORMANCE_DATA:
860 printf("%s performance data processing for hosts and services", (cmd == CMD_ENABLE_PERFORMANCE_DATA) ? "enable" : "disable");
861 break;
862
863 case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
864 printf("schedule downtime for all hosts in a particular hostgroup");
865 break;
866
867 case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
868 printf("schedule downtime for all services in a particular hostgroup");
869 break;
870
871 case CMD_START_EXECUTING_HOST_CHECKS:
872 case CMD_STOP_EXECUTING_HOST_CHECKS:
873 printf("%s executing host checks", (cmd == CMD_START_EXECUTING_HOST_CHECKS) ? "start" : "stop");
874 break;
875
876 case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
877 case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
878 printf("%s accepting passive host checks", (cmd == CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS) ? "start" : "stop");
879 break;
880
881 case CMD_ENABLE_PASSIVE_HOST_CHECKS:
882 case CMD_DISABLE_PASSIVE_HOST_CHECKS:
883 printf("%s accepting passive checks for a particular host", (cmd == CMD_ENABLE_PASSIVE_HOST_CHECKS) ? "start" : "stop");
884 break;
885
886 case CMD_START_OBSESSING_OVER_HOST_CHECKS:
887 case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
888 printf("%s obsessing over host checks", (cmd == CMD_START_OBSESSING_OVER_HOST_CHECKS) ? "start" : "stop");
889 break;
890
891 case CMD_SCHEDULE_HOST_CHECK:
892 printf("schedule a host check");
893 break;
894
895 case CMD_START_OBSESSING_OVER_SVC:
896 case CMD_STOP_OBSESSING_OVER_SVC:
897 printf("%s obsessing over a particular service", (cmd == CMD_START_OBSESSING_OVER_SVC) ? "start" : "stop");
898 break;
899
900 case CMD_START_OBSESSING_OVER_HOST:
901 case CMD_STOP_OBSESSING_OVER_HOST:
902 printf("%s obsessing over a particular host", (cmd == CMD_START_OBSESSING_OVER_HOST) ? "start" : "stop");
903 break;
904
905 case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
906 case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
907 printf("%s notifications for all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "enable" : "disable");
908 break;
909
910 case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
911 case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
912 printf("%s notifications for all hosts in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS) ? "enable" : "disable");
913 break;
914
915 case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
916 case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
917 printf("%s active checks of all services in a particular servicegroup", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? "enable" : "disable");
918 break;
919
920 case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
921 printf("schedule downtime for all hosts in a particular servicegroup");
922 break;
923
924 case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
925 printf("schedule downtime for all services in a particular servicegroup");
926 break;
927
928 case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
929 case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
930 printf("send a custom %s notification", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
931 break;
932
933 default:
934 printf("execute an unknown command. Shame on you!</DIV>");
935 return;
936 }
937
938 printf("</DIV></p>\n");
939
940 printf("<p>\n");
941 printf("<div align='center'>\n");
942
943 printf("<table border=0 width=90%%>\n");
944 printf("<tr>\n");
945 printf("<td align=center valign=top>\n");
946
947 printf("<DIV ALIGN=CENTER CLASS='optBoxTitle'>Command Options</DIV>\n");
948
949 printf("<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=1 CLASS='optBox'>\n");
950 printf("<TR><TD CLASS='optBoxItem'>\n");
951 printf("<form method='post' action='%s'>\n", COMMAND_CGI);
952 printf("<TABLE CELLSPACING=0 CELLPADDING=0 CLASS='optBox'>\n");
953
954 printf("<tr><td><INPUT TYPE='HIDDEN' NAME='cmd_typ' VALUE='%d'><INPUT TYPE='HIDDEN' NAME='cmd_mod' VALUE='%d'></td></tr>\n", cmd, CMDMODE_COMMIT);
955
956 switch(cmd) {
957
958 case CMD_ADD_HOST_COMMENT:
959 case CMD_ACKNOWLEDGE_HOST_PROBLEM:
960 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
961 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
962 printf("</b></td></tr>\n");
963 if(cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) {
964 printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
965 printf("<INPUT TYPE='checkbox' NAME='sticky_ack' CHECKED>");
966 printf("</b></td></tr>\n");
967 printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
968 printf("<INPUT TYPE='checkbox' NAME='send_notification' CHECKED>");
969 printf("</b></td></tr>\n");
970 }
971 printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? " Comment" : "");
972 printf("<INPUT TYPE='checkbox' NAME='persistent' %s>", (cmd == CMD_ACKNOWLEDGE_HOST_PROBLEM) ? "" : "CHECKED");
973 printf("</b></td></tr>\n");
974 printf("<tr><td CLASS='optBoxRequiredItem'>Author (Your Name):</td><td><b>");
975 printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
976 printf("</b></td></tr>\n");
977 printf("<tr><td CLASS='optBoxRequiredItem'>Comment:</td><td><b>");
978 printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment_data));
979 printf("</b></td></tr>\n");
980 break;
981
982 case CMD_ADD_SVC_COMMENT:
983 case CMD_ACKNOWLEDGE_SVC_PROBLEM:
984 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
985 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
986 printf("</b></td></tr>\n");
987 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
988 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
989 if(cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) {
990 printf("<tr><td CLASS='optBoxItem'>Sticky Acknowledgement:</td><td><b>");
991 printf("<INPUT TYPE='checkbox' NAME='sticky_ack' CHECKED>");
992 printf("</b></td></tr>\n");
993 printf("<tr><td CLASS='optBoxItem'>Send Notification:</td><td><b>");
994 printf("<INPUT TYPE='checkbox' NAME='send_notification' CHECKED>");
995 printf("</b></td></tr>\n");
996 }
997 printf("<tr><td CLASS='optBoxItem'>Persistent%s:</td><td><b>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? " Comment" : "");
998 printf("<INPUT TYPE='checkbox' NAME='persistent' %s>", (cmd == CMD_ACKNOWLEDGE_SVC_PROBLEM) ? "" : "CHECKED");
999 printf("</b></td></tr>\n");
1000 printf("<tr><td CLASS='optBoxRequiredItem'>Author (Your Name):</td><td><b>");
1001 printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
1002 printf("</b></td></tr>\n");
1003 printf("<tr><td CLASS='optBoxRequiredItem'>Comment:</td><td><b>");
1004 printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment_data));
1005 printf("</b></td></tr>\n");
1006 break;
1007
1008 case CMD_DEL_HOST_COMMENT:
1009 case CMD_DEL_SVC_COMMENT:
1010 printf("<tr><td CLASS='optBoxRequiredItem'>Comment ID:</td><td><b>");
1011 printf("<INPUT TYPE='TEXT' NAME='com_id' VALUE='%lu'>", comment_id);
1012 printf("</b></td></tr>\n");
1013 break;
1014
1015 case CMD_DELAY_HOST_NOTIFICATION:
1016 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1017 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1018 printf("</b></td></tr>\n");
1019 printf("<tr><td CLASS='optBoxRequiredItem'>Notification Delay (minutes from now):</td><td><b>");
1020 printf("<INPUT TYPE='TEXT' NAME='not_dly' VALUE='%d'>", notification_delay);
1021 printf("</b></td></tr>\n");
1022 break;
1023
1024 case CMD_DELAY_SVC_NOTIFICATION:
1025 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1026 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1027 printf("</b></td></tr>\n");
1028 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1029 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1030 printf("<tr><td CLASS='optBoxRequiredItem'>Notification Delay (minutes from now):</td><td><b>");
1031 printf("<INPUT TYPE='TEXT' NAME='not_dly' VALUE='%d'>", notification_delay);
1032 printf("</b></td></tr>\n");
1033 break;
1034
1035 case CMD_SCHEDULE_SVC_CHECK:
1036 case CMD_SCHEDULE_HOST_CHECK:
1037 case CMD_SCHEDULE_HOST_SVC_CHECKS:
1038 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1039 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1040 printf("</b></td></tr>\n");
1041 if(cmd == CMD_SCHEDULE_SVC_CHECK) {
1042 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1043 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1044 printf("</b></td></tr>\n");
1045 }
1046 time(&t);
1047 get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
1048 printf("<tr><td CLASS='optBoxRequiredItem'>Check Time:</td><td><b>");
1049 printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
1050 printf("</b></td></tr>\n");
1051 printf("<tr><td CLASS='optBoxItem'>Force Check:</td><td><b>");
1052 printf("<INPUT TYPE='checkbox' NAME='force_check' %s>", (force_check == TRUE) ? "CHECKED" : "");
1053 printf("</b></td></tr>\n");
1054 break;
1055
1056 case CMD_ENABLE_SVC_CHECK:
1057 case CMD_DISABLE_SVC_CHECK:
1058 case CMD_DEL_ALL_SVC_COMMENTS:
1059 case CMD_ENABLE_SVC_NOTIFICATIONS:
1060 case CMD_DISABLE_SVC_NOTIFICATIONS:
1061 case CMD_ENABLE_PASSIVE_SVC_CHECKS:
1062 case CMD_DISABLE_PASSIVE_SVC_CHECKS:
1063 case CMD_ENABLE_SVC_EVENT_HANDLER:
1064 case CMD_DISABLE_SVC_EVENT_HANDLER:
1065 case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
1066 case CMD_ENABLE_SVC_FLAP_DETECTION:
1067 case CMD_DISABLE_SVC_FLAP_DETECTION:
1068 case CMD_START_OBSESSING_OVER_SVC:
1069 case CMD_STOP_OBSESSING_OVER_SVC:
1070 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1071 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1072 printf("</b></td></tr>\n");
1073 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1074 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1075 printf("</b></td></tr>\n");
1076 break;
1077
1078 case CMD_ENABLE_HOST_SVC_CHECKS:
1079 case CMD_DISABLE_HOST_SVC_CHECKS:
1080 case CMD_DEL_ALL_HOST_COMMENTS:
1081 case CMD_ENABLE_HOST_NOTIFICATIONS:
1082 case CMD_DISABLE_HOST_NOTIFICATIONS:
1083 case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1084 case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1085 case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
1086 case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
1087 case CMD_ENABLE_HOST_EVENT_HANDLER:
1088 case CMD_DISABLE_HOST_EVENT_HANDLER:
1089 case CMD_ENABLE_HOST_CHECK:
1090 case CMD_DISABLE_HOST_CHECK:
1091 case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
1092 case CMD_ENABLE_HOST_FLAP_DETECTION:
1093 case CMD_DISABLE_HOST_FLAP_DETECTION:
1094 case CMD_ENABLE_PASSIVE_HOST_CHECKS:
1095 case CMD_DISABLE_PASSIVE_HOST_CHECKS:
1096 case CMD_START_OBSESSING_OVER_HOST:
1097 case CMD_STOP_OBSESSING_OVER_HOST:
1098 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1099 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1100 printf("</b></td></tr>\n");
1101 if(cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_DISABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_SVC_NOTIFICATIONS) {
1102 printf("<tr><td CLASS='optBoxItem'>%s For Host Too:</td><td><b>", (cmd == CMD_ENABLE_HOST_SVC_CHECKS || cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
1103 printf("<INPUT TYPE='checkbox' NAME='ahas'>");
1104 printf("</b></td></tr>\n");
1105 }
1106 if(cmd == CMD_ENABLE_HOST_NOTIFICATIONS || cmd == CMD_DISABLE_HOST_NOTIFICATIONS) {
1107 printf("<tr><td CLASS='optBoxItem'>%s Notifications For Child Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? "Enable" : "Disable");
1108 printf("<INPUT TYPE='checkbox' NAME='ptc'>");
1109 printf("</b></td></tr>\n");
1110 }
1111 break;
1112
1113 case CMD_ENABLE_NOTIFICATIONS:
1114 case CMD_DISABLE_NOTIFICATIONS:
1115 case CMD_SHUTDOWN_PROCESS:
1116 case CMD_RESTART_PROCESS:
1117 case CMD_START_EXECUTING_SVC_CHECKS:
1118 case CMD_STOP_EXECUTING_SVC_CHECKS:
1119 case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
1120 case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
1121 case CMD_ENABLE_EVENT_HANDLERS:
1122 case CMD_DISABLE_EVENT_HANDLERS:
1123 case CMD_START_OBSESSING_OVER_SVC_CHECKS:
1124 case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
1125 case CMD_ENABLE_FLAP_DETECTION:
1126 case CMD_DISABLE_FLAP_DETECTION:
1127 case CMD_ENABLE_FAILURE_PREDICTION:
1128 case CMD_DISABLE_FAILURE_PREDICTION:
1129 case CMD_ENABLE_PERFORMANCE_DATA:
1130 case CMD_DISABLE_PERFORMANCE_DATA:
1131 case CMD_START_EXECUTING_HOST_CHECKS:
1132 case CMD_STOP_EXECUTING_HOST_CHECKS:
1133 case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
1134 case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
1135 case CMD_START_OBSESSING_OVER_HOST_CHECKS:
1136 case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
1137 printf("<tr><td CLASS='optBoxItem' colspan=2>There are no options for this command.<br>Click the 'Commit' button to submit the command.</td></tr>");
1138 break;
1139
1140 case CMD_PROCESS_HOST_CHECK_RESULT:
1141 case CMD_PROCESS_SERVICE_CHECK_RESULT:
1142 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1143 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1144 printf("</b></td></tr>\n");
1145 if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT) {
1146 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1147 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1148 printf("</b></td></tr>\n");
1149 }
1150 printf("<tr><td CLASS='optBoxRequiredItem'>Check Result:</td><td><b>");
1151 printf("<SELECT NAME='plugin_state'>");
1152 if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT) {
1153 printf("<OPTION VALUE=%d SELECTED>OK\n", STATE_OK);
1154 printf("<OPTION VALUE=%d>WARNING\n", STATE_WARNING);
1155 printf("<OPTION VALUE=%d>UNKNOWN\n", STATE_UNKNOWN);
1156 printf("<OPTION VALUE=%d>CRITICAL\n", STATE_CRITICAL);
1157 }
1158 else {
1159 printf("<OPTION VALUE=0 SELECTED>UP\n");
1160 printf("<OPTION VALUE=1>DOWN\n");
1161 printf("<OPTION VALUE=2>UNREACHABLE\n");
1162 }
1163 printf("</SELECT>\n");
1164 printf("</b></td></tr>\n");
1165 printf("<tr><td CLASS='optBoxRequiredItem'>Check Output:</td><td><b>");
1166 printf("<INPUT TYPE='TEXT' NAME='plugin_output' VALUE=''>");
1167 printf("</b></td></tr>\n");
1168 printf("<tr><td CLASS='optBoxItem'>Performance Data:</td><td><b>");
1169 printf("<INPUT TYPE='TEXT' NAME='performance_data' VALUE=''>");
1170 printf("</b></td></tr>\n");
1171 break;
1172
1173 case CMD_SCHEDULE_HOST_DOWNTIME:
1174 case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
1175 case CMD_SCHEDULE_SVC_DOWNTIME:
1176
1177 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1178 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1179 printf("</b></td></tr>\n");
1180 if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
1181 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1182 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1183 }
1184 printf("<tr><td CLASS='optBoxRequiredItem'>Author (Your Name):</td><td><b>");
1185 printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
1186 printf("</b></td></tr>\n");
1187 printf("<tr><td CLASS='optBoxRequiredItem'>Comment:</td><td><b>");
1188 printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment_data));
1189 printf("</b></td></tr>\n");
1190
1191 printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
1192
1193 printf("<tr><td CLASS='optBoxItem'>Triggered By:</td><td>\n");
1194 printf("<select name='trigger'>\n");
1195 printf("<option value='0'>N/A\n");
1196
1197 for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
1198 if(temp_downtime->type != HOST_DOWNTIME)
1199 continue;
1200 printf("<option value='%lu'>", temp_downtime->downtime_id);
1201 get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME);
1202 printf("ID: %lu, Host '%s' starting @ %s\n", temp_downtime->downtime_id, temp_downtime->host_name, start_time);
1203 }
1204 for(temp_downtime = scheduled_downtime_list; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
1205 if(temp_downtime->type != SERVICE_DOWNTIME)
1206 continue;
1207 printf("<option value='%lu'>", temp_downtime->downtime_id);
1208 get_time_string(&temp_downtime->start_time, start_time, sizeof(start_time), SHORT_DATE_TIME);
1209 printf("ID: %lu, Service '%s' on host '%s' starting @ %s \n", temp_downtime->downtime_id, temp_downtime->service_description, temp_downtime->host_name, start_time);
1210 }
1211
1212 printf("</select>\n");
1213 printf("</td></tr>\n");
1214
1215 printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
1216
1217 time(&t);
1218 get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
1219 printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
1220 printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
1221 printf("</b></td></tr>\n");
1222 t += (unsigned long)7200;
1223 get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
1224 printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
1225 printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>", buffer);
1226 printf("</b></td></tr>\n");
1227 printf("<tr><td CLASS='optBoxItem'>Type:</td><td><b>");
1228 printf("<SELECT NAME='fixed'>");
1229 printf("<OPTION VALUE=1>Fixed\n");
1230 printf("<OPTION VALUE=0>Flexible\n");
1231 printf("</SELECT>\n");
1232 printf("</b></td></tr>\n");
1233
1234 printf("<tr><td CLASS='optBoxItem'>If Flexible, Duration:</td><td>");
1235 printf("<table border=0><tr>\n");
1236 printf("<td align=right><INPUT TYPE='TEXT' NAME='hours' VALUE='2' SIZE=2 MAXLENGTH=2></td>\n");
1237 printf("<td align=left>Hours</td>\n");
1238 printf("<td align=right><INPUT TYPE='TEXT' NAME='minutes' VALUE='0' SIZE=2 MAXLENGTH=2></td>\n");
1239 printf("<td align=left>Minutes</td>\n");
1240 printf("</tr></table>\n");
1241 printf("</td></tr>\n");
1242
1243 printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
1244
1245 if(cmd == CMD_SCHEDULE_HOST_DOWNTIME) {
1246 printf("<tr><td CLASS='optBoxItem'>Child Hosts:</td><td><b>");
1247 printf("<SELECT name='childoptions'>");
1248 printf("<option value='0'>Do nothing with child hosts\n");
1249 printf("<option value='1'>Schedule triggered downtime for all child hosts\n");
1250 printf("<option value='2'>Schedule non-triggered downtime for all child hosts\n");
1251 printf("</SELECT>\n");
1252 printf("</b></td></tr>\n");
1253 }
1254
1255 printf("<tr><td CLASS='optBoxItem'><br></td></tr>\n");
1256
1257 break;
1258
1259 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
1260 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
1261 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1262 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1263 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
1264 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
1265 printf("<tr><td CLASS='optBoxRequiredItem'>Hostgroup Name:</td><td><b>");
1266 printf("<INPUT TYPE='TEXT' NAME='hostgroup' VALUE='%s'>", escape_string(hostgroup_name));
1267 printf("</b></td></tr>\n");
1268 if(cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_DISABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS) {
1269 printf("<tr><td CLASS='optBoxItem'>%s For Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
1270 printf("<INPUT TYPE='checkbox' NAME='ahas'>");
1271 printf("</b></td></tr>\n");
1272 }
1273 break;
1274
1275 case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1276 case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1277 case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1278 case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1279 case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
1280 case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
1281 printf("<tr><td CLASS='optBoxRequiredItem'>Servicegroup Name:</td><td><b>");
1282 printf("<INPUT TYPE='TEXT' NAME='servicegroup' VALUE='%s'>", escape_string(servicegroup_name));
1283 printf("</b></td></tr>\n");
1284 if(cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS || cmd == CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS) {
1285 printf("<tr><td CLASS='optBoxItem'>%s For Hosts Too:</td><td><b>", (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? "Enable" : "Disable");
1286 printf("<INPUT TYPE='checkbox' NAME='ahas'>");
1287 printf("</b></td></tr>\n");
1288 }
1289 break;
1290
1291 case CMD_DEL_HOST_DOWNTIME:
1292 case CMD_DEL_SVC_DOWNTIME:
1293 printf("<tr><td CLASS='optBoxRequiredItem'>Scheduled Downtime ID:</td><td><b>");
1294 printf("<INPUT TYPE='TEXT' NAME='down_id' VALUE='%lu'>", downtime_id);
1295 printf("</b></td></tr>\n");
1296 break;
1297
1298
1299 case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
1300 case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
1301 case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
1302 case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
1303
1304 if(cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
1305 printf("<tr><td CLASS='optBoxRequiredItem'>Hostgroup Name:</td><td><b>");
1306 printf("<INPUT TYPE='TEXT' NAME='hostgroup' VALUE='%s'>", escape_string(hostgroup_name));
1307 printf("</b></td></tr>\n");
1308 }
1309 else {
1310 printf("<tr><td CLASS='optBoxRequiredItem'>Servicegroup Name:</td><td><b>");
1311 printf("<INPUT TYPE='TEXT' NAME='servicegroup' VALUE='%s'>", escape_string(servicegroup_name));
1312 printf("</b></td></tr>\n");
1313 }
1314 printf("<tr><td CLASS='optBoxRequiredItem'>Author (Your Name):</td><td><b>");
1315 printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
1316 printf("</b></td></tr>\n");
1317 printf("<tr><td CLASS='optBoxRequiredItem'>Comment:</td><td><b>");
1318 printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment_data));
1319 printf("</b></td></tr>\n");
1320 time(&t);
1321 get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
1322 printf("<tr><td CLASS='optBoxRequiredItem'>Start Time:</td><td><b>");
1323 printf("<INPUT TYPE='TEXT' NAME='start_time' VALUE='%s'>", buffer);
1324 printf("</b></td></tr>\n");
1325 t += (unsigned long)7200;
1326 get_time_string(&t, buffer, sizeof(buffer) - 1, SHORT_DATE_TIME);
1327 printf("<tr><td CLASS='optBoxRequiredItem'>End Time:</td><td><b>");
1328 printf("<INPUT TYPE='TEXT' NAME='end_time' VALUE='%s'>", buffer);
1329 printf("</b></td></tr>\n");
1330 printf("<tr><td CLASS='optBoxItem'>Type:</td><td><b>");
1331 printf("<SELECT NAME='fixed'>");
1332 printf("<OPTION VALUE=1>Fixed\n");
1333 printf("<OPTION VALUE=0>Flexible\n");
1334 printf("</SELECT>\n");
1335 printf("</b></td></tr>\n");
1336
1337 printf("<tr><td CLASS='optBoxItem'>If Flexible, Duration:</td><td>");
1338 printf("<table border=0><tr>\n");
1339 printf("<td align=right><INPUT TYPE='TEXT' NAME='hours' VALUE='2' SIZE=2 MAXLENGTH=2></td>\n");
1340 printf("<td align=left>Hours</td>\n");
1341 printf("<td align=right><INPUT TYPE='TEXT' NAME='minutes' VALUE='0' SIZE=2 MAXLENGTH=2></td>\n");
1342 printf("<td align=left>Minutes</td>\n");
1343 printf("</tr></table>\n");
1344 printf("</td></tr>\n");
1345 if(cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
1346 printf("<tr><td CLASS='optBoxItem'>Schedule Downtime For Hosts Too:</td><td><b>");
1347 printf("<INPUT TYPE='checkbox' NAME='ahas'>");
1348 printf("</b></td></tr>\n");
1349 }
1350 break;
1351
1352 case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
1353 case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
1354 printf("<tr><td CLASS='optBoxRequiredItem'>Host Name:</td><td><b>");
1355 printf("<INPUT TYPE='TEXT' NAME='host' VALUE='%s'>", escape_string(host_name));
1356 printf("</b></td></tr>\n");
1357
1358 if(cmd == CMD_SEND_CUSTOM_SVC_NOTIFICATION) {
1359 printf("<tr><td CLASS='optBoxRequiredItem'>Service:</td><td><b>");
1360 printf("<INPUT TYPE='TEXT' NAME='service' VALUE='%s'>", escape_string(service_desc));
1361 printf("</b></td></tr>\n");
1362 }
1363
1364 printf("<tr><td CLASS='optBoxItem'>Forced:</td><td><b>");
1365 printf("<INPUT TYPE='checkbox' NAME='force_notification' ");
1366 printf("</b></td></tr>\n");
1367
1368 printf("<tr><td CLASS='optBoxItem'>Broadcast:</td><td><b>");
1369 printf("<INPUT TYPE='checkbox' NAME='broadcast_notification' ");
1370 printf("</b></td></tr>\n");
1371
1372 printf("<tr><td CLASS='optBoxRequiredItem'>Author (Your Name):</td><td><b>");
1373 printf("<INPUT TYPE='TEXT' NAME='com_author' VALUE='%s' %s>", escape_string(comment_author), (lock_author_names == TRUE) ? "READONLY DISABLED" : "");
1374 printf("</b></td></tr>\n");
1375 printf("<tr><td CLASS='optBoxRequiredItem'>Comment:</td><td><b>");
1376 printf("<INPUT TYPE='TEXT' NAME='com_data' VALUE='%s' SIZE=40>", escape_string(comment_data));
1377 printf("</b></td></tr>\n");
1378 break;
1379
1380 default:
1381 printf("<tr><td CLASS='optBoxItem'>This should not be happening... :-(</td><td></td></tr>\n");
1382 }
1383
1384
1385 printf("<tr><td CLASS='optBoxItem' COLSPAN=2></td></tr>\n");
1386 printf("<tr><td CLASS='optBoxItem'></td><td CLASS='optBoxItem'><INPUT TYPE='submit' NAME='btnSubmit' VALUE='Commit'> <INPUT TYPE='reset' VALUE='Reset'></td></tr>\n");
1387
1388 printf("</table>\n");
1389 printf("</form>\n");
1390 printf("</td>\n");
1391 printf("</tr>\n");
1392 printf("</table>\n");
1393
1394 printf("</td>\n");
1395 printf("<td align=center valign=top width=50%%>\n");
1396
1397 /* show information about the command... */
1398 show_command_help(cmd);
1399
1400 printf("</td>\n");
1401 printf("</tr>\n");
1402 printf("</table>\n");
1403
1404 printf("</div>\n");
1405 printf("</p>\n");
1406
1407 printf("<P><DIV CLASS='infoMessage'>Please enter all required information before committing the command.<br>Required fields are marked in red.<br>Failure to supply all required values will result in an error.</DIV></P>");
1408
1409 return;
1410 }
1411
1412
commit_command_data(int cmd)1413 void commit_command_data(int cmd) {
1414 char *error_string = NULL;
1415 int result = OK;
1416 int authorized = FALSE;
1417 service *temp_service;
1418 host *temp_host;
1419 hostgroup *temp_hostgroup;
1420 comment *temp_comment;
1421 scheduled_downtime *temp_downtime;
1422 servicegroup *temp_servicegroup = NULL;
1423 contact *temp_contact = NULL;
1424
1425
1426 /* get authentication information */
1427 get_authentication_information(¤t_authdata);
1428
1429 /* get name to use for author */
1430 if(lock_author_names == TRUE) {
1431 temp_contact = find_contact(current_authdata.username);
1432 if(temp_contact != NULL && temp_contact->alias != NULL)
1433 comment_author = temp_contact->alias;
1434 else
1435 comment_author = current_authdata.username;
1436 }
1437
1438 switch(cmd) {
1439 case CMD_ADD_HOST_COMMENT:
1440 case CMD_ACKNOWLEDGE_HOST_PROBLEM:
1441
1442 /* make sure we have author name, and comment data... */
1443 if(!strcmp(comment_author, "")) {
1444 if(!error_string)
1445 error_string = strdup("Author was not entered");
1446 }
1447 if(!strcmp(comment_data, "")) {
1448 if(!error_string)
1449 error_string = strdup("Comment was not entered");
1450 }
1451
1452 /* clean up the comment data */
1453 clean_comment_data(comment_author);
1454 clean_comment_data(comment_data);
1455
1456 /* see if the user is authorized to issue a command... */
1457 temp_host = find_host(host_name);
1458 if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
1459 authorized = TRUE;
1460 break;
1461
1462 case CMD_ADD_SVC_COMMENT:
1463 case CMD_ACKNOWLEDGE_SVC_PROBLEM:
1464
1465 /* make sure we have author name, and comment data... */
1466 if(!strcmp(comment_author, "")) {
1467 if(!error_string)
1468 error_string = strdup("Author was not entered");
1469 }
1470 if(!strcmp(comment_data, "")) {
1471 if(!error_string)
1472 error_string = strdup("Comment was not entered");
1473 }
1474
1475 /* clean up the comment data */
1476 clean_comment_data(comment_author);
1477 clean_comment_data(comment_data);
1478
1479 /* see if the user is authorized to issue a command... */
1480 temp_service = find_service(host_name, service_desc);
1481 if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
1482 authorized = TRUE;
1483 break;
1484
1485 case CMD_DEL_HOST_COMMENT:
1486 case CMD_DEL_SVC_COMMENT:
1487
1488 /* check the sanity of the comment id */
1489 if(comment_id == 0) {
1490 if(!error_string)
1491 error_string = strdup("Comment id cannot be 0");
1492 }
1493
1494 /* find the comment */
1495 if(cmd == CMD_DEL_HOST_COMMENT)
1496 temp_comment = find_host_comment(comment_id);
1497 else
1498 temp_comment = find_service_comment(comment_id);
1499
1500 /* see if the user is authorized to issue a command... */
1501 if(cmd == CMD_DEL_HOST_COMMENT && temp_comment != NULL) {
1502 temp_host = find_host(temp_comment->host_name);
1503 if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
1504 authorized = TRUE;
1505 }
1506 if(cmd == CMD_DEL_SVC_COMMENT && temp_comment != NULL) {
1507 temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
1508 if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
1509 authorized = TRUE;
1510 }
1511
1512 /* free comment data */
1513 free_comment_data();
1514
1515 break;
1516
1517 case CMD_DEL_HOST_DOWNTIME:
1518 case CMD_DEL_SVC_DOWNTIME:
1519
1520 /* check the sanity of the downtime id */
1521 if(downtime_id == 0) {
1522 if(!error_string)
1523 error_string = strdup("Downtime id cannot be 0");
1524 }
1525
1526 /* find the downtime entry */
1527 if(cmd == CMD_DEL_HOST_DOWNTIME)
1528 temp_downtime = find_host_downtime(downtime_id);
1529 else
1530 temp_downtime = find_service_downtime(downtime_id);
1531
1532 /* see if the user is authorized to issue a command... */
1533 if(cmd == CMD_DEL_HOST_DOWNTIME && temp_downtime != NULL) {
1534 temp_host = find_host(temp_downtime->host_name);
1535 if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
1536 authorized = TRUE;
1537 }
1538 if(cmd == CMD_DEL_SVC_DOWNTIME && temp_downtime != NULL) {
1539 temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
1540 if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
1541 authorized = TRUE;
1542 }
1543
1544 /* free downtime data */
1545 free_downtime_data();
1546
1547 break;
1548
1549 case CMD_SCHEDULE_SVC_CHECK:
1550 case CMD_ENABLE_SVC_CHECK:
1551 case CMD_DISABLE_SVC_CHECK:
1552 case CMD_DEL_ALL_SVC_COMMENTS:
1553 case CMD_ENABLE_SVC_NOTIFICATIONS:
1554 case CMD_DISABLE_SVC_NOTIFICATIONS:
1555 case CMD_ENABLE_PASSIVE_SVC_CHECKS:
1556 case CMD_DISABLE_PASSIVE_SVC_CHECKS:
1557 case CMD_ENABLE_SVC_EVENT_HANDLER:
1558 case CMD_DISABLE_SVC_EVENT_HANDLER:
1559 case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
1560 case CMD_PROCESS_SERVICE_CHECK_RESULT:
1561 case CMD_SCHEDULE_SVC_DOWNTIME:
1562 case CMD_DELAY_SVC_NOTIFICATION:
1563 case CMD_ENABLE_SVC_FLAP_DETECTION:
1564 case CMD_DISABLE_SVC_FLAP_DETECTION:
1565 case CMD_START_OBSESSING_OVER_SVC:
1566 case CMD_STOP_OBSESSING_OVER_SVC:
1567
1568 /* make sure we have author name and comment data... */
1569 if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
1570 if(!strcmp(comment_data, "")) {
1571 if(!error_string)
1572 error_string = strdup("Comment was not entered");
1573 }
1574 else if(!strcmp(comment_author, "")) {
1575 if(!error_string)
1576 error_string = strdup("Author was not entered");
1577 }
1578 }
1579
1580 /* see if the user is authorized to issue a command... */
1581 temp_service = find_service(host_name, service_desc);
1582 if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
1583 authorized = TRUE;
1584
1585 /* make sure we have passive check info (if necessary) */
1586 if(cmd == CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output, "")) {
1587 if(!error_string)
1588 error_string = strdup("Plugin output cannot be blank");
1589 }
1590
1591 /* make sure we have a notification delay (if necessary) */
1592 if(cmd == CMD_DELAY_SVC_NOTIFICATION && notification_delay <= 0) {
1593 if(!error_string)
1594 error_string = strdup("Notification delay must be greater than 0");
1595 }
1596
1597 /* clean up the comment data if scheduling downtime */
1598 if(cmd == CMD_SCHEDULE_SVC_DOWNTIME) {
1599 clean_comment_data(comment_author);
1600 clean_comment_data(comment_data);
1601 }
1602
1603 /* make sure we have check time (if necessary) */
1604 if(cmd == CMD_SCHEDULE_SVC_CHECK && start_time == (time_t)0) {
1605 if(!error_string)
1606 error_string = strdup("Start time must be non-zero or bad format has been submitted.");
1607 }
1608
1609 /* make sure we have start/end times for downtime (if necessary) */
1610 if(cmd == CMD_SCHEDULE_SVC_DOWNTIME && (start_time == (time_t)0 || end_time == (time_t)0 || end_time < start_time)) {
1611 if(!error_string)
1612 error_string = strdup("Start or end time not valid");
1613 }
1614
1615 break;
1616
1617 case CMD_ENABLE_NOTIFICATIONS:
1618 case CMD_DISABLE_NOTIFICATIONS:
1619 case CMD_SHUTDOWN_PROCESS:
1620 case CMD_RESTART_PROCESS:
1621 case CMD_START_EXECUTING_SVC_CHECKS:
1622 case CMD_STOP_EXECUTING_SVC_CHECKS:
1623 case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
1624 case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
1625 case CMD_ENABLE_EVENT_HANDLERS:
1626 case CMD_DISABLE_EVENT_HANDLERS:
1627 case CMD_START_OBSESSING_OVER_SVC_CHECKS:
1628 case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
1629 case CMD_ENABLE_FLAP_DETECTION:
1630 case CMD_DISABLE_FLAP_DETECTION:
1631 case CMD_ENABLE_FAILURE_PREDICTION:
1632 case CMD_DISABLE_FAILURE_PREDICTION:
1633 case CMD_ENABLE_PERFORMANCE_DATA:
1634 case CMD_DISABLE_PERFORMANCE_DATA:
1635 case CMD_START_EXECUTING_HOST_CHECKS:
1636 case CMD_STOP_EXECUTING_HOST_CHECKS:
1637 case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
1638 case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
1639 case CMD_START_OBSESSING_OVER_HOST_CHECKS:
1640 case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
1641
1642 /* see if the user is authorized to issue a command... */
1643 if(is_authorized_for_system_commands(¤t_authdata) == TRUE)
1644 authorized = TRUE;
1645 break;
1646
1647 case CMD_ENABLE_HOST_SVC_CHECKS:
1648 case CMD_DISABLE_HOST_SVC_CHECKS:
1649 case CMD_DEL_ALL_HOST_COMMENTS:
1650 case CMD_SCHEDULE_HOST_SVC_CHECKS:
1651 case CMD_ENABLE_HOST_NOTIFICATIONS:
1652 case CMD_DISABLE_HOST_NOTIFICATIONS:
1653 case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1654 case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
1655 case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
1656 case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
1657 case CMD_ENABLE_HOST_EVENT_HANDLER:
1658 case CMD_DISABLE_HOST_EVENT_HANDLER:
1659 case CMD_ENABLE_HOST_CHECK:
1660 case CMD_DISABLE_HOST_CHECK:
1661 case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
1662 case CMD_SCHEDULE_HOST_DOWNTIME:
1663 case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
1664 case CMD_DELAY_HOST_NOTIFICATION:
1665 case CMD_ENABLE_HOST_FLAP_DETECTION:
1666 case CMD_DISABLE_HOST_FLAP_DETECTION:
1667 case CMD_PROCESS_HOST_CHECK_RESULT:
1668 case CMD_ENABLE_PASSIVE_HOST_CHECKS:
1669 case CMD_DISABLE_PASSIVE_HOST_CHECKS:
1670 case CMD_SCHEDULE_HOST_CHECK:
1671 case CMD_START_OBSESSING_OVER_HOST:
1672 case CMD_STOP_OBSESSING_OVER_HOST:
1673
1674 /* make sure we have author name and comment data... */
1675 if(cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) {
1676 if(!strcmp(comment_data, "")) {
1677 if(!error_string)
1678 error_string = strdup("Comment was not entered");
1679 }
1680 else if(!strcmp(comment_author, "")) {
1681 if(!error_string)
1682 error_string = strdup("Author was not entered");
1683 }
1684 }
1685
1686 /* see if the user is authorized to issue a command... */
1687 temp_host = find_host(host_name);
1688 if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
1689 authorized = TRUE;
1690
1691 /* clean up the comment data if scheduling downtime */
1692 if(cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) {
1693 clean_comment_data(comment_author);
1694 clean_comment_data(comment_data);
1695 }
1696
1697 /* make sure we have a notification delay (if necessary) */
1698 if(cmd == CMD_DELAY_HOST_NOTIFICATION && notification_delay <= 0) {
1699 if(!error_string)
1700 error_string = strdup("Notification delay must be greater than 0");
1701 }
1702
1703 /* make sure we have start/end times for downtime (if necessary) */
1704 if((cmd == CMD_SCHEDULE_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOST_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
1705 if(!error_string)
1706 error_string = strdup("Start or end time not valid");
1707 }
1708
1709 /* make sure we have check time (if necessary) */
1710 if((cmd == CMD_SCHEDULE_HOST_CHECK || cmd == CMD_SCHEDULE_HOST_SVC_CHECKS) && start_time == (time_t)0) {
1711 if(!error_string)
1712 error_string = strdup("Start time must be non-zero or bad format has been submitted.");
1713 }
1714
1715 /* make sure we have passive check info (if necessary) */
1716 if(cmd == CMD_PROCESS_HOST_CHECK_RESULT && !strcmp(plugin_output, "")) {
1717 if(!error_string)
1718 error_string = strdup("Plugin output cannot be blank");
1719 }
1720
1721 break;
1722
1723 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
1724 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
1725 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1726 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
1727 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
1728 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
1729 case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
1730 case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
1731
1732 /* make sure we have author and comment data */
1733 if(cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
1734 if(!strcmp(comment_data, "")) {
1735 if(!error_string)
1736 error_string = strdup("Comment was not entered");
1737 }
1738 else if(!strcmp(comment_author, "")) {
1739 if(!error_string)
1740 error_string = strdup("Author was not entered");
1741 }
1742 }
1743
1744 /* make sure we have start/end times for downtime */
1745 if((cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
1746 if(!error_string)
1747 error_string = strdup("Start or end time not valid");
1748 }
1749
1750 /* see if the user is authorized to issue a command... */
1751 temp_hostgroup = find_hostgroup(hostgroup_name);
1752 if(is_authorized_for_hostgroup_commands(temp_hostgroup, ¤t_authdata) == TRUE)
1753 authorized = TRUE;
1754
1755 /* clean up the comment data if scheduling downtime */
1756 if(cmd == CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME) {
1757 clean_comment_data(comment_author);
1758 clean_comment_data(comment_data);
1759 }
1760
1761 break;
1762
1763 case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1764 case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
1765 case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1766 case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
1767 case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
1768 case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
1769 case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
1770 case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
1771
1772 /* make sure we have author and comment data */
1773 if(cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) {
1774 if(!strcmp(comment_data, "")) {
1775 if(!error_string)
1776 error_string = strdup("Comment was not entered");
1777 }
1778 else if(!strcmp(comment_author, "")) {
1779 if(!error_string)
1780 error_string = strdup("Author was not entered");
1781 }
1782 }
1783
1784 /* make sure we have start/end times for downtime */
1785 if((cmd == CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd == CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME) && (start_time == (time_t)0 || end_time == (time_t)0 || start_time > end_time)) {
1786 if(!error_string)
1787 error_string = strdup("Start or end time not valid");
1788 }
1789
1790 /* see if the user is authorized to issue a command... */
1791
1792 temp_servicegroup = find_servicegroup(servicegroup_name);
1793 if(is_authorized_for_servicegroup_commands(temp_servicegroup, ¤t_authdata) == TRUE)
1794 authorized = TRUE;
1795
1796 break;
1797
1798 case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
1799 case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
1800
1801 /* make sure we have author and comment data */
1802 if(!strcmp(comment_data, "")) {
1803 if(!error_string)
1804 error_string = strdup("Comment was not entered");
1805 }
1806 else if(!strcmp(comment_author, "")) {
1807 if(!error_string)
1808 error_string = strdup("Author was not entered");
1809 }
1810
1811 /* see if the user is authorized to issue a command... */
1812 if(cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) {
1813 temp_host = find_host(host_name);
1814 if(is_authorized_for_host_commands(temp_host, ¤t_authdata) == TRUE)
1815 authorized = TRUE;
1816 }
1817 else {
1818 temp_service = find_service(host_name, service_desc);
1819 if(is_authorized_for_service_commands(temp_service, ¤t_authdata) == TRUE)
1820 authorized = TRUE;
1821 }
1822 break;
1823
1824 default:
1825 if(!error_string) error_string = strdup("An error occurred while processing your command!");
1826 }
1827
1828
1829 /* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
1830 if(use_authentication == FALSE) {
1831 if(content_type == WML_CONTENT)
1832 printf("<p>Error: Authentication is not enabled!</p>\n");
1833 else {
1834 printf("<P>\n");
1835 printf("<DIV CLASS='errorMessage'>Sorry Dave, I can't let you do that...</DIV><br>");
1836 printf("<DIV CLASS='errorDescription'>");
1837 printf("It seems that you have chosen to not use the authentication functionality of the CGIs.<br><br>");
1838 printf("I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Nagios,");
1839 printf("so you'll have to disable this safeguard if you are really stubborn and want to invite trouble.<br><br>");
1840 printf("<strong>Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.</strong>\n");
1841 printf("</DIV>\n");
1842 printf("</P>\n");
1843 }
1844 }
1845
1846 /* the user is not authorized to issue the given command */
1847 else if(authorized == FALSE) {
1848 if(content_type == WML_CONTENT)
1849 printf("<p>Error: You're not authorized to commit that command!</p>\n");
1850 else {
1851 printf("<P><DIV CLASS='errorMessage'>Sorry, but you are not authorized to commit the specified command.</DIV></P>\n");
1852 printf("<P><DIV CLASS='errorDescription'>Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.<BR><BR>\n");
1853 printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
1854 }
1855 }
1856
1857 /* some error occurred (data was probably missing) */
1858 else if(error_string) {
1859 if(content_type == WML_CONTENT)
1860 printf("<p>%s</p>\n", error_string);
1861 else {
1862 printf("<P><DIV CLASS='errorMessage'>%s</DIV></P>\n", error_string);
1863 free(error_string);
1864 printf("<P><DIV CLASS='errorDescription'>Go <A HREF='javascript:window.history.go(-1)'>back</A> and verify that you entered all required information correctly.<BR>\n");
1865 printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
1866 }
1867 }
1868
1869 /* if Nagios isn't checking external commands, don't do anything... */
1870 else if(check_external_commands == FALSE) {
1871 if(content_type == WML_CONTENT)
1872 printf("<p>Error: Nagios is not checking external commands!</p>\n");
1873 else {
1874 printf("<P><DIV CLASS='errorMessage'>Sorry, but Nagios is currently not checking for external commands, so your command will not be committed!</DIV></P>\n");
1875 printf("<P><DIV CLASS='errorDescription'>Read the documentation for information on how to enable external commands...<BR><BR>\n");
1876 printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
1877 }
1878 }
1879
1880 /* everything looks okay, so let's go ahead and commit the command... */
1881 else {
1882
1883 /* commit the command */
1884 result = commit_command(cmd);
1885
1886 if(result == OK) {
1887 if(content_type == WML_CONTENT)
1888 printf("<p>Your command was submitted sucessfully...</p>\n");
1889 else {
1890 printf("<P><DIV CLASS='infoMessage'>Your command request was successfully submitted to Nagios for processing.<BR><BR>\n");
1891 printf("Note: It may take a while before the command is actually processed.<BR><BR>\n");
1892 printf("<A HREF='javascript:window.history.go(-2)'>Done</A></DIV></P>");
1893 }
1894 }
1895 else {
1896 if(content_type == WML_CONTENT)
1897 printf("<p>An error occurred while committing your command!</p>\n");
1898 else {
1899 printf("<P><DIV CLASS='errorMessage'>An error occurred while attempting to commit your command for processing.<BR><BR>\n");
1900 printf("<A HREF='javascript:window.history.go(-2)'>Return from whence you came</A></DIV></P>\n");
1901 }
1902 }
1903 }
1904
1905 return;
1906 }
1907
1908 __attribute__((format(printf, 2, 3)))
cmd_submitf(int id,const char * fmt,...)1909 static int cmd_submitf(int id, const char *fmt, ...) {
1910 char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
1911 const char *command;
1912 int len, len2;
1913 va_list ap;
1914
1915 command = extcmd_get_name(id);
1916 /*
1917 * We disallow sending 'CHANGE' commands from the cgi's
1918 * until we do proper session handling to prevent cross-site
1919 * request forgery
1920 */
1921 if(!command || (strlen(command) > 6 && !memcmp("CHANGE", command, 6)))
1922 return ERROR;
1923
1924 len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command);
1925 if(len < 0)
1926 return ERROR;
1927
1928 if(fmt) {
1929 va_start(ap, fmt);
1930 len2 = vsnprintf(&cmd[len], sizeof(cmd) - len - 1, fmt, ap);
1931 va_end(ap);
1932 if(len2 < 0)
1933 return ERROR;
1934 }
1935
1936 return write_command_to_file(cmd);
1937 }
1938
1939
1940
1941 /* commits a command for processing */
commit_command(int cmd)1942 int commit_command(int cmd) {
1943 time_t current_time;
1944 time_t scheduled_time;
1945 time_t notification_time;
1946 int result;
1947
1948 /* get the current time */
1949 time(¤t_time);
1950
1951 /* get the scheduled time */
1952 scheduled_time = current_time + (schedule_delay * 60);
1953
1954 /* get the notification time */
1955 notification_time = current_time + (notification_delay * 60);
1956
1957 /*
1958 * these are supposed to be implanted inside the
1959 * completed commands shipped off to nagios and
1960 * must therefore never contain ';'
1961 */
1962 if(host_name && strchr(host_name, ';'))
1963 return ERROR;
1964 if(service_desc && strchr(service_desc, ';'))
1965 return ERROR;
1966 if(comment_author && strchr(comment_author, ';'))
1967 return ERROR;
1968 if(hostgroup_name && strchr(hostgroup_name, ';'))
1969 return ERROR;
1970 if(servicegroup_name && strchr(servicegroup_name, ';'))
1971 return ERROR;
1972
1973 /* decide how to form the command line... */
1974 switch(cmd) {
1975
1976 /* commands without arguments */
1977 case CMD_START_EXECUTING_SVC_CHECKS:
1978 case CMD_STOP_EXECUTING_SVC_CHECKS:
1979 case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
1980 case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
1981 case CMD_ENABLE_EVENT_HANDLERS:
1982 case CMD_DISABLE_EVENT_HANDLERS:
1983 case CMD_START_OBSESSING_OVER_SVC_CHECKS:
1984 case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
1985 case CMD_ENABLE_FLAP_DETECTION:
1986 case CMD_DISABLE_FLAP_DETECTION:
1987 case CMD_ENABLE_FAILURE_PREDICTION:
1988 case CMD_DISABLE_FAILURE_PREDICTION:
1989 case CMD_ENABLE_PERFORMANCE_DATA:
1990 case CMD_DISABLE_PERFORMANCE_DATA:
1991 case CMD_START_EXECUTING_HOST_CHECKS:
1992 case CMD_STOP_EXECUTING_HOST_CHECKS:
1993 case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
1994 case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
1995 case CMD_START_OBSESSING_OVER_HOST_CHECKS:
1996 case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
1997 result = cmd_submitf(cmd, NULL);
1998 break;
1999
2000 /** simple host commands **/
2001 case CMD_ENABLE_HOST_FLAP_DETECTION:
2002 case CMD_DISABLE_HOST_FLAP_DETECTION:
2003 case CMD_ENABLE_PASSIVE_HOST_CHECKS:
2004 case CMD_DISABLE_PASSIVE_HOST_CHECKS:
2005 case CMD_START_OBSESSING_OVER_HOST:
2006 case CMD_STOP_OBSESSING_OVER_HOST:
2007 case CMD_DEL_ALL_HOST_COMMENTS:
2008 case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
2009 case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
2010 case CMD_ENABLE_HOST_EVENT_HANDLER:
2011 case CMD_DISABLE_HOST_EVENT_HANDLER:
2012 case CMD_ENABLE_HOST_CHECK:
2013 case CMD_DISABLE_HOST_CHECK:
2014 case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
2015 result = cmd_submitf(cmd, "%s", host_name);
2016 break;
2017
2018 /** simple service commands **/
2019 case CMD_ENABLE_SVC_FLAP_DETECTION:
2020 case CMD_DISABLE_SVC_FLAP_DETECTION:
2021 case CMD_ENABLE_PASSIVE_SVC_CHECKS:
2022 case CMD_DISABLE_PASSIVE_SVC_CHECKS:
2023 case CMD_START_OBSESSING_OVER_SVC:
2024 case CMD_STOP_OBSESSING_OVER_SVC:
2025 case CMD_DEL_ALL_SVC_COMMENTS:
2026 case CMD_ENABLE_SVC_NOTIFICATIONS:
2027 case CMD_DISABLE_SVC_NOTIFICATIONS:
2028 case CMD_ENABLE_SVC_EVENT_HANDLER:
2029 case CMD_DISABLE_SVC_EVENT_HANDLER:
2030 case CMD_ENABLE_SVC_CHECK:
2031 case CMD_DISABLE_SVC_CHECK:
2032 case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
2033 result = cmd_submitf(cmd, "%s;%s", host_name, service_desc);
2034 break;
2035
2036 case CMD_ADD_HOST_COMMENT:
2037 result = cmd_submitf(cmd, "%s;%d;%s;%s", host_name, persistent_comment, comment_author, comment_data);
2038 break;
2039
2040 case CMD_ADD_SVC_COMMENT:
2041 result = cmd_submitf(cmd, "%s;%s;%d;%s;%s", host_name, service_desc, persistent_comment, comment_author, comment_data);
2042 break;
2043
2044 case CMD_DEL_HOST_COMMENT:
2045 case CMD_DEL_SVC_COMMENT:
2046 result = cmd_submitf(cmd, "%lu", comment_id);
2047 break;
2048
2049 case CMD_DELAY_HOST_NOTIFICATION:
2050 result = cmd_submitf(cmd, "%s;%lu", host_name, notification_time);
2051 break;
2052
2053 case CMD_DELAY_SVC_NOTIFICATION:
2054 result = cmd_submitf(cmd, "%s;%s;%lu", host_name, service_desc, notification_time);
2055 break;
2056
2057 case CMD_SCHEDULE_SVC_CHECK:
2058 case CMD_SCHEDULE_FORCED_SVC_CHECK:
2059 if(force_check == TRUE)
2060 cmd = CMD_SCHEDULE_FORCED_SVC_CHECK;
2061 result = cmd_submitf(cmd, "%s;%s;%lu", host_name, service_desc, start_time);
2062 break;
2063
2064 case CMD_DISABLE_NOTIFICATIONS:
2065 case CMD_ENABLE_NOTIFICATIONS:
2066 case CMD_SHUTDOWN_PROCESS:
2067 case CMD_RESTART_PROCESS:
2068 result = cmd_submitf(cmd, "%lu", scheduled_time);
2069 break;
2070
2071 case CMD_ENABLE_HOST_SVC_CHECKS:
2072 case CMD_DISABLE_HOST_SVC_CHECKS:
2073 result = cmd_submitf(cmd, "%s", host_name);
2074 if(affect_host_and_services == TRUE) {
2075 cmd = (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? CMD_ENABLE_HOST_CHECK : CMD_DISABLE_HOST_CHECK;
2076 result |= cmd_submitf(cmd, "%s", host_name);
2077 }
2078 break;
2079
2080 case CMD_SCHEDULE_HOST_SVC_CHECKS:
2081 if(force_check == TRUE)
2082 cmd = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
2083 result = cmd_submitf(cmd, "%s;%lu", host_name, scheduled_time);
2084 break;
2085
2086 case CMD_ENABLE_HOST_NOTIFICATIONS:
2087 case CMD_DISABLE_HOST_NOTIFICATIONS:
2088 if(propagate_to_children == TRUE)
2089 cmd = (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS : CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
2090 result = cmd_submitf(cmd, "%s", host_name);
2091 break;
2092
2093 case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
2094 case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
2095 result = cmd_submitf(cmd, "%s", host_name);
2096 if(affect_host_and_services == TRUE) {
2097 cmd = (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOST_NOTIFICATIONS : CMD_DISABLE_HOST_NOTIFICATIONS;
2098 result |= cmd_submitf(cmd, "%s", host_name);
2099 }
2100 break;
2101
2102 case CMD_ACKNOWLEDGE_HOST_PROBLEM:
2103 result = cmd_submitf(cmd, "%s;%d;%d;%d;%s;%s", host_name, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, comment_author, comment_data);
2104 break;
2105
2106 case CMD_ACKNOWLEDGE_SVC_PROBLEM:
2107 result = cmd_submitf(cmd, "%s;%s;%d;%d;%d;%s;%s", host_name, service_desc, (sticky_ack == TRUE) ? ACKNOWLEDGEMENT_STICKY : ACKNOWLEDGEMENT_NORMAL, send_notification, persistent_comment, comment_author, comment_data);
2108 break;
2109
2110 case CMD_PROCESS_SERVICE_CHECK_RESULT:
2111 result = cmd_submitf(cmd, "%s;%s;%d;%s|%s", host_name, service_desc, plugin_state, plugin_output, performance_data);
2112 break;
2113
2114 case CMD_PROCESS_HOST_CHECK_RESULT:
2115 result = cmd_submitf(cmd, "%s;%d;%s|%s", host_name, plugin_state, plugin_output, performance_data);
2116 break;
2117
2118 case CMD_SCHEDULE_HOST_DOWNTIME:
2119 if(child_options == 1)
2120 cmd = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
2121 else if(child_options == 2)
2122 cmd = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
2123
2124 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu;%s;%s", host_name, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
2125 break;
2126
2127 case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
2128 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;%lu;%lu;%s;%s", host_name, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
2129 break;
2130
2131 case CMD_SCHEDULE_SVC_DOWNTIME:
2132 result = cmd_submitf(cmd, "%s;%s;%lu;%lu;%d;%lu;%lu;%s;%s", host_name, service_desc, start_time, end_time, fixed, triggered_by, duration, comment_author, comment_data);
2133 break;
2134
2135 case CMD_DEL_HOST_DOWNTIME:
2136 case CMD_DEL_SVC_DOWNTIME:
2137 result = cmd_submitf(cmd, "%lu", downtime_id);
2138 break;
2139
2140 case CMD_SCHEDULE_HOST_CHECK:
2141 if(force_check == TRUE)
2142 cmd = CMD_SCHEDULE_FORCED_HOST_CHECK;
2143 result = cmd_submitf(cmd, "%s;%lu", host_name, start_time);
2144 break;
2145
2146 case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
2147 result = cmd_submitf(cmd, "%s;%d;%s;%s", host_name, (force_notification | broadcast_notification), comment_author, comment_data);
2148 break;
2149
2150 case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
2151 result = cmd_submitf(cmd, "%s;%s;%d;%s;%s", host_name, service_desc, (force_notification | broadcast_notification), comment_author, comment_data);
2152 break;
2153
2154
2155 /***** HOSTGROUP COMMANDS *****/
2156
2157 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
2158 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
2159 result = cmd_submitf(cmd, "%s", hostgroup_name);
2160 if(affect_host_and_services == TRUE) {
2161 cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
2162 result |= cmd_submitf(cmd, "%s", hostgroup_name);
2163 }
2164 break;
2165
2166 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
2167 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
2168 result = cmd_submitf(cmd, "%s", hostgroup_name);
2169 break;
2170
2171 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
2172 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
2173 result = cmd_submitf(cmd, "%s", hostgroup_name);
2174 if(affect_host_and_services == TRUE) {
2175 cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? CMD_ENABLE_HOSTGROUP_HOST_CHECKS : CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
2176 result |= cmd_submitf(cmd, "%s", hostgroup_name);
2177 }
2178 break;
2179
2180 case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
2181 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2182 break;
2183
2184 case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
2185 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2186 if(affect_host_and_services == TRUE)
2187 result |= cmd_submitf(CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu;%s;%s", hostgroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2188 break;
2189
2190
2191 /***** SERVICEGROUP COMMANDS *****/
2192
2193 case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
2194 case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
2195 result = cmd_submitf(cmd, "%s", servicegroup_name);
2196 if(affect_host_and_services == TRUE) {
2197 cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
2198 result |= cmd_submitf(cmd, "%s", servicegroup_name);
2199 }
2200 break;
2201
2202 case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
2203 case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
2204 result = cmd_submitf(cmd, "%s", servicegroup_name);
2205 break;
2206
2207 case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
2208 case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
2209 result = cmd_submitf(cmd, "%s", servicegroup_name);
2210 if(affect_host_and_services == TRUE) {
2211 cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? CMD_ENABLE_SERVICEGROUP_HOST_CHECKS : CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
2212 result |= cmd_submitf(cmd, "%s", servicegroup_name);
2213 }
2214 break;
2215
2216 case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
2217 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2218 break;
2219
2220 case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
2221 result = cmd_submitf(cmd, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2222 if(affect_host_and_services == TRUE)
2223 result |= cmd_submitf(CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, "%s;%lu;%lu;%d;0;%lu;%s;%s", servicegroup_name, start_time, end_time, fixed, duration, comment_author, comment_data);
2224 break;
2225
2226 default:
2227 return ERROR;
2228 break;
2229 }
2230
2231 return result;
2232 }
2233
2234
2235
2236 /* write a command entry to the command file */
write_command_to_file(char * cmd)2237 int write_command_to_file(char *cmd) {
2238 FILE *fp;
2239 struct stat statbuf;
2240
2241 /*
2242 * Commands are not allowed to have newlines in them, as
2243 * that allows malicious users to hand-craft requests that
2244 * bypass the access-restrictions.
2245 */
2246 if(!cmd || !*cmd || strchr(cmd, '\n'))
2247 return ERROR;
2248
2249 /* bail out if the external command file doesn't exist */
2250 if(stat(command_file, &statbuf)) {
2251
2252 if(content_type == WML_CONTENT)
2253 printf("<p>Error: Could not stat() external command file!</p>\n");
2254 else {
2255 printf("<P><DIV CLASS='errorMessage'>Error: Could not stat() command file '%s'!</DIV></P>\n", command_file);
2256 printf("<P><DIV CLASS='errorDescription'>");
2257 printf("The external command file may be missing, Nagios may not be running, and/or Nagios may not be checking external commands.\n");
2258 printf("</DIV></P>\n");
2259 }
2260
2261 return ERROR;
2262 }
2263
2264 /* open the command for writing (since this is a pipe, it will really be appended) */
2265 fp = fopen(command_file, "w");
2266 if(fp == NULL) {
2267
2268 if(content_type == WML_CONTENT)
2269 printf("<p>Error: Could not open command file for update!</p>\n");
2270 else {
2271 printf("<P><DIV CLASS='errorMessage'>Error: Could not open command file '%s' for update!</DIV></P>\n", command_file);
2272 printf("<P><DIV CLASS='errorDescription'>");
2273 printf("The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.\n");
2274 printf("</DIV></P>\n");
2275 }
2276
2277 return ERROR;
2278 }
2279
2280 /* write the command to file */
2281 fprintf(fp, "%s\n", cmd);
2282
2283 /* flush buffer */
2284 fflush(fp);
2285
2286 fclose(fp);
2287
2288 return OK;
2289 }
2290
2291
2292 /* strips out semicolons from comment data */
clean_comment_data(char * buffer)2293 void clean_comment_data(char *buffer) {
2294 int x;
2295 int y;
2296
2297 y = (int)strlen(buffer);
2298
2299 for(x = 0; x < y; x++) {
2300 if(buffer[x] == ';')
2301 buffer[x] = ' ';
2302 }
2303
2304 return;
2305 }
2306
2307
2308 /* display information about a command */
show_command_help(cmd)2309 void show_command_help(cmd) {
2310
2311 printf("<DIV ALIGN=CENTER CLASS='descriptionTitle'>Command Description</DIV>\n");
2312 printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='commandDescription'>\n");
2313 printf("<TR><TD CLASS='commandDescription'>\n");
2314
2315 /* decide what information to print out... */
2316 switch(cmd) {
2317
2318 case CMD_ADD_HOST_COMMENT:
2319 printf("This command is used to add a comment for the specified host. If you work with other administrators, you may find it useful to share information about a host\n");
2320 printf("that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will be automatically be deleted\n");
2321 printf("the next time Nagios is restarted.\n");
2322 break;
2323
2324 case CMD_ADD_SVC_COMMENT:
2325 printf("This command is used to add a comment for the specified service. If you work with other administrators, you may find it useful to share information about a host\n");
2326 printf("or service that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will automatically be\n");
2327 printf("deleted the next time Nagios is restarted.\n");
2328 break;
2329
2330 case CMD_DEL_HOST_COMMENT:
2331 printf("This command is used to delete a specific host comment.\n");
2332 break;
2333
2334 case CMD_DEL_SVC_COMMENT:
2335 printf("This command is used to delete a specific service comment.\n");
2336 break;
2337
2338 case CMD_DELAY_HOST_NOTIFICATION:
2339 printf("This command is used to delay the next problem notification that is sent out for the specified host. The notification delay will be disregarded if\n");
2340 printf("the host changes state before the next notification is scheduled to be sent out. This command has no effect if the host is currently UP.\n");
2341 break;
2342
2343 case CMD_DELAY_SVC_NOTIFICATION:
2344 printf("This command is used to delay the next problem notification that is sent out for the specified service. The notification delay will be disregarded if\n");
2345 printf("the service changes state before the next notification is scheduled to be sent out. This command has no effect if the service is currently in an OK state.\n");
2346 break;
2347
2348 case CMD_SCHEDULE_SVC_CHECK:
2349 printf("This command is used to schedule the next check of a particular service. Nagios will re-queue the service to be checked at the time you specify.\n");
2350 printf("If you select the <i>force check</i> option, Nagios will force a check of the service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the service.\n");
2351 break;
2352
2353 case CMD_ENABLE_SVC_CHECK:
2354 printf("This command is used to enable active checks of a service.\n");
2355 break;
2356
2357 case CMD_DISABLE_SVC_CHECK:
2358 printf("This command is used to disable active checks of a service.\n");
2359 break;
2360
2361 case CMD_DISABLE_NOTIFICATIONS:
2362 printf("This command is used to disable host and service notifications on a program-wide basis.\n");
2363 break;
2364
2365 case CMD_ENABLE_NOTIFICATIONS:
2366 printf("This command is used to enable host and service notifications on a program-wide basis.\n");
2367 break;
2368
2369 case CMD_SHUTDOWN_PROCESS:
2370 printf("This command is used to shutdown the Nagios process. Note: Once the Nagios has been shutdown, it cannot be restarted via the web interface!\n");
2371 break;
2372
2373 case CMD_RESTART_PROCESS:
2374 printf("This command is used to restart the Nagios process. Executing a restart command is equivalent to sending the process a HUP signal.\n");
2375 printf("All information will be flushed from memory, the configuration files will be re-read, and Nagios will start monitoring with the new configuration information.\n");
2376 break;
2377
2378 case CMD_ENABLE_HOST_SVC_CHECKS:
2379 printf("This command is used to enable active checks of all services associated with the specified host. This <i>does not</i> enable checks of the host unless you check the 'Enable for host too' option.\n");
2380 break;
2381
2382 case CMD_DISABLE_HOST_SVC_CHECKS:
2383 printf("This command is used to disable active checks of all services associated with the specified host. When a service is disabled Nagios will not monitor the service. Doing this will prevent any notifications being sent out for\n");
2384 printf("the specified service while it is disabled. In order to have Nagios check the service in the future you will have to re-enable the service.\n");
2385 printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with. This <i>does not</i> disable checks of the host unless you check the 'Disable for host too' option.\n");
2386 break;
2387
2388 case CMD_SCHEDULE_HOST_SVC_CHECKS:
2389 printf("This command is used to scheduled the next check of all services on the specified host. If you select the <i>force check</i> option, Nagios will force a check of all services on the host regardless of both what time the scheduled checks occur and whether or not checks are enabled for those services.\n");
2390 break;
2391
2392 case CMD_DEL_ALL_HOST_COMMENTS:
2393 printf("This command is used to delete all comments associated with the specified host.\n");
2394 break;
2395
2396 case CMD_DEL_ALL_SVC_COMMENTS:
2397 printf("This command is used to delete all comments associated with the specified service.\n");
2398 break;
2399
2400 case CMD_ENABLE_SVC_NOTIFICATIONS:
2401 printf("This command is used to enable notifications for the specified service. Notifications will only be sent out for the\n");
2402 printf("service state types you defined in your service definition.\n");
2403 break;
2404
2405 case CMD_DISABLE_SVC_NOTIFICATIONS:
2406 printf("This command is used to prevent notifications from being sent out for the specified service. You will have to re-enable notifications\n");
2407 printf("for this service before any alerts can be sent out in the future.\n");
2408 break;
2409
2410 case CMD_ENABLE_HOST_NOTIFICATIONS:
2411 printf("This command is used to enable notifications for the specified host. Notifications will only be sent out for the\n");
2412 printf("host state types you defined in your host definition. Note that this command <i>does not</i> enable notifications\n");
2413 printf("for services associated with this host.\n");
2414 break;
2415
2416 case CMD_DISABLE_HOST_NOTIFICATIONS:
2417 printf("This command is used to prevent notifications from being sent out for the specified host. You will have to re-enable notifications for this host\n");
2418 printf("before any alerts can be sent out in the future. Note that this command <i>does not</i> disable notifications for services associated with this host.\n");
2419 break;
2420
2421 case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
2422 printf("This command is used to enable notifications for all hosts and services that lie \"beyond\" the specified host\n");
2423 printf("(from the view of Nagios).\n");
2424 break;
2425
2426 case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
2427 printf("This command is used to temporarily prevent notifications from being sent out for all hosts and services that lie\n");
2428 printf("\"beyond\" the specified host (from the view of Nagios).\n");
2429 break;
2430
2431 case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
2432 printf("This command is used to enable notifications for all services on the specified host. Notifications will only be sent out for the\n");
2433 printf("service state types you defined in your service definition. This <i>does not</i> enable notifications for the host unless you check the 'Enable for host too' option.\n");
2434 break;
2435
2436 case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
2437 printf("This command is used to prevent notifications from being sent out for all services on the specified host. You will have to re-enable notifications for\n");
2438 printf("all services associated with this host before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the host unless you check the 'Disable for host too' option.\n");
2439 break;
2440
2441 case CMD_ACKNOWLEDGE_HOST_PROBLEM:
2442 printf("This command is used to acknowledge a host problem. When a host problem is acknowledged, future notifications about problems are temporarily disabled until the host changes from its current state.\n");
2443 printf("If you want acknowledgement to disable notifications until the host recovers, check the 'Sticky Acknowledgement' checkbox.\n");
2444 printf("Contacts for this host will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the host.\n");
2445 printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the host comment to remain once the acknowledgement is removed, check\n");
2446 printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
2447 break;
2448
2449 case CMD_ACKNOWLEDGE_SVC_PROBLEM:
2450 printf("This command is used to acknowledge a service problem. When a service problem is acknowledged, future notifications about problems are temporarily disabled until the service changes from its current state.\n");
2451 printf("If you want acknowledgement to disable notifications until the service recovers, check the 'Sticky Acknowledgement' checkbox.\n");
2452 printf("Contacts for this service will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the service.\n");
2453 printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the service comment to remain once the acknowledgement is removed, check\n");
2454 printf("the 'Persistent Comment' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
2455 break;
2456
2457 case CMD_START_EXECUTING_SVC_CHECKS:
2458 printf("This command is used to resume execution of active service checks on a program-wide basis. Individual services which are disabled will still not be checked.\n");
2459 break;
2460
2461 case CMD_STOP_EXECUTING_SVC_CHECKS:
2462 printf("This command is used to temporarily stop Nagios from actively executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts).\n");
2463 printf("Service checks will not be executed again until you issue a command to resume service check execution.\n");
2464 break;
2465
2466 case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
2467 printf("This command is used to make Nagios start accepting passive service check results that it finds in the external command file\n");
2468 break;
2469
2470 case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
2471 printf("This command is use to make Nagios stop accepting passive service check results that it finds in the external command file. All passive check results that are found will be ignored.\n");
2472 break;
2473
2474 case CMD_ENABLE_PASSIVE_SVC_CHECKS:
2475 printf("This command is used to allow Nagios to accept passive service check results that it finds in the external command file for this particular service.\n");
2476 break;
2477
2478 case CMD_DISABLE_PASSIVE_SVC_CHECKS:
2479 printf("This command is used to stop Nagios accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.\n");
2480 break;
2481
2482 case CMD_ENABLE_EVENT_HANDLERS:
2483 printf("This command is used to allow Nagios to run host and service event handlers.\n");
2484 break;
2485
2486 case CMD_DISABLE_EVENT_HANDLERS:
2487 printf("This command is used to temporarily prevent Nagios from running any host or service event handlers.\n");
2488 break;
2489
2490 case CMD_ENABLE_SVC_EVENT_HANDLER:
2491 printf("This command is used to allow Nagios to run the service event handler for a particular service when necessary (if one is defined).\n");
2492 break;
2493
2494 case CMD_DISABLE_SVC_EVENT_HANDLER:
2495 printf("This command is used to temporarily prevent Nagios from running the service event handler for a particular service.\n");
2496 break;
2497
2498 case CMD_ENABLE_HOST_EVENT_HANDLER:
2499 printf("This command is used to allow Nagios to run the host event handler for a particular service when necessary (if one is defined).\n");
2500 break;
2501
2502 case CMD_DISABLE_HOST_EVENT_HANDLER:
2503 printf("This command is used to temporarily prevent Nagios from running the host event handler for a particular host.\n");
2504 break;
2505
2506 case CMD_ENABLE_HOST_CHECK:
2507 printf("This command is used to enable active checks of this host.\n");
2508 break;
2509
2510 case CMD_DISABLE_HOST_CHECK:
2511 printf("This command is used to temporarily prevent Nagios from actively checking the status of a particular host. If Nagios needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.\n");
2512 break;
2513
2514 case CMD_START_OBSESSING_OVER_SVC_CHECKS:
2515 printf("This command is used to have Nagios start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.\n");
2516 break;
2517
2518 case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
2519 printf("This command is used stop Nagios from obsessing over service checks.\n");
2520 break;
2521
2522 case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
2523 printf("This command is used to remove an acknowledgement for a particular host problem. Once the acknowledgement is removed, notifications may start being\n");
2524 printf("sent out about the host problem. \n");
2525 break;
2526
2527 case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
2528 printf("This command is used to remove an acknowledgement for a particular service problem. Once the acknowledgement is removed, notifications may start being\n");
2529 printf("sent out about the service problem.\n");
2530 break;
2531
2532 case CMD_PROCESS_SERVICE_CHECK_RESULT:
2533 printf("This command is used to submit a passive check result for a particular service. It is particularly useful for resetting security-related services to OK states once they have been dealt with.\n");
2534 break;
2535
2536 case CMD_PROCESS_HOST_CHECK_RESULT:
2537 printf("This command is used to submit a passive check result for a particular host.\n");
2538 break;
2539
2540 case CMD_SCHEDULE_HOST_DOWNTIME:
2541 printf("This command is used to schedule downtime for a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n");
2542 printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n");
2543 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2544 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2545 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n");
2546 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
2547 break;
2548
2549 case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
2550 printf("This command is used to schedule downtime for all services on a particular host. During the specified downtime, Nagios will not send notifications out about the host.\n");
2551 printf("Normally, a host in downtime will not send alerts about any services in a failed state. This option will explicitly set downtime for all services for this host.\n");
2552 printf("When the scheduled downtime expires, Nagios will send out notifications for this host as it normally would. Scheduled downtimes are preserved\n");
2553 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2554 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2555 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the host goes down or becomes unreachable (sometime between the\n");
2556 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
2557 break;
2558
2559 case CMD_SCHEDULE_SVC_DOWNTIME:
2560 printf("This command is used to schedule downtime for a particular service. During the specified downtime, Nagios will not send notifications out about the service.\n");
2561 printf("When the scheduled downtime expires, Nagios will send out notifications for this service as it normally would. Scheduled downtimes are preserved\n");
2562 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2563 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2564 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when the service enters a non-OK state (sometime between the\n");
2565 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed downtime.\n");
2566 break;
2567
2568 case CMD_ENABLE_HOST_FLAP_DETECTION:
2569 printf("This command is used to enable flap detection for a specific host. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
2570 break;
2571
2572 case CMD_DISABLE_HOST_FLAP_DETECTION:
2573 printf("This command is used to disable flap detection for a specific host.\n");
2574 break;
2575
2576 case CMD_ENABLE_SVC_FLAP_DETECTION:
2577 printf("This command is used to enable flap detection for a specific service. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
2578 break;
2579
2580 case CMD_DISABLE_SVC_FLAP_DETECTION:
2581 printf("This command is used to disable flap detection for a specific service.\n");
2582 break;
2583
2584 case CMD_ENABLE_FLAP_DETECTION:
2585 printf("This command is used to enable flap detection for hosts and services on a program-wide basis. Individual hosts and services may have flap detection disabled.\n");
2586 break;
2587
2588 case CMD_DISABLE_FLAP_DETECTION:
2589 printf("This command is used to disable flap detection for hosts and services on a program-wide basis.\n");
2590 break;
2591
2592 case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
2593 printf("This command is used to enable notifications for all services in the specified hostgroup. Notifications will only be sent out for the\n");
2594 printf("service state types you defined in your service definitions. This <i>does not</i> enable notifications for the hosts in this hostgroup unless you check the 'Enable for hosts too' option.\n");
2595 break;
2596
2597 case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
2598 printf("This command is used to prevent notifications from being sent out for all services in the specified hostgroup. You will have to re-enable notifications for\n");
2599 printf("all services in this hostgroup before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the hosts in this hostgroup unless you check the 'Disable for hosts too' option.\n");
2600 break;
2601
2602 case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
2603 printf("This command is used to enable notifications for all hosts in the specified hostgroup. Notifications will only be sent out for the\n");
2604 printf("host state types you defined in your host definitions.\n");
2605 break;
2606
2607 case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
2608 printf("This command is used to prevent notifications from being sent out for all hosts in the specified hostgroup. You will have to re-enable notifications for\n");
2609 printf("all hosts in this hostgroup before any alerts can be sent out in the future.\n");
2610 break;
2611
2612 case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
2613 printf("This command is used to enable active checks of all services in the specified hostgroup. This <i>does not</i> enable active checks of the hosts in the hostgroup unless you check the 'Enable for hosts too' option.\n");
2614 break;
2615
2616 case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
2617 printf("This command is used to disable active checks of all services in the specified hostgroup. This <i>does not</i> disable checks of the hosts in the hostgroup unless you check the 'Disable for hosts too' option.\n");
2618 break;
2619
2620 case CMD_DEL_HOST_DOWNTIME:
2621 printf("This command is used to cancel active or pending scheduled downtime for the specified host.\n");
2622 break;
2623
2624 case CMD_DEL_SVC_DOWNTIME:
2625 printf("This command is used to cancel active or pending scheduled downtime for the specified service.\n");
2626 break;
2627
2628 case CMD_ENABLE_FAILURE_PREDICTION:
2629 printf("This command is used to enable failure prediction for hosts and services on a program-wide basis. Individual hosts and services may have failure prediction disabled.\n");
2630 break;
2631
2632 case CMD_DISABLE_FAILURE_PREDICTION:
2633 printf("This command is used to disable failure prediction for hosts and services on a program-wide basis.\n");
2634 break;
2635
2636 case CMD_ENABLE_PERFORMANCE_DATA:
2637 printf("This command is used to enable the processing of performance data for hosts and services on a program-wide basis. Individual hosts and services may have performance data processing disabled.\n");
2638 break;
2639
2640 case CMD_DISABLE_PERFORMANCE_DATA:
2641 printf("This command is used to disable the processing of performance data for hosts and services on a program-wide basis.\n");
2642 break;
2643
2644 case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
2645 printf("This command is used to schedule downtime for all hosts in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n");
2646 printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n");
2647 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2648 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2649 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
2650 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n");
2651 break;
2652
2653 case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
2654 printf("This command is used to schedule downtime for all services in a particular hostgroup. During the specified downtime, Nagios will not send notifications out about the services.\n");
2655 printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n");
2656 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2657 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2658 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
2659 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n");
2660 printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the hostgroup, check the 'Schedule downtime for hosts too' option.\n");
2661 break;
2662
2663 case CMD_START_EXECUTING_HOST_CHECKS:
2664 printf("This command is used to enable active host checks on a program-wide basis.\n");
2665 break;
2666
2667 case CMD_STOP_EXECUTING_HOST_CHECKS:
2668 printf("This command is used to disable active host checks on a program-wide basis.\n");
2669 break;
2670
2671 case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
2672 printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n");
2673 break;
2674
2675 case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
2676 printf("This command is used to stop Nagios from obsessing over host checks.\n");
2677 break;
2678
2679 case CMD_ENABLE_PASSIVE_HOST_CHECKS:
2680 printf("This command is used to allow Nagios to accept passive host check results that it finds in the external command file for a particular host.\n");
2681 break;
2682
2683 case CMD_DISABLE_PASSIVE_HOST_CHECKS:
2684 printf("This command is used to stop Nagios from accepting passive host check results that it finds in the external command file for a particular host. All passive check results that are found for this host will be ignored.\n");
2685 break;
2686
2687 case CMD_START_OBSESSING_OVER_HOST_CHECKS:
2688 printf("This command is used to have Nagios start obsessing over host checks. Read the documentation on distributed monitoring for more information on this.\n");
2689 break;
2690
2691 case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
2692 printf("This command is used to stop Nagios from obsessing over host checks.\n");
2693 break;
2694
2695 case CMD_SCHEDULE_HOST_CHECK:
2696 printf("This command is used to schedule the next check of a particular host. Nagios will re-queue the host to be checked at the time you specify.\n");
2697 printf("If you select the <i>force check</i> option, Nagios will force a check of the host regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host.\n");
2698 break;
2699
2700 case CMD_START_OBSESSING_OVER_SVC:
2701 printf("This command is used to have Nagios start obsessing over a particular service.\n");
2702 break;
2703
2704 case CMD_STOP_OBSESSING_OVER_SVC:
2705 printf("This command is used to stop Nagios from obsessing over a particular service.\n");
2706 break;
2707
2708 case CMD_START_OBSESSING_OVER_HOST:
2709 printf("This command is used to have Nagios start obsessing over a particular host.\n");
2710 break;
2711
2712 case CMD_STOP_OBSESSING_OVER_HOST:
2713 printf("This command is used to stop Nagios from obsessing over a particular host.\n");
2714 break;
2715
2716 case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
2717 printf("This command is used to enable notifications for all services in the specified servicegroup. Notifications will only be sent out for the\n");
2718 printf("service state types you defined in your service definitions. This <i>does not</i> enable notifications for the hosts in this servicegroup unless you check the 'Enable for hosts too' option.\n");
2719 break;
2720
2721 case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
2722 printf("This command is used to prevent notifications from being sent out for all services in the specified servicegroup. You will have to re-enable notifications for\n");
2723 printf("all services in this servicegroup before any alerts can be sent out in the future. This <i>does not</i> prevent notifications from being sent out about the hosts in this servicegroup unless you check the 'Disable for hosts too' option.\n");
2724 break;
2725
2726 case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
2727 printf("This command is used to enable notifications for all hosts in the specified servicegroup. Notifications will only be sent out for the\n");
2728 printf("host state types you defined in your host definitions.\n");
2729 break;
2730
2731 case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
2732 printf("This command is used to prevent notifications from being sent out for all hosts in the specified servicegroup. You will have to re-enable notifications for\n");
2733 printf("all hosts in this servicegroup before any alerts can be sent out in the future.\n");
2734 break;
2735
2736 case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
2737 printf("This command is used to enable active checks of all services in the specified servicegroup. This <i>does not</i> enable active checks of the hosts in the servicegroup unless you check the 'Enable for hosts too' option.\n");
2738 break;
2739
2740 case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
2741 printf("This command is used to disable active checks of all services in the specified servicegroup. This <i>does not</i> disable checks of the hosts in the servicegroup unless you check the 'Disable for hosts too' option.\n");
2742 break;
2743
2744 case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
2745 printf("This command is used to schedule downtime for all hosts in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the hosts.\n");
2746 printf("When the scheduled downtime expires, Nagios will send out notifications for the hosts as it normally would. Scheduled downtimes are preserved\n");
2747 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2748 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2749 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a host goes down or becomes unreachable (sometime between the\n");
2750 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n");
2751 break;
2752
2753 case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
2754 printf("This command is used to schedule downtime for all services in a particular servicegroup. During the specified downtime, Nagios will not send notifications out about the services.\n");
2755 printf("When the scheduled downtime expires, Nagios will send out notifications for the services as it normally would. Scheduled downtimes are preserved\n");
2756 printf("across program shutdowns and restarts. Both the start and end times should be specified in the following format: <b>mm/dd/yyyy hh:mm:ss</b>.\n");
2757 printf("If you select the <i>fixed</i> option, the downtime will be in effect between the start and end times you specify. If you do not select the <i>fixed</i>\n");
2758 printf("option, Nagios will treat this as \"flexible\" downtime. Flexible downtime starts when a service enters a non-OK state (sometime between the\n");
2759 printf("start and end times you specified) and lasts as long as the duration of time you enter. The duration fields do not apply for fixed dowtime.\n");
2760 printf("Note that scheduling downtime for services does not automatically schedule downtime for the hosts those services are associated with. If you want to also schedule downtime for all hosts in the servicegroup, check the 'Schedule downtime for hosts too' option.\n");
2761 break;
2762
2763 case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
2764 case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
2765 printf("This command is used to send a custom notification about the specified %s. Useful in emergencies when you need to notify admins of an issue regarding a monitored system or service.\n", (cmd == CMD_SEND_CUSTOM_HOST_NOTIFICATION) ? "host" : "service");
2766 printf("Custom notifications normally follow the regular notification logic in Nagios. Selecting the <i>Forced</i> option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc. Selecting the <i>Broadcast</i> option causes the notification to be sent out to all normal (non-escalated) and escalated contacts. These options allow you to override the normal notification logic if you need to get an important message out.\n");
2767 break;
2768
2769 default:
2770 printf("Sorry, but no information is available for this command.");
2771 }
2772
2773 printf("</TD></TR>\n");
2774 printf("</TABLE>\n");
2775
2776 return;
2777 }
2778
2779
2780
2781 /* converts a time string to a UNIX timestamp, respecting the date_format option */
string_to_time(char * buffer,time_t * t)2782 int string_to_time(char *buffer, time_t *t) {
2783 struct tm lt;
2784 int ret = 0;
2785
2786
2787 /* Initialize some variables just in case they don't get parsed
2788 by the sscanf() call. A better solution is to also check the
2789 CGI input for validity, but this should suffice to prevent
2790 strange problems if the input is not valid.
2791 Jan 15 2003 Steve Bonds */
2792 lt.tm_mon = 0;
2793 lt.tm_mday = 1;
2794 lt.tm_year = 1900;
2795 lt.tm_hour = 0;
2796 lt.tm_min = 0;
2797 lt.tm_sec = 0;
2798 lt.tm_wday = 0;
2799 lt.tm_yday = 0;
2800
2801
2802 if(date_format == DATE_FORMAT_EURO)
2803 ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mday, <.tm_mon, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
2804 else if(date_format == DATE_FORMAT_ISO8601 || date_format == DATE_FORMAT_STRICT_ISO8601)
2805 ret = sscanf(buffer, "%04d-%02d-%02d%*[ T]%02d:%02d:%02d", <.tm_year, <.tm_mon, <.tm_mday, <.tm_hour, <.tm_min, <.tm_sec);
2806 else
2807 ret = sscanf(buffer, "%02d-%02d-%04d %02d:%02d:%02d", <.tm_mon, <.tm_mday, <.tm_year, <.tm_hour, <.tm_min, <.tm_sec);
2808
2809 if(ret != 6)
2810 return ERROR;
2811
2812 lt.tm_mon--;
2813 lt.tm_year -= 1900;
2814
2815 /* tell mktime() to try and compute DST automatically */
2816 lt.tm_isdst = -1;
2817
2818 *t = mktime(<);
2819
2820 return OK;
2821 }
2822