[icinga-checkins] icinga.org: icinga-core/mbrooks/cgis: better handling of writing to cgi. log in cmd.cgi #1161

git at icinga.org git at icinga.org
Tue Jun 14 21:06:25 CEST 2011


Module: icinga-core
Branch: mbrooks/cgis
Commit: 2460d4210459dc401baa8d84dc600cd12043a7e8
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=2460d4210459dc401baa8d84dc600cd12043a7e8

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Thu May 12 18:53:10 2011 +0200

better handling of writing to cgi.log in cmd.cgi #1161

refs: #1161

---

 cgi/cmd.c |   39 ++++++++++++++++++++++-----------------
 1 files changed, 22 insertions(+), 17 deletions(-)

diff --git a/cgi/cmd.c b/cgi/cmd.c
index ad1522d..bd4d981 100644
--- a/cgi/cmd.c
+++ b/cgi/cmd.c
@@ -60,6 +60,7 @@ extern int  daemon_check;
 
 extern int enforce_comments_on_actions;
 extern int date_format;
+extern int use_logging;
 
 extern scheduled_downtime *scheduled_downtime_list;
 extern comment *comment_list;
@@ -2810,7 +2811,6 @@ int commit_command(int cmd){
 
 int write_command_to_file(char *cmd){
 	char *buffer;
-	char *buffer2;
 	char *ip_address;
 	int dummy;
 	char *p;
@@ -2847,26 +2847,31 @@ int write_command_to_file(char *cmd){
 		return ERROR;
 	}
 
-	/* get remote address */
-	ip_address=strdup(getenv("REMOTE_ADDR"));
+	if(use_logging==TRUE) {
+		// find closing bracket in cmd line
+		p = strchr(cmd, ']');
+		// if found get everything after closing bracket
+		if (p!=NULL)
+			p+=2;
+		else	// get complete command line
+			p=&cmd[0];
 
-	/* write command to cgi log */
-	dummy=asprintf(&buffer, "EXTERNAL COMMAND: %s;%s;", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address");
+		/* get remote address */
+		ip_address=strdup(getenv("REMOTE_ADDR"));
 
-	p = index(cmd, ']');
-	if (p!=NULL)
-		p+=2;
-	else
-		p=&cmd[0];
-
-	dummy=asprintf(&buffer2,"%s%s",buffer,p);
-
-	write_to_cgi_log(buffer2);
+		/* construct log entry */
+		dummy=asprintf(&buffer, "EXTERNAL COMMAND: %s;%s;%s", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address",p);
 
-	/* log comments if forced */
-	if(enforce_comments_on_actions==TRUE) {
-		dummy=asprintf(&buffer, "FORCED COMMENT: %s;%s;%s;%s", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address",comment_author,comment_data);
+		/* write command to cgi log */
 		write_to_cgi_log(buffer);
+
+		/* log comments if forced */
+		if(enforce_comments_on_actions==TRUE) {
+			my_free(buffer);
+			dummy=asprintf(&buffer, "FORCED COMMENT: %s;%s;%s;%s", current_authdata.username,(ip_address!=NULL)?ip_address:"unknown remote address",comment_author,comment_data);
+			write_to_cgi_log(buffer);
+		}
+		my_free(buffer);
 	}
 
 	/* write the command to file */





More information about the icinga-checkins mailing list