]> git.pld-linux.org Git - packages/nagios.git/blame - nagios-googlemap.patch
Rediff patches.
[packages/nagios.git] / nagios-googlemap.patch
CommitLineData
2a5edde2
AM
1diff -urNp -x '*.orig' nagios-4.4.6.org/cgi/statusmap.c nagios-4.4.6/cgi/statusmap.c
2--- nagios-4.4.6.org/cgi/statusmap.c 2021-04-19 12:03:46.639619108 +0200
3+++ nagios-4.4.6/cgi/statusmap.c 2021-04-19 12:03:46.922960869 +0200
4@@ -25,6 +25,10 @@
6442e2ee
ER
5 *
6 *****************************************************************************/
7
8+#include <stdio.h>
9+#include <stdlib.h>
10+#include <string.h>
11+
12 #include "../include/config.h"
13 #include "../include/common.h"
14 #include "../include/objects.h"
2a5edde2 15@@ -89,6 +93,7 @@ extern int default_statusmap_layout_meth
6442e2ee
ER
16 #define LAYOUT_CIRCULAR 4
17 #define LAYOUT_CIRCULAR_MARKUP 5
18 #define LAYOUT_CIRCULAR_BALLOON 6
e277f689
AM
19+#define LAYOUT_GOOGLEMAP 7
20
6442e2ee 21
e277f689 22 struct layer {
2a5edde2 23@@ -96,6 +101,20 @@ struct layer {
e277f689
AM
24 struct layer *next;
25 };
6442e2ee 26
e277f689 27+struct location_t {
6442e2ee
ER
28+ char* name;
29+ char* note;
30+ char* latitude;
31+ char* longitude;
32+ struct location_t* next;
e277f689 33+};
6442e2ee 34+
e277f689 35+struct general_location_t {
6442e2ee
ER
36+ char* key;
37+ char* zoom;
38+ char* latitude;
39+ char* longitude;
e277f689 40+};
6442e2ee
ER
41
42 void document_header(int);
43 void document_footer(void);
2a5edde2 44@@ -113,6 +132,10 @@ void load_background_image(void);
6442e2ee
ER
45 void draw_background_image(void);
46 void draw_background_extras(void);
47 void draw_host_links(void);
48+
49+void google_map(void);
50+void write_google_head_code(void);
51+
52 void draw_hosts(void);
2a5edde2
AM
53 void draw_host_text(char *, int, int);
54 void draw_text(char *, int, int, int);
55@@ -287,12 +310,11 @@ int main(int argc, char **argv) {
26cc3b6f
ER
56 /* initialize macros */
57 init_macros();
58
59-
60- document_header(TRUE);
61-
62 /* get authentication information */
63 get_authentication_information(&current_authdata);
64
65+ document_header(TRUE);
66+
67 /* display the network map... */
68 display_map();
69
2a5edde2 70@@ -344,9 +366,14 @@ void document_header(int use_stylesheet)
b7e814c5 71
6442e2ee
ER
72 /* write JavaScript code for popup window */
73 write_popup_code();
b7e814c5 74+ if (layout_method == LAYOUT_GOOGLEMAP)
6442e2ee
ER
75+ write_google_head_code();
76
77 printf("</head>\n");
f9ffdd32 78
b7e814c5 79+ if (layout_method == LAYOUT_GOOGLEMAP) {
6442e2ee
ER
80+ printf("<body onload='load()' onunload='GUnload()' CLASS='statusmap' name='mappage' id='mappage'>\n");
81+ } else
b7e814c5 82 printf("<body CLASS='statusmap' name='mappage' id='mappage'>\n");
6442e2ee
ER
83
84 /* include user SSI header */
2a5edde2 85@@ -718,9 +745,9 @@ void display_page_header(void) {
6442e2ee
ER
86 printf("<td align=right valign=top>\n");
87
a83427df 88 #ifdef LEGACY_GRAPHICAL_CGIS
f9ffdd32 89- printf("<form method=\"POST\" action=\"%s\">\n", STATUSMAP_CGI);
a83427df
ER
90+ printf("<form name=\"layoutform\" method=\"POST\" action=\"%s\">\n", STATUSMAP_CGI);
91 #else
92- printf("<form method=\"POST\" action=\"%s\">\n", LEGACY_STATUSMAP_CGI);
93+ printf("<form name=\"layoutform\" method=\"POST\" action=\"%s\">\n", LEGACY_STATUSMAP_CGI);
94 #endif
6442e2ee
ER
95 printf("<table border=0 CLASS='optBox'>\n");
96 printf("<tr><td valign=top>\n");
2a5edde2 97@@ -743,6 +770,7 @@ void display_page_header(void) {
f9ffdd32 98 printf("<option value=%d %s>Circular\n", LAYOUT_CIRCULAR, (layout_method == LAYOUT_CIRCULAR) ? "selected" : "");
99 printf("<option value=%d %s>Circular (Marked Up)\n", LAYOUT_CIRCULAR_MARKUP, (layout_method == LAYOUT_CIRCULAR_MARKUP) ? "selected" : "");
100 printf("<option value=%d %s>Circular (Balloon)\n", LAYOUT_CIRCULAR_BALLOON, (layout_method == LAYOUT_CIRCULAR_BALLOON) ? "selected" : "");
101+ printf("<option value=%d %s>Googlemap\n", LAYOUT_GOOGLEMAP, (layout_method == LAYOUT_GOOGLEMAP) ? "selected" : "");
6442e2ee
ER
102 printf("</select>\n");
103 printf("</td>\n");
104 printf("<td CLASS='optBoxItem'>\n");
2a5edde2 105@@ -839,6 +867,11 @@ void display_map(void) {
6442e2ee
ER
106 /* display page header */
107 display_page_header();
108
109+ if (layout_method==LAYOUT_GOOGLEMAP){
110+ google_map();
111+ return;
112+ }
113+
114 initialize_graphics();
115 draw_background_image();
116 draw_background_extras();
2a5edde2 117@@ -1585,10 +1618,19 @@ void draw_host_links(void) {
6442e2ee 118 return;
f9ffdd32 119 }
6442e2ee
ER
120
121+/* create the googlemap */
122+void google_map(void){
123+ printf("<!-- Produced by Infoflex Connect AB (http://www.infoflexconnect.se), Fredrik Nilsson and Rujinschi Remus. -->\n");
124+ printf("<P><DIV ALIGN=center>");
125+ printf("<div id='map' style='width: 800px; height: 500px'></div>");
126+ printf("</DIV></P>");
127+ printf("<!-- Produced by Infoflex Connect AB (http://www.infoflexconnect.se), Fredrik Nilsson and Rujinschi Remus. -->\n");
128
129+}
130
131 /* draws hosts */
f9ffdd32 132 void draw_hosts(void) {
6442e2ee
ER
133+
134 host *temp_host;
135 int x1, x2;
2a5edde2
AM
136 int y1;
137@@ -1608,6 +1650,8 @@ void draw_hosts(void) {
6442e2ee
ER
138 int translated_x;
139 int translated_y;
140
455492e8 141+ if (layout_method == LAYOUT_GOOGLEMAP)
6442e2ee 142+ return;
f9ffdd32 143
6442e2ee 144 /* user didn't supply any coordinates for hosts, so display a warning */
f9ffdd32 145 if(coordinates_were_specified == FALSE) {
2a5edde2 146@@ -2265,6 +2309,197 @@ void cleanup_graphics(void) {
6442e2ee
ER
147 /************************* MISC FUNCTIONS *************************/
148 /******************************************************************/
149
6442e2ee
ER
150+char* get_status_code(char* name)
151+{
152+ char* retVal;
153+ hoststatus *temp_status;
154+ temp_status=find_hoststatus(name);
155+
156+ /* strip nasty stuff from plugin output */
157+ sanitize_plugin_output(temp_status->plugin_output);
158+
159+ retVal=malloc(1000);
160+ retVal[0]=0;
161+ if(temp_status->status==HOST_DOWN){
162+ strcat(retVal,"Down");
163+ if(temp_status->problem_has_been_acknowledged==TRUE)
164+ strcat(retVal," (Acknowledged)");
165+ strcat(retVal, "");
166+ }
167+
168+ else if(temp_status->status==HOST_UNREACHABLE){
169+ strcat(retVal, "Unreachable");
170+ if(temp_status->problem_has_been_acknowledged==TRUE)
171+ strcat(retVal, " (Acknowledged)");
172+ strcat(retVal, "");
173+ }
174+
175+ else if(temp_status->status==HOST_UP)
176+ strcat(retVal, "Up");
177+
178+ else if(temp_status->status==HOST_PENDING)
179+ strcat(retVal, "Pending");
180+ return retVal;
181+}
182+
183+void write_google_head_code(void)
184+{
185+ char ch;
186+ char* ptr;
187+ int rc;
188+ FILE *fp;
189+ char stateinfo[1024];
190+ char line[1024];
191+ char key[1024];
192+ char value[1024];
b7e814c5 193+ char buf[256];
6442e2ee
ER
194+ char* filename;
195+ int state = 0;
196+ int counter = 0;
e277f689
AM
197+ struct general_location_t gen_loc;
198+ struct location_t* loc;
199+ struct location_t* loc_list=NULL;
6442e2ee
ER
200+
201+
202+/***************************************
203+ * parse location.cfg
204+ **************************************/
205+
206+ filename = "/etc/webapps/nagios/location.cfg";
207+ if((fp=fopen(filename, "r"))==NULL) {
208+ char* err_mess = "The file: location.cfg does not exist or could not be read";
209+ printf("<p>");
210+ printf("<font color=\"red\">%s</font>\r\n",err_mess);
211+ printf("</p>");
212+ return;
213+ }
214+
215+ while(fgets(buf, sizeof(buf), fp)!=NULL) {
216+ if ( (state == 1) && (buf[0] == '}')) {
217+ // we have reached a definition end
218+ state = 0;
219+ counter++;
220+ if (loc_list) {
221+ loc->next = loc_list;
222+ loc_list = loc;
223+ } else {
224+ loc_list = loc;
225+ }
226+ loc = NULL;
227+ continue;
228+ }
229+ if ( (state==2) && (buf[0] == '}')) {
230+ state=0;
231+ }
232+ key[0] = value[0] = 0;
233+ if (isspace(buf[0]))
234+ rc = sscanf(buf, "%*[ \t]%[^ \t]%*[ \t]%[^\n]", key, value);
235+ else
236+ rc = sscanf(buf, "%[^ \t]%*[ \t]%[^\n]", key, value);
237+
238+ if ( (rc == 2)) {
239+ if ( (state == 0) && (strcmp(key,"define")==0) ) {
240+ // we have a start of a new definition
241+
242+ // check if it is the default definition
243+ if ( (strncmp(value,"default ",8)==0) ||
244+ (strncmp(value,"default{",8)==0)) {
245+ state=2;
246+ continue;
247+ }
248+ state = 1;
249+ // declare a new location
250+ loc = calloc(1,sizeof(*loc));
251+ continue;
252+ }
253+ // state 2 == default definition
254+ if ( state == 2 ) {
255+ if ( strcmp(key,"key") == 0) {
256+ gen_loc.key=strdup(value);
257+ }
258+ if ( strcmp(key,"zoom") == 0) {
259+ gen_loc.zoom=strdup(value);
260+ }
261+ if ( strcmp(key,"lat") == 0) {
262+ gen_loc.latitude=strdup(value);
263+ }
264+ if ( strcmp(key,"long") == 0) {
265+ gen_loc.longitude=strdup(value);
266+ }
267+ }
268+ // state 1 == location definition
269+ if ( state == 1 ) {
270+ if ( strcmp(key,"host_name") == 0) {
271+ loc->name=strdup(value);
b7e814c5 272+ }
6442e2ee
ER
273+ if ( strcmp(key,"notes") == 0) {
274+ loc->note = strdup(value);
275+ }
276+ if ( strcmp(key,"lat") == 0) {
277+ loc->latitude = strdup(value);
278+ }
279+ if ( strcmp(key,"long") == 0) {
280+ loc->longitude = strdup(value);
281+ }
282+ }
283+ }
284+ }
285+ fclose(fp);
286+
6442e2ee 287+
455492e8
ER
288+ printf("<script type='text/javascript'>\n");
289+ printf("gstatusmap = {\n");
290+ printf("lat:%s,\n", gen_loc.latitude);
291+ printf("lng:%s,\n", gen_loc.longitude);
292+ if (user_supplied_scaling==TRUE) {
293+ printf("scale: '%2.1f',\n", user_scaling_factor);
6442e2ee 294+ } else {
455492e8 295+ printf("scale: '%2.1f',\n", gen_loc.zoom);
6442e2ee
ER
296+ user_scaling_factor = atof(gen_loc.zoom);
297+ }
455492e8
ER
298+ printf("markers: [\n");
299+
6442e2ee
ER
300+ loc = loc_list;
301+ while (loc) {
302+ // check if allowed to show hostname first
303+ host* temp_host=find_host(loc->name);
304+ int in_layer_list=FALSE;
305+ in_layer_list=is_host_in_layer_list(temp_host);
306+
307+ if ( !is_authorized_for_host(temp_host,&current_authdata) && !is_host_in_layer_list(temp_host)) {
308+ loc = loc->next;
309+ continue;
310+ } else {
311+ if((in_layer_list==TRUE && exclude_layers==TRUE) || (in_layer_list==FALSE && exclude_layers==FALSE))
312+ {
313+ loc = loc->next;
314+ continue;
315+ }
316+ ptr = get_status_code(loc->name);
317+ strcpy(stateinfo,ptr);
318+ free(ptr);
319+
320+
455492e8 321+ printf("['%s','",loc->name);
6442e2ee
ER
322+ ptr = loc->note;
323+ while ((ch = *ptr++)) {
324+ if (ch == '\'') printf("\\'");
325+ else printf("%c", ch);
326+ }
455492e8 327+ printf("',%s,%s,'%s'],\n",loc->latitude,loc->longitude,stateinfo);
6442e2ee
ER
328+
329+ loc = loc->next;
330+ }
331+ }
455492e8
ER
332+
333+ printf("0], \n");
334+ printf("images_url: '%s'\n", url_images_path);
335+ printf("};\n");
336+ printf("</script>\n");
337+
338+ printf("<script src='http://maps.google.com/maps?file=api&amp;v=2&key=%s&amp;sensor=false' type='text/javascript'></script>\n",gen_loc.key);
339+ printf("<script src='%sgooglemap.js' type='text/javascript'></script>\n", url_images_path);
6442e2ee
ER
340+}
341
342 /* write JavaScript code an layer for popup window */
2a5edde2 343 void write_popup_code(void) {
This page took 0.132632 seconds and 4 git commands to generate.