]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - siteuser.c
Fix HTML output
[thirdparty/sarg.git] / siteuser.c
index 79a229aa46174b82d2392dc971e69e89928ce358..f6a69e624462cc20aa7e83a7ba6c153df8d8d818 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
- *                                                            1998, 2008
+ *                                                            1998, 2010
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
  *
  * SARG donations:
@@ -35,9 +35,6 @@ void siteuser(void)
    char url[MAXLEN];
    char wuser[MAXLEN];
    char ourl[MAXLEN];
-   char nacc[20];
-   char nbytes[20];
-   char obytes[20];
    char csort[255];
    char general[MAXLEN];
    char general2[MAXLEN];
@@ -48,10 +45,13 @@ void siteuser(void)
    int regs=0;
    int ucount=0;
    char *users;
-   long long int llbytes=0;
+   long long int nbytes;
+   long long int obytes;
+   long long int nacc;
    int cstatus;
+   struct getwordstruct gwarea;
 
-   if(strcmp(Privacy,"yes") == 0)
+   if(Privacy)
       return;
 
    nsitesusers = 0;
@@ -62,14 +62,17 @@ void siteuser(void)
    sprintf(report,"%s/siteuser.html",dirname);
 
    if ((fp_in = fopen(per, "r")) == 0) {
-      fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],per);
+      fprintf(stderr, "SARG: (siteuser) %s: %s\n",text[45],per);
       exit(1);
    }
 
-   fgets(period,sizeof(period),fp_in);
+   if (!fgets(period,sizeof(period),fp_in)) {
+      fprintf(stderr,"SARG: (siteuser) read error in %s\n",per);
+      exit(1);
+   }
    fclose(fp_in);
 
-   sprintf(csort,"sort -k 4,4 -k 1,1 -o '%s' '%s'",general2,general);
+   sprintf(csort,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general);
    cstatus=system(csort);
    if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
       fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
@@ -109,14 +112,14 @@ void siteuser(void)
 
    fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_ou);
    fputs("<tr><td></td></tr>\n",fp_ou);
-   if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0)
+   if(BytesInSitesUsersReport)
       fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[100],text[91],text[93],text[103]);
    else
       fprintf(fp_ou,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[100],text[91],text[103]);
 
    user[0]='\0';
    ourl[0]='\0';
-   obytes[0]='\0';
+   obytes=0;
 
    if((users=(char *) malloc(204800))==NULL){
       fprintf(stderr, "SARG: ERROR: %s",text[87]);
@@ -125,7 +128,8 @@ void siteuser(void)
    strcpy(users," ");
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
-      if (getword(user,sizeof(user),buf,' ')<0) {
+      getword_start(&gwarea,buf);
+      if (getword(user,sizeof(user),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid user in the %s file of the siteuser.\n",general2);
          exit(1);
       }
@@ -142,7 +146,7 @@ void siteuser(void)
 
       /*
       In fact, even the first call is unecessary as the resolved user variable is never used.
-      if(strcmp(Ip2Name,"yes") == 0)
+      if(Ip2Name)
          ip2name(user,sizeof(user));
       */
 
@@ -151,27 +155,27 @@ void siteuser(void)
       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)
+      if(Ip2Name)
          ip2name(user,sizeof(user));
       */
 
-      if (getword(nacc,sizeof(nacc),buf,' ')<0){
+      if (getword_atoll(&nacc,&gwarea,'\t')<0){
          printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2);
          exit(1);
       }
-      if (atoi(nacc) > 0) nsitesusers = 1;
-      if (getword(nbytes,sizeof(nbytes),buf,' ')<0){
+      if (nacc > 0) nsitesusers = 1;
+      if (getword_atoll(&nbytes,&gwarea,'\t')<0){
          printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2);
          exit(1);
       }
-      if (getword(url,sizeof(url),buf,' ')<0) {
+      if (getword(url,sizeof(url),&gwarea,'\t')<0) {
          printf("SARG: Maybe you have an invalid url in your %s file of the siteuser.\n",general2);
          exit(1);
       }
 
       if(!regs) {
          strcpy(ourl,url);
-         strcpy(obytes,nbytes);
+         obytes=nbytes;
          regs++;
       }
 
@@ -196,9 +200,8 @@ void siteuser(void)
       else BlockImage[0]='\0';
 
       if(strcmp(url,ourl) != 0 && nsitesusers) {
-         if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0) {
-            llbytes=my_atoll(obytes);
-            sprintf(wwork2,"%s",fixnum(llbytes,1));
+         if(BytesInSitesUsersReport) {
+            sprintf(wwork2,"%s",fixnum(obytes,1));
             fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,wwork2,users);
          } else
             fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
@@ -207,7 +210,7 @@ void siteuser(void)
          strcpy(users,name);
          strcat(users," ");
          strcpy(ourl,url);
-         strcpy(obytes,nbytes);
+         obytes=nbytes;
       }
    }