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