*** wmlgen.c	Tue Dec 18 10:53:15 2007
--- wmlgen.c.htmlversion	Tue Dec 18 10:53:07 2007
***************
*** 59,70 ****
  static char *wml_colorname(int color)
  {
  	switch (color) {
! 	  case COL_GREEN:  return "GR"; break;
! 	  case COL_RED:    return "RE"; break;
! 	  case COL_YELLOW: return "YE"; break;
! 	  case COL_PURPLE: return "PU"; break;
! 	  case COL_CLEAR:  return "CL"; break;
! 	  case COL_BLUE:   return "BL"; break;
  	}
  
  	return "";
--- 59,70 ----
  static char *wml_colorname(int color)
  {
  	switch (color) {
! 	  case COL_GREEN:  return "<img src=\"gif/green.gif\">"; break;
! 	  case COL_RED:    return "<img src=\"gif/red.gif\">"; break;
! 	  case COL_YELLOW: return "<img src=\"gif/yellow.gif\">"; break;
! 	  case COL_PURPLE: return "<img src=\"gif/purple.gif\">"; break;
! 	  case COL_CLEAR:  return "<img src=\"gif/clear.gif\">"; break;
! 	  case COL_BLUE:   return "<img src=\"gif/blue.gif\">"; break;
  	}
  
  	return "";
***************
*** 72,84 ****
  
  static void wml_header(FILE *output, char *cardid, int idpart)
  {
! 	fprintf(output, "<?xml version=\"1.0\"?>\n");
! 	fprintf(output, "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
! 	fprintf(output, "<wml>\n");
! 	fprintf(output, "<head>\n");
! 	fprintf(output, "<meta http-equiv=\"Cache-Control\" content=\"max-age=0\"/>\n");
! 	fprintf(output, "</head>\n");
! 	fprintf(output, "<card id=\"%s%d\" title=\"Hobbit\">\n", cardid, idpart);
  }
  
  
--- 72,78 ----
  
  static void wml_header(FILE *output, char *cardid, int idpart)
  {
! 	fprintf(output, "<html> <meta http-equiv=\"expires\" content=\"-1\" /> <meta http-equiv=\"cache-control\" content=\"no-cache\">  <body bgcolor=\"black\" text=\"green\"> \n");
  }
  
  
***************
*** 95,101 ****
  	sprintf(hobbitdreq, "hobbitdlog %s.%s", host->hostname, entry->column->name);
  	hobbitdresult = sendmessage(hobbitdreq, NULL, NULL, &logbuf, 1, BBTALK_TIMEOUT);
  	if ((hobbitdresult != BB_OK) || (logbuf == NULL) || (strlen(logbuf) == 0)) {
! 		errprintf("WML: Status not available\n");
  		return;
  	}
  
--- 89,95 ----
  	sprintf(hobbitdreq, "hobbitdlog %s.%s", host->hostname, entry->column->name);
  	hobbitdresult = sendmessage(hobbitdreq, NULL, NULL, &logbuf, 1, BBTALK_TIMEOUT);
  	if ((hobbitdresult != BB_OK) || (logbuf == NULL) || (strlen(logbuf) == 0)) {
! 		//errprintf("WML: Status not available\n");
  		return;
  	}
  
***************
*** 111,117 ****
  
  	nextline = msg;
  
! 	sprintf(fn, "%s/%s.%s.wml", wmldir, host->hostname, entry->column->name);
  	fd = fopen(fn, "w");
  	if (fd == NULL) {
  		errprintf("Cannot create file %s\n", fn);
--- 105,111 ----
  
  	nextline = msg;
  
! 	sprintf(fn, "%s/%s.%s.html", wmldir, host->hostname, entry->column->name);
  	fd = fopen(fn, "w");
  	if (fd == NULL) {
  		errprintf("Cannot create file %s\n", fn);
***************
*** 120,130 ****
  
  	wml_header(fd, "name", 1);
  	fprintf(fd, "<p align=\"center\">\n");
! 	fprintf(fd, "<anchor title=\"BB\">Host<go href=\"%s.wml\"/></anchor><br/>\n", host->hostname);
! 	fprintf(fd, "%s</p>\n", timestamp);
! 	fprintf(fd, "<p align=\"left\" mode=\"nowrap\">\n");
  	fprintf(fd, "<b>%s.%s</b><br/></p><p mode=\"nowrap\">\n", host->hostname, entry->column->name);
  
  	/*
  	 * We need to parse the logfile a bit to get a decent WML
  	 * card that contains the logfile. bbd does this for
--- 114,132 ----
  
  	wml_header(fd, "name", 1);
  	fprintf(fd, "<p align=\"center\">\n");
! 	fprintf(fd, "%s\n", timestamp);
! 	fprintf(fd, "<br/><a href=\"%s.html\">Host</a><br/>\n", host->hostname);
! 	fprintf(fd, "<a href=\"/hobbit-cgi/hobbitgraph.sh?host=%s&amp;service=%s&amp;graph_width=220&amp;nostale&amp;graph=hourly&amp;action=view\">Hourly Graph</a><br/>\n", host->hostname,entry->column->name);
! 	fprintf(fd, "<a href=\"/hobbit-cgi/hobbitgraph.sh?host=%s&amp;service=%s&amp;graph_width=220&amp;nostale&amp;graph=daily&amp;action=view\">Daily Graph</a><br/>\n", host->hostname,entry->column->name);
! 	fprintf(fd, "<a href=\"/hobbit-cgi/hobbitgraph.sh?host=%s&amp;service=%s&amp;graph_width=220&amp;nostale&amp;graph=weekly&amp;action=view\">Weekly Graph</a><br/>\n", host->hostname,entry->column->name);
! 	fprintf(fd, "<a href=\"/hobbit-cgi/hobbitgraph.sh?host=%s&amp;service=%s&amp;graph_width=220&amp;nostale&amp;graph=monthly&amp;action=view\">Monthly Graph</a><br/>\n", host->hostname,entry->column->name);
! 	fprintf(fd, "</p><p align=\"left\" mode=\"nowrap\">\n");
  	fprintf(fd, "<b>%s.%s</b><br/></p><p mode=\"nowrap\">\n", host->hostname, entry->column->name);
  
+ 	fprintf(fd,"<FORM METHOD=\"POST\" NAME=selectionform ACTION=\"/hobbit-seccgi/hobbit-enadis.sh\">"); 
+ 	fprintf(fd,"<input name=cause type=hidden value=autodisable > <input name=untilok type=hidden value=on>  <input name=go type=hidden value=\"Disable now\"> <input name=disabletest type=hidden value=%s > <input name=hostname type=hidden value=%s > <INPUT TYPE=submit Name=Button VALUE=\"Disable this alert\"> </form> <br/> <br/> ", entry->column->name,host->hostname ); 
+ 
+ 
  	/*
  	 * We need to parse the logfile a bit to get a decent WML
  	 * card that contains the logfile. bbd does this for
***************
*** 184,217 ****
  						p = endtag+1;
  					}
  				}
  				else if (*p == '>') {
  					strcpy(outp, "&gt;");
  					outp += 4; p++;
  				}
  				else if (strncmp(p, "&red", 4) == 0) {
! 					strcpy(outp, "<b>red</b>");
! 					outp += 10; p += 4;
  				}
  				else if (strncmp(p, "&green", 6) == 0) {
! 					strcpy(outp, "<b>green</b>");
! 					outp += 12; p += 6;
  				}
  				else if (strncmp(p, "&purple", 7) == 0) {
! 					strcpy(outp, "<b>purple</b>");
! 					outp += 13; p += 7;
  				}
  				else if (strncmp(p, "&yellow", 7) == 0) {
! 					strcpy(outp, "<b>yellow</b>");
! 					outp += 13; p += 7;
  				}
  				else if (strncmp(p, "&clear", 6) == 0) {
! 					strcpy(outp, "<b>clear</b>");
! 					outp += 12; p += 6;
  				}
  				else if (strncmp(p, "&blue", 5) == 0) {
! 					strcpy(outp, "<b>blue</b>");
! 					outp += 11; p += 5;
  				}
  				else if (*p == '&') {
  					strcpy(outp, "&amp;");
  					outp += 5; p++;
--- 186,241 ----
  						p = endtag+1;
  					}
  				}
+ 
  				else if (*p == '>') {
  					strcpy(outp, "&gt;");
  					outp += 4; p++;
  				}
  				else if (strncmp(p, "&red", 4) == 0) {
! 					strcpy(outp, "<img src=\"gif/red.gif\">");
! 					outp += 23; p += 4;
  				}
  				else if (strncmp(p, "&green", 6) == 0) {
! 					strcpy(outp, "<img src=\"gif/green.gif\">");
! 					outp += 25; p += 6;
  				}
  				else if (strncmp(p, "&purple", 7) == 0) {
! 					strcpy(outp, "<img src=\"gif/purple.gif\">");
! 					outp += 26; p += 7;
  				}
  				else if (strncmp(p, "&yellow", 7) == 0) {
! 					strcpy(outp, "<img src=\"gif/yellow.gif\">");
! 					outp += 26; p += 7;
  				}
  				else if (strncmp(p, "&clear", 6) == 0) {
! 					strcpy(outp, "<img src=\"gif/clear.gif\">");
! 					outp += 25; p += 6;
  				}
  				else if (strncmp(p, "&blue", 5) == 0) {
! 					strcpy(outp, "<img src=\"gif/blue.gif\">");
! 					outp += 24; p += 5;
  				}
+ 
+ 				else if (strncmp(p, "red", 3) == 0) {
+                                         strcpy(outp, "<font color=\"red\">");
+                                         outp += 18; p += 3;
+                                 }
+ 				else if (strncmp(p, "yellow", 6) == 0) {
+                                         strcpy(outp, "<font color=\"yellow\">");
+                                         outp += 21; p += 6;
+                                 }
+ 				else if (strncmp(p, "purple", 6) == 0) {
+                                         strcpy(outp, "<font color=\"purple\">");
+                                         outp += 21; p += 6;
+ 				}	
+ 				else if (strncmp(p, "blue", 4) == 0) {
+                                         strcpy(outp, "<font color=\"blue\">");
+                                         outp += 19; p += 4;
+                                 }
+ 				else if (strncmp(p, "green", 6) == 0) {
+                                         strcpy(outp, "<font color=\"yellow\">");
+                                         outp += 21; p += 6;
+                                 }
  				else if (*p == '&') {
  					strcpy(outp, "&amp;");
  					outp += 5; p++;
***************
*** 233,239 ****
  		*outp = '\0';
  		if (strlen(lineout)) fprintf(fd, "%s\n<br/>\n", lineout);
  	}
! 	fprintf(fd, "<br/> </p> </card> </wml>\n");
  
  	fclose(fd);
  	if (logbuf) xfree(logbuf);
--- 257,263 ----
  		*outp = '\0';
  		if (strlen(lineout)) fprintf(fd, "%s\n<br/>\n", lineout);
  	}
! 	fprintf(fd, "<br/> </p> </html>\n");
  
  	fclose(fd);
  	if (logbuf) xfree(logbuf);
***************
*** 285,310 ****
  	for (h = hostlistBegin(); (h); h = hostlistNext()) {
  		h->hostentry->wapcolor = COL_GREEN;
  		for (t = h->hostentry->entries; (t); t = t->next) {
- 			if (t->onwap && ((t->color == COL_RED) || (t->color == COL_YELLOW))) {
  				generate_wml_statuscard(h->hostentry, t);
  				h->hostentry->anywaps = 1;
- 			}
- 			else {
- 				/* Clear the onwap flag - makes testing later a bit simpler */
- 				t->onwap = 0;
- 			}
  
  			if (t->onwap && (t->color > h->hostentry->wapcolor)) h->hostentry->wapcolor = t->color;
  		}
  
  		/* Update the bb2wapcolor */
! 		if ( (h->hostentry->wapcolor == COL_RED) || (h->hostentry->wapcolor == COL_YELLOW) ) {
! 			if (h->hostentry->wapcolor > bb2wapcolor) bb2wapcolor = h->hostentry->wapcolor;
! 		}
  	}
  
  	/* Start the BB2 WML card */
! 	sprintf(bb2fn, "%s/bb2.wml.tmp", wmldir);
  	bb2fd = fopen(bb2fn, "w");
  	if (bb2fd == NULL) {
  		errprintf("Cannot open BB2 WML file %s\n", bb2fn);
--- 309,327 ----
  	for (h = hostlistBegin(); (h); h = hostlistNext()) {
  		h->hostentry->wapcolor = COL_GREEN;
  		for (t = h->hostentry->entries; (t); t = t->next) {
  				generate_wml_statuscard(h->hostentry, t);
  				h->hostentry->anywaps = 1;
  
  			if (t->onwap && (t->color > h->hostentry->wapcolor)) h->hostentry->wapcolor = t->color;
+ 			if(h->hostentry->wapcolor == COL_CLEAR) h->hostentry->wapcolor = COL_GREEN ; 
  		}
  
  		/* Update the bb2wapcolor */
! 		if (h->hostentry->wapcolor > bb2wapcolor) bb2wapcolor = h->hostentry->wapcolor;
  	}
  
  	/* Start the BB2 WML card */
! 	sprintf(bb2fn, "%s/bb2.html.tmp", wmldir);
  	bb2fd = fopen(bb2fn, "w");
  	if (bb2fd == NULL) {
  		errprintf("Cannot open BB2 WML file %s\n", bb2fn);
***************
*** 314,327 ****
  	/* Standard BB2 wap header */
  	wml_header(bb2fd, "card", bb2part);
  	fprintf(bb2fd, "<p align=\"center\" mode=\"nowrap\">\n");
! 	fprintf(bb2fd, "%s</p>\n", timestamp);
! 	fprintf(bb2fd, "<p align=\"center\" mode=\"nowrap\">\n");
! 	fprintf(bb2fd, "Summary Status<br/><b>%s</b><br/><br/>\n", colorname(bb2wapcolor));
  
- 	/* All green ? Just say so */
- 	if (bb2wapcolor == COL_GREEN) {
- 		fprintf(bb2fd, "All is OK<br/>\n");
- 	}
  
  	/* Now loop through the hostlist again, and generate the bb2wap links and host pages */
  	for (h = hostlistBegin(); (h); h = hostlistNext()) {
--- 331,338 ----
  	/* Standard BB2 wap header */
  	wml_header(bb2fd, "card", bb2part);
  	fprintf(bb2fd, "<p align=\"center\" mode=\"nowrap\">\n");
! 	fprintf(bb2fd, "Summary Status<br/><font color=\"%s\"><b>%s</b></font><br/><br/>" , colorname(bb2wapcolor), colorname(bb2wapcolor));
  
  
  	/* Now loop through the hostlist again, and generate the bb2wap links and host pages */
  	for (h = hostlistBegin(); (h); h = hostlistNext()) {
***************
*** 328,334 ****
  		if (h->hostentry->anywaps) {
  
  			/* Create the host WAP card, with links to individual test results */
! 			sprintf(hostfn, "%s/%s.wml", wmldir, h->hostentry->hostname);
  			hostfd = fopen(hostfn, "w");
  			if (hostfd == NULL) {
  				errprintf("Cannot create file %s\n", hostfn);
--- 339,345 ----
  		if (h->hostentry->anywaps) {
  
  			/* Create the host WAP card, with links to individual test results */
! 			sprintf(hostfn, "%s/%s.html", wmldir, h->hostentry->hostname);
  			hostfd = fopen(hostfn, "w");
  			if (hostfd == NULL) {
  				errprintf("Cannot create file %s\n", hostfn);
***************
*** 337,408 ****
  
  			wml_header(hostfd, "name", 1);
  			fprintf(hostfd, "<p align=\"center\">\n");
- 			fprintf(hostfd, "<anchor title=\"BB\">Overall<go href=\"bb2.wml\"/></anchor><br/>\n");
  			fprintf(hostfd, "%s</p>\n", timestamp);
  			fprintf(hostfd, "<p align=\"left\" mode=\"nowrap\">\n");
  			fprintf(hostfd, "<b>%s</b><br/><br/>\n", h->hostentry->hostname);
  
  			for (t = h->hostentry->entries; (t); t = t->next) {
  				if (t->onwap) {
! 					fprintf(hostfd, "<b><anchor title=\"%s\">%s%s<go href=\"%s.%s.wml\"/></anchor></b> %s<br/>\n", 
  						t->column->name, 
  						wml_colorname(t->color),
! 						(t->acked ? "x" : ""),
! 						h->hostentry->hostname, t->column->name,
  						t->column->name);
  				}
  			}
! 			fprintf(hostfd, "\n</p> </card> </wml>\n");
  			fclose(hostfd);
  
  			/* Create the link from the bb2 wap card to the host card */
! 			fprintf(bb2fd, "<b><anchor title=\"%s\">%s<go href=\"%s.wml\"/></anchor></b> %s<br/>\n", 
  				h->hostentry->hostname, wml_colorname(h->hostentry->wapcolor), 
! 				h->hostentry->hostname, h->hostentry->hostname);
  
- 			/* 
- 			 * Gross hack. Some WAP phones cannot handle large cards. 
- 			 * So if the card grows larger than WMLMAXCHARS, split it into 
- 			 * multiple files and link from one file to the next.
- 			 */
- 			if (ftello(bb2fd) >= wmlmaxchars) {
- 				char oldbb2fn[PATH_MAX];
- 
- 				/* WML link is from the bb2fn except leading wmldir+'/' */
- 				strcpy(oldbb2fn, bb2fn+strlen(wmldir)+1);
- 
- 				bb2part++;
- 
- 				fprintf(bb2fd, "<br /><b><anchor title=\"Next\">Next<go href=\"bb2-%d.wml\"/></anchor></b>\n", bb2part);
- 				fprintf(bb2fd, "</p> </card> </wml>\n");
- 				fclose(bb2fd);
- 
- 				/* Start a new BB2 WML card */
- 				sprintf(bb2fn, "%s/bb2-%d.wml", wmldir, bb2part);
- 				bb2fd = fopen(bb2fn, "w");
- 				if (bb2fd == NULL) {
- 					errprintf("Cannot open BB2 WML file %s\n", bb2fn);
- 					return;
- 				}
- 				wml_header(bb2fd, "card", bb2part);
- 				fprintf(bb2fd, "<p align=\"center\">\n");
- 				fprintf(bb2fd, "<anchor title=\"Prev\">Previous<go href=\"%s\"/></anchor><br/>\n", oldbb2fn);
- 				fprintf(bb2fd, "%s</p>\n", timestamp);
- 				fprintf(bb2fd, "<p align=\"center\" mode=\"nowrap\">\n");
- 				fprintf(bb2fd, "Summary Status<br/><b>%s</b><br/><br/>\n", colorname(bb2wapcolor));
- 			}
  		}
  	}
  
! 	fprintf(bb2fd, "</p> </card> </wml>\n");
  	fclose(bb2fd);
  
  	if (chdir(wmldir) == 0) {
  		/* Rename the top-level file into place now */
! 		rename("bb2.wml.tmp", "bb2.wml");
  
  		/* Make sure there is the index.wml file pointing to bb2.wml */
! 		symlink("bb2.wml", "index.wml");
  	}
  
  	return;
--- 348,391 ----
  
  			wml_header(hostfd, "name", 1);
  			fprintf(hostfd, "<p align=\"center\">\n");
  			fprintf(hostfd, "%s</p>\n", timestamp);
+ 			fprintf(hostfd, "<a href=\"bb2.html\"> Overall </a><br/>\n");
  			fprintf(hostfd, "<p align=\"left\" mode=\"nowrap\">\n");
  			fprintf(hostfd, "<b>%s</b><br/><br/>\n", h->hostentry->hostname);
  
+ 			fprintf(hostfd,"<FORM METHOD=\"POST\" NAME=selectionform ACTION=\"/hobbit-seccgi/hobbit-enadis.sh\">"); 
+ 			fprintf(hostfd,"<input name=cause type=hidden value=autodisable > <input name=untilok type=hidden value=on>  <input name=go type=hidden value=\"Disable now\"> <input name=disabletest type=hidden value=ALL > <input name=hostname type=hidden value=%s > <INPUT TYPE=submit Name=Button VALUE=\"Disable this host\"> </form> <br/> <br/> ", h->hostentry->hostname ); 
+ 
  			for (t = h->hostentry->entries; (t); t = t->next) {
  				if (t->onwap) {
! 					fprintf(hostfd, "<b><a href=\"%s.%s.html\">%s%s </a></b> %s<br/>\n", 
! 						h->hostentry->hostname,
  						t->column->name, 
  						wml_colorname(t->color),
! 						(t->acked ? "<img src=\"gif/red-ack.gif\">" : ""),
  						t->column->name);
  				}
  			}
! 			fprintf(hostfd, "\n</p> </html>\n");
  			fclose(hostfd);
  
  			/* Create the link from the bb2 wap card to the host card */
! 			fprintf(bb2fd, "<b><a href=\"%s.html\">%s %s </a></b> <br/>\n", 
  				h->hostentry->hostname, wml_colorname(h->hostentry->wapcolor), 
! 				h->hostentry->hostname);
  
  		}
  	}
  
! 	fprintf(bb2fd, "</p> </html>\n");
  	fclose(bb2fd);
  
  	if (chdir(wmldir) == 0) {
  		/* Rename the top-level file into place now */
! 		rename("bb2.html.tmp", "bb2.html");
  
  		/* Make sure there is the index.wml file pointing to bb2.wml */
! 		symlink("bb2.html", "index.html");
  	}
  
  	return;
