]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Replaced the ifdef FOPEN64 by a single call to MY_FOPEN for code clarity.
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 9 Jul 2009 11:34:25 +0000 (11:34 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Thu, 9 Jul 2009 11:34:25 +0000 (11:34 +0000)
User IP/ID is searched only in the first column of the usertab file.
Some indentation fixes.
Speed up by removing two uncessary ip resolutions.

23 files changed:
authfail.c
convlog.c
dansguardian_log.c
dansguardian_report.c
datafile.c
denied.c
download.c
getconf.c
grepday.c
html.c
include/conf.h
include/defs.h
include/info.h
ip2name.c
log.c
realtime.c
repday.c
report.c
siteuser.c
splitlog.c
squidguard_report.c
topuser.c
util.c

index 93c2b8f7eb6d74150aafd396e21dac89aaf4bffd..ea12fc09e2f174c13176523d50988c04046c3f9e 100644 (file)
@@ -77,22 +77,14 @@ void authfail_report(void)
       fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(authfail_in,"r"))==NULL) {
-#else
-   if((fp_in=fopen(authfail_in,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(authfail_in,"r"))==NULL) {
       fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in);
       fprintf(stderr, "SARG: sort command: %s\n",csort);
       exit(1);
    }
    unlink(tmp4);
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(report,"w"))==NULL) {
-#else
-   if((fp_ou=fopen(report,"w"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],report);
      exit(1);
    }
@@ -152,19 +144,7 @@ void authfail_report(void)
             strcpy(oip,ip);
       }
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
+      get_usertab_name(user,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index ccc8e6ef91230ebc1458bdd11c458b75d59a6e4c..5387af3933a9fe6c82871c369fe9898c44e5fd00 100644 (file)
--- a/convlog.c
+++ b/convlog.c
@@ -42,11 +42,7 @@ void convlog(const char *arq, char *df, int dfrom, int duntil)
    if(arq[0] == '\0')
       arq="/usr/local/squid/logs/access.log";
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(arq,"r"))==NULL) {
-#else
-   if((fp_in=fopen(arq,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
       fprintf(stderr, "SARG: (convlog) %s: %s\n",text[8],arq);
       exit(1);
    }
index 866e39302946118ceebdf8b513bb7cfcb21ebb90..8abd018b6ab6e2d32469fe88d0d04ee44a7e2999 100644 (file)
@@ -87,11 +87,7 @@ void dansguardian_log(void)
       exit(1);
    }
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(guard_in,"a"))==NULL) {
-#else
-   if((fp_ou=fopen(guard_in,"a"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(guard_in,"a"))==NULL) {
       fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],guard_in);
       exit(1);
    }
@@ -119,16 +115,12 @@ void dansguardian_log(void)
       sprintf(msg,"%s DansGuardian %s: %s",urly,buf,loglocation);
       debuga(msg);
    }
-   
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(loglocation,"r"))==NULL) {
-#else
-   if((fp_in=fopen(loglocation,"r"))==NULL) {
-#endif
+
+   if((fp_in=MY_FOPEN(loglocation,"r"))==NULL) {
       fprintf(stderr, "SARG: (dansguardian) %s: %s\n",text[8],loglocation);
       exit(1);
    }
+
    while(fgets(buf,sizeof(buf),fp_in) != NULL) {
       if(strstr(buf," *DENIED* ") == 0)
          continue;
index aafaec2a40dd320a79f137226b6a8eaa390f05ae..7bd9a7a66e1acea00fc9821187d20e75f50a92f4 100644 (file)
@@ -67,20 +67,12 @@ void dansguardian_report(void)
    fgets(period,sizeof(period),fp_in);
    fclose(fp_in);
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(dansguardian_in,"r"))==NULL) {
-#else
-   if((fp_in=fopen(dansguardian_in,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
      fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],dansguardian_in);
      exit(1);
    }
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(report,"w"))==NULL) {
-#else
-   if((fp_ou=fopen(report,"w"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (dansguardian_report) %s: %s\n",text[8],report);
      exit(1);
    }
@@ -156,19 +148,7 @@ void dansguardian_report(void)
             strcpy(oip,ip);
       }
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
+      get_usertab_name(user,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index ea2e21fb040bf9a9db7f802ff1f5a63f32b71cfd..9b674c06b2e2e018302ca08628e4797377a94d18 100644 (file)
@@ -66,12 +66,8 @@ void data_file(char *tmp)
          continue;
       sprintf(tmp3,"%s/%s",tmp,direntp->d_name);
 
-#if defined(HAVE_FOPEN64)
-      if((fp_in=fopen64(tmp3,"r"))==NULL){
-#else
-      if((fp_in=fopen(tmp3,"r"))==NULL){
-#endif
-         fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],tmp);
+      if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){
+         fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],tmp);
          exit(1);
       }
       strcpy(wdname,direntp->d_name);
