]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Output the period as an HTML text in the HTML reports
[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 buf[MAXLEN];
38 char data[20];
39 char odata[20];
40 char hour[20];
41 char html[8000];
42 char arqout[MAXLEN];
43 char wdirname[MAXLEN];
44 char c[ 24 ][20];
45 int count=0;
46 int ihour=0;
47 long long int elap;
48 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
49 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
50 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
51 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
52 long long int tt=0, ttt=0;
53 int i;
54 struct getwordstruct gwarea;
55
56 if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
57 debuga(_("Output file name too long: %s/%s/d%s.html\n"),outdirname,uinfo->filename,uinfo->filename);
58 exit(EXIT_FAILURE);
59 }
60 snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
61
62 if(access(wdirname, R_OK) != 0)
63 return;
64
65 if((fp_in=fopen(wdirname,"r"))==NULL) {
66 debuga(_("(repday) Cannot open log file %s\n"),wdirname);
67 exit(EXIT_FAILURE);
68 }
69
70 if((fp_ou=fopen(arqout,"w"))==NULL) {
71 debuga(_("(repday) Cannot open log file %s\n"),arqout);
72 exit(EXIT_FAILURE);
73 }
74
75 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day report"));
76 close_html_header(fp_ou);
77 fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
78
79 fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",_("Period"),period.html);
80
81 fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",_("User"),uinfo->label);
82
83 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
84 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
85
86 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou);
87
88 fputs( "<tr><td></td>\n", fp_ou );
89
90 if(strcmp(datetimeby,"bytes") == 0)
91 strcpy( html, _("BYTES") );
92 else
93 strcpy( html, "H:M:S" );
94
95 for( i = 0; i < hours.len; i++ )
96 fprintf( fp_ou, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours.list[ i ], html );
97 fprintf( fp_ou,
98 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html );
99
100 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
101 fixendofline(buf);
102 getword_start(&gwarea,buf);
103 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
104 debuga(_("There is a broken date in file %s\n"),wdirname);
105 exit(EXIT_FAILURE);
106 }
107 if(!count) {
108 strcpy(odata,data);
109 count++;
110 }
111
112 if (getword(hour,sizeof(hour),&gwarea,'\t')<0) {
113 debuga(_("There is a broken time in file %s\n"),wdirname);
114 exit(EXIT_FAILURE);
115 }
116 if (getword_atoll(&elap,&gwarea,'\t')<0) {
117 debuga(_("There is a broken quantity in file %s\n"),wdirname);
118 exit(EXIT_FAILURE);
119 }
120
121 if(strcmp(data,odata) != 0) {
122 for( i = 0; i < hours.len; i++ )
123 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
124
125 for( i = 8; i <= 17; i++ )
126 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
127 bzero(c[ hours.list[ i ] ],12);
128
129 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata );
130 for( i = 0; i < hours.len; i++ )
131 fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
132 fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) );
133
134 tt=0;
135 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
136 strcpy(odata,data);
137 }
138
139 ihour=atoi(hour);
140
141 v[ ihour ]+=elap;
142 tt+=elap;
143 t[ ihour ]+=elap;
144 ttt+=elap;
145
146 }
147 fclose(fp_in);
148
149 for( i = 0; i < hours.len; i++ )
150 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
151
152 for( i = 0; i < hours.len; i++ )
153 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
154
155 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
156 for( i = 0; i < hours.len; i++ )
157 fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
158 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
159
160 for( i = 0; i < hours.len; i++ )
161 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
162
163 fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
164 for( i = 0; i < hours.len; i++ )
165 fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n", c[ hours.list[ i ] ] );
166 fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n", fixtime(ttt) );
167
168 fputs("</table>\n",fp_ou);
169 if (write_html_trailer(fp_ou)<0)
170 debuga(_("Write error in file %s\n"),arqout);
171 if (fclose(fp_ou)==EOF)
172 debuga(_("Failed to close file %s - %s\n"),arqout,strerror(errno));
173 return;
174 }