[icinga-checkins] icinga.org: icinga-core/mfriedrich/cgis: classic-ui: removed usage of javascript in trends.cgi during service selection #2412

git at icinga.org git at icinga.org
Thu Apr 19 12:07:14 CEST 2012


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

Author: Ricardo Bartels <ricardo at bitchbrothers.com>
Date:   Sat Apr 14 01:14:33 2012 +0200

classic-ui: removed usage of javascript in trends.cgi during service selection #2412

refs: #2412

the same as in avail.cgi

---

 cgi/trends.c |   56 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/cgi/trends.c b/cgi/trends.c
index 1bc31d7..5ebe2df 100644
--- a/cgi/trends.c
+++ b/cgi/trends.c
@@ -235,10 +235,8 @@ int main(int argc, char **argv) {
 	host *temp_host = NULL;
 	service *temp_service = NULL;
 	int is_authorized = TRUE;
-	int found = FALSE;
 	int problem_found = FALSE;
 	int days, hours, minutes, seconds;
-	char *first_service = NULL;
 	time_t t3;
 	time_t current_time;
 	struct tm *t;
@@ -900,46 +898,24 @@ int main(int argc, char **argv) {
 		/* ask the user for what service they want a report for */
 		else if (input_type == GET_INPUT_SERVICE_TARGET) {
 
-			printf("<SCRIPT LANGUAGE='JavaScript'>\n");
-			printf("function gethostname(hostindex){\n");
-			printf("hostnames=[");
-
-			for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
-				if (is_authorized_for_service(temp_service, &current_authdata) == TRUE) {
-					if (found == TRUE)
-						printf(",");
-					else
-						first_service = temp_service->host_name;
-					printf(" \"%s\"", temp_service->host_name);
-					found = TRUE;
-				}
-			}
-
-			printf(" ]\n");
-			printf("return hostnames[hostindex];\n");
-			printf("}\n");
-			printf("</SCRIPT>\n");
-
-
 			printf("<P><DIV ALIGN=CENTER>\n");
 			printf("<DIV CLASS='reportSelectTitle'>Step 2: Select Service</DIV>\n");
 			printf("</DIV></P>\n");
 
 			printf("<P><DIV ALIGN=CENTER>\n");
 
-			printf("<form method=\"GET\" action=\"%s\" name=\"serviceform\">\n", TRENDS_CGI);
+			printf("<form method=\"POST\" action=\"%s\" name=\"serviceform\">\n", TRENDS_CGI);
 			printf("<input type='hidden' name='input' value='getoptions'>\n");
-			printf("<input type='hidden' name='host' value='%s'>\n", (first_service == NULL) ? "unknown" : (char *)escape_string(first_service));
 
 			printf("<TABLE BORDER=0 cellpadding=5>\n");
 			printf("<tr><td class='reportSelectSubTitle'>Service:</td>\n");
 			printf("<td 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("<select name='hostservice'>\n");
 
 			for (temp_service = service_list; temp_service != NULL; temp_service = temp_service->next) {
 				if (is_authorized_for_service(temp_service, &current_authdata) == TRUE)
 					temp_host = find_host(temp_service->host_name);
-				printf("<option value='%s'>%s;%s\n", escape_string(temp_service->description), (temp_host->display_name != NULL) ? temp_host->display_name : temp_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_host->display_name != NULL) ? temp_host->display_name : temp_host->name, (temp_service->display_name != NULL) ? temp_service->display_name : temp_service->description);
 			}
 
 			printf("</select>\n");
@@ -1171,6 +1147,7 @@ int main(int argc, char **argv) {
 
 int process_cgivars(void) {
 	char **variables;
+	char *temp_buffer = NULL;
 	int error = FALSE;
 	int x;
 
@@ -1214,6 +1191,31 @@ int process_cgivars(void) {
 			display_type = DISPLAY_SERVICE_TRENDS;
 		}
 
+		/* 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_TRENDS;
+		}
+
 		/* we found first time argument */
 		else if (!strcmp(variables[x], "t1")) {
 			x++;





More information about the icinga-checkins mailing list