@@ -164,11 +160,7 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon
    FILE *fp_ou;
    char reg[MAXLEN];
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(DataFile,"a"))==NULL){
-#else
-   if((fp_ou=fopen(DataFile,"a"))==NULL){
-#endif
+   if((fp_ou=MY_FOPEN(DataFile,"a"))==NULL){
       fprintf(stderr, "SARG: (datafile) %s: %s\n",text[45],DataFile);
       exit(1);
    }
index e45fd13e2c9a25820bc76a3b3739e07bdd899da5..aed61031991103e731c7fb8a1a605fe3e48ed5d3 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -66,20 +66,12 @@ void gen_denied_report(void)
    fgets(period,sizeof(period),fp_in);
    fclose(fp_in);
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(denied_in,"r"))==NULL) {
-#else
-   if((fp_in=fopen(denied_in,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(denied_in,"r"))==NULL) {
      fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],denied_in);
      exit(1);
    }
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(report,"w"))==NULL) {
-#else
-   if((fp_ou=fopen(report,"w"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (denied) %s: %s\n",text[8],report);
      exit(1);
    }
@@ -137,19 +129,7 @@ void gen_denied_report(void)
             strcpy(oip,ip);
       }
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
+      get_usertab_name(user,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index 8970837750f4fec9a48c80568790194f434fe44b..96e1041ae3f76772b256a99168331e235e1703fe 100644 (file)
@@ -66,20 +66,12 @@ void download_report(void)
    fgets(period,sizeof(period),fp_in);
    fclose(fp_in);
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(report_in,"r"))==NULL) {
-#else
-   if((fp_in=fopen(report_in,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(report_in,"r"))==NULL) {
      fprintf(stderr, "SARG: (download) %s: %s\n",text[8],report_in);
      exit(1);
    }
 
-#if defined(HAVE_FOPEN64)
-   if((fp_ou=fopen64(report,"w"))==NULL) {
-#else
-   if((fp_ou=fopen(report,"w"))==NULL) {
-#endif
+   if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
      fprintf(stderr, "SARG: (download) %s: %s\n",text[8],report);
      exit(1);
    }
@@ -141,19 +133,7 @@ void download_report(void)
             strcpy(oip,ip);
       }
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
+      get_usertab_name(user,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index d1e0e08ce1efb0097b47f7fcfbb206d538b73a33..ee1eeb04847d1f996296f1228d9191afec913f25 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -297,8 +297,8 @@ void parmtest(char *buf)
       }
 
       if(strstr(buf,"access_log") != 0) {
-        if(strstr(buf,"realtime_access_log_lines") == 0) {
-           if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
+         if(strstr(buf,"realtime_access_log_lines") == 0) {
+            if (getword_multisep(wbuf,sizeof(wbuf),buf,' ')<0) {
                printf("SARG: Maybe you have a broken record or garbage in access_log parameter.\n");
                exit(1);
             }
index 7ed301eec612811242b4d584d33d6007f9debd27..73307fcb9e7fbc7e1be1e25c785acfbb828faac7 100644 (file)
--- a/grepday.c
+++ b/grepday.c
@@ -419,19 +419,7 @@ void greport_day(const char *user)
             ip2name(wuser,sizeof(wuser));
    }
 
-   if(UserTabFile[0] != '\0') {
-      sprintf(warea,":%s:",wuser);
-      if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-         z1=0;
-         str2=(char *) strstr(str+1,":");
-         str2++;
-         bzero(name, MAXLEN);
-         while(str2[z1] != ':') {
-            name[z1]=str2[z1];
-            z1++;
-         }
-      } else strcpy(name,wuser);
-   } else strcpy(name,user);
+   get_usertab_name(wuser,name,sizeof(name));
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       if (getword(data,sizeof(data),buf,' ')<0 || getword(day,sizeof(day),data,'/')<0) {
diff --git a/html.c b/html.c
index 71c7a89b4c9dc7f25811c8b6177211963409c802..c88b6efd6d72d402e73a898892645de8ed403c3c 100644 (file)
--- a/html.c
+++ b/html.c
@@ -50,6 +50,8 @@ void htmlrel(void)
    char *s;
    int count;
    int cstatus;
+   const char txtext[]=".txt";
+   int dlen;
 
    if(strstr(ReportType,"users_sites") == 0) return;
 
@@ -104,26 +106,25 @@ void htmlrel(void)
 
    dirp = opendir(tmp);
    while ( (direntp = readdir( dirp )) != NULL ) {
-      if(strstr(direntp->d_name,".txt") == 0)
+      dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
+      if (dlen<0) continue;
+      if(strcmp(direntp->d_name+dlen,txtext) != 0)
          continue;
 
       count=1;
-      strcpy(usuario,direntp->d_name);
-      wusuario[0]='\0';
-   
-      striptxt:
-      if (getword(warea,sizeof(warea),usuario,'.')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",tmp);
-         exit(1);
-      }
-      strcpy(denied_report,warea);
-      strcat(wusuario,warea);
-   
-      if(strcmp(usuario,"txt") !=0) {
-         strcat(wusuario,".");
-         goto striptxt;
+      if (dlen>0) {
+         if (dlen>=sizeof(wusuario)) continue;
+         strncpy(wusuario,direntp->d_name,dlen);
+         wusuario[dlen]=0;
+      } else {
+         wusuario[0]=0;
       }
+      str=strrchr(wusuario,'.');
+      if (str)
+         strcpy(denied_report,str+1);
+      else
+         strcpy(denied_report,wusuario);
+
       sprintf(warea,"%s/%s",dirname,wusuario);
       mkdir(warea,0755);
 
@@ -151,7 +152,20 @@ void htmlrel(void)
       strcat(duser,".html");
       if(access(duser, R_OK) != 0)
          denied_report[0]='\0';
-   
+
+      strcpy(u2,usuario);
+      if(userip)
+         fixip(u2);
+      if(strcmp(Ip2Name,"yes") == 0)
+         ip2name(u2,sizeof(u2));
+
+      get_usertab_name(u2,name2,sizeof(name2));
+
+      if(dotinuser && strstr(name2,"_")) {
+         str2=(char *)subs(name2,"_",".");
+         strcpy(name2,str2);
+      }
+
       if ((fp_in = fopen(arqin, "r")) == 0){
          fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin);
          exit(1);
@@ -209,12 +223,12 @@ void htmlrel(void)
       fprintf(fp_ou,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
            background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
 
-   if(strlen(LogoImage) > 0) {
-      fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
-      fprintf(fp_ou,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
-      fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
-      fputs("</table>\n",fp_ou);
-   }
+      if(strlen(LogoImage) > 0) {
+         fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
+         fprintf(fp_ou,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
+         fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
+         fputs("</table>\n",fp_ou);
+      }
 
       if(strcmp(IndexTree,"date") == 0)
          show_sarg(fp_ou, "../../../..");
@@ -224,34 +238,6 @@ void htmlrel(void)
       fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
       fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
 
-      strcpy(u2,usuario);
-      if(userip){
-         strcpy(u2,usuario);
-         fixip(u2);
-      }
-      if(strcmp(Ip2Name,"yes") == 0)
-         ip2name(u2,sizeof(u2));
-
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",u2);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,u2);
-      } else strcpy(name,u2);
-
-      strcpy(name2,name);
-      if(dotinuser && strstr(name2,"_")) {
-         str2=(char *)subs(name2,"_",".");
-         strcpy(name2,str2);
-      }
-   
       fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
       fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name2);
       fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
@@ -448,26 +434,22 @@ void htmlrel(void)
             strcat(arqip,"/");
             strcat(arqip,usuario);
             strcat(arqip,".ip");
-   
+
             if ((fp_ip = fopen(arqip, "r")) == 0){
                fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
                exit(1);
             }
 
-#if defined(HAVE_FOPEN64)
-            if ((fp_ip2 = fopen64(tmp2, "a")) == 0){
-#else
-            if ((fp_ip2 = fopen(tmp2, "a")) == 0){
-#endif
+            if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
                fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2);
                exit(1);
             }
-   
+
             while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
                if(strstr(buf,url) != 0)
                   fputs(buf,fp_ip2);
             }
-   
+
             fclose(fp_ip);
             fclose(fp_ip2);
 
@@ -478,12 +460,8 @@ void htmlrel(void)
                fprintf(stderr, "SARG: sort command: %s\n",csort);
                exit(1);
             }
-   
-#if defined(HAVE_FOPEN64)
-            if ((fp_ip = fopen64(tmp3, "r")) == 0) {
-#else
-            if ((fp_ip = fopen(tmp3, "r")) == 0) {
-#endif
+
+            if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
                fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3);
                exit(1);
             }
@@ -648,7 +626,7 @@ void htmlrel(void)
                }
                fclose(fp_usr);
             }
-  
+
             if(!limit_flag) {
                if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
                   fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
@@ -656,10 +634,10 @@ void htmlrel(void)
                }
                fprintf(fp_usr,"%s\n",u2);
                fclose(fp_usr);
-    
+
                if(debug) {
                   sprintf(msg, "%s %s %s (%s MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
-                      debuga(msg);
+                  debuga(msg);
                }
             }
          }
@@ -670,73 +648,73 @@ void htmlrel(void)
 //     continue;
 //      }
 
-   if (strstr(ReportType,"topuser") != 0) {
-      strcpy(arqper,dirname);
-      strcat(arqper,"/sarg-users");
-      if ((fp_in = fopen(arqper, "r")) == 0){
-         fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
-         exit(1);
-      }
+      if (strstr(ReportType,"topuser") != 0) {
+         strcpy(arqper,dirname);
+         strcat(arqper,"/sarg-users");
+   
+         if ((fp_in = fopen(arqper, "r")) == 0){
+            fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
+            exit(1);
+         }
 
-      fgets(totuser,8,fp_in);
-      fclose(fp_in);
-      totbytes2=totbytes/my_atoll(totuser);
-      totelap2=totelap/my_atoll(totuser);
-      if(totbytes2) {
-         perc = totbytes / 100;
-         perc = totbytes2 / perc;
-      } else perc=0;
+         fgets(totuser,8,fp_in);
+         fclose(fp_in);
    
-      if(totelap2) {
-         perc2 = totelap / 100;
-         perc2 = totelap2 / perc2;
-      } else perc2=0;
+         totbytes2=totbytes/my_atoll(totuser);
+         totelap2=totelap/my_atoll(totuser);
    
-      twork2=my_atoll(totuser);
-      twork=ttnacc/twork2;
-  
-      sprintf(wwork1,"%s",fixnum(twork,1));
-      sprintf(wwork2,"%s",fixnum(totbytes2,1));
-      sprintf(wwork3,"%s",fixnum2(totelap2,1));
-
-      sprintf(val6,"%s",buildtime(totelap2));
-      sprintf(val7,"%3.2f%%",perc2); 
+         if(totbytes2) {
+            perc = totbytes / 100;
+            perc = totbytes2 / perc;
+         } else perc=0;
+      
+         if(totelap2) {
+            perc2 = totelap / 100;
+            perc2 = totelap2 / perc2;
+         } else perc2=0;
+      
+         twork2=my_atoll(totuser);
+         twork=ttnacc/twork2;
    
-      strcpy(hbc1,"class=\"header2\"");
-      strcpy(hbc2,"class=\"header2\"");
-      strcpy(hbc3,"class=\"header2\"");
-      strcpy(hbc4,"class=\"header2\"");
-      strcpy(hbc5,"class=\"header2\"");
-      strcpy(hbc6,"class=\"header\"");
+         sprintf(wwork1,"%s",fixnum(twork,1));
+         sprintf(wwork2,"%s",fixnum(totbytes2,1));
+         sprintf(wwork3,"%s",fixnum2(totelap2,1));
 
-      if(strstr(UserReportFields,"CONNECT") == 0) {
-         bzero(wwork1, 255);
-         bzero(hbc1, 30);
-      }
-      if(strstr(UserReportFields,"BYTES") == 0) {
-         bzero(wwork2, 255);
-         bzero(hbc2, 30);
-      }
-      if(strstr(UserReportFields,"MILISEC") == 0) {
-         bzero(wwork3, 255);
-         bzero(hbc3, 30);
-      }
-      if(strstr(UserReportFields,"USED_TIME") == 0) { 
-         bzero(val6, 255);
-         bzero(hbc4, 30);
-      }
-      if(strstr(UserReportFields,"%TIME") == 0) {
-         bzero(val7, 255);
-         bzero(hbc5, 30);
-      }
-   
-      if(strstr(UserReportFields,"AVERAGE") != 0) {
-         fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th></th><th></th><th></th><th %s>%s</th><th %s>%s</font></th><th %s>%s</th></tr>\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7);
-      }
-} /* added */
+         sprintf(val6,"%s",buildtime(totelap2));
+         sprintf(val7,"%3.2f%%",perc2); 
+      
+         strcpy(hbc1,"class=\"header2\"");
+         strcpy(hbc2,"class=\"header2\"");
+         strcpy(hbc3,"class=\"header2\"");
+         strcpy(hbc4,"class=\"header2\"");
+         strcpy(hbc5,"class=\"header2\"");
+         strcpy(hbc6,"class=\"header\"");
+
+         if(strstr(UserReportFields,"CONNECT") == 0) {
+            bzero(wwork1, 255);
+            bzero(hbc1, 30);
+         }
+         if(strstr(UserReportFields,"BYTES") == 0) {
+            bzero(wwork2, 255);
+            bzero(hbc2, 30);
+         }
+         if(strstr(UserReportFields,"MILISEC") == 0) {
+            bzero(wwork3, 255);
+            bzero(hbc3, 30);
+         }
+         if(strstr(UserReportFields,"USED_TIME") == 0) { 
+            bzero(val6, 255);
+            bzero(hbc4, 30);
+         }
+         if(strstr(UserReportFields,"%TIME") == 0) {
+            bzero(val7, 255);
+            bzero(hbc5, 30);
+         }
+      
+         if(strstr(UserReportFields,"AVERAGE") != 0) {
+            fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th></th><th></th><th></th><th %s>%s</th><th %s>%s</font></th><th %s>%s</th></tr>\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7);
+         }
+      } /* added */
       tnacc=0;
       tnbytes=0;
       tnelap=0;
index 22820b37f9296376f24c2e3e24620cd97bc12370..1aff9cc26e876a0ffa0473641372bda4858f6c46 100755 (executable)
@@ -82,7 +82,7 @@ gdPoint points[4];
 
 #if HAVE_FOPEN64
 #define _FILE_OFFSET_BITS 64
-#define MY_FOPEN fopen
+#define MY_FOPEN fopen64
 #else
 #define MY_FOPEN fopen
 #endif
index 95aa6981b41112179e993cfd8c499bc8f20b4a9a..ea7d4e96eb109a9c781e0e7eb0175f3de38a7bb2 100755 (executable)
@@ -156,3 +156,5 @@ void removetmp(const char *outdir);
 void zdate(char *ftime, const char *DateFormat);
 void baddata(void);
 char *get_param_value(const char *param,char *line);
+void read_usertab(const char *UserTabFile);
+void get_usertab_name(const char *user,char *name,int namelen);
index c8cd1c9528c265824f67215dac29be9bad5c8a7b..4bea3da67b68b24e6839a907e3c41232348b170f 100755 (executable)
@@ -1,3 +1,3 @@
-#define VERSION "2.2.5 Jul-08-2009"
+#define VERSION "2.2.5 Jul-09-2009"
 #define PGM "sarg"
 #define URL "http://sarg.sourceforge.net"
index 5b0eb5ffa1c5191c84d4dae270581d91132bad44..6240e2f985b78d0f5667cb489b3bfb97b5fe69a9 100644 (file)
--- a/ip2name.c
+++ b/ip2name.c
 void ip2name(char *ip,int ip_len)
 { 
    u_long addr;
-   struct hostent *hp; 
-   char **p; 
+   struct hostent *hp;
+   char **p;
 
    if ((int)(addr = inet_addr(ip)) == -1)
       return;
 
-   hp = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET); 
-   if (hp == NULL) 
+   hp = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET);
+   if (hp == NULL)
       return;
 
