Icinga-core 1.4.0
next gen monitoring
cgi/cmd.c
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * CMD.C - Icinga Command CGI
00004  *
00005  * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00007  *
00008  * Last Modified: 08-08-2010
00009  *
00010  * License:
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License version 2 as
00014  * published by the Free Software Foundation.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024  *************************************************************************/
00025 
00031 #include "../include/config.h"
00032 #include "../include/common.h"
00033 #include "../include/objects.h"
00034 #include "../include/comments.h"
00035 #include "../include/downtime.h"
00036 
00037 #include "../include/cgiutils.h"
00038 #include "../include/cgiauth.h"
00039 #include "../include/getcgi.h"
00040 
00043 extern const char *extcmd_get_name(int id);
00044 
00045 extern char main_config_file[MAX_FILENAME_LENGTH];
00046 extern char url_html_path[MAX_FILENAME_LENGTH];
00047 extern char url_images_path[MAX_FILENAME_LENGTH];
00048 extern char command_file[MAX_FILENAME_LENGTH];
00049 extern char comment_file[MAX_FILENAME_LENGTH];
00050 
00051 extern int  check_external_commands;
00052 extern int  use_authentication;
00053 extern int  lock_author_names;
00054 extern int  persistent_ack_comments;
00055 extern int  log_external_commands_user;
00056 
00057 extern int  content_type;
00058 extern int  display_header;
00059 extern int  daemon_check;
00060 
00061 extern int enforce_comments_on_actions;
00062 extern int date_format;
00063 
00064 extern scheduled_downtime *scheduled_downtime_list;
00065 extern comment *comment_list;
00070 #define MAX_AUTHOR_LENGTH               64
00071 #define MAX_COMMENT_LENGTH              1024
00072 #define NUMBER_OF_STRUCTS               500             
00077 #define PRINT_COMMON_HEADER             1
00078 #define PRINT_AUTHOR                    2
00079 #define PRINT_STICKY_ACK                3
00080 #define PRINT_PERSISTENT                4
00081 #define PRINT_SEND_NOTFICATION          5
00082 #define PRINT_COMMENT_BOX               6
00083 #define PRINT_NOTIFICATION_DELAY        7
00084 #define PRINT_START_TIME                8
00085 #define PRINT_END_TIME                  9
00086 #define PRINT_CHECK_TIME                10
00087 #define PRINT_FORCE_CHECK               11
00088 #define PRINT_CHECK_OUTPUT_BOX          12
00089 #define PRINT_PERFORMANCE_DATA_BOX      13
00090 #define PRINT_FIXED_FLEXIBLE_TYPE       14
00091 #define PRINT_BROADCAST_NOTIFICATION    15
00092 #define PRINT_FORCE_NOTIFICATION        16
00093 
00097 #define PRINT_HOST_LIST                 17
00098 #define PRINT_SERVICE_LIST              18
00099 #define PRINT_COMMENT_LIST              19
00100 #define PRINT_DOWNTIME_LIST             20
00101 
00107 struct hostlist {
00108         char *host_name;
00109         char *description;
00110 };
00111 
00116 struct errorlist {
00117         char *message;
00118 };
00119 
00120 
00126 int show_all_hosts=TRUE;                        
00127 int show_all_hostgroups=TRUE;                   
00128 int show_all_servicegroups=TRUE;                
00129 int display_type=DISPLAY_HOSTS;                 
00134 char *host_name="";                             
00135 char *hostgroup_name="";                        
00136 char *servicegroup_name="";                     
00137 char *service_desc="";                          
00138 char *comment_author="";                        
00139 char *comment_data="";                          
00140 char *start_time_string="";                     
00141 char *end_time_string="";                       
00143 char help_text[MAX_INPUT_BUFFER]="";            
00144 char plugin_output[MAX_INPUT_BUFFER]="";        
00145 char performance_data[MAX_INPUT_BUFFER]="";     
00147 int notification_delay=0;                       
00148 int schedule_delay=0;                           
00150 int persistent_comment=FALSE;                   
00151 int sticky_ack=FALSE;                           
00152 int send_notification=FALSE;                    
00153 int force_check=FALSE;                          
00154 int plugin_state=STATE_OK;                      
00155 int affect_host_and_services=FALSE;             
00156 int propagate_to_children=FALSE;                
00157 int fixed=FALSE;                                
00158 unsigned long duration=0L;                      
00159 unsigned long triggered_by=0L;                  
00160 int child_options=0;                            
00161 int force_notification=0;                       
00162 int broadcast_notification=0;                   
00164 int command_type=CMD_NONE;                      
00165 int command_mode=CMDMODE_REQUEST;               
00167 time_t start_time=0L;                           
00168 time_t end_time=0L;                             
00170 int CGI_ID=CMD_CGI_ID;                          
00172 authdata current_authdata;                      
00175 struct hostlist commands[NUMBER_OF_STRUCTS];
00176 
00178 struct errorlist error[NUMBER_OF_STRUCTS];
00179 
00181 unsigned long multi_ids[NUMBER_OF_STRUCTS];
00182 
00184 short is_authorized[NUMBER_OF_STRUCTS];
00185 
00187 short submit_result[NUMBER_OF_STRUCTS];
00198 void request_command_data(int);
00199 
00206 void commit_command_data(int);
00207 
00217 int commit_command(int);
00218 
00228 int write_command_to_file(char *);
00229 
00235 void clean_comment_data(char *);
00236 
00244 void print_form_element(int,int);
00245 
00252 void print_object_list(int);
00253 
00259 void print_help_box(char *);
00260 
00266 void check_comment_sanity(int*);
00267 
00275 void check_time_sanity(int*);
00276 
00284 int process_cgivars(void);
00285 
00286 
00288 int main(void){
00289         int result=OK;
00290 
00291         /* get the arguments passed in the URL */
00292         process_cgivars();
00293 
00294         /* reset internal variables */
00295         reset_cgi_vars();
00296 
00297         /* read the CGI configuration file */
00298         result=read_cgi_config_file(get_cgi_config_location());
00299         if(result==ERROR){
00300                 document_header(CGI_ID,FALSE);
00301                 if(content_type==WML_CONTENT)
00302                         printf("<p>Error: Could not open CGI config file!</p>\n");
00303                 else
00304                         print_error(get_cgi_config_location(), ERROR_CGI_CFG_FILE);
00305                 document_footer(CGI_ID);
00306                 return ERROR;
00307         }
00308 
00309         /* read the main configuration file */
00310         result=read_main_config_file(main_config_file);
00311         if(result==ERROR){
00312                 document_header(CGI_ID,FALSE);
00313                 if(content_type==WML_CONTENT)
00314                         printf("<p>Error: Could not open main config file!</p>\n");
00315                 else
00316                         print_error(main_config_file, ERROR_CGI_MAIN_CFG);
00317                 document_footer(CGI_ID);
00318                 return ERROR;
00319         }
00320 
00321         /* This requires the date_format parameter in the main config file */
00322         if (strcmp(start_time_string,""))
00323                 string_to_time(start_time_string,&start_time);
00324 
00325         if (strcmp(end_time_string,""))
00326                 string_to_time(end_time_string,&end_time);
00327 
00328 
00329         /* read all object configuration data */
00330         result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA);
00331         if(result==ERROR){
00332                 document_header(CGI_ID,FALSE);
00333                 if(content_type==WML_CONTENT)
00334                         printf("<p>Error: Could not read object config data!</p>\n");
00335                 else
00336                         print_error(NULL, ERROR_CGI_OBJECT_DATA);
00337                 document_footer(CGI_ID);
00338                 return ERROR;
00339         }
00340 
00341         document_header(CGI_ID,TRUE);
00342 
00343         /* get authentication information */
00344         get_authentication_information(&current_authdata);
00345 
00346         if(display_header==TRUE){
00347 
00348                 /* Giving credits to stop.png image source */
00349                 printf("\n<!-- Image \"stop.png\" has been taken from \"http://fedoraproject.org/wiki/Template:Admon/caution\" -->\n\n");
00350 
00351                 /* begin top table */
00352                 printf("<table border=0 width=100%%>\n");
00353                 printf("<tr>\n");
00354 
00355                 /* left column of the first row */
00356                 printf("<td align=left valign=top width=33%%>\n");
00357                 display_info_table("External Command Interface",FALSE,&current_authdata, daemon_check);
00358                 printf("</td>\n");
00359 
00360                 /* center column of the first row */
00361                 printf("<td align=center valign=top width=33%%>\n");
00362                 printf("</td>\n");
00363 
00364                 /* right column of the first row */
00365                 printf("<td align=right valign=bottom width=33%%>\n");
00366 
00367                 /* display context-sensitive help */
00368                 if(command_mode==CMDMODE_COMMIT)
00369                         display_context_help(CONTEXTHELP_CMD_COMMIT);
00370                 else
00371                         display_context_help(CONTEXTHELP_CMD_INPUT);
00372 
00373                 printf("</td>\n");
00374 
00375                 /* end of top table */
00376                 printf("</tr>\n");
00377                 printf("</table>\n");
00378         }
00379 
00380         /* if no command was specified... */
00381         if(command_type==CMD_NONE){
00382                 print_generic_error_message("Error: No command was specified!",NULL,2);
00383         }
00384 
00385         /* if not authorized to perform commands*/
00386         else if (is_authorized_for_read_only(&current_authdata)==TRUE){
00387                 print_generic_error_message("Error: It appears as though you do not have permission to perform any commands!",NULL,1);
00388         }
00389 
00390         /* if this is the first request for a command, present option */
00391         else if(command_mode==CMDMODE_REQUEST)
00392                 request_command_data(command_type);
00393 
00394         /* the user wants to commit the command */
00395         else if(command_mode==CMDMODE_COMMIT)
00396                 commit_command_data(command_type);
00397 
00398         document_footer(CGI_ID);
00399 
00400         /* free allocated memory */
00401         free_memory();
00402         free_object_data();
00403 
00404         return OK;
00405 }
00406 
00407 int process_cgivars(void){
00408         char **variables;
00409         int error=FALSE;
00410         int x;
00411         int z = 0;
00412 
00413         variables=getcgivars();
00414 
00415         /* Process the variables */
00416         for(x=0;variables[x]!=NULL;x++){
00417 
00418                 /* do some basic length checking on the variable identifier to prevent buffer overflows */
00419                 if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){
00420                         x++;
00421                         continue;
00422                 }
00423 
00424                 /* we found the command type */
00425                 else if(!strcmp(variables[x],"cmd_typ")){
00426                         x++;
00427                         if(variables[x]==NULL){
00428                                 error=TRUE;
00429                                 break;
00430                         }
00431 
00432                         command_type=atoi(variables[x]);
00433                 }
00434 
00435                 /* we found the command mode */
00436                 else if(!strcmp(variables[x],"cmd_mod")){
00437                         x++;
00438                         if(variables[x]==NULL){
00439                                 error=TRUE;
00440                                 break;
00441                         }
00442 
00443                         command_mode=atoi(variables[x]);
00444                 }
00445 
00446                 /* we found a comment id or a downtime id*/
00447                 else if(!strcmp(variables[x],"com_id") || !strcmp(variables[x],"down_id")){
00448                         x++;
00449                         if(variables[x]==NULL){
00450                                 error=TRUE;
00451                                 break;
00452                         }
00453 
00454                         multi_ids[z]=strtoul(variables[x],NULL,10);
00455                         z++;
00456                 }
00457 
00458                 /* we found the notification delay */
00459                 else if(!strcmp(variables[x],"not_dly")){
00460                         x++;
00461                         if(variables[x]==NULL){
00462                                 error=TRUE;
00463                                 break;
00464                         }
00465 
00466                         notification_delay=atoi(variables[x]);
00467                 }
00468 
00469                 /* we found the schedule delay */
00470                 else if(!strcmp(variables[x],"sched_dly")){
00471                         x++;
00472                         if(variables[x]==NULL){
00473                                 error=TRUE;
00474                                 break;
00475                         }
00476 
00477                         schedule_delay=atoi(variables[x]);
00478                 }
00479 
00480                 /* we found the comment author */
00481                 else if(!strcmp(variables[x],"com_author")){
00482                         x++;
00483                         if(variables[x]==NULL){
00484                                 error=TRUE;
00485                                 break;
00486                         }
00487 
00488                         if((comment_author=(char *)strdup(variables[x]))==NULL)
00489                                 comment_author="";
00490                         strip_html_brackets(comment_author);
00491                 }
00492 
00493                 /* we found the comment data */
00494                 else if(!strcmp(variables[x],"com_data")){
00495                         x++;
00496                         if(variables[x]==NULL){
00497                                 error=TRUE;
00498                                 break;
00499                         }
00500 
00501                         if((comment_data=(char *)strdup(variables[x]))==NULL)
00502                                 comment_data="";
00503                         strip_html_brackets(comment_data);
00504                 }
00505 
00506                 /* we found the host name */
00507                 else if(!strcmp(variables[x],"host")){
00508                         x++;
00509                         if(variables[x]==NULL){
00510                                 error=TRUE;
00511                                 break;
00512                         }
00513 
00514                         if((host_name=(char *)strdup(variables[x]))==NULL)
00515                                 host_name="";
00516                         else {
00517                                 strip_html_brackets(host_name);
00518 
00519                                 /* Store hostname in struct */
00520                                 commands[x].host_name = host_name;
00521                         }
00522                 }
00523 
00524                 /* we found the hostgroup name */
00525                 else if(!strcmp(variables[x],"hostgroup")){
00526                         x++;
00527                         if(variables[x]==NULL){
00528                                 error=TRUE;
00529                                 break;
00530                         }
00531 
00532                         if((hostgroup_name=(char *)strdup(variables[x]))==NULL)
00533                                 hostgroup_name="";
00534                         strip_html_brackets(hostgroup_name);
00535                 }
00536 
00537                 /* we found the service name */
00538                 else if(!strcmp(variables[x],"service")){
00539                         x++;
00540                         if(variables[x]==NULL){
00541                                 error=TRUE;
00542                                 break;
00543                         }
00544 
00545                         if((service_desc=(char *)strdup(variables[x]))==NULL)
00546                                 service_desc="";
00547                         else {
00548                                 strip_html_brackets(service_desc);
00549 
00550                                 /* Store service description in struct */
00551                                 commands[(x-2)].description = service_desc;
00552                         }
00553                 }
00554 
00555                 /* we found the servicegroup name */
00556                 else if(!strcmp(variables[x],"servicegroup")){
00557                         x++;
00558                         if(variables[x]==NULL){
00559                                 error=TRUE;
00560                                 break;
00561                         }
00562 
00563                         if((servicegroup_name=(char *)strdup(variables[x]))==NULL)
00564                                 servicegroup_name="";
00565                         strip_html_brackets(servicegroup_name);
00566                 }
00567 
00568                 /* we got the persistence option for a comment */
00569                 else if(!strcmp(variables[x],"persistent"))
00570                         persistent_comment=TRUE;
00571 
00572                 /* we got the notification option for an acknowledgement */
00573                 else if(!strcmp(variables[x],"send_notification"))
00574                         send_notification=TRUE;
00575 
00576                 /* we got the acknowledgement type */
00577                 else if(!strcmp(variables[x],"sticky_ack"))
00578                         sticky_ack=TRUE;
00579 
00580                 /* we got the service check force option */
00581                 else if(!strcmp(variables[x],"force_check"))
00582                         force_check=TRUE;
00583 
00584                 /* we got the option to affect host and all its services */
00585                 else if(!strcmp(variables[x],"ahas"))
00586                         affect_host_and_services=TRUE;
00587 
00588                 /* we got the option to propagate to child hosts */
00589                 else if(!strcmp(variables[x],"ptc"))
00590                         propagate_to_children=TRUE;
00591 
00592                 /* we got the option for fixed downtime */
00593                 else if(!strcmp(variables[x],"fixed")){
00594                         x++;
00595                         if(variables[x]==NULL){
00596                                 error=TRUE;
00597                                 break;
00598                         }
00599 
00600                         fixed=(atoi(variables[x])>0)?TRUE:FALSE;
00601                 }
00602 
00603                 /* we got the triggered by downtime option */
00604                 else if(!strcmp(variables[x],"trigger")){
00605                         x++;
00606                         if(variables[x]==NULL){
00607                                 error=TRUE;
00608                                 break;
00609                         }
00610 
00611                         triggered_by=strtoul(variables[x],NULL,10);
00612                 }
00613 
00614                 /* we got the child options */
00615                 else if(!strcmp(variables[x],"childoptions")){
00616                         x++;
00617                         if(variables[x]==NULL){
00618                                 error=TRUE;
00619                                 break;
00620                         }
00621 
00622                         child_options=atoi(variables[x]);
00623                 }
00624 
00625                 /* we found the plugin output */
00626                 else if(!strcmp(variables[x],"plugin_output")){
00627                         x++;
00628                         if(variables[x]==NULL){
00629                                 error=TRUE;
00630                                 break;
00631                         }
00632 
00633                         /* protect against buffer overflows */
00634                         if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){
00635                                 error=TRUE;
00636                                 break;
00637                         } else
00638                                 strcpy(plugin_output,variables[x]);
00639                 }
00640 
00641                 /* we found the performance data */
00642                 else if(!strcmp(variables[x],"performance_data")){
00643                         x++;
00644                         if(variables[x]==NULL){
00645                                 error=TRUE;
00646                                 break;
00647                         }
00648 
00649                         /* protect against buffer overflows */
00650                         if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){
00651                                 error=TRUE;
00652                                 break;
00653                         } else
00654                                 strcpy(performance_data,variables[x]);
00655                 }
00656 
00657                 /* we found the plugin state */
00658                 else if(!strcmp(variables[x],"plugin_state")){
00659                         x++;
00660                         if(variables[x]==NULL){
00661                                 error=TRUE;
00662                                 break;
00663                         }
00664 
00665                         plugin_state=atoi(variables[x]);
00666                 }
00667 
00668                 /* we found the hour duration */
00669                 else if(!strcmp(variables[x],"hours")){
00670                         x++;
00671                         if(variables[x]==NULL){
00672                                 error=TRUE;
00673                                 break;
00674                         }
00675 
00676                         if(atoi(variables[x])<0){
00677                                 error=TRUE;
00678                                 break;
00679                         }
00680                         duration+=(unsigned long)(atoi(variables[x])*3600);
00681                 }
00682 
00683                 /* we found the minute duration */
00684                 else if(!strcmp(variables[x],"minutes")){
00685                         x++;
00686                         if(variables[x]==NULL){
00687                                 error=TRUE;
00688                                 break;
00689                         }
00690 
00691                         if(atoi(variables[x])<0){
00692                                 error=TRUE;
00693                                 break;
00694                         }
00695                         duration+=(unsigned long)(atoi(variables[x])*60);
00696                 }
00697 
00698                 /* we found the start time */
00699                 else if(!strcmp(variables[x],"start_time")){
00700                         x++;
00701                         if(variables[x]==NULL){
00702                                 error=TRUE;
00703                                 break;
00704                         }
00705 
00706                         start_time_string=(char *)malloc(strlen(variables[x])+1);
00707                         if(start_time_string==NULL)
00708                                 start_time_string="";
00709                         else
00710                                 strcpy(start_time_string,variables[x]);
00711                 }
00712 
00713                 /* we found the end time */
00714                 else if(!strcmp(variables[x],"end_time")){
00715                         x++;
00716                         if(variables[x]==NULL){
00717                                 error=TRUE;
00718                                 break;
00719                         }
00720 
00721                         end_time_string=(char *)malloc(strlen(variables[x])+1);
00722                         if(end_time_string==NULL)
00723                                 end_time_string="";
00724                         else
00725                                 strcpy(end_time_string,variables[x]);
00726                 }
00727 
00728                 /* we found the content type argument */
00729                 else if(!strcmp(variables[x],"content")){
00730                         x++;
00731                         if(variables[x]==NULL){
00732                                 error=TRUE;
00733                                 break;
00734                         }
00735                         if(!strcmp(variables[x],"wml")){
00736                                 content_type=WML_CONTENT;
00737                                 display_header=FALSE;
00738                         } else
00739                                 content_type=HTML_CONTENT;
00740                 }
00741 
00742                 /* we found the forced notification option */
00743                 else if(!strcmp(variables[x],"force_notification"))
00744                         force_notification=NOTIFICATION_OPTION_FORCED;
00745 
00746                 /* we found the broadcast notification option */
00747                 else if(!strcmp(variables[x],"broadcast_notification"))
00748                         broadcast_notification=NOTIFICATION_OPTION_BROADCAST;
00749 
00750                 /* we got the persistence option for a comment */
00751                 else if(!strcmp(variables[x],"nodaemoncheck"))
00752                         daemon_check = FALSE;
00753 
00754                 }
00755 
00756         /* free memory allocated to the CGI variables */
00757         free_cgivars(variables);
00758 
00759         return error;
00760 }
00761 
00762 void print_object_list(int list_type) {
00763         int x = 0;
00764         int row_color = 0;
00765 
00766         printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
00767         printf("<tr CLASS=\"sectionHeader\"><td COLSPAN=\"2\" >Affected Objects</td></tr>\n");
00768 
00769         if(list_type==PRINT_SERVICE_LIST)
00770                 printf("<tr class=\"objectDescription\"><td width=\"50%%\">Host</td><td width=\"50%%\">Service</td></tr>\n");
00771         else
00772                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
00773 
00774         for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
00775 
00776                 if (list_type==PRINT_HOST_LIST || list_type==PRINT_SERVICE_LIST ){
00777                         if (commands[x].host_name == NULL)
00778                                 continue;
00779                 } else {
00780                         if (multi_ids[x] == FALSE)
00781                                 continue;
00782                 }
00783 
00784                 row_color = (row_color==0)?1:0;
00785 
00786                 printf("<tr class=\"status%s\"><td width=\"50%%\"",(row_color==0)?"Even":"Odd ");
00787                 if (list_type==PRINT_SERVICE_LIST){
00788                         /* if hostname is empty print inputbox instead */
00789                         if(!strcmp(commands[x].host_name,""))
00790                                 printf("><INPUT TYPE='TEXT' NAME='host' SIZE=30></td>");
00791                         else
00792                                 printf("><INPUT TYPE='HIDDEN' NAME='host' VALUE='%s'>%s</td>",escape_string(commands[x].host_name),escape_string(commands[x].host_name));
00793                         /* if service description is empty print inputbox instead */
00794                         if(!strcmp(commands[x].description,""))
00795                                 printf("<td><INPUT TYPE='TEXT' NAME='service' SIZE=30></td></tr>\n");
00796                         else
00797                                 printf("<td><INPUT TYPE='HIDDEN' NAME='service' VALUE='%s'>%s</td></tr>\n",escape_string(commands[x].description),escape_string(commands[x].description));
00798                 } else if (list_type==PRINT_HOST_LIST){
00799                         /* if hostname is empty print inputbox instead */
00800                         if(!strcmp(commands[x].host_name,""))
00801                                 printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='TEXT' NAME='host' SIZE=30></td></tr>\n");
00802                         else
00803                                 printf(" style=\"font-weight:bold;\">Host:</td><td><INPUT TYPE='HIDDEN' NAME='host' VALUE='%s'>%s</td></tr>\n",escape_string(commands[x].host_name),escape_string(commands[x].host_name));
00804                 } else if (list_type==PRINT_COMMENT_LIST){
00805                         printf(" style=\"font-weight:bold;\">Comment ID:</td><td><INPUT TYPE='HIDDEN' NAME='com_id' VALUE='%lu'>%lu</td></tr>\n",multi_ids[x],multi_ids[x]);
00806                 } else if (list_type==PRINT_DOWNTIME_LIST){
00807                         printf(" style=\"font-weight:bold;\">Scheduled Downtime ID:</td><td><INPUT TYPE='HIDDEN' NAME='down_id' VALUE='%lu'>%lu</td></tr>\n",multi_ids[x],multi_ids[x]);
00808                 }
00809         }
00810 
00811         return;
00812 }
00813 
00814 void print_help_box(char *content) {
00815 
00816         printf("<img src='%s%s' onMouseOver=\"return tooltip('<table border=0 width=100%% height=100%%>",url_images_path,CONTEXT_HELP_ICON1);
00817         printf("<tr><td>%s</td></tr>",content);
00818         printf("</table>', '&nbsp;&nbsp;&nbsp;Help', 'border:1, width:500, xoffset:-250, yoffset:25, bordercolor:#333399, title_padding:2px, titletextcolor:#FFFFFF, backcolor:#CCCCFF');\" onMouseOut=\"return hideTip()\"");
00819         printf(" BORDER=0>");
00820         return;
00821 }
00822 
00823 void print_form_element(int element,int cmd) {
00824         time_t t;
00825         char buffer[MAX_INPUT_BUFFER];
00826 
00827         switch(element) {
00828 
00829         case PRINT_COMMON_HEADER:
00830                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
00831                 printf("<tr><td COLSPAN=\"2\" CLASS='sectionHeader'>Common Data</td></tr>\n");
00832                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
00833                 break;
00834 
00835         case PRINT_AUTHOR:
00836                 printf("<tr><td class=\"objectDescription descriptionleft\">Author (Your Name):</td><td align=\"left\">");
00837                 if (lock_author_names==TRUE)
00838                         printf("<INPUT TYPE='HIDDEN' NAME='com_author' VALUE='%s'>%s</td></tr>\n",escape_string(comment_author),escape_string(comment_author));
00839                 else
00840                         printf("<INPUT TYPE='INPUT' NAME='com_author' VALUE='%s'></td></tr>\n",escape_string(comment_author));
00841                 break;
00842 
00843         case PRINT_COMMENT_BOX:
00844 
00845                 strcpy(help_text,"If you work with other administrators, you may find it useful to share information about a host/service "
00846                                  "that is having problems if more than one of you may be working on it. "
00847                                  "Make sure to enter a brief description of what you are doing.");
00848 
00849                 printf("<tr><td class=\"objectDescription descriptionleft\">Comment:");
00850                 print_help_box(help_text);
00851                 printf("</td><td align=\"left\">");
00852                 printf("<TEXTAREA ID=\"com_data\" NAME='com_data' COLS=25 ROWS=2 onkeyup=\"check_input();\">%s</TEXTAREA>",escape_string(comment_data));
00853                 printf("<BR><DIV ID='com_data_error' class=\"inputError\" style=\"display:none;\">Comment data can't be send empty</DIV>");
00854                 printf("</td></tr>\n");
00855                 break;
00856 
00857         case PRINT_CHECK_OUTPUT_BOX:
00858 
00859                 snprintf(help_text,sizeof(help_text),"Fill in the exact output string which sould be sent to %s",PROGRAM_NAME);
00860                 help_text[sizeof(help_text)-1]='\x0';
00861 
00862                 printf("<tr><td class=\"objectDescription descriptionleft\">Check Output:");
00863                 print_help_box(help_text);
00864                 printf("</td><td align=\"left\">");
00865                 printf("<TEXTAREA ID=\"plugin_output\" NAME='plugin_output' COLS=25 ROWS=2  onkeyup=\"check_input();\"></TEXTAREA>");
00866                 printf("<BR><DIV ID='plugin_output_error' class=\"inputError\" style=\"display:none;\">Output string can't be send empty</DIV>");
00867                 printf("</td></tr>\n");
00868                 break;
00869 
00870         case PRINT_PERFORMANCE_DATA_BOX:
00871 
00872                 snprintf(help_text,sizeof(help_text),"Fill in the exact performance data string which sould be sent to %s",PROGRAM_NAME);
00873                 help_text[sizeof(help_text)-1]='\x0';
00874 
00875                 printf("<tr><td class=\"objectDescription descriptionleft\">Performance Data:");
00876                 print_help_box(help_text);
00877                 printf("</td><td align=\"left\">");
00878                 printf("<TEXTAREA NAME='performance_data' COLS=25 ROWS=2></TEXTAREA></td></tr>\n");
00879                 break;
00880 
00881         case PRINT_STICKY_ACK:
00882 
00883                 strcpy(help_text,"If you want acknowledgement to disable notifications until the host/service recovers, check this option.");
00884 
00885                 printf("<tr><td class=\"objectDescription descriptionleft\">Sticky Acknowledgement:");
00886                 print_help_box(help_text);
00887                 printf("</td><td align=\"left\">");
00888                 printf("<INPUT TYPE='checkbox' NAME='sticky_ack' CHECKED></td></tr>\n");
00889                 break;
00890 
00891         case PRINT_SEND_NOTFICATION:
00892 
00893                 strcpy(help_text,"If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck this option.");
00894 
00895                 printf("<tr><td class=\"objectDescription descriptionleft\">Send Notification:");
00896                 print_help_box(help_text);
00897                 printf("</td><td align=\"left\">");
00898                 printf("<INPUT TYPE='checkbox' NAME='send_notification' CHECKED></td></tr>\n");
00899                 break;
00900 
00901         case PRINT_PERSISTENT:
00902 
00903                 if (cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM)
00904                         strcpy(help_text,"If you would like the comment to remain once the acknowledgement is removed, check this checkbox.");
00905                 else {
00906                         snprintf(help_text,sizeof(help_text),"If you uncheck this option, the comment will automatically be deleted the next time %s is restarted.",PROGRAM_NAME);
00907                         help_text[sizeof(help_text)-1]='\x0';
00908                 }
00909                 printf("<tr><td class=\"objectDescription descriptionleft\">Persistent%s:",(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM)?" Comment":"");
00910                 print_help_box(help_text);
00911                 printf("</td><td align=\"left\">");
00912                 printf("<INPUT TYPE='checkbox' NAME='persistent' %s></td></tr>\n",( persistent_ack_comments==TRUE || cmd==CMD_ADD_HOST_COMMENT || cmd==CMD_ADD_SVC_COMMENT )?"CHECKED":"");
00913                 break;
00914 
00915         case PRINT_NOTIFICATION_DELAY:
00916 
00917                 strcpy(help_text,"The notification delay will be disregarded if the host/service changes state before the next notification is scheduled to be sent out.");
00918 
00919                 printf("<tr><td class=\"objectDescription descriptionleft\">Notification Delay (minutes from now):");
00920                 print_help_box(help_text);
00921                 printf("</td><td align=\"left\">");
00922                 printf("<INPUT TYPE='TEXT' ID='not_dly' NAME='not_dly' VALUE='%d' SIZE=\"4\">",notification_delay);
00923                 printf("<BR><DIV ID='not_dly_error' class=\"inputError\" style=\"display:none;\">Notification delay can't be zero</DIV>");
00924                 printf("</td></tr>\n");
00925                 break;
00926 
00927         case PRINT_START_TIME:
00928         case PRINT_END_TIME:
00929         case PRINT_CHECK_TIME:
00930                 time(&t);
00931                 if (element == PRINT_END_TIME )
00932                         t+=(unsigned long)7200;
00933                 get_time_string(&t,buffer,sizeof(buffer)-1,SHORT_DATE_TIME);
00934                 printf("<tr><td class=\"objectDescription descriptionleft\">");
00935                 if (element == PRINT_START_TIME ){
00936                         strcpy(help_text,"Set the start date/time for the downtime.");
00937                         printf("Start Time:");
00938                 }else if (element == PRINT_END_TIME ){
00939                         strcpy(help_text,"Set the end date/time for the downtime.");
00940                         printf("End Time:");
00941                 }else{
00942                         strcpy(help_text,"Set the date/time when this check should be schedule to.");
00943                         printf("Check Time:");
00944                 }
00945                 print_help_box(help_text);
00946                 printf("</td><td align=\"left\"><INPUT TYPE='TEXT' NAME='%s_time' VALUE='%s' SIZE=\"25\"></td></tr>\n",(element == PRINT_END_TIME )?"end":"start",buffer);
00947                 break;
00948 
00949         case PRINT_FIXED_FLEXIBLE_TYPE:
00950 
00951                 snprintf(help_text,sizeof(help_text),"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> "
00952                                  "option, %s will treat this as <i>flexible</i> downtime. Flexible downtime starts when the host goes down or becomes unreachable / service becomes critical (sometime between the "
00953                                  "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.",PROGRAM_NAME);
00954                 help_text[sizeof(help_text)-1]='\x0';
00955 
00956                 printf("<tr><td class=\"objectDescription descriptionleft\">Type:");
00957                 print_help_box(help_text);
00958                 printf("</td><td align=\"left\">\n");
00959 
00960                 printf("\t<SELECT ID=\"flexible_selection\" NAME='fixed' onChange=\"if (document.getElementById('flexible_selection').selectedIndex == 0) document.getElementById('fd_row').style.display = 'none'; else document.getElementById('fd_row').style.display = '';\">\n");
00961                 printf("\t\t<OPTION VALUE=1\">Fixed</OPTION>\n");
00962                 printf("\t\t<OPTION VALUE=0\">Flexible</OPTION>\n");
00963                 printf("\t</SELECT>\n");
00964 
00965                 snprintf(help_text,sizeof(help_text),"Enter here the duration of the downtime. %s will automatically delete the downtime after this time expired.",PROGRAM_NAME);
00966                 help_text[sizeof(help_text)-1]='\x0';
00967 
00968                 printf("<tr id=\"fd_row\" style=\"display:none;\"><td class=\"objectDescription descriptionleft\">Flexible Duration:");
00969                 print_help_box(help_text);
00970                 printf("</td><td align=\"left\">\n");
00971                 printf("\t<table border=0  cellspacing=0 cellpadding=0>\n");
00972                 printf("\t\t<tr>\n");
00973                 printf("\t\t\t<td><INPUT TYPE='TEXT' NAME='hours' VALUE='2' SIZE=2 MAXLENGTH=2></td>\n");
00974                 printf("\t\t\t<td width=\"50\">&nbsp;Hours</td>\n");
00975                 printf("\t\t\t<td><INPUT TYPE='TEXT' NAME='minutes' VALUE='0' SIZE=2 MAXLENGTH=2></td>\n");
00976                 printf("\t\t\t<td width=\"50\">&nbsp;Minutes</td>\n");
00977                 printf("\t\t</tr>\n");
00978                 printf("\t</table>\n");
00979                 printf("</td></tr>\n");
00980                 break;
00981 
00982         case PRINT_FORCE_CHECK:
00983 
00984                 snprintf(help_text,sizeof(help_text),"If you select this option, %s will force a check of the host/service regardless of both what time the scheduled check occurs and whether or not checks are enabled for the host/service.", PROGRAM_NAME);
00985                 help_text[sizeof(help_text)-1]='\x0';
00986 
00987                 printf("<tr><td class=\"objectDescription descriptionleft\">Force Check:");
00988                 print_help_box(help_text);
00989                 printf("</td><td align=\"left\">");
00990                 printf("<INPUT TYPE='checkbox' NAME='force_check' %s></td></tr>\n",(force_check==TRUE)?"CHECKED":"");
00991                 break;
00992 
00993         case PRINT_BROADCAST_NOTIFICATION:
00994 
00995                 strcpy(help_text,"Selecting this 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.");
00996 
00997                 printf("<tr><td class=\"objectDescription descriptionleft\">Broadcast:");
00998                 print_help_box(help_text);
00999                 printf("</td><td align=\"left\">");
01000                 printf("<INPUT TYPE='checkbox' NAME='broadcast_notification'></td></tr>\n");
01001                 break;
01002 
01003         case PRINT_FORCE_NOTIFICATION:
01004 
01005                 snprintf(help_text,sizeof(help_text),"Custom notifications normally follow the regular notification logic in %s.  Selecting this option will force the notification to be sent out, regardless of the time restrictions, whether or not notifications are enabled, etc.", PROGRAM_NAME);
01006                 help_text[sizeof(help_text)-1]='\x0';
01007 
01008                 printf("<tr><td class=\"objectDescription descriptionleft\">Forced:");
01009                 print_help_box(help_text);
01010                 printf("</td><td align=\"left\">");
01011                 printf("<INPUT TYPE='checkbox' NAME='force_notification'></td></tr>\n");
01012                 break;
01013 
01014         default:
01015                 break;
01016         }
01017 
01018         return;
01019 }
01020 
01021 void request_command_data(int cmd){
01022         char start_time[MAX_DATETIME_LENGTH];
01023         contact *temp_contact;
01024         scheduled_downtime *temp_downtime;
01025         host *temp_host=NULL;
01026         char action[MAX_INPUT_BUFFER];
01027         int found_trigger_objects=FALSE;
01028 
01029         /* get default name to use for comment author */
01030         temp_contact=find_contact(current_authdata.username);
01031         if(temp_contact!=NULL && temp_contact->alias!=NULL)
01032                 comment_author=temp_contact->alias;
01033         else
01034                 comment_author=current_authdata.username;
01035 
01036         printf("<BR>");
01037 
01038         switch(cmd){
01039 
01040         case CMD_ADD_HOST_COMMENT:
01041         case CMD_ADD_SVC_COMMENT:
01042                 snprintf(action,sizeof(action),"Add %s comments",(cmd==CMD_ADD_HOST_COMMENT)?"host":"service");
01043                 break;
01044 
01045         case CMD_DEL_HOST_COMMENT:
01046         case CMD_DEL_SVC_COMMENT:
01047                 snprintf(action,sizeof(action),"Delete %s comments",(cmd==CMD_DEL_HOST_COMMENT)?"host":"service");
01048                 break;
01049 
01050         case CMD_DELAY_HOST_NOTIFICATION:
01051         case CMD_DELAY_SVC_NOTIFICATION:
01052                 snprintf(help_text,sizeof(help_text),"This command is used to delay the next problem notification that is sent out for specified %s. The notification delay will be disregarded if "
01053                         "the %s changes state before the next notification is scheduled to be sent out.  This command has no effect if the %s are currently %s.",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"hosts":"services",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"hosts":"services",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"hosts":"services",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"UP":"in an OK state");
01054                 snprintf(action,sizeof(action),"Delay a %s notification",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"host":"service");
01055                 break;
01056 
01057         case CMD_SCHEDULE_HOST_CHECK:
01058         case CMD_SCHEDULE_SVC_CHECK:
01059                 snprintf(help_text,sizeof(help_text),"This command is used to schedule the next check of these %s. %s will re-queue the %s to be checked at the time you specify.",(cmd==CMD_SCHEDULE_HOST_CHECK)?"hosts":"services",PROGRAM_NAME,(cmd==CMD_SCHEDULE_HOST_CHECK)?"host":"service");
01060                 snprintf(action,sizeof(action),"Schedule %s checks",(cmd==CMD_SCHEDULE_HOST_CHECK)?"host":"service");
01061                 break;
01062 
01063         case CMD_ENABLE_SVC_CHECK:
01064         case CMD_DISABLE_SVC_CHECK:
01065                 snprintf(action,sizeof(action),"%s active service checks on a program-wide basis",(cmd==CMD_ENABLE_SVC_CHECK)?"Enable":"Disable");
01066                 break;
01067 
01068         case CMD_ENABLE_NOTIFICATIONS:
01069         case CMD_DISABLE_NOTIFICATIONS:
01070                 snprintf(help_text,sizeof(help_text),"This command is used to %s host and service notifications on a program-wide basis",(cmd==CMD_ENABLE_NOTIFICATIONS)?"enable":"disable");
01071                 snprintf(action,sizeof(action),"%s notifications on a program-wide basis",(cmd==CMD_ENABLE_NOTIFICATIONS)?"Enable":"Disable");
01072                 break;
01073 
01074         case CMD_SHUTDOWN_PROCESS:
01075         case CMD_RESTART_PROCESS:
01076                 snprintf(action,sizeof(action),"%s the %s process",(cmd==CMD_SHUTDOWN_PROCESS)?"Shutdown":"Restart", PROGRAM_NAME);
01077                 break;
01078 
01079         case CMD_ENABLE_HOST_SVC_CHECKS:
01080         case CMD_DISABLE_HOST_SVC_CHECKS:
01081                 if (cmd==CMD_ENABLE_HOST_SVC_CHECKS)
01082                         snprintf(help_text,sizeof(help_text),"This command is used to enable active checks of all services associated with the specified host");
01083                 else {
01084                         snprintf(help_text,sizeof(help_text),"This command is used to disable active checks of all services associated with the specified host. "
01085                                 "When a service is disabled %s will not monitor the service. Doing this will prevent any notifications being sent out for "
01086                                 "the specified service while it is disabled. In order to have %s check the service in the future you will have to re-enable the service. "
01087                                 "Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with.",PROGRAM_NAME,PROGRAM_NAME);
01088                 }
01089                 snprintf(action,sizeof(action),"%s active checks of all services on these hosts",(cmd==CMD_ENABLE_HOST_SVC_CHECKS)?"Enable":"Disable");
01090                 break;
01091 
01092         case CMD_SCHEDULE_HOST_SVC_CHECKS:
01093                 snprintf(action,sizeof(action),"Schedule a check of all services for these hosts");
01094                 break;
01095 
01096         case CMD_DEL_ALL_HOST_COMMENTS:
01097         case CMD_DEL_ALL_SVC_COMMENTS:
01098                 snprintf(action,sizeof(action),"Delete all comments for these %s",(cmd==CMD_DEL_ALL_HOST_COMMENTS)?"hosts":"services");
01099                 break;
01100 
01101         case CMD_ENABLE_SVC_NOTIFICATIONS:
01102         case CMD_DISABLE_SVC_NOTIFICATIONS:
01103                 snprintf(action,sizeof(action),"%s notifications for these services",(cmd==CMD_ENABLE_SVC_NOTIFICATIONS)?"Enable":"Disable");
01104                 break;
01105 
01106         case CMD_ENABLE_HOST_NOTIFICATIONS:
01107         case CMD_DISABLE_HOST_NOTIFICATIONS:
01108                 snprintf(action,sizeof(action),"%s notifications for these hosts",(cmd==CMD_ENABLE_HOST_NOTIFICATIONS)?"Enable":"Disable");
01109                 break;
01110 
01111         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01112         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01113                 snprintf(help_text,sizeof(help_text),"This command is used to %s notifications for all hosts and services that lie <i>beyond</i> the specified host (from the view of %s).",(cmd==CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST)?"enable":"disable",PROGRAM_NAME);
01114                 snprintf(action,sizeof(action),"%s notifications for all hosts and services beyond these hosts",(cmd==CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST)?"Enable":"Disable");
01115                 break;
01116 
01117         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
01118         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
01119                 snprintf(action,sizeof(action),"%s notifications for all services on these hosts",(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"Enable":"Disable");
01120                 break;
01121 
01122         case CMD_ACKNOWLEDGE_HOST_PROBLEM:
01123         case CMD_ACKNOWLEDGE_SVC_PROBLEM:
01124                 snprintf(action,sizeof(action),"Acknowledge %s problems",(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM)?"host":"service");
01125                 break;
01126 
01127         case CMD_START_EXECUTING_HOST_CHECKS:
01128         case CMD_STOP_EXECUTING_HOST_CHECKS:
01129                 snprintf(action,sizeof(action),"%s executing host checks on a program-wide basis",(cmd==CMD_START_EXECUTING_HOST_CHECKS)?"Start":"Stop");
01130                 break;
01131 
01132         case CMD_START_EXECUTING_SVC_CHECKS:
01133         case CMD_STOP_EXECUTING_SVC_CHECKS:
01134                 if (cmd==CMD_START_EXECUTING_SVC_CHECKS)
01135                         snprintf(help_text,sizeof(help_text),"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.");
01136                 else
01137                         snprintf(help_text,sizeof(help_text),"This command is used to temporarily stop %s 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). "
01138                                 "Service checks will not be executed again until you issue a command to resume service check execution.", PROGRAM_NAME);
01139                 snprintf(action,sizeof(action),"%s executing active service checks",(cmd==CMD_START_EXECUTING_SVC_CHECKS)?"Start":"Stop");
01140                 break;
01141 
01142         case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
01143         case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
01144                 snprintf(help_text,sizeof(help_text),"This command is used to make %s %s accepting passive service check results that it finds in the external command file.", PROGRAM_NAME,(cmd==CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS)?"start":"stop");
01145                 snprintf(action,sizeof(action),"%s accepting passive service checks on a program-wide basis",(cmd==CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS)?"Start":"Stop");
01146                 break;
01147 
01148         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
01149         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
01150                 if (cmd==CMD_ENABLE_PASSIVE_SVC_CHECKS)
01151                         snprintf(help_text,sizeof(help_text),"This command is used to allow %s to accept passive service check results that it finds in the external command file for this particular service.", PROGRAM_NAME);
01152                 else
01153                         snprintf(help_text,sizeof(help_text),"This command is used to stop %s 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.", PROGRAM_NAME);
01154                 snprintf(action,sizeof(action),"%s accepting passive service checks for these services",(cmd==CMD_ENABLE_PASSIVE_SVC_CHECKS)?"Start":"Stop");
01155                 break;
01156 
01157         case CMD_ENABLE_EVENT_HANDLERS:
01158         case CMD_DISABLE_EVENT_HANDLERS:
01159                 if (cmd==CMD_ENABLE_EVENT_HANDLERS)
01160                         snprintf(help_text,sizeof(help_text),"This command is used to allow %s to run host and service event handlers.", PROGRAM_NAME);
01161                 else
01162                         snprintf(help_text,sizeof(help_text),"This command is used to temporarily prevent %s from running any host or service event handlers.", PROGRAM_NAME);
01163                 snprintf(action,sizeof(action),"%s event handlers on a program-wide basis",(cmd==CMD_ENABLE_EVENT_HANDLERS)?"Enable":"Disable");
01164                 break;
01165 
01166         case CMD_ENABLE_HOST_EVENT_HANDLER:
01167         case CMD_DISABLE_HOST_EVENT_HANDLER:
01168                 snprintf(help_text,sizeof(help_text),"This command is used to %s the event handler for the selected hosts",(cmd==CMD_ENABLE_HOST_EVENT_HANDLER)?"enable":"disable");
01169                 snprintf(action,sizeof(action),"%s the event handler for these hosts",(cmd==CMD_ENABLE_HOST_EVENT_HANDLER)?"Enable":"Disable");
01170                 break;
01171 
01172         case CMD_ENABLE_SVC_EVENT_HANDLER:
01173         case CMD_DISABLE_SVC_EVENT_HANDLER:
01174                 snprintf(help_text,sizeof(help_text),"This command is used to %s the event handler for the selected services",(cmd==CMD_ENABLE_SVC_EVENT_HANDLER)?"enable":"disable");
01175                 snprintf(action,sizeof(action),"%s the event handler for these services",(cmd==CMD_ENABLE_SVC_EVENT_HANDLER)?"Enable":"Disable");
01176                 break;
01177 
01178         case CMD_ENABLE_HOST_CHECK:
01179         case CMD_DISABLE_HOST_CHECK:
01180                 if (cmd==CMD_DISABLE_HOST_CHECK)
01181                         snprintf(help_text,sizeof(help_text),"This command is used to temporarily prevent %s from actively checking the status of a particular host. If %s 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.", PROGRAM_NAME, PROGRAM_NAME);
01182                 snprintf(action,sizeof(action),"%s active host checks",(cmd==CMD_ENABLE_HOST_CHECK)?"Enable":"Disable");
01183                 break;
01184 
01185         case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
01186         case CMD_START_OBSESSING_OVER_SVC_CHECKS:
01187                 if (cmd==CMD_START_OBSESSING_OVER_SVC_CHECKS)
01188                         snprintf(help_text,sizeof(help_text),"This command is used to have %s start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.", PROGRAM_NAME);
01189                 snprintf(action,sizeof(action),"%s obsessing over service checks on a program-wide basis",(cmd==CMD_STOP_OBSESSING_OVER_SVC_CHECKS)?"Stop":"Start");
01190                 break;
01191 
01192         case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
01193         case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
01194                 snprintf(help_text,sizeof(help_text),"This command is used to remove an acknowledgement for %s problems. Once the acknowledgement is removed, notifications may start being "
01195                                 "sent out about the %s problem.",(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)?"host":"service",(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)?"host":"service");
01196                 snprintf(action,sizeof(action),"Remove %s acknowledgements",(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)?"host":"service");
01197                 break;
01198 
01199         case CMD_SCHEDULE_HOST_DOWNTIME:
01200         case CMD_SCHEDULE_SVC_DOWNTIME:
01201                 snprintf(help_text,sizeof(help_text),"This command is used to schedule downtime for these %s. During the specified downtime, %s will not send notifications out about the %s. "
01202                         "When the scheduled downtime expires, %s will send out notifications for this %s as it normally would.  Scheduled downtimes are preserved "
01203                         "across program shutdowns and restarts.",(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"hosts":"services",PROGRAM_NAME,(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"hosts":"services",PROGRAM_NAME,(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"hosts":"services");
01204                 snprintf(action,sizeof(action),"Schedule downtime for these %s",(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"hosts":"services");
01205                 break;
01206 
01207         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
01208                 snprintf(help_text,sizeof(help_text),"This command is used to schedule downtime for a particular host and all of its services.  During the specified downtime, %s will not send notifications out about the host. "
01209                         "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. "
01210                         "When the scheduled downtime expires, %s will send out notifications for this host as it normally would. Scheduled downtimes are preserved "
01211                         "across program shutdowns and restarts.",PROGRAM_NAME,PROGRAM_NAME);
01212                 snprintf(action,sizeof(action),"Schedule downtime for all services for these hosts and the hosts themself");
01213                 break;
01214 
01215         case CMD_PROCESS_HOST_CHECK_RESULT:
01216         case CMD_PROCESS_SERVICE_CHECK_RESULT:
01217                 snprintf(help_text,sizeof(help_text),"This command is used to submit a passive check result for these %s. "
01218                 "It is particularly useful for resetting security-related %s to %s states once they have been dealt with.",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"hosts":"services",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"hosts":"services",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"UP":"OK");
01219 
01220                 snprintf(action,sizeof(action),"Submit a passive check result for these %s",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"hosts":"services");
01221                 break;
01222 
01223         case CMD_ENABLE_HOST_FLAP_DETECTION:
01224         case CMD_DISABLE_HOST_FLAP_DETECTION:
01225                 snprintf(action,sizeof(action),"%s flap detection for these hosts",(cmd==CMD_ENABLE_HOST_FLAP_DETECTION)?"Enable":"Disable");
01226                 break;
01227 
01228         case CMD_ENABLE_SVC_FLAP_DETECTION:
01229         case CMD_DISABLE_SVC_FLAP_DETECTION:
01230                 snprintf(action,sizeof(action),"%s flap detection for these services",(cmd==CMD_ENABLE_SVC_FLAP_DETECTION)?"Enable":"Disable");
01231                 break;
01232 
01233         case CMD_ENABLE_FLAP_DETECTION:
01234         case CMD_DISABLE_FLAP_DETECTION:
01235                 snprintf(action,sizeof(action),"%s flap detection for hosts and services on a program-wide basis",(cmd==CMD_ENABLE_FLAP_DETECTION)?"Enable":"Disable");
01236                 break;
01237 
01238         case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01239         case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01240                 snprintf(action,sizeof(action),"%s notifications for all services in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"Enable":"Disable");
01241                 break;
01242 
01243         case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01244         case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01245                 snprintf(action,sizeof(action),"%s notifications for all hosts in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS)?"Enable":"Disable");
01246                 break;
01247 
01248         case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
01249         case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
01250                 snprintf(action,sizeof(action),"%s active checks of all services in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS)?"Enable":"Disable");
01251                 break;
01252 
01253         case CMD_DEL_HOST_DOWNTIME:
01254         case CMD_DEL_SVC_DOWNTIME:
01255                 snprintf(action,sizeof(action),"Cancel scheduled downtime for these %s",(cmd==CMD_DEL_HOST_DOWNTIME)?"hosts":"services");
01256                 break;
01257 
01258         case CMD_ENABLE_FAILURE_PREDICTION:
01259         case CMD_DISABLE_FAILURE_PREDICTION:
01260                 snprintf(action,sizeof(action),"%s failure prediction for hosts and service on a program-wide basis",(cmd==CMD_ENABLE_FAILURE_PREDICTION)?"Enable":"Disable");
01261                 break;
01262 
01263         case CMD_ENABLE_PERFORMANCE_DATA:
01264         case CMD_DISABLE_PERFORMANCE_DATA:
01265                 snprintf(action,sizeof(action),"%s performance data processing for hosts and services on a program-wide basis",(cmd==CMD_ENABLE_PERFORMANCE_DATA)?"Enable":"Disable");
01266                 break;
01267 
01268         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
01269         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
01270                 snprintf(action,sizeof(action),"Schedule downtime for all %s in a particular hostgroup",(cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME)?"hosts":"services");
01271                 break;
01272 
01273         case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
01274         case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
01275                 snprintf(action,sizeof(action),"%s accepting passive host checks on a program-wide basis",(cmd==CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS)?"Start":"Stop");
01276                 break;
01277 
01278         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
01279         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
01280                 snprintf(action,sizeof(action),"%s accepting passive checks for these hosts",(cmd==CMD_ENABLE_PASSIVE_HOST_CHECKS)?"Start":"Stop");
01281                 break;
01282 
01283         case CMD_START_OBSESSING_OVER_HOST_CHECKS:
01284         case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
01285                 snprintf(action,sizeof(action),"%s obsessing over host checks on a program-wide basis",(cmd==CMD_START_OBSESSING_OVER_HOST_CHECKS)?"Start":"Stop");
01286                 break;
01287 
01288         case CMD_START_OBSESSING_OVER_SVC:
01289         case CMD_STOP_OBSESSING_OVER_SVC:
01290                 snprintf(action,sizeof(action),"%s obsessing over these services",(cmd==CMD_START_OBSESSING_OVER_SVC)?"Start":"Stop");
01291                 break;
01292 
01293         case CMD_START_OBSESSING_OVER_HOST:
01294         case CMD_STOP_OBSESSING_OVER_HOST:
01295                 snprintf(action,sizeof(action),"%s obsessing over these hosts",(cmd==CMD_START_OBSESSING_OVER_HOST)?"Start":"Stop");
01296                 break;
01297 
01298         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01299         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01300                 snprintf(action,sizeof(action),"%s notifications for all services in a particular servicegroup",(cmd==CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS)?"Enable":"Disable");
01301                 break;
01302 
01303         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01304         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01305                 snprintf(action,sizeof(action),"%s notifications for all hosts in a particular servicegroup",(cmd==CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS)?"Enable":"Disable");
01306                 break;
01307 
01308         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
01309         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
01310                 snprintf(action,sizeof(action),"%s active checks of all services in a particular servicegroup",(cmd==CMD_ENABLE_SERVICEGROUP_SVC_CHECKS)?"Enable":"Disable");
01311                 break;
01312 
01313         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
01314                 snprintf(action,sizeof(action),"Schedule downtime for all hosts in a particular servicegroup");
01315                 break;
01316 
01317         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
01318                 snprintf(action,sizeof(action),"Schedule downtime for all services in a particular servicegroup");
01319                 break;
01320 
01321         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
01322         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
01323                 snprintf(help_text,sizeof(help_text),"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.",(cmd==CMD_SEND_CUSTOM_HOST_NOTIFICATION)?"host":"service");
01324                 snprintf(action,sizeof(action),"Send a custom %s notification",(cmd==CMD_SEND_CUSTOM_HOST_NOTIFICATION)?"host":"service");
01325                 break;
01326 
01327         default:
01328                 print_generic_error_message("Sorry Dave, I can't let you do that...","Executing an unknown command? Shame on you!",2);
01329 
01330                 return;
01331         }
01332 
01333         help_text[sizeof(help_text)-1]='\x0';
01334         action[sizeof(action)-1]='\x0';
01335 
01336         /* Javascript to check input */
01337         printf("<script language=\"JavaScript\">\n");
01338         printf("function check_input(){\n"
01339                 "       if (document.getElementById('com_data')) {\n"
01340                 "               if (document.getElementById('com_data').value == '') {\n"
01341                 "                       document.getElementById('com_data_error').style.display = '';\n"
01342                 "                       return false;\n"
01343                 "               } else {\n"
01344                 "                       document.getElementById('com_data_error').style.display = 'none';\n"
01345                 "               }\n"
01346                 "       }\n"
01347                 "       if (document.getElementById('plugin_output')) {\n"
01348                 "               if (document.getElementById('plugin_output').value == '') {\n"
01349                 "                       document.getElementById('plugin_output_error').style.display = '';\n"
01350                 "                       return false;\n"
01351                 "               } else {\n"
01352                 "                       document.getElementById('plugin_output_error').style.display = 'none';\n"
01353                 "               }\n"
01354                 "       }\n"
01355                 "       if (document.getElementById('not_dly')) {\n"
01356                 "               if (parseInt(document.getElementById('not_dly').value) == 0 ) {\n"
01357                 "                       document.getElementById('not_dly_error').style.display = '';\n"
01358                 "                       return false;\n"
01359                 "               }\n"
01360                 "       }\n"
01361                 "       return true;\n"
01362                 "}\n"
01363                 "</script>\n");
01364 
01365         printf("<div align='center'>\n");
01366 
01367         printf("<form method='post' action='%s' onSubmit=\"return check_input();\">\n", CMD_CGI);
01368 
01369         printf("<INPUT TYPE='HIDDEN' NAME='cmd_typ' VALUE='%d'><INPUT TYPE='HIDDEN' NAME='cmd_mod' VALUE='%d'>\n",cmd,CMDMODE_COMMIT);
01370 
01371         /* creating an extra table to make it compatible to IE6 & IE7 to have a nice frame around the form, damn it */
01372         printf("<TABLE CELLSPACING='0' CELLPADDING='0'><TR><TD CLASS='boxFrame BoxWidth'>\n");
01373 
01374         printf("<TABLE CELLSPACING='2' CELLPADDING='0' class='contentTable'>\n");
01375 
01376         printf("<tr CLASS='sectionHeader'><td COLSPAN='2'>Action</td></tr>\n");
01377         printf("<tr><td COLSPAN='2'>%s ",action);
01378         if (strlen(help_text) > 2)
01379                 print_help_box(help_text);
01380         printf("</td></tr>\n");
01381 
01382         switch(cmd){
01383 
01384         case CMD_ADD_SVC_COMMENT:
01385         case CMD_ACKNOWLEDGE_SVC_PROBLEM:
01386         case CMD_ADD_HOST_COMMENT:
01387         case CMD_ACKNOWLEDGE_HOST_PROBLEM:
01388 
01389                 if(cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM || cmd==CMD_ADD_SVC_COMMENT)
01390                         print_object_list(PRINT_SERVICE_LIST);
01391                 else
01392                         print_object_list(PRINT_HOST_LIST);
01393 
01394                 print_form_element(PRINT_COMMON_HEADER,cmd);
01395                 print_form_element(PRINT_AUTHOR,cmd);
01396                 print_form_element(PRINT_COMMENT_BOX,cmd);
01397                 print_form_element(PRINT_PERSISTENT,cmd);
01398 
01399                 if(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd==CMD_ACKNOWLEDGE_SVC_PROBLEM){
01400                         print_form_element(PRINT_STICKY_ACK,cmd);
01401                         print_form_element(PRINT_SEND_NOTFICATION,cmd);
01402                 }
01403 
01404                 break;
01405 
01406         case CMD_DEL_HOST_DOWNTIME:
01407         case CMD_DEL_SVC_DOWNTIME:
01408         case CMD_DEL_HOST_COMMENT:
01409         case CMD_DEL_SVC_COMMENT:
01410 
01411                 if (cmd==CMD_DEL_HOST_COMMENT || cmd==CMD_DEL_SVC_COMMENT)
01412                         print_object_list(PRINT_COMMENT_LIST);
01413                 else
01414                         print_object_list(PRINT_DOWNTIME_LIST);
01415 
01416                 if(enforce_comments_on_actions==TRUE) {
01417                         print_form_element(PRINT_COMMON_HEADER,cmd);
01418                         print_form_element(PRINT_AUTHOR,cmd);
01419                         print_form_element(PRINT_COMMENT_BOX,cmd);
01420                 }
01421 
01422                 break;
01423 
01424         case CMD_DELAY_SVC_NOTIFICATION:
01425         case CMD_DELAY_HOST_NOTIFICATION:
01426 
01427                 if(cmd==CMD_DELAY_SVC_NOTIFICATION)
01428                         print_object_list(PRINT_SERVICE_LIST);
01429                 else
01430                         print_object_list(PRINT_HOST_LIST);
01431 
01432                 print_form_element(PRINT_COMMON_HEADER,cmd);
01433 
01434                 if(enforce_comments_on_actions==TRUE) {
01435                         print_form_element(PRINT_AUTHOR,cmd);
01436                         print_form_element(PRINT_COMMENT_BOX,cmd);
01437                 }
01438 
01439                 print_form_element(PRINT_NOTIFICATION_DELAY,cmd);
01440 
01441                 break;
01442 
01443         case CMD_SCHEDULE_SVC_CHECK:
01444         case CMD_SCHEDULE_HOST_CHECK:
01445         case CMD_SCHEDULE_HOST_SVC_CHECKS:
01446 
01447                 if(cmd==CMD_SCHEDULE_SVC_CHECK)
01448                         print_object_list(PRINT_SERVICE_LIST);
01449                 else
01450                         print_object_list(PRINT_HOST_LIST);
01451 
01452                 print_form_element(PRINT_COMMON_HEADER,cmd);
01453 
01454                 if(enforce_comments_on_actions==TRUE) {
01455                         print_form_element(PRINT_AUTHOR,cmd);
01456                         print_form_element(PRINT_COMMENT_BOX,cmd);
01457                 }
01458 
01459                 print_form_element(PRINT_CHECK_TIME,cmd);
01460                 print_form_element(PRINT_FORCE_CHECK,cmd);
01461 
01462                 break;
01463 
01464         case CMD_ENABLE_SVC_CHECK:
01465         case CMD_DISABLE_SVC_CHECK:
01466         case CMD_DEL_ALL_SVC_COMMENTS:
01467         case CMD_ENABLE_SVC_NOTIFICATIONS:
01468         case CMD_DISABLE_SVC_NOTIFICATIONS:
01469         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
01470         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
01471         case CMD_ENABLE_SVC_EVENT_HANDLER:
01472         case CMD_DISABLE_SVC_EVENT_HANDLER:
01473         case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
01474         case CMD_ENABLE_SVC_FLAP_DETECTION:
01475         case CMD_DISABLE_SVC_FLAP_DETECTION:
01476         case CMD_START_OBSESSING_OVER_SVC:
01477         case CMD_STOP_OBSESSING_OVER_SVC:
01478 
01479                 print_object_list(PRINT_SERVICE_LIST);
01480 
01481                 if(enforce_comments_on_actions==TRUE) {
01482                         print_form_element(PRINT_COMMON_HEADER,cmd);
01483                         print_form_element(PRINT_AUTHOR,cmd);
01484                         print_form_element(PRINT_COMMENT_BOX,cmd);
01485                 }
01486 
01487                 break;
01488 
01489         case CMD_ENABLE_HOST_SVC_CHECKS:
01490         case CMD_DISABLE_HOST_SVC_CHECKS:
01491         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
01492         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
01493         case CMD_ENABLE_HOST_NOTIFICATIONS:
01494         case CMD_DISABLE_HOST_NOTIFICATIONS:
01495         case CMD_DEL_ALL_HOST_COMMENTS:
01496         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01497         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
01498         case CMD_ENABLE_HOST_EVENT_HANDLER:
01499         case CMD_DISABLE_HOST_EVENT_HANDLER:
01500         case CMD_ENABLE_HOST_CHECK:
01501         case CMD_DISABLE_HOST_CHECK:
01502         case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
01503         case CMD_ENABLE_HOST_FLAP_DETECTION:
01504         case CMD_DISABLE_HOST_FLAP_DETECTION:
01505         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
01506         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
01507         case CMD_START_OBSESSING_OVER_HOST:
01508         case CMD_STOP_OBSESSING_OVER_HOST:
01509 
01510                 print_object_list(PRINT_HOST_LIST);
01511 
01512                 if(enforce_comments_on_actions==TRUE) {
01513                         print_form_element(PRINT_COMMON_HEADER,cmd);
01514                         print_form_element(PRINT_AUTHOR,cmd);
01515                         print_form_element(PRINT_COMMENT_BOX,cmd);
01516                 }
01517 
01518                 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 || cmd==CMD_ENABLE_HOST_NOTIFICATIONS || cmd==CMD_DISABLE_HOST_NOTIFICATIONS){
01519                         if(enforce_comments_on_actions!=TRUE)
01520                                 print_form_element(PRINT_COMMON_HEADER,cmd);
01521                 }
01522 
01523                 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){
01524 
01525                         snprintf(help_text,sizeof(help_text),"This %s %s of the host too.",(cmd==CMD_ENABLE_HOST_SVC_CHECKS ||cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"enables":"disables",(cmd==CMD_ENABLE_HOST_SVC_CHECKS || cmd==CMD_DISABLE_HOST_SVC_CHECKS)?"checks":"notifications");
01526                         help_text[sizeof(help_text)-1]='\x0';
01527 
01528                         printf("<tr><td class=\"objectDescription descriptionleft\">%s For Host Too:",(cmd==CMD_ENABLE_HOST_SVC_CHECKS || cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"Enable":"Disable");
01529                         print_help_box(help_text);
01530                         printf("</td><td align=\"left\"><INPUT TYPE='checkbox' NAME='ahas'></td></tr>\n");
01531                 }
01532 
01533                 if(cmd==CMD_ENABLE_HOST_NOTIFICATIONS || cmd==CMD_DISABLE_HOST_NOTIFICATIONS){
01534 
01535                         snprintf(help_text,sizeof(help_text),"%s notifications te be sent out to child hosts.",(cmd==CMD_ENABLE_HOST_NOTIFICATIONS)?"Enable":"Disable");
01536                         help_text[sizeof(help_text)-1]='\x0';
01537 
01538                         printf("<tr><td class=\"objectDescription descriptionleft\">%s Notifications For Child Hosts Too:",(cmd==CMD_ENABLE_HOST_NOTIFICATIONS)?"Enable":"Disable");
01539                         print_help_box(help_text);
01540                         printf("</td><td align=\"left\"><INPUT TYPE='checkbox' NAME='ptc'></td></tr>\n");
01541                 }
01542                 break;
01543 
01544         case CMD_ENABLE_NOTIFICATIONS:
01545         case CMD_DISABLE_NOTIFICATIONS:
01546         case CMD_SHUTDOWN_PROCESS:
01547         case CMD_RESTART_PROCESS:
01548         case CMD_START_EXECUTING_SVC_CHECKS:
01549         case CMD_STOP_EXECUTING_SVC_CHECKS:
01550         case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
01551         case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
01552         case CMD_ENABLE_EVENT_HANDLERS:
01553         case CMD_DISABLE_EVENT_HANDLERS:
01554         case CMD_START_OBSESSING_OVER_SVC_CHECKS:
01555         case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
01556         case CMD_ENABLE_FLAP_DETECTION:
01557         case CMD_DISABLE_FLAP_DETECTION:
01558         case CMD_ENABLE_FAILURE_PREDICTION:
01559         case CMD_DISABLE_FAILURE_PREDICTION:
01560         case CMD_ENABLE_PERFORMANCE_DATA:
01561         case CMD_DISABLE_PERFORMANCE_DATA:
01562         case CMD_START_EXECUTING_HOST_CHECKS:
01563         case CMD_STOP_EXECUTING_HOST_CHECKS:
01564         case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
01565         case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
01566         case CMD_START_OBSESSING_OVER_HOST_CHECKS:
01567         case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
01568 
01569                 if(enforce_comments_on_actions==TRUE) {
01570                         print_form_element(PRINT_COMMON_HEADER,cmd);
01571                         print_form_element(PRINT_AUTHOR,cmd);
01572                         print_form_element(PRINT_COMMENT_BOX,cmd);
01573                 } else  {
01574                         printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
01575                         printf("<tr><td CLASS='objectDescription' colspan=2>There are no options for this command.<br>Click the 'Commit' button to submit the command.</td></tr>\n");
01576                 }
01577 
01578                 break;
01579 
01580         case CMD_PROCESS_HOST_CHECK_RESULT:
01581         case CMD_PROCESS_SERVICE_CHECK_RESULT:
01582 
01583                 if(cmd==CMD_PROCESS_SERVICE_CHECK_RESULT)
01584                         print_object_list(PRINT_SERVICE_LIST);
01585                 else
01586                         print_object_list(PRINT_HOST_LIST);
01587 
01588                 print_form_element(PRINT_COMMON_HEADER,cmd);
01589 
01590                 if(enforce_comments_on_actions==TRUE) {
01591                         print_form_element(PRINT_AUTHOR,cmd);
01592                         print_form_element(PRINT_COMMENT_BOX,cmd);
01593                 }
01594 
01595                 snprintf(help_text,sizeof(help_text),"Set the state which should be send to %s for this %s.",PROGRAM_NAME,(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"hosts":"services");
01596                 help_text[sizeof(help_text)-1]='\x0';
01597 
01598                 printf("<tr><td class=\"objectDescription descriptionleft\">Check Result:");
01599                 print_help_box(help_text);
01600                 printf("</td><td align=\"left\">\n");
01601                 printf("\t<SELECT NAME='plugin_state'>\n");
01602                 if(cmd==CMD_PROCESS_SERVICE_CHECK_RESULT){
01603                         printf("\t\t<OPTION VALUE=%d SELECTED>OK</OPTION>\n",STATE_OK);
01604                         printf("\t\t<OPTION VALUE=%d>WARNING</OPTION>\n",STATE_WARNING);
01605                         printf("\t\t<OPTION VALUE=%d>UNKNOWN</OPTION>\n",STATE_UNKNOWN);
01606                         printf("\t\t<OPTION VALUE=%d>CRITICAL</OPTION>\n",STATE_CRITICAL);
01607                 }else{
01608                         printf("\t\t<OPTION VALUE=0 SELECTED>UP</OPTION>\n");
01609                         printf("\t\t<OPTION VALUE=1>DOWN</OPTION>\n");
01610                         printf("\t\t<OPTION VALUE=2>UNREACHABLE</OPTION>\n");
01611                 }
01612                 printf("\t</SELECT>\n");
01613                 printf("</td></tr>\n");
01614 
01615                 print_form_element(PRINT_CHECK_OUTPUT_BOX,cmd);
01616                 print_form_element(PRINT_PERFORMANCE_DATA_BOX,cmd);
01617 
01618                 break;
01619 
01620         case CMD_SCHEDULE_HOST_DOWNTIME:
01621         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
01622         case CMD_SCHEDULE_SVC_DOWNTIME:
01623 
01624                 if(cmd==CMD_SCHEDULE_SVC_DOWNTIME)
01625                         print_object_list(PRINT_SERVICE_LIST);
01626                 else
01627                         print_object_list(PRINT_HOST_LIST);
01628 
01629                 print_form_element(PRINT_COMMON_HEADER,cmd);
01630                 print_form_element(PRINT_AUTHOR,cmd);
01631                 print_form_element(PRINT_COMMENT_BOX,cmd);
01632 
01633                 snprintf(help_text,sizeof(help_text),"Define here if this downtime should get triggerd by another downtime of a particular %s.",(cmd==CMD_PROCESS_HOST_CHECK_RESULT)?"host":"service");
01634                 help_text[sizeof(help_text)-1]='\x0';
01635 
01636                 printf("<tr id=\"trigger_select\"><td class=\"objectDescription descriptionleft\">Triggered By:");
01637                 print_help_box(help_text);
01638                 printf("</td><td align=\"left\">\n");
01639                 printf("\t<SELECT name='trigger'>\n");
01640                 printf("\t\t<OPTION VALUE='0'>N/A</OPTION>\n");
01641 
01642                 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
01643                         if(temp_downtime->type!=HOST_DOWNTIME)
01644                                 continue;
01645 
01646                         /* find the host... */
01647                          temp_host=find_host(temp_downtime->host_name);
01648 
01649                          /* make sure user has rights to view this host */
01650                         if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
01651                                 continue;
01652 
01653                         printf("\t\t<OPTION VALUE='%lu'>",temp_downtime->downtime_id);
01654                         get_time_string(&temp_downtime->start_time,start_time,sizeof(start_time),SHORT_DATE_TIME);
01655                         printf("ID: %lu, Host '%s' starting @ %s</OPTION>\n",temp_downtime->downtime_id,temp_downtime->host_name,start_time);
01656                         found_trigger_objects=TRUE;
01657                 }
01658                 for(temp_downtime=scheduled_downtime_list;temp_downtime!=NULL;temp_downtime=temp_downtime->next){
01659                         if(temp_downtime->type!=SERVICE_DOWNTIME)
01660                                 continue;
01661 
01662                         printf("\t\t<OPTION VALUE='%lu'>",temp_downtime->downtime_id);
01663                         get_time_string(&temp_downtime->start_time,start_time,sizeof(start_time),SHORT_DATE_TIME);
01664                         printf("ID: %lu, Service '%s' on host '%s' starting @ %s</OPTION>\n",temp_downtime->downtime_id,temp_downtime->service_description,temp_downtime->host_name,start_time);
01665                         found_trigger_objects=TRUE;
01666                 }
01667 
01668                 printf("\t</SELECT>\n");
01669                 printf("</td></tr>\n");
01670 
01671                 /* hide "Triggerd by" selction if nothing is found to get triggerd from */
01672                 if(!found_trigger_objects)
01673                         printf("<tr style=\"display:none;\"><td colspan=2><script language=\"JavaScript\">document.getElementById('trigger_select').style.display = 'none';</script></td></tr>\n");
01674 
01675                 print_form_element(PRINT_START_TIME,cmd);
01676                 print_form_element(PRINT_END_TIME,cmd);
01677                 print_form_element(PRINT_FIXED_FLEXIBLE_TYPE,cmd);
01678 
01679                 if(cmd==CMD_SCHEDULE_HOST_DOWNTIME){
01680                         snprintf(help_text,sizeof(help_text),"Define here what should be done with the child hosts of these hosts.");
01681                         help_text[sizeof(help_text)-1]='\x0';
01682 
01683                         printf("<tr><td class=\"objectDescription descriptionleft\">Child Hosts:");
01684                         print_help_box(help_text);
01685                         printf("</td><td align=\"left\">\n");
01686                         printf("\t<SELECT name='childoptions'>\n");
01687                         printf("\t\t<OPTION VALUE='0'>Do nothing with child hosts</OPTION>\n");
01688                         printf("\t\t<OPTION VALUE='1'>Schedule triggered downtime for all child hosts</OPTION>\n");
01689                         printf("\t\t<OPTION VALUE='2'>Schedule non-triggered downtime for all child hosts</OPTION>\n");
01690                         printf("\t</SELECT>\n");
01691                         printf("</td></tr>\n");
01692                 }
01693 
01694                 break;
01695 
01696         case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01697         case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
01698         case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01699         case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
01700         case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
01701         case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
01702 
01703                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
01704                 printf("<tr class=\"statusEven\" ><td width=\"50%%\" style=\"font-weight:bold;\">Hostgroup Name:</td>");
01705                 printf("<td><INPUT TYPE='HIDDEN' NAME='hostgroup' VALUE='%s'>%s</td></tr>\n",escape_string(hostgroup_name),escape_string(hostgroup_name));
01706 
01707                 if(enforce_comments_on_actions==TRUE) {
01708                         print_form_element(PRINT_COMMON_HEADER,cmd);
01709                         print_form_element(PRINT_AUTHOR,cmd);
01710                         print_form_element(PRINT_COMMENT_BOX,cmd);
01711                 }
01712 
01713                 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){
01714 
01715                         if(enforce_comments_on_actions!=TRUE)
01716                                 print_form_element(PRINT_COMMON_HEADER,cmd);
01717 
01718                         printf("<tr><td class=\"objectDescription descriptionleft\">%s For Hosts Too:</td><td align=\"left\">\n",(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS || cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"Enable":"Disable");
01719                         printf("<INPUT TYPE='checkbox' NAME='ahas'></td></tr>\n");
01720                 }
01721                 break;
01722 
01723         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01724         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
01725         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01726         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
01727         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
01728         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
01729 
01730                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
01731                 printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">Servicegroup Name:</td>");
01732                 printf("<td><INPUT TYPE='HIDDEN' NAME='servicegroup' VALUE='%s'>%s</td></tr>\n",escape_string(servicegroup_name),escape_string(servicegroup_name));
01733 
01734                 if(enforce_comments_on_actions==TRUE) {
01735                         print_form_element(PRINT_COMMON_HEADER,cmd);
01736                         print_form_element(PRINT_AUTHOR,cmd);
01737                         print_form_element(PRINT_COMMENT_BOX,cmd);
01738                 }
01739 
01740                 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){
01741 
01742                         if(enforce_comments_on_actions!=TRUE)
01743                                 print_form_element(PRINT_COMMON_HEADER,cmd);
01744 
01745                         printf("<tr><td class=\"objectDescription descriptionleft\">%s For Hosts Too:</td><td align=\"left\">\n",(cmd==CMD_ENABLE_SERVICEGROUP_SVC_CHECKS || cmd==CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS)?"Enable":"Disable");
01746                         printf("<INPUT TYPE='checkbox' NAME='ahas'></td></tr>\n");
01747                 }
01748                 break;
01749 
01750         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
01751         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
01752         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
01753         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
01754 
01755                 printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
01756                 printf("<tr class=\"statusEven\"><td width=\"50%%\" style=\"font-weight:bold;\">");
01757                 if(cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME)
01758                         printf("Hostgroup Name:</td><td><INPUT TYPE='HIDDEN' NAME='hostgroup' VALUE='%s'>%s</td></tr>\n",escape_string(hostgroup_name),escape_string(hostgroup_name));
01759                 else
01760                         printf("Servicegroup Name:</td><td><INPUT TYPE='HIDDEN' NAME='servicegroup' VALUE='%s'>%s</td></tr>\n",escape_string(servicegroup_name),escape_string(servicegroup_name));
01761 
01762                 print_form_element(PRINT_COMMON_HEADER,cmd);
01763                 print_form_element(PRINT_AUTHOR,cmd);
01764                 print_form_element(PRINT_COMMENT_BOX,cmd);
01765                 print_form_element(PRINT_START_TIME,cmd);
01766                 print_form_element(PRINT_END_TIME,cmd);
01767                 print_form_element(PRINT_FIXED_FLEXIBLE_TYPE,cmd);
01768 
01769                 if(cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME || cmd==CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME){
01770                         printf("<tr><td class=\"objectDescription descriptionleft\">Schedule Downtime For Hosts Too:</td><td align=\"left\">\n");
01771                         printf("<INPUT TYPE='checkbox' NAME='ahas'></td></tr>\n");
01772                 }
01773                 break;
01774 
01775         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
01776         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
01777 
01778                 if(cmd==CMD_SEND_CUSTOM_SVC_NOTIFICATION)
01779                         print_object_list(PRINT_SERVICE_LIST);
01780                 else
01781                         print_object_list(PRINT_HOST_LIST);
01782 
01783                 print_form_element(PRINT_COMMON_HEADER,cmd);
01784                 print_form_element(PRINT_AUTHOR,cmd);
01785                 print_form_element(PRINT_COMMENT_BOX,cmd);
01786                 print_form_element(PRINT_FORCE_NOTIFICATION,cmd);
01787                 print_form_element(PRINT_BROADCAST_NOTIFICATION,cmd);
01788 
01789                 break;
01790 
01791         default:
01792                 printf("<tr><td CLASS='objectDescription' COLSPAN=\"2\">This should not be happening... :-(</td></tr>\n");
01793         }
01794 
01795 
01796         printf("<tr><td COLSPAN=\"2\">&nbsp;</td></tr>\n");
01797         printf("<tr CLASS='sectionHeader'><td COLSPAN=\"2\" class=\"commitButton\"><INPUT TYPE=\"submit\" NAME=\"btnSubmit\" VALUE=\"Commit\" class=\"submitButton\">&nbsp;&nbsp;|&nbsp;&nbsp;<a HREF=\"javascript:window.history.go(-1)\">Cancel</a></td></tr>\n");
01798 
01799         printf("</table>\n");
01800         printf("</td></tr></table>\n"); /* Outer frame */
01801         printf("</form>\n");
01802 
01803         printf("</div>\n");
01804 
01805         return;
01806 }
01807 
01808 void commit_command_data(int cmd){
01809         char error_string[MAX_INPUT_BUFFER];
01810         service *temp_service;
01811         host *temp_host;
01812         hostgroup *temp_hostgroup;
01813         comment *temp_comment;
01814         scheduled_downtime *temp_downtime;
01815         servicegroup *temp_servicegroup=NULL;
01816         contact *temp_contact=NULL;
01817         int x=0;
01818         int e=0;
01819         short error_found=FALSE;
01820         short cmd_has_objects = FALSE;
01821         short row_color = 0;
01822 
01823         /* get authentication information */
01824         get_authentication_information(&current_authdata);
01825 
01826         /* allways set the first element to FALSE*/
01827         /* If there is a single COMMAND witch is not coverd correctly throught the following cases it won't get executed */
01828         is_authorized[x]=FALSE;
01829 
01830         /* get name to use for author */
01831         if(lock_author_names==TRUE){
01832                 temp_contact=find_contact(current_authdata.username);
01833                 if(temp_contact!=NULL && temp_contact->alias!=NULL)
01834                         comment_author=temp_contact->alias;
01835                 else
01836                         comment_author=current_authdata.username;
01837         }
01838 
01839         switch(cmd){
01840 
01841 
01842         case CMD_ADD_HOST_COMMENT:
01843         case CMD_ADD_SVC_COMMENT:
01844         case CMD_ACKNOWLEDGE_HOST_PROBLEM:
01845         case CMD_ACKNOWLEDGE_SVC_PROBLEM:
01846         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
01847         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
01848 
01849                 /* make sure we have author name, and comment data... */
01850                 check_comment_sanity(&e);
01851 
01852                 /* clean up the comment data */
01853                 clean_comment_data(comment_author);
01854                 clean_comment_data(comment_data);
01855 
01856                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
01857 
01858                         cmd_has_objects = TRUE;
01859 
01860                         if (commands[x].host_name == NULL)
01861                                 continue;
01862 
01863                         /* see if the user is authorized to issue a command... */
01864                         is_authorized[x]=FALSE;
01865                         if (cmd==CMD_ADD_HOST_COMMENT || cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM || cmd==CMD_SEND_CUSTOM_HOST_NOTIFICATION) {
01866                                 temp_host=find_host(commands[x].host_name);
01867                                 if(is_authorized_for_host_commands(temp_host,&current_authdata)==TRUE)
01868                                         is_authorized[x]=TRUE;
01869                         } else {
01870                                 temp_service=find_service(commands[x].host_name,commands[x].description);
01871                                 if(is_authorized_for_service_commands(temp_service,&current_authdata)==TRUE)
01872                                         is_authorized[x]=TRUE;
01873                         }
01874                 }
01875                 break;
01876 
01877         case CMD_DEL_HOST_COMMENT:
01878         case CMD_DEL_SVC_COMMENT:
01879 
01880                 if(enforce_comments_on_actions==TRUE) {
01881                         check_comment_sanity(&e);
01882                         clean_comment_data(comment_author);
01883                         clean_comment_data(comment_data);
01884                 }
01885 
01886                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
01887 
01888                         cmd_has_objects = TRUE;
01889 
01890                         if (multi_ids[x] == FALSE)
01891                                 continue;
01892 
01893                         /* check the sanity of the comment id */
01894                         if(multi_ids[x]==0) {
01895                                 error[e++].message=strdup("Comment id cannot be 0");
01896                                 continue;
01897                         }
01898 
01899                         /* find the comment */
01900                         if(cmd==CMD_DEL_HOST_COMMENT)
01901                                 temp_comment=find_host_comment(multi_ids[x]);
01902                         else
01903                                 temp_comment=find_service_comment(multi_ids[x]);
01904 
01905                         /* see if the user is authorized to issue a command... */
01906                         is_authorized[x]=FALSE;
01907                         if (cmd==CMD_DEL_HOST_COMMENT && temp_comment!=NULL) {
01908                                 temp_host=find_host(temp_comment->host_name);
01909                                 if(is_authorized_for_host_commands(temp_host,&current_authdata)==TRUE)
01910                                         is_authorized[x]=TRUE;
01911                         }
01912                         if (cmd==CMD_DEL_SVC_COMMENT && temp_comment!=NULL) {
01913                                 temp_service=find_service(temp_comment->host_name,temp_comment->service_description);
01914                                 if(is_authorized_for_service_commands(temp_service,&current_authdata)==TRUE)
01915                                         is_authorized[x]=TRUE;
01916                         }
01917                 }
01918 
01919                 /* free comment data */
01920                 free_comment_data();
01921 
01922                 break;
01923 
01924         case CMD_DEL_HOST_DOWNTIME:
01925         case CMD_DEL_SVC_DOWNTIME:
01926 
01927                 if(enforce_comments_on_actions==TRUE) {
01928                         check_comment_sanity(&e);
01929                         clean_comment_data(comment_author);
01930                         clean_comment_data(comment_data);
01931                 }
01932 
01933                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
01934 
01935                         cmd_has_objects = TRUE;
01936 
01937                         if (multi_ids[x] == FALSE)
01938                                 continue;
01939 
01940                         /* check the sanity of the downtime id */
01941                         if(multi_ids[x]==0){
01942                                 error[e++].message=strdup("Downtime id cannot be 0");
01943                                 continue;
01944                         }
01945 
01946                         /* find the downtime entry */
01947                         if(cmd==CMD_DEL_HOST_DOWNTIME)
01948                                 temp_downtime=find_host_downtime(multi_ids[x]);
01949                         else
01950                                 temp_downtime=find_service_downtime(multi_ids[x]);
01951 
01952                         /* see if the user is authorized to issue a command... */
01953                         is_authorized[x]=FALSE;
01954                         if(cmd==CMD_DEL_HOST_DOWNTIME && temp_downtime!=NULL){
01955                                 temp_host=find_host(temp_downtime->host_name);
01956                                 if(is_authorized_for_host_commands(temp_host,&current_authdata)==TRUE)
01957                                         is_authorized[x]=TRUE;
01958                         }
01959                         if(cmd==CMD_DEL_SVC_DOWNTIME && temp_downtime!=NULL){
01960                                 temp_service=find_service(temp_downtime->host_name,temp_downtime->service_description);
01961                                 if(is_authorized_for_service_commands(temp_service,&current_authdata)==TRUE)
01962                                         is_authorized[x]=TRUE;
01963                         }
01964                 }
01965 
01966                 /* free downtime data */
01967                 free_downtime_data();
01968 
01969                 break;
01970 
01971         case CMD_SCHEDULE_SVC_CHECK:
01972         case CMD_ENABLE_SVC_CHECK:
01973         case CMD_DISABLE_SVC_CHECK:
01974         case CMD_DEL_ALL_SVC_COMMENTS:
01975         case CMD_ENABLE_SVC_NOTIFICATIONS:
01976         case CMD_DISABLE_SVC_NOTIFICATIONS:
01977         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
01978         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
01979         case CMD_ENABLE_SVC_EVENT_HANDLER:
01980         case CMD_DISABLE_SVC_EVENT_HANDLER:
01981         case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
01982         case CMD_PROCESS_SERVICE_CHECK_RESULT:
01983         case CMD_SCHEDULE_SVC_DOWNTIME:
01984         case CMD_DELAY_SVC_NOTIFICATION:
01985         case CMD_ENABLE_SVC_FLAP_DETECTION:
01986         case CMD_DISABLE_SVC_FLAP_DETECTION:
01987         case CMD_START_OBSESSING_OVER_SVC:
01988         case CMD_STOP_OBSESSING_OVER_SVC:
01989 
01990                 if(cmd==CMD_SCHEDULE_SVC_DOWNTIME || enforce_comments_on_actions==TRUE) {
01991                         /* make sure we have author and comment data */
01992                         check_comment_sanity(&e);
01993 
01994                         /* make sure we have start/end times for downtime */
01995                         if (cmd==CMD_SCHEDULE_SVC_DOWNTIME)
01996                                 check_time_sanity(&e);
01997 
01998                         /* clean up the comment data if scheduling downtime */
01999                         clean_comment_data(comment_author);
02000                         clean_comment_data(comment_data);
02001                 }
02002 
02003                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02004 
02005                         cmd_has_objects = TRUE;
02006 
02007                         if (commands[x].host_name == NULL || commands[x].description == NULL)
02008                                 continue;
02009 
02010                         is_authorized[x]=FALSE;
02011                         temp_service=find_service(commands[x].host_name,commands[x].description);
02012                         if(is_authorized_for_service_commands(temp_service,&current_authdata)==TRUE)
02013                                 is_authorized[x]=TRUE;
02014                 }
02015 
02016                 /* make sure we have passive check info (if necessary) */
02017                 if(cmd==CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output,""))
02018                         error[e++].message=strdup("Check output cannot be blank");
02019 
02020                 /* make sure we have a notification delay (if necessary) */
02021                 if(cmd==CMD_DELAY_SVC_NOTIFICATION && notification_delay<=0)
02022                         error[e++].message=strdup("Notification delay must be greater than 0");
02023 
02024                 /* make sure we have check time (if necessary) */
02025                 if(cmd==CMD_SCHEDULE_SVC_CHECK && start_time==(time_t)0)
02026                         error[e++].message=strdup("Start time must be non-zero or bad format has been submitted");
02027 
02028                 break;
02029 
02030         case CMD_ENABLE_NOTIFICATIONS:
02031         case CMD_DISABLE_NOTIFICATIONS:
02032         case CMD_SHUTDOWN_PROCESS:
02033         case CMD_RESTART_PROCESS:
02034         case CMD_START_EXECUTING_SVC_CHECKS:
02035         case CMD_STOP_EXECUTING_SVC_CHECKS:
02036         case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
02037         case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
02038         case CMD_ENABLE_EVENT_HANDLERS:
02039         case CMD_DISABLE_EVENT_HANDLERS:
02040         case CMD_START_OBSESSING_OVER_SVC_CHECKS:
02041         case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
02042         case CMD_ENABLE_FLAP_DETECTION:
02043         case CMD_DISABLE_FLAP_DETECTION:
02044         case CMD_ENABLE_FAILURE_PREDICTION:
02045         case CMD_DISABLE_FAILURE_PREDICTION:
02046         case CMD_ENABLE_PERFORMANCE_DATA:
02047         case CMD_DISABLE_PERFORMANCE_DATA:
02048         case CMD_START_EXECUTING_HOST_CHECKS:
02049         case CMD_STOP_EXECUTING_HOST_CHECKS:
02050         case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
02051         case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
02052         case CMD_START_OBSESSING_OVER_HOST_CHECKS:
02053         case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
02054 
02055                 if(enforce_comments_on_actions==TRUE) {
02056                         check_comment_sanity(&e);
02057                         clean_comment_data(comment_author);
02058                         clean_comment_data(comment_data);
02059                 }
02060 
02061                 /* see if the user is authorized to issue a command... */
02062                 is_authorized[x]=FALSE;
02063                 if(is_authorized_for_system_commands(&current_authdata)==TRUE)
02064                         is_authorized[x]=TRUE;
02065                 break;
02066 
02067         case CMD_ENABLE_HOST_SVC_CHECKS:
02068         case CMD_DISABLE_HOST_SVC_CHECKS:
02069         case CMD_DEL_ALL_HOST_COMMENTS:
02070         case CMD_SCHEDULE_HOST_SVC_CHECKS:
02071         case CMD_ENABLE_HOST_NOTIFICATIONS:
02072         case CMD_DISABLE_HOST_NOTIFICATIONS:
02073         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
02074         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
02075         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
02076         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
02077         case CMD_ENABLE_HOST_EVENT_HANDLER:
02078         case CMD_DISABLE_HOST_EVENT_HANDLER:
02079         case CMD_ENABLE_HOST_CHECK:
02080         case CMD_DISABLE_HOST_CHECK:
02081         case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
02082         case CMD_SCHEDULE_HOST_DOWNTIME:
02083         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
02084         case CMD_DELAY_HOST_NOTIFICATION:
02085         case CMD_ENABLE_HOST_FLAP_DETECTION:
02086         case CMD_DISABLE_HOST_FLAP_DETECTION:
02087         case CMD_PROCESS_HOST_CHECK_RESULT:
02088         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
02089         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
02090         case CMD_SCHEDULE_HOST_CHECK:
02091         case CMD_START_OBSESSING_OVER_HOST:
02092         case CMD_STOP_OBSESSING_OVER_HOST:
02093 
02094                 if(cmd==CMD_SCHEDULE_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOST_SVC_DOWNTIME || enforce_comments_on_actions==TRUE) {
02095                         /* make sure we have author and comment data */
02096                         check_comment_sanity(&e);
02097 
02098                         /* make sure we have start/end times for downtime */
02099                         if(cmd==CMD_SCHEDULE_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOST_SVC_DOWNTIME)
02100                                 check_time_sanity(&e);
02101 
02102                         /* clean up the comment data if scheduling downtime */
02103                         clean_comment_data(comment_author);
02104                         clean_comment_data(comment_data);
02105                 }
02106 
02107                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02108 
02109                         cmd_has_objects = TRUE;
02110 
02111                         if (commands[x].host_name == NULL)
02112                                 continue;
02113 
02114                         /* see if the user is authorized to issue a command... */
02115                         is_authorized[x]=FALSE;
02116                         temp_host=find_host(commands[x].host_name);
02117                         if(is_authorized_for_host_commands(temp_host,&current_authdata)==TRUE)
02118                                 is_authorized[x]=TRUE;
02119                 }
02120 
02121                 /* make sure we have a notification delay (if necessary) */
02122                 if(cmd==CMD_DELAY_HOST_NOTIFICATION && notification_delay<=0)
02123                         error[e++].message=strdup("Notification delay must be greater than 0");
02124 
02125                 /* make sure we have check time (if necessary) */
02126                 if((cmd==CMD_SCHEDULE_HOST_CHECK || cmd==CMD_SCHEDULE_HOST_SVC_CHECKS) && start_time==(time_t)0)
02127                         error[e++].message=strdup("Start time must be non-zero or bad format has been submitted");
02128 
02129                 /* make sure we have passive check info (if necessary) */
02130                 if(cmd==CMD_PROCESS_HOST_CHECK_RESULT && !strcmp(plugin_output,""))
02131                         error[e++].message=strdup("Check output cannot be blank");
02132 
02133                 break;
02134 
02135         case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
02136         case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
02137         case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
02138         case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
02139         case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
02140         case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
02141         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
02142         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
02143         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
02144         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
02145         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
02146         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
02147         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
02148         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
02149         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
02150         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
02151 
02152 
02153                 if(cmd==CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME \
02154                 || cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME || cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME){
02155                         /* make sure we have author and comment data */
02156                         check_comment_sanity(&e);
02157 
02158                         /* make sure we have start/end times for downtime */
02159                         check_time_sanity(&e);
02160 
02161                         /* clean up the comment data if scheduling downtime */
02162                         clean_comment_data(comment_author);
02163                         clean_comment_data(comment_data);
02164                 } else if (enforce_comments_on_actions==TRUE) {
02165                         check_comment_sanity(&e);
02166                         clean_comment_data(comment_author);
02167                         clean_comment_data(comment_data);
02168                 }
02169 
02170                 /* see if the user is authorized to issue a command... */
02171                 is_authorized[x]=FALSE;
02172                 if(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS  || cmd==CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS || \
02173                    cmd==CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS || cmd==CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS || \
02174                    cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS         || cmd==CMD_DISABLE_HOSTGROUP_SVC_CHECKS || \
02175                    cmd==CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME    || cmd==CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME ){
02176                         temp_hostgroup=find_hostgroup(hostgroup_name);
02177                         if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==TRUE)
02178                                 is_authorized[x]=TRUE;
02179                 } else {
02180                         temp_servicegroup=find_servicegroup(servicegroup_name);
02181                         if(is_authorized_for_servicegroup(temp_servicegroup,&current_authdata)==TRUE)
02182                                 is_authorized[x]=TRUE;
02183                 }
02184 
02185                 break;
02186 
02187         default:
02188                 print_generic_error_message("Sorry Dave, I can't let you do that...","Executing an unknown command? Shame on you!",2);
02189 
02190                 return;
02191         }
02192 
02193 
02194         /*
02195          * these are supposed to be implanted inside the
02196          * completed commands shipped off to Icinga and
02197          * must therefore never contain ';'
02198          */
02199         for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02200                 if (commands[x].host_name == NULL)
02201                         continue;
02202 
02203                 if (strchr(commands[x].host_name, ';')) {
02204                         snprintf(error_string,sizeof(error_string),"The hostname \"%s\" contains a semicolon",commands[x].host_name);
02205                         error_string[sizeof(error_string)-1]='\x0';
02206                         error[e++].message=(char *)strdup(error_string);
02207                 }
02208                 if (commands[x].description != NULL && strchr(commands[x].description, ';')) {
02209                         snprintf(error_string,sizeof(error_string),"The service description \"%s\" on host \"%s\" contains a semicolon",commands[x].description,commands[x].host_name);
02210                         error_string[sizeof(error_string)-1]='\x0';
02211                         error[e++].message=strdup(error_string);
02212                 }
02213         }
02214         if (hostgroup_name && strchr(hostgroup_name, ';'))
02215                 error[e++].message=strdup("The hostgroup name contains a semicolon");
02216         if (servicegroup_name && strchr(servicegroup_name, ';'))
02217                 error[e++].message=strdup("The servicegroup name  contains a semicolon");
02218 
02219         printf("<BR><DIV align='center'>\n");
02220 
02221         /* if Icinga isn't checking external commands, don't do anything... */
02222         if(check_external_commands==FALSE){
02223                 print_generic_error_message("Sorry, but Icinga is currently not checking for external commands, so your command will not be committed!","Read the documentation for information on how to enable external commands...",2);
02224 
02225                 return;
02226         }
02227 
02228         /* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
02229         if(use_authentication==FALSE){
02230                 print_generic_error_message("Sorry Dave, I can't let you do that...","It seems that you have chosen to not use the authentication functionality of the CGIs. I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to Icinga, so you'll have to disable this safeguard if you are really stubborn and want to invite trouble. Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.",2);
02231 
02232                 return;
02233         }
02234 
02235         /* Check if we found errors which preventing us from submiting the command */
02236         if(e>0) {
02237                 printf("<DIV CLASS='errorBox'>\n");
02238                 printf("<DIV CLASS='errorMessage'><table cellspacing=0 cellpadding=0 border=0><tr><td width=55><img src=\"%s%s\" border=0></td>",url_images_path,CMD_STOP_ICON);
02239                 printf("<td CLASS='errorMessage'>Following errors occured.</td></tr></table></DIV>\n");
02240                 printf("<table cellspacing=0 cellpadding=0 border=0 class='errorTable'>\n");
02241                 for (e=0; e<NUMBER_OF_STRUCTS; e++) {
02242                         if (error[e].message==NULL)
02243                                 continue;
02244                         if(content_type==WML_CONTENT)
02245                                 printf("<p>Error: %s</p><BR>\n",error[e].message);
02246                         else {
02247                                 printf("<tr><td class='errorString'>ERROR:</td><td class='errorContent'>%s</td></tr>\n",error[e].message);
02248                         }
02249                 }
02250                 printf("</table>\n</DIV>\n");
02251                 printf("<BR>\n");
02252                 printf("<table cellspacing=0 cellpadding=0 border=0 class='BoxWidth'><tr>\n");
02253                 printf("<td align='left' width='50%%'><input type='submit' value='< Go back and fix it' onClick='window.history.go(-1);' class='submitButton'></td>\n");
02254                 printf("<td align='right' width='50%%'><input type='submit' value='Get me out of here' onClick='window.history.go(-2);' class='submitButton'></td>\n");
02255                 printf("</tr></table></DIV>");
02256                 return;
02257         }
02258 
02259         /* Let's see if we have a command witch dosn't have any host, services or downtime/comment id's and check the authorisation */
02260         if (cmd_has_objects == FALSE && is_authorized[0]==FALSE ) {
02261                 print_generic_error_message("Sorry, but you are not authorized to commit the specified command.","Read the section of the documentation that deals with authentication and authorization in the CGIs for more information.",2);
02262 
02263                 return;
02264         }
02265 
02266         /* everything looks okay, so let's go ahead and commit the command... */
02267         commit_command(cmd);
02268 
02269         /* for commands without objects get the first result*/
02270         if(cmd_has_objects == FALSE) {
02271                 if (submit_result[0]==OK){
02272                         if(content_type==WML_CONTENT)
02273                                 printf("<p>Your command was submitted sucessfully...</p>\n");
02274                         else{
02275                                 printf("<DIV CLASS='successBox'>\n");
02276                                 printf("<DIV CLASS='successMessage'>Your command request was successfully submitted to %s for processing.<BR><BR>\n",PROGRAM_NAME);
02277                                 printf("Note: It may take a while before the command is actually processed.</DIV>\n");
02278                                 printf("</DIV>\n");
02279                                 printf("<BR><input type='submit' value='Done' onClick='window.history.go(-2);' class='submitButton'></DIV>\n");
02280                         }
02281                 }else{
02282                         print_generic_error_message("An error occurred while attempting to commit your command for processing.","Unfortunately I can't determine the root cause of this problem.",2);
02283                 }
02284         } else {
02285                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02286                         if (cmd==CMD_DEL_HOST_COMMENT || cmd==CMD_DEL_SVC_COMMENT || cmd==CMD_DEL_HOST_DOWNTIME || cmd==CMD_DEL_SVC_DOWNTIME ) {
02287                                 if (multi_ids[x] == FALSE)
02288                                         continue;
02289                         } else {
02290                                 if (commands[x].host_name == NULL)
02291                                         continue;
02292                         }
02293 
02294                         if (is_authorized[x] == FALSE || submit_result[x] == ERROR) {
02295                                 error_found=TRUE;
02296                                 break;
02297                         }
02298                 }
02299 
02300                 if (error_found) {
02301                         print_generic_error_message("An error occurred while attempting to commit your command for processing.","Not all commands could be send off successfully...",0);
02302                 } else {
02303                         printf("<DIV CLASS='successBox'>\n");
02304                         printf("<DIV CLASS='successMessage'>Your command requests were successfully submitted to %s for processing.<BR><BR>\n",PROGRAM_NAME);
02305                         printf("Note: It may take a while before the commands are actually processed.</DIV>\n");
02306                         printf("</DIV>\n");
02307                 }
02308 
02309                 printf("<BR>\n");
02310                 printf("<TABLE CELLSPACING='0' CELLPADDING=0 BORDER=0 CLASS='BoxWidth'>\n");
02311                 printf("<tr class='BoxWidth'><td width='33%%'></td><td width='33%%' align='center'><input type='submit' value='Done' onClick='window.history.go(-2);' class='submitButton'></td><td width='33%%' align='right'>\n");
02312                 if (!error_found)
02313                         printf("<input type='submit' value='Let me see what has been done' onClick=\"document.getElementById('sumCommit').style.display = '';\" class='submitButton'>\n");
02314                 printf("</td></TR></TABLE>\n");
02315                 printf("<BR><BR>\n");
02316 
02317                 printf("<TABLE CELLSPACING='0' CELLPADDING='0' ID='sumCommit' %s><TR><TD CLASS='boxFrame BoxWidth'>\n",(error_found)?"":"style='display:none;'");
02318                 printf("<table cellspacing=2 cellpadding=0 border=0 class='contentTable'>\n");
02319                 if (cmd==CMD_DEL_HOST_COMMENT || cmd==CMD_DEL_SVC_COMMENT)
02320                         printf("<tr class='sumHeader'><td width='80%%'>Comment ID</td><td width='20%%'>Status</td></tr>\n");
02321                 else if (cmd==CMD_DEL_HOST_DOWNTIME || cmd==CMD_DEL_SVC_DOWNTIME)
02322                         printf("<tr class='sumHeader'><td width='80%%'>Downtime ID</td><td width='20%%'>Status</td></tr>\n");
02323                 else
02324                         printf("<tr class='sumHeader'><td width='40%%'>Host</td><td width='40%%'>Service</td><td width='20%%'>Status</td></tr>\n");
02325 
02326                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02327 
02328                         if (cmd==CMD_DEL_HOST_COMMENT || cmd==CMD_DEL_SVC_COMMENT || cmd==CMD_DEL_HOST_DOWNTIME || cmd==CMD_DEL_SVC_DOWNTIME) {
02329                                 if (multi_ids[x] == FALSE)
02330                                         continue;
02331                                 row_color = (row_color==0)?1:0;
02332                                 printf("<tr class='status%s'><td>%lu</td><td>",(row_color==0)?"Even":"Odd ",multi_ids[x]);
02333                         } else {
02334                                 if (commands[x].host_name == NULL)
02335                                         continue;
02336                                 row_color = (row_color==0)?1:0;
02337 
02338                                 printf("<tr class='status%s'><td>%s</td><td>%s</td><td>",(row_color==0)?"Even":"Odd ",commands[x].host_name,(commands[x].description != NULL)?commands[x].description:"N/A");
02339                         }
02340                         if (is_authorized[x] == FALSE)
02341                                 printf("<DIV class='commitFailed'>Not Authorized</DIV>");
02342                         else if (submit_result[x] == ERROR)
02343                                 printf("<DIV class='commitFailed'>FAILED</DIV>");
02344                         else if (submit_result[x] == OK)
02345                                 printf("<DIV class='commitSuccess'>Successful</DIV>");
02346                         else
02347                                 printf("<DIV class='commitUnknown'>Unknown</DIV>");
02348 
02349                         printf("</TD><TR>\n");
02350                 }
02351                 printf("</TABLE>\n");
02352                 printf("</TD></TR></TABLE></DIV>\n");
02353         }
02354         return;
02355 }
02356 
02357 
02362 __attribute__((format(printf, 2, 3)))
02363 static int cmd_submitf(int id, const char *fmt, ...){
02364         char cmd[MAX_EXTERNAL_COMMAND_LENGTH];
02365         const char *command;
02366         int len, len2;
02367         va_list ap;
02368 
02369         command = extcmd_get_name(id);
02370         /*
02371          * We disallow sending 'CHANGE' commands from the cgi's
02372          * until we do proper session handling to prevent cross-site
02373          * request forgery
02374          */
02375         if (!command || (strlen(command) > 6 && !memcmp("CHANGE", command, 6)))
02376                 return ERROR;
02377 
02378         if(log_external_commands_user==TRUE){
02379                 get_authentication_information(&current_authdata);
02380                 len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;%s;", time(NULL), command, current_authdata.username);
02381         } else {
02382                 len = snprintf(cmd, sizeof(cmd) - 1, "[%lu] %s;", time(NULL), command);
02383         }
02384 
02385         if (len < 0)
02386                 return ERROR;
02387 
02388         if(fmt) {
02389                 va_start(ap, fmt);
02390                 len2 = vsnprintf(&cmd[len], sizeof(cmd) - len - 1, fmt, ap);
02391                 va_end(ap);
02392                 if (len2 < 0)
02393                         return ERROR;
02394         }
02395 
02396         return write_command_to_file(cmd);
02397 }
02398 
02399 int commit_command(int cmd){
02400         time_t current_time;
02401         time_t scheduled_time;
02402         time_t notification_time;
02403         int x = 0;
02404 
02405         /* get the current time */
02406         time(&current_time);
02407 
02408         /* get the scheduled time */
02409         scheduled_time=current_time+(schedule_delay*60);
02410 
02411         /* get the notification time */
02412         notification_time=current_time+(notification_delay*60);
02413 
02414         /* decide how to form the command line... */
02415         switch(cmd){
02416 
02417                 /* commands without arguments */
02418         case CMD_START_EXECUTING_SVC_CHECKS:
02419         case CMD_STOP_EXECUTING_SVC_CHECKS:
02420         case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
02421         case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
02422         case CMD_ENABLE_EVENT_HANDLERS:
02423         case CMD_DISABLE_EVENT_HANDLERS:
02424         case CMD_START_OBSESSING_OVER_SVC_CHECKS:
02425         case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
02426         case CMD_ENABLE_FLAP_DETECTION:
02427         case CMD_DISABLE_FLAP_DETECTION:
02428         case CMD_ENABLE_FAILURE_PREDICTION:
02429         case CMD_DISABLE_FAILURE_PREDICTION:
02430         case CMD_ENABLE_PERFORMANCE_DATA:
02431         case CMD_DISABLE_PERFORMANCE_DATA:
02432         case CMD_START_EXECUTING_HOST_CHECKS:
02433         case CMD_STOP_EXECUTING_HOST_CHECKS:
02434         case CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS:
02435         case CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS:
02436         case CMD_START_OBSESSING_OVER_HOST_CHECKS:
02437         case CMD_STOP_OBSESSING_OVER_HOST_CHECKS:
02438                 if (is_authorized[x])
02439                         submit_result[x] = cmd_submitf(cmd,NULL);
02440                 break;
02441 
02442                 /* simple host commands */
02443         case CMD_ENABLE_HOST_FLAP_DETECTION:
02444         case CMD_DISABLE_HOST_FLAP_DETECTION:
02445         case CMD_ENABLE_PASSIVE_HOST_CHECKS:
02446         case CMD_DISABLE_PASSIVE_HOST_CHECKS:
02447         case CMD_START_OBSESSING_OVER_HOST:
02448         case CMD_STOP_OBSESSING_OVER_HOST:
02449         case CMD_DEL_ALL_HOST_COMMENTS:
02450         case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
02451         case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
02452         case CMD_ENABLE_HOST_EVENT_HANDLER:
02453         case CMD_DISABLE_HOST_EVENT_HANDLER:
02454         case CMD_ENABLE_HOST_CHECK:
02455         case CMD_DISABLE_HOST_CHECK:
02456         case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
02457                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02458                         if (commands[x].host_name == NULL)
02459                                 continue;
02460                         if (is_authorized[x])
02461                                 submit_result[x] = cmd_submitf(cmd,"%s",commands[x].host_name);
02462                 }
02463                 break;
02464 
02465                 /* simple service commands */
02466         case CMD_ENABLE_SVC_FLAP_DETECTION:
02467         case CMD_DISABLE_SVC_FLAP_DETECTION:
02468         case CMD_ENABLE_PASSIVE_SVC_CHECKS:
02469         case CMD_DISABLE_PASSIVE_SVC_CHECKS:
02470         case CMD_START_OBSESSING_OVER_SVC:
02471         case CMD_STOP_OBSESSING_OVER_SVC:
02472         case CMD_DEL_ALL_SVC_COMMENTS:
02473         case CMD_ENABLE_SVC_NOTIFICATIONS:
02474         case CMD_DISABLE_SVC_NOTIFICATIONS:
02475         case CMD_ENABLE_SVC_EVENT_HANDLER:
02476         case CMD_DISABLE_SVC_EVENT_HANDLER:
02477         case CMD_ENABLE_SVC_CHECK:
02478         case CMD_DISABLE_SVC_CHECK:
02479         case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
02480                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02481                         if (commands[x].host_name == NULL)
02482                                 continue;
02483                         if (is_authorized[x])
02484                                 submit_result[x] = cmd_submitf(cmd,"%s;%s",commands[x].host_name,commands[x].description);
02485                 }
02486                 break;
02487 
02488         case CMD_ADD_HOST_COMMENT:
02489                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02490                         if (commands[x].host_name == NULL)
02491                                 continue;
02492                         if (is_authorized[x])
02493                                 submit_result[x] = cmd_submitf(cmd,"%s;%d;%s;%s",commands[x].host_name,persistent_comment,comment_author,comment_data);
02494                 }
02495                 break;
02496 
02497         case CMD_ADD_SVC_COMMENT:
02498                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02499                         if (commands[x].host_name == NULL)
02500                                 continue;
02501                         if (is_authorized[x])
02502                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%d;%s;%s",commands[x].host_name,commands[x].description,persistent_comment,comment_author,comment_data);
02503                 }
02504                 break;
02505 
02506         case CMD_DEL_HOST_COMMENT:
02507         case CMD_DEL_SVC_COMMENT:
02508         case CMD_DEL_HOST_DOWNTIME:
02509         case CMD_DEL_SVC_DOWNTIME:
02510                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02511                         if (multi_ids[x] == FALSE)
02512                                 continue;
02513                         if (is_authorized[x])
02514                                 submit_result[x] = cmd_submitf(cmd,"%lu",multi_ids[x]);
02515                 }
02516                 break;
02517 
02518         case CMD_DELAY_HOST_NOTIFICATION:
02519                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02520                         if (commands[x].host_name == NULL)
02521                                 continue;
02522                         if (is_authorized[x])
02523                                 submit_result[x] = cmd_submitf(cmd,"%s;%lu",commands[x].host_name,notification_time);
02524                 }
02525                 break;
02526 
02527         case CMD_DELAY_SVC_NOTIFICATION:
02528                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02529                         if (commands[x].host_name == NULL)
02530                                 continue;
02531                         if (is_authorized[x])
02532                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%lu",commands[x].host_name,commands[x].description,notification_time);
02533                 }
02534                 break;
02535 
02536         case CMD_SCHEDULE_SVC_CHECK:
02537         case CMD_SCHEDULE_FORCED_SVC_CHECK:
02538                 if(force_check==TRUE)
02539                         cmd=CMD_SCHEDULE_FORCED_SVC_CHECK;
02540                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02541                         if (commands[x].host_name == NULL)
02542                                 continue;
02543                         if (is_authorized[x])
02544                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%lu",commands[x].host_name,commands[x].description,start_time);
02545                 }
02546                 break;
02547 
02548         case CMD_DISABLE_NOTIFICATIONS:
02549         case CMD_ENABLE_NOTIFICATIONS:
02550         case CMD_SHUTDOWN_PROCESS:
02551         case CMD_RESTART_PROCESS:
02552                 if (is_authorized[x])
02553                         submit_result[x] = cmd_submitf(cmd,"%lu",scheduled_time);
02554                 break;
02555 
02556         case CMD_ENABLE_HOST_SVC_CHECKS:
02557         case CMD_DISABLE_HOST_SVC_CHECKS:
02558                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02559                         if (commands[x].host_name == NULL)
02560                                 continue;
02561                         if (is_authorized[x])
02562                                 submit_result[x] = cmd_submitf(cmd,"%s",commands[x].host_name);
02563                 }
02564                 if(affect_host_and_services==TRUE){
02565                         cmd = (cmd == CMD_ENABLE_HOST_SVC_CHECKS) ? CMD_ENABLE_HOST_CHECK : CMD_DISABLE_HOST_CHECK;
02566                         for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02567                                 if (commands[x].host_name == NULL)
02568                                         continue;
02569                                 if (is_authorized[x])
02570                                         submit_result[x] |= cmd_submitf(cmd,"%s",commands[x].host_name);
02571                         }
02572                 }
02573                 break;
02574 
02575         case CMD_SCHEDULE_HOST_SVC_CHECKS:
02576                 if (force_check == TRUE)
02577                         cmd = CMD_SCHEDULE_FORCED_HOST_SVC_CHECKS;
02578                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02579                         if (commands[x].host_name == NULL)
02580                                 continue;
02581                         if (is_authorized[x])
02582                                 submit_result[x] = cmd_submitf(cmd,"%s;%lu",commands[x].host_name,scheduled_time);
02583                 }
02584                 break;
02585 
02586         case CMD_ENABLE_HOST_NOTIFICATIONS:
02587         case CMD_DISABLE_HOST_NOTIFICATIONS:
02588                 if(propagate_to_children==TRUE)
02589                         cmd = (cmd == CMD_ENABLE_HOST_NOTIFICATIONS) ? CMD_ENABLE_HOST_AND_CHILD_NOTIFICATIONS : CMD_DISABLE_HOST_AND_CHILD_NOTIFICATIONS;
02590                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02591                         if (commands[x].host_name == NULL)
02592                                 continue;
02593                         if (is_authorized[x])
02594                                 submit_result[x] = cmd_submitf(cmd,"%s",commands[x].host_name);
02595                 }
02596                 break;
02597 
02598         case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
02599         case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
02600                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02601                         if (commands[x].host_name == NULL)
02602                                 continue;
02603                         if (is_authorized[x])
02604                                 submit_result[x] = cmd_submitf(cmd,"%s",commands[x].host_name);
02605                 }
02606                 if(affect_host_and_services==TRUE){
02607                         cmd = (cmd == CMD_ENABLE_HOST_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOST_NOTIFICATIONS : CMD_DISABLE_HOST_NOTIFICATIONS;
02608                         for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02609                                 if (commands[x].host_name == NULL)
02610                                         continue;
02611                                 if (is_authorized[x])
02612                                         submit_result[x] |= cmd_submitf(cmd,"%s",commands[x].host_name);
02613                         }
02614                 }
02615                 break;
02616 
02617         case CMD_ACKNOWLEDGE_HOST_PROBLEM:
02618                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02619                         if (commands[x].host_name == NULL)
02620                                 continue;
02621                         if (is_authorized[x])
02622                                 submit_result[x] = cmd_submitf(cmd,"%s;%d;%d;%d;%s;%s",commands[x].host_name,(sticky_ack==TRUE)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL,send_notification,persistent_comment,comment_author,comment_data);
02623                 }
02624                 break;
02625 
02626         case CMD_ACKNOWLEDGE_SVC_PROBLEM:
02627                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02628                         if (commands[x].host_name == NULL)
02629                                 continue;
02630                         if (is_authorized[x])
02631                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%d;%d;%d;%s;%s",commands[x].host_name,commands[x].description,(sticky_ack==TRUE)?ACKNOWLEDGEMENT_STICKY:ACKNOWLEDGEMENT_NORMAL,send_notification,persistent_comment,comment_author,comment_data);
02632                 }
02633                 break;
02634 
02635         case CMD_PROCESS_SERVICE_CHECK_RESULT:
02636                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02637                         if (commands[x].host_name == NULL)
02638                                 continue;
02639                         if (is_authorized[x])
02640                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%d;%s|%s",commands[x].host_name,commands[x].description,plugin_state,plugin_output,performance_data);
02641                 }
02642                 break;
02643 
02644         case CMD_PROCESS_HOST_CHECK_RESULT:
02645                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02646                         if (commands[x].host_name == NULL)
02647                                 continue;
02648                         if (is_authorized[x])
02649                                 submit_result[x] = cmd_submitf(cmd,"%s;%d;%s|%s",commands[x].host_name,plugin_state,plugin_output,performance_data);
02650                 }
02651                 break;
02652 
02653         case CMD_SCHEDULE_HOST_DOWNTIME:
02654                 if(child_options==1)
02655                         cmd = CMD_SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME;
02656                 else if (child_options == 2)
02657                         cmd = CMD_SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME;
02658                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02659                         if (commands[x].host_name == NULL)
02660                                 continue;
02661                         if (is_authorized[x])
02662                                 submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;%lu;%lu;%s;%s",commands[x].host_name,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
02663                 }
02664                 break;
02665 
02666         case CMD_SCHEDULE_HOST_SVC_DOWNTIME:
02667                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02668                         if (commands[x].host_name == NULL)
02669                                 continue;
02670                         if (is_authorized[x])
02671                                 submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;%lu;%lu;%s;%s",commands[x].host_name,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
02672                 }
02673                 break;
02674 
02675         case CMD_SCHEDULE_SVC_DOWNTIME:
02676                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02677                         if (commands[x].host_name == NULL)
02678                                 continue;
02679                         if (is_authorized[x])
02680                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%lu;%lu;%d;%lu;%lu;%s;%s",commands[x].host_name,commands[x].description,start_time,end_time,fixed,triggered_by,duration,comment_author,comment_data);
02681                 }
02682                 break;
02683 
02684         case CMD_SCHEDULE_HOST_CHECK:
02685                 if (force_check == TRUE)
02686                         cmd = CMD_SCHEDULE_FORCED_HOST_CHECK;
02687                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02688                         if (commands[x].host_name == NULL)
02689                                 continue;
02690                         if (is_authorized[x])
02691                                 submit_result[x] = cmd_submitf(cmd,"%s;%lu",commands[x].host_name,start_time);
02692                 }
02693                 break;
02694 
02695         case CMD_SEND_CUSTOM_HOST_NOTIFICATION:
02696                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02697                         if (commands[x].host_name == NULL)
02698                                 continue;
02699                         if (is_authorized[x])
02700                                 submit_result[x] = cmd_submitf(cmd,"%s;%d;%s;%s",commands[x].host_name,(force_notification | broadcast_notification),comment_author,comment_data);
02701                 }
02702                 break;
02703 
02704         case CMD_SEND_CUSTOM_SVC_NOTIFICATION:
02705                 for ( x = 0; x < NUMBER_OF_STRUCTS; x++ ) {
02706                         if (commands[x].host_name == NULL)
02707                                 continue;
02708                         if (is_authorized[x])
02709                                 submit_result[x] = cmd_submitf(cmd,"%s;%s;%d;%s;%s",commands[x].host_name,commands[x].description,(force_notification | broadcast_notification),comment_author,comment_data);
02710                 }
02711                 break;
02712 
02713 
02714                 /***** HOSTGROUP COMMANDS *****/
02715 
02716         case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
02717         case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
02718                 if (is_authorized[x])
02719                         submit_result[x] = cmd_submitf(cmd,"%s",hostgroup_name);
02720                 if(affect_host_and_services==TRUE){
02721                         cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS;
02722                         if (is_authorized[x])
02723                                 submit_result[x] |= cmd_submitf(cmd,"%s",hostgroup_name);
02724                 }
02725                 break;
02726 
02727         case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
02728         case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
02729                 if (is_authorized[x])
02730                         submit_result[x] = cmd_submitf(cmd,"%s",hostgroup_name);
02731                 break;
02732 
02733         case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
02734         case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
02735                 if (is_authorized[x])
02736                         submit_result[x] = cmd_submitf(cmd,"%s",hostgroup_name);
02737                 if(affect_host_and_services==TRUE){
02738                         cmd = (cmd == CMD_ENABLE_HOSTGROUP_SVC_CHECKS) ? CMD_ENABLE_HOSTGROUP_HOST_CHECKS : CMD_DISABLE_HOSTGROUP_HOST_CHECKS;
02739                         if (is_authorized[x])
02740                                 submit_result[x] |= cmd_submitf(cmd,"%s",hostgroup_name);
02741                 }
02742                 break;
02743 
02744         case CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME:
02745                 if (is_authorized[x])
02746                         submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;0;%lu;%s;%s",hostgroup_name,start_time,end_time,fixed,duration,comment_author,comment_data);
02747                 break;
02748 
02749         case CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME:
02750                 if (is_authorized[x])
02751                         submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;0;%lu;%s;%s",hostgroup_name,start_time,end_time,fixed,duration,comment_author,comment_data);
02752                 if(affect_host_and_services==TRUE) {
02753                         if (is_authorized[x])
02754                                 submit_result[x] |= 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);
02755                 }
02756                 break;
02757 
02758 
02759                 /***** SERVICEGROUP COMMANDS *****/
02760 
02761         case CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
02762         case CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS:
02763                 if (is_authorized[x])
02764                         submit_result[x] = cmd_submitf(cmd,"%s",servicegroup_name);
02765                 if(affect_host_and_services==TRUE){
02766                         cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS) ? CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS : CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS;
02767                         if (is_authorized[x])
02768                                 submit_result[x] |= cmd_submitf(cmd,"%s",servicegroup_name);
02769                 }
02770                 break;
02771 
02772         case CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
02773         case CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS:
02774                 if (is_authorized[x])
02775                         submit_result[x] = cmd_submitf(cmd,"%s",servicegroup_name);
02776                 break;
02777 
02778         case CMD_ENABLE_SERVICEGROUP_SVC_CHECKS:
02779         case CMD_DISABLE_SERVICEGROUP_SVC_CHECKS:
02780                 if (is_authorized[x])
02781                         submit_result[x] = cmd_submitf(cmd,"%s",servicegroup_name);
02782                 if(affect_host_and_services==TRUE){
02783                         cmd = (cmd == CMD_ENABLE_SERVICEGROUP_SVC_CHECKS) ? CMD_ENABLE_SERVICEGROUP_HOST_CHECKS : CMD_DISABLE_SERVICEGROUP_HOST_CHECKS;
02784                         if (is_authorized[x])
02785                                 submit_result[x] |= cmd_submitf(cmd,"%s",servicegroup_name);
02786                 }
02787                 break;
02788 
02789         case CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME:
02790                 if (is_authorized[x])
02791                         submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;0;%lu;%s;%s",servicegroup_name,start_time,end_time,fixed,duration,comment_author,comment_data);
02792                 break;
02793 
02794         case CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME:
02795                 if (is_authorized[x])
02796                         submit_result[x] = cmd_submitf(cmd,"%s;%lu;%lu;%d;0;%lu;%s;%s",servicegroup_name,start_time,end_time,fixed,duration,comment_author,comment_data);
02797                 if(affect_host_and_services==TRUE) {
02798                         if (is_authorized[x])
02799                                 submit_result[x] |= 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);
02800                 }
02801                 break;
02802 
02803         default:
02804                 submit_result[x] = ERROR;
02805                 break;
02806         }
02807 
02808         return OK;
02809 }
02810 
02811 int write_command_to_file(char *cmd){
02812         char buffer[MAX_INPUT_BUFFER];
02813         char ip_address[16];
02814         char *p;
02815         FILE *fp;
02816         struct stat statbuf;
02817         char error_string[MAX_INPUT_BUFFER];
02818 
02819         /*
02820          * Commands are not allowed to have newlines in them, as
02821          * that allows malicious users to hand-craft requests that
02822          * bypass the access-restrictions.
02823          */
02824         if (!cmd || !*cmd || strchr(cmd, '\n'))
02825                 return ERROR;
02826 
02827         /* bail out if the external command file doesn't exist */
02828         if(stat(command_file,&statbuf)){
02829                 snprintf(error_string,sizeof(error_string),"Error: Could not stat() command file '%s'!",command_file);
02830                 error_string[sizeof(error_string)-1]='\x0';
02831 
02832                 print_generic_error_message(error_string,"The external command file may be missing, Icinga may not be running, and/or Icinga may not be checking external commands.",2);
02833 
02834                 return ERROR;
02835         }
02836 
02837         /* open the command for writing (since this is a pipe, it will really be appended) */
02838         fp=fopen(command_file,"w");
02839         if(fp==NULL){
02840                 snprintf(error_string,sizeof(error_string),"Error: Could not open command file '%s' for update!",command_file);
02841                 error_string[sizeof(error_string)-1]='\x0';
02842 
02843                 print_generic_error_message(error_string,"The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.",2);
02844 
02845                 return ERROR;
02846         }
02847 
02848         // get remote address
02849         sprintf(ip_address,"%s",getenv("REMOTE_ADDR"));
02850 
02851         /* write command to cgi log */
02852         sprintf(buffer, "EXTERNAL COMMAND: %s;%s;", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address");
02853         p = index(cmd, ']');
02854         if (p!=NULL)
02855                 p+=2;
02856         else
02857                 p=&cmd[0];
02858         strncat(buffer, p, sizeof(buffer)-strlen(buffer)-1);
02859         write_to_cgi_log(buffer);
02860 
02861         /* log comments if forced */
02862         if(enforce_comments_on_actions==TRUE) {
02863                 sprintf(buffer, "FORCED COMMENT: %s;%s;%s;%s", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address",comment_author,comment_data);
02864                 write_to_cgi_log(buffer);
02865         }
02866 
02867         /* write the command to file */
02868         fprintf(fp, "%s\n", cmd);
02869 
02870         /* flush buffer */
02871         fflush(fp);
02872 
02873         fclose(fp);
02874 
02875         return OK;
02876 }
02877 
02878 void clean_comment_data(char *buffer){
02879         int x;
02880         int y;
02881 
02882         y=(int)strlen(buffer);
02883 
02884         for(x=0;x<y;x++){
02885                 if(buffer[x]==';' || buffer[x]=='\n' || buffer[x]=='\r' )
02886                         buffer[x]=' ';
02887         }
02888 
02889         return;
02890 }
02891 
02892 void check_comment_sanity(int *e){
02893         if(!strcmp(comment_author,""))
02894                 error[(*e)++].message=strdup("Author name was not entered");
02895         if(!strcmp(comment_data,""))
02896                 error[(*e)++].message=strdup("Comment data was not entered");
02897 
02898         return;
02899 }
02900 
02901 void check_time_sanity(int *e) {
02902         if (start_time==(time_t)0)
02903                 error[(*e)++].message=strdup("Start time can't be zero or date format couldn't be recognized correctly");
02904         if (end_time==(time_t)0)
02905                 error[(*e)++].message=strdup("End time can't be zero or date format couldn't be recognized correctly");
02906         if (end_time<start_time)
02907                 error[(*e)++].message=strdup("End date before start date");
02908 
02909         return;
02910 }
 All Data Structures Files Functions Variables Typedefs Defines