Icinga-core 1.4.0
next gen monitoring
cgi/statuswml.c
Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * STATUSWML.C -  Icinga Status CGI for WAP-enabled devices
00004  *
00005  * Copyright (c) 2001-2008 Ethan Galstad (egalstad@nagios.org)
00006  * Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org)
00007  *
00008  * License:
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License version 2 as
00012  * published by the Free Software Foundation.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022  *************************************************************************/
00023 
00024 #include "../include/config.h"
00025 #include "../include/common.h"
00026 #include "../include/objects.h"
00027 #include "../include/statusdata.h"
00028 
00029 #include "../include/cgiutils.h"
00030 #include "../include/getcgi.h"
00031 #include "../include/cgiauth.h"
00032 
00033 extern time_t          program_start;
00034 
00035 extern char main_config_file[MAX_FILENAME_LENGTH];
00036 
00037 extern host *host_list;
00038 extern hostgroup *hostgroup_list;
00039 extern service *service_list;
00040 extern hoststatus *hoststatus_list;
00041 extern servicestatus *servicestatus_list;
00042 
00043 extern int      use_ssl_authentication;
00044 extern int      enable_notifications;
00045 extern int      execute_service_checks;
00046 extern int      nagios_process_state;
00047 
00048 extern char     *ping_syntax;
00049 
00050 #define DISPLAY_HOST                    0
00051 #define DISPLAY_SERVICE                 1
00052 #define DISPLAY_HOSTGROUP               2
00053 #define DISPLAY_INDEX                   3
00054 #define DISPLAY_PING                    4
00055 #define DISPLAY_TRACEROUTE              5
00056 #define DISPLAY_QUICKSTATS              6
00057 #define DISPLAY_PROCESS                 7
00058 #define DISPLAY_ALL_PROBLEMS            8
00059 #define DISPLAY_UNHANDLED_PROBLEMS      9
00060 
00061 #define DISPLAY_HOSTGROUP_SUMMARY       0
00062 #define DISPLAY_HOSTGROUP_OVERVIEW      1
00063 
00064 #define DISPLAY_HOST_SUMMARY            0
00065 #define DISPLAY_HOST_SERVICES           1
00066 
00067 int process_cgivars(void);
00068 int validate_arguments(void);
00069 int is_valid_hostip(char *hostip);
00070 
00071 int display_type=DISPLAY_INDEX;
00072 int show_all_hosts=TRUE;
00073 int show_all_hostgroups=TRUE;
00074 int show_all_servicegroups=TRUE;
00075 
00076 char *host_name=NULL;
00077 char *host_filter=NULL;
00078 char *hostgroup_name=NULL;
00079 char *servicegroup_name=NULL;
00080 char *service_desc=NULL;
00081 char *service_filter=NULL;
00082 int hostgroup_style=DISPLAY_HOSTGROUP_SUMMARY;
00083 int host_style=DISPLAY_HOST_SUMMARY;
00084 
00085 void display_index(void);
00086 void display_host(void);
00087 void display_host_services(void);
00088 void display_service(void);
00089 void display_hostgroup_summary(void);
00090 void display_hostgroup_overview(void);
00091 void display_ping(void);
00092 void display_traceroute(void);
00093 void display_quick_stats(void);
00094 void display_process(void);
00095 void display_problems(void);
00096 
00097 char *ping_address="";
00098 char *traceroute_address="";
00099 
00100 extern int daemon_check;
00101 
00102 char *dummy;    /* reduce compiler warnings */
00103 
00104 authdata current_authdata;
00105 
00106 int CGI_ID=STATUSWML_CGI_ID;
00107 
00108 int main(void){
00109         int result=OK;
00110         
00111         /* get the arguments passed in the URL */
00112         process_cgivars();
00113 
00114         /* reset internal variables */
00115         reset_cgi_vars();
00116 
00117         document_header(CGI_ID,TRUE);
00118 
00119         /* validate arguments in URL */
00120         result=validate_arguments();
00121         if(result==ERROR){
00122                 document_footer(CGI_ID);
00123                 return ERROR;
00124                 }
00125         
00126         /* read the CGI configuration file */
00127         result=read_cgi_config_file(get_cgi_config_location());
00128         if(result==ERROR){
00129                 printf("<P>Error: Could not open CGI configuration file '%s' for reading!</P>\n",get_cgi_config_location());
00130                 document_footer(CGI_ID);
00131                 return ERROR;
00132                 }
00133 
00134         /* read the main configuration file */
00135         result=read_main_config_file(main_config_file);
00136         if(result==ERROR){
00137                 printf("<P>Error: Could not open main configuration file '%s' for reading!</P>\n",main_config_file);
00138                 document_footer(CGI_ID);
00139                 return ERROR;
00140                 }
00141 
00142         /* read all object configuration data */
00143         result=read_all_object_configuration_data(main_config_file,READ_ALL_OBJECT_DATA);
00144         if(result==ERROR){
00145                 printf("<P>Error: Could not read some or all object configuration data!</P>\n");
00146                 document_footer(CGI_ID);
00147                 return ERROR;
00148                 }
00149 
00150         /* read all status data */
00151         result=read_all_status_data(get_cgi_config_location(),READ_ALL_STATUS_DATA);
00152         if(result==ERROR && daemon_check==TRUE){
00153                 printf("<P>Error: Could not read host and service status information!</P>\n");
00154                 document_footer(CGI_ID);
00155                 free_memory();
00156                 return ERROR;
00157                 }
00158 
00159         /* get authentication information */
00160         get_authentication_information(&current_authdata);
00161 
00162         /* decide what to display to the user */
00163         if(display_type==DISPLAY_HOST && host_style==DISPLAY_HOST_SERVICES)
00164                 display_host_services();
00165         else if(display_type==DISPLAY_HOST)
00166                 display_host();
00167         else if(display_type==DISPLAY_SERVICE)
00168                 display_service();
00169         else if(display_type==DISPLAY_HOSTGROUP && hostgroup_style==DISPLAY_HOSTGROUP_OVERVIEW)
00170                 display_hostgroup_overview();
00171         else if(display_type==DISPLAY_HOSTGROUP && hostgroup_style==DISPLAY_HOSTGROUP_SUMMARY)
00172                 display_hostgroup_summary();
00173         else if(display_type==DISPLAY_PING)
00174                 display_ping();
00175         else if(display_type==DISPLAY_TRACEROUTE)
00176                 display_traceroute();
00177         else if(display_type==DISPLAY_QUICKSTATS)
00178                 display_quick_stats();
00179         else if(display_type==DISPLAY_PROCESS)
00180                 display_process();
00181         else if(display_type==DISPLAY_ALL_PROBLEMS || display_type==DISPLAY_UNHANDLED_PROBLEMS)
00182                 display_problems();
00183         else
00184                 display_index();
00185 
00186         document_footer(CGI_ID);
00187 
00188         /* free all allocated memory */
00189         free_memory();
00190 
00191         return OK;
00192         }
00193 
00194 int process_cgivars(void){
00195         char **variables;
00196         int error=FALSE;
00197         int x;
00198 
00199         variables=getcgivars();
00200 
00201         for(x=0;variables[x]!=NULL;x++){
00202 
00203                 /* we found the hostgroup argument */
00204                 if(!strcmp(variables[x],"hostgroup")){
00205                         display_type=DISPLAY_HOSTGROUP;
00206                         x++;
00207                         if(variables[x]==NULL){
00208                                 error=TRUE;
00209                                 break;
00210                                 }
00211 
00212                         if((hostgroup_name=(char *)strdup(variables[x]))==NULL)
00213                                 hostgroup_name="";
00214                         strip_html_brackets(hostgroup_name);
00215 
00216                         if(!strcmp(hostgroup_name,"all"))
00217                                 show_all_hostgroups=TRUE;
00218                         else
00219                                 show_all_hostgroups=FALSE;
00220                         }
00221 
00222                 /* we found the host argument */
00223                 else if(!strcmp(variables[x],"host")){
00224                         display_type=DISPLAY_HOST;
00225                         x++;
00226                         if(variables[x]==NULL){
00227                                 error=TRUE;
00228                                 break;
00229                                 }
00230 
00231                         if((host_name=(char *)strdup(variables[x]))==NULL)
00232                                 host_name="";
00233                         strip_html_brackets(host_name);
00234                         }
00235 
00236                 /* we found the service argument */
00237                 else if(!strcmp(variables[x],"service")){
00238                         display_type=DISPLAY_SERVICE;
00239                         x++;
00240                         if(variables[x]==NULL){
00241                                 error=TRUE;
00242                                 break;
00243                                 }
00244 
00245                         if((service_desc=(char *)strdup(variables[x]))==NULL)
00246                                 service_desc="";
00247                         strip_html_brackets(service_desc);
00248                         }
00249 
00250 
00251                 /* we found the hostgroup style argument */
00252                 else if(!strcmp(variables[x],"style")){
00253                         x++;
00254                         if(variables[x]==NULL){
00255                                 error=TRUE;
00256                                 break;
00257                                 }
00258 
00259                         if(!strcmp(variables[x],"overview"))
00260                                 hostgroup_style=DISPLAY_HOSTGROUP_OVERVIEW;
00261                         else if(!strcmp(variables[x],"summary"))
00262                                 hostgroup_style=DISPLAY_HOSTGROUP_SUMMARY;
00263                         else if(!strcmp(variables[x],"servicedetail"))
00264                                 host_style=DISPLAY_HOST_SERVICES;
00265                         else if(!strcmp(variables[x],"processinfo"))
00266                                 display_type=DISPLAY_PROCESS;
00267                         else if(!strcmp(variables[x],"aprobs"))
00268                                 display_type=DISPLAY_ALL_PROBLEMS;
00269                         else if(!strcmp(variables[x],"uprobs"))
00270                                 display_type=DISPLAY_UNHANDLED_PROBLEMS;
00271                         else
00272                                 display_type=DISPLAY_QUICKSTATS;
00273                         }               
00274 
00275                 /* we found the ping argument */
00276                 else if(!strcmp(variables[x],"ping")){
00277                         display_type=DISPLAY_PING;
00278                         x++;
00279                         if(variables[x]==NULL){
00280                                 error=TRUE;
00281                                 break;
00282                                 }
00283 
00284                         if((ping_address=(char *)strdup(variables[x]))==NULL)
00285                                 ping_address="";
00286                         strip_html_brackets(ping_address);
00287                         }
00288 
00289                 /* we found the traceroute argument */
00290                 else if(!strcmp(variables[x],"traceroute")){
00291                         display_type=DISPLAY_TRACEROUTE;
00292                         x++;
00293                         if(variables[x]==NULL){
00294                                 error=TRUE;
00295                                 break;
00296                                 }
00297 
00298                         if((traceroute_address=(char *)strdup(variables[x]))==NULL)
00299                                 traceroute_address="";
00300                         strip_html_brackets(traceroute_address);
00301                         }
00302 
00303                 /* we found the nodaemoncheck option */
00304                 else if(!strcmp(variables[x],"nodaemoncheck"))
00305                         daemon_check=FALSE;
00306 
00307                 }
00308 
00309         /* free memory allocated to the CGI variables */
00310         free_cgivars(variables);
00311 
00312         return error;
00313         }
00314 
00315 int validate_arguments(void){
00316         int result=OK;
00317         if((strcmp(ping_address,"")) && !is_valid_hostip(ping_address)) {
00318                 printf("<p>Invalid host name/ip</p>\n");
00319                 result=ERROR;
00320                 }
00321         if(strcmp(traceroute_address,"") && !is_valid_hostip(traceroute_address)){
00322                 printf("<p>Invalid host name/ip</p>\n");
00323                 result=ERROR;
00324                 }
00325         return result;
00326         }
00327 
00328 int is_valid_hostip(char *hostip) {
00329         char *valid_domain_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-";
00330         if(strcmp(hostip,"") && strlen(hostip)==strspn(hostip,valid_domain_chars) && hostip[0] != '-' && hostip[strlen(hostip)-1] != '-')
00331                 return TRUE;
00332         return FALSE;
00333         }
00334 
00335 /* main intro screen */
00336 void display_index(void){
00337 
00338 
00339         /**** MAIN MENU SCREEN (CARD 1) ****/
00340         printf("<card id='card1' title='%s WAP Interface'>\n", PROGRAM_NAME);
00341         printf("<p align='center' mode='nowrap'>\n");
00342 
00343         printf("<b>%s</b><br/><b>WAP Interface</b><br/>\n", PROGRAM_NAME);
00344 
00345         printf("<b><anchor title='Quick Stats'>Quick Stats<go href='%s'><postfield name='style' value='quickstats'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00346 
00347         printf("<b><anchor title='Status Summary'>Status Summary<go href='%s'><postfield name='hostgroup' value='all'/><postfield name='style' value='summary'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00348 
00349         printf("<b><anchor title='Status Overview'>Status Overview<go href='%s'><postfield name='hostgroup' value='all'/><postfield name='style' value='overview'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00350 
00351         printf("<b><anchor title='All Problems'>All Problems<go href='%s'><postfield name='style' value='aprobs'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00352 
00353         printf("<b><anchor title='Unhandled Problems'>Unhandled Problems<go href='%s'><postfield name='style' value='uprobs'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00354 
00355         printf("<b><anchor title='Process Info'>Process Info<go href='%s'><postfield name='style' value='processinfo'/></go></anchor></b><br/>\n",STATUSWML_CGI);
00356 
00357         printf("<b><anchor title='Network Tools'>Tools<go href='#card2'/></anchor></b><br/>\n");
00358 
00359         printf("<b><anchor title='About'>About<go href='#card3'/></anchor></b><br/>\n");
00360 
00361         printf("</p>\n");
00362         printf("</card>\n");
00363 
00364 
00365         /**** TOOLS SCREEN (CARD 2) ****/
00366         printf("<card id='card2' title='Network Tools'>\n");
00367         printf("<p align='center' mode='nowrap'>\n");
00368 
00369         printf("<b>Network Tools:</b><br/>\n");
00370 
00371         printf("<b><anchor title='Ping Host'>Ping<go href='%s'><postfield name='ping' value=''/></go></anchor></b><br/>\n",STATUSWML_CGI);
00372         printf("<b><anchor title='Traceroute'>Traceroute<go href='%s'><postfield name='traceroute' value=''/></go></anchor></b><br/>\n",STATUSWML_CGI);
00373         printf("<b><anchor title='View Host'>View Host<go href='#card4'/></anchor></b><br/>\n");
00374         printf("<b><anchor title='View Hostgroup'>View Hostgroup<go href='#card5'/></anchor></b><br/>\n");
00375 
00376         printf("</p>\n");
00377         printf("</card>\n");
00378 
00379 
00380         /**** ABOUT SCREEN (CARD 3) ****/
00381         printf("<card id='card3' title='About'>\n");
00382         printf("<p align='center' mode='nowrap'>\n");
00383         printf("<b>About</b><br/>\n");
00384         printf("</p>\n");
00385 
00386         printf("<p align='center' mode='wrap'>\n");
00387         printf("<b>%s %s</b><br/><b>WAP Interface</b><br/>\n", PROGRAM_NAME, PROGRAM_VERSION);
00388         printf("Copyright (C) 2001 Ethan Galstad<br/>\n");
00389         printf("egalstad@nagios.org<br/><br/>\n");
00390         printf("License: <b>GPL</b><br/><br/>\n");
00391         printf("Based in part on features found in AskAround's Wireless Network Tools<br/>\n");
00392         printf("<b>www.askaround.com</b><br/>\n");
00393         printf("</p>\n");
00394 
00395         printf("</card>\n");
00396 
00397 
00398 
00399         /**** VIEW HOST SCREEN (CARD 4) ****/
00400         printf("<card id='card4' title='View Host'>\n");
00401         printf("<p align='center' mode='nowrap'>\n");
00402         printf("<b>View Host</b><br/>\n");
00403         printf("</p>\n");
00404 
00405         printf("<p align='center' mode='wrap'>\n");
00406         printf("<b>Host Name:</b><br/>\n");
00407         printf("<input name='hname'/>\n");
00408         printf("<do type='accept'>\n");
00409         printf("<go href='%s' method='post'><postfield name='host' value='$(hname)'/></go>\n",STATUSWML_CGI);
00410         printf("</do>\n");
00411         printf("</p>\n");
00412 
00413         printf("</card>\n");
00414 
00415 
00416 
00417         /**** VIEW HOSTGROUP SCREEN (CARD 5) ****/
00418         printf("<card id='card5' title='View Hostgroup'>\n");
00419         printf("<p align='center' mode='nowrap'>\n");
00420         printf("<b>View Hostgroup</b><br/>\n");
00421         printf("</p>\n");
00422 
00423         printf("<p align='center' mode='wrap'>\n");
00424         printf("<b>Hostgroup Name:</b><br/>\n");
00425         printf("<input name='gname'/>\n");
00426         printf("<do type='accept'>\n");
00427         printf("<go href='%s' method='post'><postfield name='hostgroup' value='$(gname)'/><postfield name='style' value='overview'/></go>\n",STATUSWML_CGI);
00428         printf("</do>\n");
00429         printf("</p>\n");
00430 
00431         printf("</card>\n");
00432 
00433 
00434         return;
00435         }
00436 
00437 
00438 /* displays process info */
00439 void display_process(void){
00440 
00441 
00442         /**** MAIN SCREEN (CARD 1) ****/
00443         printf("<card id='card1' title='Process Info'>\n");
00444         printf("<p align='center' mode='nowrap'>\n");
00445         printf("<b>Process Info</b><br/><br/>\n");
00446 
00447         /* check authorization */
00448         if(is_authorized_for_system_information(&current_authdata)==FALSE){
00449 
00450                 printf("<b>Error: Not authorized for process info!</b>\n");
00451                 printf("</p>\n");
00452                 printf("</card>\n");
00453                 return;
00454                 }
00455 
00456         if(nagios_process_state==STATE_OK)
00457                 printf("%s process is running<br/>\n", PROGRAM_NAME);
00458         else
00459                 printf("<b>%s process may not be running</b><br/>\n", PROGRAM_NAME);
00460 
00461         if(enable_notifications==TRUE)
00462                 printf("Notifications are enabled<br/>\n");
00463         else
00464                 printf("<b>Notifications are disabled</b><br/>\n");
00465 
00466         if(execute_service_checks==TRUE)
00467                 printf("Check execution is enabled<br/>\n");
00468         else
00469                 printf("<b>Check execution is disabled</b><br/>\n");
00470 
00471         printf("<br/>\n");
00472         printf("<b><anchor title='Process Commands'>Process Commands<go href='#card2'/></anchor></b>\n");
00473         printf("</p>\n");
00474 
00475         printf("</card>\n");
00476 
00477 
00478         /**** COMMANDS SCREEN (CARD 2) ****/
00479         printf("<card id='card2' title='Process Commands'>\n");
00480         printf("<p align='center' mode='nowrap'>\n");
00481         printf("<b>Process Commands</b><br/>\n");
00482 
00483         if(enable_notifications==FALSE)
00484                 printf("<b><anchor title='Enable Notifications'>Enable Notifications<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,CMD_ENABLE_NOTIFICATIONS,CMDMODE_COMMIT);
00485         else
00486                 printf("<b><anchor title='Disable Notifications'>Disable Notifications<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,CMD_DISABLE_NOTIFICATIONS,CMDMODE_COMMIT);
00487 
00488         if(execute_service_checks==FALSE)
00489                 printf("<b><anchor title='Enable Check Execution'>Enable Check Execution<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,CMD_START_EXECUTING_SVC_CHECKS,CMDMODE_COMMIT);
00490         else
00491                 printf("<b><anchor title='Disable Check Execution'>Disable Check Execution<go href='%s' method='post'><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,CMD_STOP_EXECUTING_SVC_CHECKS,CMDMODE_COMMIT);
00492 
00493         printf("</p>\n");
00494 
00495         printf("</card>\n");
00496 
00497 
00498         return;
00499         }
00500 
00501 
00502 
00503 /* displays quick stats */
00504 void display_quick_stats(void){
00505         host *temp_host;
00506         hoststatus *temp_hoststatus;
00507         service *temp_service;
00508         servicestatus *temp_servicestatus;
00509         int hosts_unreachable=0;
00510         int hosts_down=0;
00511         int hosts_up=0;
00512         int hosts_pending=0;
00513         int services_critical=0;
00514         int services_unknown=0;
00515         int services_warning=0;
00516         int services_ok=0;
00517         int services_pending=0;
00518 
00519 
00520         /**** MAIN SCREEN (CARD 1) ****/
00521         printf("<card id='card1' title='Quick Stats'>\n");
00522         printf("<p align='center' mode='nowrap'>\n");
00523         printf("<b>Quick Stats</b><br/>\n");
00524         printf("</p>\n");
00525 
00526         /* check all hosts */
00527         for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
00528 
00529                 if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
00530                         continue;
00531 
00532                 temp_hoststatus=find_hoststatus(temp_host->name);
00533                 if(temp_hoststatus==NULL)
00534                         continue;
00535 
00536                 if(temp_hoststatus->status==HOST_UNREACHABLE)
00537                         hosts_unreachable++;
00538                 else if(temp_hoststatus->status==HOST_DOWN)
00539                         hosts_down++;
00540                 else if(temp_hoststatus->status==HOST_PENDING)
00541                         hosts_pending++;
00542                 else
00543                         hosts_up++;
00544                 }
00545 
00546         /* check all services */
00547         for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){
00548 
00549                 if(is_authorized_for_service(temp_service,&current_authdata)==FALSE)
00550                         continue;
00551 
00552                 temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description);
00553                 if(temp_servicestatus==NULL)
00554                         continue;
00555 
00556                 if(temp_servicestatus->status==SERVICE_CRITICAL)
00557                         services_critical++;
00558                 else if(temp_servicestatus->status==SERVICE_UNKNOWN)
00559                         services_unknown++;
00560                 else if(temp_servicestatus->status==SERVICE_WARNING)
00561                         services_warning++;
00562                 else if(temp_servicestatus->status==SERVICE_PENDING)
00563                         services_pending++;
00564                 else
00565                         services_ok++;
00566                 }
00567 
00568         printf("<p align='left' mode='nowrap'>\n");
00569 
00570         printf("<b>Host Totals</b>:<br/>\n");
00571         printf("%d UP<br/>\n",hosts_up);
00572         printf("%d DOWN<br/>\n",hosts_down);
00573         printf("%d UNREACHABLE<br/>\n",hosts_unreachable);
00574         printf("%d PENDING<br/>\n",hosts_pending);
00575 
00576         printf("<br/>\n");
00577         
00578         printf("<b>Service Totals:</b><br/>\n");
00579         printf("%d OK<br/>\n",services_ok);
00580         printf("%d WARNING<br/>\n",services_warning);
00581         printf("%d UNKNOWN<br/>\n",services_unknown);
00582         printf("%d CRITICAL<br/>\n",services_critical);
00583         printf("%d PENDING<br/>\n",services_pending);
00584         
00585         printf("</p>\n");
00586 
00587         printf("</card>\n");
00588 
00589         return;
00590         }
00591 
00592 
00593 
00594 /* displays hostgroup status overview */
00595 void display_hostgroup_overview(void){
00596         hostgroup *temp_hostgroup;
00597         hostsmember *temp_member;
00598         host *temp_host;
00599         hoststatus *temp_hoststatus;
00600 
00601         
00602         /**** MAIN SCREEN (CARD 1) ****/
00603         printf("<card id='card1' title='Status Overview'>\n");
00604         printf("<p align='center' mode='nowrap'>\n");
00605 
00606         printf("<b><anchor title='Status Overview'>Status Overview<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='summary'/></go></anchor></b><br/><br/>\n",STATUSWML_CGI,escape_string(hostgroup_name));
00607 
00608         /* check all hostgroups */
00609         for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
00610 
00611                 if(show_all_hostgroups==FALSE && strcmp(temp_hostgroup->group_name,hostgroup_name))
00612                         continue;
00613 
00614                 if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
00615                         continue;
00616 
00617                 printf("<b>%s</b>\n",temp_hostgroup->alias);
00618 
00619                 printf("<table columns='2' align='LL'>\n");
00620 
00621                 /* check all hosts in this hostgroup */
00622                 for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
00623 
00624                         temp_host=find_host(temp_member->host_name);
00625                         if(temp_host==NULL)
00626                                 continue;
00627 
00628                         if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE)
00629                                 continue;
00630 
00631                         temp_hoststatus=find_hoststatus(temp_host->name);
00632                         if(temp_hoststatus==NULL)
00633                                 continue;
00634 
00635                         printf("<tr><td><anchor title='%s'>",temp_host->name);
00636                         if(temp_hoststatus->status==HOST_UP)
00637                                 printf("UP");
00638                         else if(temp_hoststatus->status==HOST_PENDING)
00639                                 printf("PND");
00640                         else if(temp_hoststatus->status==HOST_DOWN)
00641                                 printf("DWN");
00642                         else if(temp_hoststatus->status==HOST_UNREACHABLE)
00643                                 printf("UNR");
00644                         else
00645                                 printf("???");
00646                         printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>",STATUSWML_CGI,temp_host->name);
00647                         printf("<td>%s</td></tr>\n",temp_host->name);
00648                         }
00649 
00650                 printf("</table>\n");
00651 
00652                 printf("<br/>\n");
00653                 }
00654 
00655         if(show_all_hostgroups==FALSE)
00656                 printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='overview'/></go></anchor></b>\n",STATUSWML_CGI);
00657 
00658         printf("</p>\n");
00659         printf("</card>\n");
00660 
00661         return;
00662         }
00663 
00664 
00665 /* displays hostgroup status summary */
00666 void display_hostgroup_summary(void){
00667         hostgroup *temp_hostgroup;
00668         hostsmember *temp_member;
00669         host *temp_host;
00670         hoststatus *temp_hoststatus;
00671         service *temp_service;
00672         servicestatus *temp_servicestatus;
00673         int hosts_unreachable=0;
00674         int hosts_down=0;
00675         int hosts_up=0;
00676         int hosts_pending=0;
00677         int services_critical=0;
00678         int services_unknown=0;
00679         int services_warning=0;
00680         int services_ok=0;
00681         int services_pending=0;
00682         int found=0;
00683 
00684 
00685         /**** MAIN SCREEN (CARD 1) ****/
00686         printf("<card id='card1' title='Status Summary'>\n");
00687         printf("<p align='center' mode='nowrap'>\n");
00688 
00689         printf("<b><anchor title='Status Summary'>Status Summary<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b><br/><br/>\n",STATUSWML_CGI,escape_string(hostgroup_name));
00690 
00691         /* check all hostgroups */
00692         for(temp_hostgroup=hostgroup_list;temp_hostgroup!=NULL;temp_hostgroup=temp_hostgroup->next){
00693 
00694                 if(show_all_hostgroups==FALSE && strcmp(temp_hostgroup->group_name,hostgroup_name))
00695                         continue;
00696 
00697                 if(is_authorized_for_hostgroup(temp_hostgroup,&current_authdata)==FALSE)
00698                         continue;
00699 
00700                 printf("<b><anchor title='%s'>%s<go href='%s' method='post'><postfield name='hostgroup' value='%s'/><postfield name='style' value='overview'/></go></anchor></b>\n",temp_hostgroup->group_name,temp_hostgroup->alias,STATUSWML_CGI,temp_hostgroup->group_name);
00701 
00702                 printf("<table columns='2' align='LL'>\n");
00703 
00704                 hosts_up=0;
00705                 hosts_pending=0;
00706                 hosts_down=0;
00707                 hosts_unreachable=0;
00708 
00709                 services_ok=0;
00710                 services_pending=0;
00711                 services_warning=0;
00712                 services_unknown=0;
00713                 services_critical=0;
00714 
00715                 /* check all hosts in this hostgroup */
00716                 for(temp_member=temp_hostgroup->members;temp_member!=NULL;temp_member=temp_member->next){
00717 
00718                         temp_host=find_host(temp_member->host_name);
00719                         if(temp_host==NULL)
00720                                 continue;
00721 
00722                         if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE)
00723                                 continue;
00724 
00725                         temp_hoststatus=find_hoststatus(temp_host->name);
00726                         if(temp_hoststatus==NULL)
00727                                 continue;
00728 
00729                         if(temp_hoststatus->status==HOST_UNREACHABLE)
00730                                 hosts_unreachable++;
00731                         else if(temp_hoststatus->status==HOST_DOWN)
00732                                 hosts_down++;
00733                         else if(temp_hoststatus->status==HOST_PENDING)
00734                                 hosts_pending++;
00735                         else
00736                                 hosts_up++;
00737 
00738                         /* check all services on this host */
00739                         for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){
00740 
00741                                 if(strcmp(temp_service->host_name,temp_host->name))
00742                                         continue;
00743 
00744                                 if(is_authorized_for_service(temp_service,&current_authdata)==FALSE)
00745                                         continue;
00746 
00747                                 temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description);
00748                                 if(temp_servicestatus==NULL)
00749                                         continue;
00750 
00751                                 if(temp_servicestatus->status==SERVICE_CRITICAL)
00752                                         services_critical++;
00753                                 else if(temp_servicestatus->status==SERVICE_UNKNOWN)
00754                                         services_unknown++;
00755                                 else if(temp_servicestatus->status==SERVICE_WARNING)
00756                                         services_warning++;
00757                                 else if(temp_servicestatus->status==SERVICE_PENDING)
00758                                         services_pending++;
00759                                 else
00760                                         services_ok++;
00761                                 }
00762                         }
00763 
00764                 printf("<tr><td>Hosts:</td><td>");
00765                 found=0;
00766                 if(hosts_unreachable>0){
00767                         printf("%d UNR",hosts_unreachable);
00768                         found=1;
00769                         }
00770                 if(hosts_down>0){
00771                         printf("%s%d DWN",(found==1)?", ":"",hosts_down);
00772                         found=1;
00773                         }
00774                 if(hosts_pending>0){
00775                         printf("%s%d PND",(found==1)?", ":"",hosts_pending);
00776                         found=1;
00777                         }
00778                 printf("%s%d UP",(found==1)?", ":"",hosts_up);
00779                 printf("</td></tr>\n");
00780                 printf("<tr><td>Services:</td><td>");
00781                 found=0;
00782                 if(services_critical>0){
00783                         printf("%d CRI",services_critical);
00784                         found=1;
00785                         }
00786                 if(services_warning>0){
00787                         printf("%s%d WRN",(found==1)?", ":"",services_warning);
00788                         found=1;
00789                         }
00790                 if(services_unknown>0){
00791                         printf("%s%d UNK",(found==1)?", ":"",services_unknown);
00792                         found=1;
00793                         }
00794                 if(services_pending>0){
00795                         printf("%s%d PND",(found==1)?", ":"",services_pending);
00796                         found=1;
00797                         }
00798                 printf("%s%d OK",(found==1)?", ":"",services_ok);
00799                 printf("</td></tr>\n");
00800 
00801                 printf("</table>\n");
00802 
00803                 printf("<br/>\n");
00804                 }
00805 
00806         if(show_all_hostgroups==FALSE)
00807                 printf("<b><anchor title='View All Hostgroups'>View All Hostgroups<go href='%s' method='post'><postfield name='hostgroup' value='all'/><postfield name='style' value='summary'/></go></anchor></b>\n",STATUSWML_CGI);
00808         
00809         printf("</p>\n");
00810 
00811         printf("</card>\n");
00812 
00813         return;
00814         }
00815 
00816 
00817 
00818 /* displays host status */
00819 void display_host(void){
00820         host *temp_host;
00821         hoststatus *temp_hoststatus;
00822         char last_check[MAX_DATETIME_LENGTH];
00823         int days;
00824         int hours;
00825         int minutes;
00826         int seconds;
00827         time_t current_time;
00828         time_t t;
00829         char state_duration[48];
00830         int found;
00831 
00832         /**** MAIN SCREEN (CARD 1) ****/
00833         printf("<card id='card1' title='Host Status'>\n");
00834         printf("<p align='center' mode='nowrap'>\n");
00835         printf("<b>Host '%s'</b><br/>\n",host_name);
00836 
00837         /* find the host */
00838         temp_host=find_host(host_name);
00839         temp_hoststatus=find_hoststatus(host_name);
00840         if(temp_host==NULL || temp_hoststatus==NULL){
00841 
00842                 printf("<b>Error: Could not find host!</b>\n");
00843                 printf("</p>\n");
00844                 printf("</card>\n");
00845                 return;
00846                 }
00847 
00848         /* check authorization */
00849         if(is_authorized_for_host(temp_host,&current_authdata)==FALSE){
00850 
00851                 printf("<b>Error: Not authorized for host!</b>\n");
00852                 printf("</p>\n");
00853                 printf("</card>\n");
00854                 return;
00855                 }
00856 
00857 
00858         printf("<table columns='2' align='LL'>\n");
00859 
00860         printf("<tr><td>Status:</td><td>");
00861         if(temp_hoststatus->status==HOST_UP)
00862                 printf("UP");
00863         else if(temp_hoststatus->status==HOST_PENDING)
00864                 printf("PENDING");
00865         else if(temp_hoststatus->status==HOST_DOWN)
00866                 printf("DOWN");
00867         else if(temp_hoststatus->status==HOST_UNREACHABLE)
00868                 printf("UNREACHABLE");
00869         else
00870                 printf("?");
00871         printf("</td></tr>\n");
00872 
00873         printf("<tr><td>Info:</td><td>%s</td></tr>\n",temp_hoststatus->plugin_output);
00874 
00875         get_time_string(&temp_hoststatus->last_check,last_check,sizeof(last_check)-1,SHORT_DATE_TIME);
00876         printf("<tr><td>Last Check:</td><td>%s</td></tr>\n",last_check);
00877 
00878         current_time=time(NULL);
00879         if(temp_hoststatus->last_state_change==(time_t)0)
00880                 t=current_time-program_start;
00881         else
00882                 t=current_time-temp_hoststatus->last_state_change;
00883         get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds);
00884         snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_hoststatus->last_state_change==(time_t)0)?"+":"");
00885         printf("<tr><td>Duration:</td><td>%s</td></tr>\n",state_duration);
00886 
00887         printf("<tr><td>Properties:</td><td>");
00888         found=0;
00889         if(temp_hoststatus->checks_enabled==FALSE){
00890                 printf("%sChecks disabled",(found==1)?", ":"");
00891                 found=1;
00892                 }
00893         if(temp_hoststatus->notifications_enabled==FALSE){
00894                 printf("%sNotifications disabled",(found==1)?", ":"");
00895                 found=1;
00896                 }
00897         if(temp_hoststatus->problem_has_been_acknowledged==TRUE){
00898                 printf("%sProblem acknowledged",(found==1)?", ":"");
00899                 found=1;
00900                 }
00901         if(temp_hoststatus->scheduled_downtime_depth>0){
00902                 printf("%sIn scheduled downtime",(found==1)?", ":"");
00903                 found=1;
00904                 }
00905         if(found==0)
00906                 printf("N/A");
00907         printf("</td></tr>\n");
00908 
00909         printf("</table>\n");
00910         printf("<br/>\n");
00911         printf("<b><anchor title='View Services'>View Services<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='style' value='servicedetail'/></go></anchor></b>\n",STATUSWML_CGI,escape_string(host_name));
00912         printf("<b><anchor title='Host Commands'>Host Commands<go href='#card2'/></anchor></b>\n");
00913         printf("</p>\n");
00914 
00915         printf("</card>\n");
00916 
00917 
00918         /**** COMMANDS SCREEN (CARD 2) ****/
00919         printf("<card id='card2' title='Host Commands'>\n");
00920         printf("<p align='center' mode='nowrap'>\n");
00921         printf("<b>Host Commands</b><br/>\n");
00922 
00923         printf("<b><anchor title='Ping Host'>Ping Host<go href='%s' method='post'><postfield name='ping' value='%s'/></go></anchor></b>\n",STATUSWML_CGI,temp_host->address);
00924         printf("<b><anchor title='Ping6 Host'>Ping6 Host<go href='%s' method='post'><postfield name='ping6' value='%s'/></go></anchor></b>\n",STATUSWML_CGI,temp_host->address6);
00925         printf("<b><anchor title='Traceroute'>Traceroute<go href='%s' method='post'><postfield name='traceroute' value='%s'/></go></anchor></b>\n",STATUSWML_CGI,temp_host->address);
00926         printf("<b><anchor title='Traceroute6'>Traceroute6<go href='%s' method='post'><postfield name='traceroute6' value='%s'/></go></anchor></b>\n",STATUSWML_CGI,temp_host->address6);
00927 
00928         if(temp_hoststatus->status!=HOST_UP && temp_hoststatus->status!=HOST_PENDING)
00929                 printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");
00930 
00931         if(temp_hoststatus->checks_enabled==FALSE)
00932                 printf("<b><anchor title='Enable Host Checks'>Enable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_ENABLE_HOST_CHECK,CMDMODE_COMMIT);
00933         else
00934                 printf("<b><anchor title='Disable Host Checks'>Disable Host Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_DISABLE_HOST_CHECK,CMDMODE_COMMIT);
00935 
00936         if(temp_hoststatus->notifications_enabled==FALSE)
00937                 printf("<b><anchor title='Enable Host Notifications'>Enable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_ENABLE_HOST_NOTIFICATIONS,CMDMODE_COMMIT);
00938         else
00939                 printf("<b><anchor title='Disable Host Notifications'>Disable Host Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_DISABLE_HOST_NOTIFICATIONS,CMDMODE_COMMIT);
00940 
00941 
00942         printf("<b><anchor title='Enable All Service Checks'>Enable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_ENABLE_HOST_SVC_CHECKS,CMDMODE_COMMIT);
00943 
00944         printf("<b><anchor title='Disable All Service Checks'>Disable All Service Checks<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_DISABLE_HOST_SVC_CHECKS,CMDMODE_COMMIT);
00945 
00946         printf("<b><anchor title='Enable All Service Notifications'>Enable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_ENABLE_HOST_SVC_NOTIFICATIONS,CMDMODE_COMMIT);
00947 
00948         printf("<b><anchor title='Disable All Service Notifications'>Disable All Service Notifications<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",CMD_CGI,escape_string(host_name),CMD_DISABLE_HOST_SVC_NOTIFICATIONS,CMDMODE_COMMIT);
00949 
00950         printf("</p>\n");
00951 
00952         printf("</card>\n");
00953 
00954 
00955         /**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/
00956         printf("<card id='card3' title='Acknowledge Problem'>\n");
00957         printf("<p align='center' mode='nowrap'>\n");
00958         printf("<b>Acknowledge Problem</b><br/>\n");
00959         printf("</p>\n");
00960 
00961         printf("<p align='center' mode='wrap'>\n");
00962         printf("<b>Your Name:</b><br/>\n");
00963         printf("<input name='name' value='%s' /><br/>\n",((use_ssl_authentication)?(getenv("SSL_CLIENT_S_DN_CN")):(getenv("REMOTE_USER"))));
00964         printf("<b>Comment:</b><br/>\n");
00965         printf("<input name='comment' value='acknowledged by WAP'/>\n");
00966 
00967         printf("<do type='accept'>\n");
00968         printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='com_author' value='$(name)'/><postfield name='com_data' value='$(comment)'/><postfield name='persistent' value=''/><postfield name='send_notification' value=''/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go>\n",CMD_CGI,escape_string(host_name),CMD_ACKNOWLEDGE_HOST_PROBLEM,CMDMODE_COMMIT);
00969         printf("</do>\n");
00970 
00971         printf("</p>\n");
00972 
00973         printf("</card>\n");
00974 
00975         return;
00976         }
00977 
00978 
00979 
00980 /* displays services on a host */
00981 void display_host_services(void){
00982         service *temp_service;
00983         servicestatus *temp_servicestatus;
00984 
00985         /**** MAIN SCREEN (CARD 1) ****/
00986         printf("<card id='card1' title='Host Services'>\n");
00987         printf("<p align='center' mode='nowrap'>\n");
00988         printf("<b>Host <anchor title='%s'>",url_encode(host_name));
00989         printf("'%s'<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor> Services</b><br/>\n",host_name,STATUSWML_CGI,escape_string(host_name));
00990 
00991         printf("<table columns='2' align='LL'>\n");
00992 
00993         /* check all services */
00994         for(temp_service=service_list;temp_service!=NULL;temp_service=temp_service->next){
00995 
00996                 if(strcmp(temp_service->host_name,host_name))
00997                         continue;
00998 
00999                 if(is_authorized_for_service(temp_service,&current_authdata)==FALSE)
01000                         continue;
01001 
01002                 temp_servicestatus=find_servicestatus(temp_service->host_name,temp_service->description);
01003                 if(temp_servicestatus==NULL)
01004                         continue;
01005 
01006                 printf("<tr><td><anchor title='%s'>",temp_service->description);
01007                 if(temp_servicestatus->status==SERVICE_OK)
01008                         printf("OK");
01009                 else if(temp_servicestatus->status==SERVICE_PENDING)
01010                         printf("PND");
01011                 else if(temp_servicestatus->status==SERVICE_WARNING)
01012                         printf("WRN");
01013                 else if(temp_servicestatus->status==SERVICE_UNKNOWN)
01014                         printf("UNK");
01015                 else if(temp_servicestatus->status==SERVICE_CRITICAL)
01016                         printf("CRI");
01017                 else
01018                         printf("???");
01019 
01020                 printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='service' value='%s'/></go></anchor></td>",STATUSWML_CGI,temp_service->host_name,temp_service->description);
01021                 printf("<td>%s</td></tr>\n",temp_service->description);
01022                 }
01023 
01024         printf("</table>\n");
01025 
01026         printf("</p>\n");
01027 
01028         printf("</card>\n");
01029 
01030         return;
01031         }
01032 
01033 
01034 
01035 /* displays service status */
01036 void display_service(void){
01037         service *temp_service;
01038         servicestatus *temp_servicestatus;
01039         char last_check[MAX_DATETIME_LENGTH];
01040         int days;
01041         int hours;
01042         int minutes;
01043         int seconds;
01044         time_t current_time;
01045         time_t t;
01046         char state_duration[48];
01047         int found;
01048 
01049         /**** MAIN SCREEN (CARD 1) ****/
01050         printf("<card id='card1' title='Service Status'>\n");
01051         printf("<p align='center' mode='nowrap'>\n");
01052         printf("<b>Service '%s' on host '%s'</b><br/>\n",service_desc,host_name);
01053 
01054         /* find the service */
01055         temp_service=find_service(host_name,service_desc);
01056         temp_servicestatus=find_servicestatus(host_name,service_desc);
01057         if(temp_service==NULL || temp_servicestatus==NULL){
01058 
01059                 printf("<b>Error: Could not find service!</b>\n");
01060                 printf("</p>\n");
01061                 printf("</card>\n");
01062                 return;
01063                 }
01064 
01065         /* check authorization */
01066         if(is_authorized_for_service(temp_service,&current_authdata)==FALSE){
01067 
01068                 printf("<b>Error: Not authorized for service!</b>\n");
01069                 printf("</p>\n");
01070                 printf("</card>\n");
01071                 return;
01072                 }
01073 
01074 
01075         printf("<table columns='2' align='LL'>\n");
01076 
01077         printf("<tr><td>Status:</td><td>");
01078         if(temp_servicestatus->status==SERVICE_OK)
01079                 printf("OK");
01080         else if(temp_servicestatus->status==SERVICE_PENDING)
01081                 printf("PENDING");
01082         else if(temp_servicestatus->status==SERVICE_WARNING)
01083                 printf("WARNING");
01084         else if(temp_servicestatus->status==SERVICE_UNKNOWN)
01085                 printf("UNKNOWN");
01086         else if(temp_servicestatus->status==SERVICE_CRITICAL)
01087                 printf("CRITICAL");
01088         else
01089                 printf("?");
01090         printf("</td></tr>\n");
01091 
01092         printf("<tr><td>Info:</td><td>%s</td></tr>\n",temp_servicestatus->plugin_output);
01093 
01094         get_time_string(&temp_servicestatus->last_check,last_check,sizeof(last_check)-1,SHORT_DATE_TIME);
01095         printf("<tr><td>Last Check:</td><td>%s</td></tr>\n",last_check);
01096 
01097         current_time=time(NULL);
01098         if(temp_servicestatus->last_state_change==(time_t)0)
01099                 t=current_time-program_start;
01100         else
01101                 t=current_time-temp_servicestatus->last_state_change;
01102         get_time_breakdown((unsigned long)t,&days,&hours,&minutes,&seconds);
01103         snprintf(state_duration,sizeof(state_duration)-1,"%2dd %2dh %2dm %2ds%s",days,hours,minutes,seconds,(temp_servicestatus->last_state_change==(time_t)0)?"+":"");
01104         printf("<tr><td>Duration:</td><td>%s</td></tr>\n",state_duration);
01105 
01106         printf("<tr><td>Properties:</td><td>");
01107         found=0;
01108         if(temp_servicestatus->checks_enabled==FALSE){
01109                 printf("%sChecks disabled",(found==1)?", ":"");
01110                 found=1;
01111                 }
01112         if(temp_servicestatus->notifications_enabled==FALSE){
01113                 printf("%sNotifications disabled",(found==1)?", ":"");
01114                 found=1;
01115                 }
01116         if(temp_servicestatus->problem_has_been_acknowledged==TRUE){
01117                 printf("%sProblem acknowledged",(found==1)?", ":"");
01118                 found=1;
01119                 }
01120         if(temp_servicestatus->scheduled_downtime_depth>0){
01121                 printf("%sIn scheduled downtime",(found==1)?", ":"");
01122                 found=1;
01123                 }
01124         if(found==0)
01125                 printf("N/A");
01126         printf("</td></tr>\n");
01127 
01128         printf("</table>\n");
01129         printf("<br/>\n");
01130         printf("<b><anchor title='View Host'>View Host<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></b>\n",STATUSWML_CGI,escape_string(host_name));
01131         printf("<b><anchor title='Service Commands'>Svc. Commands<go href='#card2'/></anchor></b>\n");
01132         printf("</p>\n");
01133 
01134         printf("</card>\n");
01135 
01136 
01137         /**** COMMANDS SCREEN (CARD 2) ****/
01138         printf("<card id='card2' title='Service Commands'>\n");
01139         printf("<p align='center' mode='nowrap'>\n");
01140         printf("<b>Service Commands</b><br/>\n");
01141 
01142         if(temp_servicestatus->status!=SERVICE_OK && temp_servicestatus->status!=SERVICE_PENDING)
01143                 printf("<b><anchor title='Acknowledge Problem'>Acknowledge Problem<go href='#card3'/></anchor></b>\n");
01144 
01145         if(temp_servicestatus->checks_enabled==FALSE){
01146                 printf("<b><anchor title='Enable Checks'>Enable Checks<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01147                 printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",escape_string(service_desc),CMD_ENABLE_SVC_CHECK,CMDMODE_COMMIT);
01148                 }
01149         else{
01150                 printf("<b><anchor title='Disable Checks'>Disable Checks<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01151                 printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",escape_string(service_desc),CMD_DISABLE_SVC_CHECK,CMDMODE_COMMIT);
01152 
01153                 printf("<b><anchor title='Schedule Immediate Check'>Schedule Immediate Check<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01154                 printf("<postfield name='service' value='%s'/><postfield name='start_time' value='%lu'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",escape_string(service_desc),(unsigned long)current_time,CMD_SCHEDULE_SVC_CHECK,CMDMODE_COMMIT);
01155                 }
01156 
01157         if(temp_servicestatus->notifications_enabled==FALSE){
01158                 printf("<b><anchor title='Enable Notifications'>Enable Notifications<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01159                 printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",escape_string(service_desc),CMD_ENABLE_SVC_NOTIFICATIONS,CMDMODE_COMMIT);
01160                 }
01161         else{
01162                 printf("<b><anchor title='Disable Notifications'>Disable Notifications<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01163                 printf("<postfield name='service' value='%s'/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go></anchor></b><br/>\n",escape_string(service_desc),CMD_DISABLE_SVC_NOTIFICATIONS,CMDMODE_COMMIT);
01164                 }
01165 
01166         printf("</p>\n");
01167 
01168         printf("</card>\n");
01169 
01170 
01171         /**** ACKNOWLEDGEMENT SCREEN (CARD 3) ****/
01172         printf("<card id='card3' title='Acknowledge Problem'>\n");
01173         printf("<p align='center' mode='nowrap'>\n");
01174         printf("<b>Acknowledge Problem</b><br/>\n");
01175         printf("</p>\n");
01176 
01177         printf("<p align='center' mode='wrap'>\n");
01178         printf("<b>Your Name:</b><br/>\n");
01179         printf("<input name='name' value='%s' /><br/>\n",((use_ssl_authentication)?(getenv("SSL_CLIENT_S_DN_CN")):(getenv("REMOTE_USER"))));
01180         printf("<b>Comment:</b><br/>\n");
01181         printf("<input name='comment' value='acknowledged by WAP'/>\n");
01182 
01183         printf("<do type='accept'>\n");
01184         printf("<go href='%s' method='post'><postfield name='host' value='%s'/>",CMD_CGI,escape_string(host_name));
01185         printf("<postfield name='service' value='%s'/><postfield name='com_author' value='$(name)'/><postfield name='com_data' value='$(comment)'/><postfield name='persistent' value=''/><postfield name='send_notification' value=''/><postfield name='cmd_typ' value='%d'/><postfield name='cmd_mod' value='%d'/><postfield name='content' value='wml'/></go>\n",escape_string(service_desc),CMD_ACKNOWLEDGE_SVC_PROBLEM,CMDMODE_COMMIT);
01186         printf("</do>\n");
01187 
01188         printf("</p>\n");
01189 
01190         printf("</card>\n");
01191 
01192         return;
01193         }
01194 
01195 
01196 /* displays ping results */
01197 void display_ping(void){
01198         char input_buffer[MAX_INPUT_BUFFER];
01199         char buffer[MAX_INPUT_BUFFER];
01200         char *temp_ptr;
01201         FILE *fp;
01202         int odd=0;
01203         int in_macro=FALSE;
01204 
01205         /**** MAIN SCREEN (CARD 1) ****/
01206         printf("<card id='card1' title='Ping'>\n");
01207 
01208         if(!strcmp(ping_address,"")){
01209 
01210                 printf("<p align='center' mode='nowrap'>\n");
01211                 printf("<b>Ping Host</b><br/>\n");
01212                 printf("</p>\n");
01213 
01214                 printf("<p align='center' mode='wrap'>\n");
01215                 printf("<b>Host Name/Address:</b><br/>\n");
01216                 printf("<input name='address'/>\n");
01217                 printf("<do type='accept'>\n");
01218                 printf("<go href='%s'><postfield name='ping' value='$(address)'/></go>\n",STATUSWML_CGI);
01219                 printf("</do>\n");
01220                 printf("</p>\n");
01221                 }
01222 
01223         else{
01224 
01225                 printf("<p align='center' mode='nowrap'>\n");
01226                 printf("<b>Results For Ping Of %s:</b><br/>\n",ping_address);
01227                 printf("</p>\n");
01228 
01229                 printf("<p mode='nowrap'>\n");
01230 
01231                 if(ping_syntax==NULL)
01232                         printf("ping_syntax in CGI config file is NULL!\n");
01233         
01234                 else{
01235 
01236                         /* process macros in the ping syntax */
01237                         strcpy(buffer,"");
01238                         strncpy(input_buffer,ping_syntax,sizeof(input_buffer)-1);
01239                         input_buffer[strlen(ping_syntax)-1]='\x0';
01240                         for(temp_ptr=my_strtok(input_buffer,"$");temp_ptr!=NULL;temp_ptr=my_strtok(NULL,"$")){
01241 
01242                                 if(in_macro==FALSE){
01243                                         if(strlen(buffer)+strlen(temp_ptr)<sizeof(buffer)-1){
01244                                                 strncat(buffer,temp_ptr,sizeof(buffer)-strlen(buffer)-1);
01245                                                 buffer[sizeof(buffer)-1]='\x0';
01246                                                 }
01247                                         in_macro=TRUE;
01248                                         }
01249                                 else{
01250 
01251                                         if(strlen(buffer)+strlen(temp_ptr) < sizeof(buffer)-1){
01252 
01253                                                 if(!strcmp(temp_ptr,"HOSTADDRESS"))
01254                                                         strncat(buffer,ping_address,sizeof(buffer)-strlen(buffer)-1);
01255                                                 }
01256 
01257                                         in_macro=FALSE;
01258                                         }
01259                                 }
01260 
01261                         /* run the ping command */
01262                         fp=popen(buffer,"r");
01263                         if(fp){
01264                                 while(1){
01265                                         dummy=fgets(buffer,sizeof(buffer)-1,fp);
01266                                         if(feof(fp))
01267                                                 break;
01268 
01269                                         strip(buffer);
01270 
01271                                         if(odd){
01272                                                 odd=0;
01273                                                 printf("%s<br/>\n",buffer);
01274                                                 }
01275                                         else{
01276                                                 odd=1;
01277                                                 printf("<b>%s</b><br/>\n",buffer);
01278                                                 }
01279                                         }
01280                                 }
01281                         else
01282                                 printf("Error executing ping!\n");
01283 
01284                         pclose(fp);
01285                         }
01286 
01287                 printf("</p>\n");
01288                 }
01289 
01290         printf("</card>\n");
01291 
01292         return;
01293         }
01294 
01295 
01296 /* displays traceroute results */
01297 void display_traceroute(void){
01298         char buffer[MAX_INPUT_BUFFER];
01299         FILE *fp;
01300         int odd=0;
01301 
01302         /**** MAIN SCREEN (CARD 1) ****/
01303         printf("<card id='card1' title='Traceroute'>\n");
01304 
01305         if(!strcmp(traceroute_address,"")){
01306 
01307                 printf("<p align='center' mode='nowrap'>\n");
01308                 printf("<b>Traceroute</b><br/>\n");
01309                 printf("</p>\n");
01310 
01311                 printf("<p align='center' mode='wrap'>\n");
01312                 printf("<b>Host Name/Address:</b><br/>\n");
01313                 printf("<input name='address'/>\n");
01314                 printf("<do type='accept'>\n");
01315                 printf("<go href='%s'><postfield name='traceroute' value='$(address)'/></go>\n",STATUSWML_CGI);
01316                 printf("</do>\n");
01317                 printf("</p>\n");
01318                 }
01319 
01320         else{
01321 
01322                 printf("<p align='center' mode='nowrap'>\n");
01323                 printf("<b>Results For Traceroute To %s:</b><br/>\n",traceroute_address);
01324                 printf("</p>\n");
01325 
01326                 printf("<p mode='nowrap'>\n");
01327         
01328                 snprintf(buffer,sizeof(buffer)-1,"%s %s",TRACEROUTE_COMMAND,traceroute_address);
01329                 buffer[sizeof(buffer)-1]='\x0';
01330 
01331                 fp=popen(buffer,"r");
01332                 if(fp){
01333                         while(1){
01334                                 dummy=fgets(buffer,sizeof(buffer)-1,fp);
01335                                 if(feof(fp))
01336                                         break;
01337 
01338                                 strip(buffer);
01339 
01340                                 if(odd){
01341                                         odd=0;
01342                                         printf("%s<br/>\n",buffer);
01343                                         }
01344                                 else{
01345                                         odd=1;
01346                                         printf("<b>%s</b><br/>\n",buffer);
01347                                         }
01348                                }
01349                         }
01350                 else
01351                         printf("Error executing traceroute!\n");
01352 
01353                 pclose(fp);
01354 
01355                 printf("</p>\n");
01356                 }
01357 
01358         printf("</card>\n");
01359 
01360         return;
01361         }
01362 
01363 
01364 
01365 /* displays problems */
01366 void display_problems(void){
01367         host *temp_host;
01368         service *temp_service;
01369         hoststatus *temp_hoststatus;
01370         int total_host_problems=0;
01371         servicestatus *temp_servicestatus;
01372         int total_service_problems=0;
01373 
01374         /**** MAIN SCREEN (CARD 1) ****/
01375         printf("<card id='card1' title='%s Problems'>\n",(display_type==DISPLAY_ALL_PROBLEMS)?"All":"Unhandled");
01376         printf("<p align='center' mode='nowrap'>\n");
01377         printf("<b>%s Problems</b><br/><br/>\n",(display_type==DISPLAY_ALL_PROBLEMS)?"All":"Unhandled");
01378 
01379         printf("<b>Host Problems:</b>\n");
01380 
01381         printf("<table columns='2' align='LL'>\n");
01382 
01383         /* check all hosts */
01384         for(temp_hoststatus=hoststatus_list;temp_hoststatus!=NULL;temp_hoststatus=temp_hoststatus->next){
01385 
01386                 temp_host=find_host(temp_hoststatus->host_name);
01387                 if(temp_host==NULL)
01388                         continue;
01389 
01390                 if(is_authorized_for_host(temp_host,&current_authdata)==FALSE)
01391                         continue;
01392 
01393                 if(temp_hoststatus->status==HOST_UP || temp_hoststatus->status==HOST_PENDING)
01394                         continue;
01395 
01396                 if(display_type==DISPLAY_UNHANDLED_PROBLEMS){
01397                         if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
01398                                 continue;
01399                         if(temp_hoststatus->notifications_enabled==FALSE)
01400                                 continue;
01401                         if(temp_hoststatus->scheduled_downtime_depth>0)
01402                                 continue;
01403                         }
01404 
01405                 total_host_problems++;
01406 
01407                 printf("<tr><td><anchor title='%s'>",temp_host->name);
01408                 if(temp_hoststatus->status==HOST_DOWN)
01409                         printf("DWN");
01410                 else if(temp_hoststatus->status==HOST_UNREACHABLE)
01411                         printf("UNR");
01412                 else
01413                         printf("???");
01414                 printf("<go href='%s' method='post'><postfield name='host' value='%s'/></go></anchor></td>",STATUSWML_CGI,temp_host->name);
01415                 printf("<td>%s</td></tr>\n",temp_host->name);
01416                 }
01417 
01418         if(total_host_problems==0)
01419                 printf("<tr><td>No problems</td></tr>\n");
01420 
01421         printf("</table>\n");
01422 
01423         printf("<br/>\n");
01424 
01425 
01426         printf("<b>Svc Problems:</b>\n");
01427 
01428         printf("<table columns='2' align='LL'>\n");
01429 
01430         /* check all services */
01431         for(temp_servicestatus=servicestatus_list;temp_servicestatus!=NULL;temp_servicestatus=temp_servicestatus->next){
01432                 
01433                 temp_service=find_service(temp_servicestatus->host_name,temp_servicestatus->description);
01434                 if(temp_service==NULL)
01435                         continue;
01436 
01437                 if(is_authorized_for_service(temp_service,&current_authdata)==FALSE)
01438                         continue;
01439 
01440                 if(temp_servicestatus->status==SERVICE_OK || temp_servicestatus->status==SERVICE_PENDING)
01441                         continue;
01442 
01443                 if(display_type==DISPLAY_UNHANDLED_PROBLEMS){
01444                         if(temp_servicestatus->problem_has_been_acknowledged==TRUE)
01445                                 continue;
01446                         if(temp_servicestatus->notifications_enabled==FALSE)
01447                                 continue;
01448                         if(temp_servicestatus->scheduled_downtime_depth>0)
01449                                 continue;
01450                         if((temp_hoststatus=find_hoststatus(temp_service->host_name))){
01451                                 if(temp_hoststatus->scheduled_downtime_depth>0)
01452                                         continue;
01453                                 if(temp_hoststatus->problem_has_been_acknowledged==TRUE)
01454                                         continue;
01455                                 }
01456                         }
01457 
01458                 total_service_problems++;
01459 
01460                 printf("<tr><td><anchor title='%s'>",temp_servicestatus->description);
01461                 if(temp_servicestatus->status==SERVICE_CRITICAL)
01462                         printf("CRI");
01463                 else if(temp_servicestatus->status==SERVICE_WARNING)
01464                         printf("WRN");
01465                 else if(temp_servicestatus->status==SERVICE_UNKNOWN)
01466                         printf("UNK");
01467                 else
01468                         printf("???");
01469                 printf("<go href='%s' method='post'><postfield name='host' value='%s'/><postfield name='service' value='%s'/></go></anchor></td>",STATUSWML_CGI,temp_service->host_name,temp_service->description);
01470                 printf("<td>%s/%s</td></tr>\n",temp_service->host_name,temp_service->description);
01471                 }
01472 
01473         if(total_service_problems==0)
01474                 printf("<tr><td>No problems</td></tr>\n");
01475 
01476         printf("</table>\n");
01477 
01478         printf("</p>\n");
01479 
01480         printf("</card>\n");
01481 
01482         return;
01483         }
01484 
01485 
01486 
 All Data Structures Files Functions Variables Typedefs Defines