-   for (p = hp->h_addr_list; *p != 0; p++) { 
-      struct in_addr in; 
+   for (p = hp->h_addr_list; *p != 0; p++) {
+      struct in_addr in;
 
-      (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));         
+      (void) memcpy(&in.s_addr, *p, sizeof (in.s_addr));
       strncpy(ip,hp->h_name,ip_len-1);
       ip[ip_len-1]=0;
-   } 
+   }
 
    return;
-} 
+}
 
 void name2ip(char *name)
 { 
diff --git a/log.c b/log.c
index 94aa8235ffc31279e219f2185ad396338b17f970..eb384c4bb4a5d850855a3b7545d73c9192e2dfbf 100644 (file)
--- a/log.c
+++ b/log.c
@@ -42,7 +42,7 @@ numlist weekdays = { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
 numlist hours = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
              13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
 
-void getusers(char *pwdfile, int debug);
+static void getusers(const char *pwdfile, int debug);
 void gethexclude(char *hexfile, int debug);
 void getuexclude(char *uexfile, int debug);
 void ttx(char *user);
@@ -55,7 +55,7 @@ int main(argc,argv)
    char *argv[];
 {
 
-   FILE *fp_in = NULL, *fp_ou = NULL, *fp_denied=NULL, *fp_usr, *fp_authfail=NULL, *fp_log=NULL;
+   FILE *fp_in = NULL, *fp_ou = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL;
 
    char sz_Download_Unsort[ 20000 ] ;
    FILE * fp_Download_Unsort = NULL ;
@@ -121,7 +121,6 @@ int main(argc,argv)
    long int  max_elapsed=0;
    time_t tt;
    struct tm *t;
-   unsigned long nreg=0;
    off_t recs1=0;
    unsigned long recs2=0;
    struct rlimit rl;
@@ -320,10 +319,10 @@ int main(argc,argv)
          case 'g':
             strcpy(df,optarg);
             break;
-        case 'h':
-           usage(argv[0]);
+         case 'h':
+            usage(argv[0]);
             exit(0);
-           break;
+            break;
          case 'i':
             iprel++;
             break;
@@ -364,8 +363,8 @@ int main(argc,argv)
                strcpy(hmf,optarg);
             }
             if(strlen(hm) > 5) {
-              printf("SARG: time period must be MM or MM:SS. Exit.\n");
-              exit(1);
+               printf("SARG: time period must be MM or MM:SS. Exit.\n");
+               exit(1);
             }
             bzero(whm,15);
             if(strstr(hm,":") != 0) {
@@ -405,9 +404,9 @@ int main(argc,argv)
             debugz++;
             break;
          case ':':
-           fprintf(stderr, "Option -%c require an argument\n",optopt);
-           errflg++;
-           break;
+            fprintf(stderr, "Option -%c require an argument\n",optopt);
+            errflg++;
+            break;
          case '?':
             usage(argv[0]);
             exit(1);
@@ -424,15 +423,15 @@ int main(argc,argv)
    if(debug) debuga("Init");
 
    if(ConfigFile[0] == '\0') sprintf(ConfigFile,"%s/sarg.conf",SYSCONFDIR);
-    else if(access(ConfigFile, R_OK) != 0) {
-            sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno));
-            debuga(msg);
-            exit(1);
-         }
-    
+   if(access(ConfigFile, R_OK) != 0) {
+      sprintf(msg,"Cannot open config file: %s - %s",ConfigFile,strerror(errno));
+      debuga(msg);
+      exit(1);
+   }
+
    if(access(ConfigFile, R_OK) == 0)
       getconf();
-   
+
    if(realt) {
       realtime();
       exit(0);
@@ -446,10 +445,10 @@ int main(argc,argv)
    dataonly=0;
    if(DataFile[0] != '\0');
       dataonly++;
-   
+
    str2=(char *)subs(TopUserFields,"%BYTES","SETYB");
    strcpy(TopUserFields,str2);
-   
+
    str2=(char *)subs(UserReportFields,"%BYTES","SETYB");
    strcpy(UserReportFields,str2);
 
@@ -462,7 +461,7 @@ int main(argc,argv)
       convlog(warq[0], df, dfrom, duntil);
       exit(0);
    }
-   
+
    if(strcmp(site,"plit") == 0) {
       splitlog(warq[0], df, dfrom, duntil, hexclude);
       exit(0);
@@ -489,10 +488,9 @@ int main(argc,argv)
          sprintf(msg,"Cannot open exclude_hosts file: %s - %s",hexclude,strerror(errno));
          debuga(msg);
          exit(1);
-      } else {
-         gethexclude(hexclude,debug);
-         fhost++;
       }
+      gethexclude(hexclude,debug);
+      fhost++;
    }
 
    if(ReportType[0] == '\0')
@@ -685,802 +683,733 @@ int main(argc,argv)
       }
    }
 
-   if (UserTabFile[0] != '\0') {
-      if(debug) {
-         sprintf(msg,"%s: %s",text[86],UserTabFile);
-         debuga(msg);
-      }
-      if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
-        fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],UserTabFile,strerror(errno));
-        exit(1);
-      }
-      fseek(fp_usr, 0, SEEK_END);
-      nreg = ftell(fp_usr);
-      fseek(fp_usr, 0, SEEK_SET);
-      if((userfile=(char *) malloc(nreg+100))==NULL){
-         fprintf(stderr, "%s ERROR: %s",argv[0],text[87]);
-         exit(1);
-      }
-      bzero(userfile,nreg+100);
-      strncat(userfile,":",1);
-      z1=0;
-      z2=1;
-      while(fgets(buf,MAXLEN,fp_usr)!=NULL) {
-         buf[strlen(buf)-1]='\0';
-         if(strstr(buf,"\r") != 0) buf[strlen(buf)-1]='\0';
-        if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
-           printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
-           exit(1);
-        }
-         for(z1=0; z1<=strlen(bufy); z1++) {
-            userfile[z2]=bufy[z1];
-            z2++;
-         }
-         strncat(userfile,":",1);
-         for(z1=0; z1<=strlen(buf); z1++) {
-            userfile[z2]=buf[z1];
-            z2++;
-         }
-         strncat(userfile,":",1);
-      }
-      fclose(fp_usr);
-   }
+   read_usertab(UserTabFile);
 
    sprintf ( sz_Download_Unsort , "%s/sarg/download.unsort", tmp);
    bool_ShowReadStatistics = ( strcmp(ShowReadStatistics,"yes") == 0 ) ;
 
    while(narq--) {
       strcpy(arq,warq[iarq]);
-      iarq++;  
-
-   strcpy(arqtt,arq);
-   decomp(arq,zip,tmp);
-   if(debug) {
-      sprintf(msg, "%s: %s",text[7],arq);
-      debuga(msg);
-   }
+      iarq++;
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(arq,"r"))==NULL) {
-#else
-   if((fp_in=fopen(arq,"r"))==NULL) {
-#endif
-     fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
-     exit(1);
-   }
-   fgets(bufz,sizeof(bufz),fp_in);
-   if(!isalog && strncmp(bufz,"#Software: Mic",14) == 0) isalog++;
+      strcpy(arqtt,arq);
+      decomp(arq,zip,tmp);
+      if(debug) {
+         sprintf(msg, "%s: %s",text[7],arq);
+         debuga(msg);
+      }
 
-   if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
-      if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
-          getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+      if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
+         fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
          exit(1);
       }
-      sprintf(period,"%s-%s",val2,val3);
-      sarglog=1;
-   } else fseek(fp_in, 0, SEEK_SET);
+      fgets(bufz,sizeof(bufz),fp_in);
+      if(!isalog && strncmp(bufz,"#Software: Mic",14) == 0) isalog++;
 
-   if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
-      if(access(ParsedOutputLog,R_OK) != 0) {
-         sprintf(csort,"%s",ParsedOutputLog);
-         my_mkdir(csort);
-      }
-      sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
-#if defined(HAVE_FOPEN64)
-      if((fp_log=fopen64(arq_log,"w"))==NULL) {
-#else
-      if((fp_log=fopen(arq_log,"w"))==NULL) {
-#endif
-        fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq_log,strerror(errno));
-        exit(1);
+      if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
+         if (getword(val2,sizeof(val2),arqtt,'-')<0 || getword(val2,sizeof(val2),arqtt,'_')<0 ||
+            getword(val3,sizeof(val3),arqtt,'-')<0 || getword(val3,sizeof(val3),arqtt,'_')<0) {
+            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+            exit(1);
+         }
+         sprintf(period,"%s-%s",val2,val3);
+         sarglog=1;
+      } else fseek(fp_in, 0, SEEK_SET);
+
+      if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog) {
+         if(access(ParsedOutputLog,R_OK) != 0) {
+            sprintf(csort,"%s",ParsedOutputLog);
+            my_mkdir(csort);
+         }
+         sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
+         if((fp_log=MY_FOPEN(arq_log,"w"))==NULL) {
+            fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq_log,strerror(errno));
+            exit(1);
+         }
+         fputs("*** SARG Log ***\n",fp_log);
       }
-      fputs("*** SARG Log ***\n",fp_log);
-   }
 
-   if(strstr(ReportType,"denied") != 0) {
-#if defined(HAVE_FOPEN64)
-      if((fp_denied=fopen64(tmp4,"w"))==NULL) {
-#else
-      if((fp_denied=fopen(tmp4,"w"))==NULL) {
-#endif
-         fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp4,strerror(errno));
-         exit(1);
+      if(strstr(ReportType,"denied") != 0) {
+         if((fp_denied=MY_FOPEN(tmp4,"w"))==NULL) {
+            fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp4,strerror(errno));
+            exit(1);
+         }
       }
-   }
 
-   if(DataFile[0]=='\0') {
-      if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
-#if defined(HAVE_FOPEN64)
-         if((fp_authfail=fopen64(tmp6,"w"))==NULL) {
-#else
-         if((fp_authfail=fopen(tmp6,"w"))==NULL) {
-#endif
-            fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp6,strerror(errno));
-            exit(1);
+      if(DataFile[0]=='\0') {
+         if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
+            if((fp_authfail=MY_FOPEN(tmp6,"w"))==NULL) {
+               fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp6,strerror(errno));
+               exit(1);
+            }
          }
       }
-   }
 
