/**************************************************************************
*
* CMD.C - NetSaint Command CGI
*
* Copyright (c) 1999-2001 Ethan Galstad (netsaint@netsaint.org)
* Last Modified: 06-20-2001
*
* License:
*
* 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 "../common/comments.h"
#include "cgiutils.h"
#include "getcgi.h"
#include "auth.h"
extern char main_config_file[MAX_FILENAME_LENGTH];
extern char command_file[MAX_FILENAME_LENGTH];
extern char comment_file[MAX_FILENAME_LENGTH];
extern char url_stylesheets_path[MAX_FILENAME_LENGTH];
extern int netsaint_process_state;
extern int check_external_commands;
extern int use_authentication;
extern comment *comment_list;
extern host *host_list;
/* don't commit any commands for processing while in demo mode... */
/*#define DEMO_MODE*/
#define MAX_AUTHOR_LENGTH 64
#define MAX_COMMENT_LENGTH 1024
#define HTML_CONTENT 0
#define WML_CONTENT 1
char *host_name="";
char *hostgroup_name="";
char *service_desc="";
char *comment_author="";
char *comment_data="";
int comment_id=0;
int notification_delay=0;
int schedule_delay=0;
int persistent_comment=FALSE;
int send_notification=FALSE;
int force_check=FALSE;
int plugin_state=STATE_OK;
char plugin_output[MAX_INPUT_BUFFER]="";
time_t start_time=0L;
time_t end_time=0L;
int affect_host_and_services=FALSE;
int cancel_active=FALSE;
int cancel_pending=FALSE;
int command_type=CMD_NONE;
int command_mode=CMDMODE_REQUEST;
int content_type=HTML_CONTENT;
int display_header=TRUE;
authdata current_authdata;
void show_command_help(int);
void request_command_data(int);
void commit_command_data(int);
int commit_command(int);
int commit_hostgroup_command(int);
int write_command_to_file(char *);
void clean_comment_data(char *);
void document_header(int);
void document_footer(void);
int process_cgivars(void);
int time_to_string(time_t *,char *,int);
int string_to_time(char *,time_t *);
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);
if(content_type==WML_CONTENT)
printf("
Error: Could not open CGI config file!
\n");
else
printf("
Error: Could not open CGI configuration file '%s' for reading!
\n",DEFAULT_CGI_CONFIG_FILE);
document_footer();
return ERROR;
}
document_header(TRUE);
/* read the main configuration file */
result=read_main_config_file(main_config_file);
if(result==ERROR){
if(content_type==WML_CONTENT)
printf("
Error: Could not open main config file!
\n");
else
printf("
Error: Could not open main configuration file '%s' for reading!
\n",main_config_file);
document_footer();
return ERROR;
}
/* read all object configuration data */
result=read_all_object_configuration_data(main_config_file,READ_HOSTGROUPS|READ_CONTACTGROUPS|READ_HOSTS|READ_SERVICES);
if(result==ERROR){
if(content_type==WML_CONTENT)
printf("
Error: Could not read object config data!
\n");
else
printf("
Error: Could not read some or all object configuration data!
\n");
document_footer();
return ERROR;
}
/* get authentication information */
get_authentication_information(¤t_authdata);
if(display_header==TRUE){
/* begin top table */
printf("
\n");
}
/* if no command was specified... */
if(command_type==CMD_NONE){
if(content_type==WML_CONTENT)
printf("
Error: No command specified!
\n");
else
printf("
Error: No command was specified
\n");
}
/* if this is the first request for a command, present option */
else if(command_mode==CMDMODE_REQUEST)
request_command_data(command_type);
/* the user wants to commit the command */
else if(command_mode==CMDMODE_COMMIT)
commit_command_data(command_type);
document_footer();
/* free allocated memory */
free_memory();
free_object_data();
return OK;
}
void document_header(int use_stylesheet){
if(content_type==WML_CONTENT){
printf("Content-type: text/vnd.wap.wml\n\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
}
else{
printf("Content-type: text/html\r\n\r\n");
printf("\n");
printf("\n");
printf("\n");
printf("External Command Interface\n");
printf("\n");
if(use_stylesheet==TRUE)
printf("\n",url_stylesheets_path,COMMAND_CSS);
printf("\n");
printf("\n");
}
return;
}
void document_footer(void){
if(content_type==WML_CONTENT){
printf("\n");
printf("\n");
}
else{
printf("\n");
printf("\n");
}
return;
}
int process_cgivars(void){
char **variables;
int error=FALSE;
int x;
variables=getcgivars();
for(x=0;variables[x]!=NULL;x++){
/* do some basic length checking on the variable identifier to prevent buffer overflows */
if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){
x++;
continue;
}
/* we found the command type */
else if(!strcmp(variables[x],"cmd_typ")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
command_type=atoi(variables[x]);
}
/* we found the command mode */
else if(!strcmp(variables[x],"cmd_mod")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
command_mode=atoi(variables[x]);
}
/* we found the comment id */
else if(!strcmp(variables[x],"com_id")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
comment_id=atoi(variables[x]);
}
/* we found the notification delay */
else if(!strcmp(variables[x],"not_dly")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
notification_delay=atoi(variables[x]);
}
/* we found the schedule delay */
else if(!strcmp(variables[x],"sched_dly")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
schedule_delay=atoi(variables[x]);
}
/* we found the comment author */
else if(!strcmp(variables[x],"com_author")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
comment_author=(char *)malloc(strlen(variables[x])+1);
if(comment_author==NULL)
comment_author="";
else
strcpy(comment_author,variables[x]);
}
/* we found the comment data */
else if(!strcmp(variables[x],"com_data")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
comment_data=(char *)malloc(strlen(variables[x])+1);
if(comment_data==NULL)
comment_data="";
else
strcpy(comment_data,variables[x]);
}
/* we found the host name */
else if(!strcmp(variables[x],"host")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
host_name=(char *)malloc(strlen(variables[x])+1);
if(host_name==NULL)
host_name="";
else
strcpy(host_name,variables[x]);
}
/* we found the hostgroup name */
else if(!strcmp(variables[x],"hostgroup")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
hostgroup_name=(char *)malloc(strlen(variables[x])+1);
if(hostgroup_name==NULL)
hostgroup_name="";
else
strcpy(hostgroup_name,variables[x]);
}
/* we found the service name */
else if(!strcmp(variables[x],"service")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
service_desc=(char *)malloc(strlen(variables[x])+1);
if(service_desc==NULL)
service_desc="";
else
strcpy(service_desc,variables[x]);
}
/* we got the persistence option for a comment */
else if(!strcmp(variables[x],"persistent"))
persistent_comment=TRUE;
/* we got the notification option for an acknowledgement */
else if(!strcmp(variables[x],"send_notification"))
send_notification=TRUE;
/* we got the service check force option */
else if(!strcmp(variables[x],"force_check"))
force_check=TRUE;
/* we got the option to affect host and all its services */
else if(!strcmp(variables[x],"ahas"))
affect_host_and_services=TRUE;
/* we got the option to cancel active downtime */
else if(!strcmp(variables[x],"cancel_active"))
cancel_active=TRUE;
/* we got the option to cancel pending downtime */
else if(!strcmp(variables[x],"cancel_pending"))
cancel_pending=TRUE;
/* we found the plugin output */
else if(!strcmp(variables[x],"plugin_output")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
/* protect against buffer overflows */
if(strlen(variables[x])>=MAX_INPUT_BUFFER-1){
error=TRUE;
break;
}
else
strcpy(plugin_output,variables[x]);
}
/* we found the plugin state */
else if(!strcmp(variables[x],"plugin_state")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
plugin_state=atoi(variables[x]);
}
/* we found the start time */
else if(!strcmp(variables[x],"start_time")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
string_to_time(variables[x],&start_time);
}
/* we found the end time */
else if(!strcmp(variables[x],"end_time")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
string_to_time(variables[x],&end_time);
}
/* we found the content type argument */
else if(!strcmp(variables[x],"content")){
x++;
if(variables[x]==NULL){
error=TRUE;
break;
}
if(!strcmp(variables[x],"wml")){
content_type=WML_CONTENT;
display_header=FALSE;
}
else
content_type=HTML_CONTENT;
}
}
return error;
}
void request_command_data(int cmd){
time_t t;
char buffer[MAX_INPUT_BUFFER];
contact *temp_contact;
/* get default name to use for comment author */
temp_contact=find_contact(current_authdata.username,NULL);
if(temp_contact!=NULL && temp_contact->alias!=NULL)
comment_author=temp_contact->alias;
else
comment_author=current_authdata.username;
printf("
You are requesting to ");
switch(cmd){
case CMD_ADD_HOST_COMMENT:
case CMD_ADD_SVC_COMMENT:
printf("add a %s comment",(cmd==CMD_ADD_HOST_COMMENT)?"host":"service");
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
printf("delete a %s comment",(cmd==CMD_DEL_HOST_COMMENT)?"host":"service");
break;
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_DELAY_SVC_NOTIFICATION:
printf("delay a %s notification",(cmd==CMD_DELAY_HOST_NOTIFICATION)?"host":"service");
break;
case CMD_DELAY_SVC_CHECK:
printf("delay a service check");
break;
case CMD_IMMEDIATE_SVC_CHECK:
printf("schedule an immediate service check");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
printf("%s checks of a particular service",(cmd==CMD_ENABLE_SVC_CHECK)?"enable":"disable");
break;
case CMD_ENTER_STANDBY_MODE:
case CMD_ENTER_ACTIVE_MODE:
printf("enter %s mode",(cmd==CMD_ENTER_STANDBY_MODE)?"STANDBY":"ACTIVE");
break;
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
printf("%s the NetSaint process",(cmd==CMD_SHUTDOWN_PROCESS)?"shutdown":"restart");
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
printf("%s checks of all services on a host",(cmd==CMD_ENABLE_HOST_SVC_CHECKS)?"enable":"disable");
break;
case CMD_DELAY_HOST_SVC_CHECKS:
printf("delay all service checks for a host");
break;
case CMD_IMMEDIATE_HOST_SVC_CHECKS:
printf("schedule an immediate check of all services for a host");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_DEL_ALL_SVC_COMMENTS:
printf("delete all comments for a %s",(cmd==CMD_DEL_ALL_HOST_COMMENTS)?"host":"service");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
printf("%s notifications for a service",(cmd==CMD_ENABLE_SVC_NOTIFICATIONS)?"enable":"disable");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
printf("%s notifications for a host",(cmd==CMD_ENABLE_HOST_NOTIFICATIONS)?"enable":"disable");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("%s notifications for all hosts and services beyond a host",(cmd==CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST)?"enable":"disable");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
printf("%s notifications for all services on a host",(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"enable":"disable");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
printf("acknowledge a %s problem",(cmd==CMD_ACKNOWLEDGE_HOST_PROBLEM)?"host":"service");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
printf("%s executing service checks",(cmd==CMD_START_EXECUTING_SVC_CHECKS)?"start":"stop");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("%s accepting passive service checks",(cmd==CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS)?"start":"stop");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
printf("%s accepting passive service checks for a particular service",(cmd==CMD_ENABLE_PASSIVE_SVC_CHECKS)?"start":"stop");
break;
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
printf("%s event handlers",(cmd==CMD_ENABLE_EVENT_HANDLERS)?"enable":"disable");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
printf("%s the event handler for a particular host",(cmd==CMD_ENABLE_HOST_EVENT_HANDLER)?"enable":"disable");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
printf("%s the event handler for a particular service",(cmd==CMD_ENABLE_SVC_EVENT_HANDLER)?"enable":"disable");
break;
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
printf("%s checks of a particular host",(cmd==CMD_ENABLE_HOST_CHECK)?"enable":"disable");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
printf("%s obsessing over service checks",(cmd==CMD_STOP_OBSESSING_OVER_SVC_CHECKS)?"stop":"start");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
printf("remove a %s acknowledgement",(cmd==CMD_REMOVE_HOST_ACKNOWLEDGEMENT)?"host":"service");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("schedule downtime for a particular %s",(cmd==CMD_SCHEDULE_HOST_DOWNTIME)?"host":"service");
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("submit a passive check result for a particular service");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
printf("%s flap detection for a particular host",(cmd==CMD_ENABLE_HOST_FLAP_DETECTION)?"enable":"disable");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
printf("%s flap detection for a particular service",(cmd==CMD_ENABLE_SVC_FLAP_DETECTION)?"enable":"disable");
break;
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
printf("%s flap detection for hosts and services",(cmd==CMD_ENABLE_FLAP_DETECTION)?"enable":"disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("%s notifications for all services in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"enable":"disable");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("%s notifications for all hosts in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS)?"enable":"disable");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("%s checks of all services in a particular hostgroup",(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS)?"enable":"disable");
break;
case CMD_CANCEL_HOST_DOWNTIME:
case CMD_CANCEL_SVC_DOWNTIME:
printf("cancel scheduled downtime for a particular %s",(cmd==CMD_CANCEL_HOST_DOWNTIME)?"host":"service");
break;
default:
printf("execute an unknown command. Shame on you!
");
return;
}
printf("\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
Command Options
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n",COMMAND_CGI,cmd,CMDMODE_COMMIT);
switch(cmd){
case CMD_ADD_HOST_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
printf("
\n");
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
printf("
Host Name:
");
printf("",host_name);
printf("
\n");
printf("
Service:
");
printf("",service_desc);
printf("
\n");
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
printf("
\n");
}
break;
case CMD_ENTER_STANDBY_MODE:
case CMD_ENTER_ACTIVE_MODE:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
printf("
Execution Delay (minutes from now):
");
printf("",schedule_delay);
printf("
\n");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
printf("
There are no options for this command. Click the 'Commit' button to submit the command.
");
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("
Host Name:
");
printf("",host_name);
printf("
\n");
printf("
Service:
");
printf("",service_desc);
printf("
\n");
printf("
Check Result:
");
printf("\n");
printf("
\n");
printf("
Check Output:
");
printf("");
printf("
\n");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("
\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("
\n");
}
break;
case CMD_CANCEL_HOST_DOWNTIME:
case CMD_CANCEL_SVC_DOWNTIME:
printf("
Host Name:
");
printf("",host_name);
printf("
\n");
if(cmd==CMD_CANCEL_SVC_DOWNTIME){
printf("
Service:
");
printf("",service_desc);
}
printf("
Cancel active downtime:
");
printf("");
printf("
\n");
printf("
Cancel pending downtime:
");
printf("");
printf("
\n");
break;
default:
printf("
This should not be happening... :-(
\n");
}
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
/* show information about the command... */
show_command_help(cmd);
printf("
\n");
printf("
\n");
printf("
\n");
printf("
\n");
printf("\n");
printf("
Please enter all required information before committing the command. Required fields are marked in red. Failure to supply all required values will result in an error.
");
return;
}
void commit_command_data(int cmd){
int error=TRUE;
int result=OK;
int authorized=FALSE;
service *temp_service;
host *temp_host;
hostgroup *temp_hostgroup;
comment *temp_comment;
#ifdef DEMO_MODE
/* demo protection */
printf("
Sorry, but commands cannot be committed in demo mode!
\n");
return;
#endif
/* get authentication information */
get_authentication_information(¤t_authdata);
switch(cmd){
case CMD_ADD_HOST_COMMENT:
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
/* make sure we have some host name, author name, and comment data... */
if(strcmp(host_name,"") && strcmp(comment_author,"") && strcmp(comment_data,""))
error=FALSE;
else
error=TRUE;
/* clean up the comment data */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
/* see if the user is authorized to issue a command... */
temp_host=find_host(host_name,NULL);
if(is_authorized_for_host_commands(temp_host,¤t_authdata)==TRUE)
authorized=TRUE;
break;
case CMD_ADD_SVC_COMMENT:
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
/* make sure we have some host name and service description, author name, and comment data... */
if(strcmp(host_name,"") && strcmp(service_desc,"") && strcmp(comment_author,"") && strcmp(comment_data,""))
error=FALSE;
else
error=TRUE;
/* clean up the comment data */
clean_comment_data(comment_author);
clean_comment_data(comment_data);
/* see if the user is authorized to issue a command... */
temp_service=find_service(host_name,service_desc,NULL);
if(is_authorized_for_service_commands(temp_service,¤t_authdata)==TRUE)
authorized=TRUE;
break;
case CMD_DEL_HOST_COMMENT:
case CMD_DEL_SVC_COMMENT:
if(comment_id>0)
error=FALSE;
else
error=TRUE;
/* read comments */
read_comment_data(DEFAULT_CGI_CONFIG_FILE);
/* find the comment */
if(cmd==CMD_DEL_HOST_COMMENT)
temp_comment=find_host_comment(comment_id);
else
temp_comment=find_service_comment(comment_id);
/* see if the user is authorized to issue a command... */
if(cmd==CMD_DEL_HOST_COMMENT && temp_comment!=NULL){
temp_host=find_host(temp_comment->host_name,NULL);
if(is_authorized_for_host_commands(temp_host,¤t_authdata)==TRUE)
authorized=TRUE;
}
if(cmd==CMD_DEL_SVC_COMMENT && temp_comment!=NULL){
temp_service=find_service(temp_comment->host_name,temp_comment->service_description,NULL);
if(is_authorized_for_service_commands(temp_service,¤t_authdata)==TRUE)
authorized=TRUE;
}
/* free comment data */
free_comment_data();
break;
case CMD_DELAY_SVC_CHECK:
case CMD_IMMEDIATE_SVC_CHECK:
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
case CMD_DEL_ALL_SVC_COMMENTS:
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
case CMD_PROCESS_SERVICE_CHECK_RESULT:
case CMD_SCHEDULE_SVC_DOWNTIME:
case CMD_DELAY_SVC_NOTIFICATION:
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
case CMD_CANCEL_SVC_DOWNTIME:
/* make sure we have some host name and service description... */
if(strcmp(host_name,"") && strcmp(service_desc,""))
error=FALSE;
else
error=TRUE;
/* see if the user is authorized to issue a command... */
temp_service=find_service(host_name,service_desc,NULL);
if(is_authorized_for_service_commands(temp_service,¤t_authdata)==TRUE)
authorized=TRUE;
/* make sure we have passive check info (if necessary) */
if(cmd==CMD_PROCESS_SERVICE_CHECK_RESULT && !strcmp(plugin_output,""))
error=TRUE;
/* make sure we have a notification delay (if necessary) */
if(cmd==CMD_DELAY_SVC_NOTIFICATION && notification_delay<=0)
error=TRUE;
/* make sure we have start/end times for downtime (if necessary) */
if(cmd==CMD_SCHEDULE_SVC_DOWNTIME && (start_time<=0L || end_time<=0L))
error=TRUE;
/* make sure we have some type of downtime to cancel */
if(cmd==CMD_CANCEL_SVC_DOWNTIME && cancel_active==FALSE && cancel_pending==FALSE)
error=TRUE;
break;
case CMD_ENTER_STANDBY_MODE:
case CMD_ENTER_ACTIVE_MODE:
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
error=FALSE;
/* see if the user is authorized to issue a command... */
if(is_authorized_for_system_commands(¤t_authdata)==TRUE)
authorized=TRUE;
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
case CMD_DEL_ALL_HOST_COMMENTS:
case CMD_IMMEDIATE_HOST_SVC_CHECKS:
case CMD_DELAY_HOST_SVC_CHECKS:
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
case CMD_SCHEDULE_HOST_DOWNTIME:
case CMD_DELAY_HOST_NOTIFICATION:
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
case CMD_CANCEL_HOST_DOWNTIME:
/* make sure we have some host name... */
if(strcmp(host_name,""))
error=FALSE;
else
error=TRUE;
/* see if the user is authorized to issue a command... */
temp_host=find_host(host_name,NULL);
if(is_authorized_for_host_commands(temp_host,¤t_authdata)==TRUE)
authorized=TRUE;
/* make sure we have a notification delay (if necessary) */
if(cmd==CMD_DELAY_HOST_NOTIFICATION && notification_delay<=0)
error=TRUE;
/* make sure we have start/end times for downtime (if necessary) */
if(cmd==CMD_SCHEDULE_HOST_DOWNTIME && (start_time<=0L || end_time<=0L))
error=TRUE;
/* make sure we have some type of downtime to cancel */
if(cmd==CMD_CANCEL_HOST_DOWNTIME && cancel_active==FALSE && cancel_pending==FALSE)
error=TRUE;
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
/* make sure we have some hostgroup name... */
if(strcmp(hostgroup_name,""))
error=FALSE;
else
error=TRUE;
/* see if the user is authorized to issue a command... */
temp_hostgroup=find_hostgroup(hostgroup_name,NULL);
if(is_authorized_for_hostgroup(temp_hostgroup,¤t_authdata)==TRUE)
authorized=TRUE;
break;
default:
error=TRUE;
}
/* to be safe, we are going to REQUIRE that the authentication functionality is enabled... */
if(use_authentication==FALSE){
if(content_type==WML_CONTENT)
printf("
Error: Authentication is not enabled!
\n");
else{
printf("
\n");
printf("
Sorry Dave, I can't let you do that...
");
printf("
");
printf("It seems that you have chosen to not use the authentication functionality of the CGIs.
");
printf("I don't want to be personally responsible for what may happen as a result of allowing unauthorized users to issue commands to NetSaint,");
printf("so you'll have to disable this safeguard if you are really stubborn and want to invite trouble...
");
printf("Read the section on CGI authentication in the HTML documentation to learn how you can enable authentication and why you should want to.\n");
printf("
\n");
printf("\n");
}
}
/* the user is not authorized to issue the given command */
else if(authorized==FALSE){
if(content_type==WML_CONTENT)
printf("
Error: You're not authorized to commit that command!
\n");
else{
printf("
Sorry, but you are not authorized to commit the specified command...
\n");
printf("
Read the section of the docs that deals with authentication and authorization in the CGIs for more information...
\n");
}
}
}
return;
}
/* commits a command for processing */
int commit_command(int cmd){
char command_buffer[MAX_INPUT_BUFFER];
time_t current_time;
time_t scheduled_time;
time_t notification_time;
int result;
/* get the current time */
time(¤t_time);
/* get the scheduled time */
scheduled_time=current_time+(schedule_delay*60);
/* get the notification time */
notification_time=current_time+(notification_delay*60);
/* decide how to form the command line... */
switch(cmd){
case CMD_ADD_HOST_COMMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ADD_HOST_COMMENT;%s;%d;%s;%s\n",current_time,host_name,(persistent_comment==TRUE)?1:0,comment_author,comment_data);
break;
case CMD_ADD_SVC_COMMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ADD_SVC_COMMENT;%s;%s;%d;%s;%s\n",current_time,host_name,service_desc,(persistent_comment==TRUE)?1:0,comment_author,comment_data);
break;
case CMD_DEL_HOST_COMMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DEL_HOST_COMMENT;%d\n",current_time,comment_id);
break;
case CMD_DEL_SVC_COMMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DEL_SVC_COMMENT;%d\n",current_time,comment_id);
break;
case CMD_DELAY_HOST_NOTIFICATION:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DELAY_HOST_NOTIFICATION;%s;%lu\n",current_time,host_name,notification_time);
break;
case CMD_DELAY_SVC_NOTIFICATION:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DELAY_SVC_NOTIFICATION;%s;%s;%lu\n",current_time,host_name,service_desc,notification_time);
break;
case CMD_IMMEDIATE_SVC_CHECK:
case CMD_DELAY_SVC_CHECK:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] SCHEDULE_%sSVC_CHECK;%s;%s;%lu\n",current_time,(force_check==TRUE)?"FORCED_":"",host_name,service_desc,(cmd==CMD_IMMEDIATE_SVC_CHECK)?current_time:scheduled_time);
break;
case CMD_ENABLE_SVC_CHECK:
case CMD_DISABLE_SVC_CHECK:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_SVC_CHECK;%s;%s\n",current_time,(cmd==CMD_ENABLE_SVC_CHECK)?"ENABLE":"DISABLE",host_name,service_desc);
break;
case CMD_ENTER_STANDBY_MODE:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ENTER_STANDBY_MODE;%lu\n",current_time,scheduled_time);
break;
case CMD_ENTER_ACTIVE_MODE:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ENTER_ACTIVE_MODE;%lu\n",current_time,scheduled_time);
break;
case CMD_SHUTDOWN_PROCESS:
case CMD_RESTART_PROCESS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_PROGRAM;%lu\n",current_time,(cmd==CMD_SHUTDOWN_PROCESS)?"SHUTDOWN":"RESTART",scheduled_time);
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
case CMD_DISABLE_HOST_SVC_CHECKS:
if(affect_host_and_services==FALSE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_CHECKS;%s\n",current_time,(cmd==CMD_ENABLE_HOST_SVC_CHECKS)?"ENABLE":"DISABLE",host_name);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_CHECKS;%s\n[%lu] %s_HOST_CHECK;%s\n",current_time,(cmd==CMD_ENABLE_HOST_SVC_CHECKS)?"ENABLE":"DISABLE",host_name,current_time,(cmd==CMD_ENABLE_HOST_SVC_CHECKS)?"ENABLE":"DISABLE",host_name);
break;
case CMD_DELAY_HOST_SVC_CHECKS:
case CMD_IMMEDIATE_HOST_SVC_CHECKS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] SCHEDULE_%sHOST_SVC_CHECKS;%s;%lu\n",current_time,(force_check==TRUE)?"FORCED_":"",host_name,(cmd==CMD_IMMEDIATE_HOST_SVC_CHECKS)?current_time:scheduled_time);
break;
case CMD_DEL_ALL_HOST_COMMENTS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DEL_ALL_HOST_COMMENTS;%s\n",current_time,host_name);
break;
case CMD_DEL_ALL_SVC_COMMENTS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] DEL_ALL_SVC_COMMENTS;%s;%s\n",current_time,host_name,service_desc);
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
case CMD_DISABLE_SVC_NOTIFICATIONS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_SVC_NOTIFICATIONS;%s;%s\n",current_time,(cmd==CMD_ENABLE_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",host_name,service_desc);
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOST_NOTIFICATIONS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOST_NOTIFICATIONS)?"ENABLE":"DISABLE",host_name);
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_ALL_NOTIFICATIONS_BEYOND_HOST;%s\n",current_time,(cmd==CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST)?"ENABLE":"DISABLE",host_name);
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
if(affect_host_and_services==FALSE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",host_name);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_NOTIFICATIONS;%s\n[%lu] %s_HOST_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",host_name,current_time,(cmd==CMD_ENABLE_HOST_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",host_name);
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ADD_HOST_COMMENT;%s;%d;%s;ACKNOWLEDGEMENT: %s\n[%lu] ACKNOWLEDGE_HOST_PROBLEM;%s;%d;%s\n",current_time,host_name,(persistent_comment==TRUE)?1:0,comment_author,comment_data,current_time,host_name,(send_notification==TRUE)?1:0,comment_data);
break;
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] ADD_SVC_COMMENT;%s;%s;%d;%s;ACKNOWLEDGEMENT: %s\n[%lu] ACKNOWLEDGE_SVC_PROBLEM;%s;%s;%d;%s\n",current_time,host_name,service_desc,(persistent_comment==TRUE)?1:0,comment_author,comment_data,current_time,host_name,service_desc,(send_notification==TRUE)?1:0,comment_data);
break;
case CMD_START_EXECUTING_SVC_CHECKS:
case CMD_STOP_EXECUTING_SVC_CHECKS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_EXECUTING_SVC_CHECKS;\n",current_time,(cmd==CMD_START_EXECUTING_SVC_CHECKS)?"START":"STOP");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_ACCEPTING_PASSIVE_SVC_CHECKS;\n",current_time,(cmd==CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS)?"START":"STOP");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_PASSIVE_SVC_CHECKS;%s;%s\n",current_time,(cmd==CMD_ENABLE_PASSIVE_SVC_CHECKS)?"ENABLE":"DISABLE",host_name,service_desc);
break;
case CMD_ENABLE_EVENT_HANDLERS:
case CMD_DISABLE_EVENT_HANDLERS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_EVENT_HANDLERS;\n",current_time,(cmd==CMD_ENABLE_EVENT_HANDLERS)?"ENABLE":"DISABLE");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
case CMD_DISABLE_SVC_EVENT_HANDLER:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_SVC_EVENT_HANDLER;%s;%s\n",current_time,(cmd==CMD_ENABLE_SVC_EVENT_HANDLER)?"ENABLE":"DISABLE",host_name,service_desc);
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
case CMD_DISABLE_HOST_EVENT_HANDLER:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_EVENT_HANDLER;%s\n",current_time,(cmd==CMD_ENABLE_HOST_EVENT_HANDLER)?"ENABLE":"DISABLE",host_name);
break;
case CMD_ENABLE_HOST_CHECK:
case CMD_DISABLE_HOST_CHECK:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_CHECK;%s\n",current_time,(cmd==CMD_ENABLE_HOST_CHECK)?"ENABLE":"DISABLE",host_name);
break;
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_OBSESSING_OVER_SVC_CHECKS;\n",current_time,(cmd==CMD_START_OBSESSING_OVER_SVC_CHECKS)?"START":"STOP");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] REMOVE_HOST_ACKNOWLEDGEMENT;%s\n",current_time,host_name);
break;
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] REMOVE_SVC_ACKNOWLEDGEMENT;%s;%s\n",current_time,host_name,service_desc);
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n",current_time,host_name,service_desc,plugin_state,plugin_output);
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] SCHEDULE_HOST_DOWNTIME;%s;%lu;%lu\n",current_time,host_name,start_time,end_time);
break;
case CMD_SCHEDULE_SVC_DOWNTIME:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] SCHEDULE_SVC_DOWNTIME;%s;%s;%lu;%lu\n",current_time,host_name,service_desc,start_time,end_time);
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
case CMD_DISABLE_HOST_FLAP_DETECTION:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_FLAP_DETECTION;%s\n",current_time,(cmd==CMD_ENABLE_HOST_FLAP_DETECTION)?"ENABLE":"DISABLE",host_name);
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
case CMD_DISABLE_SVC_FLAP_DETECTION:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_SVC_FLAP_DETECTION;%s;%s\n",current_time,(cmd==CMD_ENABLE_SVC_FLAP_DETECTION)?"ENABLE":"DISABLE",host_name,service_desc);
break;
case CMD_ENABLE_FLAP_DETECTION:
case CMD_DISABLE_FLAP_DETECTION:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_FLAP_DETECTION\n",current_time,(cmd==CMD_ENABLE_FLAP_DETECTION)?"ENABLE":"DISABLE");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
result=commit_hostgroup_command(cmd);
return result;
break;
case CMD_CANCEL_HOST_DOWNTIME:
if(cancel_active==TRUE && cancel_pending==TRUE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] CANCEL_ACTIVE_HOST_DOWNTIME;%s\n[%lu] CANCEL_PENDING_HOST_DOWNTIME;%s\n",current_time,host_name,current_time,host_name);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] CANCEL_%s_HOST_DOWNTIME;%s\n",current_time,(cancel_active==TRUE)?"ACTIVE":"PENDING",host_name);
break;
case CMD_CANCEL_SVC_DOWNTIME:
if(cancel_active==TRUE && cancel_pending==TRUE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] CANCEL_ACTIVE_SVC_DOWNTIME;%s;%s\n[%lu] CANCEL_PENDING_SVC_DOWNTIME;%s;%s\n",current_time,host_name,service_desc,current_time,host_name,service_desc);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] CANCEL_%s_SVC_DOWNTIME;%s;%s\n",current_time,(cancel_active==TRUE)?"ACTIVE":"PENDING",host_name,service_desc);
break;
default:
return ERROR;
}
/* make sure command buffer is terminated */
command_buffer[sizeof(command_buffer)-1]='\x0';
/* write the command to the command file */
result=write_command_to_file(command_buffer);
return result;
}
/* commits one or more hostgroup commands for processing */
int commit_hostgroup_command(int cmd){
hostgroup *temp_hostgroup=NULL;
host *temp_host=NULL;
char command_buffer[MAX_INPUT_BUFFER];
time_t current_time;
int result;
/* get the current time */
time(¤t_time);
/* find the hostgroup */
temp_hostgroup=find_hostgroup(hostgroup_name,NULL);
if(temp_hostgroup==NULL)
return ERROR;
/* find all hosts that belong to this hostgroup... */
for(temp_host=host_list;temp_host!=NULL;temp_host=temp_host->next){
/* skip this host if it's not part of the hostgroup */
if(is_host_member_of_hostgroup(temp_hostgroup,temp_host)==FALSE)
continue;
/* is the user authorized to issue command for this host? */
if(is_authorized_for_host_commands(temp_host,¤t_authdata)==FALSE)
continue;
/* blank the command line */
strcpy(command_buffer,"");
/* decide how to form the command line... */
switch(cmd){
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
if(affect_host_and_services==FALSE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",temp_host->name);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_NOTIFICATIONS;%s\n[%lu] %s_HOST_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",temp_host->name,current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS)?"ENABLE":"DISABLE",temp_host->name);
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_NOTIFICATIONS;%s\n",current_time,(cmd==CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS)?"ENABLE":"DISABLE",temp_host->name);
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
if(affect_host_and_services==FALSE)
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_CHECKS;%s\n",current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS)?"ENABLE":"DISABLE",temp_host->name);
else
snprintf(command_buffer,sizeof(command_buffer)-1,"[%lu] %s_HOST_SVC_CHECKS;%s\n[%lu] %s_HOST_CHECK;%s\n",current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS)?"ENABLE":"DISABLE",temp_host->name,current_time,(cmd==CMD_ENABLE_HOSTGROUP_SVC_CHECKS)?"ENABLE":"DISABLE",temp_host->name);
break;
default:
return ERROR;
}
/* make sure command buffer is terminated */
command_buffer[sizeof(command_buffer)-1]='\x0';
/* write the command to the command file */
result=write_command_to_file(command_buffer);
/* bail out if we encountered an error */
if(result!=OK)
return result;
}
return OK;
}
/* write a command entry to the command file */
int write_command_to_file(char *cmd){
FILE *fp;
/* open the command for writing (since this is a pipe, it will really be appended) */
fp=fopen(command_file,"w+");
if(fp==NULL){
if(content_type==WML_CONTENT)
printf("
Error: Could not open command file for update!
\n");
else{
printf("
Error: Could not open command file '%s' for update!
\n",command_file);
printf("
");
printf("The permissions on the external command file and/or directory may be incorrect. Read the FAQs on how to setup proper permissions.\n");
printf("
\n");
}
return ERROR;
}
/* write the command to file */
fputs(cmd,fp);
/* flush buffer */
fflush(fp);
fclose(fp);
return OK;
}
/* strips out semicolons from comment data */
void clean_comment_data(char *buffer){
int x;
int y;
y=(int)strlen(buffer);
for(x=0;xCommand Description\n");
printf("
\n");
printf("
\n");
/* decide what information to print out... */
switch(cmd){
case CMD_ADD_HOST_COMMENT:
printf("This command is used to add a comment for the specified host. If you work with other administrators, you may find it useful to share information about a host\n");
printf("that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will be automatically be deleted\n");
printf("the next time NetSaint is restarted.\n");
break;
case CMD_ADD_SVC_COMMENT:
printf("This command is used to add a comment for the specified service. If you work with other administrators, you may find it useful to share information about a host\n");
printf("or service that is having problems if more than one of you may be working on it. If you do not check the 'persistent' option, the comment will automatically be\n");
printf("deleted the next time NetSaint is restarted.\n");
break;
case CMD_DEL_HOST_COMMENT:
printf("This command is used to delete a specific host comment.\n");
break;
case CMD_DEL_SVC_COMMENT:
printf("This command is used to delete a specific service comment.\n");
break;
case CMD_DELAY_HOST_NOTIFICATION:
printf("This command is used to delay the next problem notification that is sent out for the specified host. The notification delay will be disregarded if\n");
printf("the host changes state before the next notification is scheduled to be sent out. This command has no effect if the host is currently UP.\n");
break;
case CMD_DELAY_SVC_NOTIFICATION:
printf("This command is used to delay the next problem notification that is sent out for the specified service. The notification delay will be disregarded if\n");
printf("the service changes state before the next notification is scheduled to be sent out. This command has no effect if the service is currently in an OK state.\n");
break;
case CMD_DELAY_SVC_CHECK:
printf("This command is used to delay the next scheduled check of the specified service. NetSaint will re-queue the service and will not not check it again until the number\n");
printf("of minutes you specified with the check delay option has elapsed from the time the command is committed. Specifying a value of 0 for the delay value\n");
printf("is equivalent to scheduling an immediate service check.\n");
break;
case CMD_IMMEDIATE_SVC_CHECK:
printf("This command will schedule an immediate check of the specified service. Note that the check is scheduled immediately, not necessary executed immediately. If NetSaint\n");
printf("has fallen behind in its scheduling queue, it will check services that were queued prior to this one.\n");
break;
case CMD_ENABLE_SVC_CHECK:
printf("This command is used to re-enable a service check that has been disabled. Once a service check is enabled, NetSaint will begin to monitor the service as usual. If the service\n");
printf("has recovered from a problem that was detected before the check was disabled, contacts might be notified of the recovery.\n");
break;
case CMD_DISABLE_SVC_CHECK:
printf("This command is used to disable a service check. When a service is disabled NetSaint will not monitor the service. Doing this will prevent any notifications being sent out for\n");
printf("the specified service while it is disabled. In order to have NetSaint check the service in the future you will have to re-enable the service.\n");
printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with.\n");
break;
case CMD_ENTER_STANDBY_MODE:
printf("This command is used to put NetSaint in standby mode. By supplying a non-zero value for the execution delay option you can schedule a delayed mode change.\n");
printf("Specifying a value of 0 for the delay will cause NetSaint to change modes immediately upon processing the request. In standby mode NetSaint will continue to monitor all hosts\n");
printf("and services that you have defined, but it will prevent any notifications from being sent out. Contrast this with active mode, where NetSaint sends out notifications when necessary.\n");
break;
case CMD_ENTER_ACTIVE_MODE:
printf("This command is used to put NetSaint in active mode. By supplying a non-zero value for the execution delay option you can schedule a delayed mode change.\n");
printf("Specifying a value of 0 for the delay will cause NetSaint to change modes immediately upon processing the request. In active mode NetSaint will send out notifications to contacts\n");
printf("if necessary. Contrast this with standby mode, where NetSaint will prevent any notifications from being sent to contacts.\n");
break;
case CMD_SHUTDOWN_PROCESS:
printf("This command is used to shutdown the NetSaint process. By supplying a non-zero value for the execution delay option you can schedule a delayed shutdown.\n");
printf("Specifying a value of 0 for the delay will cause NetSaint to shut down immediately upon processing the request. Note: Once the NetSaint has been shutdown, it\n");
printf("cannot be restarted via the web interface!\n");
break;
case CMD_RESTART_PROCESS:
printf("This command is used to restart the NetSaint process. By supplying a non-zero value for the execution delay variable you can schedule a delayed restart.\n");
printf("Specifying a value of 0 for the delay will cause NetSaint to restart immediately upon processing the request. Executing a restart command is equivalent to sending\n");
printf("the process a HUP signal. All information will be flushed from memory, the configuration files will be re-read, and NetSaint will start monitoring with the new configuration information.\n");
break;
case CMD_ENABLE_HOST_SVC_CHECKS:
printf("This command is used to enable all service checks associated with the specified host. This does not enable checks of the host unless you check the 'Enable for host too' option.\n");
break;
case CMD_DISABLE_HOST_SVC_CHECKS:
printf("This command is used to disable all service checks associated with the specified host. When a service is disabled NetSaint will not monitor the service. Doing this will prevent any notifications being sent out for\n");
printf("the specified service while it is disabled. In order to have NetSaint check the service in the future you will have to re-enable the service.\n");
printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with. This does not disable checks of the host unless you check the 'Disable for host too' option.\n");
break;
case CMD_DELAY_HOST_SVC_CHECKS:
printf("This command is used to delay the next scheduled check of all services on the specified host. NetSaint will re-queue the services and will not not check them again until the number\n");
printf("of minutes you specified with the check delay option has elapsed from the time the command is committed. Specifying a value of 0 for the delay value\n");
printf("is equivalent to scheduling an immediate check of all the services.\n");
break;
case CMD_IMMEDIATE_HOST_SVC_CHECKS:
printf("This command will schedule an immediate check of all service on the specified host. Note that the checks are scheduled immediately, not necessary executed immediately. If NetSaint\n");
printf("has fallen behind in its scheduling queue, it will check services that were queued prior to these services.\n");
break;
case CMD_DEL_ALL_HOST_COMMENTS:
printf("This command is used to delete all comments associated with the specified host.\n");
break;
case CMD_DEL_ALL_SVC_COMMENTS:
printf("This command is used to delete all comments associated with the specified service.\n");
break;
case CMD_ENABLE_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for the specified service. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definition.\n");
break;
case CMD_DISABLE_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for the specified service. You will have to re-enable notifications\n");
printf("for this service before any alerts can be sent out in the future.\n");
break;
case CMD_ENABLE_HOST_NOTIFICATIONS:
printf("This command is used to enable notifications for the specified host. Notifications will only be sent out for the\n");
printf("host state types you defined in your host definition. Note that this command does not enable notifications\n");
printf("for services associated with this host.\n");
break;
case CMD_DISABLE_HOST_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for the specified host. You will have to re-enable notifications for this host\n");
printf("before any alerts can be sent out in the future. Note that this command does not disable notifications for services associated with this host.\n");
break;
case CMD_ENABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("This command is used to enable notifications for all hosts and services that lie \"beyond\" the specified host\n");
printf("(from the view of NetSaint).\n");
break;
case CMD_DISABLE_ALL_NOTIFICATIONS_BEYOND_HOST:
printf("This command is used to temporarily prevent notifications from being sent out for all hosts and services that lie\n");
printf("\"beyone\" the specified host (from the view of NetSaint).\n");
break;
case CMD_ENABLE_HOST_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for all services on the specified host. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definition. This does not enable notifications for the host unless you check the 'Enable for host too' option.\n");
break;
case CMD_DISABLE_HOST_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all services on the specified host. You will have to re-enable notifications for\n");
printf("all services associated with this host before any alerts can be sent out in the future. This does not prevent notifications from being sent out about the host unless you check the 'Disable for host too' option.\n");
break;
case CMD_ACKNOWLEDGE_HOST_PROBLEM:
printf("This command is used to acknowledge a host problem. When a host problem is acknowledged, future notifications about problems are temporarily disabled until the host changes state (i.e. recovers).\n");
printf("Contacts for this host will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the host.\n");
printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the host comment to be retained between restarts of NetSaint, check\n");
printf("the 'Persistent' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
break;
case CMD_ACKNOWLEDGE_SVC_PROBLEM:
printf("This command is used to acknowledge a service problem. When a service problem is acknowledged, future notifications about problems are temporarily disabled until the service changes state (i.e. recovers).\n");
printf("Contacts for this service will receive a notification about the acknowledgement, so they are aware that someone is working on the problem. Additionally, a comment will also be added to the service.\n");
printf("Make sure to enter your name and fill in a brief description of what you are doing in the comment field. If you would like the service comment to be retained between restarts of NetSaint, check\n");
printf("the 'Persistent' checkbox. If you do not want an acknowledgement notification sent out to the appropriate contacts, uncheck the 'Send Notification' checkbox.\n");
break;
case CMD_START_EXECUTING_SVC_CHECKS:
printf("This command is used to resume execution of service checks on a program-wide basis. Individual services which are disabled will still not be checked.\n");
break;
case CMD_STOP_EXECUTING_SVC_CHECKS:
printf("This command is used to temporarily stop NetSaint from executing any service checks. This will have the side effect of preventing any notifications from being sent out (for any and all services and hosts).\n");
printf("Service checks will not be executed again until you issue a command to resume service check execution.\n");
break;
case CMD_START_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("This command is used to make NetSaint start accepting passive service check results that it finds in the external command file\n");
break;
case CMD_STOP_ACCEPTING_PASSIVE_SVC_CHECKS:
printf("This command is use to make NetSaint stop accepting passive service check results that it finds in the external command file. All passive check results that are found will be ignored.\n");
break;
case CMD_ENABLE_PASSIVE_SVC_CHECKS:
printf("This command is used to allow NetSaint to accept passive service check results that it finds in the external command file for this particular service.\n");
break;
case CMD_DISABLE_PASSIVE_SVC_CHECKS:
printf("This command is used to make NetSaint stop accepting passive service check results that it finds in the external command file for this particular service. All passive check results that are found for this service will be ignored.\n");
break;
case CMD_ENABLE_EVENT_HANDLERS:
printf("This command is used to allow NetSaint to run host and service event handlers.\n");
break;
case CMD_DISABLE_EVENT_HANDLERS:
printf("This command is used to temporarily prevent NetSaint from running any host or service event handlers.\n");
break;
case CMD_ENABLE_SVC_EVENT_HANDLER:
printf("This command is used to allow NetSaint to run the service event handler for a particular service when necessary (if one is defined).\n");
break;
case CMD_DISABLE_SVC_EVENT_HANDLER:
printf("This command is used to temporarily prevent NetSaint from running the service event handler for a particular service.\n");
break;
case CMD_ENABLE_HOST_EVENT_HANDLER:
printf("This command is used to allow NetSaint to run the host event handler for a particular service when necessary (if one is defined).\n");
break;
case CMD_DISABLE_HOST_EVENT_HANDLER:
printf("This command is used to temporarily prevent NetSaint from running the host event handler for a particular host.\n");
break;
case CMD_ENABLE_HOST_CHECK:
printf("This command is used to enable checks of this host.\n");
break;
case CMD_DISABLE_HOST_CHECK:
printf("This command is used to temporarily prevent NetSaint from checking the status of a particular host. If NetSaint needs to check the status of this host, it will assume that it is in the same state that it was in before checks were disabled.\n");
break;
case CMD_START_OBSESSING_OVER_SVC_CHECKS:
printf("This command is used to have NetSaint start obsessing over service checks. Read the documentation on distributed monitoring for more information on this.\n");
break;
case CMD_STOP_OBSESSING_OVER_SVC_CHECKS:
printf("This command is used to have NetSaint stop obsessing over service checks. Read the documentation on distributed monitoring for more information on this.\n");
break;
case CMD_REMOVE_HOST_ACKNOWLEDGEMENT:
printf("This command is used to remove an acknowledgement for a particular host problem. Once the acknowledgement is removed, notifications may start being\n");
printf("sent out about the host problem. Note: Removing the acknowledgement does not remove the host comment that was originally associated\n");
printf("with the acknowledgement. You'll have to remove that as well if that's what you want.\n");
break;
case CMD_REMOVE_SVC_ACKNOWLEDGEMENT:
printf("This command is used to remove an acknowledgement for a particular service problem. Once the acknowledgement is removed, notifications may start being\n");
printf("sent out about the service problem. Note: Removing the acknowledgement does not remove the service comment that was originally associated\n");
printf("with the acknowledgement. You'll have to remove that as well if that's what you want.\n");
break;
case CMD_PROCESS_SERVICE_CHECK_RESULT:
printf("This command is used to submit a passive check result for a particular service. It is particularly useful for resetting security-related services to OK states once they have been dealt with.\n");
break;
case CMD_SCHEDULE_HOST_DOWNTIME:
printf("This command is used to schedule downtime for a particular host. During the specified downtime, NetSaint will not send notifications out about the host.\n");
printf("When the scheduled downtime expires, NetSaint will send out notifications for this host as it normally would. Scheduled downtimes are not preserved\n");
printf("across program shutdowns or restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss\n");
break;
case CMD_SCHEDULE_SVC_DOWNTIME:
printf("This command is used to schedule downtime for a particular service. During the specified downtime, NetSaint will not send notifications out about the service.\n");
printf("When the scheduled downtime expires, NetSaint will send out notifications for this service as it normally would. Scheduled downtimes are not preserved\n");
printf("across program shutdowns or restarts. Both the start and end times should be specified in the following format: mm/dd/yyyy hh:mm:ss\n");
break;
case CMD_ENABLE_HOST_FLAP_DETECTION:
printf("This command is used to enable flap detection for a specific host. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
break;
case CMD_DISABLE_HOST_FLAP_DETECTION:
printf("This command is used to disable flap detection for a specific host.\n");
break;
case CMD_ENABLE_SVC_FLAP_DETECTION:
printf("This command is used to enable flap detection for a specific service. If flap detection is disabled on a program-wide basis, this will have no effect,\n");
break;
case CMD_DISABLE_SVC_FLAP_DETECTION:
printf("This command is used to disable flap detection for a specific service.\n");
break;
case CMD_ENABLE_FLAP_DETECTION:
printf("This command is used to enable flap detection for hosts and services on a program-wide basis. Individual hosts and services may have flap detection disabled.\n");
break;
case CMD_DISABLE_FLAP_DETECTION:
printf("This command is used to disable flap detection for hosts and services on a program-wide basis.\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("This command is used to enable notifications for all services in the specified hostgroup. Notifications will only be sent out for the\n");
printf("service state types you defined in your service definitions. This does not enable notifications for the hosts in this hostgroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_HOSTGROUP_SVC_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all services in the specified hostgroup. You will have to re-enable notifications for\n");
printf("all services in this hostgroup before any alerts can be sent out in the future. This does not prevent notifications from being sent out about the hosts in this hostgroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_ENABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("This command is used to enable notifications for all hosts in the specified hostgroup. Notifications will only be sent out for the\n");
printf("host state types you defined in your host definitions.\n");
break;
case CMD_DISABLE_HOSTGROUP_HOST_NOTIFICATIONS:
printf("This command is used to prevent notifications from being sent out for all hosts in the specified hostgroup. You will have to re-enable notifications for\n");
printf("all hosts in this hostgroup before any alerts can be sent out in the future.\n");
break;
case CMD_ENABLE_HOSTGROUP_SVC_CHECKS:
printf("This command is used to enable all service checks in the specified hostgroup. This does not enable checks of the hosts in the hostgroup unless you check the 'Enable for hosts too' option.\n");
break;
case CMD_DISABLE_HOSTGROUP_SVC_CHECKS:
printf("This command is used to disable all service checks in the specified hostgroup. When a service is disabled NetSaint will not monitor the service. Doing this will prevent any notifications being sent out for\n");
printf("the specified service while it is disabled. In order to have NetSaint check the services in the future you will have to re-enable the services.\n");
printf("Note that disabling service checks may not necessarily prevent notifications from being sent out about the host which those services are associated with. This does not disable checks of the hosts in the hostgroup unless you check the 'Disable for hosts too' option.\n");
break;
case CMD_CANCEL_HOST_DOWNTIME:
printf("This command is used to cancel active or pending scheduled downtime for the specified host. You must select which type(s) of downtime you want to cancel.\n");
printf("Active downtime is downtime which is currently in effect, pending downtime is downtime which is scheduled for the future, but has not yet arrived.\n");
break;
case CMD_CANCEL_SVC_DOWNTIME:
printf("This command is used to cancel active or pending scheduled downtime for the specified service. You must select which type(s) of downtime you want to cancel.\n");
printf("Active downtime is downtime which is currently in effect, pending downtime is downtime which is scheduled for the future, but has not yet arrived.\n");
break;
default:
printf("Sorry, but no information is available for this command.");
}
printf("
\n");
printf("
\n");
return;
}
/* converts a UNIX timestamp to a string we can use */
int time_to_string(time_t *t, char *buffer, int buffer_length){
struct tm *lt;
lt=localtime(t);
snprintf(buffer,buffer_length-1,"%02d/%02d/%04d %02d:%02d:%02d",lt->tm_mon+1,lt->tm_mday,lt->tm_year+1900,lt->tm_hour,lt->tm_min,lt->tm_sec);
buffer[buffer_length-1]='\x0';
return OK;
}
/* converts a time string to a UNIX timestamp */
int string_to_time(char *buffer, time_t *t){
struct tm lt;
sscanf(buffer,"%02d/%02d/%04d %02d:%02d:%02d",<.tm_mon,<.tm_mday,<.tm_year,<.tm_hour,<.tm_min,<.tm_sec);
lt.tm_mon--;
lt.tm_year-=1900;
/* tell mktime() to try and compute DST automatically */
lt.tm_isdst=-1;
*t=mktime(<);
return OK;
}