]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - useragent.c
Fix wrong tags label.
[thirdparty/sarg.git] / useragent.c
index 42d67d3814a53ba776f9470e893c6cfa6a52bad8..b47bfced4973bb79718839403f720e9738f1a789 100644 (file)
@@ -31,6 +31,7 @@ void useragent(void)
 {
 
    FILE *fp_in = NULL, *fp_ou = NULL, *fp_ht = NULL;
+   char buf[MAXLEN];
    char ip[MAXLEN], data[MAXLEN], agent[MAXLEN], user[MAXLEN];
    char ipbefore[MAXLEN], namebefore[MAXLEN];
    char tagent[MAXLEN];
@@ -62,13 +63,13 @@ void useragent(void)
    sprintf(tmp2,"%s/squagent.log",TempDir);
 
    if((fp_in=fopen(UserAgentLog,"r"))==NULL) {
-      debuga(_("(useragent) Cannot open file: %s\n"),UserAgentLog);
-      exit(1);
+      debuga(_("(useragent) Cannot open file %s\n"),UserAgentLog);
+      exit(EXIT_FAILURE);
    }
 
    if((fp_ou=fopen(tmp3,"w"))==NULL) {
-      debuga(_("(email) Cannot open file: %s\n"),tmp3);
-      exit(1);
+      debuga(_("(useragent) Cannot open file %s\n"),tmp3);
+      exit(EXIT_FAILURE);
    }
 
    if(debug) {
@@ -80,14 +81,14 @@ void useragent(void)
       getword_start(&gwarea,buf);
       if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
           getword(data,sizeof(data),&gwarea,' ')<0) {
-         debuga(_("Maybe you have a broken record or garbage in your %s file.\n"),UserAgentLog);
-         exit(1);
+         debuga(_("Maybe you have a broken record or garbage in your %s file\n"),UserAgentLog);
+         exit(EXIT_FAILURE);
       }
       getword_start(&gwarea1,data);
       if (getword(day,sizeof(day),&gwarea1,'/')<0 || getword(month,sizeof(month),&gwarea1,'/')<0 ||
           getword(year,sizeof(year),&gwarea1,':')<0) {
-         debuga(_("Maybe you have a broken date in your %s file.\n"),UserAgentLog);
-         exit(1);
+         debuga(_("Maybe you have a broken date in your %s file\n"),UserAgentLog);
+         exit(EXIT_FAILURE);
       }
       buildymd(day,month,year,wdate);
       ndate=atoi(wdate);
@@ -97,8 +98,8 @@ void useragent(void)
          strcpy(idate,data);
       strcpy(fdate,data);
       if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
-         debuga(_("Maybe you have a broken useragent entry in your %s file.\n"),UserAgentLog);
-         exit(1);
+         debuga(_("Maybe you have a broken useragent entry in your %s file\n"),UserAgentLog);
+         exit(EXIT_FAILURE);
       }
       strcpy(warea,agent);
       strup(warea);
@@ -107,8 +108,8 @@ void useragent(void)
 
       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(1);
+            debuga(_("Maybe you have a broken record or garbage in your %s file\n"),UserAgentLog);
+            exit(EXIT_FAILURE);
          }
       }
 
@@ -138,20 +139,20 @@ void useragent(void)
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
       debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
    if((fp_in=fopen(tmp2,"r"))==NULL) {
-      debuga(_("(useragent) Cannot open file: %s\n"),tmp2);
+      debuga(_("(useragent) Cannot open file %s\n"),tmp2);
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
 
    unlink(tmp3);
 
    snprintf(hfile,sizeof(hfile),"%s/useragent.html", outdirname);
    if((fp_ht=fopen(hfile,"w"))==NULL) {
-      debuga(_("(useragent) Cannot open file: %s\n"),hfile);
-      exit(1);
+      debuga(_("(useragent) Cannot open file %s\n"),hfile);
+      exit(EXIT_FAILURE);
    }
 
    if(debug)
@@ -173,7 +174,7 @@ void useragent(void)
       getword_start(&gwarea,buf);
       if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          debuga(_("There is an invalid IP address in file %s\n"),tmp2);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
 
       if(Ip2Name) {
@@ -186,11 +187,11 @@ void useragent(void)
 
       if (getword(agent,sizeof(agent),&gwarea,'\t')<0) {
          debuga(_("There is an invalid useragent in file %s\n"),tmp2);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
       if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          debuga(_("There is an invalid user ID in file %s\n"),tmp2);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
 
       if(strcmp(user,user_old) != 0) {
@@ -213,19 +214,19 @@ void useragent(void)
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
       debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
    if((fp_in=fopen(tmp3,"r"))==NULL) {
-      debuga(_("(useragent) Cannot open file: %s\n"),tmp3);
+      debuga(_("(useragent) Cannot open file %s\n"),tmp3);
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
 
    unlink(tmp2);
 
    if((fp_ou=fopen(tmp2,"w"))==NULL) {
-      debuga(_("SARG: (useragent) Cannot open file: %s\n"),tmp2);
-      exit(1);
+      debuga(_("(useragent) Cannot open file %s\n"),tmp2);
+      exit(EXIT_FAILURE);
    }
 
    agent_old[0]='\0';
@@ -235,11 +236,11 @@ void useragent(void)
       getword_start(&gwarea,buf);
       if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
          debuga(_("There is an invalid IP address in file %s\n"),tmp);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
       if (getword(agent,sizeof(agent),&gwarea,'\t')<0) {
          debuga(_("There is an invalid useragent in file %s\n"),tmp);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
 
       if(!cont) {
@@ -270,12 +271,12 @@ void useragent(void)
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
       debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
    if((fp_in=fopen(tmp3,"r"))==NULL) {
-      debuga(_("(useragent) Cannot open file: %s\n"),tmp3);
+      debuga(_("(useragent) Cannot open file %s\n"),tmp3);
       debuga(_("sort command: %s\n"),csort);
-      exit(1);
+      exit(EXIT_FAILURE);
    }
 
    unlink(tmp2);
@@ -291,7 +292,7 @@ void useragent(void)
       getword_start(&gwarea,buf);
       if (getword(tagent,sizeof(tagent),&gwarea,' ')<0) {
          debuga(_("There is an invalid useragent in file %s\n"),tmp);
-         exit(1);
+         exit(EXIT_FAILURE);
       }
       nagent=atoi(tagent);
       perc=(agentot2>0) ? nagent * 100. / agentot2 : 0.;
@@ -301,8 +302,10 @@ void useragent(void)
    fclose(fp_in);
 
    fputs("</table></div>\n",fp_ht);
-   write_html_trailer(fp_ht);
-   fclose(fp_ht);
+   if (write_html_trailer(fp_ht)<0)
+      debuga(_("Write error in file %s\n"),hfile);
+   if (fclose(fp_ht)==EOF)
+      debuga(_("Failed to close file %s - %s\n"),hfile,strerror(errno));
 
    unlink(tmp3);