]> git.ipfire.org Git - thirdparty/sarg.git/blob - repday.c
Imported Sarg 2.1.0
[thirdparty/sarg.git] / repday.c
1 /*
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
3 * 1998, 2005
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 dia[3];
37 char mes[3];
38 char ano[3];
39 char odata[20];
40 char hora[20];
41 char elap[20];
42 char oelap[20];
43 char whora[3];
44 char html[8000];
45 char arqout[MAXLEN];
46 char wdirname[MAXLEN];
47 char wuser[255];
48 char c[ 24 ][20];
49 int count=0;
50 int ihora=0;
51 long long int telap=0;
52 long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
53 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
54 long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
55 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L };
56 long long int tt=0, ttt=0;
57 char ftime[128];
58 int i;
59
60 sprintf(arqout,"%s/%s/d%s.html",dirname,user,user);
61 sprintf(wdirname,"%s/%s.day",tmp,user);
62
63 if(access(wdirname, R_OK) != 0)
64 return;
65
66 if((fp_in=fopen(wdirname,"r"))==NULL) {
67 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],wdirname);
68 exit(1);
69 }
70
71 if((fp_ou=fopen(arqout,"w"))==NULL) {
72 fprintf(stderr, "SARG: (repday) %s: %s\n",text[8],arqout);
73 exit(1);
74 }
75
76 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou);
77 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
78 fputs("<html>\n",fp_ou);
79 fputs("<head>\n",fp_ou);
80 sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
81 fputs(html,fp_ou);
82 css(fp_ou);
83 fputs("</head>\n",fp_ou);
84
85 if(strlen(FontFace) > 0) {
86 sprintf(html,"<font face=%s>\n",FontFace);
87 fputs(html,fp_ou);
88 }
89
90 sprintf(html,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
91 fputs(html,fp_ou);
92
93 if(strlen(LogoImage) > 0) {
94 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
95 sprintf(html,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
96 fputs(html,fp_ou);
97 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
98 fputs("</table>\n",fp_ou);
99 }
100
101 if(strcmp(IndexTree,"date") == 0)
102 show_sarg(fp_ou, "../../../..");
103 else
104 show_sarg(fp_ou, "../..");
105
106 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
107 sprintf(html,"<tr><th class=\"title\" colspan=2>%s</th></tr>\n",Title);
108 fputs(html,fp_ou);
109
110 fputs("</table></center>\n",fp_ou);
111 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
112
113 sprintf(html,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[89],periodo);
114 fputs(html,fp_ou);
115
116 strcpy(wuser,user);
117 if(strstr(wuser,"_") != 0)
118 fixip(wuser);
119
120 if(strcmp(Ip2Name,"yes") == 0)
121 if((str=(char *) strstr(name, ".")) != (char *) NULL) {
122 if((str=(char *) strstr(str+1, ".")) != (char *) NULL)
123 ip2name(wuser);
124 }
125
126 if(UserTabFile[0] != '\0') {
127 sprintf(warea,":%s:",wuser);
128 if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) {
129 z1=0;
130 str2=(char *) strstr(str+1,":");
131 str2++;
132 bzero(name, MAXLEN);
133 while(str2[z1] != ':') {
134 name[z1]=str2[z1];
135 z1++;
136 }
137 } else strcpy(name,wuser);
138 } else strcpy(name,user);
139
140 if(dotinuser && strstr(name,"_")) {
141 str2=(char *)subs(name,"_",".");
142 strcpy(name,str2);
143 }
144
145 sprintf(html,"<tr><td class=\"header3\" colspan=\"2\">%s:&nbsp;%s</td></tr>\n",text[90],name);
146 fputs(html,fp_ou);
147
148 fputs("<tr><td></td></tr><tr><td></td></tr>\n",fp_ou);
149 fputs("<tr><td></td></tr><tr><td></td></tr></table>\n",fp_ou);
150
151 fputs("<table cellpadding=0 cellspacing=2>\n", fp_ou);
152
153 fputs( "<tr><td border=0></td>\n", fp_ou );
154
155 if(strcmp(datetimeby,"bytes") == 0)
156 strcpy( html, "BYTES" );
157 else
158 strcpy( html, "H:M:S" );
159
160 for( i = 0; i < hours.len; i++ )
161 fprintf( fp_ou,
162 "<td class=\"header3\">%02dH<br>%s</td>\n", hours.list[ i ], html );
163 fprintf( fp_ou,
164 "<td class=\"header3\">%s<br>%s</td></tr>\n", text[107], html );
165
166 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
167 getword(data,buf,' ');
168 if(!count) {
169 strcpy(odata,data);
170 count++;
171 }
172
173 getword(hora,buf,' ');
174 getword(elap,buf,' ');
175 elap[strlen(elap)-1]='\0';
176
177 if(strcmp(data,odata) != 0) {
178 strcpy(oelap,elap);
179
180 for( i = 0; i < hours.len; i++ )
181 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
182
183 for( i = 8; i <= 17; i++ )
184 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0)
185 bzero(c[ hours.list[ i ] ],12);
186
187 fprintf( fp_ou,
188 "<tr><td class=\"data\">%s</td>\n", odata );
189 for( i = 0; i < hours.len; i++ )
190 fprintf( fp_ou,
191 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
192 fprintf( fp_ou,
193 "<td class=\"data\">%s</td>\n", fixtime(tt) );
194
195 tt=0;
196 for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0;
197 strcpy(odata,data);
198 strcpy(elap,oelap);
199 }
200
201 ihora=atoi(hora);
202
203 v[ ihora ]+=my_atoll(elap);
204 tt+=my_atoll(elap);
205 t[ ihora ]+=my_atoll(elap);
206 ttt+=my_atoll(elap);
207
208 }
209
210 for( i = 0; i < hours.len; i++ )
211 sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ]));
212
213 for( i = 0; i < hours.len; i++ )
214 if(strcmp(c[ hours.list[ i ] ],"00:00:00") == 0) bzero(c[ hours.list[ i ] ],12);
215
216 fprintf( fp_ou,
217 "<tr><td class=\"data\">%s</td>\n", data );
218 for( i = 0; i < hours.len; i++ )
219 fprintf( fp_ou,
220 "<td class=\"data\">%s</td>\n", c[ hours.list[ i ] ] );
221 fprintf( fp_ou,
222 "<td class=\"data\">%s</td></tr>\n", fixtime(tt) );
223
224 for( i = 0; i < hours.len; i++ )
225 sprintf(c[ hours.list[ i ] ],"%s",fixtime(t[ hours.list[ i ] ]));
226
227 fprintf( fp_ou,
228 "<tr><td class=\"header\">%s</td>\n", text[107] );
229 for( i = 0; i < hours.len; i++ )
230 fprintf( fp_ou,
231 "<td class=\"header2\">%s</td>\n", c[ hours.list[ i ] ] );
232 fprintf( fp_ou,
233 "<td class=\"header2\">%s</td></tr>\n", fixtime(ttt) );
234
235 fputs("</body>\n</html>\n",fp_ou);
236
237 show_info(fp_ou);
238
239 fclose(fp_in);
240 fclose(fp_ou);
241
242 return;
243 }