diff options
Diffstat (limited to 'web/attachments/57050-check_http.cookies_patch')
-rw-r--r-- | web/attachments/57050-check_http.cookies_patch | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/web/attachments/57050-check_http.cookies_patch b/web/attachments/57050-check_http.cookies_patch new file mode 100644 index 0000000..d75778c --- /dev/null +++ b/web/attachments/57050-check_http.cookies_patch | |||
@@ -0,0 +1,159 @@ | |||
1 | --- nagios-plugins-1.3.1/plugins/check_http.c 2003-06-30 04:56:08.000000000 -0700 | ||
2 | +++ nagios-plugins-1.3.1.DS/plugins/check_http.c 2003-07-27 15:26:14.792132000 -0700 | ||
3 | @@ -44,7 +44,7 @@ | ||
4 | (-H <vhost> | -I <IP-address>) [-u <uri>] [-p <port>]\n\ | ||
5 | [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n\ | ||
6 | [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n\ | ||
7 | - [-s string] [-l] [-r <regex> | -R <case-insensitive regex>]\n\ | ||
8 | + [-s string] [-l] [-k] [-r <regex> | -R <case-insensitive regex>]\n\ | ||
9 | [-P string]" | ||
10 | |||
11 | #define LONGOPTIONS "\ | ||
12 | @@ -75,6 +75,8 @@ | ||
13 | Wrap output in HTML link (obsoleted by urlize)\n\ | ||
14 | -f, --onredirect=<ok|warning|critical|follow>\n\ | ||
15 | How to handle redirected pages\n%s%s\ | ||
16 | + -k, --keepalive\n\ | ||
17 | + Use Keep-Alive header in every request request\n\ | ||
18 | -v, --verbose\n\ | ||
19 | Show details for command-line debugging (do not use with nagios server)\n\ | ||
20 | -h, --help\n\ | ||
21 | @@ -186,6 +188,10 @@ | ||
22 | #define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" | ||
23 | #define URI_PORT ":%[0123456789]" | ||
24 | #define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" | ||
25 | +#define HDR_SETCOOKIE "%*[Ss]%*[Ee]%*[Tt]%*[-]%*[Cc]%*[Oo]%*[Kk]%*[Ii]%*[Ee]: " | ||
26 | +#define COOKIE_BODY "%[/a-zA-Z0-9._-=@,: ]" | ||
27 | +#define COOKIE_PATH ";%[/a-zA-Z0-9._-=@,: ]" | ||
28 | +#define COOKIE_DATE ";%[/a-zA-Z0-9._-=@,: ]" | ||
29 | enum { | ||
30 | MAX_IPV4_HOSTLENGTH = 255, | ||
31 | HTTP_PORT = 80, | ||
32 | @@ -206,6 +212,7 @@ | ||
33 | char *server_url = ""; | ||
34 | int server_url_length; | ||
35 | int server_expect_yn = 0; | ||
36 | +char *cookies=NULL; | ||
37 | char server_expect[MAX_INPUT_BUFFER] = HTTP_EXPECT; | ||
38 | char string_expect[MAX_INPUT_BUFFER] = ""; | ||
39 | double warning_time = 0; | ||
40 | @@ -216,6 +223,7 @@ | ||
41 | int display_html = FALSE; | ||
42 | int onredirect = STATE_OK; | ||
43 | int use_ssl = FALSE; | ||
44 | +int keepalive = FALSE; | ||
45 | int verbose = FALSE; | ||
46 | int sd; | ||
47 | char *http_method = "GET"; | ||
48 | @@ -309,6 +317,7 @@ | ||
49 | {"ereg", required_argument, 0, 'r'}, | ||
50 | {"eregi", required_argument, 0, 'R'}, | ||
51 | {"linespan", no_argument, 0, 'l'}, | ||
52 | + {"keepalive", no_argument, 0, 'k'}, | ||
53 | {"onredirect", required_argument, 0, 'f'}, | ||
54 | {"certificate", required_argument, 0, 'C'}, | ||
55 | {0, 0, 0, 0} | ||
56 | @@ -331,7 +340,7 @@ | ||
57 | strcpy (argv[c], "-n"); | ||
58 | } | ||
59 | |||
60 | -#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlLS" | ||
61 | +#define OPTCHARS "Vvht:c:w:H:P:I:a:e:p:s:R:r:u:f:C:nlkLS" | ||
62 | |||
63 | while (1) { | ||
64 | #ifdef HAVE_GETOPT_H | ||
65 | @@ -466,6 +475,9 @@ | ||
66 | } | ||
67 | break; | ||
68 | #endif | ||
69 | + case 'k': /* Keep-Alive */ | ||
70 | + keepalive = TRUE; | ||
71 | + break; | ||
72 | case 'v': /* verbose */ | ||
73 | verbose = TRUE; | ||
74 | break; | ||
75 | @@ -550,6 +562,12 @@ | ||
76 | char *x = NULL; | ||
77 | char *orig_url = NULL; | ||
78 | double elapsed_time; | ||
79 | + char *cpos = ""; | ||
80 | + char cookie_body[255]; | ||
81 | + char cookie_path[255]; | ||
82 | + char cookie_date[255]; | ||
83 | + struct tm tm; | ||
84 | + char date[255],rest[128]; | ||
85 | #ifdef HAVE_SSL | ||
86 | int sslerr; | ||
87 | #endif | ||
88 | @@ -589,6 +607,16 @@ | ||
89 | asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n", | ||
90 | buf, clean_revstring (REVISION), PACKAGE_VERSION); | ||
91 | |||
92 | + /* send Collected Cookies */ | ||
93 | + if(cookies) | ||
94 | + { | ||
95 | + asprintf (&buf, "%s%s\r\n", buf,cookies); | ||
96 | + } | ||
97 | + | ||
98 | + /* send "Connection: Keep-Alive" if need */ | ||
99 | + if(keepalive) | ||
100 | + asprintf (&buf, "%sConnection: Keep-Alive\r\n", buf); | ||
101 | + | ||
102 | /* optionally send the authentication info */ | ||
103 | if (strcmp (user_auth, "")) { | ||
104 | auth = base64 (user_auth, strlen (user_auth)); | ||
105 | @@ -615,6 +643,9 @@ | ||
106 | } | ||
107 | else { | ||
108 | #endif | ||
109 | + if (verbose) | ||
110 | + printf ("**** REQUEST ****\n%s\n", buf); | ||
111 | + | ||
112 | send (sd, buf, strlen (buf), 0); | ||
113 | #ifdef HAVE_SSL | ||
114 | } | ||
115 | @@ -737,6 +768,44 @@ | ||
116 | if (onredirect == STATE_DEPENDENT) { | ||
117 | |||
118 | asprintf (&orig_url, "%s", server_url); | ||
119 | + cpos = header; | ||
120 | + cookies=NULL; | ||
121 | + while (*cpos) { | ||
122 | + cookie_date[0]='\0'; | ||
123 | + if (sscanf(cpos, HDR_SETCOOKIE COOKIE_BODY COOKIE_PATH COOKIE_DATE, cookie_body, cookie_path, cookie_date)) { | ||
124 | + if(verbose) | ||
125 | + printf("Cookie parameters: body=%s path=%s date=%s\n", cookie_body, cookie_path, cookie_date); | ||
126 | + | ||
127 | + if(strlen(cookie_date)>1) | ||
128 | + { | ||
129 | + sscanf(cookie_date, "%*[Ee]%*[Xx]%*[Pp]%*[Ii]%*[Rr]%*[Ee]%*[Ss]=%*s %s %s %*s", date, rest); | ||
130 | + strcat(date, " "); | ||
131 | + strcat(date, rest); | ||
132 | + strptime(date,"%d-%b-%Y %T",&tm); | ||
133 | + | ||
134 | + if(verbose) | ||
135 | + printf("Cookie Date %d-%d-%d Time %d:%d:%d\n", tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec); | ||
136 | + if(mktime(&tm) < time(0)) | ||
137 | + { | ||
138 | + if(verbose) | ||
139 | + printf("Ignoring cookie since expired\n"); | ||
140 | + | ||
141 | + cpos += (size_t) strcspn (cpos, "\r\n"); | ||
142 | + cpos += (size_t) strspn (cpos, "\r\n"); | ||
143 | + continue; | ||
144 | + } | ||
145 | + } | ||
146 | + | ||
147 | + if(cookies) | ||
148 | + asprintf (&cookies, "%s;%s", cookies, cookie_body); | ||
149 | + else | ||
150 | + asprintf (&cookies, "Cookie: %s", cookie_body); | ||
151 | + } | ||
152 | + | ||
153 | + cpos += (size_t) strcspn (cpos, "\r\n"); | ||
154 | + cpos += (size_t) strspn (cpos, "\r\n"); | ||
155 | + } /* end while (cpos) */ | ||
156 | + | ||
157 | pos = header; | ||
158 | while (pos) { | ||
159 | server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1); | ||