Репозиторий Sisyphus
Последнее обновление: 1 октября 2023 | Пакетов: 18631 | Посещений: 37044769
en ru br
Репозитории ALT
S:3.0.6-alt16
5.1: 3.0.6-alt1
4.1: 3.0.3-alt1.M41.1
4.0: 2.7-alt1
3.0: 2.0-alt0.b3.1
www.altlinux.org/Changes

Группа :: Мониторинг
Пакет: nagios

 Главная   Изменения   Спек   Патчи   Sources   Загрузить   Gear   Bugs and FR  Repocop 

Патч: nagios-3.0.6-alt-format-comments.patch
Скачать


diff --git a/nagios/cgi/extinfo.c b/nagios/cgi/extinfo.c
index 5be3fb9..15deb3e 100644
--- a/nagios/cgi/extinfo.c
+++ b/nagios/cgi/extinfo.c
@@ -1831,7 +1831,96 @@ void show_servicegroup_info(){
 	return;
         }
 
+#define HTML_TAB_STR "    "
+#define HTML_NL_STR  "<br>"
+
+char *format_html(const char *comment)
+{
+    unsigned int c_len = strlen(comment);
+    const char *esc = index(comment, '\\');
+    if (!esc)
+        return strdup(comment);
+
+    unsigned int buf_len = c_len * 2;
+    char *html = malloc(buf_len);
+    if (!html) {
+        fprintf(stderr, "ERROR: Unable to allocate %d bytes!\n", buf_len);
+        return NULL;
+    }
+
+    unsigned int h_pos = 0;
+    unsigned int pos = 0;
+
+    const char *rep_str = NULL;
+    unsigned int rep_len = 0;
+    unsigned int skip = 0;
+
+    while (esc) {
+        if ((esc - comment) < (c_len - 1)) {
+            switch (*(esc + 1)) {
+            case 't':
+                rep_str = HTML_TAB_STR;
+                rep_len = strlen(rep_str);
+                skip = 2;
+                break;
+            case 'n':
+                rep_str = HTML_NL_STR;
+                rep_len = strlen(rep_str);
+                skip = 2;
+                break;
+            default:
+                esc += 2;
+                skip = 0;
+                rep_str = NULL;
+                rep_len = 0;
+            }
+        } else {
+            esc++;
+            skip = 0;
+            rep_str = NULL;
+            rep_len = 0;
+        }
+
+        if ((buf_len - h_pos) < (esc - comment - pos + rep_len)) {
+            buf_len += 2*(esc - comment - pos + rep_len);
+            html = realloc(html, buf_len);
+            if (!html) {
+                fprintf(stderr, "ERROR: Unable to reallocate %d bytes!\n", buf_len);
+                return NULL;
+            }
+        }
+
+        memcpy(html + h_pos, comment + pos, esc - comment - pos);
+        h_pos += esc - comment - pos;
+
+        if (rep_str && rep_len) {
+            memcpy(html + h_pos, rep_str, rep_len);
+            h_pos += rep_len;
+        }
+
+        pos += esc - comment - pos + skip;
+
+        if (pos < c_len) {
+            esc = index(comment + pos, '\\');
+        } else
+            esc = NULL;
+    }
+
+    if ((buf_len - h_pos) <= (c_len - pos)) {
+        buf_len += c_len - pos + 1;
+        html = realloc(html, buf_len);
+        if (!html) {
+            fprintf(stderr, "ERROR: Unable to reallocate %d bytes!\n", buf_len);
+            return NULL;
+        }
+    }
+
+    memcpy(html + h_pos, comment + pos, c_len - pos);
+    h_pos += c_len - pos;
 
+    html[h_pos] = '\0';
+    return html;
+}
 
 /* shows all service and host comments */
 void show_all_comments(void){
@@ -1844,6 +1933,7 @@ void show_all_comments(void){
 	service *temp_service;
 	char *comment_type;
 	char expire_time[MAX_DATETIME_LENGTH];
+    char *html_comment = NULL;
 
 
 	printf("<P>\n");
@@ -1902,13 +1992,21 @@ void show_all_comments(void){
 			comment_type="?";
 		        }
 
+        html_comment = format_html(temp_comment->comment_data);
+        if (!html_comment) {
+            fprintf(stderr, "ERROR: Unable to format the comment data!\n");
+            continue;
+        }
+
 		get_time_string(&temp_comment->entry_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 		get_time_string(&temp_comment->expire_time,expire_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 		printf("<tr CLASS='%s'>",bg_class);
 		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);
-		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");
+		printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'><pre>%s</pre></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,html_comment,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");
 		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);
 		printf("</tr>\n");
+
+        free(html_comment);
 	        }
 
 	if(total_comments==0)
@@ -1972,15 +2070,23 @@ void show_all_comments(void){
 			comment_type="?";
 		        }
 
+        html_comment = format_html(temp_comment->comment_data);
+        if (!html_comment) {
+            fprintf(stderr, "ERROR: Unable to format the comment data!\n");
+            continue;
+        }
+
 		get_time_string(&temp_comment->entry_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 		get_time_string(&temp_comment->expire_time,expire_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 		printf("<tr CLASS='%s'>",bg_class);
 		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);
 		printf("<td CLASS='%s'><A HREF='%s?type=%d&host=%s",bg_class,EXTINFO_CGI,DISPLAY_SERVICE_INFO,url_encode(temp_comment->host_name));
 		printf("&service=%s'>%s</A></td>",url_encode(temp_comment->service_description),temp_comment->service_description);
-		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");
+		printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'><pre>%s</pre></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,html_comment,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");
 		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);
 		printf("</tr>\n");
+
+        free(html_comment);
 	        }
 
 	if(total_comments==0)
@@ -2517,6 +2623,7 @@ void display_comments(int type){
 	comment *temp_comment;
 	char *comment_type;
 	char expire_time[MAX_DATETIME_LENGTH];
+    char *html_comment = NULL;
 
 
 	/* find the host or service */
@@ -2603,13 +2710,20 @@ void display_comments(int type){
 				comment_type="?";
 			        }
 
+            html_comment = format_html(temp_comment->comment_data);
+            if (!html_comment) {
+                fprintf(stderr, "ERROR: Unable to format the comment data!\n");
+                continue;
+            }
+
 			get_time_string(&temp_comment->entry_time,date_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 			get_time_string(&temp_comment->expire_time,expire_time,(int)sizeof(date_time),SHORT_DATE_TIME);
 			printf("<tr CLASS='%s'>",bg_class);
-			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");
+			printf("<td CLASS='%s'>%s</td><td CLASS='%s'>%s</td><td CLASS='%s'><pre>%s</pre></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,html_comment,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");
 			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);
 			printf("</tr>\n");
 
+            free(html_comment);
 			total_comments++;
 			}
 	        }
 
дизайн и разработка: Vladimir Lettiev aka crux © 2004-2005, Andrew Avramenko aka liks © 2007-2008
текущий майнтейнер: Michael Shigorin