]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fixed bug #2940124 (useragent report ignoring date range)
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 2 Feb 2010 13:10:32 +0000 (13:10 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 2 Feb 2010 13:10:32 +0000 (13:10 +0000)
ChangeLog
useragent.c

index d5dcf03bbc6609d50f965cf7f1c3170b55efac15..40ef29c0f80690ed4aecda970cdebc9da438fc3d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,12 @@
 SARG ChangeLog
 
-Jan-27-2009 Version 2.3
+Feb-02-2009 Version 2.3
                - LDAP usertab added. 
                  Now you can have your users in a LDAP Server.
                  Use these tags in sarg.conf: LDAPHost, LDAPPort, LDAPBindDN, LDAPBindPW,
                                               LDAPBaseSearch, LDAPFilterSearch
                - Parse the string flags from sarg.conf once during the reading of sarg.conf instead of manipulating and duplicating the tests of the strings where they are used.
+               - Useragent report limited to requested date range.
 
 Jan-29-2010 Version 2.2.7
                - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure.
index e2cb0529d6058e299d6575c4f8058af168ab441f..2735a7c2ce2d4453b494e82509c5fcfb1913b604 100644 (file)
@@ -39,11 +39,13 @@ void useragent(void)
    char hfile[MAXLEN];
    char idate[MAXLEN], fdate[MAXLEN];
    char tmp2[MAXLEN];
+   char day[4],month[5],year[5], wdate[20];
    int  agentot=0, agentot2=0, agentdif=0, cont=0, nagent;
    unsigned long totregsl=0;
    int cstatus;
-   char ftime[128];
-   struct getwordstruct gwarea;
+   int ndate;
+   double perc;
+   struct getwordstruct gwarea, gwarea1;
 
    ip[0]='\0';
    data[0]='\0';
@@ -79,10 +81,20 @@ void useragent(void)
          printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
          exit(1);
       }
+      getword_start(&gwarea1,data);
+      if (getword(day,sizeof(day),&gwarea1,'/')<0 || getword(month,sizeof(month),&gwarea1,'/')<0 ||
+          getword(year,sizeof(year),&gwarea1,':')<0) {
+         printf("SARG: Maybe you have a broken date in your %s file.\n",UserAgentLog);
+         exit(1);
+      }
+      buildymd(day,month,year,wdate);
+      ndate=atoi(wdate);
+      if (ndate<dfrom || ndate>duntil) continue;
       if(totregsl == 1)
          strcpy(idate,data);
+      strcpy(fdate,data);
       if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserAgentLog);
+         printf("SARG: Maybe you have a broken useragent entry in your %s file.\n",UserAgentLog);
          exit(1);
       }
       strcpy(warea,agent);
@@ -106,8 +118,6 @@ void useragent(void)
       user[0]='\0';
    }
 
-   strcpy(fdate,data);
-
    if(debug) {
       debuga("   %s: %ld",text[10],totregsl);
    }
@@ -146,8 +156,7 @@ void useragent(void)
    fprintf(fp_ht, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
    css(fp_ht);
    fputs("</head>\n",fp_ht);
-   //if(FontFace[0] != '\0') fprintf(fp_ht,"<font face=\"%s\">\n",FontFace);
-   fprintf(fp_ht,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
+   fputs("<body class=\"body\">\n",fp_ht);
    write_logo_image(fp_ht);
 
    if(IndexTree == INDEX_TREE_DATE)
@@ -155,20 +164,17 @@ void useragent(void)
    else
       show_sarg(fp_ht,"..");
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ht);
-   fprintf(fp_ht,"<tr><th align=\"center\" colspan=\"2\"><b><font color=\"%s\" size=\"+1\">%s</font></b></th></tr>\n",TiColor,text[105]);
-
-   fputs("<tr><td></td></tr><tr><td></td></tr>",fp_ht);
+   fprintf(fp_ht,"<tr><th class=\"title\">%s</th></tr>\n",text[105]);
+   fprintf(fp_ht,"<tr><td class=\"header3\">%s: %s - %s</td></tr>\n",text[89],idate,fdate);
    fputs("</table></div>\n",fp_ht);
 
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ht);
 
