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