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