/************************************************************************ * * NOTIFICATIONS.C - NetSaint Notifications CGI * * Copyright (c) 1999-2001 Ethan Galstad (netsaint@netsaint.org) * Last Modified: 06-08-2001 * * This CGI program will display the notification events for * a given host or contact or for all contacts/hosts. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ***********************************************************************/ #include "../common/config.h" #include "../common/locations.h" #include "../common/common.h" #include "getcgi.h" #include "cgiutils.h" #include "auth.h" #include "lifo.h" extern char main_config_file[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_docs_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern int log_rotation_method; extern time_t this_scheduled_log_rotation; extern time_t last_scheduled_log_rotation; #define FIND_HOST 1 #define FIND_CONTACT 2 #define FIND_SERVICE 3 #define MAX_QUERYNAME_LENGTH 256 #define SERVICE_NOTIFICATION 0 #define HOST_NOTIFICATION 1 #define SERVICE_NOTIFICATION_STRING "] SERVICE NOTIFICATION:" #define HOST_NOTIFICATION_STRING "] HOST NOTIFICATION:" void display_notifications(void); void document_header(int); void document_footer(void); int process_cgivars(void); authdata current_authdata; char log_file_to_use[MAX_FILENAME_LENGTH]; int log_archive=0; int query_type=FIND_HOST; int find_all=TRUE; char *query_contact_name="all"; char *query_host_name="all"; char *query_svc_description=""; int notification_options=NOTIFICATION_ALL; int use_lifo=TRUE; int embedded=FALSE; int display_header=TRUE; int main(void){ int result=OK; char temp_buffer[MAX_INPUT_BUFFER]; char temp_buffer2[MAX_INPUT_BUFFER]; /* get the arguments passed in the URL */ process_cgivars(); /* reset internal variables */ reset_cgi_vars(); /* read the CGI configuration file */ result=read_cgi_config_file(DEFAULT_CGI_CONFIG_FILE); if(result==ERROR){ document_header(FALSE); printf("
\n");
if(query_type==FIND_SERVICE)
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Notifications For Service %s On Host %s",query_svc_description,query_host_name);
else{
if(find_all==TRUE)
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Notifications For All %s",(query_type==FIND_HOST)?"Hosts":"Contacts");
else
snprintf(temp_buffer,sizeof(temp_buffer)-1,"Notifications For %s %s",(query_type==FIND_HOST)?"Host":"Contact",(query_type==FIND_HOST)?query_host_name:query_contact_name);
}
temp_buffer[sizeof(temp_buffer)-1]='\x0';
display_info_table(temp_buffer,FALSE,¤t_authdata);
if(query_type==FIND_HOST || query_type==FIND_SERVICE){
printf("
| \n");
/* middle column of top row */
printf("\n"); if(query_type==FIND_SERVICE){ snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s?%shost=%s&",NOTIFICATIONS_CGI,(use_lifo==FALSE)?"oldestfirst&":"",url_encode(query_host_name)); snprintf(temp_buffer2,sizeof(temp_buffer2)-1,"service=%s&type=%d&",url_encode(query_svc_description),notification_options); strncat(temp_buffer,temp_buffer2,sizeof(temp_buffer)-strlen(temp_buffer)-1); } else snprintf(temp_buffer,sizeof(temp_buffer)-1,"%s?%s%s=%s&type=%d&",NOTIFICATIONS_CGI,(use_lifo==FALSE)?"oldestfirst&":"",(query_type==FIND_HOST)?"host":"contact",(query_type==FIND_HOST)?url_encode(query_host_name):url_encode(query_contact_name),notification_options); temp_buffer[sizeof(temp_buffer)-1]='\x0'; display_nav_table(temp_buffer,log_archive); printf(" | \n"); /* right hand column of top row */ printf("\n");
printf(" | \n");
/* end of top table */
printf("
\n"); printf("
| Host | \n"); printf("Service | \n"); printf("Type | \n"); printf("Time | \n"); printf("Contact | \n"); printf("Notification Command | \n"); printf("Information | \n"); printf("|
|---|---|---|---|---|---|---|---|
| %s | \n",(odd)?"Even":"Odd",EXTINFO_CGI,DISPLAY_HOST_INFO,url_encode(host_name),host_name); if(notification_type==SERVICE_NOTIFICATION){ printf("%s | \n",url_encode(service_name),service_name); } else printf("N/A | \n",(odd)?"Even":"Odd"); printf("%s | \n",alert_level_class,alert_level); printf("%s | \n",(odd)?"Even":"Odd",date_time); printf("%s | \n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(contact_name),contact_name); printf("%s | \n",(odd)?"Even":"Odd",CONFIG_CGI,url_encode(method_name),method_name); printf("%s | \n",(odd)?"Even":"Odd",temp_buffer); printf("