]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Replaced the ifdef FOPEN64 by a single call to MY_FOPEN for code clarity.
[thirdparty/sarg.git] / repday.c
1 /*
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
3 * 1998, 2008
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
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"
27 #include "include/defs.h"
28
29 extern numlist hours;
30
31 void report_day(const char *user)
32 {
33
34 FILE *fp_in, *fp_ou;
35
36 char data[20];
37 char odata[20];
38 char hour[20];
39 char elap[20];
40 char oelap[20];
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;
47 int ihour=0;
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
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
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);
72 css(fp_ou);
73 fputs("</head>\n",fp_ou);
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);
77
78 if(strcmp(IndexTree,"date") == 0)
79 show_sarg(fp_ou, "../../../..");
80 else
81 show_sarg(fp_ou, "../..");
82
83 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
84 fprintf(fp_ou,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title);
85
86 fputs("</table></center>\n",fp_ou);
87 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
88
89 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
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)
98 ip2name(wuser,sizeof(wuser));
99 }
100
101 get_usertab_name(wuser,name,sizeof(name));
102
103 if(dotinuser && strstr(name,"_")) {
104 str2=(char *)subs(name,"_",".");
105 strcpy(name,str2);
106 }
107
108 fprintf(fp_ou,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
109
110 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
111 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
112
113 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou);
114
115 fputs( "<tr><td border=0></td>\n", fp_ou );
116
117 if(strcmp(datetimeby,"bytes") == 0)
118 strcpy( html, text[93] );
119 else
120 strcpy( html, "H:M:S" );
121
122 for( i = 0; i < hours.len; i++ )
123 fprintf( fp_ou,
124 "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
125 fprintf( fp_ou,
126 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
127
128 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
129 if (getword(data,sizeof(data),buf,' ')<0) {
130 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
131 exit(1);
132 }
133 if(!count) {
134 strcpy(odata,data);
135 count++;
136 }
137
138 if (getword(hour,sizeof(hour),buf,' ')<0 || getword(elap,sizeof(elap),buf,' ')<0) {
139 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
140 exit(1);
141 }
142 elap[strlen(elap)-1]='\0';
143
144 if(strcmp(data,odata) != 0) {
145 strcpy(oelap,elap);
146
147 for( i = 0; i < hours.len; i++ )
148 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
149
150 for( i = 8; i <= 17; i++ )
151 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
152 bzero(c[ hours.list[ i ] ],12);
153
154 fprintf( fp_ou,
155 "<tr><td class=\"data\">%s</td>\n", odata );
156 for( i = 0; i < hours.len; i++ )
157 fprintf( fp_ou,
158 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
159 fprintf( fp_ou,
160 "<td class=\"data\">%s</td>\n", fixtime(tt) );
161
162 tt=0;
163 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
164 strcpy(odata,data);
165 strcpy(elap,oelap);
166 }
167
168 ihour=atoi(hour);
169
170 v[ ihour ]+=my_atoll(elap);
171 tt+=my_atoll(elap);
172 t[ ihour ]+=my_atoll(elap);
173 ttt+=my_atoll(elap);
174
175 }
176
177 for( i = 0; i < hours.len; i++ )
178 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
179
180 for( i = 0; i < hours.len; i++ )
181 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
182
183 fprintf( fp_ou,
184 "<tr><td class=\"data\">%s</td>\n", data );
185 for( i = 0; i < hours.len; i++ )
186 fprintf( fp_ou,
187 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
188 fprintf( fp_ou,
189 "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
190
191 for( i = 0; i < hours.len; i++ )
192 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
193
194 fprintf( fp_ou,
195 "<tr><td class=\"header\">%s</td>\n", text[107] );
196 for( i = 0; i < hours.len; i++ )
197 fprintf( fp_ou,
198 "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
199 fprintf( fp_ou,
200 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
201
202 fputs("</body>\n</html>\n",fp_ou);
203
204 show_info(fp_ou);
205
206 fclose(fp_in);
207 fclose(fp_ou);
208 return;
209 }