summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_curl.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 43d5961..4b17b25 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -133,7 +133,7 @@ char *server_url = 0;
133char server_ip[DEFAULT_BUFFER_SIZE]; 133char server_ip[DEFAULT_BUFFER_SIZE];
134struct curl_slist *server_ips = NULL; 134struct curl_slist *server_ips = NULL;
135unsigned short server_port = HTTP_PORT; 135unsigned short server_port = HTTP_PORT;
136int virtual_port = 0; 136unsigned short virtual_port = 0;
137int host_name_length; 137int host_name_length;
138char output_header_search[30] = ""; 138char output_header_search[30] = "";
139char output_string_search[30] = ""; 139char output_string_search[30] = "";
@@ -256,8 +256,10 @@ main (int argc, char **argv)
256 256
257 if (display_html == TRUE) 257 if (display_html == TRUE)
258 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", 258 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
259 use_ssl ? "https" : "http", host_name ? host_name : server_address, 259 use_ssl ? "https" : "http",
260 server_port, server_url); 260 host_name ? host_name : server_address,
261 virtual_port ? virtual_port : server_port,
262 server_url);
261 263
262 result = check_http (); 264 result = check_http ();
263 return result; 265 return result;
@@ -357,14 +359,24 @@ check_http (void)
357 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT"); 359 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_TIMEOUT, socket_timeout), "CURLOPT_TIMEOUT");
358 360
359 /* compose URL: must be the host_name, only if not given take the IP address. */ 361 /* compose URL: must be the host_name, only if not given take the IP address. */
360 snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s%s", use_ssl ? "https" : "http", 362 if ((use_ssl == FALSE && virtual_port == HTTP_PORT) ||
361 host_name ? host_name : server_address, server_url); 363 (use_ssl == TRUE && virtual_port == HTTPS_PORT))
364 snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s%s", use_ssl ? "https" : "http",
365 host_name ? host_name : server_address, server_url);
366 else
367 snprintf (url, DEFAULT_BUFFER_SIZE, "%s://%s:%d%s", use_ssl ? "https" : "http",
368 host_name ? host_name : server_address, virtual_port, server_url);
362 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, url), "CURLOPT_URL"); 369 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, url), "CURLOPT_URL");
363 370
364 /* cURL does certificate checking with this host_name (and not the virtual host? 371 /* cURL does certificate checking against the host name from the URL above
365 * So we force CURLOPT_RESOLVE to make sure the resolver pickes the right IP 372 * So we use CURLOPT_CONNECT_TO or CURLOPT_RESOLVE to handle differing
366 * for this hostname. */ 373 * host names and/or ports */
367#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 3) 374#if LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 49, 0)
375 snprintf (server_ip, DEFAULT_BUFFER_SIZE, "%s:%d:%s:%d", host_name ? host_name : server_address, virtual_port, server_address, server_port);
376 server_ips = curl_slist_append (server_ips, server_ip);
377 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CONNECT_TO, server_ips), "CURLOPT_CONNECT_TO");
378
379#elif LIBCURL_VERSION_NUM >= MAKE_LIBCURL_VERSION(7, 21, 3)
368 if (host_name && strcmp (host_name, server_address)) { 380 if (host_name && strcmp (host_name, server_address)) {
369 snprintf (server_ip, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address); 381 snprintf (server_ip, DEFAULT_BUFFER_SIZE, "%s:%d:%s", host_name, server_port, server_address);
370 server_ips = curl_slist_append (server_ips, server_ip); 382 server_ips = curl_slist_append (server_ips, server_ip);
@@ -380,10 +392,6 @@ check_http (void)
380 printf ("* curl CURLOPT_PROXY: %s:%d\n", server_address, server_port); 392 printf ("* curl CURLOPT_PROXY: %s:%d\n", server_address, server_port);
381 http_method = "GET"; 393 http_method = "GET";
382 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, server_url), "CURLOPT_URL"); 394 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_URL, server_url), "CURLOPT_URL");
383 virtual_port = use_ssl ? HTTPS_PORT : HTTP_PORT;
384 } else {
385 /* set port */
386 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_PORT, server_port), "CURLOPT_PORT");
387 } 395 }
388 396
389 /* set HTTP method */ 397 /* set HTTP method */
@@ -396,7 +404,7 @@ check_http (void)
396 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, http_method), "CURLOPT_CUSTOMREQUEST"); 404 handle_curl_option_return_code (curl_easy_setopt (curl, CURLOPT_CUSTOMREQUEST, http_method), "CURLOPT_CUSTOMREQUEST");
397 } 405 }
398 406
399 /* set hostname (virtual hosts) */ 407 /* set hostname (virtual hosts), not needed if CURLOPT_CONNECT_TO is used, but left in anyway */
400 if(host_name != NULL) { 408 if(host_name != NULL) {
401 if((virtual_port != HTTP_PORT && !use_ssl) || (virtual_port != HTTPS_PORT && use_ssl)) { 409 if((virtual_port != HTTP_PORT && !use_ssl) || (virtual_port != HTTPS_PORT && use_ssl)) {
402 snprintf(http_header, DEFAULT_BUFFER_SIZE, "Host: %s:%d", host_name, virtual_port); 410 snprintf(http_header, DEFAULT_BUFFER_SIZE, "Host: %s:%d", host_name, virtual_port);
@@ -1189,7 +1197,7 @@ process_arguments (int argc, char **argv)
1189 host_name_length = strlen (host_name) - strlen (p) - 1; 1197 host_name_length = strlen (host_name) - strlen (p) - 1;
1190 free (host_name); 1198 free (host_name);
1191 host_name = strndup (optarg, host_name_length); 1199 host_name = strndup (optarg, host_name_length);
1192 } 1200 }
1193 } else if ((p = strchr (host_name, ':')) != NULL 1201 } else if ((p = strchr (host_name, ':')) != NULL
1194 && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */ 1202 && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */
1195 virtual_port = atoi (p); 1203 virtual_port = atoi (p);
@@ -1530,6 +1538,11 @@ process_arguments (int argc, char **argv)
1530 1538
1531 if (virtual_port == 0) 1539 if (virtual_port == 0)
1532 virtual_port = server_port; 1540 virtual_port = server_port;
1541 else {
1542 if ((use_ssl && server_port == HTTPS_PORT) ||
1543 (!use_ssl && server_port == HTTP_PORT))
1544 server_port = virtual_port;
1545 }
1533 1546
1534 return TRUE; 1547 return TRUE;
1535} 1548}