/* * Web Report * Copyright (C) 2000 Inter7 Internet Technologies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * */ #include #include #include #include #include #include #include #include #include #include #include #include "webreport.h" /* * Prototypes */ char *comma_string_long(); email_report *get_next_email_report(); char *strstart(); void rip_string(char *); #define TABLE_DEF_STRING "TABLE BORDER=\"0\" BGCOLOR=\"E0E0FF\"" #define TABLE_HEADER_STRING "" /* * Prices * * We charge $14.95 per 33M daily * */ #define MAX_PRICES 9 web_prices ThePrices[MAX_PRICES] = { {33333333, 14.95}, {66666666, 29.90}, {99999999, 44.85}, {133333332, 59.90}, {166666665, 74.75}, {199999998, 89.70}, {233333331, 104.65}, {266666664, 119.60}, {299999997, 134.55}, }; main( argc, argv ) int argc; char *argv[]; { /* init globals */ globals_init(); /* Get the options */ get_options(argc, argv); /* Parse the config file */ parse_config(); Globals.mytime= time(NULL); Globals.mytm = localtime(&Globals.mytime); if (Globals.mytm->tm_mday == 1 ) { Globals.new_month = 1; Globals.price_report = fopen(PRICE_REPORT_FILE_NAME, "w+"); fprintf( Globals.price_report, "From: webreport@inter7.com\n"); fprintf( Globals.price_report, "Subject: web hosting price report %d/%d/%d \n", (Globals.mytm->tm_mon+1), Globals.mytm->tm_mday, 1900+Globals.mytm->tm_year); fprintf(Globals.price_report, "Price Report for %d/%d/%d\n\n", (Globals.mytm->tm_mon+1), Globals.mytm->tm_mday, 1900+Globals.mytm->tm_year); fprintf(Globals.price_report, " Web Site Name Monthly Charge\n"); fprintf(Globals.price_report, "-------------------------------------------------- --------------\n"); } for(Globals.cur_site=SiteDef; Globals.cur_site!=NULL; Globals.cur_site=Globals.cur_site->next){ globals_clean(); process_log(); /* * Second pass */ total_trbd(); total_ttbd(); total_ttbh(); total_ttbu(); total_ttbdom(); total_ttbsdom(); total_ttbr(); total_ttbb(); sort_ttbdom(); sort_ttbsdom(); sort_ttbu(); sort_ttbr(); sort_ttbb(); /* Report the info */ report_open_files(); report_header(); report_totals(); report_trbd(); report_ttbd(); report_ttbh(); report_tdbu(); report_ttbu(); report_ttbdom(); report_ttbsdom(); report_ttbr(); report_ttbb(); report_footer(); report_close_files(); report_copy_files(); report_mail_files(); report_remove_files(); /* * Free structs */ free_site_structs(); } /* * clean logs out on the first day of the month */ if (Globals.new_month) { stop_server(); clean_logs(); start_server(); fclose(Globals.price_report); mail_price_report(); unlink( PRICE_REPORT_FILE_NAME ); } exit(0); } get_options(argc, argv) int argc; char *argv[]; { int c, errflag = 0; Globals.force_archive = 0; while( !errflag && (c = getopt(argc, argv, "Ac:")) != -1 ) { switch (c) { case 'A': Globals.force_archive = 1; break; case 'c': strncpy( Globals.conf_file, optarg, MAX_BIG_BUF); break; default: ++errflag; } } if ( errflag ) { printf("webreport -A (for force archiving) -c config_file\n"); exit(-1); } } process_log() { FILE *the_log; int i,j; char *tmpchar; int virgin = 1; int tmpint = 0; Globals.virgin_log = 1; the_log = fopen(Globals.cur_site->access_log_name, "rw"); if ( the_log == NULL ) { printf( "Could not open access log\n"); return(-1); } while (feof(the_log) == 0 ){ /* get a line */ if ( fgets( Globals.LogBuf, MAX_TEMP_BUF, the_log ) == 0 ) { break; } virgin = 0; memset(&MyLog, 0, sizeof(log_format)); tmpchar = Globals.LogBuf; /* Client */ if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.client[j] = *tmpchar; } MyLog.client[j] = 0; if ( strncmp( MyLog.client, "format", 6 ) == 0 ) { strncpy(Globals.netscape_format_line, Globals.LogBuf, MAX_BIG_BUF); continue; } ++tmpchar; } if (Globals.cur_site->do_dns == 1 ) { convert_dns(); } /* Blank */ if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.blank1[j] = *tmpchar; } MyLog.blank1[j] = 0; ++tmpchar; } if ( *tmpchar != 0 ) { /* Autuser */ for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.authuser[j] = *tmpchar; } MyLog.authuser[j] = 0; ++tmpchar; } if ( *tmpchar != 0 ) { /* pull out the sysdate & skip the blank*/ for(j=0;*tmpchar!='['&&*tmpchar!=0;++j,++tmpchar); ++tmpchar; for(j=0;*tmpchar!=':'&&*tmpchar!=0;++j,++tmpchar) { if ( *tmpchar == '/' ) { MyLog.sysdate[j] = ' '; } else { MyLog.sysdate[j] = *tmpchar; } } ++tmpchar; MyLog.sysdate[j] = 0; flip_sysdate(); } if ( Globals.cur_site->first_day[0] == 0 ) { strncpy(Globals.cur_site->first_day, MyLog.sysdate, MAX_SMALL_BUF); } strncpy(Globals.cur_site->last_day, MyLog.sysdate, MAX_SMALL_BUF); if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.syshour[j] = *tmpchar; } ++tmpchar; MyLog.syshour[j] = 0; } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!='"'&&*tmpchar!=0;++j,++tmpchar); ++tmpchar; } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar); ++tmpchar; } if ( *tmpchar != 0 ) { /* pull out the url & skip the blank*/ for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.url[j] = *tmpchar; } MyLog.url[j] = 0; /* if the url ends with .html or .htm rip that part off , or if it lacks a trailing / add it*/ rip_string(MyLog.url ); } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!='"'&&*tmpchar!=0;++j,++tmpchar); ++tmpchar; } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar); ++tmpchar; } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' '&&*tmpchar!=0;++j,++tmpchar) { MyLog.status[j] = *tmpchar; } MyLog.status[j] = 0; ++tmpchar; } if ( *tmpchar != 0 ) { /* pull out the url & skip the blank*/ for(j=0;*tmpchar!=' ' && *tmpchar != '\n' && *tmpchar != 0 ; ++j,++tmpchar) { MyLog.length[j] = *tmpchar; } MyLog.length[j] = 0; } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' ' && *tmpchar!=0;++j,++tmpchar); if ( *tmpchar != 0 ) { tmpchar+=2; for(j=0;*tmpchar!='"' && *tmpchar != '\n' && *tmpchar != 0 ; ++j,++tmpchar) { MyLog.refer[j] = *tmpchar; } MyLog.refer[j] = 0; } } if ( *tmpchar != 0 ) { for(j=0;*tmpchar!=' ' && *tmpchar!=0;++j,++tmpchar); if ( *tmpchar != 0 ) { tmpchar+=2; for(j=0;*tmpchar!='"' && *tmpchar != '\n' && *tmpchar != 0 ; ++j,++tmpchar) { MyLog.browser[j] = *tmpchar; } MyLog.browser[j] = 0; } } /* should we exclude this site */ if ( exclude_sites() == 1 ) { continue; } /* should we exclude this url */ if ( exclude_urls() == 1 ) { continue; } if ( include_this() == 0 ) { continue; } total_total(); total_tran_by_date(); total_r_by_date(); total_tran_by_hour(); total_tran_by_url(); total_tran_by_domain(); total_tran_by_sub_domain(); total_refer(); total_browser(); /*archive_log_entry();*/ } fclose(the_log); if ( virgin == 1 ) { return(0); } else { return(1); } } print_log_line() { printf("client %s, sysdate %s, url %s, length %s\n", MyLog.client, MyLog.sysdate, MyLog.url, MyLog.length ); } /* * parse the date * find a date slot or add a new one */ total_tran_by_date() { struct total_trans_by_date *ttbd; int found; /* find a date slot or add a new one */ if ( Ttbd == NULL ) { Ttbd = (struct total_trans_by_date *)malloc( sizeof(total_trans_by_date) ); if ( Ttbd == NULL ) { perror("webreport: total_tran_by_date"); return; } memset( Ttbd, 0, sizeof(total_trans_by_date) ); strncpy( Ttbd->sysdate, MyLog.sysdate, MAX_SMALL_BUF); ttbd = Ttbd; found = 1; } else { ttbd=Ttbd; found=0; while( found == 0 ) { if ( strcmp( ttbd->sysdate, MyLog.sysdate ) == 0 ) { found = 1; } else { if( ttbd->next == NULL ) { break; } else { ttbd = ttbd->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbd->next = (struct total_trans_by_date *)malloc( sizeof(total_trans_by_date) ); if ( ttbd->next == NULL ) { perror("webreport: total_tran_by_date 1"); return; } ttbd = ttbd->next; memset( ttbd, 0, sizeof(total_trans_by_date) ); strncpy( ttbd->sysdate, MyLog.sysdate, MAX_SMALL_BUF); } /* add the hit */ ++ttbd->requests; /* add the byte sent */ ttbd->bytes_sent += atol(MyLog.length); } globals_init() { SiteDef = NULL; strncpy( Globals.mail_prog, DEFAULT_MAIL_PROG, MAX_SMALL_BUF); strncpy( Globals.compress_prog, DEFAULT_COMPRESS_PROG, MAX_SMALL_BUF); strncpy( Globals.conf_file, CONFIG_FILE, MAX_BIG_BUF); } globals_clean() { Ttbd = NULL; Ttbb = NULL; Ttbr = NULL; Trbd = NULL; memset(ttbh,0, sizeof(total_trans_by_hour)*24); Ttbu = NULL; Ttbdom = NULL; Ttbsdom = NULL; /* netscape likes to have it's format line first in the log */ Globals.netscape_format_line[0] = 0; Globals.TotalRequests = 0; Globals.TotalBytes = 0; Globals.TotalDays = 0; /* get the local time */ /* If it's the first day of the month then archive */ Globals.mytime= time(NULL); Globals.mytm = localtime(&Globals.mytime); sprintf(Globals.current_year, "%d", Globals.mytm->tm_year+1900); switch( Globals.mytm->tm_mon ) { case 0: strncpy( Globals.current_month, "Jan",4); break; case 1: strncpy( Globals.current_month, "Feb",4); break; case 2: strncpy( Globals.current_month, "Mar",4); break; case 3: strncpy( Globals.current_month, "Apr",4); break; case 4: strncpy( Globals.current_month, "May",4); break; case 5: strncpy( Globals.current_month, "Jun",4); break; case 6: strncpy( Globals.current_month, "Jul",4); break; case 7: strncpy( Globals.current_month, "Aug",4); break; case 8: strncpy( Globals.current_month, "Sep",4); break; case 9: strncpy( Globals.current_month, "Oct",4); break; case 10: strncpy( Globals.current_month, "Nov",4); break; case 11: strncpy( Globals.current_month, "Dec",4); break; } } total_total() { ++Globals.TotalRequests; Globals.TotalBytes += atol(MyLog.length); } total_trbd() { struct total_root_by_date *trbd; /* * set the percentages */ for(trbd=Trbd;trbd != NULL; trbd=trbd->next) { if ( Globals.TotalRequests > 0 ) { trbd->per_req = (float)trbd->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { trbd->per_byte = (float)trbd->bytes_sent/(float)Globals.TotalBytes; } trbd->per_req *= 100.0; trbd->per_byte *= 100.0; ++Globals.TotalDays; } } total_ttbd() { struct total_trans_by_date *ttbd; /* * set the percentages */ Globals.TotalDays = 0; for(ttbd=Ttbd;ttbd != NULL; ttbd=ttbd->next) { if ( Globals.TotalRequests > 0 ) { ttbd->per_req = (float)ttbd->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbd->per_byte = (float)ttbd->bytes_sent/(float)Globals.TotalBytes; } ttbd->per_req *= 100.0; ttbd->per_byte *= 100.0; ++Globals.TotalDays; } } total_ttbr() { struct total_trans_by_refer *ttbr; for(ttbr=Ttbr;ttbr != NULL; ttbr=ttbr->next) { if ( Globals.TotalRequests > 0 ) { ttbr->per_req = (float)ttbr->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbr->per_byte = (float)ttbr->bytes_sent/(float)Globals.TotalBytes; } ttbr->per_req *= 100.0; ttbr->per_byte *= 100.0; } } total_ttbb() { struct total_trans_by_browser *ttbb; for(ttbb=Ttbb;ttbb != NULL; ttbb=ttbb->next) { if ( Globals.TotalRequests > 0 ) { ttbb->per_req = (float)ttbb->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbb->per_byte = (float)ttbb->bytes_sent/(float)Globals.TotalBytes; } ttbb->per_req *= 100.0; ttbb->per_byte *= 100.0; } } total_ttbdom() { total_trans_by_domain *ttbdom; /* * set the percentages */ for(ttbdom=Ttbdom;ttbdom != NULL; ttbdom=ttbdom->next) { if ( Globals.TotalRequests > 0 ) { ttbdom->per_req = (float)ttbdom->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbdom->per_byte = (float)ttbdom->bytes_sent/(float)Globals.TotalBytes; } ttbdom->per_req *= 100.0; ttbdom->per_byte *= 100.0; } } total_ttbsdom() { total_trans_by_sub_domain *ttbsdom; for(ttbsdom=Ttbsdom;ttbsdom != NULL; ttbsdom=ttbsdom->next) { if ( Globals.TotalRequests > 0 ) { ttbsdom->per_req = (float)ttbsdom->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbsdom->per_byte = (float)ttbsdom->bytes_sent/(float)Globals.TotalBytes; } ttbsdom->per_req *= 100.0; ttbsdom->per_byte *= 100.0; } } report_ttbd() { struct total_trans_by_date *ttbd; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; fprintf(Globals.TextReport, "\nTotal Raw Hits by Request Date\n"); fprintf(Globals.HTMLReport, "

