]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - repday.c
Append \n at the end of every debuga
[thirdparty/sarg.git] / repday.c
index 4f9de4f86cec24ca12a6cb9fa6164e1dc32c5785..4e032eb0b5ef7eab6b3bd8f7e80d472043592ae1 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -1,10 +1,11 @@
 /*
- * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
- *                                                            1998, 2010
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
+ *                                                            1998, 2010
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ *     http://sourceforge.net/projects/sarg/forums/forum/363374
  * ---------------------------------------------------------------------
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -28,7 +29,7 @@
 
 extern numlist hours;
 
-void report_day(const char *user)
+void report_day(const struct userinfostruct *uinfo)
 {
 
    FILE *fp_in, *fp_ou;
@@ -39,7 +40,6 @@ void report_day(const char *user)
    char html[8000];
    char arqout[MAXLEN];
    char wdirname[MAXLEN];
-   char wuser[255];
    char c[ 24 ][20];
    int  count=0;
    int  ihour=0;
@@ -52,82 +52,55 @@ void report_day(const char *user)
    int i;
    struct getwordstruct gwarea;
 
-   sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
-   sprintf(wdirname,"%s/%s.day",tmp,user);
+   if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
+      debuga(_("Output file name too long: %s/%s/d%s.html\n"),dirname,uinfo->filename,uinfo->filename);
+      exit(1);
+   }
+   snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
 
    if(access(wdirname, R_OK) != 0)
       return;
 
    if((fp_in=fopen(wdirname,"r"))==NULL) {
-     fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
+     fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),wdirname);
      exit(1);
    }
 
    if((fp_ou=fopen(arqout,"w"))==NULL) {
-     fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
+     fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),arqout);
      exit(1);
    }
 
-   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);
-   write_logo_image(fp_ou);
-
-   if(strcmp(IndexTree,"date") == 0)
-      show_sarg(fp_ou, "../../../..");
-   else
-      show_sarg(fp_ou, "../..");
-
-   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
-   fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
-
-   fputs("</table></div>\n",fp_ou);
-   fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
-
-   fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
+   write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day report"));
+   close_html_header(fp_ou);
+   fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
 
-   strcpy(wuser,user);
-   if(strstr(wuser,"_") != 0)
-      fixip(wuser);
-
-   if(Ip2Name)
-      if((str=(char *) strstr(name, ".")) != (char *) NULL) {
-         if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
-            ip2name(wuser,sizeof(wuser));
-   }
+   fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",_("Period"),period);
 
-   get_usertab_name(wuser,name,sizeof(name));
-
-   if(dotinuser && strchr(name,'_')) {
-      subs(name,sizeof(name),"_",".");
-   }
-
-   fprintf(fp_ou,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
+   fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",_("User"),uinfo->label);
 
    fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
    fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
 
-   fputs("<table cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
+   fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
 
    fputs( "<tr><td></td>\n", fp_ou );
 
    if(strcmp(datetimeby,"bytes") == 0)
-     strcpy( html, text[93] );
+     strcpy( html, _("BYTES") );
    else
      strcpy( html, "H:M:S" );
 
    for( i = 0; i < hours.len; i++ )
-     fprintf( fp_ou, "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
+     fprintf( fp_ou, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours.list[ i ], html );
    fprintf( fp_ou,
-     "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
+     "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html );
 
    while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
       fixendofline(buf);
       getword_start(&gwarea,buf);
       if (getword(data,sizeof(data),&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
+         debuga(_("There is a broken date in file %s\n"),wdirname);
          exit(1);
       }
       if(!count) {
@@ -135,8 +108,12 @@ void report_day(const char *user)
          count++;
       }
 
-      if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) {
-         printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
+      if (getword(hour,sizeof(hour),&gwarea,'\t')<0) {
+         debuga(_("There is a broken time in file %s\n"),wdirname);
+         exit(1);
+      }
+      if (getword_atoll(&elap,&gwarea,'\t')<0) {
+         debuga(_("There is a broken quantity in file %s\n"),wdirname);
          exit(1);
       }
 
@@ -166,6 +143,7 @@ void report_day(const char *user)
       ttt+=elap;
 
    }
+   fclose(fp_in);
 
    for( i = 0; i < hours.len; i++ )
      sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
@@ -181,17 +159,13 @@ void report_day(const char *user)
    for( i = 0; i < hours.len; i++ )
      sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
 
-   fprintf(fp_ou, "<tr><td class=\"header\">%s</td>\n", text[107] );
+   fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
    for( i = 0; i < hours.len; i++ )
-     fprintf(fp_ou, "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
-   fprintf(fp_ou, "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
-
-   fputs("</table></div>\n",fp_ou);
+     fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n", c[ hours.list[ i ] ] );
+   fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n", fixtime(ttt) );
 
-   show_info(fp_ou);
-
-   fputs("</body>\n</html>\n",fp_ou);
-   fclose(fp_in);
+   fputs("</table>\n",fp_ou);
+   write_html_trailer(fp_ou);
    fclose(fp_ou);
    return;
 }