#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.200.188.122 - - [04/May/2009:16:20:58 -0700] "GET /lspong/lspong-0.1.2.tar.bz2 HTTP/1.0" 200 3118
        while( fgets(buf, sizeof(buf), fp) != NULL)
        {
		count = 0;
		while (buf[count] != 'G'){
				count++;
			}

			if (buf[count+12] == 'l'){
				//printf("0 found\n");
				if (buf[count+13] == 's'){
					if (buf[count+14] == 'p'){ 
						if (buf[count+15] == 'o'){ 
							if (buf[count+16] == 'n'){
								//printf("0.2.1 found\n"); 
								if (buf[count+17] == 'g'){ 
									if (buf[count+19] == '0'){ 
										if (buf[count+21] == '1'){ 
											if (buf[count+23] == '2'){ 
												if (buf[count+24] == '.'){ 
													if (buf[count+25] == 't'){ 
														if (buf[count+29] == 'b'){
															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+12] == 'l'){
                                //printf("0 found\n");
                                if (buf[count+13] == 's'){
                                        if (buf[count+14] == 'p'){
                                                if (buf[count+15] == 'o'){
                                                        if (buf[count+16] == 'n'){
                                                                //printf("0.2.1 found\n");
                                                                if (buf[count+17] == 'g'){
                                                                        if (buf[count+19] == '0'){
                                                                                if (buf[count+21] == '1'){
                                                                                        if (buf[count+23] == '2'){
                                                                                                if (buf[count+24] == '.'){
                                                                                                        if (buf[count+25] == 't'){
                                                                                                                if (buf[count+29] == 'b'){
                                                                                                                        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);
}
