--- config.c.orig 2009-05-15 16:02:47.000000000 +0200 +++ config.c 2010-08-24 22:34:47.000000000 +0200 @@ -65,6 +65,7 @@ #define DISPLAY_HOSTDEPENDENCIES 11 #define DISPLAY_HOSTESCALATIONS 12 #define DISPLAY_SERVICEGROUPS 15 +#define DISPLAY_COMMAND_EXPANSION 16211 void document_header(int); void document_footer(void); @@ -84,6 +85,7 @@ void display_serviceescalations(void); void display_hostdependencies(void); void display_hostescalations(void); +void display_command_expansion(void); void unauthorized_message(void); @@ -91,6 +93,9 @@ authdata current_authdata; int display_type=DISPLAY_NONE; +char full_command[MAX_COMMAND_BUFFER]; +char *command_args[MAX_COMMAND_ARGUMENTS]; +char hashed_color[8]; int embedded=FALSE; @@ -217,6 +222,10 @@ case DISPLAY_HOSTESCALATIONS: display_context_help(CONTEXTHELP_CONFIG_HOSTESCALATIONS); break; + case DISPLAY_COMMAND_EXPANSION: + /* Reusing DISPLAY_COMMANDS help until further notice */ + display_context_help(CONTEXTHELP_CONFIG_COMMANDS); + break; default: display_context_help(CONTEXTHELP_CONFIG_MENU); break; @@ -266,6 +275,9 @@ case DISPLAY_HOSTESCALATIONS: display_hostescalations(); break; + case DISPLAY_COMMAND_EXPANSION: + display_command_expansion(); + break; default: display_options(); break; @@ -382,12 +394,26 @@ display_type=DISPLAY_HOSTDEPENDENCIES; else if(!strcmp(variables[x],"hostescalations")) display_type=DISPLAY_HOSTESCALATIONS; + else if(!strcmp(variables[x],"command")) + display_type=DISPLAY_COMMAND_EXPANSION; /* we found the embed option */ else if(!strcmp(variables[x],"embedded")) embedded=TRUE; } + /* we found the command-to-expand argument */ + else if(!strcmp(variables[x],"expand")){ + x++; + if(variables[x]==NULL){ + error=TRUE; + break; + } + strncpy(full_command,variables[x],MAX_COMMAND_BUFFER); + full_command[MAX_COMMAND_BUFFER-1]='\0'; + } + + /* we received an invalid argument */ else error=TRUE; @@ -512,7 +538,8 @@ if(temp_host->host_check_command==NULL) printf(" "); else - printf("%s\n",CONFIG_CGI,url_encode(temp_host->host_check_command),html_encode(temp_host->host_check_command,FALSE)); + /* printf("%s\n",CONFIG_CGI,url_encode(strtok(temp_host->host_check_command,"!")),html_encode(temp_host->host_check_command,FALSE)); */ + printf("%s\n",CONFIG_CGI,url_encode(temp_host->host_check_command),html_encode(temp_host->host_check_command,FALSE)); printf("\n"); printf("",bg_class); @@ -601,7 +628,8 @@ if(temp_host->event_handler==NULL) printf(" "); else - printf("%s\n",CONFIG_CGI,url_encode(temp_host->event_handler),temp_host->event_handler); + /* printf("%s\n",CONFIG_CGI,url_encode(strtok(temp_host->event_handler,"!")),temp_host->event_handler); */ + printf("%s\n",CONFIG_CGI,url_encode(temp_host->event_handler),temp_host->event_handler); printf("\n"); printf("",bg_class); @@ -1015,7 +1043,8 @@ if(temp_commandsmember!=temp_contact->service_notification_commands) printf(", "); - printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); + /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_commandsmember->command,"!")),temp_commandsmember->command); */ + printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); found=TRUE; } @@ -1030,7 +1059,8 @@ if(temp_commandsmember!=temp_contact->host_notification_commands) printf(", "); - printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); + /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_commandsmember->command,"!")),temp_commandsmember->command); */ + printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); found=TRUE; } @@ -1232,7 +1262,8 @@ command_line[sizeof(command_line)-1]='\x0'; command_name=strtok(command_line,"!"); - printf("%s\n",bg_class,CONFIG_CGI,url_encode(command_name),html_encode(temp_service->service_check_command,FALSE)); + /* printf("%s\n",bg_class,CONFIG_CGI,url_encode(command_name),html_encode(temp_service->service_check_command,FALSE)); */ + printf("%s\n",bg_class,CONFIG_CGI,url_encode(temp_service->service_check_command),html_encode(temp_service->service_check_command,FALSE)); printf("",bg_class); if(temp_service->check_period==NULL) printf(" "); @@ -1326,7 +1357,8 @@ if(temp_service->event_handler==NULL) printf(" "); else - printf("%s",CONFIG_CGI,url_encode(temp_service->event_handler),temp_service->event_handler); + /* printf("%s",CONFIG_CGI,url_encode(strtok(temp_service->event_handler,"!")),temp_service->event_handler); */ + printf("%s",CONFIG_CGI,url_encode(temp_service->event_handler),temp_service->event_handler); printf("\n"); printf("",bg_class); @@ -2138,6 +2170,112 @@ +char *hash_color(int i){ + char c; + + /* This is actually optimized for MAX_COMMAND_ARGUMENTS==32 ... */ + + if ((i%32)<16){ + if ((i%32)<8) c='7'; else c='4'; + } else { + if ((i%32)<24) c='6'; else c='5'; + } + + /* Computation for standard case */ + hashed_color[0]='#'; + hashed_color[1]=hashed_color[2]=((i%2)?c:'0'); + hashed_color[3]=hashed_color[4]=(((i/2)%2)?c:'0'); + hashed_color[5]=hashed_color[6]=(((i/4)%2)?c:'0'); + hashed_color[7]='\0'; + + /* Override shades of grey */ + if ((i%8)==7) hashed_color[1]=hashed_color[3]='0'; + if ((i%8)==0) hashed_color[2]=hashed_color[3]=hashed_color[4]=hashed_color[6]=c; + + return(hashed_color); + } + +void display_command_expansion(void){ + command *temp_command; + int odd=0; + char *bg_class=""; + int i; + char *c, *cc; + char commandline[MAX_COMMAND_BUFFER]; + + /* see if user is authorized to view command information... */ + if(is_authorized_for_configuration_information(¤t_authdata)==FALSE){ + unauthorized_message(); + return; + } + + printf("

