]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
91957808cb399e94bffd87a6693d0925d0d4d565
[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
28 extern numlist hours;
29
30 void report_day(char *user, int *iprel, int *ipuser)
31 {
32
33 FILE *fp_in, *fp_ou;
34
35 char data[20];
36 char odata[20];
37 char hour[20];
38 char elap[20];
39 char oelap[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 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;
52 int i;
53
54 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
55 sprintf(wdirname,"%s/%s.day",tmp,user);
56
57 if(access(wdirname, R_OK) != 0)
58 return;
59
60 if((fp_in=fopen(wdirname,"r"))==NULL) {
61 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
62 exit(1);
63 }
64
65 if((fp_ou=fopen(arqout,"w"))==NULL) {
66 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
67 exit(1);
68 }
69
70 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);
71 css(fp_ou);
72 fputs("</head>\n",fp_ou);
73 if(strlen(FontFace) > 0) fprintf(fp_ou,"<font face=%s>\n",FontFace);
74 fprintf(fp_ou,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
75 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);
76
77 if(strcmp(IndexTree,"date") == 0)
78 show_sarg(fp_ou, "../../../..");
79 else
80 show_sarg(fp_ou, "../..");
81
82 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
83 sprintf(html,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title);
84 fputs(html,fp_ou);
85
86 fputs("</table></center>\n",fp_ou);
87 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
88
89 sprintf(html,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],period);
90 fputs(html,fp_ou);
91
92 strcpy(wuser,user);
93 if(strstr(wuser,"_") != 0)
94 fixip(wuser);
95
96 if(strcmp(Ip2Name,"yes") == 0)
97 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
98 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
99 ip2name(wuser);
100 }
101
102 if(UserTabFile[0] != '\0') {
103 sprintf(warea,":%s:",wuser);
104 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
105 z1=0;
106 str2=(char *) strstr(str+1,":");
107 str2++;
108 bzero(name, MAXLEN);
109 while(str2[z1] != ':') {
110 name[z1]=str2[z1];
111 z1++;
112 }
113 } else strcpy(name,wuser);
114 } else strcpy(name,user);
115
116 if(dotinuser && strstr(name,"_")) {
117 str2=(char *)subs(name,"_",".");
118 strcpy(name,str2);
119 }
120
121 sprintf(html,"<tr><th class=\"header3\" colspan=\"2\">%s:&nbsp;%s</th></tr>\n",text[90],name);
122 fputs(html,fp_ou);
123
124 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
125 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
126
127 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou);
128
129 fputs( "<tr><td border=0></td>\n", fp_ou );
130
131 if(strcmp(datetimeby,"bytes") == 0)
132 strcpy( html, text[93] );
133 else
134 strcpy( html, "H:M:S" );
135
136 for( i = 0; i < hours.len; i++ )
137 fprintf( fp_ou,
138 "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
139 fprintf( fp_ou,
140 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
141
142 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
143 getword(data,buf,' ');
144 if(!count) {
145 strcpy(odata,data);
146 count++;
147 }
148
149 getword(hour,buf,' ');
150 getword(elap,buf,' ');
151 elap[strlen(elap)-1]='\0';
152
153 if(strcmp(data,odata) != 0) {
154 strcpy(oelap,elap);
155
156 for( i = 0; i < hours.len; i++ )
157 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
158
159 for( i = 8; i <= 17; i++ )
160 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
161 bzero(c[ hours.list[ i ] ],12);
162
163 fprintf( fp_ou,
164 "<tr><td class=\"data\">%s</td>\n", odata );
165 for( i = 0; i < hours.len; i++ )
166 fprintf( fp_ou,
167 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
168 fprintf( fp_ou,
169 "<td class=\"data\">%s</td>\n", fixtime(tt) );
170
171 tt=0;
172 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
173 strcpy(odata,data);
174 strcpy(elap,oelap);
175 }
176
177 ihour=atoi(hour);
178
179 v[ ihour ]+=my_atoll(elap);
180 tt+=my_atoll(elap);
181 t[ ihour ]+=my_atoll(elap);
182 ttt+=my_atoll(elap);
183
184 }
185
186 for( i = 0; i < hours.len; i++ )
187 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
188
189 for( i = 0; i < hours.len; i++ )
190 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
191
192 fprintf( fp_ou,
193 "<tr><td class=\"data\">%s</td>\n", data );
194 for( i = 0; i < hours.len; i++ )
195 fprintf( fp_ou,
196 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
197 fprintf( fp_ou,
198 "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
199
200 for( i = 0; i < hours.len; i++ )
201 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
202
203 fprintf( fp_ou,
204 "<tr><td class=\"header\">%s</td>\n", text[107] );
205 for( i = 0; i < hours.len; i++ )
206 fprintf( fp_ou,
207 "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
208 fprintf( fp_ou,
209 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
210
211 fputs("</body>\n</html>\n",fp_ou);
212
213 show_info(fp_ou);
214
215 fclose(fp_in);
216 fclose(fp_ou);
217 return;
218 }