[patch] bb-findhost.cgi redirects to the page when only one host matches

Charles Goyard cgoyard at cvf.fr
Tue Jun 27 12:05:14 CEST 2006


hi,

I made a small modification to bb-findhost.c so that when a search
yields only one results, you get transported to that page.

Since we only know there's one result after a full scan of the bb-hosts
file, and don't want to scan the file twice, I use an ugly way to do it:
a javascript redirect held in a <img> tag.

This works for 4.1.2p1, but the patch applies in 4.2-beta-20060605 too (not
tested live, thought).


Regards,

-- 
Charles Goyard
rediscovering C
-------------- next part --------------
Index: bbdisplay/bb-findhost.c
===================================================================
--- bbdisplay/bb-findhost.c	(revision 1)
+++ bbdisplay/bb-findhost.c	(working copy)
@@ -128,6 +128,7 @@
 int main(int argc, char *argv[])
 {
 	namelist_t *hosthead, *hostwalk, *clonewalk;
+	namelist_t *uniquematch;
 	int argi;
 	char *envarea = NULL;
 
@@ -232,7 +233,9 @@
 					bbh_item(hostwalk, BBH_PAGEPATH),
 					hostname,
 					bbh_item(hostwalk, BBH_PAGEPATHTITLE));
-
+				if(!gotany) {
+				        uniquematch=hostwalk;
+				}
 				clonewalk = hostwalk->next;
 				while (clonewalk && (strcmp(hostwalk->bbhostname, clonewalk->bbhostname) == 0)) {
 					printf("<br><a href=\"%s/%s#%s\">%s</a>\n",
@@ -251,7 +254,16 @@
 
 		regfree (&re); 	/*[wm] - free regex compiled patern */
 	
-		if (!gotany) printf("<tr><td align=left>%s</td><td align=left>Not found</td></tr>\n", pSearchPat);
+		if (!gotany) {
+		        printf("<tr><td align=left>%s</td><td align=left>Not found</td></tr>\n", pSearchPat);
+		}
+		else if (gotany == 1) {
+		        printf("<tr><td><img src=\"%s/clear.gif\" onload=\"window.location='%s/%s#%s'\" alt=\"redirect\"/></td></tr>",
+			       xgetenv("BBSKIN"),
+			       xgetenv("BBWEB"),
+			       bbh_item(uniquematch, BBH_PAGEPATH),
+			       uniquematch->bbhostname);
+		}
 	} 
 
 


More information about the Xymon mailing list