Command Expansion

\n"); + + /* Parse full_command into parts */ + for (i=0,c=full_command;i
\n"); + printf("\n"); + printf("\n"); + + printf("\n"); + + /* check all commands */ + for(temp_command=command_list;temp_command!=NULL;temp_command=temp_command->next){ + + if (!strcmp(temp_command->name,command_args[0])){ + + if(odd){ + odd=0; + bg_class="dataEven"; + } + else{ + odd=1; + bg_class="dataOdd"; + } + + printf("\n",bg_class); + + printf("\n",bg_class,url_encode(temp_command->name),temp_command->name); + printf("\n",bg_class,html_encode(temp_command->command_line,FALSE)); + + printf("\n\n",bg_class); + + printf("\n",bg_class); + printf("\n"); + } + + } + + printf("
Command NameCommand Line
To expand:%s",command_args[0]); + for (i=1;(i%s",hash_color(i),command_args[i]); + printf("\n
%s%s
->",bg_class); + strncpy(commandline,temp_command->command_line,MAX_COMMAND_BUFFER); + commandline[MAX_COMMAND_BUFFER-1]='\0'; + for (c=commandline;c&&(cc=strstr(c,"$ARG"));){ + (*cc)='\0'; + printf("%s",html_encode(c,FALSE)); + cc+=4; + c=strstr(cc,"$"); + i=atoi(cc); + if ((i>0)&&(i<=MAX_COMMAND_ARGUMENTS)){ + if (command_args[i]) printf("%s",hash_color(i),html_encode(command_args[i],FALSE)); + else printf("(undefined/empty)"); + } + else printf("(index error)"); + if (c) (*(c++))='\0'; + } + if (c) printf("%s",html_encode(c,FALSE)); + + printf("
\n"); + printf("

\n"); + + return; + } + + + void display_options(void){ printf("

\n");