]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - siteuser.c
Fix HTML output
[thirdparty/sarg.git] / siteuser.c
index b486c9f8703817b488051bf369d863fce887cabe..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));
@@ -91,32 +94,32 @@ void siteuser(void)
    fprintf(fp_ou, "<!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_ou);
    fputs("</head>\n",fp_ou);
-   if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
-   fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
-   if(strlen(LogoImage) > 0) fprintf(fp_ou, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
+   //if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=\"%s\">\n",FontFace);
+   fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
+   write_logo_image(fp_ou);
 
    if(strcmp(IndexTree,"date") == 0)
       show_sarg(fp_ou, "../../..");
    else
       show_sarg(fp_ou, "..");
 
-   fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
+   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
    fprintf(fp_ou,"<tr><th class=\"title\">%s</th></tr>\n",Title);
 
    fprintf(fp_ou,"<tr><td class=\"header3\">%s: %s</td></tr>\n",text[89],period);
    fprintf(fp_ou,"<tr><th class=\"header3\">%s</th></tr>\n",text[85]);
-   fputs("</table></center>\n",fp_ou);
+   fputs("</table></div>\n",fp_ou);
 
-   fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou);
+   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,30 +155,30 @@ 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++;
       }
-      
+
       sprintf(wuser," %s ",name);
       if(strstr(users,wuser) == 0 && strcmp(url,ourl) == 0) {
          strcat(users,name);
@@ -191,38 +195,37 @@ void siteuser(void)
             continue;
       }
 
-      if(strlen(BlockIt) > 0)
+      if(BlockIt[0]!='\0')
          sprintf(BlockImage,"<a href=\"%s%s?url=%s\"><img src=\"../images/sarg-squidguard-block.png\" border=\"0\"></a>&nbsp;",wwwDocumentRoot,BlockIt,ourl);
       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));
-            fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">%s<a href=\"http://%s\">%s</td><td class=\"data\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,wwork2,users);
+         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</td><td class=\"data2\">%s</td></tr>\n",regs,BlockImage,ourl,ourl,users);
+            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);
          regs++;
          ucount=0;
          strcpy(users,name);
          strcat(users," ");
          strcpy(ourl,url);
-         strcpy(obytes,nbytes);
+         obytes=nbytes;
       }
    }
 
    if(nsitesusers) {
-      fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://%s\">%s</td><td class=\"data2\">%s</td></tr>\n",regs,ourl,ourl,users);
+      fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\"><a href=\"http://%s\">%s</a></td><td class=\"data2\">%s</td></tr>\n",regs,ourl,ourl,users);
    }
 
    unlink(general2);
 
-   fputs("</table></center>\n",fp_ou);
+   fputs("</table>\n</div>\n",fp_ou);
 
    show_info(fp_ou);
 
    fputs("</body>\n</html>\n",fp_ou);
-   
+
    fclose(fp_in);
    fclose(fp_ou);