/rhcci/dsmirnov/bin/diff -u /tmp/check_http.c check_http.c --- /tmp/check_http.c 2003-07-07 09:16:27.144523707 -0700 +++ check_http.c 2003-07-07 09:41:25.721471000 -0700 @@ -194,6 +194,11 @@ #define URI_PORT ":%[0123456789]" #define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]" +#define HDR_SETCOOKIE "%*[Ss]%*[Ee]%*[Tt]%*[-]%*[Cc]%*[Oo]%*[Kk]%*[Ii]%*[Ee]: " +#define COOKIE_BODY "%[/a-zA-Z0-9._-=@,: ]" +#define COOKIE_PATH ";%[/a-zA-Z0-9._-=@,: ]" +#define COOKIE_DATE ";%[/a-zA-Z0-9._-=@,: ]" + enum { MAX_IPV4_HOSTLENGTH = 255, HTTP_PORT = 80, @@ -210,6 +215,7 @@ char server_port_text[6] = ""; char server_type[6] = "http"; char *server_address = ""; +char *cookies=NULL; char *host_name = ""; char *server_url = ""; int server_url_length; @@ -571,6 +577,13 @@ char *orig_url = NULL; double elapsed_time; int page_len = 0; + char *cpos = ""; + char cookie_body[255]; + char cookie_path[255]; + char cookie_date[255]; + struct tm tm; + char date[255],rest[128]; + #ifdef HAVE_SSL int sslerr; #endif @@ -610,6 +623,15 @@ asprintf (&buf, "%sUser-Agent: check_http/%s (nagios-plugins %s)\r\n", buf, clean_revstring (REVISION), PACKAGE_VERSION); + /* send Collected Cookies */ + if(cookies) + { + asprintf (&buf, "%s%s\r\n", buf,cookies); + } + + /* send "Connection: Keep-Alive" */ + asprintf (&buf, "%sConnection: Keep-Alive\r\n", buf); + /* optionally send the authentication info */ if (strcmp (user_auth, "")) { auth = base64 (user_auth, strlen (user_auth)); @@ -758,6 +780,44 @@ if (onredirect == STATE_DEPENDENT) { asprintf (&orig_url, "%s", server_url); + cpos = header; + cookies=NULL; + while (*cpos) { + cookie_date[0]='\0'; + if (sscanf(cpos, HDR_SETCOOKIE COOKIE_BODY COOKIE_PATH COOKIE_DATE, cookie_body, cookie_path, cookie_date)) { + if(verbose) + printf("Cookie parameters: body=%s path=%s date=%s\n", cookie_body, cookie_path, cookie_date); + + if(strlen(cookie_date)>1) + { + sscanf(cookie_date, "%*[Ee]%*[Xx]%*[Pp]%*[Ii]%*[Rr]%*[Ee]%*[Ss]=%*s %s %s %*s", date, rest); + strcat(date, " "); + strcat(date, rest); + strptime(date,"%d-%b-%Y %T",&tm); + + if(verbose) + 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); + if(mktime(&tm) < time(0)) + { + if(verbose) + printf("Ignoring cookie since expired\n"); + + cpos += (size_t) strcspn (cpos, "\r\n"); + cpos += (size_t) strspn (cpos, "\r\n"); + continue; + } + } + + if(cookies) + asprintf (&cookies, "%s;%s", cookies, cookie_body); + else + asprintf (&cookies, "Cookie: %s", cookie_body); + } + + cpos += (size_t) strcspn (cpos, "\r\n"); + cpos += (size_t) strspn (cpos, "\r\n"); + } /* end while (cpos) */ + pos = header; while (pos) { server_address = realloc (server_address, MAX_IPV4_HOSTLENGTH + 1);