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