]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
61d965f3 | 3 | * 1998, 2012 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
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 | ||
9dc20988 FM |
30 | //! The global statistics of the whole log read. |
31 | struct globalstatstruct globstat; | |
32 | ||
e5b2c6f0 FM |
33 | static FILE *fp_tt=NULL; |
34 | ||
d8e04f05 | 35 | static FILE *maketmp(const char *user, const char *dirname, int debug); |
d8e04f05 | 36 | static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache); |
6588b137 | 37 | static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap); |
9dc20988 | 38 | static void gravager(FILE *fp_gen,const char *filename, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache); |
5160b452 | 39 | static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart); |
5f3cfd1d | 40 | |
32e71fa4 | 41 | void gerarel(void) |
25697a35 | 42 | { |
9bd92830 FM |
43 | FILE *fp_in; |
44 | FILE *fp_gen; | |
d8e04f05 | 45 | FILE *fp_tmp=NULL; |
9bd92830 FM |
46 | |
47 | char *buf; | |
48 | char accdia[11], acchora[9], accip[MAXLEN], *accurl; | |
49 | char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN]; | |
50 | char wdirname[MAXLEN]; | |
51 | char *oldurl=NULL; | |
93551487 | 52 | char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1]; |
9bd92830 FM |
53 | char ipantes[MAXLEN], nameantes[MAXLEN]; |
54 | char accsmart[MAXLEN]; | |
55 | char crc2[MAXLEN/2 -1]; | |
56 | char siteind[MAX_TRUNCATED_URL]; | |
57 | char arqtt[256]; | |
58 | char *oldurltt=NULL; | |
59 | char oldaccdiatt[11],oldacchoratt[9]; | |
60 | char tmp3[MAXLEN]; | |
9bd92830 FM |
61 | char u2[MAX_USER_LEN]; |
62 | long long int nbytes=0; | |
63 | long long int nelap=0; | |
64 | long long int nacc=0; | |
9bd92830 FM |
65 | long long int incache=0; |
66 | long long int oucache=0; | |
67 | long long int accbytes, accelap; | |
68 | char *str; | |
93551487 | 69 | userscan uscan; |
9bd92830 FM |
70 | const char *sort_field; |
71 | const char *sort_order; | |
93551487 | 72 | const char *user; |
9bd92830 FM |
73 | int url_len; |
74 | int ourl_size=0; | |
75 | int ourltt_size=0; | |
76 | int same_url; | |
d8e04f05 | 77 | bool new_user; |
9bd92830 FM |
78 | struct getwordstruct gwarea; |
79 | longline line; | |
d8e04f05 | 80 | struct userinfostruct *uinfo; |
026ddd8b | 81 | DayObject daystat; |
9bd92830 FM |
82 | |
83 | ipantes[0]='\0'; | |
84 | smartfilter=0; | |
9dc20988 | 85 | memset(&globstat,0,sizeof(globstat)); |
9bd92830 FM |
86 | |
87 | if (vrfydir(&period, addr, site, us, email)<0) { | |
88 | debuga(_("Cannot create the output directory name containing the period as part of the name\n")); | |
89 | exit(EXIT_FAILURE); | |
90 | } | |
91 | ||
92 | if(debugz){ | |
9f93fec3 | 93 | debugaz(_("outdirname=%s\n"),outdirname); |
9bd92830 FM |
94 | } |
95 | ||
96 | if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); | |
97 | ||
98 | snprintf(wdirname,sizeof(wdirname),"%s/sarg-general",outdirname); | |
99 | if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){ | |
100 | debuga(_("(report) Cannot open file %s\n"),wdirname); | |
101 | exit(EXIT_FAILURE); | |
102 | } | |
103 | ||
9bd92830 | 104 | fp_tt=NULL; |
fefdc019 | 105 | sort_labels(&sort_field,&sort_order); |
9bd92830 | 106 | |
026ddd8b FM |
107 | if (indexonly || datetimeby==0) |
108 | daystat=NULL; | |
109 | else | |
110 | daystat=day_prepare(); | |
111 | ||
93551487 FM |
112 | uscan=userinfo_startscan(); |
113 | if (uscan == NULL) { | |
114 | debuga(_("Cannot enumerate the user list\n")); | |
9bd92830 FM |
115 | exit(EXIT_FAILURE); |
116 | } | |
93551487 | 117 | while ((uinfo = userinfo_advancescan(uscan)) != NULL ) { |
461b479d | 118 | sort_users_log(tmp,debug,uinfo); |
170a77ea FM |
119 | if (snprintf(tmp3,sizeof(tmp3),"%s/%s.user_log",tmp,uinfo->filename)>=sizeof(tmp3)) { |
120 | debuga(_("(report) directory entry too long: %s/%s.user_log\n"),tmp,uinfo->filename); | |
9bd92830 FM |
121 | exit(EXIT_FAILURE); |
122 | } | |
123 | if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){ | |
124 | debuga(_("(report) Cannot open file %s\n"),tmp); | |
125 | exit(EXIT_FAILURE); | |
126 | } | |
93551487 | 127 | user=uinfo->filename; |
026ddd8b | 128 | day_newuser(daystat); |
9bd92830 | 129 | |
9bd92830 FM |
130 | strcpy(u2,uinfo->id); |
131 | if(Ip2Name && uinfo->id_is_ip) { | |
132 | strcpy(ipantes,u2); | |
133 | ip2name(u2,sizeof(u2)); | |
134 | strcpy(nameantes,u2); | |
135 | } | |
136 | user_find(uinfo->label,MAX_USER_LEN, u2); | |
137 | ||
6588b137 | 138 | if (!indexonly) { |
d8e04f05 | 139 | fp_tmp=maketmp(user,tmp,debug); |
6588b137 | 140 | } |
9bd92830 FM |
141 | |
142 | ttopen=0; | |
d8e04f05 | 143 | oldurl=NULL; |
9bd92830 FM |
144 | oldurltt=NULL; |
145 | ourltt_size=0; | |
146 | memset(oldaccdiatt,0,sizeof(oldaccdiatt)); | |
147 | memset(oldacchoratt,0,sizeof(oldacchoratt)); | |
d8e04f05 FM |
148 | new_user=true; |
149 | nacc=0; | |
150 | nbytes=0; | |
151 | nelap=0; | |
152 | incache=0; | |
153 | oucache=0; | |
9bd92830 FM |
154 | |
155 | if ((line=longline_create())==NULL) { | |
156 | debuga(_("Not enough memory to read the downloaded files\n")); | |
157 | exit(EXIT_FAILURE); | |
158 | } | |
159 | ||
160 | while((buf=longline_read(fp_in,line))!=NULL) { | |
161 | getword_start(&gwarea,buf); | |
162 | if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || | |
007905af FM |
163 | getword(accip,sizeof(accip),&gwarea,'\t')<0 || |
164 | getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || | |
165 | getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { | |
9bd92830 FM |
166 | debuga(_("There is a broken record or garbage in file %s\n"),tmp3); |
167 | exit(EXIT_FAILURE); | |
168 | } | |
169 | if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; | |
170 | if (getword_atoll(&accelap,&gwarea,'\t')<0) { | |
171 | debuga(_("There is a broken elapsed time in file %s\n"),tmp3); | |
172 | exit(EXIT_FAILURE); | |
173 | } | |
174 | if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { | |
175 | debuga(_("There is a broken smart info in file %s\n"),tmp3); | |
176 | exit(EXIT_FAILURE); | |
177 | } | |
178 | ||
179 | if(accsmart[0] != '\0') { | |
180 | smartfilter++; | |
1caa1b3d | 181 | grava_SmartFilter(tmp,uinfo->id,accip,accdia,acchora,accurl,accsmart); |
9bd92830 FM |
182 | } |
183 | ||
184 | if(Ip2Name) { | |
185 | if(strcmp(accip,ipantes) != 0) { | |
186 | strcpy(ipantes,accip); | |
187 | ip2name(accip,sizeof(accip)); | |
188 | strcpy(nameantes,accip); | |
189 | } else strcpy(accip,nameantes); | |
190 | } | |
191 | ||
6588b137 | 192 | if (!indexonly) { |
026ddd8b | 193 | day_addpoint(daystat,accdia,acchora,accelap,accbytes); |
d8e04f05 | 194 | if (iprel) gravaporuser(uinfo,outdirname,accurl,accip,accdia,acchora,accbytes,accelap); |
9bd92830 FM |
195 | } |
196 | ||
d8e04f05 | 197 | if(new_user){ |
9bd92830 FM |
198 | url_len=strlen(accurl); |
199 | if (!oldurl || url_len>=ourl_size) { | |
200 | ourl_size=url_len+1; | |
201 | oldurl=realloc(oldurl,ourl_size); | |
202 | if (!oldurl) { | |
203 | debuga(_("Not enough memory to store the url\n")); | |
204 | exit(EXIT_FAILURE); | |
205 | } | |
206 | } | |
207 | strcpy(oldurl,accurl); | |
208 | strcpy(oldacccode,acccode); | |
9bd92830 FM |
209 | strcpy(oldaccip,accip); |
210 | strcpy(oldaccdia,accdia); | |
211 | strcpy(oldacchora,acchora); | |
d8e04f05 | 212 | new_user=false; |
9bd92830 FM |
213 | } |
214 | same_url=(strcmp(oldurl,accurl) == 0); | |
215 | ||
d8e04f05 FM |
216 | if(site[0] == '\0') { |
217 | if(!same_url){ | |
9bd92830 FM |
218 | if(strstr(oldacccode,"DENIED") != 0) |
219 | strcpy(oldmsg,"DENIED"); | |
220 | else | |
221 | strcpy(oldmsg,"OK"); | |
d8e04f05 FM |
222 | if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache); |
223 | gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
9bd92830 FM |
224 | nacc=0; |
225 | nbytes=0; | |
226 | nelap=0; | |
227 | incache=0; | |
228 | oucache=0; | |
229 | } | |
230 | } | |
231 | nacc++; | |
232 | nbytes+=accbytes; | |
233 | nelap+=accelap; | |
234 | ||
1219fb1a | 235 | if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 && !indexonly && |
007905af | 236 | (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) { |
9bd92830 FM |
237 | |
238 | if(!ttopen) { | |
239 | snprintf(arqtt,sizeof(arqtt),"%s/%s",outdirname,uinfo->filename); | |
240 | if(access(arqtt, R_OK) != 0) | |
241 | my_mkdir(arqtt); | |
242 | url_to_file(accurl,siteind,sizeof(siteind)); | |
243 | snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind); | |
244 | if ((fp_tt = fopen(arqtt, "w")) == 0) { | |
245 | debuga(_("(report) Cannot open file %s\n"),arqtt); | |
246 | exit(EXIT_FAILURE); | |
247 | } | |
248 | ttopen=1; | |
249 | ||
250 | /* | |
251 | if(Privacy) | |
007905af | 252 | sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s",FontSize,PrivacyStringColor,PrivacyString,PrivacyString); |
9bd92830 FM |
253 | else |
254 | sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl); | |
255 | */ | |
256 | ||
257 | write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report"),HTML_JS_NONE); | |
258 | fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("Period"),period.html); | |
259 | fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label); | |
260 | fputs("<tr><td class=\"header_c\">",fp_tt); | |
261 | fprintf(fp_tt,_("Sort: %s, %s"),sort_field,sort_order); | |
262 | fputs("</td></tr>\n",fp_tt); | |
263 | fprintf(fp_tt,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User")); | |
264 | close_html_header(fp_tt); | |
265 | ||
266 | fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt); | |
bde5073d | 267 | fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("ACCESSED SITE"),_("DATE"),_("TIME")); |
9bd92830 FM |
268 | } |
269 | ||
270 | fputs("<tr><td class=\"data\">",fp_tt); | |
271 | output_html_string(fp_tt,accurl,100); | |
272 | fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora); | |
273 | ||
274 | url_len=strlen(accurl); | |
275 | if (!oldurltt || url_len>=ourltt_size) { | |
276 | ourltt_size=url_len+1; | |
277 | oldurltt=realloc(oldurltt,ourltt_size); | |
278 | if (!oldurltt) { | |
279 | debuga(_("Not enough memory to store the url\n")); | |
280 | exit(EXIT_FAILURE); | |
281 | } | |
282 | } | |
283 | strcpy(oldurltt,accurl); | |
284 | strcpy(oldaccdiatt,accdia); | |
285 | strcpy(oldacchoratt,acchora); | |
286 | } | |
287 | ||
288 | strcpy(crc2,acccode); | |
289 | str=strchr(crc2,'/'); | |
290 | if (str) *str='\0'; | |
291 | if(strstr(crc2,"MISS") != 0) | |
292 | oucache+=accbytes; | |
d8e04f05 FM |
293 | else |
294 | incache+=accbytes; | |
9bd92830 | 295 | |
9bd92830 FM |
296 | strcpy(oldacccode,acccode); |
297 | strcpy(oldaccip,accip); | |
298 | if (!same_url) { | |
299 | url_len=strlen(accurl); | |
300 | if (url_len>=ourl_size) { | |
301 | ourl_size=url_len+1; | |
302 | oldurl=realloc(oldurl,ourl_size); | |
303 | if (!oldurl) { | |
304 | debuga(_("Not enough memory to store the url\n")); | |
305 | exit(EXIT_FAILURE); | |
306 | } | |
307 | } | |
308 | strcpy(oldurl,accurl); | |
309 | } | |
310 | strcpy(oldaccdia,accdia); | |
311 | strcpy(oldacchora,acchora); | |
9bd92830 FM |
312 | } |
313 | fclose(fp_in); | |
314 | longline_destroy(&line); | |
315 | if (oldurltt) free(oldurltt); | |
d8e04f05 FM |
316 | if (oldurl) { |
317 | if(strstr(oldacccode,"DENIED") != 0) | |
318 | strcpy(oldmsg,"DENIED"); | |
319 | else | |
320 | strcpy(oldmsg,"OK"); | |
321 | if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache); | |
322 | gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
323 | free(oldurl); | |
324 | oldurl=NULL; | |
325 | } | |
d8e04f05 | 326 | if(!new_user) { |
026ddd8b | 327 | day_totalize(daystat,tmp,uinfo); |
d8e04f05 FM |
328 | } |
329 | if (fp_tmp) { | |
330 | if (fclose(fp_tmp)==EOF) | |
331 | debuga(_("Failed to close temporary file for user %s - %s\n"),uinfo->filename,strerror(errno)); | |
332 | fp_tmp=NULL; | |
333 | } | |
11767c6a FM |
334 | if (!KeepTempLog && unlink(tmp3)) { |
335 | debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno)); | |
08f9b029 FM |
336 | exit(EXIT_FAILURE); |
337 | } | |
9bd92830 | 338 | } |
93551487 | 339 | userinfo_stopscan(uscan); |
026ddd8b | 340 | day_cleanup(daystat); |
9bd92830 | 341 | |
9dc20988 | 342 | totalger(fp_gen,wdirname); |
9bd92830 | 343 | fclose(fp_gen); |
9bd92830 | 344 | |
9bd92830 | 345 | if(email[0] == '\0') { |
edc276df | 346 | if (!indexonly) { |
9f93fec3 | 347 | if(DansGuardianConf[0] != '\0') |
edc276df | 348 | dansguardian_log(); |
9f93fec3 FM |
349 | else if (debugz) |
350 | debugaz(_("Dansguardian report not produced because no dansguardian configuration file was provided\n")); | |
9bd92830 | 351 | |
330b1c52 | 352 | redirector_log(); |
9a759ea8 | 353 | } |
9bd92830 | 354 | |
9a759ea8 FM |
355 | topuser(); |
356 | ||
357 | if (!indexonly) { | |
5138c1b9 FM |
358 | if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) |
359 | download_report(); | |
360 | else if (debugz) | |
361 | debugaz(_("Downloaded files report not requested in report_type\n")); | |
362 | ||
9f93fec3 FM |
363 | if((ReportType & REPORT_TYPE_TOPSITES) != 0) |
364 | topsites(); | |
365 | else if (debugz) | |
366 | debugaz(_("Top sites report not requested in report_type\n")); | |
367 | ||
368 | if((ReportType & REPORT_TYPE_SITES_USERS) != 0) | |
369 | siteuser(); | |
370 | else if (debugz) | |
371 | debugaz(_("Sites & users report not requested in report_type\n")); | |
1bd73f70 FM |
372 | |
373 | if ((ReportType & REPORT_TYPE_DENIED) != 0) | |
374 | gen_denied_report(); | |
9f93fec3 FM |
375 | else if (debugz) |
376 | debugaz(_("Denied accesses report not requested in report_type\n")); | |
9bd92830 | 377 | |
1bd73f70 FM |
378 | if ((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) |
379 | authfail_report(); | |
9f93fec3 FM |
380 | else if (debugz) |
381 | debugaz(_("Authentication failures report not requested in report_type\n")); | |
9bd92830 | 382 | |
edc276df | 383 | if(smartfilter) smartfilter_report(); |
9bd92830 | 384 | |
9f93fec3 FM |
385 | if(DansGuardianConf[0] != '\0') |
386 | dansguardian_report(); | |
9bd92830 | 387 | |
330b1c52 | 388 | redirector_report(); |
9bd92830 | 389 | |
9f93fec3 FM |
390 | if((ReportType & REPORT_TYPE_USERS_SITES) != 0) |
391 | htmlrel(); | |
392 | else if (debugz) | |
393 | debugaz(_("User's detailed report not requested in report_type\n")); | |
edc276df | 394 | } |
9bd92830 FM |
395 | |
396 | make_index(); | |
397 | ||
398 | if(SuccessfulMsg) debuga(_("Successful report generated on %s\n"),outdirname); | |
399 | } else { | |
400 | geramail(outdirname, debug, outdir, email, tmp); | |
401 | ||
402 | if((strcmp(email,"stdout") != 0) && SuccessfulMsg) | |
403 | debuga(_("Successful report generated and sent to %s\n"),email); | |
404 | } | |
405 | ||
6588b137 | 406 | if(indexonly) index_only(outdirname, debug); |
9bd92830 FM |
407 | |
408 | removetmp(outdirname); | |
409 | return; | |
25697a35 GS |
410 | } |
411 | ||
d8e04f05 | 412 | static FILE *maketmp(const char *user, const char *dirname, int debug) |
25697a35 | 413 | { |
9bd92830 FM |
414 | FILE *fp_ou; |
415 | char wdirname[MAXLEN]; | |
25697a35 | 416 | |
d8e04f05 FM |
417 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return(NULL); |
418 | if((ReportType & REPORT_TYPE_TOPUSERS) == 0) return(NULL); | |
25697a35 | 419 | |
9bd92830 FM |
420 | if(debug) debuga(_("Making file: %s/%s\n"),tmp,user); |
421 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,user)>=sizeof(wdirname)) { | |
422 | debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,user); | |
423 | exit(EXIT_FAILURE); | |
424 | } | |
25697a35 | 425 | |
9bd92830 FM |
426 | if((fp_ou=fopen(wdirname,"w"))==NULL){ |
427 | debuga(_("(report) Cannot open file %s\n"),wdirname); | |
428 | exit(EXIT_FAILURE); | |
429 | } | |
25697a35 | 430 | |
d8e04f05 | 431 | return(fp_ou); |
25697a35 GS |
432 | } |
433 | ||
434 | ||
d8e04f05 | 435 | static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache) |
25697a35 | 436 | { |
9bd92830 FM |
437 | /* |
438 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
439 | to print a long long int unless it is exactly 64-bits long. | |
440 | */ | |
441 | fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)nacc,(uint64_t)nbytes,oldurl,oldmsg,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache); | |
442 | ||
9bd92830 FM |
443 | ttopen=0; |
444 | ||
445 | if(fp_tt) { | |
446 | fputs("</table>\n</div>\n",fp_tt); | |
447 | fputs("</body>\n</html>\n",fp_tt); | |
448 | fclose(fp_tt); | |
449 | fp_tt=NULL; | |
450 | } | |
451 | ||
452 | return; | |
25697a35 GS |
453 | } |
454 | ||
6588b137 | 455 | static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap) |
25697a35 | 456 | { |
9bd92830 FM |
457 | FILE *fp_ou; |
458 | char wdirname[MAXLEN]; | |
25697a35 | 459 | |
6588b137 | 460 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 461 | |
9bd92830 FM |
462 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) { |
463 | debuga(_("Path too long %s/%s.ip\n"),tmp,uinfo->filename); | |
464 | exit(EXIT_FAILURE); | |
465 | } | |
25697a35 | 466 | |
9bd92830 FM |
467 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
468 | debuga(_("(report) Cannot open file %s\n"),wdirname); | |
469 | exit(EXIT_FAILURE); | |
470 | } | |
25697a35 | 471 | |
9bd92830 FM |
472 | /* |
473 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
474 | to print a long long int unless it is exactly 64-bits long. | |
475 | */ | |
476 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%"PRIu64"\t%"PRIu64"\n",ip,url,data,hora,(uint64_t)tam,(uint64_t)elap); | |
25697a35 | 477 | |
9bd92830 | 478 | fclose(fp_ou); |
4157aa09 | 479 | |
9bd92830 | 480 | return; |
25697a35 GS |
481 | } |
482 | ||
483 | ||
9dc20988 | 484 | static void gravager(FILE *fp_gen,const char *filename, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache) |
25697a35 | 485 | { |
9bd92830 FM |
486 | /* |
487 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
488 | to print a long long int unless it is exactly 64-bits long. | |
489 | */ | |
9dc20988 FM |
490 | if (fprintf(fp_gen,"%s\t%"PRIu64"\t%"PRIu64"\t%s\t%s\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",uinfo->id,(uint64_t)nacc,(uint64_t)nbytes,url,ip,hora,dia,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache)<0) { |
491 | debuga(_("Failed to write a line in %s\n"),filename); | |
492 | exit(EXIT_FAILURE); | |
493 | } | |
494 | ||
495 | globstat.nacc+=nacc; | |
496 | globstat.nbytes+=nbytes; | |
497 | globstat.elap+=nelap; | |
498 | globstat.incache+=incache; | |
499 | globstat.oucache+=oucache; | |
9bd92830 | 500 | return; |
25697a35 GS |
501 | } |
502 | ||
9dc20988 FM |
503 | /*! |
504 | Write the total line at the end of the general file. | |
505 | */ | |
506 | void totalger(FILE *fp_gen,const char *filename) | |
507 | { | |
508 | /* | |
509 | This complicated printf is due to Microsoft's inability to comply with any standard. Msvcrt is unable | |
510 | to print a long long int unless it is exactly 64-bits long. | |
511 | */ | |
512 | if (fprintf(fp_gen,"TOTAL\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)globstat.nacc,(uint64_t)globstat.nbytes,(uint64_t)globstat.elap,(uint64_t)globstat.incache,(uint64_t)globstat.oucache)<0) { | |
513 | debuga(_("Failed to write the total line in %s\n"),filename); | |
514 | exit(EXIT_FAILURE); | |
515 | } | |
516 | } | |
517 | ||
2240dcea FM |
518 | int ger_read(char *buffer,struct generalitemstruct *item,const char *filename) |
519 | { | |
9bd92830 FM |
520 | int i; |
521 | int sign; | |
522 | long long int number; | |
523 | ||
524 | if (strncmp(buffer,"TOTAL\t",6)==0) { | |
525 | item->total=1; | |
526 | buffer+=6; | |
527 | ||
528 | sign=+1; | |
529 | if (*buffer == '-') { | |
530 | buffer++; | |
531 | sign=-1; | |
532 | } else if (*buffer == '+') { | |
533 | buffer++; | |
534 | } | |
535 | number=0LL; | |
536 | while (isdigit(*buffer)) | |
537 | number=(number * 10) + (*buffer++)-'0'; | |
538 | if (*buffer!='\t') { | |
539 | debuga(_("Invalid total number of accesses in %s\n"),filename); | |
540 | exit(EXIT_FAILURE); | |
541 | } | |
542 | buffer++; | |
543 | item->nacc=number*sign; | |
544 | ||
545 | sign=+1; | |
546 | if (*buffer == '-') { | |
547 | buffer++; | |
548 | sign=-1; | |
549 | } else if (*buffer == '+') { | |
550 | buffer++; | |
551 | } | |
552 | number=0LL; | |
553 | while (isdigit(*buffer)) | |
554 | number=(number * 10) + (*buffer++)-'0'; | |
555 | if (*buffer!='\t') { | |
556 | debuga(_("Invalid total size in %s\n"),filename); | |
557 | exit(EXIT_FAILURE); | |
558 | } | |
559 | buffer++; | |
560 | item->nbytes=number*sign; | |
561 | ||
562 | sign=+1; | |
563 | if (*buffer == '-') { | |
564 | buffer++; | |
565 | sign=-1; | |
566 | } else if (*buffer == '+') { | |
567 | buffer++; | |
568 | } | |
569 | number=0LL; | |
570 | while (isdigit(*buffer)) | |
571 | number=(number * 10) + (*buffer++)-'0'; | |
572 | if (*buffer!='\t') { | |
573 | debuga(_("Invalid total elapsed time in %s\n"),filename); | |
574 | exit(EXIT_FAILURE); | |
575 | } | |
576 | buffer++; | |
577 | item->nelap=number*sign; | |
578 | ||
579 | sign=+1; | |
580 | if (*buffer == '-') { | |
581 | buffer++; | |
582 | sign=-1; | |
583 | } else if (*buffer == '+') { | |
584 | buffer++; | |
585 | } | |
586 | number=0LL; | |
587 | while (isdigit(*buffer)) | |
588 | number=(number * 10) + (*buffer++)-'0'; | |
589 | if (*buffer!='\t') { | |
590 | debuga(_("Invalid total cache hit in %s\n"),filename); | |
591 | exit(EXIT_FAILURE); | |
592 | } | |
593 | buffer++; | |
594 | item->incache=number*sign; | |
595 | ||
596 | sign=+1; | |
597 | if (*buffer == '-') { | |
598 | buffer++; | |
599 | sign=-1; | |
600 | } else if (*buffer == '+') { | |
601 | buffer++; | |
602 | } | |
603 | number=0LL; | |
604 | while (isdigit(*buffer)) | |
605 | number=(number * 10) + (*buffer++)-'0'; | |
606 | if (*buffer!='\0') { | |
607 | debuga(_("Invalid total cache miss in %s\n"),filename); | |
608 | exit(EXIT_FAILURE); | |
609 | } | |
610 | item->oucache=number*sign; | |
611 | } else { | |
612 | item->total=0; | |
613 | ||
614 | item->user=buffer; | |
615 | for (i=0 ; i<MAX_USER_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
616 | if (*buffer!='\t') { | |
617 | debuga(_("User name too long or invalid in %s\n"),filename); | |
618 | exit(EXIT_FAILURE); | |
619 | } | |
620 | *buffer++='\0'; | |
621 | ||
622 | sign=+1; | |
623 | if (*buffer == '-') { | |
624 | buffer++; | |
625 | sign=-1; | |
626 | } else if (*buffer == '+') { | |
627 | buffer++; | |
628 | } | |
629 | number=0LL; | |
630 | while (isdigit(*buffer)) | |
631 | number=(number * 10) + (*buffer++)-'0'; | |
632 | if (*buffer!='\t') { | |
633 | debuga(_("Invalid number of accesses in %s\n"),filename); | |
634 | exit(EXIT_FAILURE); | |
635 | } | |
636 | buffer++; | |
637 | item->nacc=number*sign; | |
638 | ||
639 | sign=+1; | |
640 | if (*buffer == '-') { | |
641 | buffer++; | |
642 | sign=-1; | |
643 | } else if (*buffer == '+') { | |
644 | buffer++; | |
645 | } | |
646 | number=0LL; | |
647 | while (isdigit(*buffer)) | |
648 | number=(number * 10) + (*buffer++)-'0'; | |
649 | if (*buffer!='\t') { | |
650 | debuga(_("Invalid number of bytes in %s\n"),filename); | |
651 | exit(EXIT_FAILURE); | |
652 | } | |
653 | buffer++; | |
654 | item->nbytes=number*sign; | |
655 | ||
656 | item->url=buffer; | |
657 | while ((unsigned char)*buffer>=' ') buffer++; | |
658 | if (*buffer!='\t') { | |
659 | debuga(_("URL too long or invalid in %s\n"),filename); | |
660 | exit(EXIT_FAILURE); | |
661 | } | |
662 | *buffer++='\0'; | |
663 | ||
664 | item->ip=buffer; | |
665 | for (i=0 ; i<MAX_IP_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
666 | if (*buffer!='\t') { | |
667 | debuga(_("IP address too long or invalid in %s\n"),filename); | |
668 | exit(EXIT_FAILURE); | |
669 | } | |
670 | *buffer++='\0'; | |
671 | ||
672 | item->time=buffer; | |
673 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
674 | if (*buffer!='\t') { | |
675 | debuga(_("Time too long or invalid in %s\n"),filename); | |
676 | exit(EXIT_FAILURE); | |
677 | } | |
678 | *buffer++='\0'; | |
679 | ||
680 | item->date=buffer; | |
681 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
682 | if (*buffer!='\t') { | |
683 | debuga(_("Date too long or invalid in %s\n"),filename); | |
684 | exit(EXIT_FAILURE); | |
685 | } | |
686 | *buffer++='\0'; | |
687 | ||
688 | sign=+1; | |
689 | if (*buffer == '-') { | |
690 | buffer++; | |
691 | sign=-1; | |
692 | } else if (*buffer == '+') { | |
693 | buffer++; | |
694 | } | |
695 | number=0LL; | |
696 | while (isdigit(*buffer)) | |
697 | number=(number * 10) + (*buffer++)-'0'; | |
698 | if (*buffer!='\t') { | |
699 | debuga(_("Invalid elapsed time in %s\n"),filename); | |
700 | exit(EXIT_FAILURE); | |
701 | } | |
702 | buffer++; | |
703 | item->nelap=number*sign; | |
704 | ||
705 | sign=+1; | |
706 | if (*buffer == '-') { | |
707 | buffer++; | |
708 | sign=-1; | |
709 | } else if (*buffer == '+') { | |
710 | buffer++; | |
711 | } | |
712 | number=0LL; | |
713 | while (isdigit(*buffer)) | |
714 | number=(number * 10) + (*buffer++)-'0'; | |
715 | if (*buffer!='\t') { | |
716 | debuga(_("Invalid cache hit size in %s\n"),filename); | |
717 | exit(EXIT_FAILURE); | |
718 | } | |
719 | buffer++; | |
720 | item->incache=number*sign; | |
721 | ||
722 | sign=+1; | |
723 | if (*buffer == '-') { | |
724 | buffer++; | |
725 | sign=-1; | |
726 | } else if (*buffer == '+') { | |
727 | buffer++; | |
728 | } | |
729 | number=0LL; | |
730 | while (isdigit(*buffer)) | |
731 | number=(number * 10) + (*buffer++)-'0'; | |
732 | if (*buffer!='\0') { | |
733 | debuga(_("Invalid cache miss size in %s\n"),filename); | |
734 | exit(EXIT_FAILURE); | |
735 | } | |
736 | item->oucache=number*sign; | |
737 | } | |
738 | return(0); | |
2240dcea FM |
739 | } |
740 | ||
5160b452 | 741 | static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart) |
25697a35 | 742 | { |
9bd92830 FM |
743 | FILE *fp_ou; |
744 | char wdirname[MAXLEN]; | |
25697a35 | 745 | |
1caa1b3d | 746 | if (snprintf(wdirname,sizeof(wdirname),"%s/smartfilter.int_unsort",dirname)>=sizeof(wdirname)) { |
49bc6358 | 747 | debuga(_("File name too long for %s/smartfilter.int_unsort\n"),dirname); |
1caa1b3d FM |
748 | exit(EXIT_FAILURE); |
749 | } | |
25697a35 | 750 | |
9bd92830 FM |
751 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
752 | debuga(_("(report) Cannot open file %s\n"),wdirname); | |
753 | exit(EXIT_FAILURE); | |
754 | } | |
25697a35 | 755 | |
9bd92830 FM |
756 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart); |
757 | fputs("</body>\n</html>\n",fp_tt); | |
25697a35 | 758 | |
9bd92830 | 759 | fclose(fp_ou); |
25697a35 | 760 | |
9bd92830 | 761 | return; |
25697a35 | 762 | } |