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