[icinga-checkins] icinga.org: icinga-core/test/cgis: classic ui: fixed Availability Records Break if JavaScript is disabled #2412

git at icinga.org git at icinga.org
Tue Apr 3 09:26:30 CEST 2012


Module: icinga-core
Branch: test/cgis
Commit: 684ef53d85e4efe8727998dde5a4885415490480
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=684ef53d85e4efe8727998dde5a4885415490480

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Thu Mar  8 20:52:07 2012 +0100

classic ui: fixed Availability Records Break if JavaScript is disabled #2412

refs: #2412

* now removed all javascript
* also fixed a problem that the header wasn't display when a report was generated

---

 Changelog   |    1 +
 cgi/avail.c |   68 +++++++++++++++++++++++++++++++++--------------------------
 2 files changed, 39 insertions(+), 30 deletions(-)

diff --git a/Changelog b/Changelog
index 9b259d7..be2fd60 100644
--- a/Changelog
+++ b/Changelog
@@ -40,6 +40,7 @@ FIXES
 * classic ui: fixed Commit commands with more then 500 multiple pairs of hosts and services #2373
 * classic ui: fixed reset forms on return after submitting command #2117
 * classic ui: Change Excel icon to odf spreadsheet icon #2391
+* classic ui: fixed Availability Records Break if JavaScript is disabled #2412
 
 * idoutils: fix ORA-00913 too many values when MERGE INTO eventhandlers #2319
 * idoutils: change standard string escaping for postgresql queries to use the E'foo' notation #1974
