]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Automated replacement of the translated strings by a gettext macro
[thirdparty/sarg.git] / repday.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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"
28 #include "include/defs.h"
29
30 extern numlist hours;
31
32 void report_day(const struct userinfostruct *uinfo)
33 {
34
35 FILE *fp_in, *fp_ou;
36
37 char data[20];
38 char odata[20];
39 char hour[20];
40 char html[8000];
41 char arqout[MAXLEN];
42 char wdirname[MAXLEN];
43 char c[ 24 ][20];
44 int count=0;
45 int ihour=0;
46 long long int elap;
47 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
48 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
49 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
50 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
51 long long int tt=0, ttt=0;
52 int i;
53 struct getwordstruct gwarea;
54
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);
60
61 if(access(wdirname, R_OK) != 0)
62 return;
63
64 if((fp_in=fopen(wdirname,"r"))==NULL) {
65 fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),wdirname);
66 exit(1);
67 }
68
69 if((fp_ou=fopen(arqout,"w"))==NULL) {
70 fprintf(stderr, "SARG: (repday) %s: %s\n",_("Cannot open log file"),arqout);
71 exit(1);
72 }
73
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);
77
78 fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",_("Period"),period);
79
80 fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",_("User"),uinfo->label);
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
85 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
86
87 fputs( "<tr><td></td>\n", fp_ou );
88
89 if(strcmp(datetimeby,"bytes") == 0)
90 strcpy( html, _("BYTES") );
91 else
92 strcpy( html, "H:M:S" );
93
94 for( i = 0; i < hours.len; i++ )
95 fprintf( fp_ou, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours.list[ i ], html );
96 fprintf( fp_ou,
97 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html );
98
99 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
100 fixendofline(buf);
101 getword_start(&gwarea,buf);
102 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
103 debuga(_("There is a broken date in file %s"),wdirname);
104 exit(1);
105 }
106 if(!count) {
107 strcpy(odata,data);
108 count++;
109 }
110
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);
117 exit(1);
118 }
119
120 if(strcmp(data,odata) != 0) {
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
133 tt=0;
134 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
135 strcpy(odata,data);
136 }
137
138 ihour=atoi(hour);
139
140 v[ ihour ]+=elap;
141 tt+=elap;
142 t[ ihour ]+=elap;
143 ttt+=elap;
144
145 }
146 fclose(fp_in);
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);
153
154 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
155 for( i = 0; i < hours.len; i++ )
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) );
158
159 for( i = 0; i < hours.len; i++ )
160 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
161
162 fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
163 for( i = 0; i < hours.len; i++ )
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) );
166
167 fputs("</table>\n",fp_ou);
168 write_html_trailer(fp_ou);
169 fclose(fp_ou);
170 return;
171 }