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 "
"
+
+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("
\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("
%s
%s
%s