summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c
index 9ff572e..b86b264 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -21,7 +21,7 @@
21 21
22const char *progname = "check_http"; 22const char *progname = "check_http";
23const char *revision = "$Revision$"; 23const char *revision = "$Revision$";
24const char *copyright = "1999-2004"; 24const char *copyright = "1999-2005";
25const char *email = "nagiosplug-devel@lists.sourceforge.net"; 25const char *email = "nagiosplug-devel@lists.sourceforge.net";
26 26
27#include "common.h" 27#include "common.h"
@@ -32,9 +32,9 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
32 32
33#define HTTP_EXPECT "HTTP/1." 33#define HTTP_EXPECT "HTTP/1."
34enum { 34enum {
35 MAX_IPV4_HOSTLENGTH = 255, 35 MAX_IPV4_HOSTLENGTH = 255,
36 HTTP_PORT = 80, 36 HTTP_PORT = 80,
37 HTTPS_PORT = 443 37 HTTPS_PORT = 443
38}; 38};
39 39
40#ifdef HAVE_SSL 40#ifdef HAVE_SSL
@@ -53,8 +53,8 @@ int maximum_age = -1;
53 53
54#ifdef HAVE_REGEX_H 54#ifdef HAVE_REGEX_H
55enum { 55enum {
56 REGS = 2, 56 REGS = 2,
57 MAX_RE_SIZE = 256 57 MAX_RE_SIZE = 256
58}; 58};
59#include <regex.h> 59#include <regex.h>
60regex_t preg; 60regex_t preg;
@@ -117,36 +117,36 @@ void print_usage (void);
117int 117int
118main (int argc, char **argv) 118main (int argc, char **argv)
119{ 119{
120 int result = STATE_UNKNOWN; 120 int result = STATE_UNKNOWN;
121 121
122 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ 122 /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */
123 server_url = strdup(HTTP_URL); 123 server_url = strdup(HTTP_URL);
124 server_url_length = strlen(server_url); 124 server_url_length = strlen(server_url);
125 asprintf (&user_agent, "User-Agent: check_http/%s (nagios-plugins %s)", 125 asprintf (&user_agent, "User-Agent: check_http/%s (nagios-plugins %s)",
126 clean_revstring (revision), VERSION); 126 clean_revstring (revision), VERSION);
127 127
128 if (process_arguments (argc, argv) == ERROR) 128 if (process_arguments (argc, argv) == ERROR)
129 usage4 (_("Could not parse arguments")); 129 usage4 (_("Could not parse arguments"));
130 130
131 if (strstr (timestamp, ":")) { 131 if (strstr (timestamp, ":")) {
132 if (strstr (server_url, "?")) 132 if (strstr (server_url, "?"))
133 asprintf (&server_url, "%s&%s", server_url, timestamp); 133 asprintf (&server_url, "%s&%s", server_url, timestamp);
134 else 134 else
135 asprintf (&server_url, "%s?%s", server_url, timestamp); 135 asprintf (&server_url, "%s?%s", server_url, timestamp);
136 } 136 }
137 137
138 if (display_html == TRUE) 138 if (display_html == TRUE)
139 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", 139 printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
140 use_ssl ? "https" : "http", host_name, 140 use_ssl ? "https" : "http", host_name,
141 server_port, server_url); 141 server_port, server_url);
142 142
143 /* initialize alarm signal handling, set socket timeout, start timer */ 143 /* initialize alarm signal handling, set socket timeout, start timer */
144 (void) signal (SIGALRM, socket_timeout_alarm_handler); 144 (void) signal (SIGALRM, socket_timeout_alarm_handler);
145 (void) alarm (socket_timeout); 145 (void) alarm (socket_timeout);
146 gettimeofday (&tv, NULL); 146 gettimeofday (&tv, NULL);
147 147
148 result = check_http (); 148 result = check_http ();
149 return result; 149 return result;
150} 150}
151 151
152 152
@@ -155,242 +155,242 @@ main (int argc, char **argv)
155int 155int
156process_arguments (int argc, char **argv) 156process_arguments (int argc, char **argv)
157{ 157{
158 int c = 1; 158 int c = 1;
159 159
160 int option = 0; 160 int option = 0;
161 static struct option longopts[] = { 161 static struct option longopts[] = {
162 STD_LONG_OPTS, 162 STD_LONG_OPTS,
163 {"file",required_argument,0,'F'}, 163 {"file",required_argument,0,'F'},
164 {"link", no_argument, 0, 'L'}, 164 {"link", no_argument, 0, 'L'},
165 {"nohtml", no_argument, 0, 'n'}, 165 {"nohtml", no_argument, 0, 'n'},
166 {"ssl", no_argument, 0, 'S'}, 166 {"ssl", no_argument, 0, 'S'},
167 {"verbose", no_argument, 0, 'v'}, 167 {"verbose", no_argument, 0, 'v'},
168 {"post", required_argument, 0, 'P'}, 168 {"post", required_argument, 0, 'P'},
169 {"IP-address", required_argument, 0, 'I'}, 169 {"IP-address", required_argument, 0, 'I'},
170 {"url", required_argument, 0, 'u'}, 170 {"url", required_argument, 0, 'u'},
171 {"string", required_argument, 0, 's'}, 171 {"string", required_argument, 0, 's'},
172 {"regex", required_argument, 0, 'r'}, 172 {"regex", required_argument, 0, 'r'},
173 {"ereg", required_argument, 0, 'r'}, 173 {"ereg", required_argument, 0, 'r'},
174 {"eregi", required_argument, 0, 'R'}, 174 {"eregi", required_argument, 0, 'R'},
175 {"linespan", no_argument, 0, 'l'}, 175 {"linespan", no_argument, 0, 'l'},
176 {"onredirect", required_argument, 0, 'f'}, 176 {"onredirect", required_argument, 0, 'f'},
177 {"certificate", required_argument, 0, 'C'}, 177 {"certificate", required_argument, 0, 'C'},
178 {"useragent", required_argument, 0, 'A'}, 178 {"useragent", required_argument, 0, 'A'},
179 {"header", required_argument, 0, 'k'}, 179 {"header", required_argument, 0, 'k'},
180 {"no-body", no_argument, 0, 'N'}, 180 {"no-body", no_argument, 0, 'N'},
181 {"max-age", required_argument, 0, 'M'}, 181 {"max-age", required_argument, 0, 'M'},
182 {"content-type", required_argument, 0, 'T'}, 182 {"content-type", required_argument, 0, 'T'},
183 {"pagesize", required_argument, 0, 'm'}, 183 {"pagesize", required_argument, 0, 'm'},
184 {"use-ipv4", no_argument, 0, '4'}, 184 {"use-ipv4", no_argument, 0, '4'},
185 {"use-ipv6", no_argument, 0, '6'}, 185 {"use-ipv6", no_argument, 0, '6'},
186 {0, 0, 0, 0} 186 {0, 0, 0, 0}
187 }; 187 };
188 188
189 if (argc < 2) 189 if (argc < 2)
190 return ERROR; 190 return ERROR;
191 191
192 for (c = 1; c < argc; c++) { 192 for (c = 1; c < argc; c++) {
193 if (strcmp ("-to", argv[c]) == 0) 193 if (strcmp ("-to", argv[c]) == 0)
194 strcpy (argv[c], "-t"); 194 strcpy (argv[c], "-t");
195 if (strcmp ("-hn", argv[c]) == 0) 195 if (strcmp ("-hn", argv[c]) == 0)
196 strcpy (argv[c], "-H"); 196 strcpy (argv[c], "-H");
197 if (strcmp ("-wt", argv[c]) == 0) 197 if (strcmp ("-wt", argv[c]) == 0)
198 strcpy (argv[c], "-w"); 198 strcpy (argv[c], "-w");
199 if (strcmp ("-ct", argv[c]) == 0) 199 if (strcmp ("-ct", argv[c]) == 0)
200 strcpy (argv[c], "-c"); 200 strcpy (argv[c], "-c");
201 if (strcmp ("-nohtml", argv[c]) == 0) 201 if (strcmp ("-nohtml", argv[c]) == 0)
202 strcpy (argv[c], "-n"); 202 strcpy (argv[c], "-n");
203 } 203 }
204 204
205 while (1) { 205 while (1) {
206 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option); 206 c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:T:I:a:e:p:s:R:r:u:f:C:nlLSm:M:N", longopts, &option);
207 if (c == -1 || c == EOF) 207 if (c == -1 || c == EOF)
208 break; 208 break;
209 209
210 switch (c) { 210 switch (c) {
211 case '?': /* usage */ 211 case '?': /* usage */
212 usage2 (_("Unknown argument"), optarg); 212 usage2 (_("Unknown argument"), optarg);
213 break; 213 break;
214 case 'h': /* help */ 214 case 'h': /* help */
215 print_help (); 215 print_help ();
216 exit (STATE_OK); 216 exit (STATE_OK);
217 break; 217 break;
218 case 'V': /* version */ 218 case 'V': /* version */
219 print_revision (progname, revision); 219 print_revision (progname, revision);
220 exit (STATE_OK); 220 exit (STATE_OK);
221 break; 221 break;
222 case 't': /* timeout period */ 222 case 't': /* timeout period */
223 if (!is_intnonneg (optarg)) 223 if (!is_intnonneg (optarg))
224 usage2 (_("Timeout interval must be a positive integer"), optarg); 224 usage2 (_("Timeout interval must be a positive integer"), optarg);
225 else 225 else
226 socket_timeout = atoi (optarg); 226 socket_timeout = atoi (optarg);
227 break; 227 break;
228 case 'c': /* critical time threshold */ 228 case 'c': /* critical time threshold */
229 if (!is_nonnegative (optarg)) 229 if (!is_nonnegative (optarg))
230 usage2 (_("Critical threshold must be integer"), optarg); 230 usage2 (_("Critical threshold must be integer"), optarg);
231 else { 231 else {
232 critical_time = strtod (optarg, NULL); 232 critical_time = strtod (optarg, NULL);
233 check_critical_time = TRUE; 233 check_critical_time = TRUE;
234 } 234 }
235 break; 235 break;
236 case 'w': /* warning time threshold */ 236 case 'w': /* warning time threshold */
237 if (!is_nonnegative (optarg)) 237 if (!is_nonnegative (optarg))
238 usage2 (_("Warning threshold must be integer"), optarg); 238 usage2 (_("Warning threshold must be integer"), optarg);
239 else { 239 else {
240 warning_time = strtod (optarg, NULL); 240 warning_time = strtod (optarg, NULL);
241 check_warning_time = TRUE; 241 check_warning_time = TRUE;
242 } 242 }
243 break; 243 break;
244 case 'A': /* User Agent String */ 244 case 'A': /* User Agent String */
245 asprintf (&user_agent, "User-Agent: %s", optarg); 245 asprintf (&user_agent, "User-Agent: %s", optarg);
246 break; 246 break;
247 case 'k': /* Additional headers */ 247 case 'k': /* Additional headers */
248 asprintf (&http_opt_headers, "%s", optarg); 248 asprintf (&http_opt_headers, "%s", optarg);
249 break; 249 break;
250 case 'L': /* show html link */ 250 case 'L': /* show html link */
251 display_html = TRUE; 251 display_html = TRUE;
252 break; 252 break;
253 case 'n': /* do not show html link */ 253 case 'n': /* do not show html link */
254 display_html = FALSE; 254 display_html = FALSE;
255 break; 255 break;
256 case 'S': /* use SSL */ 256 case 'S': /* use SSL */
257#ifndef HAVE_SSL 257#ifndef HAVE_SSL
258 usage4 (_("Invalid option - SSL is not available")); 258 usage4 (_("Invalid option - SSL is not available"));
259#endif 259#endif
260 use_ssl = TRUE; 260 use_ssl = TRUE;
261 if (specify_port == FALSE) 261 if (specify_port == FALSE)
262 server_port = HTTPS_PORT; 262 server_port = HTTPS_PORT;
263 break; 263 break;
264 case 'C': /* Check SSL cert validity */ 264 case 'C': /* Check SSL cert validity */
265#ifdef USE_OPENSSL 265#ifdef USE_OPENSSL
266 if (!is_intnonneg (optarg)) 266 if (!is_intnonneg (optarg))
267 usage2 (_("Invalid certificate expiration period"), optarg); 267 usage2 (_("Invalid certificate expiration period"), optarg);
268 else { 268 else {
269 days_till_exp = atoi (optarg); 269 days_till_exp = atoi (optarg);
270 check_cert = TRUE; 270 check_cert = TRUE;
271 } 271 }
272#else 272#else
273 usage4 (_("Invalid option - SSL is not available")); 273 usage4 (_("Invalid option - SSL is not available"));
274#endif 274#endif
275 break; 275 break;
276 case 'f': /* onredirect */ 276 case 'f': /* onredirect */
277 if (!strcmp (optarg, "follow")) 277 if (!strcmp (optarg, "follow"))
278 onredirect = STATE_DEPENDENT; 278 onredirect = STATE_DEPENDENT;
279 if (!strcmp (optarg, "unknown")) 279 if (!strcmp (optarg, "unknown"))
280 onredirect = STATE_UNKNOWN; 280 onredirect = STATE_UNKNOWN;
281 if (!strcmp (optarg, "ok")) 281 if (!strcmp (optarg, "ok"))
282 onredirect = STATE_OK; 282 onredirect = STATE_OK;
283 if (!strcmp (optarg, "warning")) 283 if (!strcmp (optarg, "warning"))
284 onredirect = STATE_WARNING; 284 onredirect = STATE_WARNING;
285 if (!strcmp (optarg, "critical")) 285 if (!strcmp (optarg, "critical"))
286 onredirect = STATE_CRITICAL; 286 onredirect = STATE_CRITICAL;
287 if (verbose) 287 if (verbose)
288 printf(_("option f:%d \n"), onredirect); 288 printf(_("option f:%d \n"), onredirect);
289 break; 289 break;
290 /* Note: H, I, and u must be malloc'd or will fail on redirects */ 290 /* Note: H, I, and u must be malloc'd or will fail on redirects */
291 case 'H': /* Host Name (virtual host) */ 291 case 'H': /* Host Name (virtual host) */
292 host_name = strdup (optarg); 292 host_name = strdup (optarg);
293 if (strstr (optarg, ":")) 293 if (strstr (optarg, ":"))
294 sscanf (optarg, "%*[^:]:%d", &server_port); 294 sscanf (optarg, "%*[^:]:%d", &server_port);
295 break; 295 break;
296 case 'I': /* Server IP-address */ 296 case 'I': /* Server IP-address */
297 server_address = strdup (optarg); 297 server_address = strdup (optarg);
298 break; 298 break;
299 case 'u': /* URL path */ 299 case 'u': /* URL path */
300 server_url = strdup (optarg); 300 server_url = strdup (optarg);
301 server_url_length = strlen (server_url); 301 server_url_length = strlen (server_url);
302 break; 302 break;
303 case 'p': /* Server port */ 303 case 'p': /* Server port */
304 if (!is_intnonneg (optarg)) 304 if (!is_intnonneg (optarg))
305 usage2 (_("Invalid port number"), optarg); 305 usage2 (_("Invalid port number"), optarg);
306 else { 306 else {
307 server_port = atoi (optarg); 307 server_port = atoi (optarg);
308 specify_port = TRUE; 308 specify_port = TRUE;
309 } 309 }
310 break; 310 break;
311 case 'a': /* authorization info */ 311 case 'a': /* authorization info */
312 strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1); 312 strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1);
313 user_auth[MAX_INPUT_BUFFER - 1] = 0; 313 user_auth[MAX_INPUT_BUFFER - 1] = 0;
314 break; 314 break;
315 case 'P': /* HTTP POST data in URL encoded format */ 315 case 'P': /* HTTP POST data in URL encoded format */
316 if (http_method || http_post_data) break; 316 if (http_method || http_post_data) break;
317 http_method = strdup("POST"); 317 http_method = strdup("POST");
318 http_post_data = strdup (optarg); 318 http_post_data = strdup (optarg);
319 break; 319 break;
320 case 's': /* string or substring */ 320 case 's': /* string or substring */
321 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); 321 strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1);
322 string_expect[MAX_INPUT_BUFFER - 1] = 0; 322 string_expect[MAX_INPUT_BUFFER - 1] = 0;
323 break; 323 break;
324 case 'e': /* string or substring */ 324 case 'e': /* string or substring */
325 strncpy (server_expect, optarg, MAX_INPUT_BUFFER - 1); 325 strncpy (server_expect, optarg, MAX_INPUT_BUFFER - 1);
326 server_expect[MAX_INPUT_BUFFER - 1] = 0; 326 server_expect[MAX_INPUT_BUFFER - 1] = 0;
327 server_expect_yn = 1; 327 server_expect_yn = 1;
328 break; 328 break;
329 case 'T': /* Content-type */ 329 case 'T': /* Content-type */
330 asprintf (&http_content_type, "%s", optarg); 330 asprintf (&http_content_type, "%s", optarg);
331 break; 331 break;
332#ifndef HAVE_REGEX_H 332#ifndef HAVE_REGEX_H
333 case 'l': /* linespan */ 333 case 'l': /* linespan */
334 case 'r': /* linespan */ 334 case 'r': /* linespan */
335 case 'R': /* linespan */ 335 case 'R': /* linespan */
336 usage4 (_("Call for regex which was not a compiled option")); 336 usage4 (_("Call for regex which was not a compiled option"));
337 break; 337 break;
338#else 338#else
339 case 'l': /* linespan */ 339 case 'l': /* linespan */
340 cflags &= ~REG_NEWLINE; 340 cflags &= ~REG_NEWLINE;
341 break; 341 break;
342 case 'R': /* regex */ 342 case 'R': /* regex */
343 cflags |= REG_ICASE; 343 cflags |= REG_ICASE;
344 case 'r': /* regex */ 344 case 'r': /* regex */
345 strncpy (regexp, optarg, MAX_RE_SIZE - 1); 345 strncpy (regexp, optarg, MAX_RE_SIZE - 1);
346 regexp[MAX_RE_SIZE - 1] = 0; 346 regexp[MAX_RE_SIZE - 1] = 0;
347 errcode = regcomp (&preg, regexp, cflags); 347 errcode = regcomp (&preg, regexp, cflags);
348 if (errcode != 0) { 348 if (errcode != 0) {
349 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 349 (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
350 printf (_("Could Not Compile Regular Expression: %s"), errbuf); 350 printf (_("Could Not Compile Regular Expression: %s"), errbuf);
351 return ERROR; 351 return ERROR;
352 } 352 }
353 break; 353 break;
354#endif 354#endif
355 case '4': 355 case '4':
356 address_family = AF_INET; 356 address_family = AF_INET;
357 break; 357 break;
358 case '6': 358 case '6':
359#ifdef USE_IPV6 359#ifdef USE_IPV6
360 address_family = AF_INET6; 360 address_family = AF_INET6;
361#else 361#else
362 usage4 (_("IPv6 support not available")); 362 usage4 (_("IPv6 support not available"));
363#endif 363#endif
364 break; 364 break;
365 case 'v': /* verbose */ 365 case 'v': /* verbose */
366 verbose = TRUE; 366 verbose = TRUE;
367 break; 367 break;
368 case 'm': /* min_page_length */ 368 case 'm': /* min_page_length */
369 { 369 {
370 char *tmp; 370 char *tmp;
371 if (strchr(optarg, ':') != (char *)NULL) { 371 if (strchr(optarg, ':') != (char *)NULL) {
372 /* range, so get two values, min:max */ 372 /* range, so get two values, min:max */
373 tmp = strtok(optarg, ":"); 373 tmp = strtok(optarg, ":");
374 if (tmp == NULL) { 374 if (tmp == NULL) {
375 printf("Bad format: try \"-m min:max\"\n"); 375 printf("Bad format: try \"-m min:max\"\n");
376 exit (STATE_WARNING); 376 exit (STATE_WARNING);
377 } else 377 } else
378 min_page_len = atoi(tmp); 378 min_page_len = atoi(tmp);
379 379
380 tmp = strtok(NULL, ":"); 380 tmp = strtok(NULL, ":");
381 if (tmp == NULL) { 381 if (tmp == NULL) {
382 printf("Bad format: try \"-m min:max\"\n"); 382 printf("Bad format: try \"-m min:max\"\n");
383 exit (STATE_WARNING); 383 exit (STATE_WARNING);
384 } else 384 } else
385 max_page_len = atoi(tmp); 385 max_page_len = atoi(tmp);
386 } else 386 } else
387 min_page_len = atoi (optarg); 387 min_page_len = atoi (optarg);
388 break; 388 break;
389 } 389 }
390 case 'N': /* no-body */ 390 case 'N': /* no-body */
391 no_body = TRUE; 391 no_body = TRUE;
392 break; 392 break;
393 case 'M': /* max-age */ 393 case 'M': /* max-age */
394 { 394 {
395 int L = strlen(optarg); 395 int L = strlen(optarg);
396 if (L && optarg[L-1] == 'm') 396 if (L && optarg[L-1] == 'm')
@@ -408,31 +408,31 @@ process_arguments (int argc, char **argv)
408 } 408 }
409 } 409 }
410 break; 410 break;
411 } 411 }
412 } 412 }
413 413
414 c = optind; 414 c = optind;
415 415
416 if (server_address == NULL && c < argc) 416 if (server_address == NULL && c < argc)
417 server_address = strdup (argv[c++]); 417 server_address = strdup (argv[c++]);
418 418
419 if (host_name == NULL && c < argc) 419 if (host_name == NULL && c < argc)
420 host_name = strdup (argv[c++]); 420 host_name = strdup (argv[c++]);
421 421
422 if (server_address == NULL) { 422 if (server_address == NULL) {
423 if (host_name == NULL) 423 if (host_name == NULL)
424 usage4 (_("You must specify a server address or host name")); 424 usage4 (_("You must specify a server address or host name"));
425 else 425 else
426 server_address = strdup (host_name); 426 server_address = strdup (host_name);
427 } 427 }
428 428
429 if (check_critical_time && critical_time>(double)socket_timeout) 429 if (check_critical_time && critical_time>(double)socket_timeout)
430 socket_timeout = (int)critical_time + 1; 430 socket_timeout = (int)critical_time + 1;
431 431
432 if (http_method == NULL) 432 if (http_method == NULL)
433 http_method = strdup ("GET"); 433 http_method = strdup ("GET");
434 434
435 return TRUE; 435 return TRUE;
436} 436}
437 437
438 438
@@ -442,40 +442,40 @@ static char *
442base64 (const char *bin, size_t len) 442base64 (const char *bin, size_t len)
443{ 443{
444 444
445 char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1); 445 char *buf = (char *) malloc ((len + 2) / 3 * 4 + 1);
446 size_t i = 0, j = 0; 446 size_t i = 0, j = 0;
447 447
448 char BASE64_END = '='; 448 char BASE64_END = '=';
449 char base64_table[64]; 449 char base64_table[64];
450 strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64); 450 strncpy (base64_table, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", 64);
451 451
452 while (j < len - 2) { 452 while (j < len - 2) {
453 buf[i++] = base64_table[bin[j] >> 2]; 453 buf[i++] = base64_table[bin[j] >> 2];
454 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; 454 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
455 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)]; 455 buf[i++] = base64_table[((bin[j + 1] & 15) << 2) | (bin[j + 2] >> 6)];
456 buf[i++] = base64_table[bin[j + 2] & 63]; 456 buf[i++] = base64_table[bin[j + 2] & 63];
457 j += 3; 457 j += 3;
458 } 458 }
459 459
460 switch (len - j) { 460 switch (len - j) {
461 case 1: 461 case 1:
462 buf[i++] = base64_table[bin[j] >> 2]; 462 buf[i++] = base64_table[bin[j] >> 2];
463 buf[i++] = base64_table[(bin[j] & 3) << 4]; 463 buf[i++] = base64_table[(bin[j] & 3) << 4];
464 buf[i++] = BASE64_END; 464 buf[i++] = BASE64_END;
465 buf[i++] = BASE64_END; 465 buf[i++] = BASE64_END;
466 break; 466 break;
467 case 2: 467 case 2:
468 buf[i++] = base64_table[bin[j] >> 2]; 468 buf[i++] = base64_table[bin[j] >> 2];
469 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)]; 469 buf[i++] = base64_table[((bin[j] & 3) << 4) | (bin[j + 1] >> 4)];
470 buf[i++] = base64_table[(bin[j + 1] & 15) << 2]; 470 buf[i++] = base64_table[(bin[j + 1] & 15) << 2];
471 buf[i++] = BASE64_END; 471 buf[i++] = BASE64_END;
472 break; 472 break;
473 case 0: 473 case 0:
474 break; 474 break;
475 } 475 }
476 476
477 buf[i] = '\0'; 477 buf[i] = '\0';
478 return buf; 478 return buf;
479} 479}
480 480
481 481
@@ -484,109 +484,109 @@ base64 (const char *bin, size_t len)
484static int 484static int
485document_headers_done (char *full_page) 485document_headers_done (char *full_page)
486{ 486{
487 const char *body; 487 const char *body;
488 488
489 for (body = full_page; *body; body++) { 489 for (body = full_page; *body; body++) {
490 if (!strncmp (body, "\n\n", 2) || !strncmp (body, "\n\r\n", 3)) 490 if (!strncmp (body, "\n\n", 2) || !strncmp (body, "\n\r\n", 3))
491 break; 491 break;
492 } 492 }
493 493
494 if (!*body) 494 if (!*body)
495 return 0; /* haven't read end of headers yet */ 495 return 0; /* haven't read end of headers yet */
496 496
497 full_page[body - full_page] = 0; 497 full_page[body - full_page] = 0;
498 return 1; 498 return 1;
499} 499}
500 500
501static time_t 501static time_t
502parse_time_string (const char *string) 502parse_time_string (const char *string)
503{ 503{
504 struct tm tm; 504 struct tm tm;
505 time_t t; 505 time_t t;
506 memset (&tm, 0, sizeof(tm)); 506 memset (&tm, 0, sizeof(tm));
507 507
508 /* Like this: Tue, 25 Dec 2001 02:59:03 GMT */ 508 /* Like this: Tue, 25 Dec 2001 02:59:03 GMT */
509 509
510 if (isupper (string[0]) && /* Tue */ 510 if (isupper (string[0]) && /* Tue */
511 islower (string[1]) && 511 islower (string[1]) &&
512 islower (string[2]) && 512 islower (string[2]) &&
513 ',' == string[3] && 513 ',' == string[3] &&
514 ' ' == string[4] && 514 ' ' == string[4] &&
515 (isdigit(string[5]) || string[5] == ' ') && /* 25 */ 515 (isdigit(string[5]) || string[5] == ' ') && /* 25 */
516 isdigit (string[6]) && 516 isdigit (string[6]) &&
517 ' ' == string[7] && 517 ' ' == string[7] &&
518 isupper (string[8]) && /* Dec */ 518 isupper (string[8]) && /* Dec */
519 islower (string[9]) && 519 islower (string[9]) &&
520 islower (string[10]) && 520 islower (string[10]) &&
521 ' ' == string[11] && 521 ' ' == string[11] &&
522 isdigit (string[12]) && /* 2001 */ 522 isdigit (string[12]) && /* 2001 */
523 isdigit (string[13]) && 523 isdigit (string[13]) &&
524 isdigit (string[14]) && 524 isdigit (string[14]) &&
525 isdigit (string[15]) && 525 isdigit (string[15]) &&
526 ' ' == string[16] && 526 ' ' == string[16] &&
527 isdigit (string[17]) && /* 02: */ 527 isdigit (string[17]) && /* 02: */
528 isdigit (string[18]) && 528 isdigit (string[18]) &&
529 ':' == string[19] && 529 ':' == string[19] &&
530 isdigit (string[20]) && /* 59: */ 530 isdigit (string[20]) && /* 59: */
531 isdigit (string[21]) && 531 isdigit (string[21]) &&
532 ':' == string[22] && 532 ':' == string[22] &&
533 isdigit (string[23]) && /* 03 */ 533 isdigit (string[23]) && /* 03 */
534 isdigit (string[24]) && 534 isdigit (string[24]) &&
535 ' ' == string[25] && 535 ' ' == string[25] &&
536 'G' == string[26] && /* GMT */ 536 'G' == string[26] && /* GMT */
537 'M' == string[27] && /* GMT */ 537 'M' == string[27] && /* GMT */
538 'T' == string[28]) { 538 'T' == string[28]) {
539 539
540 tm.tm_sec = 10 * (string[23]-'0') + (string[24]-'0'); 540 tm.tm_sec = 10 * (string[23]-'0') + (string[24]-'0');
541 tm.tm_min = 10 * (string[20]-'0') + (string[21]-'0'); 541 tm.tm_min = 10 * (string[20]-'0') + (string[21]-'0');
542 tm.tm_hour = 10 * (string[17]-'0') + (string[18]-'0'); 542 tm.tm_hour = 10 * (string[17]-'0') + (string[18]-'0');
543 tm.tm_mday = 10 * (string[5] == ' ' ? 0 : string[5]-'0') + (string[6]-'0'); 543 tm.tm_mday = 10 * (string[5] == ' ' ? 0 : string[5]-'0') + (string[6]-'0');
544 tm.tm_mon = (!strncmp (string+8, "Jan", 3) ? 0 : 544 tm.tm_mon = (!strncmp (string+8, "Jan", 3) ? 0 :
545 !strncmp (string+8, "Feb", 3) ? 1 : 545 !strncmp (string+8, "Feb", 3) ? 1 :
546 !strncmp (string+8, "Mar", 3) ? 2 : 546 !strncmp (string+8, "Mar", 3) ? 2 :
547 !strncmp (string+8, "Apr", 3) ? 3 : 547 !strncmp (string+8, "Apr", 3) ? 3 :
548 !strncmp (string+8, "May", 3) ? 4 : 548 !strncmp (string+8, "May", 3) ? 4 :
549 !strncmp (string+8, "Jun", 3) ? 5 : 549 !strncmp (string+8, "Jun", 3) ? 5 :
550 !strncmp (string+8, "Jul", 3) ? 6 : 550 !strncmp (string+8, "Jul", 3) ? 6 :
551 !strncmp (string+8, "Aug", 3) ? 7 : 551 !strncmp (string+8, "Aug", 3) ? 7 :
552 !strncmp (string+8, "Sep", 3) ? 8 : 552 !strncmp (string+8, "Sep", 3) ? 8 :
553 !strncmp (string+8, "Oct", 3) ? 9 : 553 !strncmp (string+8, "Oct", 3) ? 9 :
554 !strncmp (string+8, "Nov", 3) ? 10 : 554 !strncmp (string+8, "Nov", 3) ? 10 :
555 !strncmp (string+8, "Dec", 3) ? 11 : 555 !strncmp (string+8, "Dec", 3) ? 11 :
556 -1); 556 -1);
557 tm.tm_year = ((1000 * (string[12]-'0') + 557 tm.tm_year = ((1000 * (string[12]-'0') +
558 100 * (string[13]-'0') + 558 100 * (string[13]-'0') +
559 10 * (string[14]-'0') + 559 10 * (string[14]-'0') +
560 (string[15]-'0')) 560 (string[15]-'0'))
561 - 1900); 561 - 1900);
562 562
563 tm.tm_isdst = 0; /* GMT is never in DST, right? */ 563 tm.tm_isdst = 0; /* GMT is never in DST, right? */
564 564
565 if (tm.tm_mon < 0 || tm.tm_mday < 1 || tm.tm_mday > 31) 565 if (tm.tm_mon < 0 || tm.tm_mday < 1 || tm.tm_mday > 31)
566 return 0; 566 return 0;
567 567
568 /* 568 /*
569 This is actually wrong: we need to subtract the local timezone 569 This is actually wrong: we need to subtract the local timezone
570 offset from GMT from this value. But, that's ok in this usage, 570 offset from GMT from this value. But, that's ok in this usage,
571 because we only comparing these two GMT dates against each other, 571 because we only comparing these two GMT dates against each other,
572 so it doesn't matter what time zone we parse them in. 572 so it doesn't matter what time zone we parse them in.
573 */ 573 */
574 574
575 t = mktime (&tm); 575 t = mktime (&tm);
576 if (t == (time_t) -1) t = 0; 576 if (t == (time_t) -1) t = 0;
577 577
578 if (verbose) { 578 if (verbose) {
579 const char *s = string; 579 const char *s = string;
580 while (*s && *s != '\r' && *s != '\n') 580 while (*s && *s != '\r' && *s != '\n')
581 fputc (*s++, stdout); 581 fputc (*s++, stdout);
582 printf (" ==> %lu\n", (unsigned long) t); 582 printf (" ==> %lu\n", (unsigned long) t);
583 } 583 }
584 584
585 return t; 585 return t;
586 586
587 } else { 587 } else {
588 return 0; 588 return 0;
589 } 589 }
590} 590}
591 591
592 592
@@ -594,82 +594,82 @@ parse_time_string (const char *string)
594static void 594static void
595check_document_dates (const char *headers) 595check_document_dates (const char *headers)
596{ 596{
597 const char *s; 597 const char *s;
598 char *server_date = 0; 598 char *server_date = 0;
599 char *document_date = 0; 599 char *document_date = 0;
600 600
601 s = headers; 601 s = headers;
602 while (*s) { 602 while (*s) {
603 const char *field = s; 603 const char *field = s;
604 const char *value = 0; 604 const char *value = 0;
605 605
606 /* Find the end of the header field */ 606 /* Find the end of the header field */
607 while (*s && !isspace(*s) && *s != ':') 607 while (*s && !isspace(*s) && *s != ':')
608 s++; 608 s++;
609 609
610 /* Remember the header value, if any. */ 610 /* Remember the header value, if any. */
611 if (*s == ':') 611 if (*s == ':')
612 value = ++s; 612 value = ++s;
613 613
614 /* Skip to the end of the header, including continuation lines. */ 614 /* Skip to the end of the header, including continuation lines. */
615 while (*s && !(*s == '\n' && (s[1] != ' ' && s[1] != '\t'))) 615 while (*s && !(*s == '\n' && (s[1] != ' ' && s[1] != '\t')))
616 s++; 616 s++;
617 s++; 617 s++;
618 618
619 /* Process this header. */ 619 /* Process this header. */
620 if (value && value > field+2) { 620 if (value && value > field+2) {
621 char *ff = (char *) malloc (value-field); 621 char *ff = (char *) malloc (value-field);
622 char *ss = ff; 622 char *ss = ff;
623 while (field < value-1) 623 while (field < value-1)
624 *ss++ = tolower(*field++); 624 *ss++ = tolower(*field++);
625 *ss++ = 0; 625 *ss++ = 0;
626 626
627 if (!strcmp (ff, "date") || !strcmp (ff, "last-modified")) { 627 if (!strcmp (ff, "date") || !strcmp (ff, "last-modified")) {
628 const char *e; 628 const char *e;
629 while (*value && isspace (*value)) 629 while (*value && isspace (*value))
630 value++; 630 value++;
631 for (e = value; *e && *e != '\r' && *e != '\n'; e++) 631 for (e = value; *e && *e != '\r' && *e != '\n'; e++)
632 ; 632 ;
633 ss = (char *) malloc (e - value + 1); 633 ss = (char *) malloc (e - value + 1);
634 strncpy (ss, value, e - value); 634 strncpy (ss, value, e - value);
635 ss[e - value] = 0; 635 ss[e - value] = 0;
636 if (!strcmp (ff, "date")) { 636 if (!strcmp (ff, "date")) {
637 if (server_date) free (server_date); 637 if (server_date) free (server_date);
638 server_date = ss; 638 server_date = ss;
639 } else { 639 } else {
640 if (document_date) free (document_date); 640 if (document_date) free (document_date);
641 document_date = ss; 641 document_date = ss;
642 } 642 }
643 } 643 }
644 free (ff); 644 free (ff);
645 } 645 }
646 } 646 }
647 647
648 /* Done parsing the body. Now check the dates we (hopefully) parsed. */ 648 /* Done parsing the body. Now check the dates we (hopefully) parsed. */
649 if (!server_date || !*server_date) { 649 if (!server_date || !*server_date) {
650 die (STATE_UNKNOWN, _("Server date unknown\n")); 650 die (STATE_UNKNOWN, _("Server date unknown\n"));
651 } else if (!document_date || !*document_date) { 651 } else if (!document_date || !*document_date) {
652 die (STATE_CRITICAL, _("Document modification date unknown\n")); 652 die (STATE_CRITICAL, _("Document modification date unknown\n"));
653 } else { 653 } else {
654 time_t srv_data = parse_time_string (server_date); 654 time_t srv_data = parse_time_string (server_date);
655 time_t doc_data = parse_time_string (document_date); 655 time_t doc_data = parse_time_string (document_date);
656 656
657 if (srv_data <= 0) { 657 if (srv_data <= 0) {
658 die (STATE_CRITICAL, _("CRITICAL - Server date \"%100s\" unparsable"), server_date); 658 die (STATE_CRITICAL, _("CRITICAL - Server date \"%100s\" unparsable"), server_date);
659 } else if (doc_data <= 0) { 659 } else if (doc_data <= 0) {
660 die (STATE_CRITICAL, _("CRITICAL - Document date \"%100s\" unparsable"), document_date); 660 die (STATE_CRITICAL, _("CRITICAL - Document date \"%100s\" unparsable"), document_date);
661 } else if (doc_data > srv_data + 30) { 661 } else if (doc_data > srv_data + 30) {
662 die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data); 662 die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
663 } else if (doc_data < srv_data - maximum_age) { 663 } else if (doc_data < srv_data - maximum_age) {
664 int n = (srv_data - doc_data); 664 int n = (srv_data - doc_data);
665 if (n > (60 * 60 * 24 * 2)) 665 if (n > (60 * 60 * 24 * 2))
666 die (STATE_CRITICAL, 666 die (STATE_CRITICAL,
667 _("CRITICAL - Last modified %.1f days ago\n"), 667 _("CRITICAL - Last modified %.1f days ago\n"),
668 ((float) n) / (60 * 60 * 24)); 668 ((float) n) / (60 * 60 * 24));
669 else 669 else
670 die (STATE_CRITICAL, 670 die (STATE_CRITICAL,
671 _("CRITICAL - Last modified %d:%02d:%02d ago\n"), 671 _("CRITICAL - Last modified %d:%02d:%02d ago\n"),
672 n / (60 * 60), (n / 60) % 60, n % 60); 672 n / (60 * 60), (n / 60) % 60, n % 60);
673 } 673 }
674 674
675 free (server_date); 675 free (server_date);
@@ -680,358 +680,358 @@ check_document_dates (const char *headers)
680int 680int
681get_content_length (const char *headers) 681get_content_length (const char *headers)
682{ 682{
683 const char *s; 683 const char *s;
684 int content_length = 0; 684 int content_length = 0;
685 685
686 s = headers; 686 s = headers;
687 while (*s) { 687 while (*s) {
688 const char *field = s; 688 const char *field = s;
689 const char *value = 0; 689 const char *value = 0;
690 690
691 /* Find the end of the header field */ 691 /* Find the end of the header field */
692 while (*s && !isspace(*s) && *s != ':') 692 while (*s && !isspace(*s) && *s != ':')
693 s++; 693 s++;
694 694
695 /* Remember the header value, if any. */ 695 /* Remember the header value, if any. */
696 if (*s == ':') 696 if (*s == ':')
697 value = ++s; 697 value = ++s;
698 698
699 /* Skip to the end of the header, including continuation lines. */ 699 /* Skip to the end of the header, including continuation lines. */
700 while (*s && !(*s == '\n' && (s[1] != ' ' && s[1] != '\t'))) 700 while (*s && !(*s == '\n' && (s[1] != ' ' && s[1] != '\t')))
701 s++; 701 s++;
702 s++; 702 s++;
703 703
704 /* Process this header. */ 704 /* Process this header. */
705 if (value && value > field+2) { 705 if (value && value > field+2) {
706 char *ff = (char *) malloc (value-field); 706 char *ff = (char *) malloc (value-field);
707 char *ss = ff; 707 char *ss = ff;
708 while (field < value-1) 708 while (field < value-1)
709 *ss++ = tolower(*field++); 709 *ss++ = tolower(*field++);
710 *ss++ = 0; 710 *ss++ = 0;
711 711
712 if (!strcmp (ff, "content-length")) { 712 if (!strcmp (ff, "content-length")) {
713 const char *e; 713 const char *e;
714 while (*value && isspace (*value)) 714 while (*value && isspace (*value))
715 value++; 715 value++;
716 for (e = value; *e && *e != '\r' && *e != '\n'; e++) 716 for (e = value; *e && *e != '\r' && *e != '\n'; e++)
717 ; 717 ;
718 ss = (char *) malloc (e - value + 1); 718 ss = (char *) malloc (e - value + 1);
719 strncpy (ss, value, e - value); 719 strncpy (ss, value, e - value);
720 ss[e - value] = 0; 720 ss[e - value] = 0;
721 content_length = atoi(ss); 721 content_length = atoi(ss);
722 free (ss); 722 free (ss);
723 } 723 }
724 free (ff); 724 free (ff);
725 } 725 }
726 } 726 }
727 return (content_length); 727 return (content_length);
728} 728}
729 729
730int 730int
731check_http (void) 731check_http (void)
732{ 732{
733 char *msg; 733 char *msg;
734 char *status_line; 734 char *status_line;
735 char *status_code; 735 char *status_code;
736 char *header; 736 char *header;
737 char *page; 737 char *page;
738 char *auth; 738 char *auth;
739 int http_status; 739 int http_status;
740 int i = 0; 740 int i = 0;
741 size_t pagesize = 0; 741 size_t pagesize = 0;
742 char *full_page; 742 char *full_page;
743 char *buf; 743 char *buf;
744 char *pos; 744 char *pos;
745 long microsec; 745 long microsec;
746 double elapsed_time; 746 double elapsed_time;
747 int page_len = 0; 747 int page_len = 0;
748 int result = STATE_UNKNOWN; 748 int result = STATE_UNKNOWN;
749 749
750 /* try to connect to the host at the given port number */ 750 /* try to connect to the host at the given port number */
751 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) 751 if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
752 die (STATE_CRITICAL, _("Unable to open TCP socket\n")); 752 die (STATE_CRITICAL, _("Unable to open TCP socket\n"));
753#ifdef HAVE_SSL 753#ifdef HAVE_SSL
754 if (use_ssl == TRUE) { 754 if (use_ssl == TRUE) {
755 np_net_ssl_init(sd); 755 np_net_ssl_init(sd);
756 if (check_cert == TRUE) { 756 if (check_cert == TRUE) {
757 result = np_net_ssl_check_cert(days_till_exp); 757 result = np_net_ssl_check_cert(days_till_exp);
758 if(result != STATE_OK){ 758 if(result != STATE_OK){
759 np_net_ssl_cleanup(); 759 np_net_ssl_cleanup();
760 if(sd) close(sd); 760 if(sd) close(sd);
761 return result; 761 return result;
762 } 762 }
763 } 763 }
764 } 764 }
765#endif /* HAVE_SSL */ 765#endif /* HAVE_SSL */
766 766
767 asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent); 767 asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent);
768 768
769 /* optionally send the host header info */ 769 /* optionally send the host header info */
770 if (host_name) 770 if (host_name)
771 asprintf (&buf, "%sHost: %s\r\n", buf, host_name); 771 asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
772 772
773 /* optionally send any other header tag */ 773 /* optionally send any other header tag */
774 if (http_opt_headers) { 774 if (http_opt_headers) {
775 for ((pos = strtok(http_opt_headers, INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER))) 775 for ((pos = strtok(http_opt_headers, INPUT_DELIMITER)); pos; (pos = strtok(NULL, INPUT_DELIMITER)))
776 asprintf (&buf, "%s%s\r\n", buf, pos); 776 asprintf (&buf, "%s%s\r\n", buf, pos);
777 } 777 }
778 778
779 /* optionally send the authentication info */ 779 /* optionally send the authentication info */
780 if (strlen(user_auth)) { 780 if (strlen(user_auth)) {
781 auth = base64 (user_auth, strlen (user_auth)); 781 auth = base64 (user_auth, strlen (user_auth));
782 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); 782 asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth);
783 } 783 }
784 784
785 /* either send http POST data */ 785 /* either send http POST data */
786 if (http_post_data) { 786 if (http_post_data) {
787 if (http_content_type) { 787 if (http_content_type) {
788 asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); 788 asprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type);
789 } else { 789 } else {
790 asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); 790 asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf);
791 } 791 }
792 792
793 asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); 793 asprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data));
794 asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF); 794 asprintf (&buf, "%s%s%s", buf, http_post_data, CRLF);
795 } 795 }
796 else { 796 else {
797 /* or just a newline so the server knows we're done with the request */ 797 /* or just a newline so the server knows we're done with the request */
798 asprintf (&buf, "%s%s", buf, CRLF); 798 asprintf (&buf, "%s%s", buf, CRLF);
799 } 799 }
800 800
801 if (verbose) printf ("%s\n", buf); 801 if (verbose) printf ("%s\n", buf);
802 my_send (buf, strlen (buf)); 802 my_send (buf, strlen (buf));
803 803
804 /* fetch the page */ 804 /* fetch the page */
805 full_page = strdup(""); 805 full_page = strdup("");
806 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { 806 while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) {
807 buffer[i] = '\0'; 807 buffer[i] = '\0';
808 asprintf (&full_page, "%s%s", full_page, buffer); 808 asprintf (&full_page, "%s%s", full_page, buffer);
809 pagesize += i; 809 pagesize += i;
810 810
811 if (no_body && document_headers_done (full_page)) { 811 if (no_body && document_headers_done (full_page)) {
812 i = 0; 812 i = 0;
813 break; 813 break;
814 } 814 }
815 } 815 }
816 816
817 if (i < 0 && errno != ECONNRESET) { 817 if (i < 0 && errno != ECONNRESET) {
818#ifdef HAVE_SSL 818#ifdef HAVE_SSL
819 /* 819 /*
820 if (use_ssl) { 820 if (use_ssl) {
821 sslerr=SSL_get_error(ssl, i); 821 sslerr=SSL_get_error(ssl, i);
822 if ( sslerr == SSL_ERROR_SSL ) { 822 if ( sslerr == SSL_ERROR_SSL ) {
823 die (STATE_WARNING, _("Client Certificate Required\n")); 823 die (STATE_WARNING, _("Client Certificate Required\n"));
824 } else { 824 } else {
825 die (STATE_CRITICAL, _("Error on receive\n")); 825 die (STATE_CRITICAL, _("Error on receive\n"));
826 } 826 }
827 } 827 }
828 else { 828 else {
829 */ 829 */
830#endif 830#endif
831 die (STATE_CRITICAL, _("Error on receive\n")); 831 die (STATE_CRITICAL, _("Error on receive\n"));
832#ifdef HAVE_SSL 832#ifdef HAVE_SSL
833 /* XXX 833 /* XXX
834 } 834 }
835 */ 835 */
836#endif 836#endif
837 } 837 }
838 838
839 /* return a CRITICAL status if we couldn't read any data */ 839 /* return a CRITICAL status if we couldn't read any data */
840 if (pagesize == (size_t) 0) 840 if (pagesize == (size_t) 0)
841 die (STATE_CRITICAL, _("No data received %s\n"), timestamp); 841 die (STATE_CRITICAL, _("No data received %s\n"), timestamp);
842 842
843 /* close the connection */ 843 /* close the connection */
844#ifdef HAVE_SSL 844#ifdef HAVE_SSL
845 np_net_ssl_cleanup(); 845 np_net_ssl_cleanup();
846#endif 846#endif
847 if(sd) close(sd); 847 if(sd) close(sd);
848 848
849 /* reset the alarm */ 849 /* reset the alarm */
850 alarm (0); 850 alarm (0);
851 851
852 /* leave full_page untouched so we can free it later */ 852 /* leave full_page untouched so we can free it later */
853 page = full_page; 853 page = full_page;
854 854
855 if (verbose) 855 if (verbose)
856 printf ("%s://%s:%d%s is %d characters\n", 856 printf ("%s://%s:%d%s is %d characters\n",
857 use_ssl ? "https" : "http", server_address, 857 use_ssl ? "https" : "http", server_address,
858 server_port, server_url, (int)pagesize); 858 server_port, server_url, (int)pagesize);
859 859
860 /* find status line and null-terminate it */ 860 /* find status line and null-terminate it */
861 status_line = page; 861 status_line = page;
862 page += (size_t) strcspn (page, "\r\n"); 862 page += (size_t) strcspn (page, "\r\n");
863 pos = page; 863 pos = page;
864 page += (size_t) strspn (page, "\r\n"); 864 page += (size_t) strspn (page, "\r\n");
865 status_line[strcspn(status_line, "\r\n")] = 0; 865 status_line[strcspn(status_line, "\r\n")] = 0;
866 strip (status_line); 866 strip (status_line);
867 if (verbose) 867 if (verbose)
868 printf ("STATUS: %s\n", status_line); 868 printf ("STATUS: %s\n", status_line);
869 869
870 /* find header info and null-terminate it */ 870 /* find header info and null-terminate it */
871 header = page; 871 header = page;
872 while (strcspn (page, "\r\n") > 0) { 872 while (strcspn (page, "\r\n") > 0) {
873 page += (size_t) strcspn (page, "\r\n"); 873 page += (size_t) strcspn (page, "\r\n");
874 pos = page; 874 pos = page;
875 if ((strspn (page, "\r") == 1 && strspn (page, "\r\n") >= 2) || 875 if ((strspn (page, "\r") == 1 && strspn (page, "\r\n") >= 2) ||
876 (strspn (page, "\n") == 1 && strspn (page, "\r\n") >= 2)) 876 (strspn (page, "\n") == 1 && strspn (page, "\r\n") >= 2))
877 page += (size_t) 2; 877 page += (size_t) 2;
878 else 878 else
879 page += (size_t) 1; 879 page += (size_t) 1;
880 } 880 }
881 page += (size_t) strspn (page, "\r\n"); 881 page += (size_t) strspn (page, "\r\n");
882 header[pos - header] = 0; 882 header[pos - header] = 0;
883 if (verbose) 883 if (verbose)
884 printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header, 884 printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header,
885 (no_body ? " [[ skipped ]]" : page)); 885 (no_body ? " [[ skipped ]]" : page));
886 886
887 /* make sure the status line matches the response we are looking for */ 887 /* make sure the status line matches the response we are looking for */
888 if (!strstr (status_line, server_expect)) { 888 if (!strstr (status_line, server_expect)) {
889 if (server_port == HTTP_PORT) 889 if (server_port == HTTP_PORT)
890 asprintf (&msg, 890 asprintf (&msg,
891 _("Invalid HTTP response received from host\n")); 891 _("Invalid HTTP response received from host\n"));
892 else 892 else
893 asprintf (&msg, 893 asprintf (&msg,
894 _("Invalid HTTP response received from host on port %d\n"), 894 _("Invalid HTTP response received from host on port %d\n"),
895 server_port); 895 server_port);
896 die (STATE_CRITICAL, "%s", msg); 896 die (STATE_CRITICAL, "%s", msg);
897 } 897 }
898 898
899 /* Exit here if server_expect was set by user and not default */ 899 /* Exit here if server_expect was set by user and not default */
900 if ( server_expect_yn ) { 900 if ( server_expect_yn ) {
901 asprintf (&msg, 901 asprintf (&msg,
902 _("HTTP OK: Status line output matched \"%s\"\n"), 902 _("HTTP OK: Status line output matched \"%s\"\n"),
903 server_expect); 903 server_expect);
904 if (verbose) 904 if (verbose)
905 printf ("%s\n",msg); 905 printf ("%s\n",msg);
906 } 906 }
907 else { 907 else {
908 /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ 908 /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */
909 /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */ 909 /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */
910 /* Status-Code = 3 DIGITS */ 910 /* Status-Code = 3 DIGITS */
911 911
912 status_code = strchr (status_line, ' ') + sizeof (char); 912 status_code = strchr (status_line, ' ') + sizeof (char);
913 if (strspn (status_code, "1234567890") != 3) 913 if (strspn (status_code, "1234567890") != 3)
914 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line); 914 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line);
915 915
916 http_status = atoi (status_code); 916 http_status = atoi (status_code);
917 917
918 /* check the return code */ 918 /* check the return code */
919 919
920 if (http_status >= 600 || http_status < 100) 920 if (http_status >= 600 || http_status < 100)
921 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line); 921 die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line);
922 922
923 /* server errors result in a critical state */ 923 /* server errors result in a critical state */
924 else if (http_status >= 500) 924 else if (http_status >= 500)
925 die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line); 925 die (STATE_CRITICAL, _("HTTP CRITICAL: %s\n"), status_line);
926 926
927 /* client errors result in a warning state */ 927 /* client errors result in a warning state */
928 else if (http_status >= 400) 928 else if (http_status >= 400)
929 die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line); 929 die (STATE_WARNING, _("HTTP WARNING: %s\n"), status_line);
930 930
931 /* check redirected page if specified */ 931 /* check redirected page if specified */
932 else if (http_status >= 300) { 932 else if (http_status >= 300) {
933 933
934 if (onredirect == STATE_DEPENDENT) 934 if (onredirect == STATE_DEPENDENT)
935 redir (header, status_line); 935 redir (header, status_line);
936 else if (onredirect == STATE_UNKNOWN) 936 else if (onredirect == STATE_UNKNOWN)
937 printf (_("UNKNOWN")); 937 printf (_("UNKNOWN"));
938 else if (onredirect == STATE_OK) 938 else if (onredirect == STATE_OK)
939 printf (_("OK")); 939 printf (_("OK"));
940 else if (onredirect == STATE_WARNING) 940 else if (onredirect == STATE_WARNING)
941 printf (_("WARNING")); 941 printf (_("WARNING"));
942 else if (onredirect == STATE_CRITICAL) 942 else if (onredirect == STATE_CRITICAL)
943 printf (_("CRITICAL")); 943 printf (_("CRITICAL"));
944 microsec = deltime (tv); 944 microsec = deltime (tv);
945 elapsed_time = (double)microsec / 1.0e6; 945 elapsed_time = (double)microsec / 1.0e6;
946 die (onredirect, 946 die (onredirect,
947 _(" - %s - %.3f second response time %s%s|%s %s\n"), 947 _(" - %s - %.3f second response time %s%s|%s %s\n"),
948 status_line, elapsed_time, timestamp, 948 status_line, elapsed_time, timestamp,
949 (display_html ? "</A>" : ""), 949 (display_html ? "</A>" : ""),
950 perfd_time (elapsed_time), perfd_size (pagesize)); 950 perfd_time (elapsed_time), perfd_size (pagesize));
951 } /* end if (http_status >= 300) */ 951 } /* end if (http_status >= 300) */
952 952
953 } /* end else (server_expect_yn) */ 953 } /* end else (server_expect_yn) */
954 954
955 if (maximum_age >= 0) { 955 if (maximum_age >= 0) {
956 check_document_dates (header); 956 check_document_dates (header);
957 } 957 }
958 958
959 /* check elapsed time */ 959 /* check elapsed time */
960 microsec = deltime (tv); 960 microsec = deltime (tv);
961 elapsed_time = (double)microsec / 1.0e6; 961 elapsed_time = (double)microsec / 1.0e6;
962 asprintf (&msg, 962 asprintf (&msg,
963 _("HTTP WARNING: %s - %.3f second response time %s%s|%s %s\n"), 963 _("HTTP WARNING: %s - %.3f second response time %s%s|%s %s\n"),
964 status_line, elapsed_time, timestamp, 964 status_line, elapsed_time, timestamp,
965 (display_html ? "</A>" : ""), 965 (display_html ? "</A>" : ""),
966 perfd_time (elapsed_time), perfd_size (pagesize)); 966 perfd_time (elapsed_time), perfd_size (pagesize));
967 if (check_critical_time == TRUE && elapsed_time > critical_time) 967 if (check_critical_time == TRUE && elapsed_time > critical_time)
968 die (STATE_CRITICAL, "%s", msg); 968 die (STATE_CRITICAL, "%s", msg);
969 if (check_warning_time == TRUE && elapsed_time > warning_time) 969 if (check_warning_time == TRUE && elapsed_time > warning_time)
970 die (STATE_WARNING, "%s", msg); 970 die (STATE_WARNING, "%s", msg);
971 971
972 /* Page and Header content checks go here */ 972 /* Page and Header content checks go here */
973 /* these checks should be last */ 973 /* these checks should be last */
974 974
975 if (strlen (string_expect)) { 975 if (strlen (string_expect)) {
976 if (strstr (page, string_expect)) { 976 if (strstr (page, string_expect)) {
977 printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"), 977 printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
978 status_line, elapsed_time, 978 status_line, elapsed_time,
979 timestamp, (display_html ? "</A>" : ""), 979 timestamp, (display_html ? "</A>" : ""),
980 perfd_time (elapsed_time), perfd_size (pagesize)); 980 perfd_time (elapsed_time), perfd_size (pagesize));
981 exit (STATE_OK); 981 exit (STATE_OK);
982 } 982 }
983 else { 983 else {
984 printf (_("CRITICAL - string not found%s|%s %s\n"), 984 printf (_("CRITICAL - string not found%s|%s %s\n"),
985 (display_html ? "</A>" : ""), 985 (display_html ? "</A>" : ""),
986 perfd_time (elapsed_time), perfd_size (pagesize)); 986 perfd_time (elapsed_time), perfd_size (pagesize));
987 exit (STATE_CRITICAL); 987 exit (STATE_CRITICAL);
988 } 988 }
989 } 989 }
990#ifdef HAVE_REGEX_H 990#ifdef HAVE_REGEX_H
991 if (strlen (regexp)) { 991 if (strlen (regexp)) {
992 errcode = regexec (&preg, page, REGS, pmatch, 0); 992 errcode = regexec (&preg, page, REGS, pmatch, 0);
993 if (errcode == 0) { 993 if (errcode == 0) {
994 printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"), 994 printf (_("HTTP OK %s - %.3f second response time %s%s|%s %s\n"),
995 status_line, elapsed_time, 995 status_line, elapsed_time,
996 timestamp, (display_html ? "</A>" : ""), 996 timestamp, (display_html ? "</A>" : ""),
997 perfd_time (elapsed_time), perfd_size (pagesize)); 997 perfd_time (elapsed_time), perfd_size (pagesize));
998 exit (STATE_OK); 998 exit (STATE_OK);
999 } 999 }
1000 else { 1000 else {
1001 if (errcode == REG_NOMATCH) { 1001 if (errcode == REG_NOMATCH) {
1002 printf (_("CRITICAL - pattern not found%s|%s %s\n"), 1002 printf (_("CRITICAL - pattern not found%s|%s %s\n"),
1003 (display_html ? "</A>" : ""), 1003 (display_html ? "</A>" : ""),
1004 perfd_time (elapsed_time), perfd_size (pagesize)); 1004 perfd_time (elapsed_time), perfd_size (pagesize));
1005 exit (STATE_CRITICAL); 1005 exit (STATE_CRITICAL);
1006 } 1006 }
1007 else { 1007 else {
1008 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 1008 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
1009 printf (_("CRITICAL - Execute Error: %s\n"), errbuf); 1009 printf (_("CRITICAL - Execute Error: %s\n"), errbuf);
1010 exit (STATE_CRITICAL); 1010 exit (STATE_CRITICAL);
1011 } 1011 }
1012 } 1012 }
1013 } 1013 }
1014#endif 1014#endif
1015 1015
1016 /* make sure the page is of an appropriate size */ 1016 /* make sure the page is of an appropriate size */
1017 /* page_len = get_content_length(header); */ 1017 /* page_len = get_content_length(header); */
1018 page_len = pagesize; 1018 page_len = pagesize;
1019 if ((max_page_len > 0) && (page_len > max_page_len)) { 1019 if ((max_page_len > 0) && (page_len > max_page_len)) {
1020 printf (_("HTTP WARNING: page size %d too large%s|%s\n"), 1020 printf (_("HTTP WARNING: page size %d too large%s|%s\n"),
1021 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); 1021 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
1022 exit (STATE_WARNING); 1022 exit (STATE_WARNING);
1023 } else if ((min_page_len > 0) && (page_len < min_page_len)) { 1023 } else if ((min_page_len > 0) && (page_len < min_page_len)) {
1024 printf (_("HTTP WARNING: page size %d too small%s|%s\n"), 1024 printf (_("HTTP WARNING: page size %d too small%s|%s\n"),
1025 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) ); 1025 page_len, (display_html ? "</A>" : ""), perfd_size (page_len) );
1026 exit (STATE_WARNING); 1026 exit (STATE_WARNING);
1027 } 1027 }
1028 /* We only get here if all tests have been passed */ 1028 /* We only get here if all tests have been passed */
1029 asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s%s|%s %s\n"), 1029 asprintf (&msg, _("HTTP OK %s - %d bytes in %.3f seconds %s%s|%s %s\n"),
1030 status_line, page_len, elapsed_time, 1030 status_line, page_len, elapsed_time,
1031 timestamp, (display_html ? "</A>" : ""), 1031 timestamp, (display_html ? "</A>" : ""),
1032 perfd_time (elapsed_time), perfd_size (page_len)); 1032 perfd_time (elapsed_time), perfd_size (page_len));
1033 die (STATE_OK, "%s", msg); 1033 die (STATE_OK, "%s", msg);
1034 return STATE_UNKNOWN; 1034 return STATE_UNKNOWN;
1035} 1035}
1036 1036
1037 1037
@@ -1051,117 +1051,117 @@ check_http (void)
1051void 1051void
1052redir (char *pos, char *status_line) 1052redir (char *pos, char *status_line)
1053{ 1053{
1054 int i = 0; 1054 int i = 0;
1055 char *x; 1055 char *x;
1056 char xx[2]; 1056 char xx[2];
1057 char type[6]; 1057 char type[6];
1058 char *addr; 1058 char *addr;
1059 char port[6]; 1059 char port[6];
1060 char *url; 1060 char *url;
1061 1061
1062 addr = malloc (MAX_IPV4_HOSTLENGTH + 1); 1062 addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
1063 if (addr == NULL) 1063 if (addr == NULL)
1064 die (STATE_UNKNOWN, _("Could not allocate addr\n")); 1064 die (STATE_UNKNOWN, _("Could not allocate addr\n"));
1065 1065
1066 url = malloc (strcspn (pos, "\r\n")); 1066 url = malloc (strcspn (pos, "\r\n"));
1067 if (url == NULL) 1067 if (url == NULL)
1068 die (STATE_UNKNOWN, _("Could not allocate url\n")); 1068 die (STATE_UNKNOWN, _("Could not allocate url\n"));
1069 1069
1070 while (pos) { 1070 while (pos) {
1071 1071
1072 if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) { 1072 if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) {
1073 1073
1074 pos += (size_t) strcspn (pos, "\r\n"); 1074 pos += (size_t) strcspn (pos, "\r\n");
1075 pos += (size_t) strspn (pos, "\r\n"); 1075 pos += (size_t) strspn (pos, "\r\n");
1076 if (strlen(pos) == 0) 1076 if (strlen(pos) == 0)
1077 die (STATE_UNKNOWN, 1077 die (STATE_UNKNOWN,
1078 _("UNKNOWN - Could not find redirect location - %s%s\n"), 1078 _("UNKNOWN - Could not find redirect location - %s%s\n"),
1079 status_line, (display_html ? "</A>" : "")); 1079 status_line, (display_html ? "</A>" : ""));
1080 continue; 1080 continue;
1081 } 1081 }
1082 1082
1083 pos += i; 1083 pos += i;
1084 pos += strspn (pos, " \t\r\n"); 1084 pos += strspn (pos, " \t\r\n");
1085 1085
1086 url = realloc (url, strcspn (pos, "\r\n")); 1086 url = realloc (url, strcspn (pos, "\r\n"));
1087 if (url == NULL) 1087 if (url == NULL)
1088 die (STATE_UNKNOWN, _("could not allocate url\n")); 1088 die (STATE_UNKNOWN, _("could not allocate url\n"));
1089 1089
1090 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ 1090 /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
1091 if (sscanf (pos, HD1, type, addr, port, url) == 4) { 1091 if (sscanf (pos, HD1, type, addr, port, url) == 4) {
1092 use_ssl = server_type_check (type); 1092 use_ssl = server_type_check (type);
1093 i = atoi (port); 1093 i = atoi (port);
1094 } 1094 }
1095 1095
1096 /* URI_HTTP URI_HOST URI_PATH */ 1096 /* URI_HTTP URI_HOST URI_PATH */
1097 else if (sscanf (pos, HD2, type, addr, url) == 3 ) { 1097 else if (sscanf (pos, HD2, type, addr, url) == 3 ) {
1098 use_ssl = server_type_check (type); 1098 use_ssl = server_type_check (type);
1099 i = server_port_check (use_ssl); 1099 i = server_port_check (use_ssl);
1100 } 1100 }
1101 1101
1102 /* URI_HTTP URI_HOST URI_PORT */ 1102 /* URI_HTTP URI_HOST URI_PORT */
1103 else if(sscanf (pos, HD3, type, addr, port) == 3) { 1103 else if(sscanf (pos, HD3, type, addr, port) == 3) {
1104 strcpy (url, HTTP_URL); 1104 strcpy (url, HTTP_URL);
1105 use_ssl = server_type_check (type); 1105 use_ssl = server_type_check (type);
1106 i = atoi (port); 1106 i = atoi (port);
1107 } 1107 }
1108 1108
1109 /* URI_HTTP URI_HOST */ 1109 /* URI_HTTP URI_HOST */
1110 else if(sscanf (pos, HD4, type, addr) == 2) { 1110 else if(sscanf (pos, HD4, type, addr) == 2) {
1111 strcpy (url, HTTP_URL); 1111 strcpy (url, HTTP_URL);
1112 use_ssl = server_type_check (type); 1112 use_ssl = server_type_check (type);
1113 i = server_port_check (use_ssl); 1113 i = server_port_check (use_ssl);
1114 } 1114 }
1115 1115
1116 /* URI_PATH */ 1116 /* URI_PATH */
1117 else if (sscanf (pos, HD5, url) == 1) { 1117 else if (sscanf (pos, HD5, url) == 1) {
1118 /* relative url */ 1118 /* relative url */
1119 if ((url[0] != '/')) { 1119 if ((url[0] != '/')) {
1120 if ((x = strrchr(server_url, '/'))) 1120 if ((x = strrchr(server_url, '/')))
1121 *x = '\0'; 1121 *x = '\0';
1122 asprintf (&url, "%s/%s", server_url, url); 1122 asprintf (&url, "%s/%s", server_url, url);
1123 } 1123 }
1124 i = server_port; 1124 i = server_port;
1125 strcpy (type, server_type); 1125 strcpy (type, server_type);
1126 strcpy (addr, host_name); 1126 strcpy (addr, host_name);
1127 } 1127 }
1128 1128
1129 else { 1129 else {
1130 die (STATE_UNKNOWN, 1130 die (STATE_UNKNOWN,
1131 _("UNKNOWN - Could not parse redirect location - %s%s\n"), 1131 _("UNKNOWN - Could not parse redirect location - %s%s\n"),
1132 pos, (display_html ? "</A>" : "")); 1132 pos, (display_html ? "</A>" : ""));
1133 } 1133 }
1134 1134
1135 break; 1135 break;
1136 1136
1137 } /* end while (pos) */ 1137 } /* end while (pos) */
1138 1138
1139 if (++redir_depth > max_depth) 1139 if (++redir_depth > max_depth)
1140 die (STATE_WARNING, 1140 die (STATE_WARNING,
1141 _("WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"), 1141 _("WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"),
1142 max_depth, type, addr, i, url, (display_html ? "</A>" : "")); 1142 max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
1143 1143
1144 if (server_port==i && 1144 if (server_port==i &&
1145 !strcmp(server_address, addr) && 1145 !strcmp(server_address, addr) &&
1146 (host_name && !strcmp(host_name, addr)) && 1146 (host_name && !strcmp(host_name, addr)) &&
1147 !strcmp(server_url, url)) 1147 !strcmp(server_url, url))
1148 die (STATE_WARNING, 1148 die (STATE_WARNING,
1149 _("WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"), 1149 _("WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
1150 type, addr, i, url, (display_html ? "</A>" : "")); 1150 type, addr, i, url, (display_html ? "</A>" : ""));
1151 1151
1152 server_port = i; 1152 server_port = i;
1153 strcpy (server_type, type); 1153 strcpy (server_type, type);
1154 1154
1155 free (host_name); 1155 free (host_name);
1156 host_name = strdup (addr); 1156 host_name = strdup (addr);
1157 1157
1158 free (server_address); 1158 free (server_address);
1159 server_address = strdup (addr); 1159 server_address = strdup (addr);
1160 1160
1161 free (server_url); 1161 free (server_url);
1162 server_url = strdup (url); 1162 server_url = strdup (url);
1163 1163
1164 check_http (); 1164 check_http ();
1165} 1165}
1166 1166
1167 1167
@@ -1169,60 +1169,64 @@ redir (char *pos, char *status_line)
1169int 1169int
1170server_type_check (const char *type) 1170server_type_check (const char *type)
1171{ 1171{
1172 if (strcmp (type, "https")) 1172 if (strcmp (type, "https"))
1173 return FALSE; 1173 return FALSE;
1174 else 1174 else
1175 return TRUE; 1175 return TRUE;
1176} 1176}
1177 1177
1178int 1178int
1179server_port_check (int ssl_flag) 1179server_port_check (int ssl_flag)
1180{ 1180{
1181 if (ssl_flag) 1181 if (ssl_flag)
1182 return HTTPS_PORT; 1182 return HTTPS_PORT;
1183 else 1183 else
1184 return HTTP_PORT; 1184 return HTTP_PORT;
1185} 1185}
1186 1186
1187char *perfd_time (double elapsed_time) 1187char *perfd_time (double elapsed_time)
1188{ 1188{
1189 return fperfdata ("time", elapsed_time, "s", 1189 return fperfdata ("time", elapsed_time, "s",
1190 check_warning_time, warning_time, 1190 check_warning_time, warning_time,
1191 check_critical_time, critical_time, 1191 check_critical_time, critical_time,
1192 TRUE, 0, FALSE, 0); 1192 TRUE, 0, FALSE, 0);
1193} 1193}
1194 1194
1195 1195
1196 1196
1197char *perfd_size (int page_len) 1197char *perfd_size (int page_len)
1198{ 1198{
1199 return perfdata ("size", page_len, "B", 1199 return perfdata ("size", page_len, "B",
1200 (min_page_len>0?TRUE:FALSE), min_page_len, 1200 (min_page_len>0?TRUE:FALSE), min_page_len,
1201 (min_page_len>0?TRUE:FALSE), 0, 1201 (min_page_len>0?TRUE:FALSE), 0,
1202 TRUE, 0, FALSE, 0); 1202 TRUE, 0, FALSE, 0);
1203} 1203}
1204 1204
1205void 1205void
1206print_help (void) 1206print_help (void)
1207{ 1207{
1208 print_revision (progname, revision); 1208 print_revision (progname, revision);
1209 1209
1210 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); 1210 printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
1211 printf (COPYRIGHT, copyright, email); 1211 printf (COPYRIGHT, copyright, email);
1212 1212
1213 printf (_("\ 1213 printf (_("\
1214This plugin tests the HTTP service on the specified host. It can test\n\ 1214This plugin tests the HTTP service on the specified host. It can test\n\
1215normal (http) and secure (https) servers, follow redirects, search for\n\ 1215normal (http) and secure (https) servers, follow redirects, search for\n\
1216strings and regular expressions, check connection times, and report on\n\ 1216strings and regular expressions, check connection times, and report on\n\
1217certificate expiration times.\n\n")); 1217certificate expiration times."));
1218
1219 printf ("\n\n");
1220
1221 print_usage ();
1218 1222
1219 print_usage (); 1223 printf (_("NOTE: One or both of -H and -I must be specified"));
1220 1224
1221 printf (_("NOTE: One or both of -H and -I must be specified\n")); 1225 printf ("\n");
1222 1226
1223 printf (_(UT_HELP_VRSN)); 1227 printf (_(UT_HELP_VRSN));
1224 1228
1225 printf (_("\ 1229 printf (_("\
1226 -H, --hostname=ADDRESS\n\ 1230 -H, --hostname=ADDRESS\n\
1227 Host name argument for servers using host headers (virtual host)\n\ 1231 Host name argument for servers using host headers (virtual host)\n\
1228 Append a port to include it in the header (eg: example.com:5000)\n\ 1232 Append a port to include it in the header (eg: example.com:5000)\n\
@@ -1231,10 +1235,10 @@ certificate expiration times.\n\n"));
1231 -p, --port=INTEGER\n\ 1235 -p, --port=INTEGER\n\
1232 Port number (default: %d)\n"), HTTP_PORT); 1236 Port number (default: %d)\n"), HTTP_PORT);
1233 1237
1234 printf (_(UT_IPv46)); 1238 printf (_(UT_IPv46));
1235 1239
1236#ifdef HAVE_SSL 1240#ifdef HAVE_SSL
1237 printf (_("\ 1241 printf (_("\
1238 -S, --ssl\n\ 1242 -S, --ssl\n\
1239 Connect via SSL\n\ 1243 Connect via SSL\n\
1240 -C, --certificate=INTEGER\n\ 1244 -C, --certificate=INTEGER\n\
@@ -1242,7 +1246,7 @@ certificate expiration times.\n\n"));
1242 (when this option is used the url is not checked.)\n")); 1246 (when this option is used the url is not checked.)\n"));
1243#endif 1247#endif
1244 1248
1245 printf (_("\ 1249 printf (_("\
1246 -e, --expect=STRING\n\ 1250 -e, --expect=STRING\n\
1247 String to expect in first (status) line of server response (default: %s)\n\ 1251 String to expect in first (status) line of server response (default: %s)\n\
1248 If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)\n\ 1252 If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)\n\
@@ -1262,7 +1266,7 @@ certificate expiration times.\n\n"));
1262 specify Content-Type header media type when POSTing\n"), HTTP_EXPECT); 1266 specify Content-Type header media type when POSTing\n"), HTTP_EXPECT);
1263 1267
1264#ifdef HAVE_REGEX_H 1268#ifdef HAVE_REGEX_H
1265 printf (_("\ 1269 printf (_("\
1266 -l, --linespan\n\ 1270 -l, --linespan\n\
1267 Allow regex to span newlines (must precede -r or -R)\n\ 1271 Allow regex to span newlines (must precede -r or -R)\n\
1268 -r, --regex, --ereg=STRING\n\ 1272 -r, --regex, --ereg=STRING\n\
@@ -1271,7 +1275,7 @@ certificate expiration times.\n\n"));
1271 Search page for case-insensitive regex STRING\n")); 1275 Search page for case-insensitive regex STRING\n"));
1272#endif 1276#endif
1273 1277
1274 printf (_("\ 1278 printf (_("\
1275 -a, --authorization=AUTH_PAIR\n\ 1279 -a, --authorization=AUTH_PAIR\n\
1276 Username:password on sites with basic authentication\n\ 1280 Username:password on sites with basic authentication\n\
1277 -A, --useragent=STRING\n\ 1281 -A, --useragent=STRING\n\
@@ -1285,13 +1289,13 @@ certificate expiration times.\n\n"));
1285 -m, --pagesize=INTEGER<:INTEGER>\n\ 1289 -m, --pagesize=INTEGER<:INTEGER>\n\
1286 Minimum page size required (bytes) : Maximum page size required (bytes)\n")); 1290 Minimum page size required (bytes) : Maximum page size required (bytes)\n"));
1287 1291
1288 printf (_(UT_WARN_CRIT)); 1292 printf (_(UT_WARN_CRIT));
1289 1293
1290 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); 1294 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
1291 1295
1292 printf (_(UT_VERBOSE)); 1296 printf (_(UT_VERBOSE));
1293 1297
1294 printf (_("\ 1298 printf (_("\
1295This plugin will attempt to open an HTTP connection with the host. Successful\n\ 1299This plugin will attempt to open an HTTP connection with the host. Successful\n\
1296connects return STATE_OK, refusals and timeouts return STATE_CRITICAL, other\n\ 1300connects return STATE_OK, refusals and timeouts return STATE_CRITICAL, other\n\
1297errors return STATE_UNKNOWN. Successful connects, but incorrect reponse\n\ 1301errors return STATE_UNKNOWN. Successful connects, but incorrect reponse\n\
@@ -1300,18 +1304,18 @@ checking a virtual server that uses 'host headers' you must supply the FQDN\n\
1300(fully qualified domain name) as the [host_name] argument.\n")); 1304(fully qualified domain name) as the [host_name] argument.\n"));
1301 1305
1302#ifdef HAVE_SSL 1306#ifdef HAVE_SSL
1303 printf (_("\n\ 1307 printf (_("\n\
1304This plugin can also check whether an SSL enabled web server is able to\n\ 1308This plugin can also check whether an SSL enabled web server is able to\n\
1305serve content (optionally within a specified time) or whether the X509 \n\ 1309serve content (optionally within a specified time) or whether the X509 \n\
1306certificate is still valid for the specified number of days.\n")); 1310certificate is still valid for the specified number of days.\n"));
1307 printf (_("\n\ 1311 printf (_("\n\
1308CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com\n\n\ 1312CHECK CONTENT: check_http -w 5 -c 10 --ssl www.verisign.com\n\n\
1309When the 'www.verisign.com' server returns its content within 5 seconds, a\n\ 1313When the 'www.verisign.com' server returns its content within 5 seconds, a\n\
1310STATE_OK will be returned. When the server returns its content but exceeds\n\ 1314STATE_OK will be returned. When the server returns its content but exceeds\n\
1311the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,\n\ 1315the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,\n\
1312a STATE_CRITICAL will be returned.\n\n")); 1316a STATE_CRITICAL will be returned.\n\n"));
1313 1317
1314 printf (_("\ 1318 printf (_("\
1315CHECK CERTIFICATE: check_http www.verisign.com -C 14\n\n\ 1319CHECK CERTIFICATE: check_http www.verisign.com -C 14\n\n\
1316When the certificate of 'www.verisign.com' is valid for more than 14 days, a\n\ 1320When the certificate of 'www.verisign.com' is valid for more than 14 days, a\n\
1317STATE_OK is returned. When the certificate is still valid, but for less than\n\ 1321STATE_OK is returned. When the certificate is still valid, but for less than\n\
@@ -1319,7 +1323,7 @@ STATE_OK is returned. When the certificate is still valid, but for less than\n\
1319the certificate is expired.\n")); 1323the certificate is expired.\n"));
1320#endif 1324#endif
1321 1325
1322 printf (_(UT_SUPPORT)); 1326 printf (_(UT_SUPPORT));
1323 1327
1324} 1328}
1325 1329
@@ -1328,11 +1332,10 @@ the certificate is expired.\n"));
1328void 1332void
1329print_usage (void) 1333print_usage (void)
1330{ 1334{
1331 printf ("\ 1335 printf (_("Usage:"));
1332Usage: %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n\ 1336 printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname);
1333 [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\ 1337 printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n");
1334 [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\ 1338 printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n");
1335 [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\ 1339 printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n");
1336 [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] \n\ 1340 printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string] [-k string]\n");
1337 [-M <age>] [-A string] [-k string]\n", progname);
1338} 1341}