]>
git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
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 fprintf(fp_ou
,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",_("Period"),period
.html
);
77 fprintf(fp_ou
,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",_("User"),uinfo
->label
);
78 close_html_header(fp_ou
);
80 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou
);
82 if(strcmp(datetimeby
,"bytes") == 0)
83 strcpy( html
, _("BYTES") );
85 strcpy( html
, "H:M:S" );
87 for( i
= 0; i
< hours
.len
; i
++ )
88 fprintf( fp_ou
, "<td class=\"header_c\">%02dH<br>%s</td>\n", hours
.list
[ i
], html
);
90 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html
);
92 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
94 getword_start(&gwarea
,buf
);
95 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0) {
96 debuga(_("There is a broken date in file %s\n"),wdirname
);
104 if (getword(hour
,sizeof(hour
),&gwarea
,'\t')<0) {
105 debuga(_("There is a broken time in file %s\n"),wdirname
);
108 if (getword_atoll(&elap
,&gwarea
,'\t')<0) {
109 debuga(_("There is a broken quantity in file %s\n"),wdirname
);
113 if(strcmp(data
,odata
) != 0) {
114 for( i
= 0; i
< hours
.len
; i
++ )
115 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
117 for( i
= 8; i
<= 17; i
++ )
118 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0)
119 bzero(c
[ hours
.list
[ i
] ],12);
121 fprintf(fp_ou
, "<tr><td class=\"data\">%s</td>\n", odata
);
122 for( i
= 0; i
< hours
.len
; i
++ )
123 fprintf(fp_ou
,"<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
124 fprintf( fp_ou
, "<td class=\"data\">%s</td>\n", fixtime(tt
) );
127 for( i
= 0; i
< hours
.len
; i
++ ) v
[ hours
.list
[ i
] ]=0;
141 for( i
= 0; i
< hours
.len
; i
++ )
142 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
144 for( i
= 0; i
< hours
.len
; i
++ )
145 if(strcmp(c
[ hours
.list
[ i
] ],"00:00:00") == 0) bzero(c
[ hours
.list
[ i
] ],12);
147 fprintf(fp_ou
, "<tr><td class=\"data\">%s</td>\n", data
);
148 for( i
= 0; i
< hours
.len
; i
++ )
149 fprintf(fp_ou
, "<td class=\"data\">%s</td>\n", c
[ hours
.list
[ i
] ] );
150 fprintf(fp_ou
, "<td class=\"data\">%s</td></tr>\n", fixtime(tt
) );
152 for( i
= 0; i
< hours
.len
; i
++ )
153 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(t
[ hours
.list
[ i
] ]));
155 fprintf(fp_ou
, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
156 for( i
= 0; i
< hours
.len
; i
++ )
157 fprintf(fp_ou
, "<td class=\"header_r\">%s</td>\n", c
[ hours
.list
[ i
] ] );
158 fprintf(fp_ou
, "<td class=\"header_r\">%s</td></tr>\n", fixtime(ttt
) );
160 fputs("</table>\n",fp_ou
);
161 if (write_html_trailer(fp_ou
)<0)
162 debuga(_("Write error in file %s\n"),arqout
);
163 if (fclose(fp_ou
)==EOF
)
164 debuga(_("Failed to close file %s - %s\n"),arqout
,strerror(errno
));