]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Catch up with the patches from version 2.3.1
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 18 Sep 2010 12:39:21 +0000 (12:39 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sat, 18 Sep 2010 12:39:21 +0000 (12:39 +0000)
This patch failed to apply from branch 2.3 and was applied afterward.

useragent.c

index b47bfced4973bb79718839403f720e9738f1a789..a26bce5fa841f2aee45e5979c57f822e1ad30ae3 100644 (file)
@@ -59,8 +59,8 @@ void useragent(void)
    ipbefore[0]='\0';
    namebefore[0]='\0';
 
-   sprintf(tmp3,"%s/squagent.unsort",TempDir);
-   sprintf(tmp2,"%s/squagent.log",TempDir);
+   sprintf(tmp3,"%s/squagent.unsort",tmp);
+   sprintf(tmp2,"%s/squagent.log",tmp);
 
    if((fp_in=fopen(UserAgentLog,"r"))==NULL) {
       debuga(_("(useragent) Cannot open file %s\n"),UserAgentLog);
@@ -101,25 +101,21 @@ void useragent(void)
          debuga(_("Maybe you have a broken useragent entry in your %s file\n"),UserAgentLog);
          exit(EXIT_FAILURE);
       }
-      strcpy(warea,agent);
-      strup(warea);
-      if(strstr(warea,"SCRIPT") != 0 || strstr(warea,"ONLOAD") != 0)
-         baddata();
 
       if(gwarea.current[0]!='\0') {
          if (getword_skip(MAXLEN,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,'\n')<0) {
             debuga(_("Maybe you have a broken record or garbage in your %s file\n"),UserAgentLog);
             exit(EXIT_FAILURE);
          }
-      }
-
-      if(user[0] == '-')
-         strcpy(user,ip);
-      if(user[0] == '\0')
+         if(user[0] == '-')
+            strcpy(user,ip);
+         if(user[0] == '\0')
+            strcpy(user,ip);
+      } else {
          strcpy(user,ip);
+      }
 
       fprintf(fp_ou,"%s\t%s\t%s\n",ip,agent,user);
-      user[0]='\0';
       useragent_count++;
    }
 
@@ -128,7 +124,10 @@ void useragent(void)
    }
 
    fclose(fp_in);
-   fclose(fp_ou);
+   if (fclose(fp_ou)==EOF) {
+      debuga(_("Failed to close file %s - %s\n"),tmp3,strerror(errno));
+      exit(EXIT_FAILURE);
+   }
 
    if(debug) {
       debuga(_("Sorting file: %s\n"),tmp2);
@@ -195,14 +194,16 @@ void useragent(void)
       }
 
       if(strcmp(user,user_old) != 0) {
-         fprintf(fp_ht,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td></tr>\n",user,agent);
+         fprintf(fp_ht,"<tr><td class=\"data2\">%s</td><td class=\"data2\">",user);
+         output_html_string(fp_ht,agent,250);
+         fputs("</td></tr>\n",fp_ht);
          strcpy(user_old,user);
          strcpy(agent_old,agent);
-      } else {
-         if(strcmp(agent,agent_old) != 0) {
-            fprintf(fp_ht,"<tr><td></td><td class=\"data2\">%s</td></tr>\n",agent);
-            strcpy(agent_old,agent);
-         }
+      } else if(strcmp(agent,agent_old) != 0) {
+         fputs("<tr><td></td><td class=\"data2\">",fp_ht);
+         output_html_string(fp_ht,agent,250);
+         fputs("</td></tr>\n",fp_ht);
+         strcpy(agent_old,agent);
       }
    }
 
@@ -235,11 +236,11 @@ void useragent(void)
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       getword_start(&gwarea,buf);
       if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-         debuga(_("There is an invalid IP address in file %s\n"),tmp);
+         debuga(_("There is an invalid IP address in file %s\n"),tmp3);
          exit(EXIT_FAILURE);
       }
       if (getword(agent,sizeof(agent),&gwarea,'\t')<0) {
-         debuga(_("There is an invalid useragent in file %s\n"),tmp);
+         debuga(_("There is an invalid useragent in file %s\n"),tmp3);
          exit(EXIT_FAILURE);
       }
 
@@ -262,7 +263,10 @@ void useragent(void)
    agentot2+=agentot;
 
    fclose(fp_in);
-   fclose(fp_ou);
+   if (fclose(fp_ou)==EOF) {
+      debuga(_("Failed to close file %s - %s\n"),tmp3,strerror(errno));
+      exit(EXIT_FAILURE);
+   }
 
    unlink(tmp3);
 
@@ -291,13 +295,15 @@ void useragent(void)
       fixendofline(buf);
       getword_start(&gwarea,buf);
       if (getword(tagent,sizeof(tagent),&gwarea,' ')<0) {
-         debuga(_("There is an invalid useragent in file %s\n"),tmp);
+         debuga(_("There is an invalid useragent in file %s\n"),tmp3);
          exit(EXIT_FAILURE);
       }
       nagent=atoi(tagent);
       perc=(agentot2>0) ? nagent * 100. / agentot2 : 0.;
 
-      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("<tr><td class=\"data2\">",fp_ht);
+      output_html_string(fp_ht,gwarea.current,250);
+      fprintf(fp_ht,"</td><td class=\"data\">%d</td><td class=\"data\">%3.2lf</td></tr>\n",nagent,perc);
    }
    fclose(fp_in);