#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#define SIZE 1000
//int maxtextbuffer = sizeof(char)*250;
//#define SIZE sizeof(char)*250
#define SIZE 255

int main() {
	FILE* fp;
	int count = 0; 
	int detected = 0;
	char buf[SIZE];
	if( ( fp = fopen( "/var/log/httpd/access_log", "r" ) ) == NULL ) {
		fprintf( stderr, "Error opening file.\n" );
		exit( 1 );
	}
//70.166.30.6 - - [02/Mar/2009:07:26:34 -0800] "GET /lsquote/0.2.1/lsquote.pl HTTP/1.0" 200 26533
//72.30.81.155 - - [22/Feb/2009:12:06:22 -0800] "GET /lspi/0.0.1/lspi.c HTTP/1.0" 200 2729
        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
		count = 0;
		while (buf[count] != 'G'){
				count++;
			}

			if (buf[count+10] == '0'){
				//printf("0 found\n");
				if (buf[count+11] == '.'){
					if (buf[count+12] == '0'){ 
						if (buf[count+13] == '.'){ 
							if (buf[count+14] == '1'){
								//printf("0.2.1 found\n"); 
								if (buf[count+16] == 'l'){ 
									if (buf[count+17] == 's'){ 
										if (buf[count+18] == 'p'){ 
											if (buf[count+19] == 'i'){ 
												if (buf[count+20] == '.'){ 
													if (buf[count+21] == 'c'){ 
														//if (buf[count+22] == 'e'){
															detected++;
		
			}
				}
					}
						}
							}
								}
									}
										}
											}
												}
													}
														//}







	}
	//printf( "NUMBER OF CORES: %d\n", coresdetected );

	fclose( fp );



        if( ( fp = fopen( "/var/log/httpd/access_log.1", "r" ) ) == NULL ) {
                //fprintf( stderr, "Error opening file.\n" );
                //exit( 1 );
        }

        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
                count = 0;
                while (buf[count] != 'G'){
                                count++;
                        }

                        if (buf[count+10] == '0'){
                                //printf("0 found\n");
                                if (buf[count+11] == '.'){
                                        if (buf[count+12] == '0'){
                                                if (buf[count+13] == '.'){
                                                        if (buf[count+14] == '1'){
                                                                //printf("0.2.1 found\n");
                                                                if (buf[count+16] == 'l'){
                                                                        if (buf[count+17] == 's'){
                                                                                if (buf[count+18] == 'p'){
                                                                                        if (buf[count+19] == 'i'){
                                                                                                if (buf[count+20] == '.'){
                                                                                                        if (buf[count+21] == 'c'){
                                                                                                                //if (buf[count+22] == 'e'){
                                                                                                                        detected++;

                        }
                                }
                                        }
                                                }
                                                        }
                                                                }
                                                                        }
                                                                                }
                                                                                        }
                                                                                                }
                                                                                                        }
                                                                                                                //}





        }
        //printf( "NUMBER OF CORES: %d\n", coresdetected );
                                                                
        fclose( fp );











//<span style="color: rgb(2, 2, 255); font-size: 18;">Project status:</span>
printf( "Content-type: text/html\n\n");
printf( "<html>");
//printf( "</title></head>");
printf( "<body bgcolor=\"#FFFFFF\" text=\"#000000\" link=\"#FF0000\"link=\"#800000\">");
//printf( "<span style=\"color: rgb(2, 2, 255) font-size: 12\">");
printf( "<font size=\"-3\">");
printf("%d", detected);
printf( "</font>");
//printf( "</span>");
printf( "</body></html>");






	//printf("Downloaded: %d\n", detected);
	return 0;
	//return (coresdetected);
}