-   // pre-Read the file only if I have to show stats
-   if(bool_ShowReadStatistics) {
-      rewind(fp_in);
-      recs1=0;
-      recs2=0;
+      // pre-Read the file only if I have to show stats
+      if(bool_ShowReadStatistics) {
+         rewind(fp_in);
+         recs1=0;
+         recs2=0;
 
-      while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
-      rewind(fp_in);
-      printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,(float) 0);
-      fflush( stdout ) ;
-   }
-   
-   while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
-       recs2++;
-       if( bool_ShowReadStatistics && ! --OutputNonZero) {
+         while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
+         rewind(fp_in);
+         printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,(float) 0);
+         fflush( stdout ) ;
+      }
+
+      while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
+         recs2++;
+         if( bool_ShowReadStatistics && ! --OutputNonZero) {
            perc = recs2 * 100 ;
            perc = perc / recs1 ;
            printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\r",recs1,perc);
            fflush (stdout);
            OutputNonZero = REPORT_EVERY_X_LINES ;
-        }
-        if(strlen(bufz) > MAXLEN-1) continue;
-        if(!bufz[0]) continue;
-        if(strstr(bufz,"HTTP/0.0") != 0) continue;
-        if(strstr(bufz,"logfile turned over") != 0) continue;
-        if(bufz[0] == ' ') continue;
-        if(strlen(bufz) < 58) continue;
-
-        // Record only hours usage which is required
-        tt = (time_t) strtoul( bufz, NULL, 10 );
-        t = localtime( &tt );
-
-        if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
-                                        sizeof( int ), compar ) == NULL )
-          continue;
-
-        if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
-                                        sizeof( int ), compar ) == NULL )
-          continue;
-
-        // exclude_string
-        exstring=0;
-        if(strlen(ExcludeString) > 0) {
-           strcpy(warea,bufz);
-           strcpy(html,ExcludeString);
-           while(strstr(html,":") != 0) {
-              if (getword_multisep(val1,sizeof(val1),html,':')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
-                 exit(1);
-              }
-              if((str=(char *) strstr(warea,val1)) != (char *) NULL )
-                 exstring++;
-           }
-           if((str=(char *) strstr(warea,html)) != (char *) NULL )
-                 exstring++;
-        }
-        if(exstring) continue;
-
-        strcpy(bufy,bufz);
-        if ((str = strchr(bufz, '\n')) != NULL)
-           *str = '\0';          /* strip \n */       
-
-        totregsl++;
-        common=0;
-        if(debugm)
-                  printf("BUF=%s\n",bufz);
-
-        if(!sarglog && !isalog) {
-           if (getword(data,sizeof(data),bufz,' ')<0) {
-             printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
-             exit(1);
-           }
-           if((str=(char *) strstr(data, ".")) != (char *) NULL ) {
-              if((str=(char *) strstr(str+1, ".")) != (char *) NULL ) {
-                 strcpy(ip,data);
-                        strcpy(elap,"0");
-                        if(squid24) {
-                    if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
-                       printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                       exit(1);
-                    }
-                        } else {
-                       if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
-                       printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                       exit(1);
-                    }
-                 }
-                    if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
-                        getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
-                     getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
-                     getword(tam,sizeof(tam),bufz,' ')<0) {
-                    printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                    exit(1);
-                 }
-                 if((str=(char *) strstr(bufz, " ")) != (char *) NULL ) {
-                    if (getword(code,sizeof(code),bufz,' ')<0) {
-                       printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                       exit(1);
-                    }
-                 }
-                 else strcpy(code,bufz);
-
-                 if ((str = strchr(code, ':')) != NULL)
-                    *str = '/'; 
-
-                if(strcmp(tam,"\0") == 0)
-                   strcpy(tam,"0");
-
-                common++;
-                common_log=1;
-             }
-          }
-
-          if(!common) {
-             if (getword(elap,sizeof(elap),bufz,' ')<0) {
-             printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-             exit(1);
-          }
-             while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
-                if (getword(elap,sizeof(elap),bufz,' ')<0) {
-                printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                exit(1);
-             }
-              if(strlen(elap) < 1) continue;
-                 if (getword(ip,sizeof(ip),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword(code,sizeof(code),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword(tam,sizeof(tam),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword(fun,sizeof(fun),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword(url,sizeof(url),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
+         }
+         if(strlen(bufz) > MAXLEN-1) continue;
+         if(!bufz[0]) continue;
+         if(strstr(bufz,"HTTP/0.0") != 0) continue;
+         if(strstr(bufz,"logfile turned over") != 0) continue;
+         if(bufz[0] == ' ') continue;
+         if(strlen(bufz) < 58) continue;
+
+         // Record only hours usage which is required
+         tt = (time_t) strtoul( bufz, NULL, 10 );
+         t = localtime( &tt );
+
+         if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
+                                          sizeof( int ), compar ) == NULL )
+            continue;
+
+         if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
+                                          sizeof( int ), compar ) == NULL )
+            continue;
+
+         // exclude_string
+         exstring=0;
+         if(strlen(ExcludeString) > 0) {
+            strcpy(warea,bufz);
+            strcpy(html,ExcludeString);
+            while(strstr(html,":") != 0) {
+               if (getword_multisep(val1,sizeof(val1),html,':')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
+                  exit(1);
+               }
+               if((str=(char *) strstr(warea,val1)) != (char *) NULL )
+                  exstring++;
+            }
+            if((str=(char *) strstr(warea,html)) != (char *) NULL )
+                  exstring++;
+         }
+         if(exstring) continue;
+
+         strcpy(bufy,bufz);
+         if ((str = strchr(bufz, '\n')) != NULL)
+            *str = '\0';          /* strip \n */       
+
+         totregsl++;
+         common=0;
+         if(debugm)
+            printf("BUF=%s\n",bufz);
+
+         if(!sarglog && !isalog) {
+            if (getword(data,sizeof(data),bufz,' ')<0) {
+               printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
+               exit(1);
+            }
+            if((str=(char *) strstr(data, ".")) != (char *) NULL ) {
+               if((str=(char *) strstr(str+1, ".")) != (char *) NULL ) {
+                  strcpy(ip,data);
+                  strcpy(elap,"0");
+                  if(squid24) {
+                     if (getword(user,sizeof(user),bufz,' ')<0 || getword(none,sizeof(none),bufz,' ')<0) {
+                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        exit(1);
+                     }
+                  } else {
+                     if (getword(none,sizeof(none),bufz,' ')<0 || getword(user,sizeof(user),bufz,' ')<0) {
+                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        exit(1);
+                     }
+                  }
+                  if (getword(data,sizeof(data),bufz,']')<0 || getword(fun,sizeof(fun),bufz,'"')<0 ||
+                      getword(fun,sizeof(fun),bufz,' ')<0 || getword(url,sizeof(url),bufz,' ')<0 ||
+                      getword(code2,sizeof(code2),bufz,' ')<0 || getword(code2,sizeof(code2),bufz,' ')<0 ||
+                      getword(tam,sizeof(tam),bufz,' ')<0) {
+                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     exit(1);
+                  }
+                  if((str=(char *) strstr(bufz, " ")) != (char *) NULL ) {
+                     if (getword(code,sizeof(code),bufz,' ')<0) {
+                        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                        exit(1);
+                     }
+                  }
+                  else strcpy(code,bufz);
+
+                  if ((str = strchr(code, ':')) != NULL)
+                     *str = '/'; 
+
+                  if(strcmp(tam,"\0") == 0)
+                     strcpy(tam,"0");
+
+                  common++;
+                  common_log=1;
+               }
+            }
+
+            if(!common) {
+               if (getword(elap,sizeof(elap),bufz,' ')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               while(strcmp(elap,"") == 0 && strlen(bufz) > 0)
+                  if (getword(elap,sizeof(elap),bufz,' ')<0) {
+                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     exit(1);
+                  }
+               if(strlen(elap) < 1) continue;
+               if (getword(ip,sizeof(ip),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(code,sizeof(code),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(tam,sizeof(tam),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(fun,sizeof(fun),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword(url,sizeof(url),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
 //              while (strstr(bufz,"%20") != 0) {
 //                 getword(warea,bufz,' ');
 //                 strcat(url,warea);
 //              }
-              if (getword(user,sizeof(user),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              squid_log=1;
-              }
-        } else if(!isalog) {
-              if (getword(data,sizeof(data),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(hora,sizeof(hora),bufz,' ')<0) {
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(user,sizeof(user),bufz,' ')<0) {
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(ip,sizeof(ip),bufz,' ')<0) {
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(url,sizeof(url),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(tam,sizeof(tam),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(code,sizeof(code),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(elap,sizeof(elap),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-        } else if(isalog) {
-           if(!i0) {
-              if (getword(val1,sizeof(val1),bufz,' ')<0){
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-              while(strstr(bufz,"\t") != 0) {
-                 if (getword(val1,sizeof(val1),bufz,'\t')<0){
-                    printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                    exit(1);
-                 }
-                 i0++;
-                 if(strcmp(val1,"c-ip") == 0) i1=i0;
-                 if(strcmp(val1,"cs-username") == 0) i2=i0;
-                 if(strcmp(val1,"date") == 0) i3=i0;
-                 if(strcmp(val1,"time") == 0) i4=i0;
-                 if(strcmp(val1,"time-taken") == 0) i5=i0;
-                 if(strcmp(val1,"sc-bytes") == 0) i6=i0;
-                 if(strcmp(val1,"cs-uri") == 0) i7=i0;
-                 if(strcmp(val1,"sc-status") == 0) i8=i0;
-              }
-           }
-           fgets(bufz,sizeof(bufz),fp_in);
-           strcpy(val1,bufz);
-           for(x=0; x<=i1-1; x++) {
-              if (getword3(ip,sizeof(ip),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i2-1; x++) {
-              if (getword3(user,sizeof(user),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i3-1; x++) {
-              if (getword3(data,sizeof(data),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i4-1; x++) {
-              if (getword3(hora,sizeof(hora),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i5-1; x++) {
-              if (getword3(elap,sizeof(elap),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i6-1; x++) {
-              if (getword3(tam,sizeof(tam),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i7-1; x++) {
-              if (getword3(url,sizeof(url),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           strcpy(val1,bufz);
-           for(x=0; x<=i8-1; x++) {
-              if (getword3(code,sizeof(code),val1,'\t')<0) {
-                 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-                 exit(1);
-              }
-           }
-           
-           if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
-              sprintf(val1,"DENIED/%s",code);
-              strcpy(code,val1);
-           }
-           if (getword(ano,sizeof(ano),data,'-')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(mes,sizeof(mes),data,'-')<0){
-              printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
-              exit(1);
-           }
-           strcpy(dia,data);
-           conv_month_name(mes);
-           sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
-        }
-
-        if(strlen(user) > 150) {
-           totregsx++;
-           continue;
-        }
-
-       // include_users
-       if(strlen(IncludeUsers) > 0) {
-           sprintf(val1,":%s:",user);
-           if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
-              continue;
-       }
-
-        if(excode) {
-           if(vercode(code)) {
-              totregsx++;
-              continue;
-           }
-        }
-
-        if(testvaliduserchar(user))
-          continue;
-
-        if(strstr(user,"%20") != 0) {
-           if (getword(w,sizeof(w),user,'%')<0) {
-              printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-              exit(1);
-           }
-           strcpy(user,w);
-        }
-
-        while(strstr(user,"%5c") != 0) {
-           if (getword_multisep(w,sizeof(w),user,'%')<0){
-              printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-              exit(1);
-           }
-           strcpy(wuser,user+2);
-           sprintf(user,"%s.%s",w,wuser);
-        }
-
-       str=user;
-       for(z1=0; str[z1]; z1++) {
-          if(isalnum(str[z1]) || ispunct(str[z1])) {
-          if(str[z1]=='.') dotinuser++;
-          if(str[z1]=='?' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
-             str[z1]='_';
-          }
-       }
-
-        strlow(user);
-        if(strncmp(NtlmUserFormat,"user",4) == 0) {
-           if(strstr(user,"_") != 0)
-              if (getword_multisep(warea,sizeof(warea),user,'_')<0){
-                 printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-                 exit(1);
-              }
-           if(strstr(user,"+") != 0)
-              if (getword_multisep(warea,sizeof(warea),user,'+')<0){
-                 printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
-                 exit(1);
-              }
-        }
-
-        if(strstr(ReportType,"denied") != 0)
-           strcpy(urly,url);
-
-        if(strlen(DownloadSuffix)) {
-           suffix[0]='\0';
-           download_flag=0;
-           if(strncmp(url+strlen(url)-4,".",1) == 0)
-              strcpy(suffix,url+strlen(url)-3);
-           else strcpy(suffix,url+strlen(url)-4);
-           if(strstr(DownloadSuffix,suffix) != 0) {
-              strcpy(download_url,url);
-              download_flag=1;
-              download_count++;
-           }
-        }
-         
-        if (strchr(url,'/')) {
-           if (getword(w,sizeof(w),url,'/')<0){
-              printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword(w,sizeof(w),url,'/')<0){
-              printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
-              exit(1);
-           }
-           if (!strchr(url,'/')) {
-              totregsx++;
-              continue;
-          }
-        }
-
-        if(strcmp(LongUrl,"no") == 0) {
-           if (getword_multisep(w,sizeof(w),url,'/')<0){
-              printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
-              exit(1);
-           }
-           strcpy(url,w);
-           if(strlen(url) > 512 && strstr(url,"%") != 0) {
-              if (getword_multisep(w,sizeof(w),url,'%')<0){
-                 printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
-                 exit(1);
-              }
-              strcpy(url,w);
-           }
-        }
-
-        if(!sarglog) {
-           if(!common && !isalog) {
-              tt=atoi(data);
-              t=localtime(&tt);
-
-              strftime(tbuf2, 127, "%H%M", t);
-              if(strncmp(df,"u",1) == 0)
-                strftime(tbuf, 127, "%Y%b%d", t);
-              if(strncmp(df,"e",1) == 0)
-                strftime(tbuf, 127, "%d%b%Y", t);
-              if(strncmp(df,"w",1) == 0) {
-                 strcpy(IndexTree,"file");
-                strftime(tbuf, 127, "%Y.%U", t);
-              }
-
-              strftime(dia, 127, "%d/%m/%Y", t);
-              strftime(wdata, 127, "%Y%m%d", t);
-          
-              idata=atoi(wdata);
-
-              if(strncmp(df,"u",1)==0)
-                 strftime(dia, 127, "%m/%d/%Y", t);
-              sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
-              } else {
-                 strcpy(wtemp,data+1);
-                 if (getword_multisep(data,sizeof(data),wtemp,':')<0){
-                 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
-                 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword_multisep(dia,sizeof(dia),data,'/')<0){
-                 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword_multisep(mes,sizeof(mes),data,'/')<0){
-                 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-                 exit(1);
-              }
-              if (getword_multisep(ano,sizeof(ano),data,'/')<0){
-                 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-                 exit(1);
-              }
-
-              if(strcmp(df,"u") == 0)
-                sprintf(tbuf,"%s%s%s",ano,mes,dia);
-              if(strcmp(df,"e") == 0)
-                sprintf(tbuf,"%s%s%s",dia,mes,ano);
-             builddia(dia,mes,ano,df,wdata);
-              idata=atoi(wdata);
-          }
-        } else {
-              if (getword_multisep(mes,sizeof(mes),data,'/')<0){
-              printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword_multisep(dia,sizeof(dia),data,'/')<0){
-              printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-              exit(1);
-           }
-           if (getword_multisep(ano,sizeof(ano),data,0)<0){
-              printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
-              exit(1);
-           }
-        }
-
-        if(debugm)
-           printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
-
-        l=1;
-        if(strlen(us)>0){
-          if(strcmp(user,us)==0)
-             l=1;else l=0;
-       }
-           
-        if(l){
-           if(strlen(addr)>0){
-             if(strcmp(addr,ip)==0)
-                l=1;else l=0;
-          }
-           if(fhost) {
+               if (getword(user,sizeof(user),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               squid_log=1;
+            }
+         } else if(!isalog) {
+            if (getword(data,sizeof(data),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(hora,sizeof(hora),bufz,' ')<0) {
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(user,sizeof(user),bufz,' ')<0) {
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(ip,sizeof(ip),bufz,' ')<0) {
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(url,sizeof(url),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(tam,sizeof(tam),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(code,sizeof(code),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(elap,sizeof(elap),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(smartfilter,sizeof(smartfilter),bufz,' ')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+         } else if(isalog) {
+            if(!i0) {
+               if (getword(val1,sizeof(val1),bufz,' ')<0){
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+               while(strstr(bufz,"\t") != 0) {
+                  if (getword(val1,sizeof(val1),bufz,'\t')<0){
+                     printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                     exit(1);
+                  }
+                  i0++;
+                  if(strcmp(val1,"c-ip") == 0) i1=i0;
+                  if(strcmp(val1,"cs-username") == 0) i2=i0;
+                  if(strcmp(val1,"date") == 0) i3=i0;
+                  if(strcmp(val1,"time") == 0) i4=i0;
+                  if(strcmp(val1,"time-taken") == 0) i5=i0;
+                  if(strcmp(val1,"sc-bytes") == 0) i6=i0;
+                  if(strcmp(val1,"cs-uri") == 0) i7=i0;
+                  if(strcmp(val1,"sc-status") == 0) i8=i0;
+               }
+            }
+            fgets(bufz,sizeof(bufz),fp_in);
+            strcpy(val1,bufz);
+            for(x=0; x<=i1-1; x++) {
+               if (getword3(ip,sizeof(ip),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i2-1; x++) {
+               if (getword3(user,sizeof(user),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i3-1; x++) {
+               if (getword3(data,sizeof(data),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i4-1; x++) {
+               if (getword3(hora,sizeof(hora),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i5-1; x++) {
+               if (getword3(elap,sizeof(elap),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i6-1; x++) {
+               if (getword3(tam,sizeof(tam),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i7-1; x++) {
+               if (getword3(url,sizeof(url),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+            strcpy(val1,bufz);
+            for(x=0; x<=i8-1; x++) {
+               if (getword3(code,sizeof(code),val1,'\t')<0) {
+                  printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+                  exit(1);
+               }
+            }
+
+            if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
+               sprintf(val1,"DENIED/%s",code);
+               strcpy(code,val1);
+            }
+            if (getword(ano,sizeof(ano),data,'-')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(mes,sizeof(mes),data,'-')<0){
+               printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
+               exit(1);
+            }
+            strcpy(dia,data);
+            conv_month_name(mes);
+            sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
+         }
+
+         if(strlen(user) > 150) {
+            totregsx++;
+            continue;
+         }
+
+         // include_users
+         if(strlen(IncludeUsers) > 0) {
+            sprintf(val1,":%s:",user);
+            if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
+               continue;
+         }
+
+         if(excode) {
+            if(vercode(code)) {
+               totregsx++;
+               continue;
+            }
+         }
+
+         if(testvaliduserchar(user))
+            continue;
+
+         if(strstr(user,"%20") != 0) {
+            if (getword(w,sizeof(w),user,'%')<0) {
+               printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+               exit(1);
+            }
+            strcpy(user,w);
+         }
+
+         while(strstr(user,"%5c") != 0) {
+            if (getword_multisep(w,sizeof(w),user,'%')<0){
+               printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+               exit(1);
+            }
+            strcpy(wuser,user+2);
+            sprintf(user,"%s.%s",w,wuser);
+         }
+
+         str=user;
+         for(z1=0; str[z1]; z1++) {
+            if(isalnum(str[z1]) || ispunct(str[z1])) {
+            if(str[z1]=='.') dotinuser++;
+            if(str[z1]=='?' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\')
+               str[z1]='_';
+            }
+         }
+
+         strlow(user);
+         if(strncmp(NtlmUserFormat,"user",4) == 0) {
+            if(strstr(user,"_") != 0)
+               if (getword_multisep(warea,sizeof(warea),user,'_')<0){
+                  printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+                  exit(1);
+               }
+            if(strstr(user,"+") != 0)
+               if (getword_multisep(warea,sizeof(warea),user,'+')<0){
+                  printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
+                  exit(1);
+               }
+         }
+
+         if(strstr(ReportType,"denied") != 0)
+            strcpy(urly,url);
+
+         if(strlen(DownloadSuffix)) {
+            suffix[0]='\0';
+            download_flag=0;
+            if(strncmp(url+strlen(url)-4,".",1) == 0)
+               strcpy(suffix,url+strlen(url)-3);
+            else strcpy(suffix,url+strlen(url)-4);
+            if(strstr(DownloadSuffix,suffix) != 0) {
+               strcpy(download_url,url);
+               download_flag=1;
+               download_count++;
+            }
+         }
+
+         if (strchr(url,'/')) {
+            if (getword(w,sizeof(w),url,'/')<0){
+               printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword(w,sizeof(w),url,'/')<0){
+               printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+               exit(1);
+            }
+            if (!strchr(url,'/')) {
+               totregsx++;
+               continue;
+            }
+         }
+
+         if(strcmp(LongUrl,"no") == 0) {
+            if (getword_multisep(w,sizeof(w),url,'/')<0){
+               printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+               exit(1);
+            }
+            strcpy(url,w);
+            if(strlen(url) > 512 && strstr(url,"%") != 0) {
+               if (getword_multisep(w,sizeof(w),url,'%')<0){
+                  printf("SARG: Maybe you have a broken url in your %s file.\n",arq);
+                  exit(1);
+               }
+               strcpy(url,w);
+            }
+         }
+
+         if(!sarglog) {
+            if(!common && !isalog) {
+               tt=atoi(data);
+               t=localtime(&tt);
+
+               strftime(tbuf2, 127, "%H%M", t);
+               if(strncmp(df,"u",1) == 0)
+                  strftime(tbuf, 127, "%Y%b%d", t);
+               if(strncmp(df,"e",1) == 0)
+                  strftime(tbuf, 127, "%d%b%Y", t);
+               if(strncmp(df,"w",1) == 0) {
+                  strcpy(IndexTree,"file");
+                  strftime(tbuf, 127, "%Y.%U", t);
+               }
+
+               strftime(dia, 127, "%d/%m/%Y", t);
+               strftime(wdata, 127, "%Y%m%d", t);
+
+               idata=atoi(wdata);
+
+               if(strncmp(df,"u",1)==0)
+                  strftime(dia, 127, "%m/%d/%Y", t);
+               sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
+            } else {
+               strcpy(wtemp,data+1);
+               if (getword_multisep(data,sizeof(data),wtemp,':')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword_multisep(hora,sizeof(hora),wtemp,' ')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+               if (getword_multisep(ano,sizeof(ano),data,'/')<0){
+                  printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+                  exit(1);
+               }
+
+               if(strcmp(df,"u") == 0)
+                  sprintf(tbuf,"%s%s%s",ano,mes,dia);
+               if(strcmp(df,"e") == 0)
+                  sprintf(tbuf,"%s%s%s",dia,mes,ano);
+               builddia(dia,mes,ano,df,wdata);
+               idata=atoi(wdata);
+            }
+         } else {
+            if (getword_multisep(mes,sizeof(mes),data,'/')<0){
+               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword_multisep(dia,sizeof(dia),data,'/')<0){
+               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               exit(1);
+            }
+            if (getword_multisep(ano,sizeof(ano),data,0)<0){
+               printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
+               exit(1);
+            }
+         }
+
+         if(debugm)
+            printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
+
+         l=1;
+         if(strlen(us)>0){
+            if(strcmp(user,us)==0)
+               l=1;
+            else
+               l=0;
+         }
+
+         if(l){
+            if(strlen(addr)>0){
+               if(strcmp(addr,ip)==0)
+                  l=1;else l=0;
+            }
+            if(fhost) {
 //              l=vhexclude(excludefile,ip);
-              l=vhexclude(excludefile,url);
-              if(!l)
-                totregsx++;
-           }
-        }
-
-        if(l){
-           if(strlen(date) > 0){
-              if(idata >= dfrom && idata <= duntil)
-                l=1;else l=0;
-          }
-        }
-        if(l){
-           if(strlen(hm)>0) {
-              strcpy(whm,hora);
-              bzero(hmr,15);
-              chm++;
-              while(chm) {
-                 if (getword_multisep(warea,sizeof(warea),whm,':')<0){
-                    printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
-                    exit(1);
-                 }
-                 strncat(hmr,warea,2);
-                 chm--;
-              }
-              strncat(hmr,whm,2);
-
-             if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
-                l=1;else l=0;
-          }
-        }
-        if(l){
-           if(strlen(site)>0){
-             if(strstr(url,site)!=0)
-                l=1;else l=0;
-          }
-        }
-
-        if(userip)
-           strcpy(user,ip);
-
-        if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
-           if(strcmp(RecordsWithoutUser,"ip") == 0)
-             strcpy(user,ip);
-           if(strcmp(RecordsWithoutUser,"ignore") == 0)
-             continue;
-           if(strcmp(RecordsWithoutUser,"everybody") == 0)
-             strcpy(user,"everybody");
-        }
-
-        if(dotinuser) {
-           str2=(char *)subs(user,"_",".");
-           strcpy(user,str2);
-           dotinuser=0;
-        }
-
-        if(puser) {
-           sprintf(wuser,":%s:",user);
-           if(strstr(userfile, wuser) == 0)
-              continue;
-        }
-        
-        if(l) {
-           if(fuser) {
-              l=vuexclude(excludeuser,user);
-              if(!l)
-                totregsx++;
-           }
-        }
-
-        if(l) {
-           if(userip)
-              fixip(user);
-        }
-
-        if(l&&max_elapsed) {
-           if(atol(elap)>max_elapsed) {
-              elap[0]='0';
-              elap[1]='\0';
-           }
-        }
-
-        if(l) {
-          if(strcmp(user,"-") !=0 && strlen(url) > 0 && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
-              if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
-                 str[strlen(str)-1]='\0';
-                 sprintf(smartfilter,"\"%s\"",str+1);
-              } else sprintf(smartfilter,"\"\"");
-
-              sprintf(bufz, "%s %s %s %s %s %s %s %s %s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+               l=vhexclude(excludefile,url);
+               if(!l)
+                  totregsx++;
+            }
+         }
 
-#ifdef LEGACY_WRITE_USER
-              sprintf(tmp3,"%s/sarg/%s.unsort",tmp,user);
-#if defined(HAVE_FOPEN64)
-              if((fp_ou=fopen64(tmp3,"a"))==NULL) {
-#else
-              if((fp_ou=fopen(tmp3,"a"))==NULL) {
-#endif
-                fprintf(stderr, "%s: (zzzlog) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
-                exit(1);
-              }
-              fputs(bufz,fp_ou);
+         if(l){
+            if(strlen(date) > 0){
+               if(idata >= dfrom && idata <= duntil)
+                  l=1;else l=0;
+            }
+         }
+         if(l){
+            if(strlen(hm)>0) {
+               strcpy(whm,hora);
+               bzero(hmr,15);
+               chm++;
+               while(chm) {
+                  if (getword_multisep(warea,sizeof(warea),whm,':')<0){
+                     printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
+                     exit(1);
+                  }
+                  strncat(hmr,warea,2);
+                  chm--;
+               }
+               strncat(hmr,whm,2);
 
-#else
-                  if ( strcmp ( user , sz_Last_User ) != 0 ) {
-                        if ( fp_Write_User )
-                                fclose( fp_Write_User ) ;
-                        sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
+               if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
+                  l=1;else l=0;
+            }
+         }
+         if(l){
+            if(strlen(site)>0){
+               if(strstr(url,site)!=0)
+                  l=1;else l=0;
+            }
+         }
+
+         if(userip)
+            strcpy(user,ip);
+
+         if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
+            if(strcmp(RecordsWithoutUser,"ip") == 0)
+            strcpy(user,ip);
+            if(strcmp(RecordsWithoutUser,"ignore") == 0)
+            continue;
+            if(strcmp(RecordsWithoutUser,"everybody") == 0)
+            strcpy(user,"everybody");
+         }
+
+         if(dotinuser) {
+            str2=(char *)subs(user,"_",".");
+            strcpy(user,str2);
+            dotinuser=0;
+         }
+
+         if(puser) {
+            sprintf(wuser,":%s:",user);
+            if(strstr(userfile, wuser) == 0)
+               continue;
+         }
+
+         if(l) {
+            if(fuser) {
+               l=vuexclude(excludeuser,user);
+               if(!l)
+                  totregsx++;
+            }
+         }
+
+         if(l) {
+            if(userip)
+               fixip(user);
+         }
+
+         if(l&&max_elapsed) {
+            if(atol(elap)>max_elapsed) {
+               elap[0]='0';
+               elap[1]='\0';
+            }
+         }
+
+         if(l) {
+            if(strcmp(user,"-") !=0 && strlen(url) > 0 && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
+               if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
+                  str[strlen(str)-1]='\0';
+                  sprintf(smartfilter,"\"%s\"",str+1);
+               } else sprintf(smartfilter,"\"\"");
+
+               sprintf(bufz, "%s %s %s %s %s %s %s %s %s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
+
+#ifdef LEGACY_WRITE_USER
+               sprintf(tmp3,"%s/sarg/%s.unsort",tmp,user);
+               if((fp_ou=MY_FOPEN(tmp3,"a"))==NULL) {
+                  fprintf(stderr, "%s: (zzzlog) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
+                  exit(1);
+               }
+               fputs(bufz,fp_ou);
 
-#if defined(HAVE_FOPEN64)
-                        if ((fp_Write_User = fopen64 (tmp3, "a")) == NULL) {
 #else
-                        if ((fp_Write_User = fopen (tmp3, "a")) == NULL) {
-#endif
-                              fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
-                                exit (1);
-                        }
-                        strcpy( sz_Last_User , user ) ;
+               if ( strcmp ( user , sz_Last_User ) != 0 ) {
+                  if ( fp_Write_User )
+                     fclose( fp_Write_User ) ;
+                  sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
+
+                  if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
+                     fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+                     exit (1);
                   }
-                  fputs (bufz, fp_Write_User);
+                  strcpy( sz_Last_User , user ) ;
+               }
+               fputs (bufz, fp_Write_User);
 #endif
 
-              if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog)
-                 fputs(bufz,fp_log);
+               if(strcmp(ParsedOutputLog, "no") != 0 && !sarglog)
+                  fputs(bufz,fp_log);
 
 #ifdef LEGACY_WRITE_USER
-              fclose(fp_ou);
+               fclose(fp_ou);
 #endif
-             totregsg++;
+               totregsg++;
 
-              if(download_flag && strstr(code,"DENIED") == 0) {
-                 ndownload = 1;
-                 sprintf(bufz, "%s %s %s %s %s\n",dia,hora,user,ip,download_url);
+               if(download_flag && strstr(code,"DENIED") == 0) {
+                  ndownload = 1;
+                  sprintf(bufz, "%s %s %s %s %s\n",dia,hora,user,ip,download_url);
 
 #ifdef LEGACY_WRITE_DOWNLOAD
-                 sprintf(tmp3,"%s/sarg/download.unsort",tmp);
-#if defined(HAVE_FOPEN64)
-                 if((fp_ou=fopen64(tmp3,"a"))==NULL) {
-#else
-                 if((fp_ou=fopen(tmp3,"a"))==NULL) {
-#endif
-                    fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
-                    exit(1);
-                 }
-                 fputs(bufz,fp_ou);
-                 fclose(fp_ou);
-#else
-                 if ( ! fp_Download_Unsort ) {
-#if defined(HAVE_FOPEN64)
-                      if ((fp_Download_Unsort = fopen64 ( sz_Download_Unsort, "a")) == NULL) {
+                  sprintf(tmp3,"%s/sarg/download.unsort",tmp);
+                  if((fp_ou=MY_FOPEN(tmp3,"a"))==NULL) {
+                     fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[9],tmp3,strerror(errno));
+                     exit(1);
+                  }
+                  fputs(bufz,fp_ou);
+                  fclose(fp_ou);
 #else
-                      if ((fp_Download_Unsort = fopen (sz_Download_Unsort, "a")) == NULL) {
-#endif
-                          fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
-                          exit (1);
-                      }
-                 }
-                 fputs (bufz, fp_Download_Unsort);
+                  if ( ! fp_Download_Unsort ) {
+                     if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) {
+                        fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
+                        exit (1);
+                     }
+                  }
+                  fputs (bufz, fp_Download_Unsort);
 #endif
-              }
-
-              if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
-                 if(strstr(code,"DENIED/403") != 0) {
-                    fprintf(fp_denied, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
-                    denied_count++;
-                 }
-                 if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
-                    if(fp_authfail)
-                       fprintf(fp_authfail, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
-                    authfail_count++;
-                 }
-              }
-       
-              if((!totper || idata<mindate) && !sarglog){
-                    totper++;
-                 mindate=idata;
-                 sprintf(period,"%s-",tbuf);
-                 sprintf(per_hour,"%s-",tbuf2);
-                 if(strlen(date)>0)
-                    fixper(tbuf, period, cduntil);
-                 if(debugz){
-                    debugaz("tbuf",tbuf);
-                    debugaz("period",period);
-                 }
-             }
-           }
-
-           if(debugm){
-              printf("IP=\t%s\n",ip);
-              printf("USER=\t%s\n",user);
-              printf("ELAP=\t%s\n",elap);
-              printf("DATE=\t%s\n",dia);
-              printf("TIME=\t%s\n",hora);
-              printf("FUNC=\t%s\n",fun);
-              printf("URL=\t%s\n",url);
-              printf("CODE=\t%s\n",code);
-              printf("LEN=\t%s\n",tam);
-          }
-        }
+               }
+
+               if(strstr(ReportType,"denied") != 0 || strstr(ReportType,"auth_failures") != 0) {
+                  if(strstr(code,"DENIED/403") != 0) {
+                     fprintf(fp_denied, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
+                     denied_count++;
+                  }
+                  if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
+                     if(fp_authfail)
+                        fprintf(fp_authfail, "%s %s %s %s %s\n",dia,hora,user,ip,urly);
+                     authfail_count++;
+                  }
+               }
+
+               if((!totper || idata<mindate) && !sarglog){
+                  totper++;
+                  mindate=idata;
+                  sprintf(period,"%s-",tbuf);
+                  sprintf(per_hour,"%s-",tbuf2);
+                  if(strlen(date)>0)
+                     fixper(tbuf, period, cduntil);
+                  if(debugz){
+                     debugaz("tbuf",tbuf);
+                     debugaz("period",period);
+                  }
+               }
+            }
+
+            if(debugm){
+               printf("IP=\t%s\n",ip);
+               printf("USER=\t%s\n",user);
+               printf("ELAP=\t%s\n",elap);
+               printf("DATE=\t%s\n",dia);
+               printf("TIME=\t%s\n",hora);
+               printf("FUNC=\t%s\n",fun);
+               printf("URL=\t%s\n",url);
+               printf("CODE=\t%s\n",code);
+               printf("LEN=\t%s\n",tam);
+            }
+         }
       }
       if( bool_ShowReadStatistics )
         printf("SARG: Records in file: " OFFSET_STRING ", reading: %3.2f%%\n",recs1, (float) 100 );
@@ -1495,24 +1424,24 @@ int main(argc,argv)
    if(debug) {
       sprintf(msg, "   %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx);
       debuga(msg);
-  
+
       if((common_log) && (squid_log))
          debuga(text[12]);
-  
+
       if((common_log) && (!squid_log)) 
          debuga(text[13]);
+
       if((!common_log) && (squid_log))
          debuga(text[14]);
 
       if(sarglog)
          debuga(text[124]);
+
       if((!common_log) && (!squid_log) && (!sarglog) && (!isalog)) {
          if(!totregsg) {
             fprintf(stderr, "SARG: %s\n",text[16]);
             fprintf(stderr, "SARG: %s\n",text[21]);
-        } else fprintf(stderr, "SARG: %s\n",text[15]);
+         } else fprintf(stderr, "SARG: %s\n",text[15]);
          bzero(msg,sizeof(msg));
          fclose(fp_in);
 //         fclose(fp_ou);
@@ -1526,7 +1455,7 @@ int main(argc,argv)
          exit(0);
       }
    }
+
    if(!totregsg){
       fprintf(stderr, "SARG: %s\n",text[16]);
       fprintf(stderr, "SARG: %s\n",text[21]);
@@ -1603,7 +1532,7 @@ int main(argc,argv)
       }
       unlink(tmp4);
    }
+
    sort_users_log(tmp, debug);
 
    if(strlen(DataFile) > 0)
@@ -1614,9 +1543,10 @@ int main(argc,argv)
    unlink(tmp2);
    if(strstr(ReportType,"denied") != 0)
       unlink(tmp5);
+
    if((strlen(zip) > 0 && strcmp(zip,"zcat") !=0)) {
-      recomp(arq, zip); }
+      recomp(arq, zip);
+   }
 //   else  unlink(arq);
 
    if(strcmp(tmp,"/tmp") != 0) {
@@ -1641,13 +1571,13 @@ int main(argc,argv)
 }
 
 
-void getusers(char *pwdfile, int debug)
+static void getusers(const char *pwdfile, int debug)
 {
 
    FILE *fp_usr;
    char buf[255];
    char Msg[255];
-   char user[255];
+   char *str;
    unsigned long int nreg=0;
 
    if(debug) {
@@ -1662,7 +1592,7 @@ void getusers(char *pwdfile, int debug)
 
    fseek(fp_usr, (off_t)0, SEEK_END);
    nreg = ftell(fp_usr);
-   nreg = nreg+5000; 
+   nreg = nreg+5000;
    fseek(fp_usr, (off_t)0, SEEK_SET);
 
    if((userfile=(char *) malloc(nreg))==NULL){
@@ -1671,15 +1601,16 @@ void getusers(char *pwdfile, int debug)
    }
 
    bzero(userfile,nreg);
-   sprintf(userfile,":");
-
-   while(fgets(buf,255,fp_usr)!=NULL) {
-     if (getword_multisep(user,sizeof(user),buf,':')<0){
-        printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",pwdfile);
-        exit(1);
-     }
-     strncat(userfile,user,strlen(user));
-     strncat(userfile,":",1);
+   strcpy(userfile,":");
+
+   while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
+      str=strchr(buf,':');
+      if (!str) {
+         printf("SARG: You have an invalid user in your %s file.\n",pwdfile);
+         exit(1);
+      }
+      str[1]=0;
+      strcat(userfile,buf);
    }
 
    fclose(fp_usr);
index 6f729ec1db495602f53eca363fb099f90a29e8b7..1b4d1e14e0f6e78d6115be28a0bbcdfcdd5fe9cc 100755 (executable)
@@ -46,54 +46,15 @@ void realtime(void)
 
 static void getlog(void)
 {
-   FILE *tmp, *fp, *fp_usr;
+   FILE *tmp, *fp;
    char template1[255]="/var/tmp/sargtpl1.XXXXXX";
    char template2[255]="/var/tmp/sargtpl2.XXXXXX";
    char cmd[512];
    char buf[MAXLEN];
-   int  fd1,fd2,nreg;
+   int  fd1,fd2;
    int cstatus;
 
-   if(UserTabFile[0] != '\0') {
-      if(debug) {
-         sprintf(msg,"%s: %s",text[86],UserTabFile);
-         debuga(msg);
-      }
-      if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
-        fprintf(stderr, "SARG: (realtime) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
-        exit(1);
-      }
-      fseek(fp_usr, 0, SEEK_END);
-      nreg = ftell(fp_usr);
-      fseek(fp_usr, 0, SEEK_SET);
-      if((userfile=(char *) malloc(nreg+100))==NULL){
-         fprintf(stderr, "SARG ERROR: %s",text[87]);
-         exit(1);
-      }
-      bzero(userfile,nreg+100);
-      strncat(userfile,":",1);
-      z1=0;
-      z2=1;
-      while(fgets(buf,sizeof(buf),fp_usr)!=NULL){
-        buf[strlen(buf)-1]='\0';
-        if(strstr(buf,"\r") != 0) buf[strlen(buf)-1]='\0';
-        if (getword(bufy,sizeof(bufy),buf,' ')<0) {
-           printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
-           exit(1);
-        }
-        for(z1=0; z1<=strlen(bufy); z1++) {
-           userfile[z2]=bufy[z1];
-           z2++;
-        }
-        strncat(userfile,":",1);
-        for(z1=0; z1<=strlen(buf); z1++) {
-           userfile[z2]=buf[z1];
-           z2++;
-        }
-        strncat(userfile,":",1);
-      }
-      fclose(fp_usr);
-   }
+   read_usertab(UserTabFile);
 
    fd1 = mkstemp(template1);
    fd2 = mkstemp(template2);
@@ -249,19 +210,7 @@ void datashow(char *tmp)
       strcpy(u2,user);
       if(strcmp(Ip2Name,"yes") == 0)
          ip2name(u2,sizeof(u2));
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",u2);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,u2);
-      } else strcpy(name,u2);
+      get_usertab_name(u2,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index 85c5543de01220c50c8309878bb4f5d025c12eb9..a40ae0c276fafae613aa37edfa4fd629f5eb6565 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -98,19 +98,7 @@ void report_day(const char *user)
             ip2name(wuser,sizeof(wuser));
    }
 
-   if(UserTabFile[0] != '\0') {
-      sprintf(warea,":%s:",wuser);
-      if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-         z1=0;
-         str2=(char *) strstr(str+1,":");
-         str2++;
-         bzero(name, MAXLEN);
-         while(str2[z1] != ':') {
-            name[z1]=str2[z1];
-            z1++;
-         }
-      } else strcpy(name,wuser);
-   } else strcpy(name,user);
+   get_usertab_name(wuser,name,sizeof(name));
 
    if(dotinuser && strstr(name,"_")) {
       str2=(char *)subs(name,"_",".");
index 02ffdc50d9ff75d70b8fbb4c106862d01767fc79..6eb8b260f3cc6af49b1e228788fc2a312d83380b 100644 (file)
--- a/report.c
+++ b/report.c
@@ -111,6 +111,16 @@ void gerarel(void)
       maketmp(user,tmp,debug,indexonly);
       maketmp_hour(user,tmp,indexonly);
    
+      strcpy(u2,user);
+      if(strcmp(Ip2Name,"yes") == 0)
+         ip2name(u2,sizeof(u2));
+      get_usertab_name(u2,name,sizeof(name));
+
+      if(dotinuser && strstr(name,"_")) {
+         str2=(char *)subs(name,"_",".");
+         strcpy(name,str2);
+      }
+
       ttopen=0;
       bzero(html_old, MAXLEN);
    
@@ -247,28 +257,6 @@ void gerarel(void)
                fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_tt);
                fprintf(fp_tt,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
 
-               strcpy(u2,user);
-               if(strcmp(Ip2Name,"yes") == 0)
-                  ip2name(u2,sizeof(u2));
-               if(UserTabFile[0] != '\0') {
-                  sprintf(warea,":%s:",u2);
-                  if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-                     z1=0;
-                     str2=(char *) strstr(str+1,":");
-                     str2++;
-                     bzero(name, MAXLEN);
-                     while(str2[z1] != ':') {
-                        name[z1]=str2[z1];
-                        z1++;
-                     }
-                  } else strcpy(name,u2);
-               } else strcpy(name,u2);
-
-               if(dotinuser && strstr(name,"_")) {
-                  str2=(char *)subs(name,"_",".");
-                  strcpy(name,str2);
-               }
-
                fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
                fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name);
                fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s:&nbsp;%s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
index 2b33f9ef63be6f44549cbb82a5b5a11412b72c77..4a63faa4ca0d81ab31337602879aceb2147677af 100644 (file)
@@ -50,6 +50,7 @@ void siteuser(void)
    char *users;
    long long int llbytes=0;
    int cstatus;
+   char *str2;
 
    if(strcmp(Privacy,"yes") == 0)
       return;
@@ -122,7 +123,7 @@ void siteuser(void)
       fprintf(stderr, "SARG: ERROR: %s",text[87]);
       exit(1);
    }
-   strcat(users," ");
+   strcpy(users," ");
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       if (getword(user,sizeof(user),buf,' ')<0) {
@@ -134,30 +135,27 @@ void siteuser(void)
       if(userip)
          fixip(user);
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-        if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-              z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
-
-      if(dotinuser && strstr(name,"_")) {
+      get_usertab_name(user,name,sizeof(name));
+
+      if(dotinuser && strchr(name,'_')) {
          str2=(char *)subs(name,"_",".");
          strcpy(name,str2);
       }
 
+      /*
+      In fact, even the first call is unecessary as the resolved user variable is never used.
       if(strcmp(Ip2Name,"yes") == 0)
          ip2name(user,sizeof(user));
+      */
 
+      /*
+      Is this redundant ip2name a mistake or is it really necessary ? It definitely slow down sarg
+      if the first ip2name succeed because it will try to resolve a name which is not an IP but if
+      the first ip2name failed, the second attempt may find the expected address which was resolved
+      in the mean time by the DNS server.
       if(strcmp(Ip2Name,"yes") == 0)
          ip2name(user,sizeof(user));
+      */
 
       if (getword(nacc,sizeof(nacc),buf,' ')<0){
          printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
index c3cf11effc916b43474d65c6ea2e601861bee88d..96ba1a0d488a5119569728bb98fccd34ea434d60 100644 (file)
@@ -42,11 +42,7 @@ void splitlog(const char *arq, char *df, int dfrom, int duntil, char *convert)
    if(arq[0] == '\0')
       arq="/usr/local/squid/logs/access.log";
 
-#if defined(HAVE_FOPEN64)
-   if((fp_in=fopen64(arq,"r"))==NULL) {
-#else
-   if((fp_in=fopen(arq,"r"))==NULL) {
-#endif
+   if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
       fprintf(stderr, "SARG: (splitlog) %s: %s\n",text[8],arq);
       exit(1);
    }
index e2cb6af3f66354e7931b66f7160cd16f18460aba..9bb24b33612e8d3af2d113bcefc579406d615824 100644 (file)
@@ -148,19 +148,7 @@ void squidguard_report(void)
             strcpy(oip,ip);
       }
 
-      if(UserTabFile[0] != '\0') {
-         sprintf(warea,":%s:",user);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user);
-      } else strcpy(name,user);
+      get_usertab_name(user,name,sizeof(name));
 
       if(dotinuser && strstr(name,"_")) {
          str2=(char *)subs(name,"_",".");
index 29364047db5a75c1222cd82cc7bd4bd1cc75f122..f0124e1c5870a88b83ec2cc986bbb6cd7e3727f3 100644 (file)
--- a/topuser.c
+++ b/topuser.c
@@ -69,13 +69,13 @@ void topuser(void)
 
    ntopuser = 0;
    if((fp_in=fopen(wger,"r"))==NULL) {
-    fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger);
-    exit(1);
+      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],wger);
+      exit(1);
    }
 
    if((fp_top2=fopen(top2,"w"))==NULL) {
-    fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2);
-    exit(1);
+      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top2);
+      exit(1);
    }
 
    //fscanf(fp_in,"%s%s%s%s%s%s%s%s%s%s",user,nacc,nbytes,url,ip,time,date,elap,incac,oucac);
@@ -426,19 +426,8 @@ void topuser(void)
       }
 
 //      if(UserTabFile[0] != '\0' && strstr(user2,".") != 0) {
-      if(UserTabFile[0] != '\0' && strcmp(user2,"TOTAL") != 0) {
-         sprintf(warea,":%s:",user2);
-         if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
-            z1=0;
-            str2=(char *) strstr(str+1,":");
-            str2++;
-            bzero(name, MAXLEN);
-            while(str2[z1] != ':') {
-               name[z1]=str2[z1];
-               z1++;
-            }
-         } else strcpy(name,user2);
-      } else strcpy(name,user2);
+      if(strcmp(user2,"TOTAL") != 0)
+         get_usertab_name(user2,name,sizeof(name));
 
       if((strcmp(Ip2Name,"yes") == 0) && 
         ((str=(char *) strstr(name, ".")) != (char *) NULL) && 
diff --git a/util.c b/util.c
index 88869a29a294333fe5cbf793839a166f6c7802f4..1b251656ef61930da994c387b61b620fa1dbfd98 100644 (file)
--- a/util.c
+++ b/util.c
@@ -439,13 +439,13 @@ void fixip(char *ip)
 {
    char n1[MAXLEN], n2[MAXLEN], n3[MAXLEN];
    char wip[MAXLEN];
-   char sep[2]=".";
+   char sep='.';
    int iflag=0;
 
    strcpy(wip,ip);
 
-   if(strstr(ip,".") != 0) {
-      strcpy(sep,"_");
+   if(strchr(ip,'.') != 0) {
+      sep='_';
       iflag++;
    }
 
@@ -460,8 +460,7 @@ void fixip(char *ip)
          exit(1);
       }
    }
-   ip[0]='\0';
-   sprintf(ip,"%s%s%s%s%s%s%s",n1,sep,n2,sep,n3,sep,wip);
+   sprintf(ip,"%s%c%s%c%s%c%s",n1,sep,n2,sep,n3,sep,wip);
 
 }
 
@@ -1419,3 +1418,79 @@ char *get_param_value(const char *param,char *line)
    while (*line==' ' || *line=='\t') line++;
    return(line);
 }
+
+void read_usertab(const char *UserTabFile)
+{
+   FILE *fp_usr;
+   unsigned int nreg;
+   char buf[MAXLEN];
+   char bufy[MAXLEN];
+   int z2;
+   int z1;
+
+   if (UserTabFile[0] != '\0') {
+      if(debug) {
+         sprintf(msg,"%s: %s",text[86],UserTabFile);
+         debuga(msg);
+      }
+      if((fp_usr=fopen(UserTabFile,"r"))==NULL) {
+         fprintf(stderr, "SARG: (log) %s: %s - %s\n",text[45],UserTabFile,strerror(errno));
+         exit(1);
+      }
+      fseek(fp_usr, 0, SEEK_END);
+      nreg = ftell(fp_usr)+100;
+      fseek(fp_usr, 0, SEEK_SET);
+      if((userfile=(char *) malloc(nreg))==NULL){
+         fprintf(stderr, "SARG ERROR: %s",text[87]);
+         exit(1);
+      }
+      strcpy(userfile,":");
+      z2=1;
+      while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
+         if (buf[0]=='#') continue;
+         buf[strlen(buf)-1]='\0';
+         if(strstr(buf,"\r") != 0) buf[strlen(buf)-1]='\0';
+         if (getword_multisep(bufy,sizeof(bufy),buf,' ')<0) {
+            printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile);
+            exit(1);
+         }
+         if (z2+strlen(bufy)+strlen(buf)+3>=nreg) {
+            printf("SARG: The list of the users is too long in your %s file.\n",UserTabFile);
+            exit(1);
+         }
+         for(z1=0; bufy[z1]; z1++)
+            userfile[z2++]=bufy[z1];
+         userfile[z2++]='|';
+         for(z1=0; buf[z1]; z1++)
+            userfile[z2++]=buf[z1];
+         userfile[z2++]=':';
+      }
+      userfile[z2]=0;
+      fclose(fp_usr);
+   }
+}
+
+void get_usertab_name(const char *user,char *name,int namelen)
+{
+   char warea[MAXLEN];
+   char *str;
+
+   namelen--;
+   if(UserTabFile[0] == '\0') {
+      strncpy(name,user,namelen);
+      name[namelen]=0;
+   } else {
+      sprintf(warea,":%s|",user);
+      if((str=(char *) strstr(userfile,warea)) == (char *) NULL ) {
+         strncpy(name,user,namelen);
+         name[namelen]=0;
+      } else {
+         str=strchr(str+1,'|');
+         str++;
+         for(z1=0; *str != ':' && z1<namelen ; z1++) {
+            name[z1]=*str++;
+         }
+         name[z1]=0;
+      }
+   }
+}