1 /**************************************************************************
2  *
3  * EXTINFO.C -  Nagios Extended Information CGI
4  *
5  * Copyright (c) 1999-2009 Ethan Galstad (egalstad@nagios.org)
6  * Last Modified: 06-17-2009
7  *
8  * License:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *************************************************************************/
23 
24 #include "../include/config.h"
25 #include "../include/common.h"
26 #include "../include/objects.h"
27 #include "../include/macros.h"
28 #include "../include/comments.h"
29 #include "../include/downtime.h"
30 #include "../include/statusdata.h"
31 
32 #include "../include/cgiutils.h"
33 #include "../include/getcgi.h"
34 #include "../include/cgiauth.h"
35 
36 static nagios_macros *mac;
37 
38 extern char             nagios_check_command[MAX_INPUT_BUFFER];
39 extern char             nagios_process_info[MAX_INPUT_BUFFER];
40 extern int              nagios_process_state;
41 extern int              refresh_rate;
42 
43 extern time_t		program_start;
44 extern int              nagios_pid;
45 extern int              daemon_mode;
46 extern time_t           last_command_check;
47 extern time_t           last_log_rotation;
48 extern int              enable_notifications;
49 extern int              execute_service_checks;
50 extern int              accept_passive_service_checks;
51 extern int              execute_host_checks;
52 extern int              accept_passive_host_checks;
53 extern int              enable_event_handlers;
54 extern int              obsess_over_services;
55 extern int              obsess_over_hosts;
56 extern int              enable_flap_detection;
57 extern int              enable_failure_prediction;
58 extern int              process_performance_data;
59 
60 extern int              buffer_stats[1][3];
61 extern int              program_stats[MAX_CHECK_STATS_TYPES][3];
62 
63 extern char main_config_file[MAX_FILENAME_LENGTH];
64 extern char url_html_path[MAX_FILENAME_LENGTH];
65 extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
66 extern char url_docs_path[MAX_FILENAME_LENGTH];
67 extern char url_images_path[MAX_FILENAME_LENGTH];
68 extern char url_logo_images_path[MAX_FILENAME_LENGTH];
69 extern char log_file[MAX_FILENAME_LENGTH];
70 
71 extern int              enable_splunk_integration;
72 
73 extern char             *notes_url_target;
74 extern char             *action_url_target;
75 
76 extern comment           *comment_list;
77 extern scheduled_downtime  *scheduled_downtime_list;
78 extern hoststatus *hoststatus_list;
79 extern servicestatus *servicestatus_list;
80 extern hostgroup *hostgroup_list;
81 extern servicegroup *servicegroup_list;
82 
83 
84 #define MAX_MESSAGE_BUFFER		4096
85 
86 #define HEALTH_WARNING_PERCENTAGE       85
87 #define HEALTH_CRITICAL_PERCENTAGE      75
88 
89 /* SORTDATA structure */
90 typedef struct sortdata_struct {
91 	int is_service;
92 	servicestatus *svcstatus;
93 	hoststatus *hststatus;
94 	struct sortdata_struct *next;
95 	} sortdata;
96 
97 void document_header(int);
98 void document_footer(void);
99 int process_cgivars(void);
100 
101 void show_process_info(void);
102 void show_host_info(void);
103 void show_service_info(void);
104 void show_all_comments(void);
105 void show_performance_data(void);
106 void show_hostgroup_info(void);
107 void show_servicegroup_info(void);
108 void show_all_downtime(void);
109 void show_scheduling_queue(void);
110 void display_comments(int);
111 
112 int sort_data(int, int);
113 int compare_sortdata_entries(int, int, sortdata *, sortdata *);
114 void free_sortdata_list(void);
115 
116 authdata current_authdata;
117 
118 sortdata *sortdata_list = NULL;
119 
120 char *host_name = "";
121 char *hostgroup_name = "";
122 char *servicegroup_name = "";
123 char *service_desc = "";
124 
125 int display_type = DISPLAY_PROCESS_INFO;
126 
127 int sort_type = SORT_ASCENDING;
128 int sort_option = SORT_NEXTCHECKTIME;
129 
130 int embedded = FALSE;
131 int display_header = TRUE;
132 
133 
134 
main(void)135 int main(void) {
136 	int result = OK;
137 	int found = FALSE;
138 	char temp_buffer[MAX_INPUT_BUFFER] = "";
139 	char *processed_string = NULL;
140 	host *temp_host = NULL;
141 	hostsmember *temp_parenthost = NULL;
142 	hostgroup *temp_hostgroup = NULL;
143 	service *temp_service = NULL;
144 	servicegroup *temp_servicegroup = NULL;
145 
146 	mac = get_global_macros();
147 
148 	/* get the arguments passed in the URL */
149 	process_cgivars();
150 
151 	/* reset internal variables */
152 	reset_cgi_vars();
153 
154 	/* read the CGI configuration file */
155 	result = read_cgi_config_file(get_cgi_config_location());
156 	if(result == ERROR) {
157 		document_header(FALSE);
158 		cgi_config_file_error(get_cgi_config_location());
159 		document_footer();
160 		return ERROR;
161 		}
162 
163 	/* read the main configuration file */
164 	result = read_main_config_file(main_config_file);
165 	if(result == ERROR) {
166 		document_header(FALSE);
167 		main_config_file_error(main_config_file);
168 		document_footer();
169 		return ERROR;
170 		}
171 
172 	/* read all object configuration data */
173 	result = read_all_object_configuration_data(main_config_file, READ_ALL_OBJECT_DATA);
174 	if(result == ERROR) {
175 		document_header(FALSE);
176 		object_data_error();
177 		document_footer();
178 		return ERROR;
179 		}
180 
181 	/* read all status data */
182 	result = read_all_status_data(get_cgi_config_location(), READ_ALL_STATUS_DATA);
183 	if(result == ERROR) {
184 		document_header(FALSE);
185 		status_data_error();
186 		document_footer();
187 		free_memory();
188 		return ERROR;
189 		}
190 
191 	/* initialize macros */
192 	init_macros();
193 
194 	document_header(TRUE);
195 
196 	/* get authentication information */
197 	get_authentication_information(&current_authdata);
198 
199 
200 	if(display_header == TRUE) {
201 
202 		/* begin top table */
203 		printf("<table border=0 width=100%%>\n");
204 		printf("<tr>\n");
205 
206 		/* left column of the first row */
207 		printf("<td align=left valign=top width=33%%>\n");
208 
209 		if(display_type == DISPLAY_HOST_INFO)
210 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Host Information");
211 		else if(display_type == DISPLAY_SERVICE_INFO)
212 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Service Information");
213 		else if(display_type == DISPLAY_COMMENTS)
214 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Comments");
215 		else if(display_type == DISPLAY_PERFORMANCE)
216 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Performance Information");
217 		else if(display_type == DISPLAY_HOSTGROUP_INFO)
218 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Hostgroup Information");
219 		else if(display_type == DISPLAY_SERVICEGROUP_INFO)
220 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Servicegroup Information");
221 		else if(display_type == DISPLAY_DOWNTIME)
222 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "All Host and Service Scheduled Downtime");
223 		else if(display_type == DISPLAY_SCHEDULING_QUEUE)
224 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Check Scheduling Queue");
225 		else
226 			snprintf(temp_buffer, sizeof(temp_buffer) - 1, "Nagios Process Information");
227 		temp_buffer[sizeof(temp_buffer) - 1] = '\x0';
228 		display_info_table(temp_buffer, TRUE, &current_authdata);
229 
230 		/* find the host */
231 		if(display_type == DISPLAY_HOST_INFO || display_type == DISPLAY_SERVICE_INFO) {
232 
233 			temp_host = find_host(host_name);
234 			grab_host_macros_r(mac, temp_host);
235 
236 			if(display_type == DISPLAY_SERVICE_INFO) {
237 				temp_service = find_service(host_name, service_desc);
238 				grab_service_macros_r(mac, temp_service);
239 				}
240 
241 			/* write some Javascript helper functions */
242 			if(temp_host != NULL) {
243 				printf("<SCRIPT LANGUAGE=\"JavaScript\">\n<!--\n");
244 				printf("function nagios_get_host_name()\n{\n");
245 				printf("return \"%s\";\n", temp_host->name);
246 				printf("}\n");
247 				printf("function nagios_get_host_address()\n{\n");
248 				printf("return \"%s\";\n", temp_host->address);
249 				printf("}\n");
250 				if(temp_service != NULL) {
251 					printf("function nagios_get_service_description()\n{\n");
252 					printf("return \"%s\";\n", temp_service->description);
253 					printf("}\n");
254 					}
255 				printf("//-->\n</SCRIPT>\n");
256 				}
257 			}
258 
259 		/* find the hostgroup */
260 		else if(display_type == DISPLAY_HOSTGROUP_INFO) {
261 			temp_hostgroup = find_hostgroup(hostgroup_name);
262 			grab_hostgroup_macros_r(mac, temp_hostgroup);
263 			}
264 
265 		/* find the servicegroup */
266 		else if(display_type == DISPLAY_SERVICEGROUP_INFO) {
267 			temp_servicegroup = find_servicegroup(servicegroup_name);
268 			grab_servicegroup_macros_r(mac, temp_servicegroup);
269 			}
270 
271 		if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
272 			printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='linkBox'>\n");
273 			printf("<TR><TD CLASS='linkBox'>\n");
274 			if(display_type == DISPLAY_SERVICE_INFO)
275 				printf("<A HREF='%s?type=%d&host=%s'>View Information For This Host</A><br>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(host_name));
276 			if(display_type == DISPLAY_SERVICE_INFO || display_type == DISPLAY_HOST_INFO)
277 				printf("<A HREF='%s?host=%s'>View Status Detail For This Host</A><BR>\n", STATUS_CGI, url_encode(host_name));
278 			if(display_type == DISPLAY_HOST_INFO) {
279 				printf("<A HREF='%s?host=%s'>View Alert History For This Host</A><BR>\n", HISTORY_CGI, url_encode(host_name));
280 #ifdef USE_TRENDS
281 				printf("<A HREF='%s?host=%s'>View Trends For This Host</A><BR>\n", TRENDS_CGI, url_encode(host_name));
282 #endif
283 #ifdef USE_HISTOGRAM
284 				printf("<A HREF='%s?host=%s'>View Alert Histogram For This Host</A><BR>\n", HISTOGRAM_CGI, url_encode(host_name));
285 #endif
286 				printf("<A HREF='%s?host=%s&show_log_entries'>View Availability Report For This Host</A><BR>\n", AVAIL_CGI, url_encode(host_name));
287 				printf("<A HREF='%s?host=%s'>View Notifications For This Host</A>\n", NOTIFICATIONS_CGI, url_encode(host_name));
288 				}
289 			else if(display_type == DISPLAY_SERVICE_INFO) {
290 				printf("<A HREF='%s?host=%s&", HISTORY_CGI, url_encode(host_name));
291 				printf("service=%s'>View Alert History For This Service</A><BR>\n", url_encode(service_desc));
292 #ifdef USE_TRENDS
293 				printf("<A HREF='%s?host=%s&", TRENDS_CGI, url_encode(host_name));
294 				printf("service=%s'>View Trends For This Service</A><BR>\n", url_encode(service_desc));
295 #endif
296 #ifdef USE_HISTOGRAM
297 				printf("<A HREF='%s?host=%s&", HISTOGRAM_CGI, url_encode(host_name));
298 				printf("service=%s'>View Alert Histogram For This Service</A><BR>\n", url_encode(service_desc));
299 #endif
300 				printf("<A HREF='%s?host=%s&", AVAIL_CGI, url_encode(host_name));
301 				printf("service=%s&show_log_entries'>View Availability Report For This Service</A><BR>\n", url_encode(service_desc));
302 				printf("<A HREF='%s?host=%s&", NOTIFICATIONS_CGI, url_encode(host_name));
303 				printf("service=%s'>View Notifications For This Service</A>\n", url_encode(service_desc));
304 				}
305 			else if(display_type == DISPLAY_HOSTGROUP_INFO) {
306 				printf("<A HREF='%s?hostgroup=%s&style=detail'>View Status Detail For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
307 				printf("<A HREF='%s?hostgroup=%s&style=overview'>View Status Overview For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
308 				printf("<A HREF='%s?hostgroup=%s&style=grid'>View Status Grid For This Hostgroup</A><BR>\n", STATUS_CGI, url_encode(hostgroup_name));
309 				printf("<A HREF='%s?hostgroup=%s'>View Availability For This Hostgroup</A><BR>\n", AVAIL_CGI, url_encode(hostgroup_name));
310 				}
311 			else if(display_type == DISPLAY_SERVICEGROUP_INFO) {
312 				printf("<A HREF='%s?servicegroup=%s&style=detail'>View Status Detail For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
313 				printf("<A HREF='%s?servicegroup=%s&style=overview'>View Status Overview For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
314 				printf("<A HREF='%s?servicegroup=%s&style=grid'>View Status Grid For This Servicegroup</A><BR>\n", STATUS_CGI, url_encode(servicegroup_name));
315 				printf("<A HREF='%s?servicegroup=%s'>View Availability For This Servicegroup</A><BR>\n", AVAIL_CGI, url_encode(servicegroup_name));
316 				}
317 			printf("</TD></TR>\n");
318 			printf("</TABLE>\n");
319 			}
320 
321 		printf("</td>\n");
322 
323 		/* middle column of top row */
324 		printf("<td align=center valign=middle width=33%%>\n");
325 
326 		if((display_type == DISPLAY_HOST_INFO && temp_host != NULL) || (display_type == DISPLAY_SERVICE_INFO && temp_host != NULL && temp_service != NULL) || (display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) || (display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL)) {
327 
328 			if(display_type == DISPLAY_HOST_INFO) {
329 				printf("<DIV CLASS='data'>Host</DIV>\n");
330 				printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_host->alias);
331 				printf("<DIV CLASS='dataTitle'>(%s)</DIV><BR>\n", temp_host->name);
332 
333 				if(temp_host->parent_hosts != NULL) {
334 					/* print all parent hosts */
335 					printf("<DIV CLASS='data'>Parents:</DIV>\n");
336 					for(temp_parenthost = temp_host->parent_hosts; temp_parenthost != NULL; temp_parenthost = temp_parenthost->next)
337 						printf("<DIV CLASS='dataTitle'><A HREF='%s?host=%s'>%s</A></DIV>\n", STATUS_CGI, url_encode(temp_parenthost->host_name), temp_parenthost->host_name);
338 					printf("<BR>");
339 					}
340 
341 				printf("<DIV CLASS='data'>Member of</DIV><DIV CLASS='dataTitle'>");
342 				for(temp_hostgroup = hostgroup_list; temp_hostgroup != NULL; temp_hostgroup = temp_hostgroup->next) {
343 					if(is_host_member_of_hostgroup(temp_hostgroup, temp_host) == TRUE) {
344 						if(found == TRUE)
345 							printf(", ");
346 						printf("<A HREF='%s?hostgroup=%s&style=overview'>%s</A>", STATUS_CGI, url_encode(temp_hostgroup->group_name), temp_hostgroup->group_name);
347 						found = TRUE;
348 						}
349 					}
350 
351 				if(found == FALSE)
352 					printf("No hostgroups");
353 				printf("</DIV><BR>\n");
354 				printf("<DIV CLASS='data'>%s</DIV>\n", temp_host->address);
355 				}
356 			if(display_type == DISPLAY_SERVICE_INFO) {
357 				printf("<DIV CLASS='data'>Service</DIV><DIV CLASS='dataTitle'>%s</DIV><DIV CLASS='data'>On Host</DIV>\n", service_desc);
358 				printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_host->alias);
359 				printf("<DIV CLASS='dataTitle'>(<A HREF='%s?type=%d&host=%s'>%s</a>)</DIV><BR>\n", EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_host->name), temp_host->name);
360 				printf("<DIV CLASS='data'>Member of</DIV><DIV CLASS='dataTitle'>");
361 				for(temp_servicegroup = servicegroup_list; temp_servicegroup != NULL; temp_servicegroup = temp_servicegroup->next) {
362 					if(is_service_member_of_servicegroup(temp_servicegroup, temp_service) == TRUE) {
363 						if(found == TRUE)
364 							printf(", ");
365 						printf("<A HREF='%s?servicegroup=%s&style=overview'>%s</A>", STATUS_CGI, url_encode(temp_servicegroup->group_name), temp_servicegroup->group_name);
366 						found = TRUE;
367 						}
368 					}
369 
370 				if(found == FALSE)
371 					printf("No servicegroups.");
372 				printf("</DIV><BR>\n");
373 
374 				printf("<DIV CLASS='data'>%s</DIV>\n", temp_host->address);
375 				}
376 			if(display_type == DISPLAY_HOSTGROUP_INFO) {
377 				printf("<DIV CLASS='data'>Hostgroup</DIV>\n");
378 				printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_hostgroup->alias);
379 				printf("<DIV CLASS='dataTitle'>(%s)</DIV>\n", temp_hostgroup->group_name);
380 				if(temp_hostgroup->notes != NULL) {
381 					process_macros_r(mac, temp_hostgroup->notes, &processed_string, 0);
382 					printf("<p>%s</p>", processed_string);
383 					free(processed_string);
384 					}
385 				}
386 			if(display_type == DISPLAY_SERVICEGROUP_INFO) {
387 				printf("<DIV CLASS='data'>Servicegroup</DIV>\n");
388 				printf("<DIV CLASS='dataTitle'>%s</DIV>\n", temp_servicegroup->alias);
389 				printf("<DIV CLASS='dataTitle'>(%s)</DIV>\n", temp_servicegroup->group_name);
390 				if(temp_servicegroup->notes != NULL) {
391 					process_macros_r(mac, temp_servicegroup->notes, &processed_string, 0);
392 					printf("<p>%s</p>", processed_string);
393 					free(processed_string);
394 					}
395 				}
396 
397 			if(display_type == DISPLAY_SERVICE_INFO) {
398 				if(temp_service->icon_image != NULL) {
399 					printf("<img src='%s", url_logo_images_path);
400 					process_macros_r(mac, temp_service->icon_image, &processed_string, 0);
401 					printf("%s", processed_string);
402 					free(processed_string);
403 					printf("' border=0 alt='%s' title='%s'><BR CLEAR=ALL>", (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt, (temp_service->icon_image_alt == NULL) ? "" : temp_service->icon_image_alt);
404 					}
405 				if(temp_service->icon_image_alt != NULL)
406 					printf("<font size=-1><i>( %s )</i></font>\n", temp_service->icon_image_alt);
407 				if(temp_service->notes != NULL) {
408 					process_macros_r(mac, temp_service->notes, &processed_string, 0);
409 					printf("<p>%s</p>\n", processed_string);
410 					free(processed_string);
411 					}
412 				}
413 
414 			if(display_type == DISPLAY_HOST_INFO) {
415 				if(temp_host->icon_image != NULL) {
416 					printf("<img src='%s", url_logo_images_path);
417 					process_macros_r(mac, temp_host->icon_image, &processed_string, 0);
418 					printf("%s", processed_string);
419 					free(processed_string);
420 					printf("' border=0 alt='%s' title='%s'><BR CLEAR=ALL>", (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt, (temp_host->icon_image_alt == NULL) ? "" : temp_host->icon_image_alt);
421 					}
422 				if(temp_host->icon_image_alt != NULL)
423 					printf("<font size=-1><i>( %s )</i><font>\n", temp_host->icon_image_alt);
424 				if(temp_host->notes != NULL) {
425 					process_macros_r(mac, temp_host->notes, &processed_string, 0);
426 					printf("<p>%s</p>\n", processed_string);
427 					free(processed_string);
428 					}
429 				}
430 			}
431 
432 		printf("</td>\n");
433 
434 		/* right column of top row */
435 		printf("<td align=right valign=bottom width=33%%>\n");
436 
437 		if(display_type == DISPLAY_HOST_INFO && temp_host != NULL) {
438 			printf("<TABLE BORDER='0'>\n");
439 			if(temp_host->action_url != NULL && strcmp(temp_host->action_url, "")) {
440 				printf("<TR><TD ALIGN='right'>\n");
441 				printf("<A HREF='");
442 				process_macros_r(mac, temp_host->action_url, &processed_string, 0);
443 				printf("%s", processed_string);
444 				free(processed_string);
445 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Host' title='Perform Additional Actions On This Host'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
446 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
447 				printf("</TD></TR>\n");
448 				}
449 			if(temp_host->notes_url != NULL && strcmp(temp_host->notes_url, "")) {
450 				printf("<TR><TD ALIGN='right'>\n");
451 				printf("<A HREF='");
452 				process_macros_r(mac, temp_host->notes_url, &processed_string, 0);
453 				printf("%s", processed_string);
454 				free(processed_string);
455 				/*print_extra_host_url(temp_host->name,temp_host->notes_url);*/
456 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Host' title='View Additional Notes For This Host'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
457 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
458 				printf("</TD></TR>\n");
459 				}
460 			printf("</TABLE>\n");
461 			}
462 
463 		else if(display_type == DISPLAY_SERVICE_INFO && temp_service != NULL) {
464 			printf("<TABLE BORDER='0'><TR><TD ALIGN='right'>\n");
465 			if(temp_service->action_url != NULL && strcmp(temp_service->action_url, "")) {
466 				printf("<A HREF='");
467 				process_macros_r(mac, temp_service->action_url, &processed_string, 0);
468 				printf("%s", processed_string);
469 				free(processed_string);
470 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Service' title='Perform Additional Actions On This Service'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
471 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
472 				}
473 			if(temp_service->notes_url != NULL && strcmp(temp_service->notes_url, "")) {
474 				printf("<A HREF='");
475 				process_macros_r(mac, temp_service->notes_url, &processed_string, 0);
476 				printf("%s", processed_string);
477 				free(processed_string);
478 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Service' title='View Additional Notes For This Service'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
479 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
480 				}
481 			printf("</TD></TR></TABLE>\n");
482 			}
483 
484 		if(display_type == DISPLAY_HOSTGROUP_INFO && temp_hostgroup != NULL) {
485 			printf("<TABLE BORDER='0'>\n");
486 			if(temp_hostgroup->action_url != NULL && strcmp(temp_hostgroup->action_url, "")) {
487 				printf("<TR><TD ALIGN='right'>\n");
488 				printf("<A HREF='");
489 				print_extra_hostgroup_url(temp_hostgroup->group_name, temp_hostgroup->action_url);
490 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Hostgroup' title='Perform Additional Actions On This Hostgroup'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
491 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
492 				printf("</TD></TR>\n");
493 				}
494 			if(temp_hostgroup->notes_url != NULL && strcmp(temp_hostgroup->notes_url, "")) {
495 				printf("<TR><TD ALIGN='right'>\n");
496 				printf("<A HREF='");
497 				print_extra_hostgroup_url(temp_hostgroup->group_name, temp_hostgroup->notes_url);
498 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Hostgroup' title='View Additional Notes For This Hostgroup'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
499 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
500 				printf("</TD></TR>\n");
501 				}
502 			printf("</TABLE>\n");
503 			}
504 
505 		else if(display_type == DISPLAY_SERVICEGROUP_INFO && temp_servicegroup != NULL) {
506 			printf("<TABLE BORDER='0'>\n");
507 			if(temp_servicegroup->action_url != NULL && strcmp(temp_servicegroup->action_url, "")) {
508 				printf("<A HREF='");
509 				print_extra_servicegroup_url(temp_servicegroup->group_name, temp_servicegroup->action_url);
510 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='Perform Additional Actions On This Servicegroup' title='Perform Additional Actions On This Servicegroup'></A>\n", (action_url_target == NULL) ? "_blank" : action_url_target, url_images_path, ACTION_ICON);
511 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Actions</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
512 				}
513 			if(temp_servicegroup->notes_url != NULL && strcmp(temp_servicegroup->notes_url, "")) {
514 				printf("<A HREF='");
515 				print_extra_servicegroup_url(temp_servicegroup->group_name, temp_servicegroup->notes_url);
516 				printf("' TARGET='%s'><img src='%s%s' border=0 alt='View Additional Notes For This Servicegroup' title='View Additional Notes For This Servicegroup'></A>\n", (notes_url_target == NULL) ? "_blank" : notes_url_target, url_images_path, NOTES_ICON);
517 				printf("<BR CLEAR=ALL><FONT SIZE=-1><I>Extra Notes</I></FONT><BR CLEAR=ALL><BR CLEAR=ALL>\n");
518 				}
519 			printf("</TABLE>\n");
520 			}
521 
522 		/* display context-sensitive help */
523 		if(display_type == DISPLAY_HOST_INFO)
524 			display_context_help(CONTEXTHELP_EXT_HOST);
525 		else if(display_type == DISPLAY_SERVICE_INFO)
526 			display_context_help(CONTEXTHELP_EXT_SERVICE);
527 		else if(display_type == DISPLAY_HOSTGROUP_INFO)
528 			display_context_help(CONTEXTHELP_EXT_HOSTGROUP);
529 		else if(display_type == DISPLAY_SERVICEGROUP_INFO)
530 			display_context_help(CONTEXTHELP_EXT_SERVICEGROUP);
531 		else if(display_type == DISPLAY_PROCESS_INFO)
532 			display_context_help(CONTEXTHELP_EXT_PROCESS);
533 		else if(display_type == DISPLAY_PERFORMANCE)
534 			display_context_help(CONTEXTHELP_EXT_PERFORMANCE);
535 		else if(display_type == DISPLAY_COMMENTS)
536 			display_context_help(CONTEXTHELP_EXT_COMMENTS);
537 		else if(display_type == DISPLAY_DOWNTIME)
538 			display_context_help(CONTEXTHELP_EXT_DOWNTIME);
539 		else if(display_type == DISPLAY_SCHEDULING_QUEUE)
540 			display_context_help(CONTEXTHELP_EXT_QUEUE);
541 
542 		printf("</td>\n");
543 
544 		/* end of top table */
545 		printf("</tr>\n");
546 		printf("</table>\n");
547 
548 		}
549 
550 	printf("<BR>\n");
551 
552 	if(display_type == DISPLAY_HOST_INFO)
553 		show_host_info();
554 	else if(display_type == DISPLAY_SERVICE_INFO)
555 		show_service_info();
556 	else if(display_type == DISPLAY_COMMENTS)
557 		show_all_comments();
558 	else if(display_type == DISPLAY_PERFORMANCE)
559 		show_performance_data();
560 	else if(display_type == DISPLAY_HOSTGROUP_INFO)
561 		show_hostgroup_info();
562 	else if(display_type == DISPLAY_SERVICEGROUP_INFO)
563 		show_servicegroup_info();
564 	else if(display_type == DISPLAY_DOWNTIME)
565 		show_all_downtime();
566 	else if(display_type == DISPLAY_SCHEDULING_QUEUE)
567 		show_scheduling_queue();
568 	else
569 		show_process_info();
570 
571 	document_footer();
572 
573 	/* free all allocated memory */
574 	free_memory();
575 	free_comment_data();
576 	free_downtime_data();
577 
578 	return OK;
579 	}
580 
581 
582 
document_header(int use_stylesheet)583 void document_header(int use_stylesheet) {
584 	char date_time[MAX_DATETIME_LENGTH];
585 	time_t current_time;
586 	time_t expire_time;
587 
588 	printf("Cache-Control: no-store\r\n");
589 	printf("Pragma: no-cache\r\n");
590 	printf("Refresh: %d\r\n", refresh_rate);
591 
592 	time(&current_time);
593 	get_time_string(&current_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
594 	printf("Last-Modified: %s\r\n", date_time);
595 
596 	expire_time = (time_t)0L;
597 	get_time_string(&expire_time, date_time, (int)sizeof(date_time), HTTP_DATE_TIME);
598 	printf("Expires: %s\r\n", date_time);
599 
600 	printf("Content-type: text/html\r\n\r\n");
601 
602 	if(embedded == TRUE)
603 		return;
604 
605 	printf("<html>\n");
606 	printf("<head>\n");
607 	printf("<link rel=\"shortcut icon\" href=\"%sfavicon.ico\" type=\"image/ico\">\n", url_images_path);
608 	printf("<title>\n");
609 	printf("Extended Information\n");
610 	printf("</title>\n");
611 
612 	if(use_stylesheet == TRUE) {
613 		printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, COMMON_CSS);
614 		printf("<LINK REL='stylesheet' TYPE='text/css' HREF='%s%s'>", url_stylesheets_path, EXTINFO_CSS);
615 		}
616 	printf("</head>\n");
617 
618 	printf("<body CLASS='extinfo'>\n");
619 
620 	/* include user SSI header */
621 	include_ssi_files(EXTINFO_CGI, SSI_HEADER);
622 
623 	return;
624 	}
625 
626 
document_footer(void)627 void document_footer(void) {
628 
629 	if(embedded == TRUE)
630 		return;
631 
632 	/* include user SSI footer */
633 	include_ssi_files(EXTINFO_CGI, SSI_FOOTER);
634 
635 	printf("</body>\n");
636 	printf("</html>\n");
637 
638 	return;
639 	}
640 
641 
process_cgivars(void)642 int process_cgivars(void) {
643 	char **variables;
644 	int error = FALSE;
645 	int temp_type;
646 	int x;
647 
648 	variables = getcgivars();
649 
650 	for(x = 0; variables[x] != NULL; x++) {
651 
652 		/* do some basic length checking on the variable identifier to prevent buffer overflows */
653 		if(strlen(variables[x]) >= MAX_INPUT_BUFFER - 1) {
654 			continue;
655 			}
656 
657 		/* we found the display type */
658 		else if(!strcmp(variables[x], "type")) {
659 			x++;
660 			if(variables[x] == NULL) {
661 				error = TRUE;
662 				break;
663 				}
664 			temp_type = atoi(variables[x]);
665 			if(temp_type == DISPLAY_HOST_INFO)
666 				display_type = DISPLAY_HOST_INFO;
667 			else if(temp_type == DISPLAY_SERVICE_INFO)
668 				display_type = DISPLAY_SERVICE_INFO;
669 			else if(temp_type == DISPLAY_COMMENTS)
670 				display_type = DISPLAY_COMMENTS;
671 			else if(temp_type == DISPLAY_PERFORMANCE)
672 				display_type = DISPLAY_PERFORMANCE;
673 			else if(temp_type == DISPLAY_HOSTGROUP_INFO)
674 				display_type = DISPLAY_HOSTGROUP_INFO;
675 			else if(temp_type == DISPLAY_SERVICEGROUP_INFO)
676 				display_type = DISPLAY_SERVICEGROUP_INFO;
677 			else if(temp_type == DISPLAY_DOWNTIME)
678 				display_type = DISPLAY_DOWNTIME;
679 			else if(temp_type == DISPLAY_SCHEDULING_QUEUE)
680 				display_type = DISPLAY_SCHEDULING_QUEUE;
681 			else
682 				display_type = DISPLAY_PROCESS_INFO;
683 			}
684 
685 		/* we found the host name */
686 		else if(!strcmp(variables[x], "host")) {
687 			x++;
688 			if(variables[x] == NULL) {
689 				error = TRUE;
690 				break;
691 				}
692 
693 			host_name = strdup(variables[x]);
694 			if(host_name == NULL)
695 				host_name = "";
696 			strip_html_brackets(host_name);
697 			}
698 
699 		/* we found the hostgroup name */
700 		else if(!strcmp(variables[x], "hostgroup")) {
701 			x++;
702 			if(variables[x] == NULL) {
703 				error = TRUE;
704 				break;
705 				}
706 
707 			hostgroup_name = strdup(variables[x]);
708 			if(hostgroup_name == NULL)
709 				hostgroup_name = "";
710 			strip_html_brackets(hostgroup_name);
711 			}
712 
713 		/* we found the service name */
714 		else if(!strcmp(variables[x], "service")) {
715 			x++;
716 			if(variables[x] == NULL) {
717 				error = TRUE;
718 				break;
719 				}
720 
721 			service_desc = strdup(variables[x]);
722 			if(service_desc == NULL)
723 				service_desc = "";
724 			strip_html_brackets(service_desc);
725 			}
726 
727 		/* we found the servicegroup name */
728 		else if(!strcmp(variables[x], "servicegroup")) {
729 			x++;
730 			if(variables[x] == NULL) {
731 				error = TRUE;
732 				break;
733 				}
734 
735 			servicegroup_name = strdup(variables[x]);
736 			if(servicegroup_name == NULL)
737 				servicegroup_name = "";
738 			strip_html_brackets(servicegroup_name);
739 			}
740 
741 		/* we found the sort type argument */
742 		else if(!strcmp(variables[x], "sorttype")) {
743 			x++;
744 			if(variables[x] == NULL) {
745 				error = TRUE;
746 				break;
747 				}
748 
749 			sort_type = atoi(variables[x]);
750 			}
751 
752 		/* we found the sort option argument */
753 		else if(!strcmp(variables[x], "sortoption")) {
754 			x++;
755 			if(variables[x] == NULL) {
756 				error = TRUE;
757 				break;
758 				}
759 
760 			sort_option = atoi(variables[x]);
761 			}
762 
763 		/* we found the embed option */
764 		else if(!strcmp(variables[x], "embedded"))
765 			embedded = TRUE;
766 
767 		/* we found the noheader option */
768 		else if(!strcmp(variables[x], "noheader"))
769 			display_header = FALSE;
770 		}
771 
772 	/* free memory allocated to the CGI variables */
773 	free_cgivars(variables);
774 
775 	return error;
776 	}
777 
778 
779 
show_process_info(void)780 void show_process_info(void) {
781 	char date_time[MAX_DATETIME_LENGTH];
782 	time_t current_time;
783 	unsigned long run_time;
784 	char run_time_string[24];
785 	int days = 0;
786 	int hours = 0;
787 	int minutes = 0;
788 	int seconds = 0;
789 
790 	/* make sure the user has rights to view system information */
791 	if(is_authorized_for_system_information(&current_authdata) == FALSE) {
792 
793 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view process information...</DIV></P>\n");
794 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
795 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
796 
797 		return;
798 		}
799 
800 	printf("<BR />\n");
801 	printf("<DIV ALIGN=CENTER>\n");
802 
803 	printf("<TABLE BORDER=0 CELLPADDING=20>\n");
804 	printf("<TR><TD VALIGN=TOP>\n");
805 
806 	printf("<DIV CLASS='dataTitle'>Process Information</DIV>\n");
807 
808 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='data'>\n");
809 	printf("<TR><TD class='stateInfoTable1'>\n");
810 	printf("<TABLE BORDER=0>\n");
811 
812 	/* program version */
813 	printf("<TR><TD CLASS='dataVar'>Program Version:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", PROGRAM_VERSION);
814 
815 	/* program start time */
816 	get_time_string(&program_start, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
817 	printf("<TR><TD CLASS='dataVar'>Program Start Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time);
818 
819 	/* total running time */
820 	time(&current_time);
821 	run_time = (unsigned long)(current_time - program_start);
822 	get_time_breakdown(run_time, &days, &hours, &minutes, &seconds);
823 	sprintf(run_time_string, "%dd %dh %dm %ds", days, hours, minutes, seconds);
824 	printf("<TR><TD CLASS='dataVar'>Total Running Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", run_time_string);
825 
826 	/* last external check */
827 	get_time_string(&last_command_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
828 	printf("<TR><TD CLASS='dataVar'>Last External Command Check:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_command_check == (time_t)0) ? "N/A" : date_time);
829 
830 	/* last log file rotation */
831 	get_time_string(&last_log_rotation, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
832 	printf("<TR><TD CLASS='dataVar'>Last Log File Rotation:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (last_log_rotation == (time_t)0) ? "N/A" : date_time);
833 
834 	/* PID */
835 	printf("<TR><TD CLASS='dataVar'>Nagios PID</TD><TD CLASS='dataVal'>%d</TD></TR>\n", nagios_pid);
836 
837 	/* notifications enabled */
838 	printf("<TR><TD CLASS='dataVar'>Notifications Enabled?</TD><TD CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (enable_notifications == TRUE) ? "ENABLED" : "DISABLED", (enable_notifications == TRUE) ? "YES" : "NO");
839 
840 	/* service check execution enabled */
841 	printf("<TR><TD CLASS='dataVar'>Service Checks Being Executed?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (execute_service_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_service_checks == TRUE) ? "YES" : "NO");
842 
843 	/* passive service check acceptance */
844 	printf("<TR><TD CLASS='dataVar'>Passive Service Checks Being Accepted?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (accept_passive_service_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_service_checks == TRUE) ? "YES" : "NO");
845 
846 	/* host check execution enabled */
847 	printf("<TR><TD CLASS='dataVar'>Host Checks Being Executed?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (execute_host_checks == TRUE) ? "ENABLED" : "DISABLED", (execute_host_checks == TRUE) ? "YES" : "NO");
848 
849 	/* passive host check acceptance */
850 	printf("<TR><TD CLASS='dataVar'>Passive Host Checks Being Accepted?</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (accept_passive_host_checks == TRUE) ? "ENABLED" : "DISABLED", (accept_passive_host_checks == TRUE) ? "YES" : "NO");
851 
852 	/* event handlers enabled */
853 	printf("<TR><TD CLASS='dataVar'>Event Handlers Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_event_handlers == TRUE) ? "Yes" : "No");
854 
855 	/* obsessing over services */
856 	printf("<TR><TD CLASS='dataVar'>Obsessing Over Services?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (obsess_over_services == TRUE) ? "Yes" : "No");
857 
858 	/* obsessing over hosts */
859 	printf("<TR><TD CLASS='dataVar'>Obsessing Over Hosts?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (obsess_over_hosts == TRUE) ? "Yes" : "No");
860 
861 	/* flap detection enabled */
862 	printf("<TR><TD CLASS='dataVar'>Flap Detection Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_flap_detection == TRUE) ? "Yes" : "No");
863 
864 #ifdef PREDICT_FAILURES
865 	/* failure prediction enabled */
866 	printf("<TR><TD CLASS='dataVar'>Failure Prediction Enabled?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (enable_failure_prediction == TRUE) ? "Yes" : "No");
867 #endif
868 
869 	/* process performance data */
870 	printf("<TR><TD CLASS='dataVar'>Performance Data Being Processed?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (process_performance_data == TRUE) ? "Yes" : "No");
871 
872 #ifdef USE_OLDCRUD
873 	/* daemon mode */
874 	printf("<TR><TD CLASS='dataVar'>Running As A Daemon?</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (daemon_mode == TRUE) ? "Yes" : "No");
875 #endif
876 
877 	printf("</TABLE>\n");
878 	printf("</TD></TR>\n");
879 	printf("</TABLE>\n");
880 
881 
882 	printf("</TD><TD VALIGN=TOP>\n");
883 
884 	printf("<DIV CLASS='commandTitle'>Process Commands</DIV>\n");
885 
886 	printf("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 CLASS='command'>\n");
887 	printf("<TR><TD>\n");
888 
889 	if(nagios_process_state == STATE_OK) {
890 		printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 CLASS='command'>\n");
891 
892 #ifndef DUMMY_INSTALL
893 		printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Shutdown the Nagios Process' TITLE='Shutdown the Nagios Process'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Shutdown the Nagios process</a></td></tr>\n", url_images_path, STOP_ICON, COMMAND_CGI, CMD_SHUTDOWN_PROCESS);
894 		printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Restart the Nagios Process' TITLE='Restart the Nagios Process'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Restart the Nagios process</a></td></tr>\n", url_images_path, RESTART_ICON, COMMAND_CGI, CMD_RESTART_PROCESS);
895 #endif
896 
897 		if(enable_notifications == TRUE)
898 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Notifications' TITLE='Disable Notifications'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable notifications</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_NOTIFICATIONS);
899 		else
900 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Notifications' TITLE='Enable Notifications'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable notifications</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_NOTIFICATIONS);
901 
902 		if(execute_service_checks == TRUE)
903 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Executing Service Checks' TITLE='Stop Executing Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop executing service checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_SVC_CHECKS);
904 		else
905 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Executing Service Checks' TITLE='Start Executing Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start executing service checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_SVC_CHECKS);
906 
907 		if(accept_passive_service_checks == TRUE)
908 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Accepting Passive Service Checks' TITLE='Stop Accepting Passive Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop accepting passive service checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS);
909 		else
910 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Accepting Passive Service Checks' TITLE='Start Accepting Passive Service Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start accepting passive service checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS);
911 
912 		if(execute_host_checks == TRUE)
913 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Executing Host Checks' TITLE='Stop Executing Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop executing host checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_EXECUTING_HOST_CHECKS);
914 		else
915 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Executing Host Checks' TITLE='Start Executing Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start executing host checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_EXECUTING_HOST_CHECKS);
916 
917 		if(accept_passive_host_checks == TRUE)
918 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Accepting Passive Host Checks' TITLE='Stop Accepting Passive Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop accepting passive host checks</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_ACCEPTING_PASSIVE_HOST_CHECKS);
919 		else
920 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Accepting Passive Host Checks' TITLE='Start Accepting Passive Host Checks'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start accepting passive host checks</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_ACCEPTING_PASSIVE_HOST_CHECKS);
921 
922 		if(enable_event_handlers == TRUE)
923 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Event Handlers' TITLE='Disable Event Handlers'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable event handlers</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_EVENT_HANDLERS);
924 		else
925 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Event Handlers' TITLE='Enable Event Handlers'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable event handlers</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_EVENT_HANDLERS);
926 
927 		if(obsess_over_services == TRUE)
928 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Obsessing Over Services' TITLE='Stop Obsessing Over Services'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop obsessing over services</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC_CHECKS);
929 		else
930 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Obsessing Over Services' TITLE='Start Obsessing Over Services'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start obsessing over services</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_SVC_CHECKS);
931 
932 		if(obsess_over_hosts == TRUE)
933 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Stop Obsessing Over Hosts' TITLE='Stop Obsessing Over Hosts'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Stop obsessing over hosts</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST_CHECKS);
934 		else
935 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Start Obsessing Over Hosts' TITLE='Start Obsessing Over Hosts'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Start obsessing over hosts</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST_CHECKS);
936 
937 		if(enable_flap_detection == TRUE)
938 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Flap Detection' TITLE='Disable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable flap detection</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_FLAP_DETECTION);
939 		else
940 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Flap Detection' TITLE='Enable Flap Detection'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable flap detection</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FLAP_DETECTION);
941 
942 #ifdef PREDICT_FAILURES
943 		if(enable_failure_prediction == TRUE)
944 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Failure Prediction' TITLE='Disable Failure Prediction'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable failure prediction</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_FAILURE_PREDICTION);
945 		else
946 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Failure Prediction' TITLE='Enable Failure Prediction'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable failure prediction</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_FAILURE_PREDICTION);
947 #endif
948 		if(process_performance_data == TRUE)
949 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Disable Performance Data' TITLE='Disable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Disable performance data</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PERFORMANCE_DATA);
950 		else
951 			printf("<TR CLASS='command'><TD><img src='%s%s' border=0 ALT='Enable Performance Data' TITLE='Enable Performance Data'></td><td CLASS='command'><a href='%s?cmd_typ=%d'>Enable performance data</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PERFORMANCE_DATA);
952 
953 		printf("</TABLE>\n");
954 		}
955 	else {
956 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...\n");
957 		if(!strcmp(nagios_check_command, "")) {
958 			printf("<BR><BR>\n");
959 			printf("Hint: It looks as though you have not defined a command for checking the process state by supplying a value for the <b>nagios_check_command</b> option in the CGI configuration file.<BR>\n");
960 			printf("Read the documentation for more information on checking the status of the Nagios process in the CGIs.\n");
961 			}
962 		printf("</DIV>\n");
963 		}
964 
965 	printf("</TD></TR>\n");
966 	printf("</TABLE>\n");
967 
968 	printf("</TD></TR></TABLE>\n");
969 	printf("</DIV>\n");
970 	}
971 
972 
show_host_info(void)973 void show_host_info(void) {
974 	hoststatus *temp_hoststatus;
975 	host *temp_host;
976 	char date_time[MAX_DATETIME_LENGTH];
977 	char state_duration[48];
978 	char status_age[48];
979 	char state_string[MAX_INPUT_BUFFER];
980 	char *bg_class = "";
981 	char *buf = NULL;
982 	int days;
983 	int hours;
984 	int minutes;
985 	int seconds;
986 	time_t current_time;
987 	time_t t;
988 	int duration_error = FALSE;
989 
990 
991 	/* get host info */
992 	temp_host = find_host(host_name);
993 
994 	/* make sure the user has rights to view host information */
995 	if(is_authorized_for_host(temp_host, &current_authdata) == FALSE) {
996 
997 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this host...</DIV></P>\n");
998 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
999 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1000 
1001 		return;
1002 		}
1003 
1004 	/* get host status info */
1005 	temp_hoststatus = find_hoststatus(host_name);
1006 
1007 	/* make sure host information exists */
1008 	if(temp_host == NULL) {
1009 		printf("<P><DIV CLASS='errorMessage'>Error: Host Not Found!</DIV></P>>");
1010 		return;
1011 		}
1012 	if(temp_hoststatus == NULL) {
1013 		printf("<P><DIV CLASS='errorMessage'>Error: Host Status Information Not Found!</DIV></P");
1014 		return;
1015 		}
1016 
1017 
1018 	printf("<DIV ALIGN=CENTER>\n");
1019 	printf("<TABLE BORDER=0 CELLPADDING=0 WIDTH=100%%>\n");
1020 	printf("<TR>\n");
1021 
1022 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1023 
1024 	printf("<DIV CLASS='dataTitle'>Host State Information</DIV>\n");
1025 
1026 	if(temp_hoststatus->has_been_checked == FALSE)
1027 		printf("<P><DIV ALIGN=CENTER>This host has not yet been checked, so status information is not available.</DIV></P>\n");
1028 
1029 	else {
1030 
1031 		printf("<TABLE BORDER=0>\n");
1032 		printf("<TR><TD>\n");
1033 
1034 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1035 		printf("<TR><TD class='stateInfoTable1'>\n");
1036 		printf("<TABLE BORDER=0>\n");
1037 
1038 		current_time = time(NULL);
1039 		t = 0;
1040 		duration_error = FALSE;
1041 		if(temp_hoststatus->last_state_change == (time_t)0) {
1042 			if(program_start > current_time)
1043 				duration_error = TRUE;
1044 			else
1045 				t = current_time - program_start;
1046 			}
1047 		else {
1048 			if(temp_hoststatus->last_state_change > current_time)
1049 				duration_error = TRUE;
1050 			else
1051 				t = current_time - temp_hoststatus->last_state_change;
1052 			}
1053 		get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1054 		if(duration_error == TRUE)
1055 			snprintf(state_duration, sizeof(state_duration) - 1, "???");
1056 		else
1057 			snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_hoststatus->last_state_change == (time_t)0) ? "+" : "");
1058 		state_duration[sizeof(state_duration) - 1] = '\x0';
1059 
1060 		if(temp_hoststatus->status == HOST_UP) {
1061 			strcpy(state_string, "UP");
1062 			bg_class = "hostUP";
1063 			}
1064 		else if(temp_hoststatus->status == HOST_DOWN) {
1065 			strcpy(state_string, "DOWN");
1066 			bg_class = "hostDOWN";
1067 			}
1068 		else if(temp_hoststatus->status == HOST_UNREACHABLE) {
1069 			strcpy(state_string, "UNREACHABLE");
1070 			bg_class = "hostUNREACHABLE";
1071 			}
1072 
1073 		printf("<TR><TD CLASS='dataVar'>Host Status:</td><td CLASS='dataVal'><DIV CLASS='%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV>&nbsp;(for %s)%s</td></tr>\n", bg_class, state_string, state_duration, (temp_hoststatus->problem_has_been_acknowledged == TRUE) ? "&nbsp;&nbsp;(Has been acknowledged)" : "");
1074 
1075 		printf("<TR><TD CLASS='dataVar' VALIGN='top'>Status Information:</td><td CLASS='dataVal'>%s", (temp_hoststatus->plugin_output == NULL) ? "" : html_encode(temp_hoststatus->plugin_output, TRUE));
1076 		if(enable_splunk_integration == TRUE) {
1077 			printf("&nbsp;&nbsp;");
1078 			asprintf(&buf, "%s %s", temp_host->name, temp_hoststatus->plugin_output);
1079 			display_splunk_generic_url(buf, 1);
1080 			free(buf);
1081 			}
1082 		if(temp_hoststatus->long_plugin_output != NULL)
1083 			printf("<BR>%s", html_encode(temp_hoststatus->long_plugin_output, TRUE));
1084 		printf("</TD></TR>\n");
1085 
1086 		printf("<TR><TD CLASS='dataVar' VALIGN='top'>Performance Data:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_hoststatus->perf_data == NULL) ? "" : html_encode(temp_hoststatus->perf_data, TRUE));
1087 
1088 		printf("<TR><TD CLASS='dataVar'>Current Attempt:</TD><TD CLASS='dataVal'>%d/%d", temp_hoststatus->current_attempt, temp_hoststatus->max_attempts);
1089 		printf("&nbsp;&nbsp;(%s state)</TD></TR>\n", (temp_hoststatus->state_type == HARD_STATE) ? "HARD" : "SOFT");
1090 
1091 		get_time_string(&temp_hoststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1092 		printf("<TR><TD CLASS='dataVar'>Last Check Time:</td><td CLASS='dataVal'>%s</td></tr>\n", date_time);
1093 
1094 		printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->check_type == HOST_CHECK_ACTIVE) ? "ACTIVE" : "PASSIVE");
1095 
1096 		printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
1097 		if(temp_hoststatus->check_type == HOST_CHECK_ACTIVE)
1098 			printf("%.3f", temp_hoststatus->latency);
1099 		else
1100 			printf("N/A");
1101 		printf("&nbsp;/&nbsp;%.3f seconds", temp_hoststatus->execution_time);
1102 		printf("</TD></TR>\n");
1103 
1104 		get_time_string(&temp_hoststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1105 		printf("<TR><TD CLASS='dataVar'>Next Scheduled Active Check:&nbsp;&nbsp;</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_hoststatus->checks_enabled && temp_hoststatus->next_check != (time_t)0 && temp_hoststatus->should_be_scheduled == TRUE) ? date_time : "N/A");
1106 
1107 		get_time_string(&temp_hoststatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1108 		printf("<TR><TD CLASS='dataVar'>Last State Change:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_hoststatus->last_state_change == (time_t)0) ? "N/A" : date_time);
1109 
1110 		get_time_string(&temp_hoststatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1111 		printf("<TR><TD CLASS='dataVar'>Last Notification:</td><td CLASS='dataVal'>%s&nbsp;(notification %d)</td></tr>\n", (temp_hoststatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_hoststatus->current_notification_number);
1112 
1113 		printf("<TR><TD CLASS='dataVar'>Is This Host Flapping?</td><td CLASS='dataVal'>");
1114 		if(temp_hoststatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE)
1115 			printf("N/A");
1116 		else
1117 			printf("<DIV CLASS='%sflapping'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV>&nbsp;(%3.2f%% state change)", (temp_hoststatus->is_flapping == TRUE) ? "" : "not", (temp_hoststatus->is_flapping == TRUE) ? "YES" : "NO", temp_hoststatus->percent_state_change);
1118 		printf("</td></tr>\n");
1119 
1120 		printf("<TR><TD CLASS='dataVar'>In Scheduled Downtime?</td><td CLASS='dataVal'><DIV CLASS='downtime%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_hoststatus->scheduled_downtime_depth > 0) ? "YES" : "NO");
1121 
1122 		t = 0;
1123 		duration_error = FALSE;
1124 		if(temp_hoststatus->last_check > current_time)
1125 			duration_error = TRUE;
1126 		else
1127 			/*t=current_time-temp_hoststatus->last_check;*/
1128 			t = current_time - temp_hoststatus->last_update;
1129 		get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1130 		if(duration_error == TRUE)
1131 			snprintf(status_age, sizeof(status_age) - 1, "???");
1132 		else if(temp_hoststatus->last_check == (time_t)0)
1133 			snprintf(status_age, sizeof(status_age) - 1, "N/A");
1134 		else
1135 			snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds);
1136 		status_age[sizeof(status_age) - 1] = '\x0';
1137 
1138 		get_time_string(&temp_hoststatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1139 		printf("<TR><TD CLASS='dataVar'>Last Update:</td><td CLASS='dataVal'>%s&nbsp;&nbsp;(%s ago)</td></tr>\n", (temp_hoststatus->last_update == (time_t)0) ? "N/A" : date_time, status_age);
1140 
1141 		printf("</TABLE>\n");
1142 		printf("</TD></TR>\n");
1143 		printf("</TABLE>\n");
1144 
1145 		printf("</TD></TR>\n");
1146 		printf("<TR><TD>\n");
1147 
1148 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1149 		printf("<TR><TD class='stateInfoTable2'>\n");
1150 		printf("<TABLE BORDER=0>\n");
1151 
1152 		printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><TD CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
1153 
1154 		printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->accept_passive_host_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->accept_passive_host_checks) ? "ENABLED" : "DISABLED");
1155 
1156 		printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_hoststatus->obsess_over_host == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->obsess_over_host) ? "ENABLED" : "DISABLED");
1157 
1158 		printf("<TR><TD CLASS='dataVar'>Notifications:</td><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->notifications_enabled) ? "ENABLED" : "DISABLED");
1159 
1160 		printf("<TR><TD CLASS='dataVar'>Event Handler:</td><td CLASS='dataVal'><DIV CLASS='eventhandlers%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_hoststatus->event_handler_enabled) ? "ENABLED" : "DISABLED");
1161 
1162 		printf("<TR><TD CLASS='dataVar'>Flap Detection:</td><td CLASS='dataVal'><DIV CLASS='flapdetection%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></td></tr>\n", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hoststatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED");
1163 
1164 		printf("</TABLE>\n");
1165 		printf("</TD></TR>\n");
1166 		printf("</TABLE>\n");
1167 
1168 		printf("</TD></TR>\n");
1169 		printf("</TABLE>\n");
1170 		}
1171 
1172 	printf("</TD>\n");
1173 
1174 	printf("<TD ALIGN=CENTER VALIGN=TOP>\n");
1175 	printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0><TR>\n");
1176 
1177 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='commandPanel'>\n");
1178 
1179 	printf("<DIV CLASS='commandTitle'>Host Commands</DIV>\n");
1180 
1181 	printf("<TABLE BORDER='1' CELLPADDING=0 CELLSPACING=0><TR><TD>\n");
1182 
1183 	if(nagios_process_state == STATE_OK && is_authorized_for_read_only(&current_authdata) == FALSE) {
1184 
1185 		printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1186 #ifdef USE_STATUSMAP
1187 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Locate Host On Map' TITLE='Locate Host On Map'></td><td CLASS='command'><a href='%s?host=%s'>Locate host on map</a></td></tr>\n", url_images_path, STATUSMAP_ICON, STATUSMAP_CGI, url_encode(host_name));
1188 #endif
1189 		if(temp_hoststatus->checks_enabled == TRUE) {
1190 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of This Host' TITLE='Disable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable active checks of this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_CHECK, url_encode(host_name));
1191 			}
1192 		else
1193 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable active checks of this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(host_name));
1194 		printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Host Check' TITLE='Re-schedule Next Host Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s%s'>Re-schedule the next check of this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(host_name), (temp_hoststatus->checks_enabled == TRUE) ? "&force_check" : "");
1195 
1196 		if(temp_hoststatus->accept_passive_host_checks == TRUE) {
1197 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Host' TITLE='Submit Passive Check Result For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Submit passive check result for this host</a></td></tr>\n", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_HOST_CHECK_RESULT, url_encode(host_name));
1198 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Host' TITLE='Stop Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop accepting passive checks for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
1199 			}
1200 		else
1201 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Host' TITLE='Start Accepting Passive Checks For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start accepting passive checks for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_HOST_CHECKS, url_encode(host_name));
1202 
1203 		if(temp_hoststatus->obsess_over_host == TRUE)
1204 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Host' TITLE='Stop Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Stop obsessing over this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_HOST, url_encode(host_name));
1205 		else
1206 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Host' TITLE='Start Obsessing Over This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Start obsessing over this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_HOST, url_encode(host_name));
1207 
1208 		if(temp_hoststatus->status == HOST_DOWN || temp_hoststatus->status == HOST_UNREACHABLE) {
1209 			if(temp_hoststatus->problem_has_been_acknowledged == FALSE)
1210 				printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Host Problem' TITLE='Acknowledge This Host Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Acknowledge this host problem</a></td></tr>\n", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_HOST_PROBLEM, url_encode(host_name));
1211 			else
1212 				printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Remove Problem Acknowledgement' TITLE='Remove Problem Acknowledgement'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Remove problem acknowledgement</a></td></tr>\n", url_images_path, REMOVE_ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_REMOVE_HOST_ACKNOWLEDGEMENT, url_encode(host_name));
1213 			}
1214 
1215 		if(temp_hoststatus->notifications_enabled == TRUE)
1216 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For This Host' TITLE='Disable Notifications For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable notifications for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_NOTIFICATIONS, url_encode(host_name));
1217 		else
1218 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For This Host' TITLE='Enable Notifications For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable notifications for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_NOTIFICATIONS, url_encode(host_name));
1219 
1220 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Send custom host notification</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_HOST_NOTIFICATION, url_encode(host_name));
1221 
1222 		if(temp_hoststatus->status != HOST_UP)
1223 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Host Notification' TITLE='Delay Next Host Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Delay next host notification</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_HOST_NOTIFICATION, url_encode(host_name));
1224 
1225 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Host' TITLE='Schedule Downtime For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME, url_encode(host_name));
1226 
1227 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services On This Host' TITLE='Schedule Downtime For All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule downtime for all services on this host</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_DOWNTIME, url_encode(host_name));
1228 
1229 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services On This Host' TITLE='Disable Notifications For All Services On This Host'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s'>Disable notifications for all services on this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name));
1230 
1231 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services On This Host' TITLE='Enable Notifications For All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable notifications for all services on this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_NOTIFICATIONS, url_encode(host_name));
1232 
1233 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule A Check Of All Services On This Host' TITLE='Schedule A Check Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Schedule a check of all services on this host</a></td></tr>\n", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_HOST_SVC_CHECKS, url_encode(host_name));
1234 
1235 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Checks Of All Services On This Host' TITLE='Disable Checks Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable checks of all services on this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_SVC_CHECKS, url_encode(host_name));
1236 
1237 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Checks Of All Services On This Host' TITLE='Enable Checks Of All Services On This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable checks of all services on this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_SVC_CHECKS, url_encode(host_name));
1238 
1239 		if(temp_hoststatus->event_handler_enabled == TRUE)
1240 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Host' TITLE='Disable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable event handler for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_EVENT_HANDLER, url_encode(host_name));
1241 		else
1242 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Host' TITLE='Enable Event Handler For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable event handler for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_EVENT_HANDLER, url_encode(host_name));
1243 		if(temp_hoststatus->flap_detection_enabled == TRUE)
1244 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Host' TITLE='Disable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Disable flap detection for this host</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOST_FLAP_DETECTION, url_encode(host_name));
1245 		else
1246 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Host' TITLE='Enable Flap Detection For This Host'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s'>Enable flap detection for this host</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOST_FLAP_DETECTION, url_encode(host_name));
1247 
1248 		printf("</TABLE>\n");
1249 		}
1250 	else if(is_authorized_for_read_only(&current_authdata) == TRUE) {
1251 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1252 		}
1253 	else {
1254 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1255 		printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1256 		}
1257 	printf("</TD></TR></TABLE>\n");
1258 
1259 	printf("</TD>\n");
1260 
1261 	printf("</TR>\n");
1262 	printf("</TABLE></TR>\n");
1263 
1264 	printf("<TR>\n");
1265 
1266 	printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
1267 
1268 	if(is_authorized_for_read_only(&current_authdata) == FALSE) {
1269 		/* display comments */
1270 		display_comments(HOST_COMMENT);
1271 		}
1272 	printf("</TD>\n");
1273 
1274 	printf("</TR>\n");
1275 	printf("</TABLE>\n");
1276 	printf("</DIV>\n");
1277 
1278 	return;
1279 	}
1280 
1281 
show_service_info(void)1282 void show_service_info(void) {
1283 	service *temp_service;
1284 	char date_time[MAX_DATETIME_LENGTH];
1285 	char status_age[48];
1286 	char state_duration[48];
1287 	servicestatus *temp_svcstatus;
1288 	char state_string[MAX_INPUT_BUFFER];
1289 	char *bg_class = "";
1290 	char *buf = NULL;
1291 	int days;
1292 	int hours;
1293 	int minutes;
1294 	int seconds;
1295 	time_t t;
1296 	time_t current_time;
1297 	int duration_error = FALSE;
1298 
1299 	/* find the service */
1300 	temp_service = find_service(host_name, service_desc);
1301 
1302 	/* make sure the user has rights to view service information */
1303 	if(is_authorized_for_service(temp_service, &current_authdata) == FALSE) {
1304 
1305 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this service...</DIV></P>\n");
1306 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1307 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1308 
1309 		return;
1310 		}
1311 
1312 	/* get service status info */
1313 	temp_svcstatus = find_servicestatus(host_name, service_desc);
1314 
1315 	/* make sure service information exists */
1316 	if(temp_service == NULL) {
1317 		printf("<P><DIV CLASS='errorMessage'>Error: Service Not Found!</DIV></P>");
1318 		return;
1319 		}
1320 	if(temp_svcstatus == NULL) {
1321 		printf("<P><DIV CLASS='errorMessage'>Error: Service Status Not Found!</DIV></P>");
1322 		return;
1323 		}
1324 
1325 
1326 	printf("<DIV ALIGN=CENTER>\n");
1327 	printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%%>\n");
1328 	printf("<TR>\n");
1329 
1330 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1331 
1332 	printf("<DIV CLASS='dataTitle'>Service State Information</DIV>\n");
1333 
1334 	if(temp_svcstatus->has_been_checked == FALSE)
1335 		printf("<P><DIV ALIGN=CENTER>This service has not yet been checked, so status information is not available.</DIV></P>\n");
1336 
1337 	else {
1338 
1339 		printf("<TABLE BORDER=0>\n");
1340 
1341 		printf("<TR><TD>\n");
1342 
1343 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1344 		printf("<TR><TD class='stateInfoTable1'>\n");
1345 		printf("<TABLE BORDER=0>\n");
1346 
1347 
1348 		current_time = time(NULL);
1349 		t = 0;
1350 		duration_error = FALSE;
1351 		if(temp_svcstatus->last_state_change == (time_t)0) {
1352 			if(program_start > current_time)
1353 				duration_error = TRUE;
1354 			else
1355 				t = current_time - program_start;
1356 			}
1357 		else {
1358 			if(temp_svcstatus->last_state_change > current_time)
1359 				duration_error = TRUE;
1360 			else
1361 				t = current_time - temp_svcstatus->last_state_change;
1362 			}
1363 		get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1364 		if(duration_error == TRUE)
1365 			snprintf(state_duration, sizeof(state_duration) - 1, "???");
1366 		else
1367 			snprintf(state_duration, sizeof(state_duration) - 1, "%2dd %2dh %2dm %2ds%s", days, hours, minutes, seconds, (temp_svcstatus->last_state_change == (time_t)0) ? "+" : "");
1368 		state_duration[sizeof(state_duration) - 1] = '\x0';
1369 
1370 		if(temp_svcstatus->status == SERVICE_OK) {
1371 			strcpy(state_string, "OK");
1372 			bg_class = "serviceOK";
1373 			}
1374 		else if(temp_svcstatus->status == SERVICE_WARNING) {
1375 			strcpy(state_string, "WARNING");
1376 			bg_class = "serviceWARNING";
1377 			}
1378 		else if(temp_svcstatus->status == SERVICE_CRITICAL) {
1379 			strcpy(state_string, "CRITICAL");
1380 			bg_class = "serviceCRITICAL";
1381 			}
1382 		else {
1383 			strcpy(state_string, "UNKNOWN");
1384 			bg_class = "serviceUNKNOWN";
1385 			}
1386 		printf("<TR><TD CLASS='dataVar'>Current Status:</TD><TD CLASS='dataVal'><DIV CLASS='%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV>&nbsp;(for %s)%s</TD></TR>\n", bg_class, state_string, state_duration, (temp_svcstatus->problem_has_been_acknowledged == TRUE) ? "&nbsp;&nbsp;(Has been acknowledged)" : "");
1387 
1388 		printf("<TR><TD CLASS='dataVar' VALIGN='top'>Status Information:</TD><TD CLASS='dataVal'>%s", (temp_svcstatus->plugin_output == NULL) ? "" : html_encode(temp_svcstatus->plugin_output, TRUE));
1389 		if(enable_splunk_integration == TRUE) {
1390 			printf("&nbsp;&nbsp;");
1391 			asprintf(&buf, "%s %s %s", temp_service->host_name, temp_service->description, temp_svcstatus->plugin_output);
1392 			display_splunk_generic_url(buf, 1);
1393 			free(buf);
1394 			}
1395 		if(temp_svcstatus->long_plugin_output != NULL)
1396 			printf("<BR>%s", html_encode(temp_svcstatus->long_plugin_output, TRUE));
1397 		printf("</TD></TR>\n");
1398 
1399 		printf("<TR><TD CLASS='dataVar' VALIGN='top'>Performance Data:</td><td CLASS='dataVal'>%s</td></tr>\n", (temp_svcstatus->perf_data == NULL) ? "" : html_encode(temp_svcstatus->perf_data, TRUE));
1400 
1401 		printf("<TR><TD CLASS='dataVar'>Current Attempt:</TD><TD CLASS='dataVal'>%d/%d", temp_svcstatus->current_attempt, temp_svcstatus->max_attempts);
1402 		printf("&nbsp;&nbsp;(%s state)</TD></TR>\n", (temp_svcstatus->state_type == HARD_STATE) ? "HARD" : "SOFT");
1403 
1404 		get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1405 		printf("<TR><TD CLASS='dataVar'>Last Check Time:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", date_time);
1406 
1407 		printf("<TR><TD CLASS='dataVar'>Check Type:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->check_type == SERVICE_CHECK_ACTIVE) ? "ACTIVE" : "PASSIVE");
1408 
1409 		printf("<TR><TD CLASS='dataVar' NOWRAP>Check Latency / Duration:</TD><TD CLASS='dataVal'>");
1410 		if(temp_svcstatus->check_type == SERVICE_CHECK_ACTIVE)
1411 			printf("%.3f", temp_svcstatus->latency);
1412 		else
1413 			printf("N/A");
1414 		printf("&nbsp;/&nbsp;%.3f seconds", temp_svcstatus->execution_time);
1415 		printf("</TD></TR>\n");
1416 
1417 		get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1418 		printf("<TR><TD CLASS='dataVar'>Next Scheduled Check:&nbsp;&nbsp;</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->checks_enabled && temp_svcstatus->next_check != (time_t)0 && temp_svcstatus->should_be_scheduled == TRUE) ? date_time : "N/A");
1419 
1420 		get_time_string(&temp_svcstatus->last_state_change, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1421 		printf("<TR><TD CLASS='dataVar'>Last State Change:</TD><TD CLASS='dataVal'>%s</TD></TR>\n", (temp_svcstatus->last_state_change == (time_t)0) ? "N/A" : date_time);
1422 
1423 		get_time_string(&temp_svcstatus->last_notification, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1424 		printf("<TR><TD CLASS='dataVar'>Last Notification:</TD><TD CLASS='dataVal'>%s&nbsp;(notification %d)</TD></TR>\n", (temp_svcstatus->last_notification == (time_t)0) ? "N/A" : date_time, temp_svcstatus->current_notification_number);
1425 
1426 		printf("<TR><TD CLASS='dataVar'>Is This Service Flapping?</TD><TD CLASS='dataVal'>");
1427 		if(temp_svcstatus->flap_detection_enabled == FALSE || enable_flap_detection == FALSE)
1428 			printf("N/A");
1429 		else
1430 			printf("<DIV CLASS='%sflapping'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV>&nbsp;(%3.2f%% state change)", (temp_svcstatus->is_flapping == TRUE) ? "" : "not", (temp_svcstatus->is_flapping == TRUE) ? "YES" : "NO", temp_svcstatus->percent_state_change);
1431 		printf("</TD></TR>\n");
1432 
1433 		printf("<TR><TD CLASS='dataVar'>In Scheduled Downtime?</TD><TD CLASS='dataVal'><DIV CLASS='downtime%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->scheduled_downtime_depth > 0) ? "ACTIVE" : "INACTIVE", (temp_svcstatus->scheduled_downtime_depth > 0) ? "YES" : "NO");
1434 
1435 		t = 0;
1436 		duration_error = FALSE;
1437 		if(temp_svcstatus->last_check > current_time)
1438 			duration_error = TRUE;
1439 		else
1440 			/*t=current_time-temp_svcstatus->last_check;*/
1441 			t = current_time - temp_svcstatus->last_update;
1442 		get_time_breakdown((unsigned long)t, &days, &hours, &minutes, &seconds);
1443 		if(duration_error == TRUE)
1444 			snprintf(status_age, sizeof(status_age) - 1, "???");
1445 		else if(temp_svcstatus->last_check == (time_t)0)
1446 			snprintf(status_age, sizeof(status_age) - 1, "N/A");
1447 		else
1448 			snprintf(status_age, sizeof(status_age) - 1, "%2dd %2dh %2dm %2ds", days, hours, minutes, seconds);
1449 		status_age[sizeof(status_age) - 1] = '\x0';
1450 
1451 		get_time_string(&temp_svcstatus->last_update, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1452 		printf("<TR><TD CLASS='dataVar'>Last Update:</TD><TD CLASS='dataVal'>%s&nbsp;&nbsp;(%s ago)</TD></TR>\n", (temp_svcstatus->last_update == (time_t)0) ? "N/A" : date_time, status_age);
1453 
1454 
1455 		printf("</TABLE>\n");
1456 		printf("</TD></TR>\n");
1457 		printf("</TABLE>\n");
1458 
1459 		printf("</TD></TR>\n");
1460 
1461 		printf("<TR><TD>\n");
1462 
1463 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
1464 		printf("<TR><TD class='stateInfoTable2'>\n");
1465 		printf("<TABLE BORDER=0>\n");
1466 
1467 		printf("<TR><TD CLASS='dataVar'>Active Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled) ? "ENABLED" : "DISABLED");
1468 
1469 		printf("<TR><TD CLASS='dataVar'>Passive Checks:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->accept_passive_service_checks == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->accept_passive_service_checks) ? "ENABLED" : "DISABLED");
1470 
1471 		printf("<TR><TD CLASS='dataVar'>Obsessing:</TD><td CLASS='dataVal'><DIV CLASS='checks%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->obsess_over_service == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->obsess_over_service) ? "ENABLED" : "DISABLED");
1472 
1473 		printf("<TR><td CLASS='dataVar'>Notifications:</TD><td CLASS='dataVal'><DIV CLASS='notifications%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->notifications_enabled) ? "ENABLED" : "DISABLED");
1474 
1475 		printf("<TR><TD CLASS='dataVar'>Event Handler:</TD><td CLASS='dataVal'><DIV CLASS='eventhandlers%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED", (temp_svcstatus->event_handler_enabled) ? "ENABLED" : "DISABLED");
1476 
1477 		printf("<TR><TD CLASS='dataVar'>Flap Detection:</TD><td CLASS='dataVal'><DIV CLASS='flapdetection%s'>&nbsp;&nbsp;%s&nbsp;&nbsp;</DIV></TD></TR>\n", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->flap_detection_enabled == TRUE) ? "ENABLED" : "DISABLED");
1478 
1479 
1480 		printf("</TABLE>\n");
1481 		printf("</TD></TR>\n");
1482 		printf("</TABLE>\n");
1483 
1484 		printf("</TD></TR>\n");
1485 
1486 		printf("</TABLE>\n");
1487 		}
1488 
1489 
1490 	printf("</TD>\n");
1491 
1492 	printf("<TD ALIGN=CENTER VALIGN=TOP>\n");
1493 	printf("<TABLE BORDER='0' CELLPADDING=0 CELLSPACING=0><TR>\n");
1494 
1495 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='commandPanel'>\n");
1496 
1497 	printf("<DIV CLASS='dataTitle'>Service Commands</DIV>\n");
1498 
1499 	printf("<TABLE BORDER='1' CELLSPACING=0 CELLPADDING=0>\n");
1500 	printf("<TR><TD>\n");
1501 
1502 	if(nagios_process_state == STATE_OK &&  is_authorized_for_read_only(&current_authdata) == FALSE) {
1503 		printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1504 
1505 		if(temp_svcstatus->checks_enabled) {
1506 
1507 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of This Service' TITLE='Disable Active Checks Of This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_CHECK, url_encode(host_name));
1508 			printf("&service=%s'>Disable active checks of this service</a></td></tr>\n", url_encode(service_desc));
1509 			}
1510 		else {
1511 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of This Service' TITLE='Enable Active Checks Of This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_CHECK, url_encode(host_name));
1512 			printf("&service=%s'>Enable active checks of this service</a></td></tr>\n", url_encode(service_desc));
1513 			}
1514 		printf("<tr CLASS='data'><td><img src='%s%s' border=0 ALT='Re-schedule Next Service Check' TITLE='Re-schedule Next Service Check'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(host_name));
1515 		printf("&service=%s%s'>Re-schedule the next check of this service</a></td></tr>\n", url_encode(service_desc), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "");
1516 
1517 		if(temp_svcstatus->accept_passive_service_checks == TRUE) {
1518 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Submit Passive Check Result For This Service' TITLE='Submit Passive Check Result For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, PASSIVE_ICON, COMMAND_CGI, CMD_PROCESS_SERVICE_CHECK_RESULT, url_encode(host_name));
1519 			printf("&service=%s'>Submit passive check result for this service</a></td></tr>\n", url_encode(service_desc));
1520 
1521 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Accepting Passive Checks For This Service' TITLE='Stop Accepting Passive Checks For This Service'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_PASSIVE_SVC_CHECKS, url_encode(host_name));
1522 			printf("&service=%s'>Stop accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc));
1523 			}
1524 		else {
1525 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Accepting Passive Checks For This Service' TITLE='Start Accepting Passive Checks For This Service'></td><td CLASS='command' NOWRAP><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_PASSIVE_SVC_CHECKS, url_encode(host_name));
1526 			printf("&service=%s'>Start accepting passive checks for this service</a></td></tr>\n", url_encode(service_desc));
1527 			}
1528 
1529 		if(temp_svcstatus->obsess_over_service == TRUE) {
1530 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Stop Obsessing Over This Service' TITLE='Stop Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_STOP_OBSESSING_OVER_SVC, url_encode(host_name));
1531 			printf("&service=%s'>Stop obsessing over this service</a></td></tr>\n", url_encode(service_desc));
1532 			}
1533 		else {
1534 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Start Obsessing Over This Service' TITLE='Start Obsessing Over This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_START_OBSESSING_OVER_SVC, url_encode(host_name));
1535 			printf("&service=%s'>Start obsessing over this service</a></td></tr>\n", url_encode(service_desc));
1536 			}
1537 
1538 		if((temp_svcstatus->status == SERVICE_WARNING || temp_svcstatus->status == SERVICE_UNKNOWN || temp_svcstatus->status == SERVICE_CRITICAL) && temp_svcstatus->state_type == HARD_STATE) {
1539 			if(temp_svcstatus->problem_has_been_acknowledged == FALSE) {
1540 				printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Acknowledge This Service Problem' TITLE='Acknowledge This Service Problem'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_ACKNOWLEDGE_SVC_PROBLEM, url_encode(host_name));
1541 				printf("&service=%s'>Acknowledge this service problem</a></td></tr>\n", url_encode(service_desc));
1542 				}
1543 			else {
1544 				printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Remove Problem Acknowledgement' TITLE='Remove Problem Acknowledgement'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, REMOVE_ACKNOWLEDGEMENT_ICON, COMMAND_CGI, CMD_REMOVE_SVC_ACKNOWLEDGEMENT, url_encode(host_name));
1545 				printf("&service=%s'>Remove problem acknowledgement</a></td></tr>\n", url_encode(service_desc));
1546 				}
1547 			}
1548 		if(temp_svcstatus->notifications_enabled == TRUE) {
1549 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For This Service' TITLE='Disable Notifications For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_NOTIFICATIONS, url_encode(host_name));
1550 			printf("&service=%s'>Disable notifications for this service</a></td></tr>\n", url_encode(service_desc));
1551 			if(temp_svcstatus->status != SERVICE_OK) {
1552 				printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Delay Next Service Notification' TITLE='Delay Next Service Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DELAY_ICON, COMMAND_CGI, CMD_DELAY_SVC_NOTIFICATION, url_encode(host_name));
1553 				printf("&service=%s'>Delay next service notification</a></td></tr>\n", url_encode(service_desc));
1554 				}
1555 			}
1556 		else {
1557 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For This Service' TITLE='Enable Notifications For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_NOTIFICATIONS, url_encode(host_name));
1558 			printf("&service=%s'>Enable notifications for this service</a></td></tr>\n", url_encode(service_desc));
1559 			}
1560 
1561 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Send Custom Notification' TITLE='Send Custom Notification'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_SEND_CUSTOM_SVC_NOTIFICATION, url_encode(host_name));
1562 		printf("&service=%s'>Send custom service notification</a></td></tr>\n", url_encode(service_desc));
1563 
1564 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For This Service' TITLE='Schedule Downtime For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SVC_DOWNTIME, url_encode(host_name));
1565 		printf("&service=%s'>Schedule downtime for this service</a></td></tr>\n", url_encode(service_desc));
1566 
1567 		/*
1568 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Cancel Scheduled Downtime For This Service' TITLE='Cancel Scheduled Downtime For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s",url_images_path,SCHEDULED_DOWNTIME_ICON,COMMAND_CGI,CMD_CANCEL_SVC_DOWNTIME,url_encode(host_name));
1569 		printf("&service=%s'>Cancel scheduled downtime for this service</a></td></tr>\n",url_encode(service_desc));
1570 		*/
1571 
1572 		if(temp_svcstatus->event_handler_enabled == TRUE) {
1573 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Event Handler For This Service' TITLE='Disable Event Handler For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_EVENT_HANDLER, url_encode(host_name));
1574 			printf("&service=%s'>Disable event handler for this service</a></td></tr>\n", url_encode(service_desc));
1575 			}
1576 		else {
1577 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Event Handler For This Service' TITLE='Enable Event Handler For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_EVENT_HANDLER, url_encode(host_name));
1578 			printf("&service=%s'>Enable event handler for this service</a></td></tr>\n", url_encode(service_desc));
1579 			}
1580 
1581 		if(temp_svcstatus->flap_detection_enabled == TRUE) {
1582 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Flap Detection For This Service' TITLE='Disable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SVC_FLAP_DETECTION, url_encode(host_name));
1583 			printf("&service=%s'>Disable flap detection for this service</a></td></tr>\n", url_encode(service_desc));
1584 			}
1585 		else {
1586 			printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Flap Detection For This Service' TITLE='Enable Flap Detection For This Service'></td><td CLASS='command'><a href='%s?cmd_typ=%d&host=%s", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SVC_FLAP_DETECTION, url_encode(host_name));
1587 			printf("&service=%s'>Enable flap detection for this service</a></td></tr>\n", url_encode(service_desc));
1588 			}
1589 
1590 		printf("</table>\n");
1591 		}
1592 	else if(is_authorized_for_read_only(&current_authdata) == TRUE) {
1593 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1594 		}
1595 	else {
1596 		printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1597 		printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1598 		}
1599 
1600 	printf("</td></tr>\n");
1601 	printf("</table>\n");
1602 
1603 	printf("</TD>\n");
1604 
1605 	printf("</TR></TABLE></TD>\n");
1606 	printf("</TR>\n");
1607 
1608 	printf("<TR><TD COLSPAN=2><BR></TD></TR>\n");
1609 
1610 	printf("<TR>\n");
1611 	printf("<TD COLSPAN=2 ALIGN=CENTER VALIGN=TOP CLASS='commentPanel'>\n");
1612 
1613 	if(is_authorized_for_read_only(&current_authdata) == FALSE) {
1614 		/* display comments */
1615 		display_comments(SERVICE_COMMENT);
1616 		}
1617 	printf("</TD>\n");
1618 	printf("</TR>\n");
1619 
1620 	printf("</TABLE>\n");
1621 	printf("</DIV>\n");
1622 
1623 	return;
1624 	}
1625 
1626 
1627 
1628 
show_hostgroup_info(void)1629 void show_hostgroup_info(void) {
1630 	hostgroup *temp_hostgroup;
1631 
1632 
1633 	/* get hostgroup info */
1634 	temp_hostgroup = find_hostgroup(hostgroup_name);
1635 
1636 	/* make sure the user has rights to view hostgroup information */
1637 	if(is_authorized_for_hostgroup(temp_hostgroup, &current_authdata) == FALSE) {
1638 
1639 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this hostgroup...</DIV></P>\n");
1640 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1641 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1642 
1643 		return;
1644 		}
1645 
1646 	/* make sure hostgroup information exists */
1647 	if(temp_hostgroup == NULL) {
1648 		printf("<P><DIV CLASS='errorMessage'>Error: Hostgroup Not Found!</DIV></P>");
1649 		return;
1650 		}
1651 
1652 
1653 	printf("<DIV ALIGN=CENTER>\n");
1654 	printf("<TABLE BORDER=0 WIDTH=100%%>\n");
1655 	printf("<TR>\n");
1656 
1657 
1658 	/* top left panel */
1659 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1660 
1661 	/* right top panel */
1662 	printf("</TD><TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel' ROWSPAN=2>\n");
1663 
1664 	printf("<DIV CLASS='dataTitle'>Hostgroup Commands</DIV>\n");
1665 
1666 	if(nagios_process_state == STATE_OK && is_authorized_for_read_only(&current_authdata) == FALSE) {
1667 
1668 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1669 		printf("<TR><TD>\n");
1670 
1671 		printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1672 
1673 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Hosts In This Hostgroup' TITLE='Schedule Downtime For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Schedule downtime for all hosts in this hostgroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_HOST_DOWNTIME, url_encode(hostgroup_name));
1674 
1675 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services In This Hostgroup' TITLE='Schedule Downtime For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Schedule downtime for all services in this hostgroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_HOSTGROUP_SVC_DOWNTIME, url_encode(hostgroup_name));
1676 
1677 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Hosts In This Hostgroup' TITLE='Enable Notifications For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable notifications for all hosts in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name));
1678 
1679 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Hosts In This Hostgroup' TITLE='Disable Notifications For All Hosts In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable notifications for all hosts in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS, url_encode(hostgroup_name));
1680 
1681 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services In This Hostgroup' TITLE='Enable Notifications For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable notifications for all services in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name));
1682 
1683 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services In This Hostgroup' TITLE='Disable Notifications For All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable notifications for all services in this hostgroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS, url_encode(hostgroup_name));
1684 
1685 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of All Services In This Hostgroup' TITLE='Enable Active Checks Of All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Enable active checks of all services in this hostgroup</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name));
1686 
1687 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of All Services In This Hostgroup' TITLE='Disable Active Checks Of All Services In This Hostgroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&hostgroup=%s'>Disable active checks of all services in this hostgroup</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_HOSTGROUP_SVC_CHECKS, url_encode(hostgroup_name));
1688 
1689 		printf("</table>\n");
1690 
1691 		printf("</TD></TR>\n");
1692 		printf("</TABLE>\n");
1693 		}
1694 	else if(is_authorized_for_read_only(&current_authdata) == TRUE) {
1695 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to execute commands.<br>\n");
1696 		}
1697 	else {
1698 		printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1699 		printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1700 		}
1701 
1702 	printf("</TD></TR>\n");
1703 	printf("<TR>\n");
1704 
1705 	/* left bottom panel */
1706 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1707 
1708 	printf("</TD></TR>\n");
1709 	printf("</TABLE>\n");
1710 	printf("</DIV>\n");
1711 
1712 
1713 	printf("</div>\n");
1714 
1715 	printf("</TD>\n");
1716 
1717 
1718 
1719 	return;
1720 	}
1721 
1722 
1723 
1724 
show_servicegroup_info()1725 void show_servicegroup_info() {
1726 	servicegroup *temp_servicegroup;
1727 
1728 
1729 	/* get servicegroup info */
1730 	temp_servicegroup = find_servicegroup(servicegroup_name);
1731 
1732 	/* make sure the user has rights to view servicegroup information */
1733 	if(is_authorized_for_servicegroup(temp_servicegroup, &current_authdata) == FALSE) {
1734 
1735 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view information for this servicegroup...</DIV></P>\n");
1736 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
1737 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
1738 
1739 		return;
1740 		}
1741 
1742 	/* make sure servicegroup information exists */
1743 	if(temp_servicegroup == NULL) {
1744 		printf("<P><DIV CLASS='errorMessage'>Error: Servicegroup Not Found!</DIV></P>");
1745 		return;
1746 		}
1747 
1748 
1749 	printf("<DIV ALIGN=CENTER>\n");
1750 	printf("<TABLE BORDER=0 WIDTH=100%%>\n");
1751 	printf("<TR>\n");
1752 
1753 
1754 	/* top left panel */
1755 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1756 
1757 	/* right top panel */
1758 	printf("</TD><TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel' ROWSPAN=2>\n");
1759 
1760 	printf("<DIV CLASS='dataTitle'>Servicegroup Commands</DIV>\n");
1761 
1762 	if(nagios_process_state == STATE_OK) {
1763 
1764 		printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1765 		printf("<TR><TD>\n");
1766 
1767 		printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS='command'>\n");
1768 
1769 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Hosts In This Servicegroup' TITLE='Schedule Downtime For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Schedule downtime for all hosts in this servicegroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_HOST_DOWNTIME, url_encode(servicegroup_name));
1770 
1771 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Schedule Downtime For All Services In This Servicegroup' TITLE='Schedule Downtime For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Schedule downtime for all services in this servicegroup</a></td></tr>\n", url_images_path, DOWNTIME_ICON, COMMAND_CGI, CMD_SCHEDULE_SERVICEGROUP_SVC_DOWNTIME, url_encode(servicegroup_name));
1772 
1773 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Hosts In This Servicegroup' TITLE='Enable Notifications For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable notifications for all hosts in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name));
1774 
1775 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Hosts In This Servicegroup' TITLE='Disable Notifications For All Hosts In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable notifications for all hosts in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_HOST_NOTIFICATIONS, url_encode(servicegroup_name));
1776 
1777 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Notifications For All Services In This Servicegroup' TITLE='Enable Notifications For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable notifications for all services in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATION_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name));
1778 
1779 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Notifications For All Services In This Servicegroup' TITLE='Disable Notifications For All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable notifications for all services in this servicegroup</a></td></tr>\n", url_images_path, NOTIFICATIONS_DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_NOTIFICATIONS, url_encode(servicegroup_name));
1780 
1781 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Enable Active Checks Of All Services In This Servicegroup' TITLE='Enable Active Checks Of All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Enable active checks of all services in this servicegroup</a></td></tr>\n", url_images_path, ENABLED_ICON, COMMAND_CGI, CMD_ENABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name));
1782 
1783 		printf("<tr CLASS='command'><td><img src='%s%s' border=0 ALT='Disable Active Checks Of All Services In This Servicegroup' TITLE='Disable Active Checks Of All Services In This Servicegroup'></td><td CLASS='command'><a href='%s?cmd_typ=%d&servicegroup=%s'>Disable active checks of all services in this servicegroup</a></td></tr>\n", url_images_path, DISABLED_ICON, COMMAND_CGI, CMD_DISABLE_SERVICEGROUP_SVC_CHECKS, url_encode(servicegroup_name));
1784 
1785 		printf("</table>\n");
1786 
1787 		printf("</TD></TR>\n");
1788 		printf("</TABLE>\n");
1789 		}
1790 	else {
1791 		printf("<DIV CLASS='infoMessage'>It appears as though Nagios is not running, so commands are temporarily unavailable...<br>\n");
1792 		printf("Click <a href='%s?type=%d'>here</a> to view Nagios process information</DIV>\n", EXTINFO_CGI, DISPLAY_PROCESS_INFO);
1793 		}
1794 
1795 	printf("</TD></TR>\n");
1796 	printf("<TR>\n");
1797 
1798 	/* left bottom panel */
1799 	printf("<TD ALIGN=CENTER VALIGN=TOP CLASS='stateInfoPanel'>\n");
1800 
1801 	printf("</TD></TR>\n");
1802 	printf("</TABLE>\n");
1803 	printf("</DIV>\n");
1804 
1805 
1806 	printf("</div>\n");
1807 
1808 	printf("</TD>\n");
1809 
1810 
1811 	return;
1812 	}
1813 
1814 
1815 
1816 /* shows all service and host comments */
show_all_comments(void)1817 void show_all_comments(void) {
1818 	int total_comments = 0;
1819 	char *bg_class = "";
1820 	int odd = 0;
1821 	char date_time[MAX_DATETIME_LENGTH];
1822 	comment *temp_comment;
1823 	host *temp_host;
1824 	service *temp_service;
1825 	char *comment_type;
1826 	char expire_time[MAX_DATETIME_LENGTH];
1827 
1828 
1829 	if(is_authorized_for_read_only(&current_authdata) == TRUE) {
1830 		printf("<DIV ALIGN=CENTER CLASS='infoMessage'>Your account does not have permissions to view comments.<br>\n");
1831 		return;
1832 		}
1833 
1834 
1835 	printf("<BR />\n");
1836 	printf("<DIV CLASS='commentNav'>[&nbsp;<A HREF='#HOSTCOMMENTS' CLASS='commentNav'>Host Comments</A>&nbsp;|&nbsp;<A HREF='#SERVICECOMMENTS' CLASS='commentNav'>Service Comments</A>&nbsp;]</DIV>\n");
1837 	printf("<BR />\n");
1838 
1839 	printf("<A NAME=HOSTCOMMENTS></A>\n");
1840 	printf("<DIV CLASS='commentTitle'>Host Comments</DIV>\n");
1841 
1842 	printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON);
1843 	printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT);
1844 	printf("Add a new host comment</a></div>\n");
1845 
1846 	printf("<BR />\n");
1847 	printf("<DIV ALIGN=CENTER>\n");
1848 	printf("<TABLE BORDER=0 CLASS='comment'>\n");
1849 	printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
1850 
1851 	/* display all the host comments */
1852 	for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
1853 
1854 		if(temp_comment->comment_type != HOST_COMMENT)
1855 			continue;
1856 
1857 		temp_host = find_host(temp_comment->host_name);
1858 
1859 		/* make sure the user has rights to view host information */
1860 		if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
1861 			continue;
1862 
1863 		total_comments++;
1864 
1865 		if(odd) {
1866 			odd = 0;
1867 			bg_class = "commentOdd";
1868 			}
1869 		else {
1870 			odd = 1;
1871 			bg_class = "commentEven";
1872 			}
1873 
1874 		switch(temp_comment->entry_type) {
1875 			case USER_COMMENT:
1876 				comment_type = "User";
1877 				break;
1878 			case DOWNTIME_COMMENT:
1879 				comment_type = "Scheduled Downtime";
1880 				break;
1881 			case FLAPPING_COMMENT:
1882 				comment_type = "Flap Detection";
1883 				break;
1884 			case ACKNOWLEDGEMENT_COMMENT:
1885 				comment_type = "Acknowledgement";
1886 				break;
1887 			default:
1888 				comment_type = "?";
1889 			}
1890 
1891 		get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1892 		get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1893 		printf("<tr CLASS='%s'>", bg_class);
1894 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name);
1895 		printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
1896 		printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_HOST_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
1897 		printf("</tr>\n");
1898 		}
1899 
1900 	if(total_comments == 0)
1901 		printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN=9>There are no host comments</TD></TR>");
1902 
1903 	printf("</TABLE>\n");
1904 	printf("</DIV>\n");
1905 
1906 	printf("<BR /><BR /><BR />\n");
1907 
1908 
1909 	printf("<A NAME=SERVICECOMMENTS></A>\n");
1910 	printf("<DIV CLASS='commentTitle'>Service Comments</DIV>\n");
1911 
1912 	printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, COMMENT_ICON);
1913 	printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_ADD_SVC_COMMENT);
1914 	printf("Add a new service comment</a></div>\n");
1915 
1916 	printf("<BR />\n");
1917 	printf("<DIV ALIGN=CENTER>\n");
1918 	printf("<TABLE BORDER=0 CLASS='comment'>\n");
1919 	printf("<TR CLASS='comment'><TH CLASS='comment'>Host Name</TH><TH CLASS='comment'>Service</TH><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
1920 
1921 	/* display all the service comments */
1922 	for(temp_comment = comment_list, total_comments = 0; temp_comment != NULL; temp_comment = temp_comment->next) {
1923 
1924 		if(temp_comment->comment_type != SERVICE_COMMENT)
1925 			continue;
1926 
1927 		temp_service = find_service(temp_comment->host_name, temp_comment->service_description);
1928 
1929 		/* make sure the user has rights to view service information */
1930 		if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
1931 			continue;
1932 
1933 		total_comments++;
1934 
1935 		if(odd) {
1936 			odd = 0;
1937 			bg_class = "commentOdd";
1938 			}
1939 		else {
1940 			odd = 1;
1941 			bg_class = "commentEven";
1942 			}
1943 
1944 		switch(temp_comment->entry_type) {
1945 			case USER_COMMENT:
1946 				comment_type = "User";
1947 				break;
1948 			case DOWNTIME_COMMENT:
1949 				comment_type = "Scheduled Downtime";
1950 				break;
1951 			case FLAPPING_COMMENT:
1952 				comment_type = "Flap Detection";
1953 				break;
1954 			case ACKNOWLEDGEMENT_COMMENT:
1955 				comment_type = "Acknowledgement";
1956 				break;
1957 			default:
1958 				comment_type = "?";
1959 			}
1960 
1961 		get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1962 		get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
1963 		printf("<tr CLASS='%s'>", bg_class);
1964 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_comment->host_name), temp_comment->host_name);
1965 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_comment->host_name));
1966 		printf("&service=%s'>%s</A></td>", url_encode(temp_comment->service_description), temp_comment->service_description);
1967 		printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%ld</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
1968 		printf("<td><a href='%s?cmd_typ=%d&com_id=%ld'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
1969 		printf("</tr>\n");
1970 		}
1971 
1972 	if(total_comments == 0)
1973 		printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN=10>There are no service comments</TD></TR>");
1974 
1975 	printf("</TABLE>\n");
1976 	printf("</DIV>\n");
1977 
1978 	return;
1979 	}
1980 
1981 
1982 
show_performance_data(void)1983 void show_performance_data(void) {
1984 	service *temp_service = NULL;
1985 	servicestatus *temp_servicestatus = NULL;
1986 	host *temp_host = NULL;
1987 	hoststatus *temp_hoststatus = NULL;
1988 	int total_active_service_checks = 0;
1989 	int total_passive_service_checks = 0;
1990 	double min_service_execution_time = 0.0;
1991 	double max_service_execution_time = 0.0;
1992 	double total_service_execution_time = 0.0;
1993 	int have_min_service_execution_time = FALSE;
1994 	int have_max_service_execution_time = FALSE;
1995 	double min_service_latency = 0.0;
1996 	double max_service_latency = 0.0;
1997 	double long total_service_latency = 0.0;
1998 	int have_min_service_latency = FALSE;
1999 	int have_max_service_latency = FALSE;
2000 	double min_host_latency = 0.0;
2001 	double max_host_latency = 0.0;
2002 	double total_host_latency = 0.0;
2003 	int have_min_host_latency = FALSE;
2004 	int have_max_host_latency = FALSE;
2005 	double min_service_percent_change_a = 0.0;
2006 	double max_service_percent_change_a = 0.0;
2007 	double total_service_percent_change_a = 0.0;
2008 	int have_min_service_percent_change_a = FALSE;
2009 	int have_max_service_percent_change_a = FALSE;
2010 	double min_service_percent_change_b = 0.0;
2011 	double max_service_percent_change_b = 0.0;
2012 	double total_service_percent_change_b = 0.0;
2013 	int have_min_service_percent_change_b = FALSE;
2014 	int have_max_service_percent_change_b = FALSE;
2015 	int active_service_checks_1min = 0;
2016 	int active_service_checks_5min = 0;
2017 	int active_service_checks_15min = 0;
2018 	int active_service_checks_1hour = 0;
2019 	int active_service_checks_start = 0;
2020 	int active_service_checks_ever = 0;
2021 	int passive_service_checks_1min = 0;
2022 	int passive_service_checks_5min = 0;
2023 	int passive_service_checks_15min = 0;
2024 	int passive_service_checks_1hour = 0;
2025 	int passive_service_checks_start = 0;
2026 	int passive_service_checks_ever = 0;
2027 	int total_active_host_checks = 0;
2028 	int total_passive_host_checks = 0;
2029 	double min_host_execution_time = 0.0;
2030 	double max_host_execution_time = 0.0;
2031 	double total_host_execution_time = 0.0;
2032 	int have_min_host_execution_time = FALSE;
2033 	int have_max_host_execution_time = FALSE;
2034 	double min_host_percent_change_a = 0.0;
2035 	double max_host_percent_change_a = 0.0;
2036 	double total_host_percent_change_a = 0.0;
2037 	int have_min_host_percent_change_a = FALSE;
2038 	int have_max_host_percent_change_a = FALSE;
2039 	double min_host_percent_change_b = 0.0;
2040 	double max_host_percent_change_b = 0.0;
2041 	double total_host_percent_change_b = 0.0;
2042 	int have_min_host_percent_change_b = FALSE;
2043 	int have_max_host_percent_change_b = FALSE;
2044 	int active_host_checks_1min = 0;
2045 	int active_host_checks_5min = 0;
2046 	int active_host_checks_15min = 0;
2047 	int active_host_checks_1hour = 0;
2048 	int active_host_checks_start = 0;
2049 	int active_host_checks_ever = 0;
2050 	int passive_host_checks_1min = 0;
2051 	int passive_host_checks_5min = 0;
2052 	int passive_host_checks_15min = 0;
2053 	int passive_host_checks_1hour = 0;
2054 	int passive_host_checks_start = 0;
2055 	int passive_host_checks_ever = 0;
2056 	time_t current_time;
2057 
2058 
2059 	time(&current_time);
2060 
2061 	/* check all services */
2062 	for(temp_servicestatus = servicestatus_list; temp_servicestatus != NULL; temp_servicestatus = temp_servicestatus->next) {
2063 
2064 		/* find the service */
2065 		temp_service = find_service(temp_servicestatus->host_name, temp_servicestatus->description);
2066 
2067 		/* make sure the user has rights to view service information */
2068 		if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
2069 			continue;
2070 
2071 		/* is this an active or passive check? */
2072 		if(temp_servicestatus->check_type == SERVICE_CHECK_ACTIVE) {
2073 
2074 			total_active_service_checks++;
2075 
2076 			total_service_execution_time += temp_servicestatus->execution_time;
2077 			if(have_min_service_execution_time == FALSE || temp_servicestatus->execution_time < min_service_execution_time) {
2078 				have_min_service_execution_time = TRUE;
2079 				min_service_execution_time = temp_servicestatus->execution_time;
2080 				}
2081 			if(have_max_service_execution_time == FALSE || temp_servicestatus->execution_time > max_service_execution_time) {
2082 				have_max_service_execution_time = TRUE;
2083 				max_service_execution_time = temp_servicestatus->execution_time;
2084 				}
2085 
2086 			total_service_percent_change_a += temp_servicestatus->percent_state_change;
2087 			if(have_min_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_a) {
2088 				have_min_service_percent_change_a = TRUE;
2089 				min_service_percent_change_a = temp_servicestatus->percent_state_change;
2090 				}
2091 			if(have_max_service_percent_change_a == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_a) {
2092 				have_max_service_percent_change_a = TRUE;
2093 				max_service_percent_change_a = temp_servicestatus->percent_state_change;
2094 				}
2095 
2096 			total_service_latency += temp_servicestatus->latency;
2097 			if(have_min_service_latency == FALSE || temp_servicestatus->latency < min_service_latency) {
2098 				have_min_service_latency = TRUE;
2099 				min_service_latency = temp_servicestatus->latency;
2100 				}
2101 			if(have_max_service_latency == FALSE || temp_servicestatus->latency > max_service_latency) {
2102 				have_max_service_latency = TRUE;
2103 				max_service_latency = temp_servicestatus->latency;
2104 				}
2105 
2106 			if(temp_servicestatus->last_check >= (current_time - 60))
2107 				active_service_checks_1min++;
2108 			if(temp_servicestatus->last_check >= (current_time - 300))
2109 				active_service_checks_5min++;
2110 			if(temp_servicestatus->last_check >= (current_time - 900))
2111 				active_service_checks_15min++;
2112 			if(temp_servicestatus->last_check >= (current_time - 3600))
2113 				active_service_checks_1hour++;
2114 			if(temp_servicestatus->last_check >= program_start)
2115 				active_service_checks_start++;
2116 			if(temp_servicestatus->last_check != (time_t)0)
2117 				active_service_checks_ever++;
2118 			}
2119 
2120 		else {
2121 			total_passive_service_checks++;
2122 
2123 			total_service_percent_change_b += temp_servicestatus->percent_state_change;
2124 			if(have_min_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change < min_service_percent_change_b) {
2125 				have_min_service_percent_change_b = TRUE;
2126 				min_service_percent_change_b = temp_servicestatus->percent_state_change;
2127 				}
2128 			if(have_max_service_percent_change_b == FALSE || temp_servicestatus->percent_state_change > max_service_percent_change_b) {
2129 				have_max_service_percent_change_b = TRUE;
2130 				max_service_percent_change_b = temp_servicestatus->percent_state_change;
2131 				}
2132 
2133 			if(temp_servicestatus->last_check >= (current_time - 60))
2134 				passive_service_checks_1min++;
2135 			if(temp_servicestatus->last_check >= (current_time - 300))
2136 				passive_service_checks_5min++;
2137 			if(temp_servicestatus->last_check >= (current_time - 900))
2138 				passive_service_checks_15min++;
2139 			if(temp_servicestatus->last_check >= (current_time - 3600))
2140 				passive_service_checks_1hour++;
2141 			if(temp_servicestatus->last_check >= program_start)
2142 				passive_service_checks_start++;
2143 			if(temp_servicestatus->last_check != (time_t)0)
2144 				passive_service_checks_ever++;
2145 			}
2146 		}
2147 
2148 	/* check all hosts */
2149 	for(temp_hoststatus = hoststatus_list; temp_hoststatus != NULL; temp_hoststatus = temp_hoststatus->next) {
2150 
2151 		/* find the host */
2152 		temp_host = find_host(temp_hoststatus->host_name);
2153 
2154 		/* make sure the user has rights to view host information */
2155 		if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
2156 			continue;
2157 
2158 		/* is this an active or passive check? */
2159 		if(temp_hoststatus->check_type == HOST_CHECK_ACTIVE) {
2160 
2161 			total_active_host_checks++;
2162 
2163 			total_host_execution_time += temp_hoststatus->execution_time;
2164 			if(have_min_host_execution_time == FALSE || temp_hoststatus->execution_time < min_host_execution_time) {
2165 				have_min_host_execution_time = TRUE;
2166 				min_host_execution_time = temp_hoststatus->execution_time;
2167 				}
2168 			if(have_max_host_execution_time == FALSE || temp_hoststatus->execution_time > max_host_execution_time) {
2169 				have_max_host_execution_time = TRUE;
2170 				max_host_execution_time = temp_hoststatus->execution_time;
2171 				}
2172 
2173 			total_host_percent_change_a += temp_hoststatus->percent_state_change;
2174 			if(have_min_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_a) {
2175 				have_min_host_percent_change_a = TRUE;
2176 				min_host_percent_change_a = temp_hoststatus->percent_state_change;
2177 				}
2178 			if(have_max_host_percent_change_a == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_a) {
2179 				have_max_host_percent_change_a = TRUE;
2180 				max_host_percent_change_a = temp_hoststatus->percent_state_change;
2181 				}
2182 
2183 			total_host_latency += temp_hoststatus->latency;
2184 			if(have_min_host_latency == FALSE || temp_hoststatus->latency < min_host_latency) {
2185 				have_min_host_latency = TRUE;
2186 				min_host_latency = temp_hoststatus->latency;
2187 				}
2188 			if(have_max_host_latency == FALSE || temp_hoststatus->latency > max_host_latency) {
2189 				have_max_host_latency = TRUE;
2190 				max_host_latency = temp_hoststatus->latency;
2191 				}
2192 
2193 			if(temp_hoststatus->last_check >= (current_time - 60))
2194 				active_host_checks_1min++;
2195 			if(temp_hoststatus->last_check >= (current_time - 300))
2196 				active_host_checks_5min++;
2197 			if(temp_hoststatus->last_check >= (current_time - 900))
2198 				active_host_checks_15min++;
2199 			if(temp_hoststatus->last_check >= (current_time - 3600))
2200 				active_host_checks_1hour++;
2201 			if(temp_hoststatus->last_check >= program_start)
2202 				active_host_checks_start++;
2203 			if(temp_hoststatus->last_check != (time_t)0)
2204 				active_host_checks_ever++;
2205 			}
2206 
2207 		else {
2208 			total_passive_host_checks++;
2209 
2210 			total_host_percent_change_b += temp_hoststatus->percent_state_change;
2211 			if(have_min_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change < min_host_percent_change_b) {
2212 				have_min_host_percent_change_b = TRUE;
2213 				min_host_percent_change_b = temp_hoststatus->percent_state_change;
2214 				}
2215 			if(have_max_host_percent_change_b == FALSE || temp_hoststatus->percent_state_change > max_host_percent_change_b) {
2216 				have_max_host_percent_change_b = TRUE;
2217 				max_host_percent_change_b = temp_hoststatus->percent_state_change;
2218 				}
2219 
2220 			if(temp_hoststatus->last_check >= (current_time - 60))
2221 				passive_host_checks_1min++;
2222 			if(temp_hoststatus->last_check >= (current_time - 300))
2223 				passive_host_checks_5min++;
2224 			if(temp_hoststatus->last_check >= (current_time - 900))
2225 				passive_host_checks_15min++;
2226 			if(temp_hoststatus->last_check >= (current_time - 3600))
2227 				passive_host_checks_1hour++;
2228 			if(temp_hoststatus->last_check >= program_start)
2229 				passive_host_checks_start++;
2230 			if(temp_hoststatus->last_check != (time_t)0)
2231 				passive_host_checks_ever++;
2232 			}
2233 		}
2234 
2235 
2236 	printf("<div align=center>\n");
2237 
2238 
2239 	printf("<DIV CLASS='dataTitle'>Program-Wide Performance Information</DIV>\n");
2240 
2241 	printf("<table border='0' cellpadding='10'>\n");
2242 
2243 
2244 	/***** ACTIVE SERVICE CHECKS *****/
2245 
2246 	printf("<tr>\n");
2247 	printf("<td valign=middle><div class='perfTypeTitle'>Services Actively Checked:</div></td>\n");
2248 	printf("<td valign=top>\n");
2249 
2250 	/* fake this so we don't divide by zero for just showing the table */
2251 	if(total_active_service_checks == 0)
2252 		total_active_service_checks = 1;
2253 
2254 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2255 	printf("<TR><TD class='stateInfoTable1'>\n");
2256 	printf("<TABLE BORDER=0>\n");
2257 
2258 	printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Services Checked</th></tr>\n");
2259 	printf("<tr><td class='dataVar'>&lt;= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_1min, (double)(((double)active_service_checks_1min * 100.0) / (double)total_active_service_checks));
2260 	printf("<tr><td class='dataVar'>&lt;= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_5min, (double)(((double)active_service_checks_5min * 100.0) / (double)total_active_service_checks));
2261 	printf("<tr><td class='dataVar'>&lt;= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_15min, (double)(((double)active_service_checks_15min * 100.0) / (double)total_active_service_checks));
2262 	printf("<tr><td class='dataVar'>&lt;= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_service_checks_1hour, (double)(((double)active_service_checks_1hour * 100.0) / (double)total_active_service_checks));
2263 	printf("<tr><td class='dataVar'>Since program start:&nbsp;&nbsp;</td><td class='dataVal'>%d (%.1f%%)</td>", active_service_checks_start, (double)(((double)active_service_checks_start * 100.0) / (double)total_active_service_checks));
2264 
2265 	printf("</TABLE>\n");
2266 	printf("</TD></TR>\n");
2267 	printf("</TABLE>\n");
2268 
2269 	printf("</td><td valign=top>\n");
2270 
2271 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2272 	printf("<TR><TD class='stateInfoTable2'>\n");
2273 	printf("<TABLE BORDER=0>\n");
2274 
2275 	printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2276 
2277 	printf("<tr><td class='dataVar'>Check Execution Time:&nbsp;&nbsp;</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_service_execution_time, max_service_execution_time, (double)((double)total_service_execution_time / (double)total_active_service_checks));
2278 
2279 	printf("<tr><td class='dataVar'>Check Latency:</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_service_latency, max_service_latency, (double)((double)total_service_latency / (double)total_active_service_checks));
2280 
2281 	printf("<tr><td class='dataVar'>Percent State Change:</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_service_percent_change_a, max_service_percent_change_a, (double)((double)total_service_percent_change_a / (double)total_active_service_checks));
2282 
2283 	printf("</TABLE>\n");
2284 	printf("</TD></TR>\n");
2285 	printf("</TABLE>\n");
2286 
2287 
2288 	printf("</td>\n");
2289 	printf("</tr>\n");
2290 
2291 
2292 	/***** PASSIVE SERVICE CHECKS *****/
2293 
2294 	printf("<tr>\n");
2295 	printf("<td valign=middle><div class='perfTypeTitle'>Services Passively Checked:</div></td>\n");
2296 	printf("<td valign=top>\n");
2297 
2298 
2299 	/* fake this so we don't divide by zero for just showing the table */
2300 	if(total_passive_service_checks == 0)
2301 		total_passive_service_checks = 1;
2302 
2303 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2304 	printf("<TR><TD class='stateInfoTable1'>\n");
2305 	printf("<TABLE BORDER=0>\n");
2306 
2307 	printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Services Checked</th></tr>\n");
2308 	printf("<tr><td class='dataVar'>&lt;= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_1min, (double)(((double)passive_service_checks_1min * 100.0) / (double)total_passive_service_checks));
2309 	printf("<tr><td class='dataVar'>&lt;= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_5min, (double)(((double)passive_service_checks_5min * 100.0) / (double)total_passive_service_checks));
2310 	printf("<tr><td class='dataVar'>&lt;= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_15min, (double)(((double)passive_service_checks_15min * 100.0) / (double)total_passive_service_checks));
2311 	printf("<tr><td class='dataVar'>&lt;= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_1hour, (double)(((double)passive_service_checks_1hour * 100.0) / (double)total_passive_service_checks));
2312 	printf("<tr><td class='dataVar'>Since program start:&nbsp;&nbsp;</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_service_checks_start, (double)(((double)passive_service_checks_start * 100.0) / (double)total_passive_service_checks));
2313 
2314 	printf("</TABLE>\n");
2315 	printf("</TD></TR>\n");
2316 	printf("</TABLE>\n");
2317 
2318 	printf("</td><td valign=top>\n");
2319 
2320 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2321 	printf("<TR><TD class='stateInfoTable2'>\n");
2322 	printf("<TABLE BORDER=0>\n");
2323 
2324 	printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2325 	printf("<tr><td class='dataVar'>Percent State Change:&nbsp;&nbsp;</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_service_percent_change_b, max_service_percent_change_b, (double)((double)total_service_percent_change_b / (double)total_passive_service_checks));
2326 
2327 	printf("</TABLE>\n");
2328 	printf("</TD></TR>\n");
2329 	printf("</TABLE>\n");
2330 
2331 	printf("</td>\n");
2332 	printf("</tr>\n");
2333 
2334 
2335 	/***** ACTIVE HOST CHECKS *****/
2336 
2337 	printf("<tr>\n");
2338 	printf("<td valign=middle><div class='perfTypeTitle'>Hosts Actively Checked:</div></td>\n");
2339 	printf("<td valign=top>\n");
2340 
2341 	/* fake this so we don't divide by zero for just showing the table */
2342 	if(total_active_host_checks == 0)
2343 		total_active_host_checks = 1;
2344 
2345 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2346 	printf("<TR><TD class='stateInfoTable1'>\n");
2347 	printf("<TABLE BORDER=0>\n");
2348 
2349 	printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Hosts Checked</th></tr>\n");
2350 	printf("<tr><td class='dataVar'>&lt;= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_1min, (double)(((double)active_host_checks_1min * 100.0) / (double)total_active_host_checks));
2351 	printf("<tr><td class='dataVar'>&lt;= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_5min, (double)(((double)active_host_checks_5min * 100.0) / (double)total_active_host_checks));
2352 	printf("<tr><td class='dataVar'>&lt;= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_15min, (double)(((double)active_host_checks_15min * 100.0) / (double)total_active_host_checks));
2353 	printf("<tr><td class='dataVar'>&lt;= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", active_host_checks_1hour, (double)(((double)active_host_checks_1hour * 100.0) / (double)total_active_host_checks));
2354 	printf("<tr><td class='dataVar'>Since program start:&nbsp;&nbsp;</td><td class='dataVal'>%d (%.1f%%)</td>", active_host_checks_start, (double)(((double)active_host_checks_start * 100.0) / (double)total_active_host_checks));
2355 
2356 	printf("</TABLE>\n");
2357 	printf("</TD></TR>\n");
2358 	printf("</TABLE>\n");
2359 
2360 	printf("</td><td valign=top>\n");
2361 
2362 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2363 	printf("<TR><TD class='stateInfoTable2'>\n");
2364 	printf("<TABLE BORDER=0>\n");
2365 
2366 	printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2367 
2368 	printf("<tr><td class='dataVar'>Check Execution Time:&nbsp;&nbsp;</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_host_execution_time, max_host_execution_time, (double)((double)total_host_execution_time / (double)total_active_host_checks));
2369 
2370 	printf("<tr><td class='dataVar'>Check Latency:</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.2f sec</td><td class='dataVal'>%.3f sec</td></tr>\n", min_host_latency, max_host_latency, (double)((double)total_host_latency / (double)total_active_host_checks));
2371 
2372 	printf("<tr><td class='dataVar'>Percent State Change:</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_host_percent_change_a, max_host_percent_change_a, (double)((double)total_host_percent_change_a / (double)total_active_host_checks));
2373 
2374 	printf("</TABLE>\n");
2375 	printf("</TD></TR>\n");
2376 	printf("</TABLE>\n");
2377 
2378 
2379 	printf("</td>\n");
2380 	printf("</tr>\n");
2381 
2382 
2383 	/***** PASSIVE HOST CHECKS *****/
2384 
2385 	printf("<tr>\n");
2386 	printf("<td valign=middle><div class='perfTypeTitle'>Hosts Passively Checked:</div></td>\n");
2387 	printf("<td valign=top>\n");
2388 
2389 
2390 	/* fake this so we don't divide by zero for just showing the table */
2391 	if(total_passive_host_checks == 0)
2392 		total_passive_host_checks = 1;
2393 
2394 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2395 	printf("<TR><TD class='stateInfoTable1'>\n");
2396 	printf("<TABLE BORDER=0>\n");
2397 
2398 	printf("<tr class='data'><th class='data'>Time Frame</th><th class='data'>Hosts Checked</th></tr>\n");
2399 	printf("<tr><td class='dataVar'>&lt;= 1 minute:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_1min, (double)(((double)passive_host_checks_1min * 100.0) / (double)total_passive_host_checks));
2400 	printf("<tr><td class='dataVar'>&lt;= 5 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_5min, (double)(((double)passive_host_checks_5min * 100.0) / (double)total_passive_host_checks));
2401 	printf("<tr><td class='dataVar'>&lt;= 15 minutes:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_15min, (double)(((double)passive_host_checks_15min * 100.0) / (double)total_passive_host_checks));
2402 	printf("<tr><td class='dataVar'>&lt;= 1 hour:</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_1hour, (double)(((double)passive_host_checks_1hour * 100.0) / (double)total_passive_host_checks));
2403 	printf("<tr><td class='dataVar'>Since program start:&nbsp;&nbsp;</td><td class='dataVal'>%d (%.1f%%)</td></tr>", passive_host_checks_start, (double)(((double)passive_host_checks_start * 100.0) / (double)total_passive_host_checks));
2404 
2405 	printf("</TABLE>\n");
2406 	printf("</TD></TR>\n");
2407 	printf("</TABLE>\n");
2408 
2409 	printf("</td><td valign=top>\n");
2410 
2411 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2412 	printf("<TR><TD class='stateInfoTable2'>\n");
2413 	printf("<TABLE BORDER=0>\n");
2414 
2415 	printf("<tr class='data'><th class='data'>Metric</th><th class='data'>Min.</th><th class='data'>Max.</th><th class='data'>Average</th></tr>\n");
2416 	printf("<tr><td class='dataVar'>Percent State Change:&nbsp;&nbsp;</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td><td class='dataVal'>%.2f%%</td></tr>\n", min_host_percent_change_b, max_host_percent_change_b, (double)((double)total_host_percent_change_b / (double)total_passive_host_checks));
2417 
2418 	printf("</TABLE>\n");
2419 	printf("</TD></TR>\n");
2420 	printf("</TABLE>\n");
2421 
2422 	printf("</td>\n");
2423 	printf("</tr>\n");
2424 
2425 
2426 
2427 	/***** CHECK STATS *****/
2428 
2429 	printf("<tr>\n");
2430 	printf("<td valign=center><div class='perfTypeTitle'>Check Statistics:</div></td>\n");
2431 	printf("<td valign=top colspan='2'>\n");
2432 
2433 
2434 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2435 	printf("<TR><TD class='stateInfoTable1'>\n");
2436 	printf("<TABLE BORDER=0>\n");
2437 
2438 	printf("<tr class='data'><th class='data'>Type</th><th class='data'>Last 1 Min</th><th class='data'>Last 5 Min</th><th class='data'>Last 15 Min</th></tr>\n");
2439 	printf("<tr><td class='dataVar'>Active Scheduled Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_HOST_CHECK_STATS][2]);
2440 	printf("<tr><td class='dataVar'>Active On-Demand Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_HOST_CHECK_STATS][2]);
2441 	printf("<tr><td class='dataVar'>Parallel Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PARALLEL_HOST_CHECK_STATS][0], program_stats[PARALLEL_HOST_CHECK_STATS][1], program_stats[PARALLEL_HOST_CHECK_STATS][2]);
2442 	printf("<tr><td class='dataVar'>Serial Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[SERIAL_HOST_CHECK_STATS][0], program_stats[SERIAL_HOST_CHECK_STATS][1], program_stats[SERIAL_HOST_CHECK_STATS][2]);
2443 	printf("<tr><td class='dataVar'>Cached Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][0], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][1], program_stats[ACTIVE_CACHED_HOST_CHECK_STATS][2]);
2444 	printf("<tr><td class='dataVar'>Passive Host Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PASSIVE_HOST_CHECK_STATS][0], program_stats[PASSIVE_HOST_CHECK_STATS][1], program_stats[PASSIVE_HOST_CHECK_STATS][2]);
2445 
2446 	printf("<tr><td class='dataVar'>Active Scheduled Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_SCHEDULED_SERVICE_CHECK_STATS][2]);
2447 	printf("<tr><td class='dataVar'>Active On-Demand Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_ONDEMAND_SERVICE_CHECK_STATS][2]);
2448 	printf("<tr><td class='dataVar'>Cached Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][0], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][1], program_stats[ACTIVE_CACHED_SERVICE_CHECK_STATS][2]);
2449 	printf("<tr><td class='dataVar'>Passive Service Checks</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[PASSIVE_SERVICE_CHECK_STATS][0], program_stats[PASSIVE_SERVICE_CHECK_STATS][1], program_stats[PASSIVE_SERVICE_CHECK_STATS][2]);
2450 
2451 	printf("<tr><td class='dataVar'>External Commands</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", program_stats[EXTERNAL_COMMAND_STATS][0], program_stats[EXTERNAL_COMMAND_STATS][1], program_stats[EXTERNAL_COMMAND_STATS][2]);
2452 
2453 	printf("</TABLE>\n");
2454 	printf("</TD></TR>\n");
2455 	printf("</TABLE>\n");
2456 
2457 	printf("</td>\n");
2458 	printf("</tr>\n");
2459 
2460 
2461 
2462 	/***** BUFFER STATS *****/
2463 
2464 	printf("<tr>\n");
2465 	printf("<td valign=center><div class='perfTypeTitle'>Buffer Usage:</div></td>\n");
2466 	printf("<td valign=top colspan='2'>\n");
2467 
2468 
2469 	printf("<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0>\n");
2470 	printf("<TR><TD class='stateInfoTable1'>\n");
2471 	printf("<TABLE BORDER=0>\n");
2472 
2473 	printf("<tr class='data'><th class='data'>Type</th><th class='data'>In Use</th><th class='data'>Max Used</th><th class='data'>Total Available</th></tr>\n");
2474 	printf("<tr><td class='dataVar'>External Commands&nbsp;</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td><td class='dataVal'>%d</td></tr>", buffer_stats[0][1], buffer_stats[0][2], buffer_stats[0][0]);
2475 
2476 	printf("</TABLE>\n");
2477 	printf("</TD></TR>\n");
2478 	printf("</TABLE>\n");
2479 
2480 	printf("</td>\n");
2481 	printf("</tr>\n");
2482 
2483 
2484 
2485 	printf("</table>\n");
2486 
2487 
2488 	printf("</div>\n");
2489 
2490 	return;
2491 	}
2492 
2493 
2494 
display_comments(int type)2495 void display_comments(int type) {
2496 	host *temp_host = NULL;
2497 	service *temp_service = NULL;
2498 	int total_comments = 0;
2499 	int display_comment = FALSE;
2500 	char *bg_class = "";
2501 	int odd = 1;
2502 	char date_time[MAX_DATETIME_LENGTH];
2503 	comment *temp_comment;
2504 	char *comment_type;
2505 	char expire_time[MAX_DATETIME_LENGTH];
2506 
2507 
2508 	/* find the host or service */
2509 	if(type == HOST_COMMENT) {
2510 		temp_host = find_host(host_name);
2511 		if(temp_host == NULL)
2512 			return;
2513 		}
2514 	else {
2515 		temp_service = find_service(host_name, service_desc);
2516 		if(temp_service == NULL)
2517 			return;
2518 		}
2519 
2520 
2521 	printf("<A NAME=comments></A>\n");
2522 	printf("<DIV CLASS='commentTitle'>%s Comments</DIV>\n", (type == HOST_COMMENT) ? "Host" : "Service");
2523 	printf("<TABLE BORDER=0>\n");
2524 
2525 	printf("<tr>\n");
2526 	printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, COMMENT_ICON);
2527 	if(type == HOST_COMMENT)
2528 		printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_ADD_HOST_COMMENT, url_encode(host_name));
2529 	else {
2530 		printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_ADD_SVC_COMMENT, url_encode(host_name));
2531 		printf("service=%s' CLASS='comment'>", url_encode(service_desc));
2532 		}
2533 	printf("Add a new comment</a></td>\n");
2534 
2535 	printf("<td valign=middle><img src='%s%s' border=0 align=center></td><td CLASS='comment'>", url_images_path, DELETE_ICON);
2536 	if(type == HOST_COMMENT)
2537 		printf("<a href='%s?cmd_typ=%d&host=%s' CLASS='comment'>", COMMAND_CGI, CMD_DEL_ALL_HOST_COMMENTS, url_encode(host_name));
2538 	else {
2539 		printf("<a href='%s?cmd_typ=%d&host=%s&", COMMAND_CGI, CMD_DEL_ALL_SVC_COMMENTS, url_encode(host_name));
2540 		printf("service=%s' CLASS='comment'>", url_encode(service_desc));
2541 		}
2542 	printf("Delete all comments</a></td>\n");
2543 	printf("</tr>\n");
2544 
2545 	printf("</TABLE>\n");
2546 	//printf("</DIV>\n");
2547 
2548 
2549 	printf("<DIV ALIGN=CENTER>\n");
2550 	printf("<TABLE BORDER=0 CLASS='comment'>\n");
2551 	printf("<TR CLASS='comment'><TH CLASS='comment'>Entry Time</TH><TH CLASS='comment'>Author</TH><TH CLASS='comment'>Comment</TH><TH CLASS='comment'>Comment ID</TH><TH CLASS='comment'>Persistent</TH><TH CLASS='comment'>Type</TH><TH CLASS='comment'>Expires</TH><TH CLASS='comment'>Actions</TH></TR>\n");
2552 
2553 	/* check all the comments to see if they apply to this host or service */
2554 	/* Comments are displayed in the order they are read from the status.dat file */
2555 	for(temp_comment = get_first_comment_by_host(host_name); temp_comment != NULL; temp_comment = get_next_comment_by_host(host_name, temp_comment)) {
2556 
2557 		display_comment = FALSE;
2558 
2559 		if(type == HOST_COMMENT && temp_comment->comment_type == HOST_COMMENT)
2560 			display_comment = TRUE;
2561 
2562 		else if(type == SERVICE_COMMENT && temp_comment->comment_type == SERVICE_COMMENT && !strcmp(temp_comment->service_description, service_desc))
2563 			display_comment = TRUE;
2564 
2565 		if(display_comment == TRUE) {
2566 
2567 			if(odd) {
2568 				odd = 0;
2569 				bg_class = "commentOdd";
2570 				}
2571 			else {
2572 				odd = 1;
2573 				bg_class = "commentEven";
2574 				}
2575 
2576 			switch(temp_comment->entry_type) {
2577 				case USER_COMMENT:
2578 					comment_type = "User";
2579 					break;
2580 				case DOWNTIME_COMMENT:
2581 					comment_type = "Scheduled Downtime";
2582 					break;
2583 				case FLAPPING_COMMENT:
2584 					comment_type = "Flap Detection";
2585 					break;
2586 				case ACKNOWLEDGEMENT_COMMENT:
2587 					comment_type = "Acknowledgement";
2588 					break;
2589 				default:
2590 					comment_type = "?";
2591 				}
2592 
2593 			get_time_string(&temp_comment->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2594 			get_time_string(&temp_comment->expire_time, expire_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2595 			printf("<tr CLASS='%s'>", bg_class);
2596 			printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%lu</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'>%s</td>", bg_class, date_time, bg_class, temp_comment->author, bg_class, temp_comment->comment_data, bg_class, temp_comment->comment_id, bg_class, (temp_comment->persistent) ? "Yes" : "No", bg_class, comment_type, bg_class, (temp_comment->expires == TRUE) ? expire_time : "N/A");
2597 			printf("<td><a href='%s?cmd_typ=%d&com_id=%lu'><img src='%s%s' border=0 ALT='Delete This Comment' TITLE='Delete This Comment'></td>", COMMAND_CGI, (type == HOST_COMMENT) ? CMD_DEL_HOST_COMMENT : CMD_DEL_SVC_COMMENT, temp_comment->comment_id, url_images_path, DELETE_ICON);
2598 			printf("</tr>\n");
2599 
2600 			total_comments++;
2601 			}
2602 		}
2603 
2604 	/* see if this host or service has any comments associated with it */
2605 	if(total_comments == 0)
2606 		printf("<TR CLASS='commentOdd'><TD CLASS='commentOdd' COLSPAN='%d'>This %s has no comments associated with it</TD></TR>", (type == HOST_COMMENT) ? 9 : 10, (type == HOST_COMMENT) ? "host" : "service");
2607 
2608 	printf("</TABLE></DIV>\n");
2609 
2610 	return;
2611 	}
2612 
2613 
2614 
2615 
2616 /* shows all service and host scheduled downtime */
show_all_downtime(void)2617 void show_all_downtime(void) {
2618 	int total_downtime = 0;
2619 	char *bg_class = "";
2620 	int odd = 0;
2621 	char date_time[MAX_DATETIME_LENGTH];
2622 	scheduled_downtime *temp_downtime;
2623 	host *temp_host;
2624 	service *temp_service;
2625 	int days;
2626 	int hours;
2627 	int minutes;
2628 	int seconds;
2629 
2630 
2631 	printf("<BR />\n");
2632 	printf("<DIV CLASS='downtimeNav'>[&nbsp;<A HREF='#HOSTDOWNTIME' CLASS='downtimeNav'>Host Downtime</A>&nbsp;|&nbsp;<A HREF='#SERVICEDOWNTIME' CLASS='downtimeNav'>Service Downtime</A>&nbsp;]</DIV>\n");
2633 	printf("<BR />\n");
2634 
2635 	printf("<A NAME=HOSTDOWNTIME></A>\n");
2636 	printf("<DIV CLASS='downtimeTitle'>Scheduled Host Downtime</DIV>\n");
2637 
2638 	printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, DOWNTIME_ICON);
2639 	printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_SCHEDULE_HOST_DOWNTIME);
2640 	printf("Schedule host downtime</a></div>\n");
2641 
2642 	printf("<BR />\n");
2643 	printf("<DIV ALIGN=CENTER>\n");
2644 	printf("<TABLE BORDER=0 CLASS='downtime'>\n");
2645 	printf("<TR CLASS='downtime'><TH CLASS='downtime'>Host Name</TH><TH CLASS='downtime'>Entry Time</TH><TH CLASS='downtime'>Author</TH><TH CLASS='downtime'>Comment</TH><TH CLASS='downtime'>Start Time</TH><TH CLASS='downtime'>End Time</TH><TH CLASS='downtime'>Type</TH><TH CLASS='downtime'>Duration</TH><TH CLASS='downtime'>Downtime ID</TH><TH CLASS='downtime'>Trigger ID</TH><TH CLASS='downtime'>Actions</TH></TR>\n");
2646 
2647 	/* display all the host downtime */
2648 	for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
2649 
2650 		if(temp_downtime->type != HOST_DOWNTIME)
2651 			continue;
2652 
2653 		temp_host = find_host(temp_downtime->host_name);
2654 
2655 		/* make sure the user has rights to view host information */
2656 		if(is_authorized_for_host(temp_host, &current_authdata) == FALSE)
2657 			continue;
2658 
2659 		total_downtime++;
2660 
2661 		if(odd) {
2662 			odd = 0;
2663 			bg_class = "downtimeOdd";
2664 			}
2665 		else {
2666 			odd = 1;
2667 			bg_class = "downtimeEven";
2668 			}
2669 
2670 		printf("<tr CLASS='%s'>", bg_class);
2671 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name);
2672 		get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2673 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2674 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author);
2675 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment);
2676 		get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2677 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2678 		get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2679 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2680 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible");
2681 		get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds);
2682 		printf("<td CLASS='%s'>%dd %dh %dm %ds</td>", bg_class, days, hours, minutes, seconds);
2683 		printf("<td CLASS='%s'>%lu</td>", bg_class, temp_downtime->downtime_id);
2684 		printf("<td CLASS='%s'>", bg_class);
2685 		if(temp_downtime->triggered_by == 0)
2686 			printf("N/A");
2687 		else
2688 			printf("%lu", temp_downtime->triggered_by);
2689 		printf("</td>\n");
2690 		printf("<td><a href='%s?cmd_typ=%d&down_id=%lu'><img src='%s%s' border=0 ALT='Delete/Cancel This Scheduled Downtime Entry' TITLE='Delete/Cancel This Scheduled Downtime Entry'></td>", COMMAND_CGI, CMD_DEL_HOST_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON);
2691 		printf("</tr>\n");
2692 		}
2693 
2694 	if(total_downtime == 0)
2695 		printf("<TR CLASS='downtimeOdd'><TD CLASS='downtimeOdd' COLSPAN=11>There are no hosts with scheduled downtime</TD></TR>");
2696 
2697 	printf("</TABLE>\n");
2698 	printf("</DIV>\n");
2699 
2700 	printf("<BR /><BR /><BR />\n");
2701 
2702 
2703 	printf("<A NAME=SERVICEDOWNTIME></A>\n");
2704 	printf("<DIV CLASS='downtimeTitle'>Scheduled Service Downtime</DIV>\n");
2705 
2706 	printf("<div CLASS='comment'><img src='%s%s' border=0>&nbsp;", url_images_path, DOWNTIME_ICON);
2707 	printf("<a href='%s?cmd_typ=%d'>", COMMAND_CGI, CMD_SCHEDULE_SVC_DOWNTIME);
2708 	printf("Schedule service downtime</a></div>\n");
2709 
2710 	printf("<BR />\n");
2711 	printf("<DIV ALIGN=CENTER>\n");
2712 	printf("<TABLE BORDER=0 CLASS='downtime'>\n");
2713 	printf("<TR CLASS='downtime'><TH CLASS='downtime'>Host Name</TH><TH CLASS='downtime'>Service</TH><TH CLASS='downtime'>Entry Time</TH><TH CLASS='downtime'>Author</TH><TH CLASS='downtime'>Comment</TH><TH CLASS='downtime'>Start Time</TH><TH CLASS='downtime'>End Time</TH><TH CLASS='downtime'>Type</TH><TH CLASS='downtime'>Duration</TH><TH CLASS='downtime'>Downtime ID</TH><TH CLASS='downtime'>Trigger ID</TH><TH CLASS='downtime'>Actions</TH></TR>\n");
2714 
2715 	/* display all the service downtime */
2716 	for(temp_downtime = scheduled_downtime_list, total_downtime = 0; temp_downtime != NULL; temp_downtime = temp_downtime->next) {
2717 
2718 		if(temp_downtime->type != SERVICE_DOWNTIME)
2719 			continue;
2720 
2721 		temp_service = find_service(temp_downtime->host_name, temp_downtime->service_description);
2722 
2723 		/* make sure the user has rights to view service information */
2724 		if(is_authorized_for_service(temp_service, &current_authdata) == FALSE)
2725 			continue;
2726 
2727 		total_downtime++;
2728 
2729 		if(odd) {
2730 			odd = 0;
2731 			bg_class = "downtimeOdd";
2732 			}
2733 		else {
2734 			odd = 1;
2735 			bg_class = "downtimeEven";
2736 			}
2737 
2738 		printf("<tr CLASS='%s'>", bg_class);
2739 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s'>%s</A></td>", bg_class, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_downtime->host_name), temp_downtime->host_name);
2740 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s", bg_class, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_downtime->host_name));
2741 		printf("&service=%s'>%s</A></td>", url_encode(temp_downtime->service_description), temp_downtime->service_description);
2742 		get_time_string(&temp_downtime->entry_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2743 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2744 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->author == NULL) ? "N/A" : temp_downtime->author);
2745 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->comment == NULL) ? "N/A" : temp_downtime->comment);
2746 		get_time_string(&temp_downtime->start_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2747 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2748 		get_time_string(&temp_downtime->end_time, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2749 		printf("<td CLASS='%s'>%s</td>", bg_class, date_time);
2750 		printf("<td CLASS='%s'>%s</td>", bg_class, (temp_downtime->fixed == TRUE) ? "Fixed" : "Flexible");
2751 		get_time_breakdown(temp_downtime->duration, &days, &hours, &minutes, &seconds);
2752 		printf("<td CLASS='%s'>%dd %dh %dm %ds</td>", bg_class, days, hours, minutes, seconds);
2753 		printf("<td CLASS='%s'>%lu</td>", bg_class, temp_downtime->downtime_id);
2754 		printf("<td CLASS='%s'>", bg_class);
2755 		if(temp_downtime->triggered_by == 0)
2756 			printf("N/A");
2757 		else
2758 			printf("%lu", temp_downtime->triggered_by);
2759 		printf("</td>\n");
2760 		printf("<td><a href='%s?cmd_typ=%d&down_id=%lu'><img src='%s%s' border=0 ALT='Delete/Cancel This Scheduled Downtime Entry' TITLE='Delete/Cancel This Scheduled Downtime Entry'></td>", COMMAND_CGI, CMD_DEL_SVC_DOWNTIME, temp_downtime->downtime_id, url_images_path, DELETE_ICON);
2761 		printf("</tr>\n");
2762 		}
2763 
2764 	if(total_downtime == 0)
2765 		printf("<TR CLASS='downtimeOdd'><TD CLASS='downtimeOdd' COLSPAN=12>There are no services with scheduled downtime</TD></TR>");
2766 
2767 	printf("</TABLE>\n");
2768 	printf("</DIV>\n");
2769 
2770 	return;
2771 	}
2772 
2773 
2774 
2775 /* shows check scheduling queue */
show_scheduling_queue(void)2776 void show_scheduling_queue(void) {
2777 	sortdata *temp_sortdata;
2778 	servicestatus *temp_svcstatus = NULL;
2779 	hoststatus *temp_hststatus = NULL;
2780 	char date_time[MAX_DATETIME_LENGTH];
2781 	char temp_url[MAX_INPUT_BUFFER];
2782 	int odd = 0;
2783 	char *bgclass = "";
2784 
2785 
2786 	/* make sure the user has rights to view system information */
2787 	if(is_authorized_for_system_information(&current_authdata) == FALSE) {
2788 
2789 		printf("<P><DIV CLASS='errorMessage'>It appears as though you do not have permission to view process information...</DIV></P>\n");
2790 		printf("<P><DIV CLASS='errorDescription'>If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI<br>");
2791 		printf("and check the authorization options in your CGI configuration file.</DIV></P>\n");
2792 
2793 		return;
2794 		}
2795 
2796 	/* sort hosts and services */
2797 	sort_data(sort_type, sort_option);
2798 
2799 	printf("<DIV ALIGN=CENTER CLASS='statusSort'>Entries sorted by <b>");
2800 	if(sort_option == SORT_HOSTNAME)
2801 		printf("host name");
2802 	else if(sort_option == SORT_SERVICENAME)
2803 		printf("service name");
2804 	else if(sort_option == SORT_SERVICESTATUS)
2805 		printf("service status");
2806 	else if(sort_option == SORT_LASTCHECKTIME)
2807 		printf("last check time");
2808 	else if(sort_option == SORT_NEXTCHECKTIME)
2809 		printf("next check time");
2810 	printf("</b> (%s)\n", (sort_type == SORT_ASCENDING) ? "ascending" : "descending");
2811 	printf("</DIV>\n");
2812 
2813 	printf("<P>\n");
2814 	printf("<DIV ALIGN=CENTER>\n");
2815 	printf("<TABLE BORDER=0 CLASS='queue'>\n");
2816 	printf("<TR CLASS='queue'>");
2817 
2818 	snprintf(temp_url, sizeof(temp_url) - 1, "%s?type=%d", EXTINFO_CGI, DISPLAY_SCHEDULING_QUEUE);
2819 	temp_url[sizeof(temp_url) - 1] = '\x0';
2820 
2821 	printf("<TH CLASS='queue'>Host&nbsp;<A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (ascending)' TITLE='Sort by host name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by host name (descending)' TITLE='Sort by host name (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_HOSTNAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_HOSTNAME, url_images_path, DOWN_ARROW_ICON);
2822 
2823 	printf("<TH CLASS='queue'>Service&nbsp;<A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (ascending)' TITLE='Sort by service name (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by service name (descending)' TITLE='Sort by service name (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_SERVICENAME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_SERVICENAME, url_images_path, DOWN_ARROW_ICON);
2824 
2825 	printf("<TH CLASS='queue'>Last Check&nbsp;<A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (ascending)' TITLE='Sort by last check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by last check time (descending)' TITLE='Sort by last check time (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_LASTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_LASTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
2826 
2827 	printf("<TH CLASS='queue'>Next Check&nbsp;<A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by next check time (ascending)' TITLE='Sort by next check time (ascending)'></A><A HREF='%s&sorttype=%d&sortoption=%d'><IMG SRC='%s%s' BORDER=0 ALT='Sort by next check time (descending)' TITLE='Sort by next check time (descending)'></A></TH>", temp_url, SORT_ASCENDING, SORT_NEXTCHECKTIME, url_images_path, UP_ARROW_ICON, temp_url, SORT_DESCENDING, SORT_NEXTCHECKTIME, url_images_path, DOWN_ARROW_ICON);
2828 
2829 
2830 	printf("<TH CLASS='queue'>Type</TH><TH CLASS='queue'>Active Checks</TH><TH CLASS='queue'>Actions</TH></TR>\n");
2831 
2832 
2833 	/* display all services and hosts */
2834 	for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
2835 
2836 		/* skip hosts and services that shouldn't be scheduled */
2837 		if(temp_sortdata->is_service == TRUE) {
2838 			temp_svcstatus = temp_sortdata->svcstatus;
2839 			if(temp_svcstatus->should_be_scheduled == FALSE) {
2840 				/* passive-only checks should appear if they're being forced */
2841 				if(!(temp_svcstatus->checks_enabled == FALSE && temp_svcstatus->next_check != (time_t)0L && (temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)))
2842 					continue;
2843 				}
2844 			}
2845 		else {
2846 			temp_hststatus = temp_sortdata->hststatus;
2847 			if(temp_hststatus->should_be_scheduled == FALSE) {
2848 				/* passive-only checks should appear if they're being forced */
2849 				if(!(temp_hststatus->checks_enabled == FALSE && temp_hststatus->next_check != (time_t)0L && (temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)))
2850 					continue;
2851 				}
2852 			}
2853 
2854 		if(odd) {
2855 			odd = 0;
2856 			bgclass = "Even";
2857 			}
2858 		else {
2859 			odd = 1;
2860 			bgclass = "Odd";
2861 			}
2862 
2863 		printf("<TR CLASS='queue%s'>", bgclass);
2864 
2865 		/* get the service status */
2866 		if(temp_sortdata->is_service == TRUE) {
2867 
2868 			printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s'>%s</A></TD>", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_svcstatus->host_name), temp_svcstatus->host_name);
2869 
2870 			printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s", bgclass, EXTINFO_CGI, DISPLAY_SERVICE_INFO, url_encode(temp_svcstatus->host_name));
2871 			printf("&service=%s'>%s</A></TD>", url_encode(temp_svcstatus->description), temp_svcstatus->description);
2872 
2873 			get_time_string(&temp_svcstatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2874 			printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_svcstatus->last_check == (time_t)0) ? "N/A" : date_time);
2875 
2876 			get_time_string(&temp_svcstatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2877 			printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_svcstatus->next_check == (time_t)0) ? "N/A" : date_time);
2878 
2879 			printf("<TD CLASS='queue%s'>", bgclass);
2880 			if(temp_svcstatus->check_options == CHECK_OPTION_NONE)
2881 				printf("Normal ");
2882 			else {
2883 				if(temp_svcstatus->check_options & CHECK_OPTION_FORCE_EXECUTION)
2884 					printf("Forced ");
2885 				if(temp_svcstatus->check_options & CHECK_OPTION_FRESHNESS_CHECK)
2886 					printf("Freshness ");
2887 				if(temp_svcstatus->check_options & CHECK_OPTION_ORPHAN_CHECK)
2888 					printf("Orphan ");
2889 				}
2890 			printf("</TD>");
2891 
2892 			printf("<TD CLASS='queue%s'>%s</TD>", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_svcstatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
2893 
2894 			printf("<TD CLASS='queue%s'>", bgclass);
2895 			if(temp_svcstatus->checks_enabled == TRUE) {
2896 				printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_DISABLE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2897 				printf("&service=%s'><img src='%s%s' border=0 ALT='Disable Active Checks Of This Service' TITLE='Disable Active Checks Of This Service'></a>\n", url_encode(temp_svcstatus->description), url_images_path, DISABLED_ICON);
2898 				}
2899 			else {
2900 				printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_ENABLE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2901 				printf("&service=%s'><img src='%s%s' border=0 ALT='Enable Active Checks Of This Service' TITLE='Enable Active Checks Of This Service'></a>\n", url_encode(temp_svcstatus->description), url_images_path, ENABLED_ICON);
2902 				}
2903 			printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_SCHEDULE_SVC_CHECK, url_encode(temp_svcstatus->host_name));
2904 			printf("&service=%s%s'><img src='%s%s' border=0 ALT='Re-schedule This Service Check' TITLE='Re-schedule This Service Check'></a>\n", url_encode(temp_svcstatus->description), (temp_svcstatus->checks_enabled == TRUE) ? "&force_check" : "", url_images_path, DELAY_ICON);
2905 			printf("</TD>\n");
2906 			}
2907 
2908 		/* get the host status */
2909 		else {
2910 
2911 			printf("<TD CLASS='queue%s'><A HREF='%s?type=%d&host=%s'>%s</A></TD>", bgclass, EXTINFO_CGI, DISPLAY_HOST_INFO, url_encode(temp_hststatus->host_name), temp_hststatus->host_name);
2912 
2913 			printf("<TD CLASS='queue%s'>&nbsp;</TD>", bgclass);
2914 
2915 			get_time_string(&temp_hststatus->last_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2916 			printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_hststatus->last_check == (time_t)0) ? "N/A" : date_time);
2917 
2918 			get_time_string(&temp_hststatus->next_check, date_time, (int)sizeof(date_time), SHORT_DATE_TIME);
2919 			printf("<TD CLASS='queue%s'>%s</TD>", bgclass, (temp_hststatus->next_check == (time_t)0) ? "N/A" : date_time);
2920 
2921 			printf("<TD CLASS='queue%s'>", bgclass);
2922 			if(temp_hststatus->check_options == CHECK_OPTION_NONE)
2923 				printf("Normal ");
2924 			else {
2925 				if(temp_hststatus->check_options & CHECK_OPTION_FORCE_EXECUTION)
2926 					printf("Forced ");
2927 				if(temp_hststatus->check_options & CHECK_OPTION_FRESHNESS_CHECK)
2928 					printf("Freshness ");
2929 				if(temp_hststatus->check_options & CHECK_OPTION_ORPHAN_CHECK)
2930 					printf("Orphan ");
2931 				}
2932 			printf("</TD>");
2933 
2934 			printf("<TD CLASS='queue%s'>%s</TD>", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED", (temp_hststatus->checks_enabled == TRUE) ? "ENABLED" : "DISABLED");
2935 
2936 			printf("<TD CLASS='queue%s'>", bgclass);
2937 			if(temp_hststatus->checks_enabled == TRUE) {
2938 				printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_DISABLE_HOST_CHECK, url_encode(temp_hststatus->host_name));
2939 				printf("'><img src='%s%s' border=0 ALT='Disable Active Checks Of This Host' TITLE='Disable Active Checks Of This Host'></a>\n", url_images_path, DISABLED_ICON);
2940 				}
2941 			else {
2942 				printf("<a href='%s?cmd_typ=%d&host=%s", COMMAND_CGI, CMD_ENABLE_HOST_CHECK, url_encode(temp_hststatus->host_name));
2943 				printf("'><img src='%s%s' border=0 ALT='Enable Active Checks Of This Host' TITLE='Enable Active Checks Of This Host'></a>\n", url_images_path, ENABLED_ICON);
2944 				}
2945 			printf("<a href='%s?cmd_typ=%d&host=%s%s", COMMAND_CGI, CMD_SCHEDULE_HOST_CHECK, url_encode(temp_hststatus->host_name), (temp_hststatus->checks_enabled == TRUE) ? "&force_check" : "");
2946 			printf("'><img src='%s%s' border=0 ALT='Re-schedule This Host Check' TITLE='Re-schedule This Host Check'></a>\n", url_images_path, DELAY_ICON);
2947 			printf("</TD>\n");
2948 			}
2949 
2950 		printf("</TR>\n");
2951 
2952 		}
2953 
2954 	printf("</TABLE>\n");
2955 	printf("</DIV>\n");
2956 	printf("</P>\n");
2957 
2958 
2959 	/* free memory allocated to sorted data list */
2960 	free_sortdata_list();
2961 
2962 	return;
2963 	}
2964 
2965 
2966 
2967 /* sorts host and service data */
sort_data(int s_type,int s_option)2968 int sort_data(int s_type, int s_option) {
2969 	sortdata *new_sortdata;
2970 	sortdata *last_sortdata;
2971 	sortdata *temp_sortdata;
2972 	servicestatus *temp_svcstatus;
2973 	hoststatus *temp_hststatus;
2974 
2975 	if(s_type == SORT_NONE)
2976 		return ERROR;
2977 
2978 	/* sort all service status entries */
2979 	for(temp_svcstatus = servicestatus_list; temp_svcstatus != NULL; temp_svcstatus = temp_svcstatus->next) {
2980 
2981 		/* allocate memory for a new sort structure */
2982 		new_sortdata = (sortdata *)malloc(sizeof(sortdata));
2983 		if(new_sortdata == NULL)
2984 			return ERROR;
2985 
2986 		new_sortdata->is_service = TRUE;
2987 		new_sortdata->svcstatus = temp_svcstatus;
2988 		new_sortdata->hststatus = NULL;
2989 
2990 		last_sortdata = sortdata_list;
2991 		for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
2992 
2993 			if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
2994 				new_sortdata->next = temp_sortdata;
2995 				if(temp_sortdata == sortdata_list)
2996 					sortdata_list = new_sortdata;
2997 				else
2998 					last_sortdata->next = new_sortdata;
2999 				break;
3000 				}
3001 			else
3002 				last_sortdata = temp_sortdata;
3003 			}
3004 
3005 		if(sortdata_list == NULL) {
3006 			new_sortdata->next = NULL;
3007 			sortdata_list = new_sortdata;
3008 			}
3009 		else if(temp_sortdata == NULL) {
3010 			new_sortdata->next = NULL;
3011 			last_sortdata->next = new_sortdata;
3012 			}
3013 		}
3014 
3015 	/* sort all host status entries */
3016 	for(temp_hststatus = hoststatus_list; temp_hststatus != NULL; temp_hststatus = temp_hststatus->next) {
3017 
3018 		/* allocate memory for a new sort structure */
3019 		new_sortdata = (sortdata *)malloc(sizeof(sortdata));
3020 		if(new_sortdata == NULL)
3021 			return ERROR;
3022 
3023 		new_sortdata->is_service = FALSE;
3024 		new_sortdata->svcstatus = NULL;
3025 		new_sortdata->hststatus = temp_hststatus;
3026 
3027 		last_sortdata = sortdata_list;
3028 		for(temp_sortdata = sortdata_list; temp_sortdata != NULL; temp_sortdata = temp_sortdata->next) {
3029 
3030 			if(compare_sortdata_entries(s_type, s_option, new_sortdata, temp_sortdata) == TRUE) {
3031 				new_sortdata->next = temp_sortdata;
3032 				if(temp_sortdata == sortdata_list)
3033 					sortdata_list = new_sortdata;
3034 				else
3035 					last_sortdata->next = new_sortdata;
3036 				break;
3037 				}
3038 			else
3039 				last_sortdata = temp_sortdata;
3040 			}
3041 
3042 		if(sortdata_list == NULL) {
3043 			new_sortdata->next = NULL;
3044 			sortdata_list = new_sortdata;
3045 			}
3046 		else if(temp_sortdata == NULL) {
3047 			new_sortdata->next = NULL;
3048 			last_sortdata->next = new_sortdata;
3049 			}
3050 		}
3051 
3052 	return OK;
3053 	}
3054 
3055 
compare_sortdata_entries(int s_type,int s_option,sortdata * new_sortdata,sortdata * temp_sortdata)3056 int compare_sortdata_entries(int s_type, int s_option, sortdata *new_sortdata, sortdata *temp_sortdata) {
3057 	hoststatus *temp_hststatus = NULL;
3058 	servicestatus *temp_svcstatus = NULL;
3059 	time_t last_check[2];
3060 	time_t next_check[2];
3061 	int current_attempt[2];
3062 	int status[2];
3063 	char *host_name[2];
3064 	char *service_description[2];
3065 
3066 	if(new_sortdata->is_service == TRUE) {
3067 		temp_svcstatus = new_sortdata->svcstatus;
3068 		last_check[0] = temp_svcstatus->last_check;
3069 		next_check[0] = temp_svcstatus->next_check;
3070 		status[0] = temp_svcstatus->status;
3071 		host_name[0] = temp_svcstatus->host_name;
3072 		service_description[0] = temp_svcstatus->description;
3073 		current_attempt[0] = temp_svcstatus->current_attempt;
3074 		}
3075 	else {
3076 		temp_hststatus = new_sortdata->hststatus;
3077 		last_check[0] = temp_hststatus->last_check;
3078 		next_check[0] = temp_hststatus->next_check;
3079 		status[0] = temp_hststatus->status;
3080 		host_name[0] = temp_hststatus->host_name;
3081 		service_description[0] = "";
3082 		current_attempt[0] = temp_hststatus->current_attempt;
3083 		}
3084 	if(temp_sortdata->is_service == TRUE) {
3085 		temp_svcstatus = temp_sortdata->svcstatus;
3086 		last_check[1] = temp_svcstatus->last_check;
3087 		next_check[1] = temp_svcstatus->next_check;
3088 		status[1] = temp_svcstatus->status;
3089 		host_name[1] = temp_svcstatus->host_name;
3090 		service_description[1] = temp_svcstatus->description;
3091 		current_attempt[1] = temp_svcstatus->current_attempt;
3092 		}
3093 	else {
3094 		temp_hststatus = temp_sortdata->hststatus;
3095 		last_check[1] = temp_hststatus->last_check;
3096 		next_check[1] = temp_hststatus->next_check;
3097 		status[1] = temp_hststatus->status;
3098 		host_name[1] = temp_hststatus->host_name;
3099 		service_description[1] = "";
3100 		current_attempt[1] = temp_hststatus->current_attempt;
3101 		}
3102 
3103 	if(s_type == SORT_ASCENDING) {
3104 
3105 		if(s_option == SORT_LASTCHECKTIME) {
3106 			if(last_check[0] <= last_check[1])
3107 				return TRUE;
3108 			else
3109 				return FALSE;
3110 			}
3111 		if(s_option == SORT_NEXTCHECKTIME) {
3112 			if(next_check[0] <= next_check[1])
3113 				return TRUE;
3114 			else
3115 				return FALSE;
3116 			}
3117 		else if(s_option == SORT_CURRENTATTEMPT) {
3118 			if(current_attempt[0] <= current_attempt[1])
3119 				return TRUE;
3120 			else
3121 				return FALSE;
3122 			}
3123 		else if(s_option == SORT_SERVICESTATUS) {
3124 			if(status[0] <= status[1])
3125 				return TRUE;
3126 			else
3127 				return FALSE;
3128 			}
3129 		else if(s_option == SORT_HOSTNAME) {
3130 			if(strcasecmp(host_name[0], host_name[1]) < 0)
3131 				return TRUE;
3132 			else
3133 				return FALSE;
3134 			}
3135 		else if(s_option == SORT_SERVICENAME) {
3136 			if(strcasecmp(service_description[0], service_description[1]) < 0)
3137 				return TRUE;
3138 			else
3139 				return FALSE;
3140 			}
3141 		}
3142 	else {
3143 		if(s_option == SORT_LASTCHECKTIME) {
3144 			if(last_check[0] > last_check[1])
3145 				return TRUE;
3146 			else
3147 				return FALSE;
3148 			}
3149 		if(s_option == SORT_NEXTCHECKTIME) {
3150 			if(next_check[0] > next_check[1])
3151 				return TRUE;
3152 			else
3153 				return FALSE;
3154 			}
3155 		else if(s_option == SORT_CURRENTATTEMPT) {
3156 			if(current_attempt[0] > current_attempt[1])
3157 				return TRUE;
3158 			else
3159 				return FALSE;
3160 			}
3161 		else if(s_option == SORT_SERVICESTATUS) {
3162 			if(status[0] > status[1])
3163 				return TRUE;
3164 			else
3165 				return FALSE;
3166 			}
3167 		else if(s_option == SORT_HOSTNAME) {
3168 			if(strcasecmp(host_name[0], host_name[1]) > 0)
3169 				return TRUE;
3170 			else
3171 				return FALSE;
3172 			}
3173 		else if(s_option == SORT_SERVICENAME) {
3174 			if(strcasecmp(service_description[0], service_description[1]) > 0)
3175 				return TRUE;
3176 			else
3177 				return FALSE;
3178 			}
3179 		}
3180 
3181 	return TRUE;
3182 	}
3183 
3184 
3185 
3186 /* free all memory allocated to the sortdata structures */
free_sortdata_list(void)3187 void free_sortdata_list(void) {
3188 	sortdata *this_sortdata;
3189 	sortdata *next_sortdata;
3190 
3191 	/* free memory for the sortdata list */
3192 	for(this_sortdata = sortdata_list; this_sortdata != NULL; this_sortdata = next_sortdata) {
3193 		next_sortdata = this_sortdata->next;
3194 		free(this_sortdata);
3195 		}
3196 
3197 	return;
3198 	}
3199 
3200