]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Ported r225 from branches/v2_2_7 (remove Pedro Orso's mail from headers)
[thirdparty/sarg.git] / repday.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2010
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
10 *
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.
15 *
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.
20 *
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.
24 *
25 */
26
27 #include "include/conf.h"
28 #include "include/defs.h"
29
30 extern numlist hours;
31
32 void report_day(const char *user)
33 {
34
35 FILE *fp_in, *fp_ou;
36
37 char data[20];
38 char odata[20];
39 char hour[20];
40 char html[8000];
41 char arqout[MAXLEN];
42 char wdirname[MAXLEN];
43 char wuser[255];
44 char c[ 24 ][20];
45 int count=0;
46 int ihour=0;
47 long long int elap;
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 struct getwordstruct gwarea;
55
56 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
57 sprintf(wdirname,"%s/%s.day",tmp,user);
58
59 if(access(wdirname, R_OK) != 0)
60 return;
61
62 if((fp_in=fopen(wdirname,"r"))==NULL) {
63 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
64 exit(1);
65 }
66
67 if((fp_ou=fopen(arqout,"w"))==NULL) {
68 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
69 exit(1);
70 }
71
72 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);
73 css(fp_ou);
74 fputs("</head>\n",fp_ou);
75 //if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
76 fprintf(fp_ou,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage);
77 write_logo_image(fp_ou);
78
79 if(IndexTree == INDEX_TREE_DATE)
80 show_sarg(fp_ou, "../../../..");
81 else
82 show_sarg(fp_ou, "../..");
83
84 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
85 fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
86
87 fputs("</table></div>\n",fp_ou);
88 fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
89
90 fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
91
92 strcpy(wuser,user);
93 if(strstr(wuser,"_") != 0)
94 fixip(wuser);
95
96 if(Ip2Name)
97 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
98 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
99 ip2name(wuser,sizeof(wuser));
100 }
101
102 user_find(name, sizeof(name), wuser);
103
104 if(dotinuser && strchr(name,'_')) {
105 subs(name,sizeof(name),"_",".");
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></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, "<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) {
128 fixendofline(buf);
129 getword_start(&gwarea,buf);
130 if (getword(data,sizeof(data),&gwarea,'\t')<0) {
131 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
132 exit(1);
133 }
134 if(!count) {
135 strcpy(odata,data);
136 count++;
137 }
138
139 if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) {
140 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname);
141 exit(1);
142 }
143
144 if(strcmp(data,odata) != 0) {
145 for( i = 0; i < hours.len; i++ )
146 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
147
148 for( i = 8; i <= 17; i++ )
149 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
150 bzero(c[ hours.list[ i ] ],12);
151
152 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", odata );
153 for( i = 0; i < hours.len; i++ )
154 fprintf(fp_ou,"<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
155 fprintf( fp_ou, "<td class=\"data\">%s</td>\n", fixtime(tt) );
156
157 tt=0;
158 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
159 strcpy(odata,data);
160 }
161
162 ihour=atoi(hour);
163
164 v[ ihour ]+=elap;
165 tt+=elap;
166 t[ ihour ]+=elap;
167 ttt+=elap;
168
169 }
170
171 for( i = 0; i < hours.len; i++ )
172 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
173
174 for( i = 0; i < hours.len; i++ )
175 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
176
177 fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data );
178 for( i = 0; i < hours.len; i++ )
179 fprintf(fp_ou, "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
180 fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
181
182 for( i = 0; i < hours.len; i++ )
183 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
184
185 fprintf(fp_ou, "<tr><td class=\"header\">%s</td>\n", text[107] );
186 for( i = 0; i < hours.len; i++ )
187 fprintf(fp_ou, "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
188 fprintf(fp_ou, "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
189
190 fputs("</table></div>\n",fp_ou);
191
192 show_info(fp_ou);
193
194 fputs("</body>\n</html>\n",fp_ou);
195 fclose(fp_in);
196 fclose(fp_ou);
197 return;
198 }