]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
c37945ed FM |
2 | * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com |
3 | * 1998, 2008 | |
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" | |
27 | #include "include/defs.h" | |
28 | ||
29 | void gerarel() | |
30 | { | |
31 | ||
d6e703cc | 32 | FILE *fp_in; |
25697a35 GS |
33 | |
34 | char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10]; | |
35 | char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN]; | |
36 | char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; | |
37 | char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50], user[MAXLEN]; | |
38 | char ipantes[MAXLEN], nameantes[MAXLEN], wdname[MAXLEN], wname2[MAXLEN]; | |
39 | char accsmart[MAXLEN]; | |
40 | char wcrc[50]; | |
41 | char crc2[50]; | |
25697a35 GS |
42 | long long int nbytes=0; |
43 | long long int nelap=0; | |
44 | long long int nacc=0; | |
45 | long long int rtotal=0; | |
46 | long long int incache=0; | |
47 | long long int oucache=0; | |
48 | char *s; | |
49 | DIR *dirp; | |
50 | struct dirent *direntp; | |
51 | ||
52 | ipantes[0]='\0'; | |
53 | nameantes[0]='\0'; | |
54 | smartfilter=0; | |
55 | ||
d6e703cc FM |
56 | sprintf(dirname, "%s%s", outdir, period); |
57 | sprintf(wdir, "%s%s", outdir, period); | |
58 | strcpy(per1,period); | |
25697a35 GS |
59 | vrfydir(wdir, per1, addr, site, us, email); |
60 | ||
61 | if(debugz){ | |
62 | debugaz("dirname",dirname); | |
63 | debugaz("wdir",wdir); | |
64 | } | |
65 | ||
66 | strcpy(wdirname,dirname); | |
d6e703cc | 67 | gperiod(); |
25697a35 | 68 | |
d6e703cc | 69 | if(strlen(UserAgentLog) > 0 && email[0] == '\0') useragent(); |
25697a35 GS |
70 | |
71 | olduser[0]='\0'; | |
72 | strncat(tmp,"/sarg",5); | |
73 | ||
74 | dirp = opendir(tmp); | |
75 | while ((direntp = readdir( dirp )) != NULL ) { | |
d6e703cc FM |
76 | if((strstr(direntp->d_name,".log") == 0) || |
77 | (strncmp(direntp->d_name,"download.log",12) == 0) || | |
78 | (strncmp(direntp->d_name,"denied.log",10) == 0) || | |
79 | (strncmp(direntp->d_name,"authfail.log.unsort",19) == 0)) | |
25697a35 | 80 | continue; |
d6e703cc FM |
81 | sprintf(tmp3,"%s/%s",tmp,direntp->d_name); |
82 | if((fp_in=fopen(tmp3,"r"))==NULL){ | |
83 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],tmp); | |
25697a35 GS |
84 | exit(1); |
85 | } | |
86 | ||
87 | strcpy(wdname,direntp->d_name); | |
88 | strip_prefix: | |
4bcb77cf FM |
89 | if (getword(wname2,sizeof(wname2),wdname,'.')<0) { |
90 | printf("SARG: Maybe you have a broken record or garbage in your %s directory.\n",tmp); | |
91 | exit(1); | |
92 | } | |
25697a35 GS |
93 | strcat(user,wname2); |
94 | ||
95 | if(strcmp(wdname,"log") !=0) { | |
96 | strcat(user,"."); | |
97 | goto strip_prefix; | |
98 | } | |
99 | ||
100 | strcpy(wdirname,dirname); | |
101 | maketmp(user,tmp,debug,indexonly); | |
102 | maketmp_hour(user,tmp,indexonly); | |
103 | ||
104 | ttopen=0; | |
105 | bzero(html_old, MAXLEN); | |
106 | ||
107 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |
4bcb77cf FM |
108 | if (getword(accdia,sizeof(accdia),buf,' ')<0 || getword(acchora,sizeof(acchora),buf,' ')<0 || |
109 | getword(accuser,sizeof(accuser),buf,' ')<0 || getword(accip,sizeof(accip),buf,' ')<0 || | |
110 | getword(accurl,sizeof(accurl),buf,' ')<0 || getword(accbytes,sizeof(accbytes),buf,' ')<0 || | |
111 | getword(acccode,sizeof(acccode),buf,' ')<0) { | |
112 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); | |
113 | exit(1); | |
114 | } | |
d6e703cc | 115 | if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; |
4bcb77cf FM |
116 | if (getword(accelap,sizeof(accelap),buf,' ')<0 || getword(accsmart,sizeof(accsmart),buf,' ')<0 || |
117 | getword(accsmart,sizeof(accsmart),buf,'"')<0) { | |
118 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); | |
119 | exit(1); | |
120 | } | |
25697a35 GS |
121 | |
122 | if(strlen(accsmart) > 0) { | |
123 | smartfilter++; | |
124 | strcpy(wdirname,dirname); | |
125 | grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart); | |
126 | } | |
127 | ||
128 | if(strcmp(Ip2Name,"yes") == 0) { | |
129 | if(strcmp(accip,ipantes) != 0) { | |
130 | strcpy(ipantes,accip); | |
a1c55d8c | 131 | ip2name(accip,sizeof(accip)); |
25697a35 GS |
132 | strcpy(nameantes,accip); |
133 | } else strcpy(accip,nameantes); | |
134 | } | |
135 | ||
136 | strcpy(wdirname,dirname); | |
137 | gravatmp_hora(wdirname,accuser,accdia,acchora,accelap,accbytes,indexonly); | |
138 | ||
139 | if(iprel){ | |
140 | strcpy(wdirname,dirname); | |
141 | gravaporuser(accuser,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); | |
142 | } | |
143 | ||
144 | if(!rtotal){ | |
145 | strcpy(oldurl,accurl); | |
146 | strcpy(oldacccode,acccode); | |
147 | strcpy(oldaccelap,accelap); | |
148 | strcpy(oldaccuser,accuser); | |
149 | strcpy(oldaccip,accip); | |
150 | strcpy(oldaccdia,accdia); | |
151 | strcpy(oldacchora,acchora); | |
152 | rtotal++; | |
153 | } | |
154 | ||
155 | if(site[0] != '\0') { | |
156 | if(strcmp(oldaccuser,accuser) != 0){ | |
157 | strcpy(oldmsg,"OK"); | |
158 | if(strstr(oldacccode,"DENIED") != 0) | |
159 | sprintf(oldmsg,"%s",text[46]); | |
160 | gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); | |
161 | gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap, | |
162 | incache,oucache); | |
163 | nacc=0; | |
164 | nbytes=0; | |
165 | nelap=0; | |
166 | incache=0; | |
167 | oucache=0; | |
168 | } | |
169 | } else { | |
170 | if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){ | |
171 | strcpy(oldmsg,"OK"); | |
172 | if(strstr(oldacccode,"DENIED") != 0) | |
173 | sprintf(oldmsg,"%s",text[46]); | |
174 | strcpy(wdirname,dirname); | |
175 | gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); | |
176 | strcpy(wdirname,dirname); | |
177 | gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
178 | nacc=0; | |
179 | nbytes=0; | |
180 | nelap=0; | |
181 | incache=0; | |
182 | oucache=0; | |
183 | if(strcmp(oldaccuser,accuser) != 0) | |
184 | ind2=0; | |
185 | } | |
186 | } | |
187 | nacc++; | |
188 | nbytes+=my_atoll(accbytes); | |
189 | nelap+=my_atoll(accelap); | |
190 | ||
191 | if(strstr(ReportType,"site_user_time_date") != 0) { | |
192 | if(!ttopen) { | |
193 | ind2++; | |
194 | strcpy(siteind,accurl); | |
195 | str=siteind; | |
a1c55d8c FM |
196 | for(z1=0; str[z1]; z1++) { |
197 | if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' || | |
198 | str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$') | |
199 | str[z1]='_'; | |
200 | } | |
25697a35 GS |
201 | sprintf(arqtt,"%s/%s",dirname,accuser); |
202 | if(access(arqtt, R_OK) != 0) | |
203 | my_mkdir(arqtt); | |
204 | sprintf(arqtt,"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind); | |
205 | if(strlen(arqtt) > 255) { | |
206 | strncpy(val7,arqtt,255); | |
207 | bzero(arqtt,MAXLEN); | |
208 | strcpy(arqtt,val7); | |
209 | } | |
210 | if ((fp_tt = fopen(arqtt, "w")) == 0) { | |
211 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt); | |
212 | exit(1); | |
213 | } | |
214 | ttopen=1; | |
215 | ||
216 | if(strcmp(Privacy,"yes") == 0) | |
217 | sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s", \ | |
218 | FontSize,PrivacyStringColor,PrivacyString,PrivacyString); | |
219 | else | |
220 | sprintf(httplink,"<font size=%s><a href=http://%s>%s</A>",FontSize,accurl,accurl); | |
221 | ||
222 | sprintf(ltext110,"%s",text[110]); | |
223 | if(ltext110){ | |
224 | for(s=ltext110; *s; ++s) | |
225 | *s=tolower(*s); | |
226 | } | |
227 | ||
d6e703cc | 228 | fprintf(fp_tt, "<!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); |
25697a35 GS |
229 | css(fp_tt); |
230 | fputs("</head>\n",fp_tt); | |
d6e703cc FM |
231 | fprintf(fp_tt,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage); |
232 | if(strlen(LogoImage) > 0) fprintf(fp_tt, "<center><table cellpadding=\"0\" cellspacing=\"0\">\n<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n<tr><td height=\"5\"></td></tr>\n</table>\n",LogoImage,Width,Height,LogoText); | |
25697a35 | 233 | |
491b862f GS |
234 | if(strcmp(IndexTree,"date") == 0) |
235 | show_sarg(fp_tt, "../../../.."); | |
236 | else | |
237 | show_sarg(fp_tt, "../.."); | |
25697a35 | 238 | |
d6e703cc FM |
239 | fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_tt); |
240 | fprintf(fp_tt,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title); | |
25697a35 GS |
241 | |
242 | strcpy(u2,user); | |
243 | if(strcmp(Ip2Name,"yes") == 0) | |
a1c55d8c | 244 | ip2name(u2,sizeof(u2)); |
25697a35 GS |
245 | if(UserTabFile[0] != '\0') { |
246 | sprintf(warea,":%s:",u2); | |
247 | if((str=(char *) strstr(userfile,warea)) != (char *) NULL ) { | |
248 | z1=0; | |
249 | str2=(char *) strstr(str+1,":"); | |
250 | str2++; | |
251 | bzero(name, MAXLEN); | |
252 | while(str2[z1] != ':') { | |
253 | name[z1]=str2[z1]; | |
254 | z1++; | |
255 | } | |
256 | } else strcpy(name,u2); | |
257 | } else strcpy(name,u2); | |
258 | ||
94ff9470 GS |
259 | if(dotinuser && strstr(name,"_")) { |
260 | str2=(char *)subs(name,"_","."); | |
261 | strcpy(name,str2); | |
262 | } | |
263 | ||
d6e703cc FM |
264 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[89],period); |
265 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[90],name); | |
266 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder); | |
267 | fprintf(fp_tt,"<tr><th class=\"header3\" colspan=2>%s</th></tr>\n",text[32]); | |
25697a35 GS |
268 | |
269 | fputs("</table></center>\n",fp_tt); | |
270 | fputs("<center><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt); | |
271 | fputs("<tr><td></td><td></td></tr>",fp_tt); | |
272 | bzero(tmp4, MAXLEN); | |
25697a35 | 273 | strncpy(tmp4,text[110],4); |
d6e703cc | 274 | fprintf(fp_tt,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[91],tmp4,text[110]+5); |
25697a35 GS |
275 | } |
276 | ||
277 | sprintf(html,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora); | |
278 | ||
279 | if(strcmp(html,html_old) != 0) | |
280 | fputs(html,fp_tt); | |
281 | strcpy(html_old, html); | |
d6e703cc | 282 | } else bzero(ltext110, 50); |
25697a35 GS |
283 | |
284 | strcpy(wcrc,acccode); | |
4bcb77cf FM |
285 | if (getword(crc2,sizeof(crc2),wcrc,'/')<0) { |
286 | printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); | |
287 | exit(1); | |
288 | } | |
25697a35 GS |
289 | |
290 | if(strstr(crc2,"MISS") != 0) | |
291 | oucache+=my_atoll(accbytes); | |
292 | else incache+=my_atoll(accbytes); | |
293 | ||
294 | strcpy(oldurl,accurl); | |
295 | ||
296 | if(strcmp(accuser,oldaccuser) != 0) { | |
297 | strcpy(wdirname,dirname); | |
d6e703cc | 298 | day_totalize(tmp,oldaccuser,indexonly); |
25697a35 GS |
299 | } |
300 | ||
301 | strcpy(oldaccuser,accuser); | |
302 | strcpy(oldacccode,acccode); | |
303 | strcpy(oldaccelap,accelap); | |
304 | strcpy(oldaccip,accip); | |
305 | strcpy(oldaccdia,accdia); | |
306 | strcpy(oldacchora,acchora); | |
307 | ||
308 | } | |
309 | bzero(user,MAXLEN); | |
310 | fclose(fp_in); | |
311 | unlink(tmp3); | |
312 | } | |
313 | ||
314 | strcpy(oldmsg,"OK"); | |
315 | if(strstr(oldacccode,"DENIED") != 0) | |
316 | sprintf(oldmsg,"%s",text[46]); | |
317 | strcpy(wdirname,dirname); | |
d6e703cc FM |
318 | if(strlen(oldaccuser) == 0) |
319 | strcpy(oldaccuser,accuser); | |
25697a35 GS |
320 | gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
321 | strcpy(wdirname,dirname); | |
322 | gravager(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
323 | strcpy(wdirname,dirname); | |
d6e703cc | 324 | day_totalize(tmp,oldaccuser,indexonly); |
25697a35 GS |
325 | |
326 | tmpsort(); | |
327 | ||
328 | strcpy(wdirname,dirname); | |
329 | totalger(wdirname, debug, outdir); | |
330 | ||
331 | if(strlen(email) == 0) { | |
d6e703cc | 332 | if(strstr(ReportType,"downloads") != 0) download_report(); |
25697a35 GS |
333 | |
334 | if(strlen(DansGuardianConf) > 0) { | |
335 | strcpy(wdirname,dirname); | |
336 | dansguardian_log(); | |
337 | } | |
338 | ||
491b862f GS |
339 | strcpy(wdirname,dirname); |
340 | squidguard_log(); | |
25697a35 GS |
341 | |
342 | strcpy(wdirname,dirname); | |
343 | topuser(); | |
344 | ||
d6e703cc | 345 | if(strstr(ReportType,"topsites") != 0) topsites(); |
25697a35 | 346 | |
d6e703cc | 347 | if(strstr(ReportType,"sites_users") != 0) siteuser(); |
25697a35 GS |
348 | gen_denied_report(); |
349 | ||
350 | strcpy(wdirname,dirname); | |
351 | authfail_report(); | |
352 | ||
d6e703cc | 353 | if(smartfilter) smartfilter_report(); |
25697a35 | 354 | |
d6e703cc | 355 | if(strlen(DansGuardianConf) > 0) dansguardian_report(); |
25697a35 | 356 | |
491b862f | 357 | squidguard_report(); |
25697a35 | 358 | |
d6e703cc | 359 | if(strstr(ReportType,"users_sites") != 0) htmlrel(); |
25697a35 | 360 | |
491b862f | 361 | make_index(); |
25697a35 | 362 | |
d6e703cc | 363 | if(strncmp(SuccessfulMsg,"yes",3) == 0) fprintf(stderr, "SARG: %s %s\n",text[47],dirname); |
25697a35 GS |
364 | } else { |
365 | strcpy(wdirname,dirname); | |
366 | geramail(wdirname, debug, outdir, userip, email, TempDir); | |
367 | ||
d6e703cc | 368 | if((strcmp(email,"stdout") != 0) && (strncmp(SuccessfulMsg,"yes",3) == 0)) |
25697a35 | 369 | fprintf(stderr, "SARG: %s %s\n",text[48],email); |
25697a35 GS |
370 | } |
371 | ||
372 | if(indexonly) { | |
373 | strcpy(wdirname,dirname); | |
374 | index_only(wdirname, debug); | |
375 | } | |
376 | ||
d6e703cc FM |
377 | if(strlen(email) < 0) |
378 | removetmp(dirname); | |
25697a35 GS |
379 | |
380 | return; | |
381 | } | |
382 | ||
383 | ||
384 | void maketmp(char *user, char *dirname, int debug, int indexonly) | |
385 | { | |
386 | ||
387 | FILE *fp_ou; | |
388 | ||
389 | char wdirname[MAXLEN]; | |
390 | ||
391 | if(indexonly) return; | |
392 | if(strstr(ReportType,"users_sites") == 0) return; | |
393 | ||
394 | strcpy(wdirname,tmp); | |
395 | strcat(wdirname,"/"); | |
396 | strcat(wdirname,user); | |
397 | ||
398 | if(debug){ | |
399 | sprintf(msg,"%s: %s",text[49],wdirname); | |
400 | debuga(msg); | |
401 | } | |
402 | ||
403 | strcat(wdirname,".utmp"); | |
404 | if((fp_ou=fopen(wdirname,"w"))==NULL){ | |
405 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
406 | exit(1); | |
407 | } | |
408 | ||
409 | fclose(fp_ou); | |
410 | return; | |
411 | } | |
412 | ||
413 | ||
414 | void maketmp_hour(char *user, char *dirname, int indexonly) | |
415 | { | |
416 | ||
417 | FILE *fp_ou; | |
418 | ||
419 | char wdirname[MAXLEN]; | |
420 | ||
421 | if(indexonly) return; | |
422 | if(strstr(ReportType,"users_sites") == 0) return; | |
423 | ||
424 | strcpy(wdirname,tmp); | |
425 | strcat(wdirname,"/"); | |
426 | strcat(wdirname,user); | |
427 | ||
428 | strcat(wdirname,".htmp"); | |
429 | if((fp_ou=fopen(wdirname,"w"))==NULL){ | |
430 | fprintf(stderr, "SARG: (report-1) %s: %s - %s\n",text[45],wdirname,strerror(errno)); | |
431 | exit(1); | |
432 | } | |
433 | ||
434 | fclose(fp_ou); | |
435 | return; | |
436 | } | |
437 | ||
438 | ||
439 | void gravatmp(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) | |
440 | { | |
441 | ||
442 | FILE *fp_ou; | |
443 | ||
25697a35 GS |
444 | char wdirname[MAXLEN]; |
445 | ||
446 | if(indexonly) return; | |
447 | if(strstr(ReportType,"users_sites") == 0) return; | |
448 | ||
449 | strcpy(wdirname,tmp); | |
450 | strcat(wdirname,"/"); | |
451 | strcat(wdirname,oldaccuser); | |
452 | strcat(wdirname,".utmp"); | |
453 | ||
454 | if((fp_ou=fopen(wdirname,"a"))==NULL){ | |
455 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
456 | exit(1); | |
457 | } | |
458 | ||
459 | my_lltoa(nacc,val1,15); | |
460 | my_lltoa(nbytes,val2,15); | |
461 | my_lltoa(nelap,val3,15); | |
462 | my_lltoa(incache,val4,15); | |
463 | my_lltoa(oucache,val5,15); | |
d6e703cc | 464 | fprintf(fp_ou,"%s %s %s %s %s %s %s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); |
25697a35 GS |
465 | |
466 | fclose(fp_ou); | |
467 | ttopen=0; | |
468 | ||
469 | if(fp_tt) { | |
470 | fputs("</table>\n",fp_tt); | |
471 | fputs("</body>\n</html>\n",fp_tt); | |
472 | fclose(fp_tt); | |
473 | } | |
474 | ||
475 | return; | |
476 | ||
477 | } | |
478 | ||
479 | ||
480 | void gravatmp_hora(char *dirname, char *user, char *data, char *hora, char *elap, char *bytes, int indexonly) | |
481 | { | |
482 | ||
483 | FILE *fp_ou; | |
484 | ||
25697a35 GS |
485 | char wdirname[MAXLEN]; |
486 | ||
d6e703cc | 487 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 GS |
488 | |
489 | strcpy(wdirname,tmp); | |
490 | strcat(wdirname,"/"); | |
491 | strcat(wdirname,user); | |
492 | strcat(wdirname,".htmp"); | |
493 | ||
494 | if((fp_ou=fopen(wdirname,"a"))==NULL){ | |
495 | fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno)); | |
496 | exit(1); | |
497 | } | |
498 | ||
d6e703cc FM |
499 | if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s %s %s\n",data,hora,bytes); |
500 | else fprintf(fp_ou,"%s %s %s\n",data,hora,elap); | |
25697a35 GS |
501 | |
502 | fclose(fp_ou); | |
503 | ||
504 | return; | |
505 | } | |
506 | ||
507 | ||
508 | void gravaporuser(char *user, char *dirname, char *url, char *ip, char *data, char *hora, char *tam, char *elap, int indexonly) | |
509 | { | |
510 | ||
511 | FILE *fp_ou; | |
512 | ||
25697a35 GS |
513 | char wdirname[MAXLEN]; |
514 | ||
d6e703cc | 515 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 GS |
516 | |
517 | strcpy(wdirname,tmp); | |
518 | strcat(wdirname,"/"); | |
519 | strcat(wdirname,user); | |
520 | strcat(wdirname,".ip"); | |
521 | ||
522 | if((fp_ou=fopen(wdirname,"a"))==NULL){ | |
523 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
524 | exit(1); | |
525 | } | |
526 | ||
d6e703cc | 527 | fprintf(fp_ou,"%s %s %s %s %s %s\n",ip,url,data,hora,tam,elap); |
25697a35 GS |
528 | |
529 | fclose(fp_ou); | |
530 | ||
531 | return; | |
532 | ||
533 | } | |
534 | ||
535 | ||
536 | void gravatmpf(char *oldaccuser, char *dirname, char *oldurl, long long int nacc, long long int nbytes, char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) | |
537 | { | |
538 | ||
539 | FILE *fp_ou; | |
540 | ||
25697a35 GS |
541 | char wdirname[MAXLEN]; |
542 | ||
d6e703cc | 543 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 GS |
544 | |
545 | strcpy(wdirname,tmp); | |
546 | strcat(wdirname,"/"); | |
547 | strcat(wdirname,oldaccuser); | |
548 | strcat(wdirname,".utmp"); | |
549 | ||
550 | if((fp_ou=fopen(wdirname,"a"))==NULL){ | |
551 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
552 | exit(1); | |
553 | } | |
554 | ||
555 | my_lltoa(nacc,val1,15); | |
556 | my_lltoa(nbytes,val2,15); | |
557 | my_lltoa(nelap,val3,15); | |
558 | my_lltoa(incache,val4,15); | |
559 | my_lltoa(oucache,val5,15); | |
d6e703cc | 560 | fprintf(fp_ou,"%s %s %s %s %s %s %s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); |
25697a35 GS |
561 | |
562 | fclose(fp_ou); | |
563 | ttopen=0; | |
564 | ind2=0; | |
565 | ||
566 | if(fp_tt) { | |
567 | fputs("</table>\n",fp_tt); | |
568 | fputs("</html>\n",fp_tt); | |
569 | fclose(fp_tt); | |
570 | } | |
571 | ||
572 | return; | |
573 | ||
574 | } | |
575 | ||
576 | ||
577 | void gravager(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache) | |
578 | { | |
579 | ||
580 | FILE *fp_ou; | |
25697a35 GS |
581 | |
582 | strcat(dirname,"/"); | |
d6e703cc | 583 | strcat(dirname,"sarg-general"); |
25697a35 GS |
584 | |
585 | if((fp_ou=fopen(dirname,"a"))==NULL){ | |
586 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname); | |
587 | exit(1); | |
588 | } | |
589 | ||
590 | my_lltoa(nacc,val1,15); | |
591 | my_lltoa(nbytes,val2,15); | |
592 | my_lltoa(nelap,val3,15); | |
593 | my_lltoa(incache,val4,15); | |
594 | my_lltoa(oucache,val5,15); | |
d6e703cc | 595 | fprintf(fp_ou,"%s %s %s %s %s %s %s %s %s %s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5); |
25697a35 GS |
596 | |
597 | fclose(fp_ou); | |
598 | return; | |
599 | ||
600 | } | |
601 | ||
602 | void grava_SmartFilter(char *dirname, char *user, char *ip, char *data, char *hora, char *url, char *smart) | |
603 | { | |
604 | ||
605 | FILE *fp_ou; | |
606 | ||
25697a35 GS |
607 | char wdirname[MAXLEN]; |
608 | ||
609 | sprintf(wdirname,"%s/smartfilter.unsort",dirname); | |
610 | ||
611 | if((fp_ou=fopen(wdirname,"a"))==NULL){ | |
612 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
613 | exit(1); | |
614 | } | |
615 | ||
d6e703cc | 616 | fprintf(fp_ou,"%s %s %s %s %s %s\n",user,data,hora,ip,url,smart); |
25697a35 GS |
617 | fputs("</body>\n</html>\n",fp_tt); |
618 | ||
619 | fclose(fp_ou); | |
620 | ||
621 | return; | |
622 | ||
623 | } |