]>
Commit | Line | Data |
---|---|---|
25697a35 | 1 | /* |
94ff9470 | 2 | * SARG Squid Analysis Report Generator http://sarg.sourceforge.net |
1164c474 | 3 | * 1998, 2010 |
25697a35 GS |
4 | * |
5 | * SARG donations: | |
6 | * please look at http://sarg.sourceforge.net/donations.php | |
1164c474 FM |
7 | * Support: |
8 | * http://sourceforge.net/projects/sarg/forums/forum/363374 | |
25697a35 GS |
9 | * --------------------------------------------------------------------- |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or | |
14 | * (at your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | * GNU General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "include/conf.h" | |
28 | #include "include/defs.h" | |
29 | ||
e5b2c6f0 FM |
30 | static FILE *fp_tt=NULL; |
31 | ||
5f3cfd1d FM |
32 | static void maketmp(const char *user, const char *dirname, int debug, int indexonly); |
33 | static void maketmp_hour(const char *user, const char *dirname, int indexonly); | |
f2ec8c75 FM |
34 | static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); |
35 | static void gravatmpf(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); | |
36 | 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, int indexonly); | |
37 | static void gravager(FILE *fp_gen, 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 | 38 | 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 | 39 | |
32e71fa4 | 40 | void gerarel(void) |
25697a35 GS |
41 | { |
42 | ||
d6e703cc | 43 | FILE *fp_in; |
0a4e18e1 | 44 | FILE *fp_gen; |
25697a35 | 45 | |
ac422f9b | 46 | char *buf; |
f2ec8c75 | 47 | char accdia[11], acchora[9], accip[MAXLEN], *accurl; |
e6414a9d | 48 | char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN]; |
f2ec8c75 | 49 | char wdirname[MAXLEN]; |
e5b2c6f0 | 50 | char *oldurl=NULL; |
f2ec8c75 | 51 | char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAX_USER_LEN]; |
4157aa09 | 52 | char ipantes[MAXLEN], nameantes[MAXLEN]; |
25697a35 | 53 | char accsmart[MAXLEN]; |
623c04aa | 54 | char crc2[MAXLEN/2 -1]; |
e5b2c6f0 | 55 | char siteind[MAX_TRUNCATED_URL]; |
ac422f9b | 56 | char arqtt[256]; |
e5b2c6f0 FM |
57 | char *oldurltt=NULL; |
58 | char oldaccdiatt[11],oldacchoratt[9]; | |
2240dcea FM |
59 | char tmp3[MAXLEN]; |
60 | char tmp4[5]; | |
f2ec8c75 | 61 | char u2[MAX_USER_LEN]; |
4157aa09 FM |
62 | long long int nbytes=0; |
63 | long long int nelap=0; | |
25697a35 GS |
64 | long long int nacc=0; |
65 | long long int rtotal=0; | |
66 | long long int incache=0; | |
67 | long long int oucache=0; | |
6e792ade | 68 | long long int accbytes, accelap; |
9c7c6346 | 69 | char *str; |
25697a35 GS |
70 | DIR *dirp; |
71 | struct dirent *direntp; | |
8db846b0 FM |
72 | const char logext[]=".log"; |
73 | int dlen; | |
e5b2c6f0 FM |
74 | int url_len; |
75 | int ourl_size=0; | |
76 | int ourltt_size=0; | |
1bafebef | 77 | int same_url; |
f2ec8c75 | 78 | int new_user; |
9c7c6346 | 79 | struct getwordstruct gwarea; |
afaa3b67 | 80 | longline line; |
f2ec8c75 | 81 | struct userinfostruct *uinfo,*puinfo; |
25697a35 GS |
82 | |
83 | ipantes[0]='\0'; | |
25697a35 GS |
84 | smartfilter=0; |
85 | ||
fa6552b0 FM |
86 | if (vrfydir(&period, addr, site, us, email)<0) { |
87 | debuga(_("Cannot create the output directory name containing the period as part of the name\n")); | |
88 | exit(EXIT_FAILURE); | |
89 | } | |
25697a35 GS |
90 | |
91 | if(debugz){ | |
d5d021c5 | 92 | debugaz("outdirname",outdirname); |
25697a35 | 93 | } |
48864d28 | 94 | |
4157aa09 | 95 | if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); |
25697a35 | 96 | |
d5d021c5 | 97 | snprintf(wdirname,sizeof(wdirname),"%s/sarg-general",outdirname); |
1bafebef | 98 | if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){ |
d574e592 | 99 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 100 | exit(EXIT_FAILURE); |
0a4e18e1 FM |
101 | } |
102 | ||
f2ec8c75 | 103 | puinfo=NULL; |
25697a35 | 104 | strncat(tmp,"/sarg",5); |
e5b2c6f0 | 105 | fp_tt=NULL; |
25697a35 | 106 | |
e21b6c02 FM |
107 | if ((dirp = opendir(tmp)) == NULL) { |
108 | debuga(_("Failed to open directory %s - %s\n"),tmp,strerror(errno)); | |
109 | exit(EXIT_FAILURE); | |
110 | } | |
25697a35 | 111 | while ((direntp = readdir( dirp )) != NULL ) { |
8db846b0 FM |
112 | dlen=strlen(direntp->d_name)-(sizeof(logext)-1); |
113 | if (dlen<0) continue; | |
114 | if((strcmp(direntp->d_name+dlen,logext) != 0) || | |
d6e703cc FM |
115 | (strncmp(direntp->d_name,"download.log",12) == 0) || |
116 | (strncmp(direntp->d_name,"denied.log",10) == 0) || | |
5f3cfd1d | 117 | (strncmp(direntp->d_name,"authfail.log.unsort",19) == 0)) |
25697a35 | 118 | continue; |
8db846b0 | 119 | if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) { |
bc877ad2 | 120 | debuga(_("(report) directory entry too long: %s/%s\n"),tmp,direntp->d_name); |
06b39c87 | 121 | exit(EXIT_FAILURE); |
25697a35 | 122 | } |
b6d3adea | 123 | if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){ |
bc877ad2 | 124 | debuga(_("(report) Cannot open file %s\n"),tmp); |
06b39c87 | 125 | exit(EXIT_FAILURE); |
4bcb77cf | 126 | } |
48864d28 | 127 | |
8db846b0 FM |
128 | if (dlen>0) { |
129 | if (dlen>=sizeof(user)) continue; | |
130 | strncpy(user,direntp->d_name,dlen); | |
131 | user[dlen]=0; | |
132 | } else { | |
133 | user[0]='\0'; | |
25697a35 | 134 | } |
48864d28 | 135 | |
f2ec8c75 FM |
136 | uinfo=userinfo_find_from_file(user); |
137 | if (!uinfo) { | |
10210234 | 138 | debuga(_("Ignoring unknown user file %s\n"),user); |
f2ec8c75 FM |
139 | continue; |
140 | } | |
141 | strcpy(u2,uinfo->id); | |
72c27633 FM |
142 | if(Ip2Name && uinfo->id_is_ip) { |
143 | strcpy(ipantes,u2); | |
144 | ip2name(u2,sizeof(u2)); | |
145 | strcpy(nameantes,u2); | |
146 | } | |
f2ec8c75 FM |
147 | user_find(uinfo->label,MAX_USER_LEN, u2); |
148 | ||
25697a35 GS |
149 | maketmp(user,tmp,debug,indexonly); |
150 | maketmp_hour(user,tmp,indexonly); | |
48864d28 | 151 | |
25697a35 | 152 | ttopen=0; |
e5b2c6f0 FM |
153 | oldurltt=NULL; |
154 | ourltt_size=0; | |
ac422f9b FM |
155 | memset(oldaccdiatt,0,sizeof(oldaccdiatt)); |
156 | memset(oldacchoratt,0,sizeof(oldacchoratt)); | |
f2ec8c75 | 157 | new_user=1; |
48864d28 | 158 | |
afaa3b67 | 159 | if ((line=longline_create())==NULL) { |
10210234 | 160 | debuga(_("Not enough memory to read the downloaded files\n")); |
06b39c87 | 161 | exit(EXIT_FAILURE); |
ac422f9b FM |
162 | } |
163 | ||
afaa3b67 | 164 | while((buf=longline_read(fp_in,line))!=NULL) { |
9c7c6346 FM |
165 | getword_start(&gwarea,buf); |
166 | if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || | |
f2ec8c75 | 167 | getword(accip,sizeof(accip),&gwarea,'\t')<0 || |
e5b2c6f0 | 168 | getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || |
9c7c6346 | 169 | getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { |
10210234 | 170 | debuga(_("There is a broken record or garbage in file %s\n"),tmp3); |
06b39c87 | 171 | exit(EXIT_FAILURE); |
4bcb77cf | 172 | } |
d6e703cc | 173 | if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; |
e34a7c98 | 174 | if (getword_atoll(&accelap,&gwarea,'\t')<0) { |
10210234 | 175 | debuga(_("There is a broken elapsed time in file %s\n"),tmp3); |
06b39c87 | 176 | exit(EXIT_FAILURE); |
e6414a9d | 177 | } |
e34a7c98 | 178 | if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { |
10210234 | 179 | debuga(_("There is a broken smart info in file %s\n"),tmp3); |
06b39c87 | 180 | exit(EXIT_FAILURE); |
4bcb77cf | 181 | } |
48864d28 | 182 | |
4157aa09 | 183 | if(accsmart[0] != '\0') { |
25697a35 | 184 | smartfilter++; |
d5d021c5 | 185 | grava_SmartFilter(outdirname,uinfo->id,accip,accdia,acchora,accurl,accsmart); |
25697a35 GS |
186 | } |
187 | ||
246c8489 | 188 | if(Ip2Name) { |
25697a35 GS |
189 | if(strcmp(accip,ipantes) != 0) { |
190 | strcpy(ipantes,accip); | |
a1c55d8c | 191 | ip2name(accip,sizeof(accip)); |
25697a35 GS |
192 | strcpy(nameantes,accip); |
193 | } else strcpy(accip,nameantes); | |
194 | } | |
48864d28 | 195 | |
d5d021c5 | 196 | gravatmp_hora(outdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly); |
25697a35 GS |
197 | |
198 | if(iprel){ | |
d5d021c5 | 199 | gravaporuser(uinfo,outdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); |
25697a35 GS |
200 | } |
201 | ||
202 | if(!rtotal){ | |
e5b2c6f0 FM |
203 | url_len=strlen(accurl); |
204 | if (!oldurl || url_len>=ourl_size) { | |
205 | ourl_size=url_len+1; | |
206 | oldurl=realloc(oldurl,ourl_size); | |
207 | if (!oldurl) { | |
10210234 | 208 | debuga(_("Not enough memory to store the url\n")); |
06b39c87 | 209 | exit(EXIT_FAILURE); |
e5b2c6f0 FM |
210 | } |
211 | } | |
25697a35 GS |
212 | strcpy(oldurl,accurl); |
213 | strcpy(oldacccode,acccode); | |
f2ec8c75 | 214 | puinfo=uinfo; |
25697a35 GS |
215 | strcpy(oldaccip,accip); |
216 | strcpy(oldaccdia,accdia); | |
217 | strcpy(oldacchora,acchora); | |
f2ec8c75 | 218 | new_user=0; |
25697a35 GS |
219 | rtotal++; |
220 | } | |
1bafebef | 221 | same_url=(strcmp(oldurl,accurl) == 0); |
25697a35 GS |
222 | |
223 | if(site[0] != '\0') { | |
f2ec8c75 | 224 | if(new_user){ |
25697a35 | 225 | if(strstr(oldacccode,"DENIED") != 0) |
94558017 FM |
226 | strcpy(oldmsg,"DENIED"); |
227 | else | |
228 | strcpy(oldmsg,"OK"); | |
f2ec8c75 FM |
229 | gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
230 | gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
25697a35 GS |
231 | nacc=0; |
232 | nbytes=0; | |
233 | nelap=0; | |
234 | incache=0; | |
235 | oucache=0; | |
236 | } | |
5f3cfd1d | 237 | } else { |
f2ec8c75 | 238 | if(!same_url || new_user){ |
25697a35 | 239 | if(strstr(oldacccode,"DENIED") != 0) |
94558017 | 240 | strcpy(oldmsg,"DENIED"); |
ac422f9b FM |
241 | else |
242 | strcpy(oldmsg,"OK"); | |
f2ec8c75 FM |
243 | gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
244 | gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
25697a35 GS |
245 | nacc=0; |
246 | nbytes=0; | |
247 | nelap=0; | |
248 | incache=0; | |
249 | oucache=0; | |
32e71fa4 | 250 | } |
5f3cfd1d FM |
251 | } |
252 | nacc++; | |
6e792ade FM |
253 | nbytes+=accbytes; |
254 | nelap+=accelap; | |
5f3cfd1d | 255 | |
ac422f9b | 256 | if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0 && |
e5b2c6f0 | 257 | (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) { |
ac422f9b | 258 | |
5f3cfd1d | 259 | if(!ttopen) { |
e5b2c6f0 | 260 | url_to_file(accurl,siteind,sizeof(siteind)); |
d5d021c5 | 261 | snprintf(arqtt,sizeof(arqtt),"%s/%s",outdirname,uinfo->filename); |
5f3cfd1d FM |
262 | if(access(arqtt, R_OK) != 0) |
263 | my_mkdir(arqtt); | |
d5d021c5 | 264 | snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind); |
5f3cfd1d | 265 | if ((fp_tt = fopen(arqtt, "w")) == 0) { |
bc877ad2 | 266 | debuga(_("(report) Cannot open file %s\n"),arqtt); |
06b39c87 | 267 | exit(EXIT_FAILURE); |
5f3cfd1d FM |
268 | } |
269 | ttopen=1; | |
270 | ||
24977ddb | 271 | /* |
e6414a9d | 272 | if(Privacy) |
5f3cfd1d FM |
273 | sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s", \ |
274 | FontSize,PrivacyStringColor,PrivacyString,PrivacyString); | |
275 | else | |
4157aa09 | 276 | sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl); |
24977ddb | 277 | */ |
5f3cfd1d | 278 | |
c0ec9cc7 | 279 | write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report")); |
94558017 FM |
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 | fprintf(fp_tt,"<tr><td class=\"header_c\">%s: %s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder); | |
c36c7384 | 283 | fprintf(fp_tt,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User")); |
c0ec9cc7 FM |
284 | close_html_header(fp_tt); |
285 | ||
286 | fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt); | |
c36c7384 | 287 | strncpy(tmp4,_("DATE/TIME"),4); |
2240dcea | 288 | tmp4[4]='\0'; |
c36c7384 | 289 | fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("ACCESSED SITE"),tmp4,_("DATE/TIME")+5); |
94ff9470 GS |
290 | } |
291 | ||
e5b2c6f0 FM |
292 | fputs("<tr><td class=\"data\">",fp_tt); |
293 | output_html_string(fp_tt,accurl,100); | |
294 | fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora); | |
25697a35 | 295 | |
e5b2c6f0 FM |
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) { | |
10210234 | 301 | debuga(_("Not enough memory to store the url\n")); |
06b39c87 | 302 | exit(EXIT_FAILURE); |
e5b2c6f0 FM |
303 | } |
304 | } | |
ac422f9b FM |
305 | strcpy(oldurltt,accurl); |
306 | strcpy(oldaccdiatt,accdia); | |
307 | strcpy(oldacchoratt,acchora); | |
308 | } | |
25697a35 | 309 | |
9c7c6346 FM |
310 | strcpy(crc2,acccode); |
311 | str=strchr(crc2,'/'); | |
312 | if (str) *str='\0'; | |
5f3cfd1d | 313 | if(strstr(crc2,"MISS") != 0) |
6e792ade FM |
314 | oucache+=accbytes; |
315 | else incache+=accbytes; | |
25697a35 | 316 | |
f2ec8c75 FM |
317 | if(new_user) { |
318 | new_user=0; | |
f2ec8c75 | 319 | day_totalize(tmp,puinfo,indexonly); |
5f3cfd1d FM |
320 | } |
321 | ||
f2ec8c75 | 322 | puinfo=uinfo; |
5f3cfd1d | 323 | strcpy(oldacccode,acccode); |
5f3cfd1d | 324 | strcpy(oldaccip,accip); |
1bafebef FM |
325 | if (!same_url) { |
326 | url_len=strlen(accurl); | |
327 | if (url_len>=ourl_size) { | |
328 | ourl_size=url_len+1; | |
329 | oldurl=realloc(oldurl,ourl_size); | |
330 | if (!oldurl) { | |
10210234 | 331 | debuga(_("Not enough memory to store the url\n")); |
06b39c87 | 332 | exit(EXIT_FAILURE); |
1bafebef | 333 | } |
e5b2c6f0 | 334 | } |
1bafebef | 335 | strcpy(oldurl,accurl); |
e5b2c6f0 | 336 | } |
5f3cfd1d FM |
337 | strcpy(oldaccdia,accdia); |
338 | strcpy(oldacchora,acchora); | |
25697a35 | 339 | |
5f3cfd1d | 340 | } |
5f3cfd1d | 341 | fclose(fp_in); |
afaa3b67 | 342 | longline_destroy(&line); |
e5b2c6f0 | 343 | if (oldurltt) free(oldurltt); |
1bafebef | 344 | unlink(tmp3); |
25697a35 | 345 | } |
05b90947 | 346 | closedir(dirp); |
25697a35 | 347 | |
e5b2c6f0 FM |
348 | if (oldurl) { |
349 | if(strstr(oldacccode,"DENIED") != 0) | |
94558017 | 350 | strcpy(oldmsg,"DENIED"); |
e5b2c6f0 FM |
351 | else |
352 | strcpy(oldmsg,"OK"); | |
f2ec8c75 | 353 | gravatmpf(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
f2ec8c75 | 354 | gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); |
e5b2c6f0 FM |
355 | free(oldurl); |
356 | } | |
0a4e18e1 | 357 | fclose(fp_gen); |
f2ec8c75 | 358 | if (puinfo) day_totalize(tmp,puinfo,indexonly); |
25697a35 GS |
359 | |
360 | tmpsort(); | |
361 | ||
d5d021c5 | 362 | totalger(outdirname, debug, outdir); |
25697a35 | 363 | |
5542cb59 | 364 | if(email[0] == '\0') { |
085c1e1f | 365 | if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report(); |
25697a35 | 366 | |
65740c50 | 367 | if(DansGuardianConf[0] != '\0') { |
25697a35 GS |
368 | dansguardian_log(); |
369 | } | |
370 | ||
491b862f | 371 | squidguard_log(); |
25697a35 | 372 | |
25697a35 GS |
373 | topuser(); |
374 | ||
085c1e1f | 375 | if((ReportType & REPORT_TYPE_TOPSITES) != 0) topsites(); |
25697a35 | 376 | |
085c1e1f | 377 | if((ReportType & REPORT_TYPE_SITES_USERS) != 0) siteuser(); |
25697a35 GS |
378 | gen_denied_report(); |
379 | ||
25697a35 GS |
380 | authfail_report(); |
381 | ||
d6e703cc | 382 | if(smartfilter) smartfilter_report(); |
25697a35 | 383 | |
65740c50 | 384 | if(DansGuardianConf[0] != '\0') dansguardian_report(); |
25697a35 | 385 | |
491b862f | 386 | squidguard_report(); |
25697a35 | 387 | |
085c1e1f | 388 | if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel(); |
25697a35 | 389 | |
491b862f | 390 | make_index(); |
25697a35 | 391 | |
d5d021c5 | 392 | if(SuccessfulMsg) debuga(_("Successful report generated on %s\n"),outdirname); |
25697a35 | 393 | } else { |
2824ec9b | 394 | geramail(outdirname, debug, outdir, email, TempDir); |
25697a35 | 395 | |
e6414a9d | 396 | if((strcmp(email,"stdout") != 0) && SuccessfulMsg) |
d5d021c5 | 397 | debuga(_("Successful report generated and sent to %s\n"),email); |
25697a35 GS |
398 | } |
399 | ||
400 | if(indexonly) { | |
d5d021c5 | 401 | index_only(outdirname, debug); |
25697a35 GS |
402 | } |
403 | ||
c274f011 FM |
404 | /* |
405 | 2009-10-13(Frederic) This piece of code is never called so it is commented out for good. | |
d6e703cc FM |
406 | if(strlen(email) < 0) |
407 | removetmp(dirname); | |
c274f011 | 408 | */ |
25697a35 GS |
409 | |
410 | return; | |
411 | } | |
412 | ||
5f3cfd1d | 413 | static void maketmp(const char *user, const char *dirname, int debug, int indexonly) |
25697a35 GS |
414 | { |
415 | ||
416 | FILE *fp_ou; | |
417 | ||
418 | char wdirname[MAXLEN]; | |
419 | ||
420 | if(indexonly) return; | |
085c1e1f | 421 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 422 | |
10210234 | 423 | if(debug) debuga(_("Making file: %s/%s\n"),tmp,user); |
2240dcea | 424 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,user)>=sizeof(wdirname)) { |
10210234 | 425 | debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,user); |
06b39c87 | 426 | exit(EXIT_FAILURE); |
25697a35 GS |
427 | } |
428 | ||
25697a35 | 429 | if((fp_ou=fopen(wdirname,"w"))==NULL){ |
d574e592 | 430 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 431 | exit(EXIT_FAILURE); |
25697a35 GS |
432 | } |
433 | ||
434 | fclose(fp_ou); | |
435 | return; | |
436 | } | |
437 | ||
438 | ||
5f3cfd1d | 439 | static void maketmp_hour(const char *user, const char *dirname, int indexonly) |
25697a35 GS |
440 | { |
441 | ||
442 | FILE *fp_ou; | |
443 | ||
444 | char wdirname[MAXLEN]; | |
445 | ||
446 | if(indexonly) return; | |
085c1e1f | 447 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 448 | |
2240dcea | 449 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { |
10210234 | 450 | debuga(_("Temporary file name too long: %s/%s.htmp\n"),tmp,user); |
06b39c87 | 451 | exit(EXIT_FAILURE); |
2240dcea | 452 | } |
25697a35 | 453 | |
25697a35 | 454 | if((fp_ou=fopen(wdirname,"w"))==NULL){ |
d574e592 | 455 | debuga(_("(report-1) Cannot open file %s - %s\n"),wdirname,strerror(errno)); |
06b39c87 | 456 | exit(EXIT_FAILURE); |
25697a35 GS |
457 | } |
458 | ||
459 | fclose(fp_ou); | |
460 | return; | |
461 | } | |
462 | ||
463 | ||
f2ec8c75 | 464 | void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) |
25697a35 | 465 | { |
25697a35 | 466 | FILE *fp_ou; |
25697a35 GS |
467 | char wdirname[MAXLEN]; |
468 | ||
469 | if(indexonly) return; | |
085c1e1f | 470 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 471 | |
f2ec8c75 | 472 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 473 | debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,uinfo->filename); |
06b39c87 | 474 | exit(EXIT_FAILURE); |
0a4e18e1 | 475 | } |
25697a35 | 476 | |
b6d3adea | 477 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
d574e592 | 478 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 479 | exit(EXIT_FAILURE); |
4157aa09 | 480 | } |
25697a35 | 481 | |
e5b2c6f0 | 482 | fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache); |
25697a35 GS |
483 | |
484 | fclose(fp_ou); | |
485 | ttopen=0; | |
486 | ||
487 | if(fp_tt) { | |
c0ec9cc7 | 488 | fputs("</table>\n</div>\n",fp_tt); |
25697a35 GS |
489 | fputs("</body>\n</html>\n",fp_tt); |
490 | fclose(fp_tt); | |
e5b2c6f0 | 491 | fp_tt=NULL; |
25697a35 GS |
492 | } |
493 | ||
494 | return; | |
25697a35 GS |
495 | } |
496 | ||
f2ec8c75 | 497 | static void gravatmpf(const struct userinfostruct *uinfo,const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) |
25697a35 | 498 | { |
25697a35 | 499 | FILE *fp_ou; |
25697a35 GS |
500 | char wdirname[MAXLEN]; |
501 | ||
f2ec8c75 | 502 | if(indexonly || (ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 503 | |
f2ec8c75 | 504 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 505 | debuga(_("Path too long %s/%s.utmp\n"),tmp,uinfo->filename); |
06b39c87 | 506 | exit(EXIT_FAILURE); |
0a4e18e1 | 507 | } |
25697a35 | 508 | |
b6d3adea | 509 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
d574e592 | 510 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 511 | exit(EXIT_FAILURE); |
25697a35 GS |
512 | } |
513 | ||
f2ec8c75 | 514 | fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache); |
25697a35 GS |
515 | |
516 | fclose(fp_ou); | |
f2ec8c75 FM |
517 | ttopen=0; |
518 | ||
519 | if(fp_tt) { | |
520 | fputs("</table>\n",fp_tt); | |
521 | fputs("</body>\n</html>\n",fp_tt); | |
522 | fclose(fp_tt); | |
523 | fp_tt=NULL; | |
524 | } | |
25697a35 GS |
525 | |
526 | return; | |
527 | } | |
528 | ||
529 | ||
f2ec8c75 | 530 | static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) |
25697a35 GS |
531 | { |
532 | ||
533 | FILE *fp_ou; | |
25697a35 GS |
534 | char wdirname[MAXLEN]; |
535 | ||
085c1e1f | 536 | if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; |
25697a35 | 537 | |
f2ec8c75 | 538 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 539 | debuga(_("Path too long %s/%s.htmp\n"),tmp,uinfo->filename); |
06b39c87 | 540 | exit(EXIT_FAILURE); |
0a4e18e1 | 541 | } |
25697a35 | 542 | |
b6d3adea | 543 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
d574e592 | 544 | debuga(_("(report-2) Cannot open file %s - %s\n"),wdirname,strerror(errno)); |
06b39c87 | 545 | exit(EXIT_FAILURE); |
4157aa09 | 546 | } |
25697a35 | 547 | |
f2ec8c75 FM |
548 | if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); |
549 | else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); | |
25697a35 GS |
550 | |
551 | fclose(fp_ou); | |
552 | ||
553 | return; | |
25697a35 GS |
554 | } |
555 | ||
556 | ||
f2ec8c75 | 557 | 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, int indexonly) |
25697a35 GS |
558 | { |
559 | ||
560 | FILE *fp_ou; | |
25697a35 GS |
561 | char wdirname[MAXLEN]; |
562 | ||
085c1e1f | 563 | if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; |
25697a35 | 564 | |
f2ec8c75 | 565 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 566 | debuga(_("Path too long %s/%s.ip\n"),tmp,uinfo->filename); |
06b39c87 | 567 | exit(EXIT_FAILURE); |
0a4e18e1 | 568 | } |
25697a35 | 569 | |
b6d3adea | 570 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
d574e592 | 571 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 572 | exit(EXIT_FAILURE); |
25697a35 GS |
573 | } |
574 | ||
f2ec8c75 | 575 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); |
25697a35 GS |
576 | |
577 | fclose(fp_ou); | |
25697a35 GS |
578 | |
579 | return; | |
4157aa09 | 580 | |
25697a35 GS |
581 | } |
582 | ||
583 | ||
f2ec8c75 | 584 | static void gravager(FILE *fp_gen, 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 | 585 | { |
f2ec8c75 | 586 | fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",uinfo->id,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache); |
25697a35 | 587 | return; |
25697a35 GS |
588 | } |
589 | ||
2240dcea FM |
590 | int ger_read(char *buffer,struct generalitemstruct *item,const char *filename) |
591 | { | |
592 | int i; | |
593 | int sign; | |
594 | long long int number; | |
595 | ||
596 | if (strncmp(buffer,"TOTAL\t",6)==0) { | |
597 | item->total=1; | |
598 | buffer+=6; | |
599 | ||
600 | sign=+1; | |
601 | if (*buffer == '-') { | |
602 | buffer++; | |
603 | sign=-1; | |
604 | } else if (*buffer == '+') { | |
605 | buffer++; | |
606 | } | |
607 | number=0LL; | |
608 | while (isdigit(*buffer)) | |
609 | number=(number * 10) + (*buffer++)-'0'; | |
610 | if (*buffer!='\t') { | |
10210234 | 611 | debuga(_("Invalid total number of accesses in %s\n"),filename); |
06b39c87 | 612 | exit(EXIT_FAILURE); |
2240dcea FM |
613 | } |
614 | buffer++; | |
615 | item->nacc=number*sign; | |
616 | ||
617 | sign=+1; | |
618 | if (*buffer == '-') { | |
619 | buffer++; | |
620 | sign=-1; | |
621 | } else if (*buffer == '+') { | |
622 | buffer++; | |
623 | } | |
624 | number=0LL; | |
625 | while (isdigit(*buffer)) | |
626 | number=(number * 10) + (*buffer++)-'0'; | |
627 | if (*buffer!='\t') { | |
10210234 | 628 | debuga(_("Invalid total size in %s\n"),filename); |
06b39c87 | 629 | exit(EXIT_FAILURE); |
2240dcea FM |
630 | } |
631 | buffer++; | |
632 | item->nbytes=number*sign; | |
633 | ||
634 | sign=+1; | |
635 | if (*buffer == '-') { | |
636 | buffer++; | |
637 | sign=-1; | |
638 | } else if (*buffer == '+') { | |
639 | buffer++; | |
640 | } | |
641 | number=0LL; | |
642 | while (isdigit(*buffer)) | |
643 | number=(number * 10) + (*buffer++)-'0'; | |
644 | if (*buffer!='\t') { | |
10210234 | 645 | debuga(_("Invalid total elapsed time in %s\n"),filename); |
06b39c87 | 646 | exit(EXIT_FAILURE); |
2240dcea FM |
647 | } |
648 | buffer++; | |
649 | item->nelap=number*sign; | |
650 | ||
651 | sign=+1; | |
652 | if (*buffer == '-') { | |
653 | buffer++; | |
654 | sign=-1; | |
655 | } else if (*buffer == '+') { | |
656 | buffer++; | |
657 | } | |
658 | number=0LL; | |
659 | while (isdigit(*buffer)) | |
660 | number=(number * 10) + (*buffer++)-'0'; | |
661 | if (*buffer!='\t') { | |
10210234 | 662 | debuga(_("Invalid total cache hit in %s\n"),filename); |
06b39c87 | 663 | exit(EXIT_FAILURE); |
2240dcea FM |
664 | } |
665 | buffer++; | |
666 | item->incache=number*sign; | |
667 | ||
668 | sign=+1; | |
669 | if (*buffer == '-') { | |
670 | buffer++; | |
671 | sign=-1; | |
672 | } else if (*buffer == '+') { | |
673 | buffer++; | |
674 | } | |
675 | number=0LL; | |
676 | while (isdigit(*buffer)) | |
677 | number=(number * 10) + (*buffer++)-'0'; | |
678 | if (*buffer!='\0') { | |
10210234 | 679 | debuga(_("Invalid total cache miss in %s\n"),filename); |
06b39c87 | 680 | exit(EXIT_FAILURE); |
2240dcea FM |
681 | } |
682 | item->oucache=number*sign; | |
683 | } else { | |
684 | item->total=0; | |
685 | ||
686 | item->user=buffer; | |
687 | for (i=0 ; i<MAX_USER_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
688 | if (*buffer!='\t') { | |
10210234 | 689 | debuga(_("User name too long or invalid in %s\n"),filename); |
06b39c87 | 690 | exit(EXIT_FAILURE); |
2240dcea FM |
691 | } |
692 | *buffer++='\0'; | |
693 | ||
694 | sign=+1; | |
695 | if (*buffer == '-') { | |
696 | buffer++; | |
697 | sign=-1; | |
698 | } else if (*buffer == '+') { | |
699 | buffer++; | |
700 | } | |
701 | number=0LL; | |
702 | while (isdigit(*buffer)) | |
703 | number=(number * 10) + (*buffer++)-'0'; | |
704 | if (*buffer!='\t') { | |
10210234 | 705 | debuga(_("Invalid number of accesses in %s\n"),filename); |
06b39c87 | 706 | exit(EXIT_FAILURE); |
2240dcea FM |
707 | } |
708 | buffer++; | |
709 | item->nacc=number*sign; | |
710 | ||
711 | sign=+1; | |
712 | if (*buffer == '-') { | |
713 | buffer++; | |
714 | sign=-1; | |
715 | } else if (*buffer == '+') { | |
716 | buffer++; | |
717 | } | |
718 | number=0LL; | |
719 | while (isdigit(*buffer)) | |
720 | number=(number * 10) + (*buffer++)-'0'; | |
721 | if (*buffer!='\t') { | |
10210234 | 722 | debuga(_("Invalid number of bytes in %s\n"),filename); |
06b39c87 | 723 | exit(EXIT_FAILURE); |
2240dcea FM |
724 | } |
725 | buffer++; | |
726 | item->nbytes=number*sign; | |
727 | ||
728 | item->url=buffer; | |
729 | while ((unsigned char)*buffer>=' ') buffer++; | |
730 | if (*buffer!='\t') { | |
10210234 | 731 | debuga(_("URL too long or invalid in %s\n"),filename); |
06b39c87 | 732 | exit(EXIT_FAILURE); |
2240dcea FM |
733 | } |
734 | *buffer++='\0'; | |
735 | ||
736 | item->ip=buffer; | |
737 | for (i=0 ; i<MAX_IP_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
738 | if (*buffer!='\t') { | |
10210234 | 739 | debuga(_("IP address too long or invalid in %s\n"),filename); |
06b39c87 | 740 | exit(EXIT_FAILURE); |
2240dcea FM |
741 | } |
742 | *buffer++='\0'; | |
743 | ||
744 | item->time=buffer; | |
745 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
746 | if (*buffer!='\t') { | |
10210234 | 747 | debuga(_("Time too long or invalid in %s\n"),filename); |
06b39c87 | 748 | exit(EXIT_FAILURE); |
2240dcea FM |
749 | } |
750 | *buffer++='\0'; | |
751 | ||
752 | item->date=buffer; | |
753 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
754 | if (*buffer!='\t') { | |
10210234 | 755 | debuga(_("Date too long or invalid in %s\n"),filename); |
06b39c87 | 756 | exit(EXIT_FAILURE); |
2240dcea FM |
757 | } |
758 | *buffer++='\0'; | |
759 | ||
760 | sign=+1; | |
761 | if (*buffer == '-') { | |
762 | buffer++; | |
763 | sign=-1; | |
764 | } else if (*buffer == '+') { | |
765 | buffer++; | |
766 | } | |
767 | number=0LL; | |
768 | while (isdigit(*buffer)) | |
769 | number=(number * 10) + (*buffer++)-'0'; | |
770 | if (*buffer!='\t') { | |
10210234 | 771 | debuga(_("Invalid elapsed time in %s\n"),filename); |
06b39c87 | 772 | exit(EXIT_FAILURE); |
2240dcea FM |
773 | } |
774 | buffer++; | |
775 | item->nelap=number*sign; | |
776 | ||
777 | sign=+1; | |
778 | if (*buffer == '-') { | |
779 | buffer++; | |
780 | sign=-1; | |
781 | } else if (*buffer == '+') { | |
782 | buffer++; | |
783 | } | |
784 | number=0LL; | |
785 | while (isdigit(*buffer)) | |
786 | number=(number * 10) + (*buffer++)-'0'; | |
787 | if (*buffer!='\t') { | |
10210234 | 788 | debuga(_("Invalid cache hit size in %s\n"),filename); |
06b39c87 | 789 | exit(EXIT_FAILURE); |
2240dcea FM |
790 | } |
791 | buffer++; | |
792 | item->incache=number*sign; | |
793 | ||
794 | sign=+1; | |
795 | if (*buffer == '-') { | |
796 | buffer++; | |
797 | sign=-1; | |
798 | } else if (*buffer == '+') { | |
799 | buffer++; | |
800 | } | |
801 | number=0LL; | |
802 | while (isdigit(*buffer)) | |
803 | number=(number * 10) + (*buffer++)-'0'; | |
804 | if (*buffer!='\0') { | |
10210234 | 805 | debuga(_("Invalid cache miss size in %s\n"),filename); |
06b39c87 | 806 | exit(EXIT_FAILURE); |
2240dcea FM |
807 | } |
808 | item->oucache=number*sign; | |
809 | } | |
810 | return(0); | |
811 | } | |
812 | ||
5160b452 | 813 | 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 GS |
814 | { |
815 | ||
816 | FILE *fp_ou; | |
25697a35 GS |
817 | char wdirname[MAXLEN]; |
818 | ||
819 | sprintf(wdirname,"%s/smartfilter.unsort",dirname); | |
820 | ||
b6d3adea | 821 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
d574e592 | 822 | debuga(_("(report) Cannot open file %s\n"),wdirname); |
06b39c87 | 823 | exit(EXIT_FAILURE); |
25697a35 GS |
824 | } |
825 | ||
120d768c | 826 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart); |
25697a35 GS |
827 | fputs("</body>\n</html>\n",fp_tt); |
828 | ||
829 | fclose(fp_ou); | |
830 | ||
831 | return; | |
832 | ||
833 | } |