]>
git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
3855fc29d47b8953f7b883423b1c2714ffbfd848
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
32 void report_day(const struct userinfostruct
*uinfo
)
43 char wdirname
[MAXLEN
];
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;
54 struct getwordstruct gwarea
;
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
);
60 snprintf(wdirname
,sizeof(wdirname
),"%s/%s.day",tmp
,uinfo
->filename
);
62 if(access(wdirname
, R_OK
) != 0)
65 if((fp_in
=fopen(wdirname
,"r"))==NULL
) {
66 debuga(_("(repday) Cannot open log file %s\n"),wdirname
);
70 if((fp_ou
=fopen(arqout
,"w"))==NULL
) {
71 debuga(_("(repday) Cannot open log file %s\n"),arqout
);
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
);
79 fprintf(fp_ou
,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",_("Period"),period
.html
);
81 fprintf(fp_ou
,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",_("User"),uinfo
->label
);
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
);
86 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou
);
88 fputs( "<tr><td></td>\n", fp_ou
);
90 if(strcmp(datetimeby
,"bytes") == 0)
91 strcpy( html
, _("BYTES") );
93 strcpy( html
, "H:M:S" );
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
);
98 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html
);
100 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
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
);
112 if (getword(hour
,sizeof(hour
),&gwarea
,'\t')<0) {
113 debuga(_("There is a broken time in file %s\n"),wdirname
);
116 if (getword_atoll(&elap
,&gwarea
,'\t')<0) {
117 debuga(_("There is a broken quantity in file %s\n"),wdirname
);
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
] ]));
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);
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
) );
135 for( i
= 0; i
< hours
.len
; i
++ ) v
[ hours
.list
[ i
] ]=0;
149 for( i
= 0; i
< hours
.len
; i
++ )
150 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
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);
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
) );
160 for( i
= 0; i
< hours
.len
; i
++ )
161 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(t
[ hours
.list
[ i
] ]));
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
) );
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
));