diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2022-12-22 10:40:19 (GMT) |
---|---|---|
committer | Sven Nierlein <sven@nierlein.org> | 2023-01-07 17:34:46 (GMT) |
commit | 67d10625307a1bcd5def7cc298314706cef78182 (patch) | |
tree | e57993d5ef25811e08d8c31a191369e1dca8de64 /plugins/check_http.c | |
parent | 029168276fc3a02daa676c4fcc7a597e3319929a (diff) | |
download | monitoring-plugins-67d1062.tar.gz |
Undo clang formatting
Diffstat (limited to 'plugins/check_http.c')
-rw-r--r-- | plugins/check_http.c | 1635 |
1 files changed, 790 insertions, 845 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index d5b6b37..dbaa0d7 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -1,35 +1,35 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_http plugin | 3 | * Monitoring check_http plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2013 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_http plugin | 10 | * This file contains the check_http plugin |
11 | * | 11 | * |
12 | * This plugin tests the HTTP service on the specified host. It can test | 12 | * This plugin tests the HTTP service on the specified host. It can test |
13 | * normal (http) and secure (https) servers, follow redirects, search for | 13 | * normal (http) and secure (https) servers, follow redirects, search for |
14 | * strings and regular expressions, check connection times, and report on | 14 | * strings and regular expressions, check connection times, and report on |
15 | * certificate expiration times. | 15 | * certificate expiration times. |
16 | * | 16 | * |
17 | * | 17 | * |
18 | * This program is free software: you can redistribute it and/or modify | 18 | * This program is free software: you can redistribute it and/or modify |
19 | * it under the terms of the GNU General Public License as published by | 19 | * it under the terms of the GNU General Public License as published by |
20 | * the Free Software Foundation, either version 3 of the License, or | 20 | * the Free Software Foundation, either version 3 of the License, or |
21 | * (at your option) any later version. | 21 | * (at your option) any later version. |
22 | * | 22 | * |
23 | * This program is distributed in the hope that it will be useful, | 23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | * GNU General Public License for more details. | 26 | * GNU General Public License for more details. |
27 | * | 27 | * |
28 | * You should have received a copy of the GNU General Public License | 28 | * You should have received a copy of the GNU General Public License |
29 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 29 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
30 | * | 30 | * |
31 | * | 31 | * |
32 | *****************************************************************************/ | 32 | *****************************************************************************/ |
33 | 33 | ||
34 | const char *progname = "check_http"; | 34 | const char *progname = "check_http"; |
35 | const char *copyright = "1999-2022"; | 35 | const char *copyright = "1999-2022"; |
@@ -41,6 +41,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
41 | #include "base64.h" | 41 | #include "base64.h" |
42 | #include "netutils.h" | 42 | #include "netutils.h" |
43 | #include "utils.h" | 43 | #include "utils.h" |
44 | #include "base64.h" | ||
44 | #include <ctype.h> | 45 | #include <ctype.h> |
45 | 46 | ||
46 | #define STICKY_NONE 0 | 47 | #define STICKY_NONE 0 |
@@ -63,18 +64,19 @@ int ssl_version = 0; | |||
63 | int days_till_exp_warn, days_till_exp_crit; | 64 | int days_till_exp_warn, days_till_exp_crit; |
64 | char *randbuff; | 65 | char *randbuff; |
65 | X509 *server_cert; | 66 | X509 *server_cert; |
66 | #define my_recv(buf, len) \ | 67 | # define my_recv(buf, len) ((use_ssl) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) |
67 | ((use_ssl) ? np_net_ssl_read(buf, len) : read(sd, buf, len)) | 68 | # define my_send(buf, len) ((use_ssl) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) |
68 | #define my_send(buf, len) \ | ||
69 | ((use_ssl) ? np_net_ssl_write(buf, len) : send(sd, buf, len, 0)) | ||
70 | #else /* ifndef HAVE_SSL */ | 69 | #else /* ifndef HAVE_SSL */ |
71 | #define my_recv(buf, len) read(sd, buf, len) | 70 | # define my_recv(buf, len) read(sd, buf, len) |
72 | #define my_send(buf, len) send(sd, buf, len, 0) | 71 | # define my_send(buf, len) send(sd, buf, len, 0) |
73 | #endif /* HAVE_SSL */ | 72 | #endif /* HAVE_SSL */ |
74 | bool no_body = false; | 73 | bool no_body = false; |
75 | int maximum_age = -1; | 74 | int maximum_age = -1; |
76 | 75 | ||
77 | enum { REGS = 2, MAX_RE_SIZE = 1024 }; | 76 | enum { |
77 | REGS = 2, | ||
78 | MAX_RE_SIZE = 1024 | ||
79 | }; | ||
78 | #include "regex.h" | 80 | #include "regex.h" |
79 | regex_t preg; | 81 | regex_t preg; |
80 | regmatch_t pmatch[REGS]; | 82 | regmatch_t pmatch[REGS]; |
@@ -134,68 +136,72 @@ char *client_cert = NULL; | |||
134 | char *client_privkey = NULL; | 136 | char *client_privkey = NULL; |
135 | 137 | ||
136 | // Forward function declarations | 138 | // Forward function declarations |
137 | bool process_arguments(int, char **); | 139 | bool process_arguments (int, char **); |
138 | int check_http(void); | 140 | int check_http (void); |
139 | void redir(char *pos, char *status_line); | 141 | void redir (char *pos, char *status_line); |
140 | bool server_type_check(const char *type); | 142 | bool server_type_check(const char *type); |
141 | int server_port_check(int ssl_flag); | 143 | int server_port_check(int ssl_flag); |
142 | char *perfd_time(double microsec); | 144 | char *perfd_time (double microsec); |
143 | char *perfd_time_connect(double microsec); | 145 | char *perfd_time_connect (double microsec); |
144 | char *perfd_time_ssl(double microsec); | 146 | char *perfd_time_ssl (double microsec); |
145 | char *perfd_time_firstbyte(double microsec); | 147 | char *perfd_time_firstbyte (double microsec); |
146 | char *perfd_time_headers(double microsec); | 148 | char *perfd_time_headers (double microsec); |
147 | char *perfd_time_transfer(double microsec); | 149 | char *perfd_time_transfer (double microsec); |
148 | char *perfd_size(int page_len); | 150 | char *perfd_size (int page_len); |
149 | void print_help(void); | 151 | void print_help (void); |
150 | void print_usage(void); | 152 | void print_usage (void); |
151 | char *unchunk_content(const char *content); | 153 | char *unchunk_content(const char *content); |
152 | 154 | ||
153 | int main(int argc, char **argv) { | 155 | int |
156 | main (int argc, char **argv) | ||
157 | { | ||
154 | int result = STATE_UNKNOWN; | 158 | int result = STATE_UNKNOWN; |
155 | 159 | ||
156 | setlocale(LC_ALL, ""); | 160 | setlocale (LC_ALL, ""); |
157 | bindtextdomain(PACKAGE, LOCALEDIR); | 161 | bindtextdomain (PACKAGE, LOCALEDIR); |
158 | textdomain(PACKAGE); | 162 | textdomain (PACKAGE); |
159 | 163 | ||
160 | /* Set default URL. Must be malloced for subsequent realloc if | 164 | /* Set default URL. Must be malloced for subsequent realloc if --onredirect=follow */ |
161 | * --onredirect=follow */ | ||
162 | server_url = strdup(HTTP_URL); | 165 | server_url = strdup(HTTP_URL); |
163 | server_url_length = strlen(server_url); | 166 | server_url_length = strlen(server_url); |
164 | xasprintf(&user_agent, "User-Agent: check_http/v%s (monitoring-plugins %s)", | 167 | xasprintf (&user_agent, "User-Agent: check_http/v%s (monitoring-plugins %s)", |
165 | NP_VERSION, VERSION); | 168 | NP_VERSION, VERSION); |
166 | 169 | ||
167 | /* Parse extra opts if any */ | 170 | /* Parse extra opts if any */ |
168 | argv = np_extra_opts(&argc, argv, progname); | 171 | argv=np_extra_opts (&argc, argv, progname); |
169 | 172 | ||
170 | if (process_arguments(argc, argv) == false) | 173 | if (process_arguments (argc, argv) == false) |
171 | usage4(_("Could not parse arguments")); | 174 | usage4 (_("Could not parse arguments")); |
172 | 175 | ||
173 | if (display_html == true) | 176 | if (display_html == true) |
174 | printf("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", | 177 | printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">", |
175 | use_ssl ? "https" : "http", host_name ? host_name : server_address, | 178 | use_ssl ? "https" : "http", host_name ? host_name : server_address, |
176 | server_port, server_url); | 179 | server_port, server_url); |
177 | 180 | ||
178 | /* initialize alarm signal handling, set socket timeout, start timer */ | 181 | /* initialize alarm signal handling, set socket timeout, start timer */ |
179 | (void)signal(SIGALRM, socket_timeout_alarm_handler); | 182 | (void) signal (SIGALRM, socket_timeout_alarm_handler); |
180 | (void)alarm(socket_timeout); | 183 | (void) alarm (socket_timeout); |
181 | gettimeofday(&tv, NULL); | 184 | gettimeofday (&tv, NULL); |
182 | 185 | ||
183 | result = check_http(); | 186 | result = check_http (); |
184 | return result; | 187 | return result; |
185 | } | 188 | } |
186 | 189 | ||
187 | /* check whether a file exists */ | 190 | /* check whether a file exists */ |
188 | void test_file(char *path) { | 191 | void |
192 | test_file (char *path) | ||
193 | { | ||
189 | if (access(path, R_OK) == 0) | 194 | if (access(path, R_OK) == 0) |
190 | return; | 195 | return; |
191 | usage2(_("file does not exist or is not readable"), path); | 196 | usage2 (_("file does not exist or is not readable"), path); |
192 | } | 197 | } |
193 | 198 | ||
194 | /* | 199 | /* |
195 | * process command-line arguments | 200 | * process command-line arguments |
196 | * returns true on succes, false otherwise | 201 | * returns true on succes, false otherwise |
197 | */ | 202 | */ |
198 | bool process_arguments(int argc, char **argv) { | 203 | bool process_arguments (int argc, char **argv) |
204 | { | ||
199 | int c = 1; | 205 | int c = 1; |
200 | char *p; | 206 | char *p; |
201 | char *temp; | 207 | char *temp; |
@@ -209,85 +215,83 @@ bool process_arguments(int argc, char **argv) { | |||
209 | 215 | ||
210 | int option = 0; | 216 | int option = 0; |
211 | static struct option longopts[] = { | 217 | static struct option longopts[] = { |
212 | STD_LONG_OPTS, | 218 | STD_LONG_OPTS, |
213 | {"link", no_argument, 0, 'L'}, | 219 | {"link", no_argument, 0, 'L'}, |
214 | {"nohtml", no_argument, 0, 'n'}, | 220 | {"nohtml", no_argument, 0, 'n'}, |
215 | {"ssl", optional_argument, 0, 'S'}, | 221 | {"ssl", optional_argument, 0, 'S'}, |
216 | {"sni", no_argument, 0, SNI_OPTION}, | 222 | {"sni", no_argument, 0, SNI_OPTION}, |
217 | {"post", required_argument, 0, 'P'}, | 223 | {"post", required_argument, 0, 'P'}, |
218 | {"method", required_argument, 0, 'j'}, | 224 | {"method", required_argument, 0, 'j'}, |
219 | {"IP-address", required_argument, 0, 'I'}, | 225 | {"IP-address", required_argument, 0, 'I'}, |
220 | {"url", required_argument, 0, 'u'}, | 226 | {"url", required_argument, 0, 'u'}, |
221 | {"port", required_argument, 0, 'p'}, | 227 | {"port", required_argument, 0, 'p'}, |
222 | {"authorization", required_argument, 0, 'a'}, | 228 | {"authorization", required_argument, 0, 'a'}, |
223 | {"proxy-authorization", required_argument, 0, 'b'}, | 229 | {"proxy-authorization", required_argument, 0, 'b'}, |
224 | {"header-string", required_argument, 0, 'd'}, | 230 | {"header-string", required_argument, 0, 'd'}, |
225 | {"string", required_argument, 0, 's'}, | 231 | {"string", required_argument, 0, 's'}, |
226 | {"expect", required_argument, 0, 'e'}, | 232 | {"expect", required_argument, 0, 'e'}, |
227 | {"regex", required_argument, 0, 'r'}, | 233 | {"regex", required_argument, 0, 'r'}, |
228 | {"ereg", required_argument, 0, 'r'}, | 234 | {"ereg", required_argument, 0, 'r'}, |
229 | {"eregi", required_argument, 0, 'R'}, | 235 | {"eregi", required_argument, 0, 'R'}, |
230 | {"linespan", no_argument, 0, 'l'}, | 236 | {"linespan", no_argument, 0, 'l'}, |
231 | {"onredirect", required_argument, 0, 'f'}, | 237 | {"onredirect", required_argument, 0, 'f'}, |
232 | {"certificate", required_argument, 0, 'C'}, | 238 | {"certificate", required_argument, 0, 'C'}, |
233 | {"client-cert", required_argument, 0, 'J'}, | 239 | {"client-cert", required_argument, 0, 'J'}, |
234 | {"private-key", required_argument, 0, 'K'}, | 240 | {"private-key", required_argument, 0, 'K'}, |
235 | {"continue-after-certificate", no_argument, 0, CONTINUE_AFTER_CHECK_CERT}, | 241 | {"continue-after-certificate", no_argument, 0, CONTINUE_AFTER_CHECK_CERT}, |
236 | {"useragent", required_argument, 0, 'A'}, | 242 | {"useragent", required_argument, 0, 'A'}, |
237 | {"header", required_argument, 0, 'k'}, | 243 | {"header", required_argument, 0, 'k'}, |
238 | {"no-body", no_argument, 0, 'N'}, | 244 | {"no-body", no_argument, 0, 'N'}, |
239 | {"max-age", required_argument, 0, 'M'}, | 245 | {"max-age", required_argument, 0, 'M'}, |
240 | {"content-type", required_argument, 0, 'T'}, | 246 | {"content-type", required_argument, 0, 'T'}, |
241 | {"pagesize", required_argument, 0, 'm'}, | 247 | {"pagesize", required_argument, 0, 'm'}, |
242 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, | 248 | {"invert-regex", no_argument, NULL, INVERT_REGEX}, |
243 | {"use-ipv4", no_argument, 0, '4'}, | 249 | {"use-ipv4", no_argument, 0, '4'}, |
244 | {"use-ipv6", no_argument, 0, '6'}, | 250 | {"use-ipv6", no_argument, 0, '6'}, |
245 | {"extended-perfdata", no_argument, 0, 'E'}, | 251 | {"extended-perfdata", no_argument, 0, 'E'}, |
246 | {"show-body", no_argument, 0, 'B'}, | 252 | {"show-body", no_argument, 0, 'B'}, |
247 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, | 253 | {"max-redirs", required_argument, 0, MAX_REDIRS_OPTION}, |
248 | {0, 0, 0, 0}}; | 254 | {0, 0, 0, 0} |
255 | }; | ||
249 | 256 | ||
250 | if (argc < 2) | 257 | if (argc < 2) |
251 | return false; | 258 | return false; |
252 | 259 | ||
253 | for (c = 1; c < argc; c++) { | 260 | for (c = 1; c < argc; c++) { |
254 | if (strcmp("-to", argv[c]) == 0) | 261 | if (strcmp ("-to", argv[c]) == 0) |
255 | strcpy(argv[c], "-t"); | 262 | strcpy (argv[c], "-t"); |
256 | if (strcmp("-hn", argv[c]) == 0) | 263 | if (strcmp ("-hn", argv[c]) == 0) |
257 | strcpy(argv[c], "-H"); | 264 | strcpy (argv[c], "-H"); |
258 | if (strcmp("-wt", argv[c]) == 0) | 265 | if (strcmp ("-wt", argv[c]) == 0) |
259 | strcpy(argv[c], "-w"); | 266 | strcpy (argv[c], "-w"); |
260 | if (strcmp("-ct", argv[c]) == 0) | 267 | if (strcmp ("-ct", argv[c]) == 0) |
261 | strcpy(argv[c], "-c"); | 268 | strcpy (argv[c], "-c"); |
262 | if (strcmp("-nohtml", argv[c]) == 0) | 269 | if (strcmp ("-nohtml", argv[c]) == 0) |
263 | strcpy(argv[c], "-n"); | 270 | strcpy (argv[c], "-n"); |
264 | } | 271 | } |
265 | 272 | ||
266 | while (1) { | 273 | while (1) { |
267 | c = getopt_long( | 274 | c = getopt_long (argc, argv, "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NEB", longopts, &option); |
268 | argc, argv, | ||
269 | "Vvh46t:c:w:A:k:H:P:j:T:I:a:b:d:e:p:s:R:r:u:f:C:J:K:nlLS::m:M:NEB", | ||
270 | longopts, &option); | ||
271 | if (c == -1 || c == EOF) | 275 | if (c == -1 || c == EOF) |
272 | break; | 276 | break; |
273 | 277 | ||
274 | switch (c) { | 278 | switch (c) { |
275 | case '?': /* usage */ | 279 | case '?': /* usage */ |
276 | usage5(); | 280 | usage5 (); |
277 | break; | 281 | break; |
278 | case 'h': /* help */ | 282 | case 'h': /* help */ |
279 | print_help(); | 283 | print_help (); |
280 | exit(STATE_UNKNOWN); | 284 | exit (STATE_UNKNOWN); |
281 | break; | 285 | break; |
282 | case 'V': /* version */ | 286 | case 'V': /* version */ |
283 | print_revision(progname, NP_VERSION); | 287 | print_revision (progname, NP_VERSION); |
284 | exit(STATE_UNKNOWN); | 288 | exit (STATE_UNKNOWN); |
285 | break; | 289 | break; |
286 | case 't': /* timeout period */ | 290 | case 't': /* timeout period */ |
287 | if (!is_intnonneg(optarg)) | 291 | if (!is_intnonneg (optarg)) |
288 | usage2(_("Timeout interval must be a positive integer"), optarg); | 292 | usage2 (_("Timeout interval must be a positive integer"), optarg); |
289 | else | 293 | else |
290 | socket_timeout = atoi(optarg); | 294 | socket_timeout = atoi (optarg); |
291 | break; | 295 | break; |
292 | case 'c': /* critical time threshold */ | 296 | case 'c': /* critical time threshold */ |
293 | critical_thresholds = optarg; | 297 | critical_thresholds = optarg; |
@@ -296,14 +300,13 @@ bool process_arguments(int argc, char **argv) { | |||
296 | warning_thresholds = optarg; | 300 | warning_thresholds = optarg; |
297 | break; | 301 | break; |
298 | case 'A': /* User Agent String */ | 302 | case 'A': /* User Agent String */ |
299 | xasprintf(&user_agent, "User-Agent: %s", optarg); | 303 | xasprintf (&user_agent, "User-Agent: %s", optarg); |
300 | break; | 304 | break; |
301 | case 'k': /* Additional headers */ | 305 | case 'k': /* Additional headers */ |
302 | if (http_opt_headers_count == 0) | 306 | if (http_opt_headers_count == 0) |
303 | http_opt_headers = malloc(sizeof(char *) * (++http_opt_headers_count)); | 307 | http_opt_headers = malloc (sizeof (char *) * (++http_opt_headers_count)); |
304 | else | 308 | else |
305 | http_opt_headers = realloc(http_opt_headers, | 309 | http_opt_headers = realloc (http_opt_headers, sizeof (char *) * (++http_opt_headers_count)); |
306 | sizeof(char *) * (++http_opt_headers_count)); | ||
307 | http_opt_headers[http_opt_headers_count - 1] = optarg; | 310 | http_opt_headers[http_opt_headers_count - 1] = optarg; |
308 | /* xasprintf (&http_opt_headers, "%s", optarg); */ | 311 | /* xasprintf (&http_opt_headers, "%s", optarg); */ |
309 | break; | 312 | break; |
@@ -315,27 +318,27 @@ bool process_arguments(int argc, char **argv) { | |||
315 | break; | 318 | break; |
316 | case 'C': /* Check SSL cert validity */ | 319 | case 'C': /* Check SSL cert validity */ |
317 | #ifdef HAVE_SSL | 320 | #ifdef HAVE_SSL |
318 | if ((temp = strchr(optarg, ',')) != NULL) { | 321 | if ((temp=strchr(optarg,','))!=NULL) { |
319 | *temp = '\0'; | 322 | *temp='\0'; |
320 | if (!is_intnonneg(optarg)) | 323 | if (!is_intnonneg (optarg)) |
321 | usage2(_("Invalid certificate expiration period"), optarg); | 324 | usage2 (_("Invalid certificate expiration period"), optarg); |
322 | days_till_exp_warn = atoi(optarg); | 325 | days_till_exp_warn = atoi(optarg); |
323 | *temp = ','; | 326 | *temp=','; |
324 | temp++; | 327 | temp++; |
325 | if (!is_intnonneg(temp)) | 328 | if (!is_intnonneg (temp)) |
326 | usage2(_("Invalid certificate expiration period"), temp); | 329 | usage2 (_("Invalid certificate expiration period"), temp); |
327 | days_till_exp_crit = atoi(temp); | 330 | days_till_exp_crit = atoi (temp); |
328 | } else { | 331 | } |
329 | days_till_exp_crit = 0; | 332 | else { |
330 | if (!is_intnonneg(optarg)) | 333 | days_till_exp_crit=0; |
331 | usage2(_("Invalid certificate expiration period"), optarg); | 334 | if (!is_intnonneg (optarg)) |
332 | days_till_exp_warn = atoi(optarg); | 335 | usage2 (_("Invalid certificate expiration period"), optarg); |
336 | days_till_exp_warn = atoi (optarg); | ||
333 | } | 337 | } |
334 | check_cert = true; | 338 | check_cert = true; |
335 | goto enable_ssl; | 339 | goto enable_ssl; |
336 | #endif | 340 | #endif |
337 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is | 341 | case CONTINUE_AFTER_CHECK_CERT: /* don't stop after the certificate is checked */ |
338 | checked */ | ||
339 | #ifdef HAVE_SSL | 342 | #ifdef HAVE_SSL |
340 | continue_after_check_cert = true; | 343 | continue_after_check_cert = true; |
341 | break; | 344 | break; |
@@ -355,16 +358,15 @@ bool process_arguments(int argc, char **argv) { | |||
355 | case 'S': /* use SSL */ | 358 | case 'S': /* use SSL */ |
356 | #ifdef HAVE_SSL | 359 | #ifdef HAVE_SSL |
357 | enable_ssl: | 360 | enable_ssl: |
358 | /* ssl_version initialized to 0 as a default. Only set if it's non-zero. | 361 | /* ssl_version initialized to 0 as a default. Only set if it's non-zero. This helps when we include multiple |
359 | This helps when we include multiple parameters, like -S and -C | 362 | parameters, like -S and -C combinations */ |
360 | combinations */ | ||
361 | use_ssl = true; | 363 | use_ssl = true; |
362 | if (c == 'S' && optarg != NULL) { | 364 | if (c=='S' && optarg != NULL) { |
363 | int got_plus = strchr(optarg, '+') != NULL; | 365 | int got_plus = strchr(optarg, '+') != NULL; |
364 | 366 | ||
365 | if (!strncmp(optarg, "1.2", 3)) | 367 | if (!strncmp (optarg, "1.2", 3)) |
366 | ssl_version = got_plus ? MP_TLSv1_2_OR_NEWER : MP_TLSv1_2; | 368 | ssl_version = got_plus ? MP_TLSv1_2_OR_NEWER : MP_TLSv1_2; |
367 | else if (!strncmp(optarg, "1.1", 3)) | 369 | else if (!strncmp (optarg, "1.1", 3)) |
368 | ssl_version = got_plus ? MP_TLSv1_1_OR_NEWER : MP_TLSv1_1; | 370 | ssl_version = got_plus ? MP_TLSv1_1_OR_NEWER : MP_TLSv1_1; |
369 | else if (optarg[0] == '1') | 371 | else if (optarg[0] == '1') |
370 | ssl_version = got_plus ? MP_TLSv1_OR_NEWER : MP_TLSv1; | 372 | ssl_version = got_plus ? MP_TLSv1_OR_NEWER : MP_TLSv1; |
@@ -373,104 +375,101 @@ bool process_arguments(int argc, char **argv) { | |||
373 | else if (optarg[0] == '2') | 375 | else if (optarg[0] == '2') |
374 | ssl_version = got_plus ? MP_SSLv2_OR_NEWER : MP_SSLv2; | 376 | ssl_version = got_plus ? MP_SSLv2_OR_NEWER : MP_SSLv2; |
375 | else | 377 | else |
376 | usage4(_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 " | 378 | usage4 (_("Invalid option - Valid SSL/TLS versions: 2, 3, 1, 1.1, 1.2 (with optional '+' suffix)")); |
377 | "(with optional '+' suffix)")); | ||
378 | } | 379 | } |
379 | if (specify_port == false) | 380 | if (specify_port == false) |
380 | server_port = HTTPS_PORT; | 381 | server_port = HTTPS_PORT; |
381 | #else | 382 | #else |
382 | /* -C -J and -K fall through to here without SSL */ | 383 | /* -C -J and -K fall through to here without SSL */ |
383 | usage4(_("Invalid option - SSL is not available")); | 384 | usage4 (_("Invalid option - SSL is not available")); |
384 | #endif | 385 | #endif |
385 | break; | 386 | break; |
386 | case SNI_OPTION: | 387 | case SNI_OPTION: |
387 | use_sni = true; | 388 | use_sni = true; |
388 | break; | 389 | break; |
389 | case MAX_REDIRS_OPTION: | 390 | case MAX_REDIRS_OPTION: |
390 | if (!is_intnonneg(optarg)) | 391 | if (!is_intnonneg (optarg)) |
391 | usage2(_("Invalid max_redirs count"), optarg); | 392 | usage2 (_("Invalid max_redirs count"), optarg); |
392 | else { | 393 | else { |
393 | max_depth = atoi(optarg); | 394 | max_depth = atoi (optarg); |
394 | } | 395 | } |
395 | break; | 396 | break; |
396 | case 'f': /* onredirect */ | 397 | case 'f': /* onredirect */ |
397 | if (!strcmp(optarg, "stickyport")) | 398 | if (!strcmp (optarg, "stickyport")) |
398 | onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST | STICKY_PORT; | 399 | onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST|STICKY_PORT; |
399 | else if (!strcmp(optarg, "sticky")) | 400 | else if (!strcmp (optarg, "sticky")) |
400 | onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST; | 401 | onredirect = STATE_DEPENDENT, followsticky = STICKY_HOST; |
401 | else if (!strcmp(optarg, "follow")) | 402 | else if (!strcmp (optarg, "follow")) |
402 | onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE; | 403 | onredirect = STATE_DEPENDENT, followsticky = STICKY_NONE; |
403 | else if (!strcmp(optarg, "unknown")) | 404 | else if (!strcmp (optarg, "unknown")) |
404 | onredirect = STATE_UNKNOWN; | 405 | onredirect = STATE_UNKNOWN; |
405 | else if (!strcmp(optarg, "ok")) | 406 | else if (!strcmp (optarg, "ok")) |
406 | onredirect = STATE_OK; | 407 | onredirect = STATE_OK; |
407 | else if (!strcmp(optarg, "warning")) | 408 | else if (!strcmp (optarg, "warning")) |
408 | onredirect = STATE_WARNING; | 409 | onredirect = STATE_WARNING; |
409 | else if (!strcmp(optarg, "critical")) | 410 | else if (!strcmp (optarg, "critical")) |
410 | onredirect = STATE_CRITICAL; | 411 | onredirect = STATE_CRITICAL; |
411 | else | 412 | else usage2 (_("Invalid onredirect option"), optarg); |
412 | usage2(_("Invalid onredirect option"), optarg); | ||
413 | if (verbose) | 413 | if (verbose) |
414 | printf(_("option f:%d \n"), onredirect); | 414 | printf(_("option f:%d \n"), onredirect); |
415 | break; | 415 | break; |
416 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ | 416 | /* Note: H, I, and u must be malloc'd or will fail on redirects */ |
417 | case 'H': /* Host Name (virtual host) */ | 417 | case 'H': /* Host Name (virtual host) */ |
418 | host_name = strdup(optarg); | 418 | host_name = strdup (optarg); |
419 | if (host_name[0] == '[') { | 419 | if (host_name[0] == '[') { |
420 | if ((p = strstr(host_name, "]:")) != NULL) { /* [IPv6]:port */ | 420 | if ((p = strstr (host_name, "]:")) != NULL) { /* [IPv6]:port */ |
421 | virtual_port = atoi(p + 2); | 421 | virtual_port = atoi (p + 2); |
422 | /* cut off the port */ | 422 | /* cut off the port */ |
423 | host_name_length = strlen(host_name) - strlen(p) - 1; | 423 | host_name_length = strlen (host_name) - strlen (p) - 1; |
424 | free(host_name); | 424 | free (host_name); |
425 | host_name = strndup(optarg, host_name_length); | 425 | host_name = strndup (optarg, host_name_length); |
426 | if (specify_port == false) | ||
427 | server_port = virtual_port; | ||
428 | } | ||
429 | } else if ((p = strchr (host_name, ':')) != NULL | ||
430 | && strchr (++p, ':') == NULL) { /* IPv4:port or host:port */ | ||
431 | virtual_port = atoi (p); | ||
432 | /* cut off the port */ | ||
433 | host_name_length = strlen (host_name) - strlen (p) - 1; | ||
434 | free (host_name); | ||
435 | host_name = strndup (optarg, host_name_length); | ||
426 | if (specify_port == false) | 436 | if (specify_port == false) |
427 | server_port = virtual_port; | 437 | server_port = virtual_port; |
428 | } | 438 | } |
429 | } else if ((p = strchr(host_name, ':')) != NULL && | ||
430 | strchr(++p, ':') == NULL) { /* IPv4:port or host:port */ | ||
431 | virtual_port = atoi(p); | ||
432 | /* cut off the port */ | ||
433 | host_name_length = strlen(host_name) - strlen(p) - 1; | ||
434 | free(host_name); | ||
435 | host_name = strndup(optarg, host_name_length); | ||
436 | if (specify_port == false) | ||
437 | server_port = virtual_port; | ||
438 | } | ||
439 | break; | 439 | break; |
440 | case 'I': /* Server IP-address */ | 440 | case 'I': /* Server IP-address */ |
441 | server_address = strdup(optarg); | 441 | server_address = strdup (optarg); |
442 | break; | 442 | break; |
443 | case 'u': /* URL path */ | 443 | case 'u': /* URL path */ |
444 | server_url = strdup(optarg); | 444 | server_url = strdup (optarg); |
445 | server_url_length = strlen(server_url); | 445 | server_url_length = strlen (server_url); |
446 | break; | 446 | break; |
447 | case 'p': /* Server port */ | 447 | case 'p': /* Server port */ |
448 | if (!is_intnonneg(optarg)) | 448 | if (!is_intnonneg (optarg)) |
449 | usage2(_("Invalid port number"), optarg); | 449 | usage2 (_("Invalid port number"), optarg); |
450 | else { | 450 | else { |
451 | server_port = atoi(optarg); | 451 | server_port = atoi (optarg); |
452 | specify_port = true; | 452 | specify_port = true; |
453 | } | 453 | } |
454 | break; | 454 | break; |
455 | case 'a': /* authorization info */ | 455 | case 'a': /* authorization info */ |
456 | strncpy(user_auth, optarg, MAX_INPUT_BUFFER - 1); | 456 | strncpy (user_auth, optarg, MAX_INPUT_BUFFER - 1); |
457 | user_auth[MAX_INPUT_BUFFER - 1] = 0; | 457 | user_auth[MAX_INPUT_BUFFER - 1] = 0; |
458 | break; | 458 | break; |
459 | case 'b': /* proxy-authorization info */ | 459 | case 'b': /* proxy-authorization info */ |
460 | strncpy(proxy_auth, optarg, MAX_INPUT_BUFFER - 1); | 460 | strncpy (proxy_auth, optarg, MAX_INPUT_BUFFER - 1); |
461 | proxy_auth[MAX_INPUT_BUFFER - 1] = 0; | 461 | proxy_auth[MAX_INPUT_BUFFER - 1] = 0; |
462 | break; | 462 | break; |
463 | case 'P': /* HTTP POST data in URL encoded format; ignored if settings | 463 | case 'P': /* HTTP POST data in URL encoded format; ignored if settings already */ |
464 | already */ | 464 | if (! http_post_data) |
465 | if (!http_post_data) | 465 | http_post_data = strdup (optarg); |
466 | http_post_data = strdup(optarg); | 466 | if (! http_method) |
467 | if (!http_method) | ||
468 | http_method = strdup("POST"); | 467 | http_method = strdup("POST"); |
469 | break; | 468 | break; |
470 | case 'j': /* Set HTTP method */ | 469 | case 'j': /* Set HTTP method */ |
471 | if (http_method) | 470 | if (http_method) |
472 | free(http_method); | 471 | free(http_method); |
473 | http_method = strdup(optarg); | 472 | http_method = strdup (optarg); |
474 | char *tmp; | 473 | char *tmp; |
475 | if ((tmp = strstr(http_method, ":")) > 0) { | 474 | if ((tmp = strstr(http_method, ":")) > 0) { |
476 | tmp[0] = '\0'; | 475 | tmp[0] = '\0'; |
@@ -479,20 +478,20 @@ bool process_arguments(int argc, char **argv) { | |||
479 | } | 478 | } |
480 | break; | 479 | break; |
481 | case 'd': /* string or substring */ | 480 | case 'd': /* string or substring */ |
482 | strncpy(header_expect, optarg, MAX_INPUT_BUFFER - 1); | 481 | strncpy (header_expect, optarg, MAX_INPUT_BUFFER - 1); |
483 | header_expect[MAX_INPUT_BUFFER - 1] = 0; | 482 | header_expect[MAX_INPUT_BUFFER - 1] = 0; |
484 | break; | 483 | break; |
485 | case 's': /* string or substring */ | 484 | case 's': /* string or substring */ |
486 | strncpy(string_expect, optarg, MAX_INPUT_BUFFER - 1); | 485 | strncpy (string_expect, optarg, MAX_INPUT_BUFFER - 1); |
487 | string_expect[MAX_INPUT_BUFFER - 1] = 0; | 486 | string_expect[MAX_INPUT_BUFFER - 1] = 0; |
488 | break; | 487 | break; |
489 | case 'e': /* string or substring */ | 488 | case 'e': /* string or substring */ |
490 | strncpy(server_expect, optarg, MAX_INPUT_BUFFER - 1); | 489 | strncpy (server_expect, optarg, MAX_INPUT_BUFFER - 1); |
491 | server_expect[MAX_INPUT_BUFFER - 1] = 0; | 490 | server_expect[MAX_INPUT_BUFFER - 1] = 0; |
492 | server_expect_yn = 1; | 491 | server_expect_yn = 1; |
493 | break; | 492 | break; |
494 | case 'T': /* Content-type */ | 493 | case 'T': /* Content-type */ |
495 | xasprintf(&http_content_type, "%s", optarg); | 494 | xasprintf (&http_content_type, "%s", optarg); |
496 | break; | 495 | break; |
497 | case 'l': /* linespan */ | 496 | case 'l': /* linespan */ |
498 | cflags &= ~REG_NEWLINE; | 497 | cflags &= ~REG_NEWLINE; |
@@ -500,12 +499,12 @@ bool process_arguments(int argc, char **argv) { | |||
500 | case 'R': /* regex */ | 499 | case 'R': /* regex */ |
501 | cflags |= REG_ICASE; | 500 | cflags |= REG_ICASE; |
502 | case 'r': /* regex */ | 501 | case 'r': /* regex */ |
503 | strncpy(regexp, optarg, MAX_RE_SIZE - 1); | 502 | strncpy (regexp, optarg, MAX_RE_SIZE - 1); |
504 | regexp[MAX_RE_SIZE - 1] = 0; | 503 | regexp[MAX_RE_SIZE - 1] = 0; |
505 | errcode = regcomp(&preg, regexp, cflags); | 504 | errcode = regcomp (&preg, regexp, cflags); |
506 | if (errcode != 0) { | 505 | if (errcode != 0) { |
507 | (void)regerror(errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 506 | (void) regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
508 | printf(_("Could Not Compile Regular Expression: %s"), errbuf); | 507 | printf (_("Could Not Compile Regular Expression: %s"), errbuf); |
509 | return false; | 508 | return false; |
510 | } | 509 | } |
511 | break; | 510 | break; |
@@ -519,53 +518,55 @@ bool process_arguments(int argc, char **argv) { | |||
519 | #ifdef USE_IPV6 | 518 | #ifdef USE_IPV6 |
520 | address_family = AF_INET6; | 519 | address_family = AF_INET6; |
521 | #else | 520 | #else |
522 | usage4(_("IPv6 support not available")); | 521 | usage4 (_("IPv6 support not available")); |
523 | #endif | 522 | #endif |
524 | break; | 523 | break; |
525 | case 'v': /* verbose */ | 524 | case 'v': /* verbose */ |
526 | verbose = true; | 525 | verbose = true; |
527 | break; | 526 | break; |
528 | case 'm': /* min_page_length */ | 527 | case 'm': /* min_page_length */ |
529 | { | 528 | { |
530 | char *tmp; | 529 | char *tmp; |
531 | if (strchr(optarg, ':') != (char *)NULL) { | 530 | if (strchr(optarg, ':') != (char *)NULL) { |
532 | /* range, so get two values, min:max */ | 531 | /* range, so get two values, min:max */ |
533 | tmp = strtok(optarg, ":"); | 532 | tmp = strtok(optarg, ":"); |
534 | if (tmp == NULL) { | 533 | if (tmp == NULL) { |
535 | printf("Bad format: try \"-m min:max\"\n"); | 534 | printf("Bad format: try \"-m min:max\"\n"); |
536 | exit(STATE_WARNING); | 535 | exit (STATE_WARNING); |
537 | } else | 536 | } else |
538 | min_page_len = atoi(tmp); | 537 | min_page_len = atoi(tmp); |
539 | 538 | ||
540 | tmp = strtok(NULL, ":"); | 539 | tmp = strtok(NULL, ":"); |
541 | if (tmp == NULL) { | 540 | if (tmp == NULL) { |
542 | printf("Bad format: try \"-m min:max\"\n"); | 541 | printf("Bad format: try \"-m min:max\"\n"); |
543 | exit(STATE_WARNING); | 542 | exit (STATE_WARNING); |
544 | } else | 543 | } else |
545 | max_page_len = atoi(tmp); | 544 | max_page_len = atoi(tmp); |
546 | } else | 545 | } else |
547 | min_page_len = atoi(optarg); | 546 | min_page_len = atoi (optarg); |
548 | break; | 547 | break; |
549 | } | 548 | } |
550 | case 'N': /* no-body */ | 549 | case 'N': /* no-body */ |
551 | no_body = true; | 550 | no_body = true; |
552 | break; | 551 | break; |
553 | case 'M': /* max-age */ | 552 | case 'M': /* max-age */ |
554 | { | 553 | { |
555 | int L = strlen(optarg); | 554 | int L = strlen(optarg); |
556 | if (L && optarg[L - 1] == 'm') | 555 | if (L && optarg[L-1] == 'm') |
557 | maximum_age = atoi(optarg) * 60; | 556 | maximum_age = atoi (optarg) * 60; |
558 | else if (L && optarg[L - 1] == 'h') | 557 | else if (L && optarg[L-1] == 'h') |
559 | maximum_age = atoi(optarg) * 60 * 60; | 558 | maximum_age = atoi (optarg) * 60 * 60; |
560 | else if (L && optarg[L - 1] == 'd') | 559 | else if (L && optarg[L-1] == 'd') |
561 | maximum_age = atoi(optarg) * 60 * 60 * 24; | 560 | maximum_age = atoi (optarg) * 60 * 60 * 24; |
562 | else if (L && (optarg[L - 1] == 's' || isdigit(optarg[L - 1]))) | 561 | else if (L && (optarg[L-1] == 's' || |
563 | maximum_age = atoi(optarg); | 562 | isdigit (optarg[L-1]))) |
564 | else { | 563 | maximum_age = atoi (optarg); |
565 | fprintf(stderr, "unparsable max-age: %s\n", optarg); | 564 | else { |
566 | exit(STATE_WARNING); | 565 | fprintf (stderr, "unparsable max-age: %s\n", optarg); |
567 | } | 566 | exit (STATE_WARNING); |
568 | } break; | 567 | } |
568 | } | ||
569 | break; | ||
569 | case 'E': /* show extended perfdata */ | 570 | case 'E': /* show extended perfdata */ |
570 | show_extended_perfdata = true; | 571 | show_extended_perfdata = true; |
571 | break; | 572 | break; |
@@ -578,32 +579,31 @@ bool process_arguments(int argc, char **argv) { | |||
578 | c = optind; | 579 | c = optind; |
579 | 580 | ||
580 | if (server_address == NULL && c < argc) | 581 | if (server_address == NULL && c < argc) |
581 | server_address = strdup(argv[c++]); | 582 | server_address = strdup (argv[c++]); |
582 | 583 | ||
583 | if (host_name == NULL && c < argc) | 584 | if (host_name == NULL && c < argc) |
584 | host_name = strdup(argv[c++]); | 585 | host_name = strdup (argv[c++]); |
585 | 586 | ||
586 | if (server_address == NULL) { | 587 | if (server_address == NULL) { |
587 | if (host_name == NULL) | 588 | if (host_name == NULL) |
588 | usage4(_("You must specify a server address or host name")); | 589 | usage4 (_("You must specify a server address or host name")); |
589 | else | 590 | else |
590 | server_address = strdup(host_name); | 591 | server_address = strdup (host_name); |
591 | } | 592 | } |
592 | 593 | ||
593 | set_thresholds(&thlds, warning_thresholds, critical_thresholds); | 594 | set_thresholds(&thlds, warning_thresholds, critical_thresholds); |
594 | 595 | ||
595 | if (critical_thresholds && thlds->critical->end > (double)socket_timeout) | 596 | if (critical_thresholds && thlds->critical->end>(double)socket_timeout) |
596 | socket_timeout = (int)thlds->critical->end + 1; | 597 | socket_timeout = (int)thlds->critical->end + 1; |
597 | 598 | ||
598 | if (http_method == NULL) | 599 | if (http_method == NULL) |
599 | http_method = strdup("GET"); | 600 | http_method = strdup ("GET"); |
600 | 601 | ||
601 | if (http_method_proxy == NULL) | 602 | if (http_method_proxy == NULL) |
602 | http_method_proxy = strdup("GET"); | 603 | http_method_proxy = strdup ("GET"); |
603 | 604 | ||
604 | if (client_cert && !client_privkey) | 605 | if (client_cert && !client_privkey) |
605 | usage4(_("If you use a client certificate you must also specify a private " | 606 | usage4 (_("If you use a client certificate you must also specify a private key file")); |
606 | "key file")); | ||
607 | 607 | ||
608 | if (virtual_port == 0) | 608 | if (virtual_port == 0) |
609 | virtual_port = server_port; | 609 | virtual_port = server_port; |
@@ -611,68 +611,89 @@ bool process_arguments(int argc, char **argv) { | |||
611 | return true; | 611 | return true; |
612 | } | 612 | } |
613 | 613 | ||
614 | |||
615 | |||
614 | /* Returns 1 if we're done processing the document body; 0 to keep going */ | 616 | /* Returns 1 if we're done processing the document body; 0 to keep going */ |
615 | static int document_headers_done(char *full_page) { | 617 | static int |
618 | document_headers_done (char *full_page) | ||
619 | { | ||
616 | const char *body; | 620 | const char *body; |
617 | 621 | ||
618 | for (body = full_page; *body; body++) { | 622 | for (body = full_page; *body; body++) { |
619 | if (!strncmp(body, "\n\n", 2) || !strncmp(body, "\n\r\n", 3)) | 623 | if (!strncmp (body, "\n\n", 2) || !strncmp (body, "\n\r\n", 3)) |
620 | break; | 624 | break; |
621 | } | 625 | } |
622 | 626 | ||
623 | if (!*body) | 627 | if (!*body) |
624 | return 0; /* haven't read end of headers yet */ | 628 | return 0; /* haven't read end of headers yet */ |
625 | 629 | ||
626 | full_page[body - full_page] = 0; | 630 | full_page[body - full_page] = 0; |
627 | return 1; | 631 | return 1; |
628 | } | 632 | } |
629 | 633 | ||
630 | static time_t parse_time_string(const char *string) { | 634 | static time_t |
635 | parse_time_string (const char *string) | ||
636 | { | ||
631 | struct tm tm; | 637 | struct tm tm; |
632 | time_t t; | 638 | time_t t; |
633 | memset(&tm, 0, sizeof(tm)); | 639 | memset (&tm, 0, sizeof(tm)); |
634 | 640 | ||
635 | /* Like this: Tue, 25 Dec 2001 02:59:03 GMT */ | 641 | /* Like this: Tue, 25 Dec 2001 02:59:03 GMT */ |
636 | 642 | ||
637 | if (isupper(string[0]) && /* Tue */ | 643 | if (isupper (string[0]) && /* Tue */ |
638 | islower(string[1]) && islower(string[2]) && ',' == string[3] && | 644 | islower (string[1]) && |
639 | ' ' == string[4] && (isdigit(string[5]) || string[5] == ' ') && /* 25 */ | 645 | islower (string[2]) && |
640 | isdigit(string[6]) && ' ' == string[7] && isupper(string[8]) && /* Dec */ | 646 | ',' == string[3] && |
641 | islower(string[9]) && islower(string[10]) && ' ' == string[11] && | 647 | ' ' == string[4] && |
642 | isdigit(string[12]) && /* 2001 */ | 648 | (isdigit(string[5]) || string[5] == ' ') && /* 25 */ |
643 | isdigit(string[13]) && isdigit(string[14]) && isdigit(string[15]) && | 649 | isdigit (string[6]) && |
644 | ' ' == string[16] && isdigit(string[17]) && /* 02: */ | 650 | ' ' == string[7] && |
645 | isdigit(string[18]) && ':' == string[19] && | 651 | isupper (string[8]) && /* Dec */ |
646 | isdigit(string[20]) && /* 59: */ | 652 | islower (string[9]) && |
647 | isdigit(string[21]) && ':' == string[22] && | 653 | islower (string[10]) && |
648 | isdigit(string[23]) && /* 03 */ | 654 | ' ' == string[11] && |
649 | isdigit(string[24]) && ' ' == string[25] && 'G' == string[26] && /* GMT */ | 655 | isdigit (string[12]) && /* 2001 */ |
650 | 'M' == string[27] && /* GMT */ | 656 | isdigit (string[13]) && |
651 | 'T' == string[28]) { | 657 | isdigit (string[14]) && |
652 | 658 | isdigit (string[15]) && | |
653 | tm.tm_sec = 10 * (string[23] - '0') + (string[24] - '0'); | 659 | ' ' == string[16] && |
654 | tm.tm_min = 10 * (string[20] - '0') + (string[21] - '0'); | 660 | isdigit (string[17]) && /* 02: */ |
655 | tm.tm_hour = 10 * (string[17] - '0') + (string[18] - '0'); | 661 | isdigit (string[18]) && |
656 | tm.tm_mday = | 662 | ':' == string[19] && |
657 | 10 * (string[5] == ' ' ? 0 : string[5] - '0') + (string[6] - '0'); | 663 | isdigit (string[20]) && /* 59: */ |
658 | tm.tm_mon = (!strncmp(string + 8, "Jan", 3) ? 0 | 664 | isdigit (string[21]) && |
659 | : !strncmp(string + 8, "Feb", 3) ? 1 | 665 | ':' == string[22] && |
660 | : !strncmp(string + 8, "Mar", 3) ? 2 | 666 | isdigit (string[23]) && /* 03 */ |
661 | : !strncmp(string + 8, "Apr", 3) ? 3 | 667 | isdigit (string[24]) && |
662 | : !strncmp(string + 8, "May", 3) ? 4 | 668 | ' ' == string[25] && |
663 | : !strncmp(string + 8, "Jun", 3) ? 5 | 669 | 'G' == string[26] && /* GMT */ |
664 | : !strncmp(string + 8, "Jul", 3) ? 6 | 670 | 'M' == string[27] && /* GMT */ |
665 | : !strncmp(string + 8, "Aug", 3) ? 7 | 671 | 'T' == string[28]) { |
666 | : !strncmp(string + 8, "Sep", 3) ? 8 | 672 | |
667 | : !strncmp(string + 8, "Oct", 3) ? 9 | 673 | tm.tm_sec = 10 * (string[23]-'0') + (string[24]-'0'); |
668 | : !strncmp(string + 8, "Nov", 3) ? 10 | 674 | tm.tm_min = 10 * (string[20]-'0') + (string[21]-'0'); |
669 | : !strncmp(string + 8, "Dec", 3) ? 11 | 675 | tm.tm_hour = 10 * (string[17]-'0') + (string[18]-'0'); |
670 | : -1); | 676 | tm.tm_mday = 10 * (string[5] == ' ' ? 0 : string[5]-'0') + (string[6]-'0'); |
671 | tm.tm_year = ((1000 * (string[12] - '0') + 100 * (string[13] - '0') + | 677 | tm.tm_mon = (!strncmp (string+8, "Jan", 3) ? 0 : |
672 | 10 * (string[14] - '0') + (string[15] - '0')) - | 678 | !strncmp (string+8, "Feb", 3) ? 1 : |
673 | 1900); | 679 | !strncmp (string+8, "Mar", 3) ? 2 : |
674 | 680 | !strncmp (string+8, "Apr", 3) ? 3 : | |
675 | tm.tm_isdst = 0; /* GMT is never in DST, right? */ | 681 | !strncmp (string+8, "May", 3) ? 4 : |
682 | !strncmp (string+8, "Jun", 3) ? 5 : | ||
683 | !strncmp (string+8, "Jul", 3) ? 6 : | ||
684 | !strncmp (string+8, "Aug", 3) ? 7 : | ||
685 | !strncmp (string+8, "Sep", 3) ? 8 : | ||
686 | !strncmp (string+8, "Oct", 3) ? 9 : | ||
687 | !strncmp (string+8, "Nov", 3) ? 10 : | ||
688 | !strncmp (string+8, "Dec", 3) ? 11 : | ||
689 | -1); | ||
690 | tm.tm_year = ((1000 * (string[12]-'0') + | ||
691 | 100 * (string[13]-'0') + | ||
692 | 10 * (string[14]-'0') + | ||
693 | (string[15]-'0')) | ||
694 | - 1900); | ||
695 | |||
696 | tm.tm_isdst = 0; /* GMT is never in DST, right? */ | ||
676 | 697 | ||
677 | if (tm.tm_mon < 0 || tm.tm_mday < 1 || tm.tm_mday > 31) | 698 | if (tm.tm_mon < 0 || tm.tm_mday < 1 || tm.tm_mday > 31) |
678 | return 0; | 699 | return 0; |
@@ -684,15 +705,14 @@ static time_t parse_time_string(const char *string) { | |||
684 | so it doesn't matter what time zone we parse them in. | 705 | so it doesn't matter what time zone we parse them in. |
685 | */ | 706 | */ |
686 | 707 | ||
687 | t = mktime(&tm); | 708 | t = mktime (&tm); |
688 | if (t == (time_t)-1) | 709 | if (t == (time_t) -1) t = 0; |
689 | t = 0; | ||
690 | 710 | ||
691 | if (verbose) { | 711 | if (verbose) { |
692 | const char *s = string; | 712 | const char *s = string; |
693 | while (*s && *s != '\r' && *s != '\n') | 713 | while (*s && *s != '\r' && *s != '\n') |
694 | fputc(*s++, stdout); | 714 | fputc (*s++, stdout); |
695 | printf(" ==> %lu\n", (unsigned long)t); | 715 | printf (" ==> %lu\n", (unsigned long) t); |
696 | } | 716 | } |
697 | 717 | ||
698 | return t; | 718 | return t; |
@@ -703,24 +723,28 @@ static time_t parse_time_string(const char *string) { | |||
703 | } | 723 | } |
704 | 724 | ||
705 | /* Checks if the server 'reply' is one of the expected 'statuscodes' */ | 725 | /* Checks if the server 'reply' is one of the expected 'statuscodes' */ |
706 | static int expected_statuscode(const char *reply, const char *statuscodes) { | 726 | static int |
727 | expected_statuscode (const char *reply, const char *statuscodes) | ||
728 | { | ||
707 | char *expected, *code; | 729 | char *expected, *code; |
708 | int result = 0; | 730 | int result = 0; |
709 | 731 | ||
710 | if ((expected = strdup(statuscodes)) == NULL) | 732 | if ((expected = strdup (statuscodes)) == NULL) |
711 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); | 733 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); |
712 | 734 | ||
713 | for (code = strtok(expected, ","); code != NULL; code = strtok(NULL, ",")) | 735 | for (code = strtok (expected, ","); code != NULL; code = strtok (NULL, ",")) |
714 | if (strstr(reply, code) != NULL) { | 736 | if (strstr (reply, code) != NULL) { |
715 | result = 1; | 737 | result = 1; |
716 | break; | 738 | break; |
717 | } | 739 | } |
718 | 740 | ||
719 | free(expected); | 741 | free (expected); |
720 | return result; | 742 | return result; |
721 | } | 743 | } |
722 | 744 | ||
723 | static int check_document_dates(const char *headers, char **msg) { | 745 | static int |
746 | check_document_dates (const char *headers, char **msg) | ||
747 | { | ||
724 | const char *s; | 748 | const char *s; |
725 | char *server_date = 0; | 749 | char *server_date = 0; |
726 | char *document_date = 0; | 750 | char *document_date = 0; |
@@ -748,78 +772,73 @@ static int check_document_dates(const char *headers, char **msg) { | |||
748 | s++; | 772 | s++; |
749 | 773 | ||
750 | /* Process this header. */ | 774 | /* Process this header. */ |
751 | if (value && value > field + 2) { | 775 | if (value && value > field+2) { |
752 | char *ff = (char *)malloc(value - field); | 776 | char *ff = (char *) malloc (value-field); |
753 | char *ss = ff; | 777 | char *ss = ff; |
754 | while (field < value - 1) | 778 | while (field < value-1) |
755 | *ss++ = tolower(*field++); | 779 | *ss++ = tolower(*field++); |
756 | *ss++ = 0; | 780 | *ss++ = 0; |
757 | 781 | ||
758 | if (!strcmp(ff, "date") || !strcmp(ff, "last-modified")) { | 782 | if (!strcmp (ff, "date") || !strcmp (ff, "last-modified")) { |
759 | const char *e; | 783 | const char *e; |
760 | while (*value && isspace(*value)) | 784 | while (*value && isspace (*value)) |
761 | value++; | 785 | value++; |
762 | for (e = value; *e && *e != '\r' && *e != '\n'; e++) | 786 | for (e = value; *e && *e != '\r' && *e != '\n'; e++) |
763 | ; | 787 | ; |
764 | ss = (char *)malloc(e - value + 1); | 788 | ss = (char *) malloc (e - value + 1); |
765 | strncpy(ss, value, e - value); | 789 | strncpy (ss, value, e - value); |
766 | ss[e - value] = 0; | 790 | ss[e - value] = 0; |
767 | if (!strcmp(ff, "date")) { | 791 | if (!strcmp (ff, "date")) { |
768 | if (server_date) | 792 | if (server_date) free (server_date); |
769 | free(server_date); | ||
770 | server_date = ss; | 793 | server_date = ss; |
771 | } else { | 794 | } else { |
772 | if (document_date) | 795 | if (document_date) free (document_date); |
773 | free(document_date); | ||
774 | document_date = ss; | 796 | document_date = ss; |
775 | } | 797 | } |
776 | } | 798 | } |
777 | free(ff); | 799 | free (ff); |
778 | } | 800 | } |
779 | } | 801 | } |
780 | 802 | ||
781 | /* Done parsing the body. Now check the dates we (hopefully) parsed. */ | 803 | /* Done parsing the body. Now check the dates we (hopefully) parsed. */ |
782 | if (!server_date || !*server_date) { | 804 | if (!server_date || !*server_date) { |
783 | xasprintf(msg, _("%sServer date unknown, "), *msg); | 805 | xasprintf (msg, _("%sServer date unknown, "), *msg); |
784 | date_result = max_state_alt(STATE_UNKNOWN, date_result); | 806 | date_result = max_state_alt(STATE_UNKNOWN, date_result); |
785 | } else if (!document_date || !*document_date) { | 807 | } else if (!document_date || !*document_date) { |
786 | xasprintf(msg, _("%sDocument modification date unknown, "), *msg); | 808 | xasprintf (msg, _("%sDocument modification date unknown, "), *msg); |
787 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 809 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
788 | } else { | 810 | } else { |
789 | time_t srv_data = parse_time_string(server_date); | 811 | time_t srv_data = parse_time_string (server_date); |
790 | time_t doc_data = parse_time_string(document_date); | 812 | time_t doc_data = parse_time_string (document_date); |
791 | 813 | ||
792 | if (srv_data <= 0) { | 814 | if (srv_data <= 0) { |
793 | xasprintf(msg, _("%sServer date \"%100s\" unparsable, "), *msg, | 815 | xasprintf (msg, _("%sServer date \"%100s\" unparsable, "), *msg, server_date); |
794 | server_date); | ||
795 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 816 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
796 | } else if (doc_data <= 0) { | 817 | } else if (doc_data <= 0) { |
797 | xasprintf(msg, _("%sDocument date \"%100s\" unparsable, "), *msg, | 818 | xasprintf (msg, _("%sDocument date \"%100s\" unparsable, "), *msg, document_date); |
798 | document_date); | ||
799 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 819 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
800 | } else if (doc_data > srv_data + 30) { | 820 | } else if (doc_data > srv_data + 30) { |
801 | xasprintf(msg, _("%sDocument is %d seconds in the future, "), *msg, | 821 | xasprintf (msg, _("%sDocument is %d seconds in the future, "), *msg, (int)doc_data - (int)srv_data); |
802 | (int)doc_data - (int)srv_data); | ||
803 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 822 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
804 | } else if (doc_data < srv_data - maximum_age) { | 823 | } else if (doc_data < srv_data - maximum_age) { |
805 | int n = (srv_data - doc_data); | 824 | int n = (srv_data - doc_data); |
806 | if (n > (60 * 60 * 24 * 2)) { | 825 | if (n > (60 * 60 * 24 * 2)) { |
807 | xasprintf(msg, _("%sLast modified %.1f days ago, "), *msg, | 826 | xasprintf (msg, _("%sLast modified %.1f days ago, "), *msg, ((float) n) / (60 * 60 * 24)); |
808 | ((float)n) / (60 * 60 * 24)); | ||
809 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 827 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
810 | } else { | 828 | } else { |
811 | xasprintf(msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, | 829 | xasprintf (msg, _("%sLast modified %d:%02d:%02d ago, "), *msg, n / (60 * 60), (n / 60) % 60, n % 60); |
812 | n / (60 * 60), (n / 60) % 60, n % 60); | ||
813 | date_result = max_state_alt(STATE_CRITICAL, date_result); | 830 | date_result = max_state_alt(STATE_CRITICAL, date_result); |
814 | } | 831 | } |
815 | } | 832 | } |
816 | free(server_date); | 833 | free (server_date); |
817 | free(document_date); | 834 | free (document_date); |
818 | } | 835 | } |
819 | return date_result; | 836 | return date_result; |
820 | } | 837 | } |
821 | 838 | ||
822 | int get_content_length(const char *headers) { | 839 | int |
840 | get_content_length (const char *headers) | ||
841 | { | ||
823 | const char *s; | 842 | const char *s; |
824 | int content_length = 0; | 843 | int content_length = 0; |
825 | 844 | ||
@@ -845,46 +864,50 @@ int get_content_length(const char *headers) { | |||
845 | s++; | 864 | s++; |
846 | 865 | ||
847 | /* Process this header. */ | 866 | /* Process this header. */ |
848 | if (value && value > field + 2) { | 867 | if (value && value > field+2) { |
849 | char *ff = (char *)malloc(value - field); | 868 | char *ff = (char *) malloc (value-field); |
850 | char *ss = ff; | 869 | char *ss = ff; |
851 | while (field < value - 1) | 870 | while (field < value-1) |
852 | *ss++ = tolower(*field++); | 871 | *ss++ = tolower(*field++); |
853 | *ss++ = 0; | 872 | *ss++ = 0; |
854 | 873 | ||
855 | if (!strcmp(ff, "content-length")) { | 874 | if (!strcmp (ff, "content-length")) { |
856 | const char *e; | 875 | const char *e; |
857 | while (*value && isspace(*value)) | 876 | while (*value && isspace (*value)) |
858 | value++; | 877 | value++; |
859 | for (e = value; *e && *e != '\r' && *e != '\n'; e++) | 878 | for (e = value; *e && *e != '\r' && *e != '\n'; e++) |
860 | ; | 879 | ; |
861 | ss = (char *)malloc(e - value + 1); | 880 | ss = (char *) malloc (e - value + 1); |
862 | strncpy(ss, value, e - value); | 881 | strncpy (ss, value, e - value); |
863 | ss[e - value] = 0; | 882 | ss[e - value] = 0; |
864 | content_length = atoi(ss); | 883 | content_length = atoi(ss); |
865 | free(ss); | 884 | free (ss); |
866 | } | 885 | } |
867 | free(ff); | 886 | free (ff); |
868 | } | 887 | } |
869 | } | 888 | } |
870 | return (content_length); | 889 | return (content_length); |
871 | } | 890 | } |
872 | 891 | ||
873 | char *prepend_slash(char *path) { | 892 | char * |
893 | prepend_slash (char *path) | ||
894 | { | ||
874 | char *newpath; | 895 | char *newpath; |
875 | 896 | ||
876 | if (path[0] == '/') | 897 | if (path[0] == '/') |
877 | return path; | 898 | return path; |
878 | 899 | ||
879 | if ((newpath = malloc(strlen(path) + 2)) == NULL) | 900 | if ((newpath = malloc (strlen(path) + 2)) == NULL) |
880 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); | 901 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Memory allocation error\n")); |
881 | newpath[0] = '/'; | 902 | newpath[0] = '/'; |
882 | strcpy(newpath + 1, path); | 903 | strcpy (newpath + 1, path); |
883 | free(path); | 904 | free (path); |
884 | return newpath; | 905 | return newpath; |
885 | } | 906 | } |
886 | 907 | ||
887 | int check_http(void) { | 908 | int |
909 | check_http (void) | ||
910 | { | ||
888 | char *msg; | 911 | char *msg; |
889 | char *status_line; | 912 | char *status_line; |
890 | char *status_code; | 913 | char *status_code; |
@@ -915,73 +938,62 @@ int check_http(void) { | |||
915 | char *force_host_header = NULL; | 938 | char *force_host_header = NULL; |
916 | 939 | ||
917 | /* try to connect to the host at the given port number */ | 940 | /* try to connect to the host at the given port number */ |
918 | gettimeofday(&tv_temp, NULL); | 941 | gettimeofday (&tv_temp, NULL); |
919 | if (my_tcp_connect(server_address, server_port, &sd) != STATE_OK) | 942 | if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK) |
920 | die(STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); | 943 | die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n")); |
921 | microsec_connect = deltime(tv_temp); | 944 | microsec_connect = deltime (tv_temp); |
922 | 945 | ||
923 | /* if we are called with the -I option, the -j method is CONNECT and */ | 946 | /* if we are called with the -I option, the -j method is CONNECT and */ |
924 | /* we received -S for SSL, then we tunnel the request through a proxy*/ | 947 | /* we received -S for SSL, then we tunnel the request through a proxy*/ |
925 | /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */ | 948 | /* @20100414, public[at]frank4dd.com, http://www.frank4dd.com/howto */ |
926 | 949 | ||
927 | if (server_address != NULL && strcmp(http_method, "CONNECT") == 0 && | 950 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
928 | host_name != NULL && use_ssl == true) { | 951 | && host_name != NULL && use_ssl == true) { |
929 | 952 | ||
930 | if (verbose) | 953 | if (verbose) printf ("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", server_address, server_port, host_name, HTTPS_PORT); |
931 | printf("Entering CONNECT tunnel mode with proxy %s:%d to dst %s:%d\n", | 954 | asprintf (&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, HTTPS_PORT, user_agent); |
932 | server_address, server_port, host_name, HTTPS_PORT); | ||
933 | asprintf(&buf, "%s %s:%d HTTP/1.1\r\n%s\r\n", http_method, host_name, | ||
934 | HTTPS_PORT, user_agent); | ||
935 | if (strlen(proxy_auth)) { | 955 | if (strlen(proxy_auth)) { |
936 | base64_encode_alloc(proxy_auth, strlen(proxy_auth), &auth); | 956 | base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); |
937 | xasprintf(&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); | 957 | xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); |
938 | } | 958 | } |
939 | /* optionally send any other header tag */ | 959 | /* optionally send any other header tag */ |
940 | if (http_opt_headers_count) { | 960 | if (http_opt_headers_count) { |
941 | for (i = 0; i < http_opt_headers_count; i++) { | 961 | for (i = 0; i < http_opt_headers_count ; i++) { |
942 | if (force_host_header != http_opt_headers[i]) { | 962 | if (force_host_header != http_opt_headers[i]) { |
943 | xasprintf(&buf, "%s%s\r\n", buf, http_opt_headers[i]); | 963 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); |
944 | } | 964 | } |
945 | } | 965 | } |
946 | /* This cannot be free'd here because a redirection will then try to | 966 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ |
947 | * access this and segfault */ | ||
948 | /* Covered in a testcase in tests/check_http.t */ | 967 | /* Covered in a testcase in tests/check_http.t */ |
949 | /* free(http_opt_headers); */ | 968 | /* free(http_opt_headers); */ |
950 | } | 969 | } |
951 | asprintf(&buf, "%sProxy-Connection: keep-alive\r\n", buf); | 970 | asprintf (&buf, "%sProxy-Connection: keep-alive\r\n", buf); |
952 | asprintf(&buf, "%sHost: %s\r\n", buf, host_name); | 971 | asprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
953 | /* we finished our request, send empty line with CRLF */ | 972 | /* we finished our request, send empty line with CRLF */ |
954 | asprintf(&buf, "%s%s", buf, CRLF); | 973 | asprintf (&buf, "%s%s", buf, CRLF); |
955 | if (verbose) | 974 | if (verbose) printf ("%s\n", buf); |
956 | printf("%s\n", buf); | 975 | send(sd, buf, strlen (buf), 0); |
957 | send(sd, buf, strlen(buf), 0); | 976 | buf[0]='\0'; |
958 | buf[0] = '\0'; | 977 | |
959 | 978 | if (verbose) printf ("Receive response from proxy\n"); | |
960 | if (verbose) | 979 | read (sd, buffer, MAX_INPUT_BUFFER-1); |
961 | printf("Receive response from proxy\n"); | 980 | if (verbose) printf ("%s", buffer); |
962 | read(sd, buffer, MAX_INPUT_BUFFER - 1); | ||
963 | if (verbose) | ||
964 | printf("%s", buffer); | ||
965 | /* Here we should check if we got HTTP/1.1 200 Connection established */ | 981 | /* Here we should check if we got HTTP/1.1 200 Connection established */ |
966 | } | 982 | } |
967 | #ifdef HAVE_SSL | 983 | #ifdef HAVE_SSL |
968 | elapsed_time_connect = (double)microsec_connect / 1.0e6; | 984 | elapsed_time_connect = (double)microsec_connect / 1.0e6; |
969 | if (use_ssl == true) { | 985 | if (use_ssl == true) { |
970 | gettimeofday(&tv_temp, NULL); | 986 | gettimeofday (&tv_temp, NULL); |
971 | result = np_net_ssl_init_with_hostname_version_and_cert( | 987 | result = np_net_ssl_init_with_hostname_version_and_cert(sd, (use_sni ? host_name : NULL), ssl_version, client_cert, client_privkey); |
972 | sd, (use_sni ? host_name : NULL), ssl_version, client_cert, | 988 | if (verbose) printf ("SSL initialized\n"); |
973 | client_privkey); | ||
974 | if (verbose) | ||
975 | printf("SSL initialized\n"); | ||
976 | if (result != STATE_OK) | 989 | if (result != STATE_OK) |
977 | die(STATE_CRITICAL, NULL); | 990 | die (STATE_CRITICAL, NULL); |
978 | microsec_ssl = deltime(tv_temp); | 991 | microsec_ssl = deltime (tv_temp); |
979 | elapsed_time_ssl = (double)microsec_ssl / 1.0e6; | 992 | elapsed_time_ssl = (double)microsec_ssl / 1.0e6; |
980 | if (check_cert == true) { | 993 | if (check_cert == true) { |
981 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); | 994 | result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit); |
982 | if (continue_after_check_cert == false) { | 995 | if (continue_after_check_cert == false) { |
983 | if (sd) | 996 | if (sd) close(sd); |
984 | close(sd); | ||
985 | np_net_ssl_cleanup(); | 997 | np_net_ssl_cleanup(); |
986 | return result; | 998 | return result; |
987 | } | 999 | } |
@@ -989,20 +1001,18 @@ int check_http(void) { | |||
989 | } | 1001 | } |
990 | #endif /* HAVE_SSL */ | 1002 | #endif /* HAVE_SSL */ |
991 | 1003 | ||
992 | if (server_address != NULL && strcmp(http_method, "CONNECT") == 0 && | 1004 | if ( server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
993 | host_name != NULL && use_ssl == true) | 1005 | && host_name != NULL && use_ssl == true) |
994 | asprintf(&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, | 1006 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method_proxy, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); |
995 | host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | ||
996 | else | 1007 | else |
997 | asprintf(&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, | 1008 | asprintf (&buf, "%s %s %s\r\n%s\r\n", http_method, server_url, host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); |
998 | host_name ? "HTTP/1.1" : "HTTP/1.0", user_agent); | ||
999 | 1009 | ||
1000 | /* tell HTTP/1.1 servers not to keep the connection alive */ | 1010 | /* tell HTTP/1.1 servers not to keep the connection alive */ |
1001 | xasprintf(&buf, "%sConnection: close\r\n", buf); | 1011 | xasprintf (&buf, "%sConnection: close\r\n", buf); |
1002 | 1012 | ||
1003 | /* check if Host header is explicitly set in options */ | 1013 | /* check if Host header is explicitly set in options */ |
1004 | if (http_opt_headers_count) { | 1014 | if (http_opt_headers_count) { |
1005 | for (i = 0; i < http_opt_headers_count; i++) { | 1015 | for (i = 0; i < http_opt_headers_count ; i++) { |
1006 | if (strncmp(http_opt_headers[i], "Host:", 5) == 0) { | 1016 | if (strncmp(http_opt_headers[i], "Host:", 5) == 0) { |
1007 | force_host_header = http_opt_headers[i]; | 1017 | force_host_header = http_opt_headers[i]; |
1008 | } | 1018 | } |
@@ -1012,8 +1022,9 @@ int check_http(void) { | |||
1012 | /* optionally send the host header info */ | 1022 | /* optionally send the host header info */ |
1013 | if (host_name) { | 1023 | if (host_name) { |
1014 | if (force_host_header) { | 1024 | if (force_host_header) { |
1015 | xasprintf(&buf, "%s%s\r\n", buf, force_host_header); | 1025 | xasprintf (&buf, "%s%s\r\n", buf, force_host_header); |
1016 | } else { | 1026 | } |
1027 | else { | ||
1017 | /* | 1028 | /* |
1018 | * Specify the port only if we're using a non-default port (see RFC 2616, | 1029 | * Specify the port only if we're using a non-default port (see RFC 2616, |
1019 | * 14.23). Some server applications/configurations cause trouble if the | 1030 | * 14.23). Some server applications/configurations cause trouble if the |
@@ -1021,69 +1032,65 @@ int check_http(void) { | |||
1021 | */ | 1032 | */ |
1022 | if ((use_ssl == false && virtual_port == HTTP_PORT) || | 1033 | if ((use_ssl == false && virtual_port == HTTP_PORT) || |
1023 | (use_ssl == true && virtual_port == HTTPS_PORT) || | 1034 | (use_ssl == true && virtual_port == HTTPS_PORT) || |
1024 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 && | 1035 | (server_address != NULL && strcmp(http_method, "CONNECT") == 0 |
1025 | host_name != NULL && use_ssl == true)) | 1036 | && host_name != NULL && use_ssl == true)) |
1026 | xasprintf(&buf, "%sHost: %s\r\n", buf, host_name); | 1037 | xasprintf (&buf, "%sHost: %s\r\n", buf, host_name); |
1027 | else | 1038 | else |
1028 | xasprintf(&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port); | 1039 | xasprintf (&buf, "%sHost: %s:%d\r\n", buf, host_name, virtual_port); |
1029 | } | 1040 | } |
1030 | } | 1041 | } |
1031 | 1042 | ||
1032 | /* optionally send any other header tag */ | 1043 | /* optionally send any other header tag */ |
1033 | if (http_opt_headers_count) { | 1044 | if (http_opt_headers_count) { |
1034 | for (i = 0; i < http_opt_headers_count; i++) { | 1045 | for (i = 0; i < http_opt_headers_count ; i++) { |
1035 | if (force_host_header != http_opt_headers[i]) { | 1046 | if (force_host_header != http_opt_headers[i]) { |
1036 | xasprintf(&buf, "%s%s\r\n", buf, http_opt_headers[i]); | 1047 | xasprintf (&buf, "%s%s\r\n", buf, http_opt_headers[i]); |
1037 | } | 1048 | } |
1038 | } | 1049 | } |
1039 | /* This cannot be free'd here because a redirection will then try to access | 1050 | /* This cannot be free'd here because a redirection will then try to access this and segfault */ |
1040 | * this and segfault */ | ||
1041 | /* Covered in a testcase in tests/check_http.t */ | 1051 | /* Covered in a testcase in tests/check_http.t */ |
1042 | /* free(http_opt_headers); */ | 1052 | /* free(http_opt_headers); */ |
1043 | } | 1053 | } |
1044 | 1054 | ||
1045 | /* optionally send the authentication info */ | 1055 | /* optionally send the authentication info */ |
1046 | if (strlen(user_auth)) { | 1056 | if (strlen(user_auth)) { |
1047 | base64_encode_alloc(user_auth, strlen(user_auth), &auth); | 1057 | base64_encode_alloc (user_auth, strlen (user_auth), &auth); |
1048 | xasprintf(&buf, "%sAuthorization: Basic %s\r\n", buf, auth); | 1058 | xasprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); |
1049 | } | 1059 | } |
1050 | 1060 | ||
1051 | /* optionally send the proxy authentication info */ | 1061 | /* optionally send the proxy authentication info */ |
1052 | if (strlen(proxy_auth)) { | 1062 | if (strlen(proxy_auth)) { |
1053 | base64_encode_alloc(proxy_auth, strlen(proxy_auth), &auth); | 1063 | base64_encode_alloc (proxy_auth, strlen (proxy_auth), &auth); |
1054 | xasprintf(&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); | 1064 | xasprintf (&buf, "%sProxy-Authorization: Basic %s\r\n", buf, auth); |
1055 | } | 1065 | } |
1056 | 1066 | ||
1057 | /* either send http POST data (any data, not only POST)*/ | 1067 | /* either send http POST data (any data, not only POST)*/ |
1058 | if (http_post_data) { | 1068 | if (http_post_data) { |
1059 | if (http_content_type) { | 1069 | if (http_content_type) { |
1060 | xasprintf(&buf, "%sContent-Type: %s\r\n", buf, http_content_type); | 1070 | xasprintf (&buf, "%sContent-Type: %s\r\n", buf, http_content_type); |
1061 | } else { | 1071 | } else { |
1062 | xasprintf(&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", | 1072 | xasprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); |
1063 | buf); | ||
1064 | } | 1073 | } |
1065 | 1074 | ||
1066 | xasprintf(&buf, "%sContent-Length: %i\r\n\r\n", buf, | 1075 | xasprintf (&buf, "%sContent-Length: %i\r\n\r\n", buf, (int)strlen (http_post_data)); |
1067 | (int)strlen(http_post_data)); | 1076 | xasprintf (&buf, "%s%s", buf, http_post_data); |
1068 | xasprintf(&buf, "%s%s", buf, http_post_data); | ||
1069 | } else { | 1077 | } else { |
1070 | /* or just a newline so the server knows we're done with the request */ | 1078 | /* or just a newline so the server knows we're done with the request */ |
1071 | xasprintf(&buf, "%s%s", buf, CRLF); | 1079 | xasprintf (&buf, "%s%s", buf, CRLF); |
1072 | } | 1080 | } |
1073 | 1081 | ||
1074 | if (verbose) | 1082 | if (verbose) printf ("%s\n", buf); |
1075 | printf("%s\n", buf); | 1083 | gettimeofday (&tv_temp, NULL); |
1076 | gettimeofday(&tv_temp, NULL); | 1084 | my_send (buf, strlen (buf)); |
1077 | my_send(buf, strlen(buf)); | 1085 | microsec_headers = deltime (tv_temp); |
1078 | microsec_headers = deltime(tv_temp); | ||
1079 | elapsed_time_headers = (double)microsec_headers / 1.0e6; | 1086 | elapsed_time_headers = (double)microsec_headers / 1.0e6; |
1080 | 1087 | ||
1081 | /* fetch the page */ | 1088 | /* fetch the page */ |
1082 | full_page = strdup(""); | 1089 | full_page = strdup(""); |
1083 | gettimeofday(&tv_temp, NULL); | 1090 | gettimeofday (&tv_temp, NULL); |
1084 | while ((i = my_recv(buffer, MAX_INPUT_BUFFER - 1)) > 0) { | 1091 | while ((i = my_recv (buffer, MAX_INPUT_BUFFER-1)) > 0) { |
1085 | if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) { | 1092 | if ((i >= 1) && (elapsed_time_firstbyte <= 0.000001)) { |
1086 | microsec_firstbyte = deltime(tv_temp); | 1093 | microsec_firstbyte = deltime (tv_temp); |
1087 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; | 1094 | elapsed_time_firstbyte = (double)microsec_firstbyte / 1.0e6; |
1088 | } | 1095 | } |
1089 | while (pos = memchr(buffer, '\0', i)) { | 1096 | while (pos = memchr(buffer, '\0', i)) { |
@@ -1101,12 +1108,12 @@ int check_http(void) { | |||
1101 | 1108 | ||
1102 | pagesize += i; | 1109 | pagesize += i; |
1103 | 1110 | ||
1104 | if (no_body && document_headers_done(full_page)) { | 1111 | if (no_body && document_headers_done (full_page)) { |
1105 | i = 0; | 1112 | i = 0; |
1106 | break; | 1113 | break; |
1107 | } | 1114 | } |
1108 | } | 1115 | } |
1109 | microsec_transfer = deltime(tv_temp); | 1116 | microsec_transfer = deltime (tv_temp); |
1110 | elapsed_time_transfer = (double)microsec_transfer / 1.0e6; | 1117 | elapsed_time_transfer = (double)microsec_transfer / 1.0e6; |
1111 | 1118 | ||
1112 | if (i < 0 && errno != ECONNRESET) { | 1119 | if (i < 0 && errno != ECONNRESET) { |
@@ -1114,123 +1121,121 @@ int check_http(void) { | |||
1114 | } | 1121 | } |
1115 | 1122 | ||
1116 | /* return a CRITICAL status if we couldn't read any data */ | 1123 | /* return a CRITICAL status if we couldn't read any data */ |
1117 | if (pagesize == (size_t)0) | 1124 | if (pagesize == (size_t) 0) |
1118 | die(STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); | 1125 | die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n")); |
1119 | 1126 | ||
1120 | /* close the connection */ | 1127 | /* close the connection */ |
1121 | if (sd) | 1128 | if (sd) close(sd); |
1122 | close(sd); | ||
1123 | #ifdef HAVE_SSL | 1129 | #ifdef HAVE_SSL |
1124 | np_net_ssl_cleanup(); | 1130 | np_net_ssl_cleanup(); |
1125 | #endif | 1131 | #endif |
1126 | 1132 | ||
1127 | /* Save check time */ | 1133 | /* Save check time */ |
1128 | microsec = deltime(tv); | 1134 | microsec = deltime (tv); |
1129 | elapsed_time = (double)microsec / 1.0e6; | 1135 | elapsed_time = (double)microsec / 1.0e6; |
1130 | 1136 | ||
1131 | /* leave full_page untouched so we can free it later */ | 1137 | /* leave full_page untouched so we can free it later */ |
1132 | page = full_page; | 1138 | page = full_page; |
1133 | 1139 | ||
1134 | if (verbose) | 1140 | if (verbose) |
1135 | printf("%s://%s:%d%s is %d characters\n", use_ssl ? "https" : "http", | 1141 | printf ("%s://%s:%d%s is %d characters\n", |
1136 | server_address, server_port, server_url, (int)pagesize); | 1142 | use_ssl ? "https" : "http", server_address, |
1143 | server_port, server_url, (int)pagesize); | ||
1137 | 1144 | ||
1138 | /* find status line and null-terminate it */ | 1145 | /* find status line and null-terminate it */ |
1139 | status_line = page; | 1146 | status_line = page; |
1140 | page += (size_t)strcspn(page, "\r\n"); | 1147 | page += (size_t) strcspn (page, "\r\n"); |
1141 | pos = page; | 1148 | pos = page; |
1142 | page += (size_t)strspn(page, "\r\n"); | 1149 | page += (size_t) strspn (page, "\r\n"); |
1143 | status_line[strcspn(status_line, "\r\n")] = 0; | 1150 | status_line[strcspn(status_line, "\r\n")] = 0; |
1144 | strip(status_line); | 1151 | strip (status_line); |
1145 | if (verbose) | 1152 | if (verbose) |
1146 | printf("STATUS: %s\n", status_line); | 1153 | printf ("STATUS: %s\n", status_line); |
1147 | 1154 | ||
1148 | /* find header info and null-terminate it */ | 1155 | /* find header info and null-terminate it */ |
1149 | header = page; | 1156 | header = page; |
1150 | while (strcspn(page, "\r\n") > 0) { | 1157 | while (strcspn (page, "\r\n") > 0) { |
1151 | page += (size_t)strcspn(page, "\r\n"); | 1158 | page += (size_t) strcspn (page, "\r\n"); |
1152 | pos = page; | 1159 | pos = page; |
1153 | if ((strspn(page, "\r") == 1 && strspn(page, "\r\n") >= 2) || | 1160 | if ((strspn (page, "\r") == 1 && strspn (page, "\r\n") >= 2) || |
1154 | (strspn(page, "\n") == 1 && strspn(page, "\r\n") >= 2)) | 1161 | (strspn (page, "\n") == 1 && strspn (page, "\r\n") >= 2)) |
1155 | page += (size_t)2; | 1162 | page += (size_t) 2; |
1156 | else | 1163 | else |
1157 | page += (size_t)1; | 1164 | page += (size_t) 1; |
1158 | } | 1165 | } |
1159 | page += (size_t)strspn(page, "\r\n"); | 1166 | page += (size_t) strspn (page, "\r\n"); |
1160 | header[pos - header] = 0; | 1167 | header[pos - header] = 0; |
1161 | if (verbose) | 1168 | if (verbose) |
1162 | printf("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header, | 1169 | printf ("**** HEADER ****\n%s\n**** CONTENT ****\n%s\n", header, |
1163 | (no_body ? " [[ skipped ]]" : page)); | 1170 | (no_body ? " [[ skipped ]]" : page)); |
1164 | 1171 | ||
1165 | /* make sure the status line matches the response we are looking for */ | 1172 | /* make sure the status line matches the response we are looking for */ |
1166 | if (!expected_statuscode(status_line, server_expect)) { | 1173 | if (!expected_statuscode (status_line, server_expect)) { |
1167 | if (server_port == HTTP_PORT) | 1174 | if (server_port == HTTP_PORT) |
1168 | xasprintf(&msg, _("Invalid HTTP response received from host: %s\n"), | 1175 | xasprintf (&msg, |
1176 | _("Invalid HTTP response received from host: %s\n"), | ||
1169 | status_line); | 1177 | status_line); |
1170 | else | 1178 | else |
1171 | xasprintf(&msg, | 1179 | xasprintf (&msg, |
1172 | _("Invalid HTTP response received from host on port %d: %s\n"), | 1180 | _("Invalid HTTP response received from host on port %d: %s\n"), |
1173 | server_port, status_line); | 1181 | server_port, status_line); |
1174 | if (show_body) | 1182 | if (show_body) |
1175 | xasprintf(&msg, _("%s\n%s"), msg, page); | 1183 | xasprintf (&msg, _("%s\n%s"), msg, page); |
1176 | die(STATE_CRITICAL, "HTTP CRITICAL - %s", msg); | 1184 | die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg); |
1177 | } | 1185 | } |
1178 | 1186 | ||
1179 | /* Bypass normal status line check if server_expect was set by user and not | 1187 | /* Bypass normal status line check if server_expect was set by user and not default */ |
1180 | * default */ | 1188 | /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string */ |
1181 | /* NOTE: After this if/else block msg *MUST* be an asprintf-allocated string | 1189 | if ( server_expect_yn ) { |
1182 | */ | 1190 | xasprintf (&msg, |
1183 | if (server_expect_yn) { | 1191 | _("Status line output matched \"%s\" - "), server_expect); |
1184 | xasprintf(&msg, _("Status line output matched \"%s\" - "), server_expect); | ||
1185 | if (verbose) | 1192 | if (verbose) |
1186 | printf("%s\n", msg); | 1193 | printf ("%s\n",msg); |
1187 | } else { | 1194 | } |
1195 | else { | ||
1188 | /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ | 1196 | /* Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF */ |
1189 | /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */ | 1197 | /* HTTP-Version = "HTTP" "/" 1*DIGIT "." 1*DIGIT */ |
1190 | /* Status-Code = 3 DIGITS */ | 1198 | /* Status-Code = 3 DIGITS */ |
1191 | 1199 | ||
1192 | status_code = strchr(status_line, ' ') + sizeof(char); | 1200 | status_code = strchr (status_line, ' ') + sizeof (char); |
1193 | if (strspn(status_code, "1234567890") != 3) | 1201 | if (strspn (status_code, "1234567890") != 3) |
1194 | die(STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), | 1202 | die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status Line (%s)\n"), status_line); |
1195 | status_line); | ||
1196 | 1203 | ||
1197 | http_status = atoi(status_code); | 1204 | http_status = atoi (status_code); |
1198 | 1205 | ||
1199 | /* check the return code */ | 1206 | /* check the return code */ |
1200 | 1207 | ||
1201 | if (http_status >= 600 || http_status < 100) { | 1208 | if (http_status >= 600 || http_status < 100) { |
1202 | die(STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), | 1209 | die (STATE_CRITICAL, _("HTTP CRITICAL: Invalid Status (%s)\n"), status_line); |
1203 | status_line); | ||
1204 | } | 1210 | } |
1205 | /* server errors result in a critical state */ | 1211 | /* server errors result in a critical state */ |
1206 | else if (http_status >= 500) { | 1212 | else if (http_status >= 500) { |
1207 | xasprintf(&msg, _("%s - "), status_line); | 1213 | xasprintf (&msg, _("%s - "), status_line); |
1208 | result = STATE_CRITICAL; | 1214 | result = STATE_CRITICAL; |
1209 | } | 1215 | } |
1210 | /* client errors result in a warning state */ | 1216 | /* client errors result in a warning state */ |
1211 | else if (http_status >= 400) { | 1217 | else if (http_status >= 400) { |
1212 | xasprintf(&msg, _("%s - "), status_line); | 1218 | xasprintf (&msg, _("%s - "), status_line); |
1213 | result = max_state_alt(STATE_WARNING, result); | 1219 | result = max_state_alt(STATE_WARNING, result); |
1214 | } | 1220 | } |
1215 | /* check redirected page if specified */ | 1221 | /* check redirected page if specified */ |
1216 | else if (http_status >= 300) { | 1222 | else if (http_status >= 300) { |
1217 | 1223 | ||
1218 | if (onredirect == STATE_DEPENDENT) | 1224 | if (onredirect == STATE_DEPENDENT) |
1219 | redir(header, status_line); | 1225 | redir (header, status_line); |
1220 | else | 1226 | else |
1221 | result = max_state_alt(onredirect, result); | 1227 | result = max_state_alt(onredirect, result); |
1222 | xasprintf(&msg, _("%s - "), status_line); | 1228 | xasprintf (&msg, _("%s - "), status_line); |
1223 | } /* end if (http_status >= 300) */ | 1229 | } /* end if (http_status >= 300) */ |
1224 | else { | 1230 | else { |
1225 | /* Print OK status anyway */ | 1231 | /* Print OK status anyway */ |
1226 | xasprintf(&msg, _("%s - "), status_line); | 1232 | xasprintf (&msg, _("%s - "), status_line); |
1227 | } | 1233 | } |
1228 | 1234 | ||
1229 | } /* end else (server_expect_yn) */ | 1235 | } /* end else (server_expect_yn) */ |
1230 | 1236 | ||
1231 | /* reset the alarm - must be called *after* redir or we'll never die on | 1237 | /* reset the alarm - must be called *after* redir or we'll never die on redirects! */ |
1232 | * redirects! */ | 1238 | alarm (0); |
1233 | alarm(0); | ||
1234 | 1239 | ||
1235 | if (maximum_age >= 0) { | 1240 | if (maximum_age >= 0) { |
1236 | result = max_state_alt(check_document_dates(header, &msg), result); | 1241 | result = max_state_alt(check_document_dates(header, &msg), result); |
@@ -1247,10 +1252,7 @@ int check_http(void) { | |||
1247 | bcopy("...", &output_header_search[sizeof(output_header_search) - 4], | 1252 | bcopy("...", &output_header_search[sizeof(output_header_search) - 4], |
1248 | 4); | 1253 | 4); |
1249 | } | 1254 | } |
1250 | xasprintf(&msg, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, | 1255 | xasprintf (&msg, _("%sheader '%s' not found on '%s://%s:%d%s', "), msg, output_header_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); |
1251 | output_header_search, use_ssl ? "https" : "http", | ||
1252 | host_name ? host_name : server_address, server_port, | ||
1253 | server_url); | ||
1254 | result = STATE_CRITICAL; | 1256 | result = STATE_CRITICAL; |
1255 | } | 1257 | } |
1256 | } | 1258 | } |
@@ -1288,10 +1290,7 @@ int check_http(void) { | |||
1288 | bcopy("...", &output_string_search[sizeof(output_string_search) - 4], | 1290 | bcopy("...", &output_string_search[sizeof(output_string_search) - 4], |
1289 | 4); | 1291 | 4); |
1290 | } | 1292 | } |
1291 | xasprintf(&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, | 1293 | xasprintf (&msg, _("%sstring '%s' not found on '%s://%s:%d%s', "), msg, output_string_search, use_ssl ? "https" : "http", host_name ? host_name : server_address, server_port, server_url); |
1292 | output_string_search, use_ssl ? "https" : "http", | ||
1293 | host_name ? host_name : server_address, server_port, | ||
1294 | server_url); | ||
1295 | result = STATE_CRITICAL; | 1294 | result = STATE_CRITICAL; |
1296 | } | 1295 | } |
1297 | } | 1296 | } |
@@ -1302,17 +1301,18 @@ int check_http(void) { | |||
1302 | (errcode == REG_NOMATCH && invert_regex == 1)) { | 1301 | (errcode == REG_NOMATCH && invert_regex == 1)) { |
1303 | /* OK - No-op to avoid changing the logic around it */ | 1302 | /* OK - No-op to avoid changing the logic around it */ |
1304 | result = max_state_alt(STATE_OK, result); | 1303 | result = max_state_alt(STATE_OK, result); |
1305 | } else if ((errcode == REG_NOMATCH && invert_regex == 0) || | 1304 | } |
1306 | (errcode == 0 && invert_regex == 1)) { | 1305 | else if ((errcode == REG_NOMATCH && invert_regex == 0) || (errcode == 0 && invert_regex == 1)) { |
1307 | if (invert_regex == 0) | 1306 | if (invert_regex == 0) |
1308 | xasprintf(&msg, _("%spattern not found, "), msg); | 1307 | xasprintf (&msg, _("%spattern not found, "), msg); |
1309 | else | 1308 | else |
1310 | xasprintf(&msg, _("%spattern found, "), msg); | 1309 | xasprintf (&msg, _("%spattern found, "), msg); |
1311 | result = STATE_CRITICAL; | 1310 | result = STATE_CRITICAL; |
1312 | } else { | 1311 | } |
1312 | else { | ||
1313 | /* FIXME: Shouldn't that be UNKNOWN? */ | 1313 | /* FIXME: Shouldn't that be UNKNOWN? */ |
1314 | regerror(errcode, &preg, errbuf, MAX_INPUT_BUFFER); | 1314 | regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); |
1315 | xasprintf(&msg, _("%sExecute Error: %s, "), msg, errbuf); | 1315 | xasprintf (&msg, _("%sExecute Error: %s, "), msg, errbuf); |
1316 | result = STATE_CRITICAL; | 1316 | result = STATE_CRITICAL; |
1317 | } | 1317 | } |
1318 | } | 1318 | } |
@@ -1328,42 +1328,46 @@ int check_http(void) { | |||
1328 | */ | 1328 | */ |
1329 | page_len = pagesize; | 1329 | page_len = pagesize; |
1330 | if ((max_page_len > 0) && (page_len > max_page_len)) { | 1330 | if ((max_page_len > 0) && (page_len > max_page_len)) { |
1331 | xasprintf(&msg, _("%spage size %d too large, "), msg, page_len); | 1331 | xasprintf (&msg, _("%spage size %d too large, "), msg, page_len); |
1332 | result = max_state_alt(STATE_WARNING, result); | 1332 | result = max_state_alt(STATE_WARNING, result); |
1333 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { | 1333 | } else if ((min_page_len > 0) && (page_len < min_page_len)) { |
1334 | xasprintf(&msg, _("%spage size %d too small, "), msg, page_len); | 1334 | xasprintf (&msg, _("%spage size %d too small, "), msg, page_len); |
1335 | result = max_state_alt(STATE_WARNING, result); | 1335 | result = max_state_alt(STATE_WARNING, result); |
1336 | } | 1336 | } |
1337 | 1337 | ||
1338 | /* Cut-off trailing characters */ | 1338 | /* Cut-off trailing characters */ |
1339 | if (msg[strlen(msg) - 2] == ',') | 1339 | if(msg[strlen(msg)-2] == ',') |
1340 | msg[strlen(msg) - 2] = '\0'; | 1340 | msg[strlen(msg)-2] = '\0'; |
1341 | else | 1341 | else |
1342 | msg[strlen(msg) - 3] = '\0'; | 1342 | msg[strlen(msg)-3] = '\0'; |
1343 | 1343 | ||
1344 | /* check elapsed time */ | 1344 | /* check elapsed time */ |
1345 | if (show_extended_perfdata) | 1345 | if (show_extended_perfdata) |
1346 | xasprintf( | 1346 | xasprintf (&msg, |
1347 | &msg, | 1347 | _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), |
1348 | _("%s - %d bytes in %.3f second response time %s|%s %s %s %s %s %s %s"), | 1348 | msg, page_len, elapsed_time, |
1349 | msg, page_len, elapsed_time, (display_html ? "</A>" : ""), | 1349 | (display_html ? "</A>" : ""), |
1350 | perfd_time(elapsed_time), perfd_size(page_len), | 1350 | perfd_time (elapsed_time), |
1351 | perfd_time_connect(elapsed_time_connect), | 1351 | perfd_size (page_len), |
1352 | use_ssl == true ? perfd_time_ssl(elapsed_time_ssl) : "", | 1352 | perfd_time_connect (elapsed_time_connect), |
1353 | perfd_time_headers(elapsed_time_headers), | 1353 | use_ssl == true ? perfd_time_ssl (elapsed_time_ssl) : "", |
1354 | perfd_time_firstbyte(elapsed_time_firstbyte), | 1354 | perfd_time_headers (elapsed_time_headers), |
1355 | perfd_time_transfer(elapsed_time_transfer)); | 1355 | perfd_time_firstbyte (elapsed_time_firstbyte), |
1356 | perfd_time_transfer (elapsed_time_transfer)); | ||
1356 | else | 1357 | else |
1357 | xasprintf(&msg, _("%s - %d bytes in %.3f second response time %s|%s %s"), | 1358 | xasprintf (&msg, |
1358 | msg, page_len, elapsed_time, (display_html ? "</A>" : ""), | 1359 | _("%s - %d bytes in %.3f second response time %s|%s %s"), |
1359 | perfd_time(elapsed_time), perfd_size(page_len)); | 1360 | msg, page_len, elapsed_time, |
1361 | (display_html ? "</A>" : ""), | ||
1362 | perfd_time (elapsed_time), | ||
1363 | perfd_size (page_len)); | ||
1360 | 1364 | ||
1361 | if (show_body) | 1365 | if (show_body) |
1362 | xasprintf(&msg, _("%s\n%s"), msg, page); | 1366 | xasprintf (&msg, _("%s\n%s"), msg, page); |
1363 | 1367 | ||
1364 | result = max_state_alt(get_status(elapsed_time, thlds), result); | 1368 | result = max_state_alt(get_status(elapsed_time, thlds), result); |
1365 | 1369 | ||
1366 | die(result, "HTTP %s: %s\n", state_text(result), msg); | 1370 | die (result, "HTTP %s: %s\n", state_text(result), msg); |
1367 | /* die failed? */ | 1371 | /* die failed? */ |
1368 | return STATE_UNKNOWN; | 1372 | return STATE_UNKNOWN; |
1369 | } | 1373 | } |
@@ -1453,22 +1457,20 @@ char *unchunk_content(const char *content) { | |||
1453 | 1457 | ||
1454 | /* per RFC 2396 */ | 1458 | /* per RFC 2396 */ |
1455 | #define URI_HTTP "%5[HTPShtps]" | 1459 | #define URI_HTTP "%5[HTPShtps]" |
1456 | #define URI_HOST \ | 1460 | #define URI_HOST "%255[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" |
1457 | "%255[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" | ||
1458 | #define URI_PORT "%6d" /* MAX_PORT's width is 5 chars, 6 to detect overflow */ | 1461 | #define URI_PORT "%6d" /* MAX_PORT's width is 5 chars, 6 to detect overflow */ |
1459 | #define URI_PATH \ | 1462 | #define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" |
1460 | "%[-_.!~*'();/" \ | ||
1461 | "?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" | ||
1462 | #define HD1 URI_HTTP "://" URI_HOST ":" URI_PORT "/" URI_PATH | 1463 | #define HD1 URI_HTTP "://" URI_HOST ":" URI_PORT "/" URI_PATH |
1463 | #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH | 1464 | #define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH |
1464 | #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT | 1465 | #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT |
1465 | #define HD4 URI_HTTP "://" URI_HOST | 1466 | #define HD4 URI_HTTP "://" URI_HOST |
1466 | /* relative reference redirect like //www.site.org/test | 1467 | /* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */ |
1467 | * https://tools.ietf.org/html/rfc3986 */ | ||
1468 | #define HD5 "//" URI_HOST "/" URI_PATH | 1468 | #define HD5 "//" URI_HOST "/" URI_PATH |
1469 | #define HD6 URI_PATH | 1469 | #define HD6 URI_PATH |
1470 | 1470 | ||
1471 | void redir(char *pos, char *status_line) { | 1471 | void |
1472 | redir (char *pos, char *status_line) | ||
1473 | { | ||
1472 | int i = 0; | 1474 | int i = 0; |
1473 | char *x; | 1475 | char *x; |
1474 | char xx[2]; | 1476 | char xx[2]; |
@@ -1476,101 +1478,101 @@ void redir(char *pos, char *status_line) { | |||
1476 | char *addr; | 1478 | char *addr; |
1477 | char *url; | 1479 | char *url; |
1478 | 1480 | ||
1479 | addr = malloc(MAX_IPV4_HOSTLENGTH + 1); | 1481 | addr = malloc (MAX_IPV4_HOSTLENGTH + 1); |
1480 | if (addr == NULL) | 1482 | if (addr == NULL) |
1481 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n")); | 1483 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n")); |
1482 | 1484 | ||
1483 | memset(addr, 0, MAX_IPV4_HOSTLENGTH); | 1485 | memset(addr, 0, MAX_IPV4_HOSTLENGTH); |
1484 | url = malloc(strcspn(pos, "\r\n")); | 1486 | url = malloc (strcspn (pos, "\r\n")); |
1485 | if (url == NULL) | 1487 | if (url == NULL) |
1486 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); | 1488 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); |
1487 | 1489 | ||
1488 | while (pos) { | 1490 | while (pos) { |
1489 | sscanf(pos, "%1[Ll]%*1[Oo]%*1[Cc]%*1[Aa]%*1[Tt]%*1[Ii]%*1[Oo]%*1[Nn]:%n", | 1491 | sscanf (pos, "%1[Ll]%*1[Oo]%*1[Cc]%*1[Aa]%*1[Tt]%*1[Ii]%*1[Oo]%*1[Nn]:%n", xx, &i); |
1490 | xx, &i); | ||
1491 | if (i == 0) { | 1492 | if (i == 0) { |
1492 | pos += (size_t)strcspn(pos, "\r\n"); | 1493 | pos += (size_t) strcspn (pos, "\r\n"); |
1493 | pos += (size_t)strspn(pos, "\r\n"); | 1494 | pos += (size_t) strspn (pos, "\r\n"); |
1494 | if (strlen(pos) == 0) | 1495 | if (strlen(pos) == 0) |
1495 | die(STATE_UNKNOWN, | 1496 | die (STATE_UNKNOWN, |
1496 | _("HTTP UNKNOWN - Could not find redirect location - %s%s\n"), | 1497 | _("HTTP UNKNOWN - Could not find redirect location - %s%s\n"), |
1497 | status_line, (display_html ? "</A>" : "")); | 1498 | status_line, (display_html ? "</A>" : "")); |
1498 | continue; | 1499 | continue; |
1499 | } | 1500 | } |
1500 | 1501 | ||
1501 | pos += i; | 1502 | pos += i; |
1502 | pos += strspn(pos, " \t"); | 1503 | pos += strspn (pos, " \t"); |
1503 | 1504 | ||
1504 | /* | 1505 | /* |
1505 | * RFC 2616 (4.2): ``Header fields can be extended over multiple lines by | 1506 | * RFC 2616 (4.2): ``Header fields can be extended over multiple lines by |
1506 | * preceding each extra line with at least one SP or HT.'' | 1507 | * preceding each extra line with at least one SP or HT.'' |
1507 | */ | 1508 | */ |
1508 | for (; (i = strspn(pos, "\r\n")); pos += i) { | 1509 | for (; (i = strspn (pos, "\r\n")); pos += i) { |
1509 | pos += i; | 1510 | pos += i; |
1510 | if (!(i = strspn(pos, " \t"))) { | 1511 | if (!(i = strspn (pos, " \t"))) { |
1511 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Empty redirect location%s\n"), | 1512 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Empty redirect location%s\n"), |
1512 | display_html ? "</A>" : ""); | 1513 | display_html ? "</A>" : ""); |
1513 | } | 1514 | } |
1514 | } | 1515 | } |
1515 | 1516 | ||
1516 | url = realloc(url, strcspn(pos, "\r\n") + 1); | 1517 | url = realloc (url, strcspn (pos, "\r\n") + 1); |
1517 | if (url == NULL) | 1518 | if (url == NULL) |
1518 | die(STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); | 1519 | die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate URL\n")); |
1519 | 1520 | ||
1520 | /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ | 1521 | /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ |
1521 | if (sscanf(pos, HD1, type, addr, &i, url) == 4) { | 1522 | if (sscanf (pos, HD1, type, addr, &i, url) == 4) { |
1522 | url = prepend_slash(url); | 1523 | url = prepend_slash (url); |
1523 | use_ssl = server_type_check(type); | 1524 | use_ssl = server_type_check (type); |
1524 | } | 1525 | } |
1525 | 1526 | ||
1526 | /* URI_HTTP URI_HOST URI_PATH */ | 1527 | /* URI_HTTP URI_HOST URI_PATH */ |
1527 | else if (sscanf(pos, HD2, type, addr, url) == 3) { | 1528 | else if (sscanf (pos, HD2, type, addr, url) == 3 ) { |
1528 | url = prepend_slash(url); | 1529 | url = prepend_slash (url); |
1529 | use_ssl = server_type_check(type); | 1530 | use_ssl = server_type_check (type); |
1530 | i = server_port_check(use_ssl); | 1531 | i = server_port_check (use_ssl); |
1531 | } | 1532 | } |
1532 | 1533 | ||
1533 | /* URI_HTTP URI_HOST URI_PORT */ | 1534 | /* URI_HTTP URI_HOST URI_PORT */ |
1534 | else if (sscanf(pos, HD3, type, addr, &i) == 3) { | 1535 | else if (sscanf (pos, HD3, type, addr, &i) == 3) { |
1535 | strcpy(url, HTTP_URL); | 1536 | strcpy (url, HTTP_URL); |
1536 | use_ssl = server_type_check(type); | 1537 | use_ssl = server_type_check (type); |
1537 | } | 1538 | } |
1538 | 1539 | ||
1539 | /* URI_HTTP URI_HOST */ | 1540 | /* URI_HTTP URI_HOST */ |
1540 | else if (sscanf(pos, HD4, type, addr) == 2) { | 1541 | else if (sscanf (pos, HD4, type, addr) == 2) { |
1541 | strcpy(url, HTTP_URL); | 1542 | strcpy (url, HTTP_URL); |
1542 | use_ssl = server_type_check(type); | 1543 | use_ssl = server_type_check (type); |
1543 | i = server_port_check(use_ssl); | 1544 | i = server_port_check (use_ssl); |
1544 | } | 1545 | } |
1545 | /* URI_HTTP, URI_HOST, URI_PATH */ | 1546 | /* URI_HTTP, URI_HOST, URI_PATH */ |
1546 | else if (sscanf(pos, HD5, addr, url) == 2) { | 1547 | else if (sscanf (pos, HD5, addr, url) == 2) { |
1547 | if (use_ssl) { | 1548 | if(use_ssl){ |
1548 | strcpy(type, "https"); | 1549 | strcpy (type,"https"); |
1549 | } else { | ||
1550 | strcpy(type, server_type); | ||
1551 | } | 1550 | } |
1552 | xasprintf(&url, "/%s", url); | 1551 | else{ |
1553 | use_ssl = server_type_check(type); | 1552 | strcpy (type, server_type); |
1554 | i = server_port_check(use_ssl); | 1553 | } |
1554 | xasprintf (&url, "/%s", url); | ||
1555 | use_ssl = server_type_check (type); | ||
1556 | i = server_port_check (use_ssl); | ||
1555 | } | 1557 | } |
1556 | 1558 | ||
1557 | /* URI_PATH */ | 1559 | /* URI_PATH */ |
1558 | else if (sscanf(pos, HD6, url) == 1) { | 1560 | else if (sscanf (pos, HD6, url) == 1) { |
1559 | /* relative url */ | 1561 | /* relative url */ |
1560 | if ((url[0] != '/')) { | 1562 | if ((url[0] != '/')) { |
1561 | if ((x = strrchr(server_url, '/'))) | 1563 | if ((x = strrchr(server_url, '/'))) |
1562 | *x = '\0'; | 1564 | *x = '\0'; |
1563 | xasprintf(&url, "%s/%s", server_url, url); | 1565 | xasprintf (&url, "%s/%s", server_url, url); |
1564 | } | 1566 | } |
1565 | i = server_port; | 1567 | i = server_port; |
1566 | strcpy(type, server_type); | 1568 | strcpy (type, server_type); |
1567 | strcpy(addr, host_name ? host_name : server_address); | 1569 | strcpy (addr, host_name ? host_name : server_address); |
1568 | } | 1570 | } |
1569 | 1571 | ||
1570 | else { | 1572 | else { |
1571 | die(STATE_UNKNOWN, | 1573 | die (STATE_UNKNOWN, |
1572 | _("HTTP UNKNOWN - Could not parse redirect location - %s%s\n"), pos, | 1574 | _("HTTP UNKNOWN - Could not parse redirect location - %s%s\n"), |
1573 | (display_html ? "</A>" : "")); | 1575 | pos, (display_html ? "</A>" : "")); |
1574 | } | 1576 | } |
1575 | 1577 | ||
1576 | break; | 1578 | break; |
@@ -1578,356 +1580,299 @@ void redir(char *pos, char *status_line) { | |||
1578 | } /* end while (pos) */ | 1580 | } /* end while (pos) */ |
1579 | 1581 | ||
1580 | if (++redir_depth > max_depth) | 1582 | if (++redir_depth > max_depth) |
1581 | die(STATE_WARNING, | 1583 | die (STATE_WARNING, |
1582 | _("HTTP WARNING - maximum redirection depth %d exceeded - " | 1584 | _("HTTP WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"), |
1583 | "%s://%s:%d%s%s\n"), | 1585 | max_depth, type, addr, i, url, (display_html ? "</A>" : "")); |
1584 | max_depth, type, addr, i, url, (display_html ? "</A>" : "")); | ||
1585 | 1586 | ||
1586 | if (server_port == i && !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && | 1587 | if (server_port==i && |
1588 | !strncmp(server_address, addr, MAX_IPV4_HOSTLENGTH) && | ||
1587 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && | 1589 | (host_name && !strncmp(host_name, addr, MAX_IPV4_HOSTLENGTH)) && |
1588 | !strcmp(server_url, url)) | 1590 | !strcmp(server_url, url)) |
1589 | die(STATE_CRITICAL, | 1591 | die (STATE_CRITICAL, |
1590 | _("HTTP CRITICAL - redirection creates an infinite loop - " | 1592 | _("HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"), |
1591 | "%s://%s:%d%s%s\n"), | 1593 | type, addr, i, url, (display_html ? "</A>" : "")); |
1592 | type, addr, i, url, (display_html ? "</A>" : "")); | ||
1593 | 1594 | ||
1594 | strcpy(server_type, type); | 1595 | strcpy (server_type, type); |
1595 | 1596 | ||
1596 | free(host_name); | 1597 | free (host_name); |
1597 | host_name = strndup(addr, MAX_IPV4_HOSTLENGTH); | 1598 | host_name = strndup (addr, MAX_IPV4_HOSTLENGTH); |
1598 | 1599 | ||
1599 | if (!(followsticky & STICKY_HOST)) { | 1600 | if (!(followsticky & STICKY_HOST)) { |
1600 | free(server_address); | 1601 | free (server_address); |
1601 | server_address = strndup(addr, MAX_IPV4_HOSTLENGTH); | 1602 | server_address = strndup (addr, MAX_IPV4_HOSTLENGTH); |
1602 | } | 1603 | } |
1603 | if (!(followsticky & STICKY_PORT)) { | 1604 | if (!(followsticky & STICKY_PORT)) { |
1604 | server_port = i; | 1605 | server_port = i; |
1605 | } | 1606 | } |
1606 | 1607 | ||
1607 | free(server_url); | 1608 | free (server_url); |
1608 | server_url = url; | 1609 | server_url = url; |
1609 | 1610 | ||
1610 | if (server_port > MAX_PORT) | 1611 | if (server_port > MAX_PORT) |
1611 | die(STATE_UNKNOWN, | 1612 | die (STATE_UNKNOWN, |
1612 | _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"), | 1613 | _("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"), |
1613 | MAX_PORT, server_type, server_address, server_port, server_url, | 1614 | MAX_PORT, server_type, server_address, server_port, server_url, |
1614 | display_html ? "</A>" : ""); | 1615 | display_html ? "</A>" : ""); |
1615 | 1616 | ||
1616 | /* reset virtual port */ | 1617 | /* reset virtual port */ |
1617 | virtual_port = server_port; | 1618 | virtual_port = server_port; |
1618 | 1619 | ||
1619 | if (verbose) | 1620 | if (verbose) |
1620 | printf(_("Redirection to %s://%s:%d%s\n"), server_type, | 1621 | printf (_("Redirection to %s://%s:%d%s\n"), server_type, |
1621 | host_name ? host_name : server_address, server_port, server_url); | 1622 | host_name ? host_name : server_address, server_port, server_url); |
1622 | 1623 | ||
1623 | free(addr); | 1624 | free(addr); |
1624 | check_http(); | 1625 | check_http (); |
1625 | } | 1626 | } |
1626 | 1627 | ||
1627 | bool server_type_check(const char *type) { | 1628 | |
1628 | if (strcmp(type, "https")) | 1629 | bool |
1630 | server_type_check (const char *type) | ||
1631 | { | ||
1632 | if (strcmp (type, "https")) | ||
1629 | return false; | 1633 | return false; |
1630 | else | 1634 | else |
1631 | return true; | 1635 | return true; |
1632 | } | 1636 | } |
1633 | 1637 | ||
1634 | int server_port_check(int ssl_flag) { | 1638 | int |
1639 | server_port_check (int ssl_flag) | ||
1640 | { | ||
1635 | if (ssl_flag) | 1641 | if (ssl_flag) |
1636 | return HTTPS_PORT; | 1642 | return HTTPS_PORT; |
1637 | else | 1643 | else |
1638 | return HTTP_PORT; | 1644 | return HTTP_PORT; |
1639 | } | 1645 | } |
1640 | 1646 | ||
1641 | char *perfd_time(double elapsed_time) { | 1647 | char *perfd_time (double elapsed_time) |
1642 | return fperfdata("time", elapsed_time, "s", thlds->warning ? true : false, | 1648 | { |
1643 | thlds->warning ? thlds->warning->end : 0, | 1649 | return fperfdata ("time", elapsed_time, "s", |
1644 | thlds->critical ? true : false, | 1650 | thlds->warning?true:false, thlds->warning?thlds->warning->end:0, |
1645 | thlds->critical ? thlds->critical->end : 0, true, 0, true, | 1651 | thlds->critical?true:false, thlds->critical?thlds->critical->end:0, |
1646 | socket_timeout); | 1652 | true, 0, true, socket_timeout); |
1647 | } | 1653 | } |
1648 | 1654 | ||
1649 | char *perfd_time_connect(double elapsed_time_connect) { | 1655 | char *perfd_time_connect (double elapsed_time_connect) |
1650 | return fperfdata("time_connect", elapsed_time_connect, "s", false, 0, false, | 1656 | { |
1651 | 0, false, 0, true, socket_timeout); | 1657 | return fperfdata ("time_connect", elapsed_time_connect, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1652 | } | 1658 | } |
1653 | 1659 | ||
1654 | char *perfd_time_ssl(double elapsed_time_ssl) { | 1660 | char *perfd_time_ssl (double elapsed_time_ssl) |
1655 | return fperfdata("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, | 1661 | { |
1656 | 0, true, socket_timeout); | 1662 | return fperfdata ("time_ssl", elapsed_time_ssl, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1657 | } | 1663 | } |
1658 | 1664 | ||
1659 | char *perfd_time_headers(double elapsed_time_headers) { | 1665 | char *perfd_time_headers (double elapsed_time_headers) |
1660 | return fperfdata("time_headers", elapsed_time_headers, "s", false, 0, false, | 1666 | { |
1661 | 0, false, 0, true, socket_timeout); | 1667 | return fperfdata ("time_headers", elapsed_time_headers, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1662 | } | 1668 | } |
1663 | 1669 | ||
1664 | char *perfd_time_firstbyte(double elapsed_time_firstbyte) { | 1670 | char *perfd_time_firstbyte (double elapsed_time_firstbyte) |
1665 | return fperfdata("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, | 1671 | { |
1666 | false, 0, false, 0, true, socket_timeout); | 1672 | return fperfdata ("time_firstbyte", elapsed_time_firstbyte, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1667 | } | 1673 | } |
1668 | 1674 | ||
1669 | char *perfd_time_transfer(double elapsed_time_transfer) { | 1675 | char *perfd_time_transfer (double elapsed_time_transfer) |
1670 | return fperfdata("time_transfer", elapsed_time_transfer, "s", false, 0, false, | 1676 | { |
1671 | 0, false, 0, true, socket_timeout); | 1677 | return fperfdata ("time_transfer", elapsed_time_transfer, "s", false, 0, false, 0, false, 0, true, socket_timeout); |
1672 | } | 1678 | } |
1673 | 1679 | ||
1674 | char *perfd_size(int page_len) { | 1680 | char *perfd_size (int page_len) |
1675 | return perfdata("size", page_len, "B", (min_page_len > 0 ? true : false), | 1681 | { |
1676 | min_page_len, (min_page_len > 0 ? true : false), 0, true, 0, | 1682 | return perfdata ("size", page_len, "B", |
1677 | false, 0); | 1683 | (min_page_len>0?true:false), min_page_len, |
1684 | (min_page_len>0?true:false), 0, | ||
1685 | true, 0, false, 0); | ||
1678 | } | 1686 | } |
1679 | 1687 | ||
1680 | void print_help(void) { | 1688 | void |
1681 | print_revision(progname, NP_VERSION); | 1689 | print_help (void) |
1690 | { | ||
1691 | print_revision (progname, NP_VERSION); | ||
1682 | 1692 | ||
1683 | printf("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 1693 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
1684 | printf(COPYRIGHT, copyright, email); | 1694 | printf (COPYRIGHT, copyright, email); |
1685 | 1695 | ||
1686 | printf("%s\n", _("This plugin tests the HTTP service on the specified host. " | 1696 | printf ("%s\n", _("This plugin tests the HTTP service on the specified host. It can test")); |
1687 | "It can test")); | 1697 | printf ("%s\n", _("normal (http) and secure (https) servers, follow redirects, search for")); |
1688 | printf("%s\n", _("normal (http) and secure (https) servers, follow " | 1698 | printf ("%s\n", _("strings and regular expressions, check connection times, and report on")); |
1689 | "redirects, search for")); | 1699 | printf ("%s\n", _("certificate expiration times.")); |
1690 | printf("%s\n", _("strings and regular expressions, check connection times, " | ||
1691 | "and report on")); | ||
1692 | printf("%s\n", _("certificate expiration times.")); | ||
1693 | 1700 | ||
1694 | printf("\n\n"); | 1701 | printf ("\n\n"); |
1695 | 1702 | ||
1696 | print_usage(); | 1703 | print_usage (); |
1697 | 1704 | ||
1698 | #ifdef HAVE_SSL | 1705 | #ifdef HAVE_SSL |
1699 | printf(_("In the first form, make an HTTP request.")); | 1706 | printf (_("In the first form, make an HTTP request.")); |
1700 | printf(_("In the second form, connect to the server and check the TLS " | 1707 | printf (_("In the second form, connect to the server and check the TLS certificate.")); |
1701 | "certificate.")); | ||
1702 | #endif | 1708 | #endif |
1703 | printf(_("NOTE: One or both of -H and -I must be specified")); | 1709 | printf (_("NOTE: One or both of -H and -I must be specified")); |
1704 | 1710 | ||
1705 | printf("\n"); | 1711 | printf ("\n"); |
1706 | 1712 | ||
1707 | printf(UT_HELP_VRSN); | 1713 | printf (UT_HELP_VRSN); |
1708 | printf(UT_EXTRA_OPTS); | 1714 | printf (UT_EXTRA_OPTS); |
1709 | 1715 | ||
1710 | printf(" %s\n", "-H, --hostname=ADDRESS"); | 1716 | printf (" %s\n", "-H, --hostname=ADDRESS"); |
1711 | printf(" %s\n", | 1717 | printf (" %s\n", _("Host name argument for servers using host headers (virtual host)")); |
1712 | _("Host name argument for servers using host headers (virtual host)")); | 1718 | printf (" %s\n", _("Append a port to include it in the header (eg: example.com:5000)")); |
1713 | printf(" %s\n", | 1719 | printf (" %s\n", "-I, --IP-address=ADDRESS"); |
1714 | _("Append a port to include it in the header (eg: example.com:5000)")); | 1720 | printf (" %s\n", _("IP address or name (use numeric address if possible to bypass DNS lookup).")); |
1715 | printf(" %s\n", "-I, --IP-address=ADDRESS"); | 1721 | printf (" %s\n", "-p, --port=INTEGER"); |
1716 | printf(" %s\n", _("IP address or name (use numeric address if possible to " | 1722 | printf (" %s", _("Port number (default: ")); |
1717 | "bypass DNS lookup).")); | 1723 | printf ("%d)\n", HTTP_PORT); |
1718 | printf(" %s\n", "-p, --port=INTEGER"); | ||
1719 | printf(" %s", _("Port number (default: ")); | ||
1720 | printf("%d)\n", HTTP_PORT); | ||
1721 | 1724 | ||
1722 | printf(UT_IPv46); | 1725 | printf (UT_IPv46); |
1723 | 1726 | ||
1724 | #ifdef HAVE_SSL | 1727 | #ifdef HAVE_SSL |
1725 | printf(" %s\n", "-S, --ssl=VERSION[+]"); | 1728 | printf (" %s\n", "-S, --ssl=VERSION[+]"); |
1726 | printf(" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is " | 1729 | printf (" %s\n", _("Connect via SSL. Port defaults to 443. VERSION is optional, and prevents")); |
1727 | "optional, and prevents")); | 1730 | printf (" %s\n", _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); |
1728 | printf( | 1731 | printf (" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are also accepted.")); |
1729 | " %s\n", | 1732 | printf (" %s\n", "--sni"); |
1730 | _("auto-negotiation (2 = SSLv2, 3 = SSLv3, 1 = TLSv1, 1.1 = TLSv1.1,")); | 1733 | printf (" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); |
1731 | printf(" %s\n", _("1.2 = TLSv1.2). With a '+' suffix, newer versions are " | 1734 | printf (" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); |
1732 | "also accepted.")); | 1735 | printf (" %s\n", _("Minimum number of days a certificate has to be valid. Port defaults to 443")); |
1733 | printf(" %s\n", "--sni"); | 1736 | printf (" %s\n", _("(when this option is used the URL is not checked by default. You can use")); |
1734 | printf(" %s\n", _("Enable SSL/TLS hostname extension support (SNI)")); | 1737 | printf (" %s\n", _(" --continue-after-certificate to override this behavior)")); |
1735 | printf(" %s\n", "-C, --certificate=INTEGER[,INTEGER]"); | 1738 | printf (" %s\n", "--continue-after-certificate"); |
1736 | printf(" %s\n", _("Minimum number of days a certificate has to be valid. " | 1739 | printf (" %s\n", _("Allows the HTTP check to continue after performing the certificate check.")); |
1737 | "Port defaults to 443")); | 1740 | printf (" %s\n", _("Does nothing unless -C is used.")); |
1738 | printf(" %s\n", _("(when this option is used the URL is not checked by " | 1741 | printf (" %s\n", "-J, --client-cert=FILE"); |
1739 | "default. You can use")); | 1742 | printf (" %s\n", _("Name of file that contains the client certificate (PEM format)")); |
1740 | printf(" %s\n", | 1743 | printf (" %s\n", _("to be used in establishing the SSL session")); |
1741 | _(" --continue-after-certificate to override this behavior)")); | 1744 | printf (" %s\n", "-K, --private-key=FILE"); |
1742 | printf(" %s\n", "--continue-after-certificate"); | 1745 | printf (" %s\n", _("Name of file containing the private key (PEM format)")); |
1743 | printf(" %s\n", _("Allows the HTTP check to continue after performing the " | 1746 | printf (" %s\n", _("matching the client certificate")); |
1744 | "certificate check.")); | ||
1745 | printf(" %s\n", _("Does nothing unless -C is used.")); | ||
1746 | printf(" %s\n", "-J, --client-cert=FILE"); | ||
1747 | printf(" %s\n", | ||
1748 | _("Name of file that contains the client certificate (PEM format)")); | ||
1749 | printf(" %s\n", _("to be used in establishing the SSL session")); | ||
1750 | printf(" %s\n", "-K, --private-key=FILE"); | ||
1751 | printf(" %s\n", _("Name of file containing the private key (PEM format)")); | ||
1752 | printf(" %s\n", _("matching the client certificate")); | ||
1753 | #endif | 1747 | #endif |
1754 | 1748 | ||
1755 | printf(" %s\n", "-e, --expect=STRING"); | 1749 | printf (" %s\n", "-e, --expect=STRING"); |
1756 | printf(" %s\n", _("Comma-delimited list of strings, at least one of them " | 1750 | printf (" %s\n", _("Comma-delimited list of strings, at least one of them is expected in")); |
1757 | "is expected in")); | 1751 | printf (" %s", _("the first (status) line of the server response (default: ")); |
1758 | printf(" %s", | 1752 | printf ("%s)\n", HTTP_EXPECT); |
1759 | _("the first (status) line of the server response (default: ")); | 1753 | printf (" %s\n", _("If specified skips all other status line logic (ex: 3xx, 4xx, 5xx processing)")); |
1760 | printf("%s)\n", HTTP_EXPECT); | 1754 | printf (" %s\n", "-d, --header-string=STRING"); |
1761 | printf(" %s\n", _("If specified skips all other status line logic (ex: " | 1755 | printf (" %s\n", _("String to expect in the response headers")); |
1762 | "3xx, 4xx, 5xx processing)")); | 1756 | printf (" %s\n", "-s, --string=STRING"); |
1763 | printf(" %s\n", "-d, --header-string=STRING"); | 1757 | printf (" %s\n", _("String to expect in the content")); |
1764 | printf(" %s\n", _("String to expect in the response headers")); | 1758 | printf (" %s\n", "-u, --url=PATH"); |
1765 | printf(" %s\n", "-s, --string=STRING"); | 1759 | printf (" %s\n", _("URL to GET or POST (default: /)")); |
1766 | printf(" %s\n", _("String to expect in the content")); | 1760 | printf (" %s\n", "-P, --post=STRING"); |
1767 | printf(" %s\n", "-u, --url=PATH"); | 1761 | printf (" %s\n", _("URL encoded http POST data")); |
1768 | printf(" %s\n", _("URL to GET or POST (default: /)")); | 1762 | printf (" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE, CONNECT, CONNECT:POST)"); |
1769 | printf(" %s\n", "-P, --post=STRING"); | 1763 | printf (" %s\n", _("Set HTTP method.")); |
1770 | printf(" %s\n", _("URL encoded http POST data")); | 1764 | printf (" %s\n", "-N, --no-body"); |
1771 | printf(" %s\n", "-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, " | 1765 | printf (" %s\n", _("Don't wait for document body: stop reading after headers.")); |
1772 | "PUT, DELETE, CONNECT, CONNECT:POST)"); | 1766 | printf (" %s\n", _("(Note that this still does an HTTP GET or POST, not a HEAD.)")); |
1773 | printf(" %s\n", _("Set HTTP method.")); | 1767 | printf (" %s\n", "-M, --max-age=SECONDS"); |
1774 | printf(" %s\n", "-N, --no-body"); | 1768 | printf (" %s\n", _("Warn if document is more than SECONDS old. the number can also be of")); |
1775 | printf(" %s\n", | 1769 | printf (" %s\n", _("the form \"10m\" for minutes, \"10h\" for hours, or \"10d\" for days.")); |
1776 | _("Don't wait for document body: stop reading after headers.")); | 1770 | printf (" %s\n", "-T, --content-type=STRING"); |
1777 | printf(" %s\n", | 1771 | printf (" %s\n", _("specify Content-Type header media type when POSTing\n")); |
1778 | _("(Note that this still does an HTTP GET or POST, not a HEAD.)")); | 1772 | |
1779 | printf(" %s\n", "-M, --max-age=SECONDS"); | 1773 | printf (" %s\n", "-l, --linespan"); |
1780 | printf(" %s\n", _("Warn if document is more than SECONDS old. the number " | 1774 | printf (" %s\n", _("Allow regex to span newlines (must precede -r or -R)")); |
1781 | "can also be of")); | 1775 | printf (" %s\n", "-r, --regex, --ereg=STRING"); |
1782 | printf(" %s\n", _("the form \"10m\" for minutes, \"10h\" for hours, or " | 1776 | printf (" %s\n", _("Search page for regex STRING")); |
1783 | "\"10d\" for days.")); | 1777 | printf (" %s\n", "-R, --eregi=STRING"); |
1784 | printf(" %s\n", "-T, --content-type=STRING"); | 1778 | printf (" %s\n", _("Search page for case-insensitive regex STRING")); |
1785 | printf(" %s\n", | 1779 | printf (" %s\n", "--invert-regex"); |
1786 | _("specify Content-Type header media type when POSTing\n")); | 1780 | printf (" %s\n", _("Return CRITICAL if found, OK if not\n")); |
1787 | 1781 | ||
1788 | printf(" %s\n", "-l, --linespan"); | 1782 | printf (" %s\n", "-a, --authorization=AUTH_PAIR"); |
1789 | printf(" %s\n", _("Allow regex to span newlines (must precede -r or -R)")); | 1783 | printf (" %s\n", _("Username:password on sites with basic authentication")); |
1790 | printf(" %s\n", "-r, --regex, --ereg=STRING"); | 1784 | printf (" %s\n", "-b, --proxy-authorization=AUTH_PAIR"); |
1791 | printf(" %s\n", _("Search page for regex STRING")); | 1785 | printf (" %s\n", _("Username:password on proxy-servers with basic authentication")); |
1792 | printf(" %s\n", "-R, --eregi=STRING"); | 1786 | printf (" %s\n", "-A, --useragent=STRING"); |
1793 | printf(" %s\n", _("Search page for case-insensitive regex STRING")); | 1787 | printf (" %s\n", _("String to be sent in http header as \"User Agent\"")); |
1794 | printf(" %s\n", "--invert-regex"); | 1788 | printf (" %s\n", "-k, --header=STRING"); |
1795 | printf(" %s\n", _("Return CRITICAL if found, OK if not\n")); | 1789 | printf (" %s\n", _("Any other tags to be sent in http header. Use multiple times for additional headers")); |
1796 | 1790 | printf (" %s\n", "-E, --extended-perfdata"); | |
1797 | printf(" %s\n", "-a, --authorization=AUTH_PAIR"); | 1791 | printf (" %s\n", _("Print additional performance data")); |
1798 | printf(" %s\n", _("Username:password on sites with basic authentication")); | 1792 | printf (" %s\n", "-B, --show-body"); |
1799 | printf(" %s\n", "-b, --proxy-authorization=AUTH_PAIR"); | 1793 | printf (" %s\n", _("Print body content below status line")); |
1800 | printf(" %s\n", | 1794 | printf (" %s\n", "-L, --link"); |
1801 | _("Username:password on proxy-servers with basic authentication")); | 1795 | printf (" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); |
1802 | printf(" %s\n", "-A, --useragent=STRING"); | 1796 | printf (" %s\n", "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); |
1803 | printf(" %s\n", _("String to be sent in http header as \"User Agent\"")); | 1797 | printf (" %s\n", _("How to handle redirected pages. sticky is like follow but stick to the")); |
1804 | printf(" %s\n", "-k, --header=STRING"); | 1798 | printf (" %s\n", _("specified IP address. stickyport also ensures port stays the same.")); |
1805 | printf(" %s\n", _("Any other tags to be sent in http header. Use multiple " | 1799 | printf (" %s\n", "--max-redirs=INTEGER"); |
1806 | "times for additional headers")); | 1800 | printf (" %s", _("Maximal number of redirects (default: ")); |
1807 | printf(" %s\n", "-E, --extended-perfdata"); | 1801 | printf ("%d)\n", DEFAULT_MAX_REDIRS); |
1808 | printf(" %s\n", _("Print additional performance data")); | 1802 | printf (" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); |
1809 | printf(" %s\n", "-B, --show-body"); | 1803 | printf (" %s\n", _("Minimum page size required (bytes) : Maximum page size required (bytes)")); |
1810 | printf(" %s\n", _("Print body content below status line")); | 1804 | printf (UT_WARN_CRIT); |
1811 | printf(" %s\n", "-L, --link"); | 1805 | |
1812 | printf(" %s\n", _("Wrap output in HTML link (obsoleted by urlize)")); | 1806 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1813 | printf(" %s\n", | 1807 | |
1814 | "-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>"); | 1808 | printf (UT_VERBOSE); |
1815 | printf(" %s\n", _("How to handle redirected pages. sticky is like follow " | 1809 | |
1816 | "but stick to the")); | 1810 | printf ("\n"); |
1817 | printf( | 1811 | printf ("%s\n", _("Notes:")); |
1818 | " %s\n", | 1812 | printf (" %s\n", _("This plugin will attempt to open an HTTP connection with the host.")); |
1819 | _("specified IP address. stickyport also ensures port stays the same.")); | 1813 | printf (" %s\n", _("Successful connects return STATE_OK, refusals and timeouts return STATE_CRITICAL")); |
1820 | printf(" %s\n", "--max-redirs=INTEGER"); | 1814 | printf (" %s\n", _("other errors return STATE_UNKNOWN. Successful connects, but incorrect response")); |
1821 | printf(" %s", _("Maximal number of redirects (default: ")); | 1815 | printf (" %s\n", _("messages from the host result in STATE_WARNING return values. If you are")); |
1822 | printf("%d)\n", DEFAULT_MAX_REDIRS); | 1816 | printf (" %s\n", _("checking a virtual server that uses 'host headers' you must supply the FQDN")); |
1823 | printf(" %s\n", "-m, --pagesize=INTEGER<:INTEGER>"); | 1817 | printf (" %s\n", _("(fully qualified domain name) as the [host_name] argument.")); |
1824 | printf(" %s\n", _("Minimum page size required (bytes) : Maximum page size " | ||
1825 | "required (bytes)")); | ||
1826 | printf(UT_WARN_CRIT); | ||
1827 | |||
1828 | printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | ||
1829 | |||
1830 | printf(UT_VERBOSE); | ||
1831 | |||
1832 | printf("\n"); | ||
1833 | printf("%s\n", _("Notes:")); | ||
1834 | printf( | ||
1835 | " %s\n", | ||
1836 | _("This plugin will attempt to open an HTTP connection with the host.")); | ||
1837 | printf(" %s\n", _("Successful connects return STATE_OK, refusals and " | ||
1838 | "timeouts return STATE_CRITICAL")); | ||
1839 | printf(" %s\n", _("other errors return STATE_UNKNOWN. Successful connects, " | ||
1840 | "but incorrect response")); | ||
1841 | printf(" %s\n", _("messages from the host result in STATE_WARNING return " | ||
1842 | "values. If you are")); | ||
1843 | printf(" %s\n", _("checking a virtual server that uses 'host headers' you " | ||
1844 | "must supply the FQDN")); | ||
1845 | printf(" %s\n", | ||
1846 | _("(fully qualified domain name) as the [host_name] argument.")); | ||
1847 | 1818 | ||
1848 | #ifdef HAVE_SSL | 1819 | #ifdef HAVE_SSL |
1849 | printf("\n"); | 1820 | printf ("\n"); |
1850 | printf(" %s\n", _("This plugin can also check whether an SSL enabled web " | 1821 | printf (" %s\n", _("This plugin can also check whether an SSL enabled web server is able to")); |
1851 | "server is able to")); | 1822 | printf (" %s\n", _("serve content (optionally within a specified time) or whether the X509 ")); |
1852 | printf(" %s\n", _("serve content (optionally within a specified time) or " | 1823 | printf (" %s\n", _("certificate is still valid for the specified number of days.")); |
1853 | "whether the X509 ")); | 1824 | printf ("\n"); |
1854 | printf(" %s\n", | 1825 | printf (" %s\n", _("Please note that this plugin does not check if the presented server")); |
1855 | _("certificate is still valid for the specified number of days.")); | 1826 | printf (" %s\n", _("certificate matches the hostname of the server, or if the certificate")); |
1856 | printf("\n"); | 1827 | printf (" %s\n", _("has a valid chain of trust to one of the locally installed CAs.")); |
1857 | printf( | 1828 | printf ("\n"); |
1858 | " %s\n", | 1829 | printf ("%s\n", _("Examples:")); |
1859 | _("Please note that this plugin does not check if the presented server")); | 1830 | printf (" %s\n\n", "CHECK CONTENT: check_http -w 5 -c 10 --ssl -H www.verisign.com"); |
1860 | printf(" %s\n", _("certificate matches the hostname of the server, or if the " | 1831 | printf (" %s\n", _("When the 'www.verisign.com' server returns its content within 5 seconds,")); |
1861 | "certificate")); | 1832 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); |
1862 | printf(" %s\n", | 1833 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); |
1863 | _("has a valid chain of trust to one of the locally installed CAs.")); | 1834 | printf (" %s\n", _("a STATE_CRITICAL will be returned.")); |
1864 | printf("\n"); | 1835 | printf ("\n"); |
1865 | printf("%s\n", _("Examples:")); | 1836 | printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14"); |
1866 | printf(" %s\n\n", | 1837 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 14 days,")); |
1867 | "CHECK CONTENT: check_http -w 5 -c 10 --ssl -H www.verisign.com"); | 1838 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); |
1868 | printf(" %s\n", _("When the 'www.verisign.com' server returns its content " | 1839 | printf (" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL will be returned when")); |
1869 | "within 5 seconds,")); | 1840 | printf (" %s\n\n", _("the certificate is expired.")); |
1870 | printf(" %s\n", _("a STATE_OK will be returned. When the server returns its " | 1841 | printf ("\n"); |
1871 | "content but exceeds")); | 1842 | printf (" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); |
1872 | printf(" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. " | 1843 | printf (" %s\n", _("When the certificate of 'www.verisign.com' is valid for more than 30 days,")); |
1873 | "When an error occurs,")); | 1844 | printf (" %s\n", _("a STATE_OK is returned. When the certificate is still valid, but for less than")); |
1874 | printf(" %s\n", _("a STATE_CRITICAL will be returned.")); | 1845 | printf (" %s\n", _("30 days, but more than 14 days, a STATE_WARNING is returned.")); |
1875 | printf("\n"); | 1846 | printf (" %s\n", _("A STATE_CRITICAL will be returned when certificate expires in less than 14 days")); |
1876 | printf(" %s\n\n", "CHECK CERTIFICATE: check_http -H www.verisign.com -C 14"); | 1847 | |
1877 | printf(" %s\n", _("When the certificate of 'www.verisign.com' is valid for " | 1848 | printf (" %s\n\n", "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: "); |
1878 | "more than 14 days,")); | 1849 | printf (" %s\n", _("check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S -j CONNECT -H www.verisign.com ")); |
1879 | printf(" %s\n", _("a STATE_OK is returned. When the certificate is still " | 1850 | printf (" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> -u <check-url> -S(sl) -j CONNECT -H <webserver>")); |
1880 | "valid, but for less than")); | 1851 | printf (" %s\n", _("a STATE_OK will be returned. When the server returns its content but exceeds")); |
1881 | printf(" %s\n", _("14 days, a STATE_WARNING is returned. A STATE_CRITICAL " | 1852 | printf (" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. When an error occurs,")); |
1882 | "will be returned when")); | 1853 | printf (" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to the method you can set the method used")); |
1883 | printf(" %s\n\n", _("the certificate is expired.")); | 1854 | printf (" %s\n", _("inside the proxied connection: -j CONNECT:POST")); |
1884 | printf("\n"); | ||
1885 | printf(" %s\n\n", | ||
1886 | "CHECK CERTIFICATE: check_http -H www.verisign.com -C 30,14"); | ||
1887 | printf(" %s\n", _("When the certificate of 'www.verisign.com' is valid for " | ||
1888 | "more than 30 days,")); | ||
1889 | printf(" %s\n", _("a STATE_OK is returned. When the certificate is still " | ||
1890 | "valid, but for less than")); | ||
1891 | printf(" %s\n", | ||
1892 | _("30 days, but more than 14 days, a STATE_WARNING is returned.")); | ||
1893 | printf(" %s\n", _("A STATE_CRITICAL will be returned when certificate " | ||
1894 | "expires in less than 14 days")); | ||
1895 | |||
1896 | printf(" %s\n\n", | ||
1897 | "CHECK SSL WEBSERVER CONTENT VIA PROXY USING HTTP 1.1 CONNECT: "); | ||
1898 | printf(" %s\n", | ||
1899 | _("check_http -I 192.168.100.35 -p 80 -u https://www.verisign.com/ -S " | ||
1900 | "-j CONNECT -H www.verisign.com ")); | ||
1901 | printf(" %s\n", _("all these options are needed: -I <proxy> -p <proxy-port> " | ||
1902 | "-u <check-url> -S(sl) -j CONNECT -H <webserver>")); | ||
1903 | printf(" %s\n", _("a STATE_OK will be returned. When the server returns its " | ||
1904 | "content but exceeds")); | ||
1905 | printf(" %s\n", _("the 5-second threshold, a STATE_WARNING will be returned. " | ||
1906 | "When an error occurs,")); | ||
1907 | printf(" %s\n", _("a STATE_CRITICAL will be returned. By adding a colon to " | ||
1908 | "the method you can set the method used")); | ||
1909 | printf(" %s\n", _("inside the proxied connection: -j CONNECT:POST")); | ||
1910 | 1855 | ||
1911 | #endif | 1856 | #endif |
1912 | 1857 | ||
1913 | printf(UT_SUPPORT); | 1858 | printf (UT_SUPPORT); |
1859 | |||
1914 | } | 1860 | } |
1915 | 1861 | ||
1916 | void print_usage(void) { | 1862 | |
1917 | printf("%s\n", _("Usage:")); | 1863 | |
1918 | printf(" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n", progname); | 1864 | void |
1919 | printf(" [-J <client certificate file>] [-K <private key>]\n"); | 1865 | print_usage (void) |
1920 | printf(" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] " | 1866 | { |
1921 | "[-E] [-a auth]\n"); | 1867 | printf ("%s\n", _("Usage:")); |
1922 | printf(" [-b proxy_auth] [-f " | 1868 | printf (" %s -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]\n",progname); |
1923 | "<ok|warning|critcal|follow|sticky|stickyport>]\n"); | 1869 | printf (" [-J <client certificate file>] [-K <private key>]\n"); |
1924 | printf(" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R " | 1870 | printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-E] [-a auth]\n"); |
1925 | "<case-insensitive regex>]\n"); | 1871 | printf (" [-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]\n"); |
1926 | printf(" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M " | 1872 | printf (" [-e <expect>] [-d string] [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n"); |
1927 | "<age>]\n"); | 1873 | printf (" [-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]\n"); |
1928 | printf(" [-A string] [-k string] [-S <version>] [--sni]\n"); | 1874 | printf (" [-A string] [-k string] [-S <version>] [--sni]\n"); |
1929 | printf(" [-T <content-type>] [-j method]\n"); | 1875 | printf (" [-T <content-type>] [-j method]\n"); |
1930 | printf(" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n", | 1876 | printf (" %s -H <vhost> | -I <IP-address> -C <warn_age>[,<crit_age>]\n",progname); |
1931 | progname); | 1877 | printf (" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); |
1932 | printf(" [-p <port>] [-t <timeout>] [-4|-6] [--sni]\n"); | ||
1933 | } | 1878 | } |