diff --git a/cgi/avail.c b/cgi/avail.c
index ed72ab3..1d0a550 100644
--- a/cgi/avail.c
+++ b/cgi/avail.c
@@ -266,7 +266,6 @@ int main(int argc, char **argv) {
 	time_t t3;
 	time_t current_time;
 	struct tm *t;
-	char *firsthostpointer;
 
 	/* reset internal CGI variables */
 	reset_cgi_vars();
@@ -600,7 +599,8 @@ int main(int argc, char **argv) {
 		printf("</table>\n");
 		printf("</form>\n");
 
-		print_export_link(HTML_CONTENT, AVAIL_CGI, NULL);
+		if (display_type == DISPLAY_NO_AVAIL || get_date_parts == TRUE)
+			print_export_link(HTML_CONTENT, AVAIL_CGI, NULL);
 
 		printf("</td>\n");
 
@@ -631,10 +631,10 @@ int main(int argc, char **argv) {
 		printf("<input type='hidden' name='show_log_entries' value=''>\n");
 		if (display_type == DISPLAY_HOSTGROUP_AVAIL)
 			printf("<input type='hidden' name='hostgroup' value='%s'>\n", escape_string(hostgroup_name));
-		if (display_type == DISPLAY_HOST_AVAIL || display_type == DISPLAY_SERVICE_AVAIL)
+		if (display_type == DISPLAY_HOST_AVAIL)
 			printf("<input type='hidden' name='host' value='%s'>\n", escape_string(host_name));
 		if (display_type == DISPLAY_SERVICE_AVAIL)
-			printf("<input type='hidden' name='service' value='%s'>\n", escape_string(service_desc));
+			printf("<input type='hidden' name='hostservice' value='%s^%s'>\n", escape_string(host_name), escape_string(service_desc));
 		if (display_type == DISPLAY_SERVICEGROUP_AVAIL)
 			printf("<input type='hidden' name='servicegroup' value='%s'>\n", escape_string(servicegroup_name));
 
@@ -903,40 +903,21 @@ int main(int argc, char **argv) {
 	/* step 2 - the user wants to select a service */
 	else if (select_services == TRUE) {
 
-		printf("<SCRIPT LANGUAGE='JavaScript'>\n");
-		printf("function gethostname(hostindex){\n");
-		printf("hostnames=[\"all\"");
-
-		firsthostpointer = NULL;
-		for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
-			if (is_authorized_for_service(temp_service, &current_authdata) == TRUE) {
-				if (!firsthostpointer)
-					firsthostpointer = temp_service->host_name;
-				printf(", \"%s\"", temp_service->host_name);
-			}
-		}
-
-		printf(" ]\n");
-		printf("return hostnames[hostindex];\n");
-		printf("}\n");
-		printf("</SCRIPT>\n");
-
 		printf("<p><div align=center class='reportSelectTitle'>Step 2: Select Service</div></p>\n");
 
 		printf("<p><div align=center>\n");
 
-		printf("<form method=\"get\" action=\"%s\" name='serviceform'>\n", AVAIL_CGI);
+		printf("<form method=\"post\" action=\"%s\" name='serviceform'>\n", AVAIL_CGI);
 		printf("<input type='hidden' name='get_date_parts'>\n");
-		printf("<input type='hidden' name='host' value='%s'>\n", (firsthostpointer == NULL) ? "unknown" : (char *)escape_string(firsthostpointer));
 
 		printf("<table border=0 cellpadding=5>\n");
 
 		printf("<tr><td class='reportSelectSubTitle' valign=center>Service(s):</td><td align=left valign=center class='reportSelectItem'>\n");
-		printf("<select name='service' onFocus='document.serviceform.host.value=gethostname(this.selectedIndex);' onChange='document.serviceform.host.value=gethostname(this.selectedIndex);'>\n");
-		printf("<option value='all'>** ALL SERVICES **\n");
+		printf("<select name='hostservice' >\n");
+		printf("<option value='all^all'>** ALL SERVICES **\n");
 		for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
 			if (is_authorized_for_service(temp_service, &current_authdata) == TRUE)
-				printf("<option value='%s'>%s;%s\n", escape_string(temp_service->description), temp_service->host_name, (temp_service->display_name != NULL) ? temp_service->display_name : temp_service->description);
+				printf("<option value='%s^%s'>%s;%s\n", escape_string(temp_service->host_name), escape_string(temp_service->description), temp_service->host_name, (temp_service->display_name != NULL) ? temp_service->display_name : temp_service->description);
 		}
 
 		printf("</select>\n");
@@ -1171,6 +1152,7 @@ int main(int argc, char **argv) {
 
 int process_cgivars(void) {
 	char **variables;
+	char *temp_buffer = NULL;
 	int error = FALSE;
 	int x;
 
@@ -1250,6 +1232,32 @@ int process_cgivars(void) {
 			show_all_services = (strcmp(service_desc, "all")) ? FALSE : TRUE;
 		}
 
+		/* we found a combined host/service */
+		else if (!strcmp(variables[x], "hostservice")) {
+			x++;
+			if (variables[x] == NULL) {
+				error = TRUE;
+				break;
+			}
+
+			temp_buffer = strtok(variables[x], "^");
+
+			if ((host_name = (char *)strdup(temp_buffer)) == NULL)
+				host_name = "";
+			else
+				strip_html_brackets(host_name);
+
+			temp_buffer = strtok(NULL, "");
+
+			if ((service_desc = (char *)strdup(temp_buffer)) == NULL)
+				service_desc = "";
+			else
+				strip_html_brackets(service_desc);
+
+			display_type = DISPLAY_SERVICE_AVAIL;
+			show_all_services = (strcmp(service_desc, "all")) ? FALSE : TRUE;
+		}
+
 		/* we found first time argument */
 		else if (!strcmp(variables[x], "t1")) {
 			x++;
@@ -1442,7 +1450,7 @@ int process_cgivars(void) {
 			content_type = XML_CONTENT;
 		}
 
-		/* we found the standard timeperiod argument */
+		/* we found the content type argument */
 		else if (!strcmp(variables[x], "content_type")) {
 			x++;
 			if (variables[x] == NULL) {
@@ -1458,11 +1466,11 @@ int process_cgivars(void) {
 				content_type = JSON_CONTENT;
 			else if (!strcmp(variables[x], "html"))
 				content_type = HTML_CONTENT;
-
 			else
 				continue;
 
-			display_header = FALSE;
+			if (content_type != HTML_CONTENT)
+				display_header = FALSE;
 		}
 
 		/* we found the log entries option  */





More information about the icinga-checkins mailing list