]> git.ipfire.org Git - thirdparty/sarg.git/blame - repday.c
Automated replacement of the translated strings by a gettext macro
[thirdparty/sarg.git] / repday.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35
GS
29
30extern numlist hours;
31
f2ec8c75 32void report_day(const struct userinfostruct *uinfo)
25697a35
GS
33{
34
35 FILE *fp_in, *fp_ou;
36
37 char data[20];
25697a35 38 char odata[20];
d6e703cc 39 char hour[20];
25697a35
GS
40 char html[8000];
41 char arqout[MAXLEN];
42 char wdirname[MAXLEN];
25697a35
GS
43 char c[ 24 ][20];
44 int count=0;
d6e703cc 45 int ihour=0;
6e792ade 46 long long int elap;
120d768c 47 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
25697a35 48 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
120d768c 49 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
25697a35
GS
50 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
51 long long int tt=0, ttt=0;
25697a35 52 int i;
9c7c6346 53 struct getwordstruct gwarea;
25697a35 54
f2ec8c75
FM
55 if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
56 debuga(_("Output file name too long: %s/%s/d%s.html"),dirname,uinfo->filename,uinfo->filename);
57 exit(1);
58 }
59 snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
25697a35
GS
60
61 if(access(wdirname, R_OK) != 0)
62 return;
63
64 if((fp_in=fopen(wdirname,"r"))==NULL) {
c36c7384 65 fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),wdirname);
25697a35
GS
66 exit(1);
67 }
68
69 if((fp_ou=fopen(arqout,"w"))==NULL) {
c36c7384 70 fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),arqout);
25697a35
GS
71 exit(1);
72 }
73
c0ec9cc7
FM
74 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day report"));
75 close_html_header(fp_ou);
76 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
25697a35 77
c36c7384 78 fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",_("Period"),period);
25697a35 79
c36c7384 80 fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",_("User"),uinfo->label);
25697a35
GS
81
82 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
83 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
84
c0ec9cc7 85 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
25697a35 86
dfb337be 87 fputs( "<tr><td></td>\n", fp_ou );
25697a35
GS
88
89 if(strcmp(datetimeby,"bytes") == 0)
c36c7384 90 strcpy( html, _("BYTES") );
25697a35
GS
91 else
92 strcpy( html, "H:M:S" );
93
94 for( i = 0; i < hours.len; i++ )
b18ce4a0 95 fprintf( fp_ou, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours.list[ i ], html );
25697a35 96 fprintf( fp_ou,
c36c7384 97 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html );
25697a35
GS
98
99 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
100 fixendofline(buf);
101 getword_start(&gwarea,buf);
102 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
f2ec8c75 103 debuga(_("There is a broken date in file %s"),wdirname);
4bcb77cf
FM
104 exit(1);
105 }
25697a35
GS
106 if(!count) {
107 strcpy(odata,data);
108 count++;
109 }
110
f2ec8c75
FM
111 if (getword(hour,sizeof(hour),&gwarea,'\t')<0) {
112 debuga(_("There is a broken time in file %s"),wdirname);
113 exit(1);
114 }
115 if (getword_atoll(&elap,&gwarea,'\t')<0) {
116 debuga(_("There is a broken quantity in file %s"),wdirname);
4bcb77cf
FM
117 exit(1);
118 }
25697a35
GS
119
120 if(strcmp(data,odata) != 0) {
dfb337be
FM
121 for( i = 0; i < hours.len; i++ )
122 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
123
124 for( i = 8; i <= 17; i++ )
125 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
126 bzero(c[ hours.list[ i ] ],12);
127
128 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata );
129 for( i = 0; i < hours.len; i++ )
130 fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
131 fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) );
132
25697a35 133 tt=0;
dfb337be 134 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
25697a35 135 strcpy(odata,data);
25697a35
GS
136 }
137
d6e703cc 138 ihour=atoi(hour);
25697a35 139
6e792ade
FM
140 v[ ihour ]+=elap;
141 tt+=elap;
142 t[ ihour ]+=elap;
143 ttt+=elap;
25697a35
GS
144
145 }
c0ec9cc7 146 fclose(fp_in);
25697a35
GS
147
148 for( i = 0; i < hours.len; i++ )
149 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
150
151 for( i = 0; i < hours.len; i++ )
152 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
dfb337be
FM
153
154 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
25697a35 155 for( i = 0; i < hours.len; i++ )
dfb337be
FM
156 fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
157 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
25697a35
GS
158
159 for( i = 0; i < hours.len; i++ )
160 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
161
c36c7384 162 fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
25697a35 163 for( i = 0; i < hours.len; i++ )
b18ce4a0
FM
164 fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n", c[ hours.list[ i ] ] );
165 fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n", fixtime(ttt) );
25697a35 166
c0ec9cc7
FM
167 fputs("</table>\n",fp_ou);
168 write_html_trailer(fp_ou);
25697a35 169 fclose(fp_ou);
25697a35
GS
170 return;
171}