]>
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
)
42 char wdirname
[MAXLEN
];
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;
53 struct getwordstruct gwarea
;
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
);
59 snprintf(wdirname
,sizeof(wdirname
),"%s/%s.day",tmp
,uinfo
->filename
);
61 if(access(wdirname
, R_OK
) != 0)
64 if((fp_in
=fopen(wdirname
,"r"))==NULL
) {
65 fprintf(stderr
, "SARG: (repday) %s: %s\n",_("Cannot open log file"),wdirname
);
69 if((fp_ou
=fopen(arqout
,"w"))==NULL
) {
70 fprintf(stderr
, "SARG: (repday) %s: %s\n",_("Cannot open log file"),arqout
);
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
);
78 fprintf(fp_ou
,"<tr><td class=\"header_c\" colspan=\"2\">%s: %s</td></tr>\n",_("Period"),period
);
80 fprintf(fp_ou
,"<tr><th class=\"header_c\" colspan=\"2\">%s: %s</th></tr>\n",_("User"),uinfo
->label
);
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
);
85 fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", fp_ou
);
87 fputs( "<tr><td></td>\n", fp_ou
);
89 if(strcmp(datetimeby
,"bytes") == 0)
90 strcpy( html
, _("BYTES") );
92 strcpy( html
, "H:M:S" );
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
);
97 "<td class=\"header_c\">%s<br>%s</td></tr>\n", _("TOTAL"), html
);
99 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
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
);
111 if (getword(hour
,sizeof(hour
),&gwarea
,'\t')<0) {
112 debuga(_("There is a broken time in file %s"),wdirname
);
115 if (getword_atoll(&elap
,&gwarea
,'\t')<0) {
116 debuga(_("There is a broken quantity in file %s"),wdirname
);
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
] ]));
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);
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
) );
134 for( i
= 0; i
< hours
.len
; i
++ ) v
[ hours
.list
[ i
] ]=0;
148 for( i
= 0; i
< hours
.len
; i
++ )
149 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(v
[ hours
.list
[ i
] ]));
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);
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
) );
159 for( i
= 0; i
< hours
.len
; i
++ )
160 sprintf(c
[ hours
.list
[ i
] ],"%s",fixtime(t
[ hours
.list
[ i
] ]));
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
) );
167 fputs("</table>\n",fp_ou
);
168 write_html_trailer(fp_ou
);