]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br |
25697a35 | 3 | * 1998, 2005 |
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 | 28 | |
32e71fa4 | 29 | void htmlrel(void) |
25697a35 GS |
30 | { |
31 | DIR *dirp; | |
32e71fa4 | 32 | FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr; |
25697a35 GS |
33 | |
34 | struct dirent *direntp; | |
35 | long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0; | |
36 | long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; | |
37 | long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0; | |
0a4e18e1 FM |
38 | long long int ltemp; |
39 | long long int ntotuser; | |
40 | long long int userbytes, userelap; | |
25697a35 | 41 | char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; |
0a4e18e1 | 42 | char url[MAXLEN], tmsg[50], csort[MAXLEN]; |
d6e703cc | 43 | char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN]; |
0a4e18e1 FM |
44 | char userurl[1024], userhora[9], userdia[9]; |
45 | char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; | |
94ff9470 | 46 | char denied_report[255], name2[MAXLEN]; |
32e71fa4 | 47 | //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3]; |
25697a35 | 48 | char *str; |
32e71fa4 | 49 | char warea[MAXLEN]; |
0a4e18e1 | 50 | char totuser[8]; |
25697a35 GS |
51 | long long int tnacc=0, ttnacc=0, unacc=0; |
52 | float perc=0, perc2=0, ouperc=0, inperc=0; | |
53 | char *s; | |
32e71fa4 | 54 | int count; |
456d78a5 | 55 | int cstatus; |
936c9905 FM |
56 | const char txtext[]=".txt"; |
57 | int dlen; | |
dfb337be | 58 | char href2[MAXLEN]; |
4157aa09 FM |
59 | char urly[MAXLEN]; |
60 | char siteind[MAXLEN]; | |
9c7c6346 | 61 | struct getwordstruct gwarea; |
25697a35 | 62 | |
25697a35 GS |
63 | if(strstr(ReportType,"users_sites") == 0) return; |
64 | ||
65 | strcpy(tmp2,TempDir); | |
66 | strcat(tmp2,"/sargtmp.unsort"); | |
67 | ||
68 | strcpy(tmp3,TempDir); | |
69 | strcat(tmp3,"/sargtmp.log"); | |
70 | ||
71 | strcpy(arqper,dirname); | |
d6e703cc | 72 | strcat(arqper,"/sarg-period"); |
25697a35 GS |
73 | |
74 | if ((fp_in = fopen(arqper, "r")) == 0){ | |
75 | fprintf(stderr, "SARG: (html1) %s: %s\n",text[45],arqper); | |
76 | exit(1); | |
77 | } | |
78 | ||
05b90947 FM |
79 | if (!fgets(period,sizeof(period),fp_in)) { |
80 | fprintf(stderr,"SARG: (html1) read error in %s\n",arqper); | |
81 | exit(1); | |
82 | } | |
25697a35 GS |
83 | fclose(fp_in); |
84 | ||
85 | strcpy(arqper,dirname); | |
d6e703cc | 86 | strcat(arqper,"/sarg-general"); |
25697a35 GS |
87 | |
88 | if ((fp_in = fopen(arqper, "r")) == 0){ | |
89 | fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper); | |
90 | exit(1); | |
91 | } | |
92 | ||
93 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
94 | if(strstr(buf,"TOTAL") == 0) { | |
9c7c6346 | 95 | getword_start(&gwarea,buf); |
0a4e18e1 | 96 | if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(<emp,&gwarea,'\t')<0) { |
4bcb77cf FM |
97 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper); |
98 | exit(1); | |
99 | } | |
0a4e18e1 FM |
100 | ttnacc+=ltemp; |
101 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
4bcb77cf FM |
102 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper); |
103 | exit(1); | |
104 | } | |
0a4e18e1 | 105 | totbytes+=ltemp; |
9c7c6346 FM |
106 | if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || |
107 | getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || | |
0a4e18e1 FM |
108 | getword_atoll(<emp,&gwarea,'\t')<0) { |
109 | printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__); | |
4bcb77cf FM |
110 | exit(1); |
111 | } | |
0a4e18e1 | 112 | totelap+=ltemp; |
25697a35 GS |
113 | } |
114 | } | |
115 | ||
116 | fclose(fp_in); | |
117 | ||
118 | dirp = opendir(tmp); | |
119 | while ( (direntp = readdir( dirp )) != NULL ) { | |
936c9905 FM |
120 | dlen=strlen(direntp->d_name)-(sizeof(txtext)-1); |
121 | if (dlen<0) continue; | |
122 | if(strcmp(direntp->d_name+dlen,txtext) != 0) | |
25697a35 GS |
123 | continue; |
124 | ||
125 | count=1; | |
936c9905 FM |
126 | if (dlen>0) { |
127 | if (dlen>=sizeof(wusuario)) continue; | |
128 | strncpy(wusuario,direntp->d_name,dlen); | |
129 | wusuario[dlen]=0; | |
130 | } else { | |
131 | wusuario[0]=0; | |
25697a35 | 132 | } |
936c9905 FM |
133 | str=strrchr(wusuario,'.'); |
134 | if (str) | |
135 | strcpy(denied_report,str+1); | |
136 | else | |
137 | strcpy(denied_report,wusuario); | |
138 | ||
05b90947 FM |
139 | if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) { |
140 | fprintf(stderr,"SARG: destination directory too long: %s/%s\n",dirname,wusuario); | |
141 | exit(1); | |
142 | } | |
25697a35 GS |
143 | mkdir(warea,0755); |
144 | ||
32e71fa4 FM |
145 | report_day(wusuario); |
146 | greport_day(wusuario); | |
25697a35 GS |
147 | |
148 | strcpy(usuario,wusuario); | |
149 | strcpy(arqin,tmp); | |
150 | strcat(arqin,"/"); | |
151 | strcpy(arqou,dirname); | |
152 | strcat(arqou,"/"); | |
153 | strcat(arqou,usuario); | |
154 | strcat(arqou,"/"); | |
155 | strcat(arqou,usuario); | |
156 | strcat(arqou,".html"); | |
157 | strcpy(duser,arqin); | |
158 | strcat(duser,"denied_"); | |
159 | strcat(arqin,direntp->d_name); | |
4157aa09 | 160 | |
25697a35 GS |
161 | if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) { |
162 | if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) | |
163 | fixip(denied_report); | |
164 | } | |
165 | strcat(duser,denied_report); | |
166 | strcat(duser,".html"); | |
167 | if(access(duser, R_OK) != 0) | |
168 | denied_report[0]='\0'; | |
936c9905 FM |
169 | |
170 | strcpy(u2,usuario); | |
171 | if(userip) | |
172 | fixip(u2); | |
246c8489 | 173 | if(Ip2Name) |
936c9905 FM |
174 | ip2name(u2,sizeof(u2)); |
175 | ||
176 | get_usertab_name(u2,name2,sizeof(name2)); | |
177 | ||
48864d28 FM |
178 | if(dotinuser && strchr(name2,'_')) { |
179 | subs(name2,sizeof(name2),"_","."); | |
936c9905 FM |
180 | } |
181 | ||
25697a35 GS |
182 | if ((fp_in = fopen(arqin, "r")) == 0){ |
183 | fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin); | |
184 | exit(1); | |
185 | } | |
48864d28 | 186 | |
25697a35 | 187 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { |
9c7c6346 | 188 | getword_start(&gwarea,buf); |
0a4e18e1 | 189 | if (getword_atoll(<emp,&gwarea,'\t')<0) { |
4bcb77cf FM |
190 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); |
191 | exit(1); | |
192 | } | |
0a4e18e1 FM |
193 | tnacc+=ltemp; |
194 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
4bcb77cf FM |
195 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); |
196 | exit(1); | |
197 | } | |
0a4e18e1 | 198 | tnbytes+=ltemp; |
9c7c6346 | 199 | if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || |
0a4e18e1 | 200 | getword_atoll(<emp,&gwarea,'\t')<0) { |
4bcb77cf FM |
201 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); |
202 | exit(1); | |
203 | } | |
0a4e18e1 FM |
204 | tnelap+=ltemp; |
205 | if (getword_atoll(<emp,&gwarea,'\t')<0) { | |
4bcb77cf FM |
206 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); |
207 | exit(1); | |
208 | } | |
0a4e18e1 FM |
209 | tnincache+=ltemp; |
210 | if (getword_atoll(<emp,&gwarea,'\n')<0) { | |
211 | printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__); | |
4bcb77cf FM |
212 | exit(1); |
213 | } | |
0a4e18e1 | 214 | tnoucache+=ltemp; |
25697a35 GS |
215 | } |
216 | ||
ec7b26a5 | 217 | rewind(fp_in); |
32d1c674 | 218 | |
25697a35 GS |
219 | if ((fp_ou = fopen(arqou, "w")) == 0){ |
220 | fprintf(stderr, "SARG: (html5) %s: %s\n",text[45],arqou); | |
221 | exit(1); | |
222 | } | |
32d1c674 | 223 | |
dfb337be | 224 | fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou); |
25697a35 GS |
225 | fputs("<html>\n",fp_ou); |
226 | fputs("<head>\n",fp_ou); | |
354c1a68 | 227 | fprintf(fp_ou," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); |
25697a35 GS |
228 | css(fp_ou); |
229 | fputs("</head>\n",fp_ou); | |
230 | ||
354c1a68 | 231 | fprintf(fp_ou,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \ |
25697a35 | 232 | background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage); |
25697a35 | 233 | |
dfb337be | 234 | write_logo_image(fp_ou); |
25697a35 | 235 | |
491b862f GS |
236 | if(strcmp(IndexTree,"date") == 0) |
237 | show_sarg(fp_ou, "../../../.."); | |
238 | else | |
239 | show_sarg(fp_ou, "../.."); | |
240 | ||
dfb337be | 241 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou); |
354c1a68 | 242 | fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title); |
25697a35 | 243 | |
354c1a68 FM |
244 | fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[89],period); |
245 | fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[90],name2); | |
246 | fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder); | |
dfb337be | 247 | fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s %s</td></tr>\n",text[32],text[55]); |
25697a35 | 248 | fputs("<tr><td></td></tr>\n",fp_ou); |
32d1c674 | 249 | |
dfb337be FM |
250 | fputs("</table></div>\n",fp_ou); |
251 | fputs("<div align=\"center\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou); | |
32d1c674 | 252 | |
4157aa09 | 253 | if(denied_report[0]!='\0') { |
dfb337be | 254 | fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,text[116],text[55]); |
25697a35 | 255 | } |
32d1c674 | 256 | |
25697a35 GS |
257 | strcpy(val3,text[92]); |
258 | strcpy(val4,text[93]); | |
259 | sprintf(val11,"%%%s",text[93]); | |
260 | sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]); | |
261 | strcpy(val6,text[94]); | |
262 | strcpy(val7,text[95]); | |
263 | sprintf(val8,"%%%s",text[99]); | |
dfb337be | 264 | strcpy(val9,"colspan=\"2\""); |
25697a35 | 265 | bzero(val10, 255); |
32d1c674 | 266 | |
25697a35 GS |
267 | if(strstr(UserReportFields,"CONNECT") == 0) |
268 | bzero(val3, 255); | |
269 | if(strstr(UserReportFields,"BYTES") == 0) | |
270 | bzero(val4, 255); | |
271 | if(strstr(UserReportFields,"SETYB") == 0) | |
272 | bzero(val11, 255); | |
273 | if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { | |
274 | bzero(val5, 255); | |
275 | bzero(val9, 255); | |
276 | strcpy(val10,"<td></td>"); | |
277 | } | |
278 | if(strstr(UserReportFields,"USED_TIME") == 0) | |
279 | bzero(val6, 255); | |
280 | if(strstr(UserReportFields,"MILISEC") == 0) | |
281 | bzero(val7, 255); | |
282 | if(strstr(UserReportFields,"%TIME") == 0) | |
283 | bzero(val8, 255); | |
32d1c674 | 284 | |
354c1a68 | 285 | fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header3\" %s>%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[91],val3,val4,val11,val9,val5,val6,val7,val8); |
32d1c674 | 286 | |
25697a35 GS |
287 | if(debug) { |
288 | if(userip) { | |
289 | strcpy(u2,usuario); | |
290 | fixip(u2); | |
d2fe0c32 | 291 | debuga("%s: %s",text[61],u2); |
25697a35 | 292 | } else |
d2fe0c32 | 293 | debuga("%s: %s",text[61],usuario); |
25697a35 GS |
294 | } |
295 | ||
4157aa09 | 296 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { |
9c7c6346 | 297 | getword_start(&gwarea,buf); |
0a4e18e1 | 298 | if (getword_atoll(&twork,&gwarea,'\t')<0) { |
4157aa09 FM |
299 | printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin); |
300 | exit(1); | |
301 | } | |
0a4e18e1 | 302 | if (getword_atoll(&nnbytes,&gwarea,'\t')<0) { |
4157aa09 FM |
303 | printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin); |
304 | exit(1); | |
305 | } | |
9c7c6346 | 306 | if (getword(url,sizeof(url),&gwarea,'\t')<0) { |
4157aa09 FM |
307 | printf("SARG: Maybe you have a broken url in your %s file.\n",arqin); |
308 | exit(1); | |
309 | } | |
9c7c6346 | 310 | if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) { |
4157aa09 FM |
311 | printf("SARG: Maybe you have a broken status in your %s file.\n",arqin); |
312 | exit(1); | |
313 | } | |
0a4e18e1 | 314 | if (getword_atoll(&nnelap,&gwarea,'\t')<0) { |
4157aa09 FM |
315 | printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin); |
316 | exit(1); | |
317 | } | |
0a4e18e1 | 318 | if (getword_atoll(&incache,&gwarea,'\t')<0) { |
4157aa09 FM |
319 | printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin); |
320 | exit(1); | |
321 | } | |
0a4e18e1 FM |
322 | if (getword_atoll(&oucache,&gwarea,'\n')<0) { |
323 | printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__); | |
4157aa09 FM |
324 | exit(1); |
325 | } | |
25697a35 | 326 | |
25697a35 GS |
327 | if(strncmp(tmsg,"OK",2) != 0) |
328 | sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]); | |
329 | else bzero(tmsg, 50); | |
330 | ||
25697a35 GS |
331 | if(nnbytes) { |
332 | perc=nnbytes * 100; | |
333 | perc=perc / tnbytes; | |
334 | } else { | |
335 | perc=0; | |
336 | ouperc=0; | |
337 | } | |
338 | ||
339 | if(nnelap) { | |
340 | perc2=nnelap * 100; | |
341 | perc2=perc2 / tnelap; | |
342 | } else perc2=0; | |
4157aa09 | 343 | |
25697a35 GS |
344 | if(incache) { |
345 | inperc=incache * 100; | |
346 | inperc=inperc / nnbytes; | |
347 | } else inperc=0; | |
32d1c674 | 348 | |
25697a35 GS |
349 | if(oucache) { |
350 | ouperc=oucache * 100; | |
351 | ouperc=ouperc / nnbytes; | |
352 | } else ouperc=0; | |
32d1c674 | 353 | |
32e71fa4 FM |
354 | strcpy(wwork1,fixnum(twork,1)); |
355 | strcpy(wwork2,fixnum(nnbytes,1)); | |
356 | strcpy(wwork3,fixnum2(nnelap,1)); | |
25697a35 | 357 | |
246c8489 | 358 | if(!LongUrl) { |
4157aa09 FM |
359 | char *endofhost=strchr(url,'/'); |
360 | if (endofhost) *endofhost='\0'; | |
25697a35 GS |
361 | strcpy(urly,url); |
362 | } else { | |
363 | strcpy(urly,url); | |
364 | url_module(url, module); | |
9c7c6346 FM |
365 | str=strchr(url,'/'); |
366 | if (str){ | |
367 | *str='\0'; | |
368 | strcat(url,"..."); | |
369 | strcat(url,module); | |
4bcb77cf | 370 | } |
25697a35 GS |
371 | } |
372 | ||
e6414a9d | 373 | if(Privacy) |
dfb337be | 374 | sprintf(httplink,"<span style=\"color:%s;\">%s</span>",PrivacyStringColor,PrivacyString); |
32d1c674 | 375 | else { |
dfb337be FM |
376 | if(strcmp(IndexTree,"date") == 0) |
377 | sprintf(tmp6,"../%s",ImageFile); | |
378 | else | |
379 | strcpy(tmp6,"../../images"); | |
380 | if(BlockIt[0]!='\0') | |
381 | snprintf(httplink,sizeof(httplink),"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a><a href=http://%s> %s</a>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly); | |
382 | else | |
383 | snprintf(httplink,sizeof(httplink),"<a href=\"http://%s\" title=\"%s\">%s</a>",urly,urly,url); | |
32d1c674 | 384 | } |
25697a35 GS |
385 | |
386 | if(strstr(ReportType,"site_user_time_date") != 0) { | |
32e71fa4 FM |
387 | strcpy(ltext110,text[110]); |
388 | for(s=ltext110; *s; ++s) | |
389 | *s=tolower(*s); | |
25697a35 GS |
390 | strcpy(siteind,urly); |
391 | str=siteind; | |
a1c55d8c FM |
392 | for(z1=0; str[z1]; z1++) { |
393 | if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' || | |
394 | str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$') | |
25697a35 GS |
395 | str[z1]='_'; |
396 | } | |
dfb337be | 397 | sprintf(href2,"<a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\" alt=\"T\"></a>",usuario,siteind,tmp6,ltext110,text[55]); |
25697a35 GS |
398 | } else { |
399 | bzero(href2, MAXLEN); | |
400 | bzero(ltext110, 50); | |
4157aa09 | 401 | } |
25697a35 GS |
402 | |
403 | sprintf(val2,"%s",href2); | |
404 | sprintf(val3,"%3.2f%%",perc); | |
405 | sprintf(val4,"%3.2f%%",inperc); | |
406 | sprintf(val5,"%3.2f%%",ouperc); | |
407 | sprintf(val6,"%s",buildtime(nnelap)); | |
408 | sprintf(val7,"%3.2f%%",perc2); | |
dfb337be | 409 | |
25697a35 GS |
410 | if(strstr(UserReportFields,"CONNECT") == 0) { |
411 | bzero(wwork1, 255); | |
412 | bzero(hbc1, 30); | |
413 | } | |
414 | if(strstr(UserReportFields,"BYTES") == 0) { | |
415 | bzero(wwork2, 255); | |
416 | bzero(hbc2, 30); | |
417 | } | |
418 | if(strstr(UserReportFields,"MILISEC") == 0) { | |
419 | bzero(wwork3, 255); | |
420 | bzero(hbc3, 30); | |
421 | } | |
422 | if(strstr(UserReportFields,"SETYB") == 0) { | |
423 | bzero(val3, 255); | |
424 | bzero(hbc4, 30); | |
425 | } | |
426 | if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { | |
427 | bzero(val4, 255); | |
428 | bzero(val5, 255); | |
429 | bzero(hbc5, 30); | |
430 | bzero(hbc6, 30); | |
431 | } | |
432 | if(strstr(UserReportFields,"USED_TIME") == 0) { | |
433 | bzero(val6, 255); | |
434 | bzero(hbc7, 30); | |
435 | } | |
436 | if(strstr(UserReportFields,"%TIME") == 0) { | |
437 | bzero(val7, 255); | |
438 | bzero(hbc8, 30); | |
439 | } | |
440 | if(strncmp(tmsg," ",1) == 0) | |
441 | bzero(hbc9, 30); | |
442 | ||
4157aa09 | 443 | |
354c1a68 FM |
444 | if(UserReportLimit<=0 || count<=UserReportLimit) { |
445 | fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data2\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td>%s</tr>\n",val2,httplink,wwork1,wwork2,val3,val4,val5,val6,wwork3,val7,tmsg); | |
446 | count++; | |
447 | } | |
25697a35 GS |
448 | |
449 | if(iprel) { | |
450 | strcpy(arqip,tmp); | |
451 | strcat(arqip,"/"); | |
452 | strcat(arqip,usuario); | |
453 | strcat(arqip,".ip"); | |
936c9905 | 454 | |
25697a35 GS |
455 | if ((fp_ip = fopen(arqip, "r")) == 0){ |
456 | fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip); | |
457 | exit(1); | |
458 | } | |
0dda06bf | 459 | |
936c9905 | 460 | if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){ |
25697a35 GS |
461 | fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2); |
462 | exit(1); | |
463 | } | |
936c9905 | 464 | |
25697a35 GS |
465 | while(fgets(buf,sizeof(buf),fp_ip)!=NULL) { |
466 | if(strstr(buf,url) != 0) | |
467 | fputs(buf,fp_ip2); | |
468 | } | |
936c9905 | 469 | |
25697a35 GS |
470 | fclose(fp_ip); |
471 | fclose(fp_ip2); | |
472 | ||
9a2efbd0 | 473 | sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2); |
456d78a5 FM |
474 | cstatus=system(csort); |
475 | if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { | |
476 | fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); | |
477 | fprintf(stderr, "SARG: sort command: %s\n",csort); | |
478 | exit(1); | |
479 | } | |
936c9905 FM |
480 | |
481 | if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) { | |
25697a35 GS |
482 | fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3); |
483 | exit(1); | |
484 | } | |
485 | ||
05b90947 | 486 | olduserip[0]='\0'; |
dfb337be | 487 | |
05b90947 | 488 | while(fgets(buf,sizeof(buf),fp_ip)) { |
9c7c6346 FM |
489 | getword_start(&gwarea,buf); |
490 | if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) { | |
05b90947 FM |
491 | printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3); |
492 | exit(1); | |
493 | } | |
9c7c6346 | 494 | if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) { |
05b90947 FM |
495 | printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3); |
496 | exit(1); | |
497 | } | |
9c7c6346 | 498 | if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) { |
05b90947 FM |
499 | printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3); |
500 | exit(1); | |
501 | } | |
9c7c6346 | 502 | if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) { |
05b90947 FM |
503 | printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3); |
504 | exit(1); | |
505 | } | |
0a4e18e1 | 506 | if (getword_atoll(&userbytes,&gwarea,'\t')<0) { |
05b90947 FM |
507 | printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3); |
508 | exit(1); | |
509 | } | |
0a4e18e1 FM |
510 | if (getword_atoll(&userelap,&gwarea,'\t')<0) { |
511 | printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__); | |
05b90947 FM |
512 | exit(1); |
513 | } | |
25697a35 GS |
514 | if(strcmp(user_ip,olduserip) != 0) { |
515 | my_lltoa(unelap,val2,0); | |
516 | sprintf(wwork1,"%s",fixnum(unbytes,1)); | |
354c1a68 | 517 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val2); |
dfb337be | 518 | |
25697a35 GS |
519 | strcpy(olduserip,user_ip); |
520 | unacc=0; | |
521 | unbytes=0; | |
522 | unelap=0; | |
523 | } | |
dfb337be | 524 | |
0a4e18e1 FM |
525 | unbytes=unbytes+userbytes; |
526 | unelap=unelap+userelap; | |
25697a35 GS |
527 | } |
528 | ||
529 | fclose(fp_ip); | |
530 | ||
531 | unlink(tmp2); | |
532 | unlink(tmp3); | |
533 | ||
534 | my_lltoa(unelap,val3,0); | |
535 | sprintf(wwork1,"%s",fixnum(unbytes,1)); | |
dfb337be | 536 | fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val3); |
25697a35 GS |
537 | } |
538 | ||
539 | unacc=0; | |
540 | unbytes=0; | |
541 | unelap=0; | |
542 | ||
25697a35 GS |
543 | } |
544 | ||
545 | if(iprel) | |
546 | unlink(arqip); | |
547 | unlink(arqin); | |
548 | ||
549 | if(tnbytes) { | |
550 | perc=totbytes / 100; | |
551 | perc=tnbytes / perc; | |
552 | } else perc=0; | |
dfb337be | 553 | |
25697a35 GS |
554 | if(tnelap) { |
555 | perc2=totelap / 100; | |
556 | perc2=tnelap / perc2; | |
557 | } else perc2=0; | |
dfb337be | 558 | |
25697a35 GS |
559 | if(tnoucache) { |
560 | ouperc=tnoucache * 100; | |
561 | ouperc=ouperc / tnbytes; | |
562 | } else ouperc=0; | |
dfb337be | 563 | |
25697a35 GS |
564 | if(tnincache) { |
565 | inperc=tnincache * 100; | |
566 | inperc=inperc / tnbytes; | |
567 | } else inperc=0; | |
dfb337be | 568 | |
25697a35 GS |
569 | sprintf(wwork1,"%s",fixnum(tnacc,1)); |
570 | sprintf(wwork2,"%s",fixnum(tnbytes,1)); | |
d6e703cc | 571 | sprintf(wwork3,"%s",fixnum2(tnelap,1)); |
25697a35 GS |
572 | |
573 | sprintf(val2,"%s%s",href2,ltext110); | |
574 | sprintf(val3,"%3.2f%%",perc); | |
575 | sprintf(val4,"%3.2f%%",inperc); | |
576 | sprintf(val5,"%3.2f%%",ouperc); | |
577 | sprintf(val6,"%s",buildtime(tnelap)); | |
578 | sprintf(val7,"%3.2f%%",perc2); | |
579 | ||
580 | strcpy(hbc1,"class=\"header2\""); | |
581 | strcpy(hbc2,"class=\"header2\""); | |
582 | strcpy(hbc3,"class=\"header2\""); | |
583 | strcpy(hbc4,"class=\"header2\""); | |
584 | strcpy(hbc5,"class=\"header2\""); | |
585 | strcpy(hbc6,"class=\"header2\""); | |
586 | strcpy(hbc7,"class=\"header2\""); | |
587 | strcpy(hbc8,"class=\"header2\""); | |
588 | strcpy(hbc9,"class=\"header\""); | |
589 | ||
590 | if(strstr(UserReportFields,"CONNECT") == 0) { | |
591 | bzero(wwork1, 255); | |
592 | bzero(hbc1, 30); | |
593 | } | |
594 | if(strstr(UserReportFields,"BYTES") == 0) { | |
595 | bzero(wwork2, 255); | |
596 | bzero(hbc2, 30); | |
597 | } | |
598 | if(strstr(UserReportFields,"MILISEC") == 0) { | |
599 | bzero(wwork3, 255); | |
600 | bzero(hbc3, 30); | |
601 | } | |
602 | if(strstr(UserReportFields,"SETYB") == 0) { | |
603 | bzero(val3, 255); | |
604 | bzero(hbc4, 30); | |
605 | } | |
606 | if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { | |
607 | bzero(val4, 255); | |
608 | bzero(hbc5, 30); | |
609 | } | |
610 | if(strstr(UserReportFields,"IN-CACHE-OUT") == 0) { | |
611 | bzero(val5, 255); | |
612 | bzero(hbc6, 30); | |
613 | } | |
614 | if(strstr(UserReportFields,"USED_TIME") == 0) { | |
615 | bzero(val6, 255); | |
616 | bzero(hbc7, 30); | |
617 | } | |
618 | if(strstr(UserReportFields,"%TIME") == 0) { | |
619 | bzero(val7, 255); | |
620 | bzero(hbc8, 30); | |
621 | } | |
622 | ||
623 | if(strstr(UserReportFields,"TOTAL") != 0) { | |
dfb337be | 624 | fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc9,text[107],hbc1,wwork1,hbc2,wwork2,hbc4,val3,hbc5,val4,hbc6,val5,hbc7,val6,hbc3,wwork3,hbc8,val7); |
25697a35 GS |
625 | } |
626 | ||
627 | fclose(fp_in); | |
4157aa09 | 628 | |
e6414a9d FM |
629 | if(PerUserLimit > 0) { |
630 | if(tnbytes > (PerUserLimit*1000000)) { | |
25697a35 GS |
631 | limit_flag=0; |
632 | if(access(PerUserLimitFile, R_OK) == 0) { | |
633 | if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) { | |
634 | fprintf(stderr, "SARG: (html9) %s: %s\n",text[45],PerUserLimitFile); | |
635 | exit(1); | |
636 | } | |
491b862f GS |
637 | while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) { |
638 | if(strstr(tmp6,"\n") != 0) | |
639 | tmp6[strlen(tmp6)-1]='\0'; | |
640 | if(strcmp(tmp6,u2) == 0) { | |
25697a35 GS |
641 | limit_flag=1; |
642 | break; | |
643 | } | |
644 | } | |
645 | fclose(fp_usr); | |
646 | } | |
936c9905 | 647 | |
25697a35 GS |
648 | if(!limit_flag) { |
649 | if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) { | |
650 | fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile); | |
651 | exit(1); | |
652 | } | |
354c1a68 | 653 | fprintf(fp_usr,"%s\n",u2); |
25697a35 | 654 | fclose(fp_usr); |
936c9905 | 655 | |
d2fe0c32 | 656 | if(debug) |
e6414a9d | 657 | debuga("%s %s %s (%d MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile); |
25697a35 GS |
658 | } |
659 | } | |
660 | } | |
661 | ||
d6e703cc FM |
662 | // if(indexonly) { |
663 | // unlink(arqou); | |
664 | // continue; | |
665 | // } | |
666 | ||
936c9905 FM |
667 | if (strstr(ReportType,"topuser") != 0) { |
668 | strcpy(arqper,dirname); | |
669 | strcat(arqper,"/sarg-users"); | |
dfb337be | 670 | |
936c9905 FM |
671 | if ((fp_in = fopen(arqper, "r")) == 0){ |
672 | fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper); | |
673 | exit(1); | |
674 | } | |
25697a35 | 675 | |
0a4e18e1 | 676 | if (!fgets(totuser,sizeof(totuser),fp_in)) { |
05b90947 FM |
677 | fprintf(stderr,"SARG: (html11) read error in %s\n",arqper); |
678 | exit(1); | |
679 | } | |
936c9905 | 680 | fclose(fp_in); |
dfb337be | 681 | |
0a4e18e1 FM |
682 | ntotuser=my_atoll(totuser); |
683 | if (ntotuser<=0) ntotuser=1; | |
684 | totbytes2=totbytes/ntotuser; | |
685 | totelap2=totelap/ntotuser; | |
dfb337be | 686 | |
936c9905 FM |
687 | if(totbytes2) { |
688 | perc = totbytes / 100; | |
689 | perc = totbytes2 / perc; | |
690 | } else perc=0; | |
dfb337be | 691 | |
936c9905 FM |
692 | if(totelap2) { |
693 | perc2 = totelap / 100; | |
694 | perc2 = totelap2 / perc2; | |
695 | } else perc2=0; | |
dfb337be | 696 | |
0a4e18e1 | 697 | twork2=ntotuser; |
936c9905 | 698 | twork=ttnacc/twork2; |
dfb337be | 699 | |
48864d28 FM |
700 | strcpy(wwork1,fixnum(twork,1)); |
701 | strcpy(wwork2,fixnum(totbytes2,1)); | |
702 | strcpy(wwork3,fixnum2(totelap2,1)); | |
25697a35 | 703 | |
936c9905 | 704 | sprintf(val6,"%s",buildtime(totelap2)); |
4157aa09 | 705 | sprintf(val7,"%3.2f%%",perc2); |
dfb337be | 706 | |
936c9905 FM |
707 | strcpy(hbc1,"class=\"header2\""); |
708 | strcpy(hbc2,"class=\"header2\""); | |
709 | strcpy(hbc3,"class=\"header2\""); | |
710 | strcpy(hbc4,"class=\"header2\""); | |
711 | strcpy(hbc5,"class=\"header2\""); | |
712 | strcpy(hbc6,"class=\"header\""); | |
713 | ||
714 | if(strstr(UserReportFields,"CONNECT") == 0) { | |
715 | bzero(wwork1, 255); | |
716 | bzero(hbc1, 30); | |
717 | } | |
718 | if(strstr(UserReportFields,"BYTES") == 0) { | |
719 | bzero(wwork2, 255); | |
720 | bzero(hbc2, 30); | |
721 | } | |
722 | if(strstr(UserReportFields,"MILISEC") == 0) { | |
723 | bzero(wwork3, 255); | |
724 | bzero(hbc3, 30); | |
725 | } | |
4157aa09 | 726 | if(strstr(UserReportFields,"USED_TIME") == 0) { |
936c9905 FM |
727 | bzero(val6, 255); |
728 | bzero(hbc4, 30); | |
729 | } | |
730 | if(strstr(UserReportFields,"%TIME") == 0) { | |
731 | bzero(val7, 255); | |
732 | bzero(hbc5, 30); | |
733 | } | |
4157aa09 | 734 | |
936c9905 | 735 | if(strstr(UserReportFields,"AVERAGE") != 0) { |
dfb337be | 736 | fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th></th><th></th><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7); |
936c9905 FM |
737 | } |
738 | } /* added */ | |
25697a35 GS |
739 | tnacc=0; |
740 | tnbytes=0; | |
741 | tnelap=0; | |
742 | tnincache=0; | |
743 | tnoucache=0; | |
744 | ||
dfb337be | 745 | fputs("</table></div>\n",fp_ou); |
25697a35 GS |
746 | |
747 | show_info(fp_ou); | |
748 | ||
749 | fputs("</body>\n</html>\n",fp_ou); | |
750 | ||
751 | fclose(fp_ou); | |
752 | ||
491b862f | 753 | htaccess(wusuario); |
25697a35 GS |
754 | |
755 | } | |
756 | ||
757 | (void)rewinddir(dirp); | |
758 | (void)closedir(dirp); | |
c274f011 | 759 | greport_cleanup(); |
25697a35 GS |
760 | |
761 | return; | |
762 | } |