webalizer.c

来自「统计日志的工具」· C语言 代码 · 共 1,572 行 · 第 1/5 页

C
1,572
字号
      /*********************************************/      else      {         /* If first record, check if stupid Netscape header stuff      */         if ( (total_rec==1) && (strncmp(buffer,"format=",7)==0) )         {            /* Skipping Netscape header record */            if (verbose>1) printf("%s\n",msg_ign_nscp);            /* count it as ignored... */            total_ignore++;         }         else         {            /* really bad record... */            total_bad++;            if (verbose)            {               fprintf(stderr,"%s (%lu)",msg_bad_rec,total_rec);               if (debug_mode) fprintf(stderr,":\n%s\n",tmp_buf);               else fprintf(stderr,"\n");            }         }      }   }   /*********************************************/   /* DONE READING LOG FILE - final processing  */   /*********************************************/   /* close log file if needed */   if (gz_log) gzclose(gzlog_fp);   else if (log_fname) fclose(log_fp);   if (good_rec)                             /* were any good records?   */   {      tm_site[cur_day-1]=dt_site;            /* If yes, clean up a bit   */      tm_visit[cur_day-1]=tot_visit(sd_htab);      t_visit=tot_visit(sm_htab);      if (ht_hit > mh_hit) mh_hit = ht_hit;      if (total_rec > (total_ignore+total_bad)) /* did we process any?   */      {         if (incremental)         {            if (save_state())                /* incremental stuff        */            {               /* Error: Unable to save current run data */               if (verbose) fprintf(stderr,"%s\n",msg_data_err);               unlink(state_fname);            }         }         month_update_exit(rec_tstamp);      /* calculate exit pages     */         write_month_html();                 /* write monthly HTML file  */         write_main_index();                 /* write main HTML file     */         put_history();                      /* write history            */      }      end_time = times(&mytms);              /* display timing totals?   */      if (time_me || (verbose>1))      {         printf("%lu %s ",total_rec, msg_records);         if (total_ignore)         {            printf("(%lu %s",total_ignore,msg_ignored);            if (total_bad) printf(", %lu %s) ",total_bad,msg_bad);               else        printf(") ");         }         else if (total_bad) printf("(%lu %s) ",total_bad,msg_bad);         /* get processing time (end-start) */         temp_time = (float)(end_time-start_time)/CLK_TCK;         printf("%s %.2f %s", msg_in, temp_time, msg_seconds);         /* calculate records per second */         if (temp_time)           i=( (int)( (float)total_rec/temp_time ) );         else i=0;         if ( (i>0) && (i<=total_rec) ) printf(", %d/sec\n", i);            else  printf("\n");      }#ifdef USE_DNS      if (dns_db) close_cache();#endif      /* Whew, all done! Exit with completion status (0) */      exit(0);   }   else   {      /* No valid records found... exit with error (1) */      if (verbose) printf("%s\n",msg_no_vrec);      exit(1);   }}/*********************************************//* GET_CONFIG - get configuration file info  *//*********************************************/void get_config(char *fname){   char *kwords[]= { "Undefined",         /* 0 = undefined keyword       0  */                     "OutputDir",         /* Output directory            1  */                     "LogFile",           /* Log file to use for input   2  */                     "ReportTitle",       /* Title for reports           3  */                     "HostName",          /* Hostname to use             4  */                     "IgnoreHist",        /* Ignore history file         5  */                     "Quiet",             /* Run in quiet mode           6  */                     "TimeMe",            /* Produce timing results      7  */                     "Debug",             /* Produce debug information   8  */                     "HourlyGraph",       /* Hourly stats graph          9  */                     "HourlyStats",       /* Hourly stats table         10  */                     "TopSites",          /* Top sites                  11  */                     "TopURLs",           /* Top URL's                  12  */                     "TopReferrers",      /* Top Referrers              13  */                     "TopAgents",         /* Top User Agents            14  */                     "TopCountries",      /* Top Countries              15  */                     "HideSite",          /* Sites to hide              16  */                     "HideURL",           /* URL's to hide              17  */                     "HideReferrer",      /* Referrers to hide          18  */                     "HideAgent",         /* User Agents to hide        19  */                     "IndexAlias",        /* Aliases for index.html     20  */                     "HTMLHead",          /* HTML Top1 code             21  */                     "HTMLPost",          /* HTML Top2 code             22  */                     "HTMLTail",          /* HTML Tail code             23  */                     "MangleAgents",      /* Mangle User Agents         24  */                     "IgnoreSite",        /* Sites to ignore            25  */                     "IgnoreURL",         /* Url's to ignore            26  */                     "IgnoreReferrer",    /* Referrers to ignore        27  */                     "IgnoreAgent",       /* User Agents to ignore      28  */                     "ReallyQuiet",       /* Dont display ANY messages  29  */                     "GMTTime",           /* Local or UTC time?         30  */                     "GroupURL",          /* Group URL's                31  */                     "GroupSite",         /* Group Sites                32  */                     "GroupReferrer",     /* Group Referrers            33  */                     "GroupAgent",        /* Group Agents               34  */                     "GroupShading",      /* Shade Grouped entries      35  */                     "GroupHighlight",    /* BOLD Grouped entries       36  */                     "Incremental",       /* Incremental runs           37  */                     "IncrementalName",   /* Filename for state data    38  */                     "HistoryName",       /* Filename for history data  39  */                     "HTMLExtension",     /* HTML filename extension    40  */                     "HTMLPre",           /* HTML code at beginning     41  */                     "HTMLBody",          /* HTML body code             42  */                     "HTMLEnd",           /* HTML code at end           43  */                     "UseHTTPS",          /* Use https:// on URL's      44  */                     "IncludeSite",       /* Sites to always include    45  */                     "IncludeURL",        /* URL's to always include    46  */                     "IncludeReferrer",   /* Referrers to include       47  */                     "IncludeAgent",      /* User Agents to include     48  */                     "PageType",          /* Page Type (pageview)       49  */                     "VisitTimeout",      /* Visit timeout (seconds)    50  */                     "GraphLegend",       /* Graph Legends (yes/no)     51  */                     "GraphLines",        /* Graph Lines (0=none)       52  */                     "FoldSeqErr",        /* Fold sequence errors       53  */                     "CountryGraph",      /* Display ctry graph (0=no)  54  */                     "TopKSites",         /* Top sites (by KBytes)      55  */                     "TopKURLs",          /* Top URL's (by KBytes)      56  */                     "TopEntry",          /* Top Entry Pages            57  */                     "TopExit",           /* Top Exit Pages             58  */                     "TopSearch",         /* Top Search Strings         59  */                     "LogType",           /* Log Type (clf/ftp/squid)   60  */                     "SearchEngine",      /* SearchEngine strings       61  */                     "GroupDomains",      /* Group domains (n=level)    62  */                     "HideAllSites",      /* Hide ind. sites (0=no)     63  */                     "AllSites",          /* List all sites?            64  */                     "AllURLs",           /* List all URLs?             65  */                     "AllReferrers",      /* List all Referrers?        66  */                     "AllAgents",         /* List all User Agents?      67  */                     "AllSearchStr",      /* List all Search Strings?   68  */                     "AllUsers",          /* List all Users?            69  */                     "TopUsers",          /* Top Usernames to show      70  */                     "HideUser",          /* Usernames to hide          71  */                     "IgnoreUser",        /* Usernames to ignore        72  */                     "IncludeUser",       /* Usernames to include       73  */                     "GroupUser",         /* Usernames to group         74  */                     "DumpPath",          /* Path for dump files        75  */                     "DumpExtension",     /* Dump filename extension    76  */                     "DumpHeader",        /* Dump header as first rec?  77  */                     "DumpSites",         /* Dump sites tab file        78  */                     "DumpURLs",          /* Dump urls tab file         79  */                     "DumpReferrers",     /* Dump referrers tab file    80  */                     "DumpAgents",        /* Dump user agents tab file  81  */                     "DumpUsers",         /* Dump usernames tab file    82  */                     "DumpSearchStr",     /* Dump search str tab file   83  */                     "DNSCache",          /* DNS Cache file name        84  */                     "DNSChildren",       /* DNS Children (0=no DNS)    85  */                     "DailyGraph",        /* Daily Graph (0=no)         86  */                     "DailyStats"         /* Daily Stats (0=no)         87  */                   };   FILE *fp;   char buffer[BUFSIZE];   char keyword[32];   char value[132];   char *cp1, *cp2;   int  i,key;   int	num_kwords=sizeof(kwords)/sizeof(char *);   if ( (fp=fopen(fname,"r")) == NULL)   {      if (verbose)      fprintf(stderr,"%s %s\n",msg_bad_conf,fname);      return;   }   while ( (fgets(buffer,BUFSIZE,fp)) != NULL)   {      /* skip comments and blank lines */      if ( (buffer[0]=='#') || isspace((int)buffer[0]) ) continue;      /* Get keyword */      cp1=buffer;cp2=keyword;      while ( isalnum((int)*cp1) ) *cp2++ = *cp1++;      *cp2='\0';      /* Get value */      cp2=value;      while ( (*cp1!='\n')&&(*cp1!='\0')&&(isspace((int)*cp1)) ) cp1++;      while ( (*cp1!='\n')&&(*cp1!='\0') ) *cp2++ = *cp1++;      *cp2--='\0';      while ( (isspace((int)*cp2)) && (cp2 != value) ) *cp2--='\0';      /* check if blank keyword/value */      if ( (keyword[0]=='\0') || (value[0]=='\0') ) continue;      key=0;      for (i=0;i<num_kwords;i++)         if (!strcmp(keyword,kwords[i])) { key=i; break; }      if (key==0) { printf("%s '%s' (%s)\n",       /* Invalid keyword       */                    msg_bad_key,keyword,fname);                    continue;                  }      switch (key)      {        case 1:  out_dir=save_opt(value);          break; /* OutputDir      */        case 2:  log_fname=save_opt(value);        break; /* LogFile        */        case 3:  msg_title=save_opt(value);        break; /* ReportTitle    */        case 4:  hname=save_opt(value);            break; /* HostName       */        case 5:  ignore_hist=(value[0]=='n')?0:1;  break; /* IgnoreHist     */        case 6:  verbose=(value[0]=='n')?2:1;      break; /* Quiet          */        case 7:  time_me=(value[0]=='n')?0:1;      break; /* TimeMe         */        case 8:  debug_mode=(value[0]=='n')?0:1;   break; /* Debug          */        case 9:  hourly_graph=(value[0]=='n')?0:1; break; /* HourlyGraph    */        case 10: hourly_stats=(value[0]=='n')?0:1; break; /* HourlyStats    */        case 11: ntop_sites = atoi(value);         break; /* TopSites       */        case 12: ntop_urls = atoi(value);          break; /* TopURLs        */        case 13: ntop_refs = atoi(value);          break; /* TopRefs        */        case 14: ntop_agents = atoi(value);        break; /* TopAgents      */        case 15: ntop_ctrys = atoi(value);         break; /* TopCountries   */        case 16: add_nlist(value,&hidden_sites);   break; /* HideSite       */        case 17: add_nlist(value,&hidden_urls);    break; /* HideURL        */        case 18: add_nlist(value,&hidden_refs);    break; /* HideReferrer   */        case 19: add_nlist(value,&hidden_agents);  break; /* HideAgent      */        case 20: add_nlist(value,&index_alias);    break; /* IndexAlias     */        case 21: add_nlist(value,&html_head);      break; /* HTMLHead       */        case 22: add_nlist(value,&html_post);      break; /* HTMLPost       */        case 23: add_nlist(value,&html_tail);      break; /* HTMLTail       */        case 24: mangle_agent=atoi(value);         break; /* MangleAgents   */        case 25: add_nlist(value,&ignored_sites);  break; /* IgnoreSite     */        case 26: add_nlist(value,&ignored_urls);   break; /* IgnoreURL      */        case 27: add_nlist(value,&ignored_refs);   break; /* IgnoreReferrer */        case 28: add_nlist(value,&ignored_agents); break; /* IgnoreAgent    */        case 29: if (value[0]=='y') verbose=0;     break; /* ReallyQuiet    */        case 30: local_time=(value[0]=='y')?0:1;   break; /* GMTTime        */        case 31: add_glist(value,&group_urls);     break; /* GroupURL       */        case 32: add_glist(value,&group_sites);    break; /* GroupSite      */        case 33: add_glist(value,&group_refs);     break; /* GroupReferrer  */        case 34: add_glist(value,&group_agents);   break; /* GroupAgent     */        case 35: shade_groups=(value[0]=='y')?1:0; break; /* GroupShading   */        case 36: hlite_groups=(value[0]=='y')?1:0; break; /* GroupHighlight */        case 37: incremental=(value[0]=='y')?1:0;  break; /* Incremental    */        case 38: state_fname=save_opt(value);      break; /* State FName    */        case 39: hist_fname=save_opt(value);       break; /* History FName  */        case 40: html_ext=save_opt(value);         break; /* HTML extension */        case 41: add_nlist(value,&html_pre);       break; /* HTML Pre code  */        case 42: add_nlist(value,&html_body);      break; /* HTML Body code */        case 43: add_nlist(value,&html_end);       break; /* HTML End code  */        case 44: use_https=(value[0]=='y')?1:0;    break; /* Use https://   */        case 45: add_nlist(value,&include_sites);  break; /* IncludeSite    */        case 46: add_nlist(value,&include_urls);   break; /* IncludeURL     */        case 47: add_nlist(value,&include_refs);   break; /* IncludeReferrer*/        case 48: add_nlist(value,&include_agents); break; /* IncludeAgent   */        case 49: add_nlist(value,&page_type);      break; /* PageType       */        case 50: visit_timeout=atoi(value);        break; /* VisitTimeout   */        case 51: graph_legend=(value[0]=='y')?1:0; break; /* GraphLegend    */        case 52: graph_lines = atoi(value);        break; /* GraphLines     */        case 53: fold_seq_err=(value[0]=='y')?1:0; break; /* FoldSeqErr     */        case 54: ctry_graph=(value[0]=='y')?1:0;   break; /* CountryGraph   */        case 55: ntop_sitesK = atoi(value);        break; /* TopKSites (KB) */        case 56: ntop_urlsK  = atoi(value);        break; /* TopKUrls (KB)  */        case 57: ntop_entry  = atoi(value);        break; /* Top Entry pgs  */        case 58: ntop_exit   = atoi(value);        break; /* Top Exit pages */        case 59: ntop_search = atoi(value);        break; /* Top Search pgs */        case 60: log_type=(value[0]=='f')?                 LOG_FTP:((value[0]=='s')?                 LOG_SQUID:LOG_CLF);               break; /* LogType        */        case 61: add_glist(value,&search_list);    break; /* SearchEngine   */        case 62: group_domains=atoi(value);        break; /* GroupDomains   */        case 63: hide_sites=(value[0]=='y')?1:0;   break; /* HideAllSites   */        case 64: all_sites=(value[0]=='y')?1:0;    break; /* All Sites?     */        case 65: all_urls=(value[0]=='y')?1:0;     break; /* All URL's?     */        case 66: all_refs=(value[0]=='y')?1:0;     break; /* All Refs       */        case 67: all_agents=(value[0]=='y')?1:0;   break; /* All Agents?    */        case 68: all_search=(value[0]=='y')?1:0;   break; /* All Srch str   */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?