/*********************************************************************** * * CONFIG.C - NetSaint Configuration CGI * * Copyright (c) 1999-2001 Ethan Galstad (netsaint@netsaint.org) * Last Modified: 05-23-2001 * * This CGI program will display various configuration information. * * * 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 "../common/objects.h" #include "getcgi.h" #include "cgiutils.h" #include "auth.h" extern char main_config_file[MAX_FILENAME_LENGTH]; extern char url_html_path[MAX_FILENAME_LENGTH]; extern char url_docs_path[MAX_FILENAME_LENGTH]; extern char url_images_path[MAX_FILENAME_LENGTH]; extern char url_stylesheets_path[MAX_FILENAME_LENGTH]; extern host *host_list; extern hostgroup *hostgroup_list; extern contactgroup *contactgroup_list; extern command *command_list; extern timeperiod *timeperiod_list; extern service *service_list; extern contact *contact_list; #define DISPLAY_NONE 0 #define DISPLAY_HOSTS 1 #define DISPLAY_HOSTGROUPS 2 #define DISPLAY_CONTACTS 3 #define DISPLAY_CONTACTGROUPS 4 #define DISPLAY_SERVICES 5 #define DISPLAY_TIMEPERIODS 6 #define DISPLAY_COMMANDS 7 void document_header(int); void document_footer(void); int process_cgivars(void); void display_options(void); void display_hosts(void); void display_hostgroups(void); void display_contacts(void); void display_contactgroups(void); void display_services(void); void display_timeperiods(void); void display_commands(void); void unauthorized_message(void); authdata current_authdata; int display_type=DISPLAY_NONE; int embedded=FALSE; int main(void){ int result=OK; /* 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"); display_info_table("Configuration",FALSE,¤t_authdata); printf(" | \n"); /* right hand column of top row */ printf("\n"); printf(" | \n"); /* end of top table */ printf("
| Host Name | "); printf("Alias/Description | "); printf("Address | "); printf("Parent Hosts | "); printf("Max. Check Attempts | "); printf("Notification Interval | "); printf("Notification Options | "); printf("Notification Period | "); printf("Host Check Command | "); printf("Event Handler | "); printf("
|---|---|---|---|---|---|---|---|---|---|
| %s | \n",bg_class,url_encode(temp_host->name),temp_host->name); printf("%s | \n",bg_class,temp_host->alias); printf("%s | \n",bg_class,temp_host->address); printf("",bg_class); for(temp_hostsmember=temp_host->parent_hosts;temp_hostsmember!=NULL;temp_hostsmember=temp_hostsmember->next){ if(temp_hostsmember!=temp_host->parent_hosts) printf(", "); printf("%s\n",CONFIG_CGI,url_encode(temp_hostsmember->host_name),temp_hostsmember->host_name); } if(temp_host->parent_hosts==NULL) printf(" "); printf(" | \n"); printf("%d | \n",bg_class,temp_host->max_attempts); get_interval_time_string(temp_host->notification_interval,time_string,sizeof(time_string)); printf("%s | \n",bg_class,(temp_host->notification_interval==0)?"No Re-notification":time_string); printf("",bg_class); options=0; if(temp_host->notify_on_down){ options=1; printf("Down",url_docs_path); } if(temp_host->notify_on_unreachable){ printf("%sUnreachable",(options)?", ":"",url_docs_path); options=1; } if(temp_host->notify_on_recovery){ printf("%sRecovery",(options)?", ":"",url_docs_path); options=1; } if(options==0) printf("None"); printf(" | \n"); printf("",bg_class); if(temp_host->notification_period==NULL) printf(" "); else printf("%s",CONFIG_CGI,url_encode(temp_host->notification_period),temp_host->notification_period); printf(" | \n"); printf("",bg_class); if(temp_host->host_check_command==NULL) printf(" "); else printf("%s | \n",CONFIG_CGI,url_encode(temp_host->host_check_command),temp_host->host_check_command); printf("\n"); printf("",bg_class); if(temp_host->event_handler==NULL) printf(" "); else printf("%s | \n",CONFIG_CGI,url_encode(temp_host->event_handler),temp_host->event_handler); printf("\n"); printf("
\n"); printf("
| Group Name | "); printf("Description | "); printf("Contact Groups | "); printf("Hosts | "); printf("
|---|---|---|---|
| %s | ",bg_class,temp_hostgroup->group_name); printf("%s | \n",bg_class,temp_hostgroup->alias); printf("",bg_class); /* find all the contact groups for this hostgroup... */ for(temp_contactgroupsmember=temp_hostgroup->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){ if(temp_contactgroupsmember!=temp_hostgroup->contact_groups) printf(", "); printf("%s\n",CONFIG_CGI,url_encode(temp_contactgroupsmember->group_name),temp_contactgroupsmember->group_name); } printf(" | \n"); printf("",bg_class); /* find all the hosts that are members of this hostgroup... */ for(temp_hostgroupmember=temp_hostgroup->members;temp_hostgroupmember!=NULL;temp_hostgroupmember=temp_hostgroupmember->next){ if(temp_hostgroupmember!=temp_hostgroup->members) printf(", "); printf("%s\n",CONFIG_CGI,url_encode(temp_hostgroupmember->host_name),temp_hostgroupmember->host_name); } printf(" | \n"); printf("
\n"); printf("
| Contact Name | "); printf("Alias | "); printf("Email Address | "); printf("Pager Address/Number | "); printf("Service Notification Options | "); printf("Host Notification Options | "); printf("Service Notification Period | "); printf("Host Notification Period | "); printf("Service Notification Commands | "); printf("Host Notification Commands | "); printf("
|---|---|---|---|---|---|---|---|---|---|
| %s | \n",bg_class,url_encode(temp_contact->name),temp_contact->name); printf("%s | \n",bg_class,temp_contact->alias); printf("%s | \n",bg_class,(temp_contact->email==NULL)?" ":temp_contact->email,(temp_contact->email==NULL)?" ":temp_contact->email); printf("%s | \n",bg_class,(temp_contact->pager==NULL)?" ":temp_contact->pager); printf("",bg_class); options=0; if(temp_contact->notify_on_service_unknown){ options=1; printf("Unknown",url_docs_path); } if(temp_contact->notify_on_service_warning){ printf("%sWarning",(options)?", ":"",url_docs_path); options=1; } if(temp_contact->notify_on_service_critical){ printf("%sCritical",(options)?", ":"",url_docs_path); options=1; } if(temp_contact->notify_on_service_recovery){ printf("%sRecovery",(options)?", ":"",url_docs_path); options=1; } if(!options) printf("None"); printf(" | \n"); printf("",bg_class); options=0; if(temp_contact->notify_on_host_down){ options=1; printf("Down",url_docs_path); } if(temp_contact->notify_on_host_unreachable){ printf("%sUnreachable",(options)?", ":"",url_docs_path); options=1; } if(temp_contact->notify_on_host_recovery){ printf("%sRecovery",(options)?", ":"",url_docs_path); options=1; } if(!options) printf("None"); printf(" | \n"); printf("%s | \n",bg_class,CONFIG_CGI,url_encode(temp_contact->service_notification_period),temp_contact->service_notification_period); printf("%s | \n",bg_class,CONFIG_CGI,url_encode(temp_contact->host_notification_period),temp_contact->host_notification_period); printf("",bg_class); for(temp_commandsmember=temp_contact->service_notification_commands;temp_commandsmember!=NULL;temp_commandsmember=temp_commandsmember->next){ if(temp_commandsmember!=temp_contact->service_notification_commands) printf(", "); printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); } printf(" | \n"); printf("",bg_class); for(temp_commandsmember=temp_contact->host_notification_commands;temp_commandsmember!=NULL;temp_commandsmember=temp_commandsmember->next){ if(temp_commandsmember!=temp_contact->host_notification_commands) printf(", "); printf("%s",CONFIG_CGI,url_encode(temp_commandsmember->command),temp_commandsmember->command); } printf(" | \n"); printf("
\n"); printf("
| Group Name | \n"); printf("Description | \n"); printf("Members | \n"); printf("
|---|---|---|
| %s | \n",bg_class,url_encode(temp_contactgroup->group_name),temp_contactgroup->group_name); printf("%s | \n",bg_class,temp_contactgroup->alias); /* find all the contact who are members of this contact group... */ printf("",bg_class); for(temp_contactgroupmember=temp_contactgroup->members;temp_contactgroupmember!=NULL;temp_contactgroupmember=temp_contactgroupmember->next){ if(temp_contactgroupmember!=temp_contactgroup->members) printf(", "); printf("%s\n",CONFIG_CGI,url_encode(temp_contactgroupmember->contact_name),temp_contactgroupmember->contact_name); } printf(" | \n"); printf("
\n"); printf("
| Host | \n"); printf("Service | \n"); printf("Volatile? | \n"); printf("Check Period | \n"); printf("Normal Check Interval | \n"); printf("Retry Check Interal | \n"); printf("Max. Check Attempts | \n"); printf("Parallelize? | \n"); printf("Contact Groups | \n"); printf("Notification Interval | \n"); printf("Notification Options | \n"); printf("Notification Period | \n"); printf("Event Handler | \n"); printf("Check Command | \n"); printf("
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ",url_encode(temp_service->description)); printf("%s | \n",CONFIG_CGI,url_encode(temp_service->host_name),temp_service->host_name); printf("%s | \n",bg_class,temp_service->description); printf("%s | \n",bg_class,(temp_service->is_volatile==TRUE)?"Yes":"No"); printf("",bg_class); if(temp_service->check_period==NULL) printf(" "); else printf("%s",CONFIG_CGI,url_encode(temp_service->check_period),temp_service->check_period); printf(" | \n"); get_interval_time_string(temp_service->check_interval,time_string,sizeof(time_string)); printf("%s | \n",bg_class,time_string); get_interval_time_string(temp_service->retry_interval,time_string,sizeof(time_string)); printf("%s | \n",bg_class,time_string); printf("%d | \n",bg_class,temp_service->max_attempts); printf("%s | \n",bg_class,(temp_service->parallelize==TRUE)?"Yes":"No"); printf("",bg_class); for(temp_contactgroupsmember=temp_service->contact_groups;temp_contactgroupsmember!=NULL;temp_contactgroupsmember=temp_contactgroupsmember->next){ if(temp_contactgroupsmember!=temp_service->contact_groups) printf(", "); printf("%s",CONFIG_CGI,url_encode(temp_contactgroupsmember->group_name),temp_contactgroupsmember->group_name); } if(temp_service->contact_groups==NULL) printf(" "); printf(" | \n"); get_interval_time_string(temp_service->notification_interval,time_string,sizeof(time_string)); printf("%s | \n",bg_class,(temp_service->notification_interval==0)?"No Re-notification":time_string); printf("",bg_class); options=0; if(temp_service->notify_on_unknown){ options=1; printf("Unknown",url_docs_path); } if(temp_service->notify_on_warning){ printf("%sWarning",(options)?", ":"",url_docs_path); options=1; } if(temp_service->notify_on_critical){ printf("%sCritical",(options)?", ":"",url_docs_path); options=1; } if(temp_service->notify_on_recovery){ printf("%sRecovery",(options)?", ":"",url_docs_path); options=1; } if(!options) printf("None"); printf(" | \n"); printf("",bg_class); if(temp_service->notification_period==NULL) printf(" "); else printf("%s",CONFIG_CGI,url_encode(temp_service->notification_period),temp_service->notification_period); printf(" | \n"); printf("",bg_class); if(temp_service->event_handler==NULL) printf(" "); else printf("%s",CONFIG_CGI,url_encode(temp_service->event_handler),temp_service->event_handler); printf(" | \n"); strncpy(command_line,temp_service->service_check_command,sizeof(command_line)); command_line[sizeof(command_line)-1]='\x0'; command_name=strtok(command_line,"!"); printf("%s | \n",bg_class,CONFIG_CGI,url_encode(command_name),temp_service->service_check_command); printf("
\n"); printf("
| Name | \n"); printf("Alias/Description | \n"); printf("Sunday Time Ranges | \n"); printf("Monday Time Ranges | \n"); printf("Tuesday Time Ranges | \n"); printf("Wednesday Time Ranges | \n"); printf("Thursday Time Ranges | \n"); printf("Friday Time Ranges | \n"); printf("Saturday Time Ranges | \n"); printf("
|---|---|---|---|---|---|---|---|---|
| %s | \n",bg_class,url_encode(temp_timeperiod->name),temp_timeperiod->name); printf("%s | \n",bg_class,temp_timeperiod->alias); for(day=0;day<7;day++){ printf("",bg_class); for(temp_timerange=temp_timeperiod->days[day];temp_timerange!=NULL;temp_timerange=temp_timerange->next){ if(temp_timerange!=temp_timeperiod->days[day]) printf(", "); hours=temp_timerange->range_start/3600; minutes=(temp_timerange->range_start-(hours*3600))/60; seconds=temp_timerange->range_start-(hours*3600)-(minutes*60); snprintf(timestring,sizeof(timestring)-1,"%02d:%02d:%02d",hours,minutes,seconds); timestring[sizeof(timestring)-1]='\x0'; printf("%s - ",timestring); hours=temp_timerange->range_end/3600; minutes=(temp_timerange->range_end-(hours*3600))/60; seconds=temp_timerange->range_end-(hours*3600)-(minutes*60); snprintf(timestring,sizeof(timestring)-1,"%02d:%02d:%02d",hours,minutes,seconds); timestring[sizeof(timestring)-1]='\x0'; printf("%s",timestring); } if(temp_timeperiod->days[day]==NULL) printf(" "); printf(" | \n"); } printf("