Total Raw Hits by Request Date

\n"); fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Date\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s %s%s %sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sRequests%sDate", TABLE_HEADER_STRING, TABLE_HEADER_STRING ); if ( Ttbd==NULL ) { return; } for(ttbd=Ttbd;ttbd!=NULL;ttbd=ttbd->next) { strncpy( tmp_sent, comma_string_long(ttbd->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbd->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbd->per_req, ttbd->per_byte, tmp_sent, tmp_reqs, ttbd->sysdate); fprintf(Globals.HTMLReport, "%5.2f%5.2f", ttbd->per_req, ttbd->per_byte); fprintf(Globals.HTMLReport, "%12s %8s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbd->sysdate); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } report_ttbdom() { total_trans_by_domain *ttbdom; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; int i; int count,j; fprintf(Globals.TextReport, "\nTotal Transfers by Domain\n"); if ( Globals.cur_site->max_domains > 0 ) { fprintf(Globals.TextReport, "Top %d domains\n", Globals.cur_site->max_domains); } fprintf(Globals.HTMLReport, "

Total Transfers by Domain

\n"); if ( Globals.cur_site->max_domains > 0 ) { fprintf(Globals.HTMLReport, "Top %d domains", Globals.cur_site->max_domains); } fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Domain\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | ------------------------------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s%s%s%sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sRequests%sDomain\n", TABLE_HEADER_STRING, TABLE_HEADER_STRING); if ( Ttbdom==NULL ) { return; } count = Globals.cur_site->max_domains; if ( count == 0 ) { count = 999999; } for(j=0,ttbdom=Ttbdom;jnext,++j) { for(i=0;idomain, DomainAbbr[i][0] ) == 0 ) { break; } } if ( i == MAX_DOMAINS ) { --i; } strncpy( tmp_sent, comma_string_long(ttbdom->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbdom->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %-7s %s\n", ttbdom->per_req, ttbdom->per_byte, tmp_sent, tmp_reqs, ttbdom->domain, DomainAbbr[i][1]); fprintf(Globals.HTMLReport, "%5.2f %5.2f", ttbdom->per_req, ttbdom->per_byte); fprintf(Globals.HTMLReport, "%s %s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s%s\n", ttbdom->domain, DomainAbbr[i][1]); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } char *comma_string_long(in_long ) unsigned long in_long; { char tmpbuf[MAX_TINY_BUF]; static char tmpbuf1[MAX_TINY_BUF]; char *tmpstr; int num_commas; int newl; int oldl; int i; sprintf(tmpbuf, "%u", in_long); oldl = strlen(tmpbuf); num_commas = (oldl-1)/3; newl = oldl + num_commas; for(i=-1;oldl>=0;--oldl){ tmpbuf1[newl] = tmpbuf[oldl]; --newl; ++i; if ( i == 3 ) { i = 0; tmpbuf1[newl] = ','; --newl; } } return(tmpbuf1); } report_totals() { char total_requests[MAX_SMALL_BUF]; char total_bytes[MAX_SMALL_BUF]; char ave_requests[MAX_SMALL_BUF]; char ave_bytes[MAX_SMALL_BUF]; total_trans_by_date *ttbd; int price_level; int i; for(i=MAX_PRICES-1;i>0;--i){ if (Globals.TotalBytes > ThePrices[i].bytes_sent ) { break; } } price_level = i; strncpy( total_requests, comma_string_long(Globals.TotalRequests), MAX_SMALL_BUF); strncpy( total_bytes, comma_string_long(Globals.TotalBytes), MAX_SMALL_BUF); if ( Globals.TotalDays > 0 ) { strncpy( ave_requests, comma_string_long(Globals.TotalRequests/Globals.TotalDays), MAX_SMALL_BUF); } else { strncpy( ave_requests, "0", MAX_SMALL_BUF); } if ( Globals.TotalDays > 0 ) { strncpy( ave_bytes, comma_string_long(Globals.TotalBytes/Globals.TotalDays), MAX_SMALL_BUF); } else { strncpy( ave_bytes, "0", MAX_SMALL_BUF); } /* Text Section */ fprintf(Globals.TextReport, "Totals for summary period %s to %s\n\n", Globals.cur_site->first_day, Globals.cur_site->last_day); fprintf(Globals.TextReport, "Requests Received During Summary Period %20s\n", total_requests); fprintf(Globals.TextReport, "Bytes Transmitted During Summary Period %20s\n", total_bytes); fprintf(Globals.TextReport, "Average Requests Received Daily %20s\n", ave_requests); fprintf(Globals.TextReport, "Average Bytes Transmitted Daily %20s\n\n", ave_bytes); fprintf(Globals.TextReport, "Monthly Charge %7.2f\n\n", ThePrices[price_level].price); if ( Globals.new_month ) { fprintf(Globals.price_report, "%-52s %7.2f\n", Globals.cur_site->title, ThePrices[price_level].price); } /* HTML section */ fprintf(Globals.HTMLReport, "

Totals for summary period %s to %s

", Globals.cur_site->first_day, Globals.cur_site->last_day); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); /*fprintf(Globals.HTMLReport, "\n");*/ fprintf(Globals.HTMLReport, ""); fprintf(Globals.HTMLReport, "\n", total_requests); fprintf(Globals.HTMLReport, ""); fprintf(Globals.HTMLReport, "\n", total_bytes); fprintf(Globals.HTMLReport, ""); fprintf(Globals.HTMLReport, "\n", ave_requests); fprintf(Globals.HTMLReport, ""); fprintf(Globals.HTMLReport, "", ave_bytes); fprintf(Globals.HTMLReport, ""); fprintf(Globals.HTMLReport, "", ThePrices[price_level].price); fprintf(Globals.HTMLReport, "
Requests Received During Summary Period%20s
Bytes Transmitted During Summary Period%20s
Average Requests Received Daily%20s
Average Bytes Transmitted Daily%20s
Monthly Charge%7.2f

\n"); } parse_config() { FILE *the_config; char *tmpstr; struct www_site_def *sitedef = NULL; the_config = fopen(Globals.conf_file, "r"); if ( the_config == NULL ) { fprintf( stderr, "Could not open config file: %s\n", CONFIG_FILE); return(-1); } while (feof(the_config) == 0 ){ /* get a line */ if ( fgets( Globals.TmpBuf, MAX_TEMP_BUF, the_config ) == 0 ) { break; } tmpstr = strtok(Globals.TmpBuf, CONFIG_STRING_TOKENS); while( tmpstr != NULL ){ /* Check for comments */ if (*tmpstr == '#') { break; } /* Site */ if ( strcmp(tmpstr, CONFIG_SITE_NAME) == 0 ) { if ( SiteDef == NULL ) { SiteDef = (www_site_def *)malloc(sizeof(www_site_def)); if ( SiteDef == NULL ) { perror("webreport: parse config 1"); return; } sitedef = SiteDef; } else { for(sitedef=SiteDef; sitedef->next!=NULL; sitedef=sitedef->next) ; sitedef->next = (www_site_def *)malloc( sizeof(www_site_def)); if ( sitedef->next == NULL ) { perror("webreport: parse config 2"); return; } sitedef = sitedef->next; } memset( sitedef, 0, sizeof(www_site_def)); tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->site_name, tmpstr, MAX_BIG_BUF); } else { fprintf( stderr, "webreport: conf: error on site name\n"); } /* Init site global defaults */ strncpy( sitedef->bg_color, "#AAAAFF", MAX_TINY_BUF); strncpy( sitedef->fg_color, "#000000", MAX_TINY_BUF); sprintf( sitedef->title, "Web Stats for %s", sitedef->site_name); break; } else if ( strcmp(tmpstr, CONFIG_MAX_DOMAINS) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site name before max domains\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { sitedef->max_domains = atoi(tmpstr); } else { fprintf( stderr, "webreport: conf: error on max domains for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_MAX_SUB_DOMAINS) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site name before max sub domains\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { sitedef->max_sub_domains = atoi(tmpstr); } else { fprintf( stderr, "webreport: conf: error on max sub domains for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_MAX_URLS) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site name before max urls\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { sitedef->max_urls = atoi(tmpstr); } else { fprintf( stderr, "webreport: conf: error on max urls for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_ACCESS_LOG) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site name before access log\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->access_log_name, tmpstr, MAX_BIG_BUF); } else { fprintf( stderr, "webreport: conf: error on access log name for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_24_HOUR_TIME) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site name before 24 hour time\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( strcmp( tmpstr, CONFIG_ON ) == 0 ) { sitedef->hour_time_24 = 1; } else { sitedef->hour_time_24 = 0; } } else { fprintf( stderr, "webreport: conf: error on 23 time for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_HTML_HEADER) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site def before html header\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->html_header, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on html header for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_HTML_FOOTER) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site def before html footer\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->html_footer, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on html footer for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_BG_COLOR) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site def before bg color\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->bg_color, tmpstr, MAX_TINY_BUF); } else { fprintf( stderr, "webreport: conf: error on bg color for %s\n", sitedef->site_name); } break; } else if ( strcmp(tmpstr, CONFIG_FG_COLOR) == 0 ) { if ( sitedef == NULL ) { fprintf(stderr, "webreport: conf: need site def before fg color\n"); break; } tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->fg_color, tmpstr, MAX_TINY_BUF); } else { fprintf( stderr, "webreport: conf: error on fg color for %s\n", sitedef->site_name); } break; /* Report Title */ } else if ( strcmp(tmpstr, CONFIG_TITLE) == 0 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); while( *tmpstr == ' ' ) ++tmpstr; if ( tmpstr != NULL ) { strncpy( sitedef->title, tmpstr, MAX_BIG_BUF); } else { fprintf( stderr, "webreport: conf: error on access title for %s\n", sitedef->site_name); } break; /* Report Title */ } else if ( strcmp(tmpstr, CONFIG_TITLE) == 0 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->title, tmpstr, MAX_BIG_BUF); printf("title = %s\n", sitedef->title); } else { fprintf( stderr, "webreport: conf: error on access title for %s\n", sitedef->site_name); } break; /* dns */ } else if ( strcmp(tmpstr, CONFIG_DNS) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( strcmp( tmpstr, "CONFIG_ON" ) == 0 ) { sitedef->do_dns = 1; } else { sitedef->do_dns = 0; } } else { fprintf( stderr, "webreport: conf: error on access dns for %s\n", sitedef->site_name); } break; /* log archive dir */ } else if ( strcmp(tmpstr, CONFIG_LOG_ARCHIVE_DIR) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->log_archive_dir, tmpstr, MAX_BIG_BUF); } else { fprintf( stderr, "webreport: conf: error on archive dir for %s\n", sitedef->site_name); } break; /* exclude sites */ } else if ( strcmp(tmpstr, CONFIG_EXCLUDE_SITES) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( sitedef->max_exclude_sites >= MAX_EXCLUDE_DIRS ) { fprintf( stderr, "webreport: conf: too many exclude sites for %s\n", sitedef->site_name); } else { strncpy( &sitedef->exclude_sites[sitedef->max_exclude_sites][0], tmpstr, MAX_SMALL_BUF); ++sitedef->max_exclude_sites; } } else { fprintf( stderr, "webreport: conf: error on exclude sites for %s\n", sitedef->site_name); } break; /* exclude dir */ } else if ( strcmp(tmpstr, CONFIG_EXCLUDE_DIR) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( sitedef->max_exclude_dirs >= MAX_EXCLUDE_DIRS ) { fprintf( stderr, "webreport: conf: too many exclude dirs for %s\n", sitedef->site_name); } else { strncpy( &sitedef->exclude_dirs[sitedef->max_exclude_dirs][0], tmpstr, MAX_SMALL_BUF); ++sitedef->max_exclude_dirs; } } else { fprintf( stderr, "webreport: conf: error on exclude dir for %s\n", sitedef->site_name); } break; /* include dir */ } else if ( strcmp(tmpstr, CONFIG_INCLUDE_DIR) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( sitedef->max_include_dirs >= MAX_INCLUDE_DIRS ) { fprintf( stderr, "webreport: conf: too many include dirs for %s\n", sitedef->site_name); } else { strncpy( &sitedef->include_dirs[sitedef->max_include_dirs][0], tmpstr, MAX_SMALL_BUF); ++sitedef->max_include_dirs; } } else { fprintf( stderr, "webreport: conf: error on include dir for %s\n", sitedef->site_name); } break; /* report archive dir */ } else if ( strcmp(tmpstr, CONFIG_REPORT_ARCHIVE_DIR) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->report_archive_dir, tmpstr, MAX_BIG_BUF); } else { fprintf( stderr, "webreport: conf: error on archive dir for %s\n", sitedef->site_name); } break; /* stop prog */ } else if ( strcmp(tmpstr, CONFIG_STOP_PROG) == 0 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); if ( tmpstr != NULL ) { strncpy( Globals.stop_prog, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on stop_prog\n"); } break; } else if ( strcmp(tmpstr, CONFIG_LOG_DIR) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( Globals.log_dir, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on log_dir\n"); } break; /* bg pic */ } else if ( strcmp(tmpstr, CONFIG_BG_PIC) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->bg_pic, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on config bg pic for %s\n", sitedef->site_name); } break; /* HTML FILE */ } else if ( strcmp(tmpstr, CONFIG_HTML_FILE ) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->html_file, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on html file for %s\n", sitedef->site_name); } break; /* HTML FILE */ } else if ( strcmp(tmpstr, CONFIG_TEXT_FILE ) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( sitedef->text_file, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on text file for %s\n", sitedef->site_name); } break; /* start prog */ } else if ( strcmp(tmpstr, CONFIG_START_PROG) == 0 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); if ( tmpstr != NULL ) { strncpy( Globals.start_prog, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on start_prog\n"); } break; /* compress prog */ } else if ( strcmp(tmpstr, CONFIG_COMPRESS_PROG) == 0 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); if ( tmpstr != NULL ) { strncpy( Globals.compress_prog, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on compress_prog\n"); } break; /* mail prog */ } else if ( strcmp(tmpstr, CONFIG_MAIL_PROG) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { strncpy( Globals.mail_prog, tmpstr, MAX_SMALL_BUF); } else { fprintf( stderr, "webreport: conf: error on mail prog\n"); } break; /* email prog */ } else if ( strcmp(tmpstr, CONFIG_PRICE_REPORT) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL && Globals.max_price_report < (MAX_PRICE_REPORT-1) ) { strncpy( &Globals.price_report_email_addr [Globals.max_price_report][0], tmpstr, MAX_SMALL_BUF); ++Globals.max_price_report; } break; } else if ( strcmp(tmpstr, CONFIG_EMAIL) == 0 ) { int i; struct email_report *er; er = get_next_email_report(sitedef); sprintf( er->subject, "Web stats for %s\n", Globals.cur_site->site_name); for(i=0;i<4;++i) { if ( i == 3 ) { tmpstr = strtok( NULL, CONFIG_TITLE_TOKENS); } else { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); } if ( tmpstr != NULL ) { switch(i) { case 0: strncpy( er->email_addr, tmpstr, MAX_SMALL_BUF); break; case 1: strncpy( er->output_type, tmpstr, MAX_SMALL_BUF); break; case 2: strncpy( er->frequency, tmpstr, MAX_SMALL_BUF); break; case 3: strncpy( er->subject, tmpstr, MAX_SMALL_BUF); break; } } else { switch(i) { case 0: fprintf( stderr, "webreport: conf: error on email_addr for %s\n", sitedef->site_name); break; case 1: fprintf( stderr, "webreport: conf: error on email output type for %s\n", sitedef->site_name); break; case 2: fprintf( stderr, "webreport: conf: error on email frequency for %s\n", sitedef->site_name); case 3: fprintf( stderr, "webreport: conf: error on email subject for %s\n", sitedef->site_name); break; } } } break; /* rotate prog */ } else if ( strcmp(tmpstr, CONFIG_ROTATE) == 0 ) { tmpstr = strtok( NULL, CONFIG_STRING_TOKENS); if ( tmpstr != NULL ) { if ( strcmp( tmpstr, "on") == 0 ) { sitedef->rotate = 1; } else { sitedef->rotate = 0; } } else { fprintf( stderr, "webreport: conf: error on rotate for %s\n", sitedef->site_name); } break; } else { fprintf( stderr, "webreport: conf: unknown command %s\n", tmpstr); break; } } } fclose(the_config); } free_site_structs() { total_trans_by_browser *ttbb; total_trans_by_browser *ttbb_next; total_trans_by_refer *ttbr; total_trans_by_refer *ttbr_next; total_trans_by_date *ttbd; total_trans_by_date *ttbd_next; total_trans_by_url *ttbu; total_trans_by_url *ttbu_next; total_trans_by_domain *ttbdom; total_trans_by_domain *ttbdom_next; total_trans_by_sub_domain *ttbsdom; total_trans_by_sub_domain *ttbsdom_next; total_root_by_date *trbd; total_root_by_date *trbd_next; email_report *er; email_report *er_next; archive_log_close(); if ( Ttbd != NULL ) { ttbd=Ttbd; do { ttbd_next = ttbd->next; free(ttbd); ttbd = ttbd_next; } while (ttbd != NULL); Ttbd = NULL; } if ( Ttbr != NULL ) { ttbr=Ttbr; do { ttbr_next = ttbr->next; free(ttbr); ttbr = ttbr_next; } while (ttbr != NULL); Ttbr = NULL; } if ( Ttbdom != NULL ) { ttbdom=Ttbdom; do { ttbdom_next = ttbdom->next; free(ttbdom); ttbdom = ttbdom_next; } while (ttbdom != NULL); Ttbdom = NULL; } if ( Ttbsdom != NULL ) { ttbsdom=Ttbsdom; do { ttbsdom_next = ttbsdom->next; free(ttbsdom); ttbsdom = ttbsdom_next; } while (ttbsdom != NULL); Ttbsdom = NULL; } if ( Trbd != NULL ) { trbd=Trbd; do { trbd_next = trbd->next; free(trbd); trbd = trbd_next; } while (trbd != NULL); Trbd = NULL; } if ( Globals.cur_site->er != NULL ) { er=Globals.cur_site->er; do { er_next = er->next; free(er); er = er_next; } while (er != NULL); Globals.cur_site->er = NULL; } } total_tran_by_hour() { int the_hour; char tmpbuf[20]; /* figure out the hour */ tmpbuf[0] = MyLog.syshour[0]; tmpbuf[1] = MyLog.syshour[1]; tmpbuf[2] = 0; the_hour = atoi(tmpbuf); if ( the_hour >= 24 || the_hour < 0 ) { printf("error!!!!!!!\n"); } ++ttbh[the_hour].requests; ttbh[the_hour].bytes_sent += atol(MyLog.length); } total_ttbh() { int i; /* * set the percentages */ for(i=0;i<24;++i) { if ( Globals.TotalRequests > 0 ) { ttbh[i].per_req = (float)ttbh[i].requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbh[i].per_byte = (float)ttbh[i].bytes_sent/(float)Globals.TotalBytes; } ttbh[i].per_req *= 100.0; ttbh[i].per_byte *= 100.0; } } report_ttbh() { static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; int i; fprintf(Globals.TextReport, "Total Transfers by Request Hour\n"); fprintf(Globals.HTMLReport, "

Total Transfers by Request Hour

\n"); fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Time\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | --------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s%s%s%sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%SRequests%sTime\n", TABLE_HEADER_STRING, TABLE_HEADER_STRING); for(i=0;i<24;++i){ if ( ttbh[i].requests > 0.0 ) { strncpy( tmp_sent, comma_string_long(ttbh[i].bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbh[i].requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | ", ttbh[i].per_req, ttbh[i].per_byte, tmp_sent, tmp_reqs ); if ( Globals.cur_site->hour_time_24 == 1 ) { fprintf(Globals.TextReport, "%5d\n", i); } else { fprintf(Globals.TextReport, "%8s\n", TimeAbbr[i]); } fprintf(Globals.HTMLReport, "%5.2f", ttbh[i].per_req); fprintf(Globals.HTMLReport, "%5.2f", ttbh[i].per_byte); fprintf(Globals.HTMLReport, "%12s%8s", tmp_sent, tmp_reqs); if ( Globals.cur_site->hour_time_24 == 1 ) { fprintf(Globals.HTMLReport, "%8s\n", TimeAbbr[i]); } else { fprintf(Globals.HTMLReport, "%d\n", i); } } } fprintf(Globals.HTMLReport,"
\n"); fprintf(Globals.TextReport,"\n"); } total_ttbu() { struct total_trans_by_url *ttbu; int i; if ( Ttbu == NULL ) { return; } /* * set the percentages */ for(ttbu=Ttbu;ttbu!=NULL; ttbu=ttbu->next) { if ( Globals.TotalRequests > 0 ) { ttbu->per_req = (float)ttbu->requests/(float)Globals.TotalRequests; } if ( Globals.TotalBytes > 0 ) { ttbu->per_byte = (float)ttbu->bytes_sent/(float)Globals.TotalBytes; } ttbu->per_req *= 100.0; ttbu->per_byte *= 100.0; } } report_ttbu() { struct total_trans_by_url *ttbu; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; int count,j; int l,m; fprintf(Globals.TextReport, "Total Transfers by Url\n"); if ( Globals.cur_site->max_urls > 0 ) { fprintf(Globals.TextReport, "Top %d URLs\n", Globals.cur_site->max_urls); } fprintf(Globals.HTMLReport, "

Total Transfers by Url

<%s>\n", TABLE_DEF_STRING); if ( Globals.cur_site->max_urls > 0 ) { fprintf(Globals.HTMLReport, "Top %d URLs\n", Globals.cur_site->max_urls); } fprintf(Globals.TextReport, "%s %s Bytes Sent Requests URL \n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "%s%s%s%s%sBytes Sent%sRequests", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING, TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sURL\n", TABLE_HEADER_STRING); if ( Ttbd==NULL ) { return; } count = Globals.cur_site->max_urls; if ( count == 0 ) { count = 999999; } for(j=0,ttbu=Ttbu;jnext,++j) { l = strlen(ttbu->url); --l; if ( ttbu->url[l] == '/' || ttbu->url[l] == 'l' || ttbu->url[l] == 'm' ) { } else { continue; } strncpy( tmp_sent, comma_string_long(ttbu->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbu->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbu->per_req, ttbu->per_byte, tmp_sent, tmp_reqs, ttbu->url); fprintf(Globals.HTMLReport, "%5.2f %5.2f", ttbu->per_req, ttbu->per_byte); fprintf(Globals.HTMLReport, "%s%s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbu->url, ttbu->url); } fprintf(Globals.HTMLReport, "
\n"); fprintf(Globals.TextReport, "\n"); } /* * parse the date * find a date slot or add a new one */ total_tran_by_url() { struct total_trans_by_url *ttbu; int found; /* find a date slot or add a new one */ if ( Ttbu == NULL ) { Ttbu = (struct total_trans_by_url *)malloc( sizeof(total_trans_by_url) ); if ( Ttbu == NULL ) { perror("webreport: total_tran_by_url 1"); return; } memset( Ttbu, 0, sizeof(total_trans_by_url) ); strncpy( Ttbu->url, MyLog.url, MAX_SMALL_BUF); ttbu = Ttbu; found = 1; } else { ttbu=Ttbu; found=0; while( found == 0 ) { if ( strcmp( ttbu->url, MyLog.url ) == 0 ) { found = 1; } else { if( ttbu->next == NULL ) { break; } else { ttbu = ttbu->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbu->next = (struct total_trans_by_url *)malloc( sizeof(total_trans_by_url) ); if ( ttbu->next == NULL ) { perror("webreport: total_tran_by_url 2"); return; } ttbu = ttbu->next; memset( ttbu, 0, sizeof(total_trans_by_url) ); strncpy( ttbu->url, MyLog.url, MAX_SMALL_BUF); } /* add the hit */ ++ttbu->requests; /* add the byte sent */ ttbu->bytes_sent += atol(MyLog.length); } convert_dns( ) { struct hostent *hp; u_long addr; char **p; if ((int)(addr = inet_addr(MyLog.client)) == -1) { return; } hp = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET); if (hp == NULL) { return; } else { strncpy(MyLog.client, hp->h_name, MAX_SMALL_BUF); printf("hp->h_name = %s\n", hp->h_name); } } email_report *get_next_email_report(sitedef) struct www_site_def *sitedef; { struct email_report *er; if ( sitedef->er == NULL ) { sitedef->er = (email_report *)malloc(sizeof(email_report)); if ( sitedef->er == NULL ) { perror("webreport: get next email report 1"); return; } memset( sitedef->er, 0, sizeof(email_report)); er = sitedef->er; } else { for(er=sitedef->er;er->next!=NULL;er=er->next); er->next = (email_report *)malloc(sizeof(email_report)); if ( er->next == NULL ) { perror("webreport: get next email report 2"); return; } er = er->next; memset( er, 0, sizeof(email_report)); } return(er); } report_open_files() { strncpy( Globals.TextReportName, "/var/tmp/webreport.text.XXXXXX", 100); mkstemp(Globals.TextReportName); strncpy( Globals.HTMLReportName, "/var/tmp/webreport.html.XXXXXX", 100); mkstemp(Globals.HTMLReportName); Globals.TextReport = fopen(Globals.TextReportName, "w"); Globals.HTMLReport = fopen(Globals.HTMLReportName, "w"); chmod(Globals.TextReportName, 644); chmod(Globals.HTMLReportName, 644); } report_close_files() { fclose(Globals.TextReport); fclose(Globals.HTMLReport); Globals.TextReport = NULL; Globals.HTMLReport = NULL; } report_mail_files() { struct email_report *er; char command_line[200]; for(er=Globals.cur_site->er;er!=NULL;er=er->next){ if (( strcmp( er->frequency, EMAIL_FREQ_DAILY ) == 0 ) || ( strcmp( er->frequency, EMAIL_FREQ_WEEKLY) == 0 && Globals.mytm->tm_wday == 0 ) || ( strcmp( er->frequency, EMAIL_FREQ_MONTHLY) == 0 && Globals.mytm->tm_mday == 1 ) ) { sprintf(command_line,"%s %s < ", Globals.mail_prog, er->email_addr); if ( strcmp( er->output_type, EMAIL_TEXT_REPORT) == 0 ) { strcat(command_line, Globals.TextReportName); } else if ( strcmp( er->output_type, EMAIL_HTML_REPORT) == 0 ) { strcat(command_line, Globals.HTMLReportName); } else { break; } system(command_line); } } } report_remove_files() { unlink(Globals.TextReportName); unlink(Globals.HTMLReportName); Globals.TextReportName[0] = 0; Globals.HTMLReportName[0] = 0; } archive_log_open(month, year) char *month; char *year; { check_log_archive_dir(year); sprintf(Globals.current_archive_file, "%s/%s/access-%s", Globals.cur_site->log_archive_dir, year, month); Globals.cur_site->archive_file = fopen(Globals.current_archive_file, "w"); if ( Globals.netscape_format_line[0] != 0 ) { fwrite( Globals.netscape_format_line, sizeof(char), strlen(Globals.netscape_format_line), Globals.cur_site->archive_file); } } archive_log_close() { char command_line[200]; if ( Globals.cur_site->archive_file == NULL ) { return; } /* close the file */ fclose(Globals.cur_site->archive_file); Globals.cur_site->archive_file = NULL; /* commpress it */ if ( strcmp( Globals.current_month, Globals.cur_site->archive_month ) != 0 || strcmp( Globals.current_year, Globals.cur_site->archive_year ) != 0 ) { sprintf(command_line, "%s %s", Globals.compress_prog, Globals.current_archive_file); system(command_line); } Globals.current_archive_file[0] = 0; } archive_log_entry() { int result; Globals.cur_site->log_month[0] = MyLog.sysdate[0]; Globals.cur_site->log_month[1] = MyLog.sysdate[1]; Globals.cur_site->log_month[2] = MyLog.sysdate[2]; Globals.cur_site->log_month[3] = 0; Globals.cur_site->log_year[0] = MyLog.sysdate[7]; Globals.cur_site->log_year[1] = MyLog.sysdate[8]; Globals.cur_site->log_year[2] = MyLog.sysdate[9]; Globals.cur_site->log_year[3] = MyLog.sysdate[10]; Globals.cur_site->log_year[4] = 0; if ( Globals.virgin_log == 1 && strcmp(Globals.cur_site->log_month, Globals.current_month) == 0 && strcmp(Globals.cur_site->log_year, Globals.current_year) == 0 ) { return; } Globals.virgin_log = 0; if ( strcmp( Globals.cur_site->log_month, Globals.cur_site->archive_month ) != 0 || strcmp( Globals.cur_site->log_year, Globals.cur_site->archive_year ) != 0 ) { archive_log_close(); Globals.cur_site->restart_server = 1; strncpy( Globals.cur_site->archive_month, Globals.cur_site->log_month, MAX_SMALL_BUF ); strncpy( Globals.cur_site->archive_year, Globals.cur_site->log_year, MAX_SMALL_BUF); archive_log_open(Globals.cur_site->archive_month, Globals.cur_site->archive_year); } if ( Globals.cur_site->archive_file != NULL ) { result = fwrite( Globals.LogBuf, sizeof(char), strlen(Globals.LogBuf), Globals.cur_site->archive_file); } } stop_server() { if ( Globals.stop_prog[0] == 0 ) { return; } system(Globals.stop_prog); } start_server() { if ( Globals.start_prog[0] == 0 ) { return; } system(Globals.start_prog); } clean_logs() { char command_line[120]; if ( Globals.log_dir[0] != 0 ) { sprintf( command_line, "rm %s/*", Globals.log_dir); system(command_line); } } move_logs() { char command_line[120]; if ( Globals.virgin_log == 1 ) { return; } /* unlink the current log */ unlink(Globals.cur_site->access_log_name); /* link the temp log to the current log */ sprintf( command_line, "mv %s %s", Globals.current_archive_file, Globals.cur_site->access_log_name); system(command_line); } check_log_archive_dir(year) char *year; { char tmpbuf[100]; struct stat ms; sprintf(tmpbuf, "%s/%s", Globals.cur_site->log_archive_dir, year); if ( stat(tmpbuf, &ms) != 0 ) { mkdir(tmpbuf, 0744); } } report_header() { FILE *fs; if ( Globals.cur_site->html_header[0] != 0 ) { fs = fopen(Globals.cur_site->html_header, "r"); while ( fgets( Globals.TmpBuf, MAX_TEMP_BUF, fs ) == 0 ) { fputs( Globals.TmpBuf, fs); } } else { fprintf(Globals.HTMLReport, "Subject: %s\n", Globals.cur_site->title); fprintf( Globals.HTMLReport, "Content-Type: text/html; charset=us-ascii\n"); fprintf( Globals.HTMLReport, "Content-Transfer-Encoding: 7bit\n"); fprintf( Globals.HTMLReport, "X-Mozilla-Status: 8001\n"); fprintf( Globals.HTMLReport, "\n"); fprintf( Globals.HTMLReport, "%s\n", Globals.cur_site->title); fprintf( Globals.HTMLReport, "\n"); } fprintf( Globals.HTMLReport, "\n", Globals.cur_site->bg_color, Globals.cur_site->fg_color); fprintf( Globals.HTMLReport, "

%s

\n", Globals.cur_site->title); fprintf( Globals.TextReport, "Subject: %s\n", Globals.cur_site->title); fprintf( Globals.TextReport, "%s\n", Globals.cur_site->title); fprintf( Globals.TextReport, "Last updated %s\n", asctime(Globals.mytm)); fprintf(Globals.HTMLReport, "Last updated: %s\n", asctime(Globals.mytm)); /* fprintf(Globals.HTMLReport, "\n"); */ } report_footer() { FILE *fs; fprintf(Globals.TextReport, "This summary was generated by\n"); fprintf(Globals.TextReport, "http://www.inter7.com/webreport/\n"); fprintf(Globals.HTMLReport, "
\n"); fprintf(Globals.HTMLReport, "This summary was generated by\n"); fprintf(Globals.HTMLReport, "webreport-1.05\n"); fprintf(Globals.HTMLReport, "
\n"); if ( Globals.cur_site->html_footer[0] != 0 ) { fs = fopen(Globals.cur_site->html_footer, "r"); while ( fgets( Globals.TmpBuf, MAX_TEMP_BUF, fs ) == 0 ) { fputs( Globals.TmpBuf, fs); } } else { fprintf(Globals.HTMLReport, "\n"); } } report_copy_files() { char tmpbuf[100]; if ( Globals.cur_site->html_file[0] != 0 ) { sprintf( tmpbuf, "cp %s %s", Globals.HTMLReportName, Globals.cur_site->html_file); system(tmpbuf); } if ( Globals.cur_site->text_file[0] != 0 ) { sprintf( tmpbuf, "cp %s %s", Globals.TextReportName, Globals.cur_site->text_file); system(tmpbuf); } } total_tran_by_domain() { total_trans_by_domain *ttbdom; int found; char domain[MAX_SMALL_BUF]; int i; if ( isdigit(MyLog.client[0]) ) { strncpy( domain, "unresolved", MAX_SMALL_BUF); } else { i = strlen( MyLog.client ); while (MyLog.client[i] != '.' ) { --i; } ++i; strncpy( domain, &MyLog.client[i], MAX_SMALL_BUF); for(i=0;domain[i]!=0;++i){ if ( isupper(domain[i]) ) { domain[i] = tolower(domain[i]); } } } /* find a domain slot or add a new one */ if ( Ttbdom == NULL ) { Ttbdom = (total_trans_by_domain *)malloc( sizeof(total_trans_by_domain) ); memset( Ttbdom, 0, sizeof(total_trans_by_domain ) ); strncpy( Ttbdom->domain, domain, MAX_SMALL_BUF); ttbdom = Ttbdom; found = 1; } else { ttbdom=Ttbdom; found=0; while( found == 0 ) { if ( strcmp( ttbdom->domain, domain) == 0 ) { found = 1; } else { if( ttbdom->next == NULL ) { break; } else { ttbdom = ttbdom->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbdom->next = (total_trans_by_domain *)malloc( sizeof(total_trans_by_domain) ); ttbdom = ttbdom->next; memset( ttbdom, 0, sizeof(total_trans_by_domain) ); strncpy( ttbdom->domain, domain, MAX_SMALL_BUF); } ++ttbdom->requests; /* add the byte sent */ ttbdom->bytes_sent += atol(MyLog.length); } report_ttbsdom() { total_trans_by_sub_domain *ttbsdom; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; int i; int count,j; fprintf(Globals.TextReport, "\nTotal Transfers by Sub Domain\n"); if ( Globals.cur_site->max_domains > 0 ) { fprintf(Globals.TextReport, "Top %d sub domains\n", Globals.cur_site->max_sub_domains); } fprintf(Globals.HTMLReport, "

Total Transfers by Sub Domain

\n"); if ( Globals.cur_site->max_domains > 0 ) { fprintf(Globals.HTMLReport, "Top %d sub domains\n", Globals.cur_site->max_sub_domains); } fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Sub Domain\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | ---------------------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s%s%s", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte"); fprintf(Globals.HTMLReport, "%sBytes Sent%sRequests%sSub Domain\n", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); if ( Ttbsdom==NULL ) { return; } count = Globals.cur_site->max_sub_domains; if ( count == 0 ) { count = 999999; } for(j=0,ttbsdom=Ttbsdom;jnext,++j) { strncpy( tmp_sent, comma_string_long(ttbsdom->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbsdom->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbsdom->per_req, ttbsdom->per_byte, tmp_sent, tmp_reqs, ttbsdom->sub_domain); fprintf(Globals.HTMLReport, "%5.2f%5.2f", ttbsdom->per_req, ttbsdom->per_byte); fprintf(Globals.HTMLReport, "%s%s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbsdom->sub_domain); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } total_tran_by_sub_domain() { total_trans_by_sub_domain *ttbsdom; int found; char sub_domain[MAX_SMALL_BUF]; int i; if ( isdigit(MyLog.client[0]) ) { strncpy( sub_domain, "unresolved", MAX_SMALL_BUF); } else { i = strlen( MyLog.client ); while (MyLog.client[i] != '.' ) { --i; } --i; while (MyLog.client[i] != '.' && MyLog.client[i] != '@') { --i; } ++i; strncpy( sub_domain, &MyLog.client[i], MAX_SMALL_BUF); for(i=0;sub_domain[i]!=0;++i){ if ( isupper(sub_domain[i]) ) { sub_domain[i] = tolower(sub_domain[i]); } } } /* find a sub_domain slot or add a new one */ if ( Ttbsdom == NULL ) { Ttbsdom = (total_trans_by_sub_domain *)malloc( sizeof(total_trans_by_sub_domain) ); memset( Ttbsdom, 0, sizeof(total_trans_by_sub_domain ) ); strncpy( Ttbsdom->sub_domain, sub_domain, MAX_SMALL_BUF); ttbsdom = Ttbsdom; found = 1; } else { ttbsdom=Ttbsdom; found=0; while( found == 0 ) { if ( strcmp( ttbsdom->sub_domain, sub_domain) == 0 ) { found = 1; } else { if( ttbsdom->next == NULL ) { break; } else { ttbsdom = ttbsdom->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbsdom->next = (total_trans_by_sub_domain *)malloc( sizeof(total_trans_by_sub_domain) ); ttbsdom = ttbsdom->next; memset( ttbsdom, 0, sizeof(total_trans_by_sub_domain) ); strncpy( ttbsdom->sub_domain, sub_domain, MAX_SMALL_BUF); } ++ttbsdom->requests; /* add the byte sent */ ttbsdom->bytes_sent += atol(MyLog.length); } sort_ttbdom() { total_trans_by_domain *ttbdom0; total_trans_by_domain *ttbdom1; total_trans_by_domain *ttbdom2; int found; if ( Ttbdom == NULL || Ttbdom->next == NULL ) { return; } found = 1; while( found == 1 ) { /* init */ ttbdom0 = NULL; ttbdom1 = Ttbdom; ttbdom2 = Ttbdom->next; found = 0; while( ttbdom2 != NULL ) { if ( ttbdom1->requests < ttbdom2->requests ) { found = 1; ttbdom1->next = ttbdom2->next; ttbdom2->next = ttbdom1; if ( ttbdom0 == NULL ) { Ttbdom = ttbdom2; } else { ttbdom0->next = ttbdom2; } ttbdom0 = ttbdom2; ttbdom2 = ttbdom1->next; } else { ttbdom0 = ttbdom1; ttbdom1 = ttbdom2; ttbdom2 = ttbdom1->next; } } } } flip_sysdate() { char day[2]; day[0] = MyLog.sysdate[0]; day[1] = MyLog.sysdate[1]; MyLog.sysdate[0] = MyLog.sysdate[3]; MyLog.sysdate[1] = MyLog.sysdate[4]; MyLog.sysdate[2] = MyLog.sysdate[5]; MyLog.sysdate[3] = ' '; MyLog.sysdate[4] = day[0]; MyLog.sysdate[5] = day[1]; } sort_ttbsdom() { total_trans_by_sub_domain *ttbsdom0; total_trans_by_sub_domain *ttbsdom1; total_trans_by_sub_domain *ttbsdom2; int found; if ( Ttbdom == NULL || Ttbdom->next == NULL ) { return; } found = 1; while( found == 1 ) { /* init */ ttbsdom0 = NULL; ttbsdom1 = Ttbsdom; ttbsdom2 = Ttbsdom->next; found = 0; while( ttbsdom2 != NULL ) { if ( ttbsdom1->requests < ttbsdom2->requests ) { found = 1; ttbsdom1->next = ttbsdom2->next; ttbsdom2->next = ttbsdom1; if ( ttbsdom0 == NULL ) { Ttbsdom = ttbsdom2; } else { ttbsdom0->next = ttbsdom2; } ttbsdom0 = ttbsdom2; ttbsdom2 = ttbsdom1->next; } else { ttbsdom0 = ttbsdom1; ttbsdom1 = ttbsdom2; ttbsdom2 = ttbsdom1->next; } } } } sort_ttbu() { total_trans_by_url *ttburl0; total_trans_by_url *ttburl1; total_trans_by_url *ttburl2; int found; if ( Ttbu == NULL || Ttbu->next == NULL ) { return; } found = 1; while( found == 1 ) { /* init */ ttburl0 = NULL; ttburl1 = Ttbu; ttburl2 = Ttbu->next; found = 0; while( ttburl2 != NULL ) { if ( ttburl1->requests < ttburl2->requests ) { found = 1; ttburl1->next = ttburl2->next; ttburl2->next = ttburl1; if ( ttburl0 == NULL ) { Ttbu = ttburl2; } else { ttburl0->next = ttburl2; } ttburl0 = ttburl2; ttburl2 = ttburl1->next; } else { ttburl0 = ttburl1; ttburl1 = ttburl2; ttburl2 = ttburl1->next; } } } } /* * parse the date * find a date slot or add a new one */ total_refer() { struct total_trans_by_refer *ttbr; int found; /* find a refer slot or add a new one */ if ( Ttbr == NULL ) { Ttbr = (struct total_trans_by_refer *)malloc( sizeof(total_trans_by_refer) ); memset( Ttbr, 0, sizeof(total_trans_by_refer) ); strncpy( Ttbr->refer, MyLog.refer, MAX_BIG_BUF); ttbr = Ttbr; found = 1; } else { ttbr=Ttbr; found=0; while( found == 0 ) { if ( strncmp( ttbr->refer, MyLog.refer, MAX_BIG_BUF ) == 0 ) { found = 1; } else { if( ttbr->next == NULL ) { break; } else { ttbr = ttbr->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbr->next = (struct total_trans_by_refer *)malloc( sizeof(total_trans_by_refer) ); ttbr = ttbr->next; memset( ttbr, 0, sizeof(total_trans_by_refer) ); strncpy( ttbr->refer, MyLog.refer, MAX_BIG_BUF); } /* add the hit */ ++ttbr->requests; /* add the byte sent */ ttbr->bytes_sent += atol(MyLog.length); } sort_ttbr() { total_trans_by_refer *ttbr0; total_trans_by_refer *ttbr1; total_trans_by_refer *ttbr2; int found; if ( Ttbr == NULL || Ttbr->next == NULL ) { return; } found = 1; while( found == 1 ) { /* init */ ttbr0 = NULL; ttbr1 = Ttbr; ttbr2 = Ttbr->next; found = 0; while( ttbr2 != NULL ) { if ( ttbr1->requests < ttbr2->requests ) { found = 1; ttbr1->next = ttbr2->next; ttbr2->next = ttbr1; if ( ttbr0 == NULL ) { Ttbr = ttbr2; } else { ttbr0->next = ttbr2; } ttbr0 = ttbr2; ttbr2 = ttbr1->next; } else { ttbr0 = ttbr1; ttbr1 = ttbr2; ttbr2 = ttbr1->next; } } } } report_ttbr() { struct total_trans_by_refer *ttbr; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; fprintf(Globals.TextReport, "\nTotal Transfers by Referer\n"); fprintf(Globals.HTMLReport, "

Total Transfers by Referer

\n"); fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Referer\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s %s%s%sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "Requests%sReferer", TABLE_HEADER_STRING, TABLE_HEADER_STRING ); if ( Ttbr==NULL ) { return; } for(ttbr=Ttbr;ttbr!=NULL;ttbr=ttbr->next) { strncpy( tmp_sent, comma_string_long(ttbr->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbr->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbr->per_req, ttbr->per_byte, tmp_sent, tmp_reqs, ttbr->refer); fprintf(Globals.HTMLReport, "%5.2f%5.2f", ttbr->per_req, ttbr->per_byte); fprintf(Globals.HTMLReport, "%12s %8s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbr->refer); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } sort_ttbb() { total_trans_by_browser *ttbb0; total_trans_by_browser *ttbb1; total_trans_by_browser *ttbb2; int found; if ( Ttbb == NULL || Ttbb->next == NULL ) { return; } found = 1; while( found == 1 ) { /* init */ ttbb0 = NULL; ttbb1 = Ttbb; ttbb2 = Ttbb->next; found = 0; while( ttbb2 != NULL ) { if ( ttbb1->requests < ttbb2->requests ) { found = 1; ttbb1->next = ttbb2->next; ttbb2->next = ttbb1; if ( ttbb0 == NULL ) { Ttbb = ttbb2; } else { ttbb0->next = ttbb2; } ttbb0 = ttbb2; ttbb2 = ttbb1->next; } else { ttbb0 = ttbb1; ttbb1 = ttbb2; ttbb2 = ttbb1->next; } } } } report_ttbb() { struct total_trans_by_browser *ttbb; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; fprintf(Globals.TextReport, "\nTotal Transfers by Browser\n"); fprintf(Globals.HTMLReport, "

Total Transfers by Browser

\n"); fprintf(Globals.TextReport, "%s %s Bytes Sent Requests Browser\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s %s%s %sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sRequests%sBrowser", TABLE_HEADER_STRING, TABLE_HEADER_STRING ); if ( Ttbb==NULL ) { return; } for(ttbb=Ttbb;ttbb!=NULL;ttbb=ttbb->next) { strncpy( tmp_sent, comma_string_long(ttbb->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbb->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbb->per_req, ttbb->per_byte, tmp_sent, tmp_reqs, ttbb->browser); fprintf(Globals.HTMLReport, "%5.2f%5.2f", ttbb->per_req, ttbb->per_byte); fprintf(Globals.HTMLReport, "%12s %8s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbb->browser); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } total_browser() { struct total_trans_by_browser *ttbb; int found; /* find a browser slot or add a new one */ if ( Ttbb == NULL ) { Ttbb = (struct total_trans_by_browser *)malloc( sizeof(total_trans_by_browser) ); memset( Ttbb, 0, sizeof(total_trans_by_browser) ); strncpy( Ttbb->browser, MyLog.browser, MAX_BIG_BUF); ttbb = Ttbb; found = 1; } else { ttbb=Ttbb; found=0; while( found == 0 ) { if ( strcmp( ttbb->browser, MyLog.browser ) == 0 ) { found = 1; } else { if( ttbb->next == NULL ) { break; } else { ttbb = ttbb->next; } } } } /* add a new slot */ if ( found == 0 ) { ttbb->next = (struct total_trans_by_browser *)malloc( sizeof(total_trans_by_browser) ); ttbb = ttbb->next; memset( ttbb, 0, sizeof(total_trans_by_browser) ); strncpy( ttbb->browser, MyLog.browser, MAX_BIG_BUF); } /* add the hit */ ++ttbb->requests; /* add the byte sent */ ttbb->bytes_sent += atol(MyLog.length); } include_this() { int i; if ( Globals.cur_site->max_include_dirs == 0 ) { return(1); } for(i=0;imax_include_dirs;++i){ if ( strstart(MyLog.url, &Globals.cur_site->include_dirs[i][0]) != NULL ) { return(1); } } return(0); } exclude_sites() { int i; for(i=0;imax_exclude_sites;++i){ if ( strstr(MyLog.client, &Globals.cur_site->exclude_sites[i][0]) != NULL ) { return(1); } } return(0); } exclude_urls() { int i; for(i=0;imax_exclude_dirs;++i){ if ( strstart(MyLog.url, &Globals.cur_site->exclude_dirs[i][0]) != NULL ) { return(1); } } return(0); } char *strstart(sstr, tstr) char *sstr; char *tstr; { char *ret_str; ret_str = sstr; if ( sstr == NULL || tstr == NULL ) { return(NULL); } while ( *sstr != 0 && *tstr != 0 ) { if ( *sstr != *tstr ) { return(NULL); } ++sstr; ++tstr; } if ( *tstr == 0 ) { return(ret_str); } return(NULL); } report_trbd() { struct total_root_by_date *trbd; static char tmp_sent[MAX_TINY_BUF]; static char tmp_reqs[MAX_TINY_BUF]; fprintf(Globals.TextReport, "\nTotal Unique Visitors by Date\n"); fprintf(Globals.HTMLReport, "

Total Unique Visitors by Request Date

\n"); fprintf(Globals.TextReport, "%s %s Bytes Sent Vistors Date\n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "<%s>\n", TABLE_DEF_STRING); fprintf(Globals.HTMLReport, "%s%s %s%s %sBytes Sent", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sVisitors%sDate", TABLE_HEADER_STRING, TABLE_HEADER_STRING ); if ( Trbd==NULL ) { return; } for(trbd=Trbd;trbd!=NULL;trbd=trbd->next) { strncpy( tmp_sent, comma_string_long(trbd->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(trbd->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", trbd->per_req, trbd->per_byte, tmp_sent, tmp_reqs, trbd->sysdate); fprintf(Globals.HTMLReport, "%5.2f%5.2f", trbd->per_req, trbd->per_byte); fprintf(Globals.HTMLReport, "%12s %8s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", trbd->sysdate); } fprintf(Globals.TextReport, "\n\n"); fprintf(Globals.HTMLReport, "
\n"); } total_r_by_date() { struct total_root_by_date *trbd; int found; if ( strcmp( MyLog.url, ROOT_URL ) != 0 ) { return(0); } /* find a date slot or add a new one */ if ( Trbd == NULL ) { Trbd = (struct total_root_by_date *)malloc( sizeof(total_root_by_date) ); memset( Trbd, 0, sizeof(total_root_by_date) ); strncpy( Trbd->sysdate, MyLog.sysdate, MAX_SMALL_BUF); trbd = Trbd; found = 1; } else { trbd=Trbd; found=0; while( found == 0 ) { if ( strcmp( trbd->sysdate, MyLog.sysdate ) == 0 ) { found = 1; } else { if( trbd->next == NULL ) { break; } else { trbd = trbd->next; } } } } /* add a new slot */ if ( found == 0 ) { trbd->next = (struct total_root_by_date *)malloc( sizeof(total_root_by_date) ); trbd = trbd->next; memset( trbd, 0, sizeof(total_root_by_date) ); strncpy( trbd->sysdate, MyLog.sysdate, MAX_SMALL_BUF); } /* add the hit */ ++trbd->requests; /* add the byte sent */ trbd->bytes_sent += atol(MyLog.length); } mail_price_report() { char command_line[200]; int i; for(i=0;imax_urls > 0 ) { fprintf(Globals.TextReport, "Top %d URLs\n", Globals.cur_site->max_urls); } fprintf(Globals.HTMLReport, "

Total Downloads by Url

<%s>\n", TABLE_DEF_STRING); if ( Globals.cur_site->max_urls > 0 ) { fprintf(Globals.HTMLReport, "Top %d URLs\n", Globals.cur_site->max_urls); } fprintf(Globals.TextReport, "%s %s Bytes Sent Requests URL \n", "%Reqs", "%Byte"); fprintf(Globals.TextReport, "----- ----- ------------ -------- | -----------\n"); fprintf(Globals.HTMLReport, "%s%s%s%s%sBytes Sent%sRequests", TABLE_HEADER_STRING, "%Reqs", TABLE_HEADER_STRING, "%Byte", TABLE_HEADER_STRING, TABLE_HEADER_STRING); fprintf(Globals.HTMLReport, "%sURL\n", TABLE_HEADER_STRING); if ( Ttbd==NULL ) { return; } count = Globals.cur_site->max_urls; if ( count == 0 ) { count = 999999; } for(j=0,ttbu=Ttbu;jnext,++j) { if (!strstr(ttbu->url,".tar") && !strstr(ttbu->url,".mp3")) continue; strncpy( tmp_sent, comma_string_long(ttbu->bytes_sent), MAX_TINY_BUF); strncpy( tmp_reqs, comma_string_long(ttbu->requests), MAX_TINY_BUF); fprintf(Globals.TextReport, "%5.2f %5.2f %12s %8s | %s\n", ttbu->per_req, ttbu->per_byte, tmp_sent, tmp_reqs, ttbu->url); fprintf(Globals.HTMLReport, "%5.2f %5.2f", ttbu->per_req, ttbu->per_byte); fprintf(Globals.HTMLReport, "%s%s", tmp_sent, tmp_reqs); fprintf(Globals.HTMLReport, "%s\n", ttbu->url, ttbu->url); } fprintf(Globals.HTMLReport, "
\n"); fprintf(Globals.TextReport, "\n"); } void rip_string(char *url) { int i; int url_len; char *strloc; strloc = strstr(url, INDEX_HTML_NAME); if ( strloc == NULL ) return; if ( strlen(strloc) > 10 ) return; *strloc = 0; }