-   fprintf(fp_ht,"<tr><td align=\"right\" bgcolor=\"%s\">%s:<td align=\"left\" bgcolor=\"%s\">%s - %s</td></td></tr>\n",HeaderBgColor,text[89],TxBgColor,idate,fdate);
-
    fputs("</table></div>\n",fp_ht);
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ht);
-   fputs("<tr><td></td><td></td></tr>",fp_ht);
+   fputs("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>",fp_ht);
 
-   fprintf(fp_ou,"<tr><th align=\"left\" bgcolor=\"%s\"><font color=\"%s\">%s</font></th><th bgcolor=\"%s\" align=\"left\"><font color=\"%s\">%s</font></th></tr>\n",HeaderBgColor,HeaderColor,text[98],HeaderBgColor,HeaderColor,text[106]);
+   fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[98],text[106]);
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       getword_start(&gwarea,buf);
@@ -192,12 +198,12 @@ void useragent(void)
       }
 
       if(strcmp(user,user_old) != 0) {
-         fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"left\" bgcolor=\"%s\">%s</td></tr>\n",TxBgColor,user,TxBgColor,agent);
+         fprintf(fp_ht,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td></tr>\n",user,agent);
          strcpy(user_old,user);
          strcpy(agent_old,agent);
       } else {
          if(strcmp(agent,agent_old) != 0) {
-            fprintf(fp_ht,"<tr><td></td><td align=\"left\" bgcolor=\"%s\">%s</td></tr>\n",TxBgColor,agent);
+            fprintf(fp_ht,"<tr><td></td><td class=\"data2\">%s</td></tr>\n",agent);
             strcpy(agent_old,agent);
          }
       }
@@ -281,10 +287,10 @@ void useragent(void)
       exit(1);
    }
 
-   fputs("<br><br>\n",fp_ht);
+   fputs("<br/><br/>\n",fp_ht);
 
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ht);
-   fprintf(fp_ht,"<tr><th align=\"left\" bgcolor=\"%s\"><font color=\"%s\">%s</font></th><th bgcolor=\"%s\" align=\"left\"><font color=\"%s\">%s</font></th><th align=\"center\" bgcolor=\"%s\"><font color=\"%s\">%%</font></th></tr>\n",HeaderBgColor,HeaderColor,text[106],HeaderBgColor,HeaderColor,text[107],HeaderBgColor,HeaderColor);
+   fprintf(fp_ht,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header3\">%%</th></tr>\n",text[106],text[107]);
 
    perc=0.;
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
@@ -295,19 +301,13 @@ void useragent(void)
          exit(1);
       }
       nagent=atoi(tagent);
-      if(agentot2>0) {
-         perc=nagent * 100;
-         perc=perc / agentot2;
-      }
+      perc=(agentot2>0) ? nagent * 100. / agentot2 : 0.;
 
-      fprintf(fp_ht,"<tr><td align=\"left\" bgcolor=\"%s\">%s</td><td align=\"right\" bgcolor=\"%s\">%d</td><td align=\"right\" bgcolor=\"%s\">%3.2f</td></tr>\n",TxBgColor,gwarea.current,TxBgColor,nagent,TxBgColor,perc);
+      fprintf(fp_ht,"<tr><td class=\"data2\">%s</td><td class=\"data\">%d</td><td class=\"data\">%3.2lf</td></tr>\n",gwarea.current,nagent,perc);
    }
 
    fputs("</table></html>\n",fp_ht);
-   if(ShowSargInfo) {
-      zdate(ftime, sizeof(ftime), DateFormat);
-      fprintf(fp_ht,"<br><br><div align=\"center\"><font size=\"-2\">%s <a href=\"%s\">%s-%s</a> %s %s</font></div>\n",text[108],URL,PGM,VERSION,text[109],ftime);
-   }
+   show_info(fp_ht);
 
    fputs("</table>\n</body>\n</html>\n",fp_ht);
    fclose(fp_in);