]> git.ipfire.org Git - thirdparty/sarg.git/blame - repday.c
Update version date.
[thirdparty/sarg.git] / repday.c
CommitLineData
25697a35 1/*
c37945ed
FM
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
23 *
24 */
25
26#include "include/conf.h"
5f3cfd1d 27#include "include/defs.h"
25697a35
GS
28
29extern numlist hours;
30
32e71fa4 31void report_day(const char *user)
25697a35
GS
32{
33
34 FILE *fp_in, *fp_ou;
35
36 char data[20];
25697a35 37 char odata[20];
d6e703cc 38 char hour[20];
25697a35
GS
39 char elap[20];
40 char oelap[20];
25697a35
GS
41 char html[8000];
42 char arqout[MAXLEN];
43 char wdirname[MAXLEN];
44 char wuser[255];
45 char c[ 24 ][20];
46 int count=0;
d6e703cc 47 int ihour=0;
25697a35
GS
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;
25697a35
GS
53 int i;
54
55 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
56 sprintf(wdirname,"%s/%s.day",tmp,user);
57
58 if(access(wdirname, R_OK) != 0)
59 return;
60
61 if((fp_in=fopen(wdirname,"r"))==NULL) {
62 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
63 exit(1);
64 }
65
66 if((fp_ou=fopen(arqout,"w"))==NULL) {
67 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
68 exit(1);
69 }
70
d6e703cc 71 fprintf(fp_ou, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
25697a35
GS
72 css(fp_ou);
73 fputs("</head>\n",fp_ou);
d6e703cc
FM
74 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
75 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
76 if(strlen(LogoImage) > 0) fprintf(fp_ou, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText);
25697a35 77
491b862f
GS
78 if(strcmp(IndexTree,"date") == 0)
79 show_sarg(fp_ou, "../../../..");
80 else
81 show_sarg(fp_ou, "../..");
82
25697a35 83 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
354c1a68 84 fprintf(fp_ou,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title);
25697a35
GS
85
86 fputs("</table></center>\n",fp_ou);
87 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
88
354c1a68 89 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
25697a35
GS
90
91 strcpy(wuser,user);
92 if(strstr(wuser,"_") != 0)
93 fixip(wuser);
94
95 if(strcmp(Ip2Name,"yes") == 0)
96 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
97 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
a1c55d8c 98 ip2name(wuser,sizeof(wuser));
25697a35
GS
99 }
100
936c9905 101 get_usertab_name(wuser,name,sizeof(name));
94ff9470 102
48864d28
FM
103 if(dotinuser && strchr(name,'_')) {
104 subs(name,sizeof(name),"_",".");
94ff9470 105 }
48864d28 106
354c1a68 107 fprintf(fp_ou,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
25697a35
GS
108
109 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
110 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
111
112 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou);
113
114 fputs( "<tr><td border=0></td>\n", fp_ou );
115
116 if(strcmp(datetimeby,"bytes") == 0)
d6e703cc 117 strcpy( html, text[93] );
25697a35
GS
118 else
119 strcpy( html, "H:M:S" );
120
121 for( i = 0; i < hours.len; i++ )
122 fprintf( fp_ou,
123 "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
124 fprintf( fp_ou,
125 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
126
127 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
4bcb77cf
FM
128 if (getword(data,sizeof(data),buf,' ')<0) {
129 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
130 exit(1);
131 }
25697a35
GS
132 if(!count) {
133 strcpy(odata,data);
134 count++;
135 }
136
4bcb77cf
FM
137 if (getword(hour,sizeof(hour),buf,' ')<0 || getword(elap,sizeof(elap),buf,' ')<0) {
138 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
139 exit(1);
140 }
25697a35
GS
141 elap[strlen(elap)-1]='\0';
142
143 if(strcmp(data,odata) != 0) {
144 strcpy(oelap,elap);
145
146 for( i = 0; i < hours.len; i++ )
147 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
148
149 for( i = 8; i <= 17; i++ )
150 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
151 bzero(c[ hours.list[ i ] ],12);
152
153 fprintf( fp_ou,
154 "<tr><td class=\"data\">%s</td>\n", odata );
155 for( i = 0; i < hours.len; i++ )
156 fprintf( fp_ou,
157 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
158 fprintf( fp_ou,
159 "<td class=\"data\">%s</td>\n", fixtime(tt) );
160
161 tt=0;
162 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
163 strcpy(odata,data);
164 strcpy(elap,oelap);
165 }
166
d6e703cc 167 ihour=atoi(hour);
25697a35 168
d6e703cc 169 v[ ihour ]+=my_atoll(elap);
25697a35 170 tt+=my_atoll(elap);
d6e703cc 171 t[ ihour ]+=my_atoll(elap);
25697a35
GS
172 ttt+=my_atoll(elap);
173
174 }
175
176 for( i = 0; i < hours.len; i++ )
177 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
178
179 for( i = 0; i < hours.len; i++ )
180 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
181
182 fprintf( fp_ou,
183 "<tr><td class=\"data\">%s</td>\n", data );
184 for( i = 0; i < hours.len; i++ )
185 fprintf( fp_ou,
186 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
187 fprintf( fp_ou,
188 "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
189
190 for( i = 0; i < hours.len; i++ )
191 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
192
193 fprintf( fp_ou,
194 "<tr><td class=\"header\">%s</td>\n", text[107] );
195 for( i = 0; i < hours.len; i++ )
196 fprintf( fp_ou,
197 "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
198 fprintf( fp_ou,
199 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
200
201 fputs("</body>\n</html>\n",fp_ou);
202
203 show_info(fp_ou);
204
205 fclose(fp_in);
206 fclose(fp_ou);
25697a35
GS
207 return;
208}