]>
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; |
ac422f9b | 80 | struct longlinestruct line; |
f2ec8c75 | 81 | struct userinfostruct *uinfo,*puinfo; |
25697a35 GS |
82 | |
83 | ipantes[0]='\0'; | |
25697a35 GS |
84 | smartfilter=0; |
85 | ||
d6e703cc | 86 | sprintf(dirname, "%s%s", outdir, period); |
e6414a9d | 87 | vrfydir(period, addr, site, us, email); |
25697a35 GS |
88 | |
89 | if(debugz){ | |
90 | debugaz("dirname",dirname); | |
25697a35 | 91 | } |
48864d28 FM |
92 | |
93 | gperiod(dirname,period); | |
25697a35 | 94 | |
4157aa09 | 95 | if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); |
25697a35 | 96 | |
0a4e18e1 | 97 | sprintf(wdirname,"%s/sarg-general",dirname); |
1bafebef | 98 | if((fp_gen=MY_FOPEN(wdirname,"w"))==NULL){ |
c36c7384 | 99 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
0a4e18e1 FM |
100 | exit(1); |
101 | } | |
102 | ||
f2ec8c75 | 103 | puinfo=NULL; |
25697a35 | 104 | strncat(tmp,"/sarg",5); |
e5b2c6f0 | 105 | fp_tt=NULL; |
25697a35 GS |
106 | |
107 | dirp = opendir(tmp); | |
108 | while ((direntp = readdir( dirp )) != NULL ) { | |
8db846b0 FM |
109 | dlen=strlen(direntp->d_name)-(sizeof(logext)-1); |
110 | if (dlen<0) continue; | |
111 | if((strcmp(direntp->d_name+dlen,logext) != 0) || | |
d6e703cc FM |
112 | (strncmp(direntp->d_name,"download.log",12) == 0) || |
113 | (strncmp(direntp->d_name,"denied.log",10) == 0) || | |
5f3cfd1d | 114 | (strncmp(direntp->d_name,"authfail.log.unsort",19) == 0)) |
25697a35 | 115 | continue; |
8db846b0 FM |
116 | if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) { |
117 | fprintf(stderr, "SARG: (report) directory entry too long: %s/%s\n",tmp,direntp->d_name); | |
25697a35 GS |
118 | exit(1); |
119 | } | |
b6d3adea | 120 | if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){ |
c36c7384 | 121 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),tmp); |
4bcb77cf FM |
122 | exit(1); |
123 | } | |
48864d28 | 124 | |
8db846b0 FM |
125 | if (dlen>0) { |
126 | if (dlen>=sizeof(user)) continue; | |
127 | strncpy(user,direntp->d_name,dlen); | |
128 | user[dlen]=0; | |
129 | } else { | |
130 | user[0]='\0'; | |
25697a35 | 131 | } |
48864d28 | 132 | |
f2ec8c75 FM |
133 | uinfo=userinfo_find_from_file(user); |
134 | if (!uinfo) { | |
10210234 | 135 | debuga(_("Ignoring unknown user file %s\n"),user); |
f2ec8c75 FM |
136 | continue; |
137 | } | |
138 | strcpy(u2,uinfo->id); | |
72c27633 FM |
139 | if(Ip2Name && uinfo->id_is_ip) { |
140 | strcpy(ipantes,u2); | |
141 | ip2name(u2,sizeof(u2)); | |
142 | strcpy(nameantes,u2); | |
143 | } | |
f2ec8c75 FM |
144 | user_find(uinfo->label,MAX_USER_LEN, u2); |
145 | ||
25697a35 GS |
146 | strcpy(wdirname,dirname); |
147 | maketmp(user,tmp,debug,indexonly); | |
148 | maketmp_hour(user,tmp,indexonly); | |
48864d28 | 149 | |
25697a35 | 150 | ttopen=0; |
e5b2c6f0 FM |
151 | oldurltt=NULL; |
152 | ourltt_size=0; | |
ac422f9b FM |
153 | memset(oldaccdiatt,0,sizeof(oldaccdiatt)); |
154 | memset(oldacchoratt,0,sizeof(oldacchoratt)); | |
f2ec8c75 | 155 | new_user=1; |
48864d28 | 156 | |
ac422f9b | 157 | if (longline_prepare(&line)<0) { |
10210234 | 158 | debuga(_("Not enough memory to read the downloaded files\n")); |
ac422f9b FM |
159 | exit(1); |
160 | } | |
161 | ||
162 | while((buf=longline_read(fp_in,&line))!=NULL) { | |
9c7c6346 FM |
163 | getword_start(&gwarea,buf); |
164 | if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || | |
f2ec8c75 | 165 | getword(accip,sizeof(accip),&gwarea,'\t')<0 || |
e5b2c6f0 | 166 | getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || |
9c7c6346 | 167 | getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { |
10210234 | 168 | debuga(_("There is a broken record or garbage in file %s\n"),tmp3); |
4bcb77cf FM |
169 | exit(1); |
170 | } | |
d6e703cc | 171 | if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; |
e34a7c98 | 172 | if (getword_atoll(&accelap,&gwarea,'\t')<0) { |
10210234 | 173 | debuga(_("There is a broken elapsed time in file %s\n"),tmp3); |
e6414a9d FM |
174 | exit(1); |
175 | } | |
e34a7c98 | 176 | if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { |
10210234 | 177 | debuga(_("There is a broken smart info in file %s\n"),tmp3); |
4bcb77cf FM |
178 | exit(1); |
179 | } | |
48864d28 | 180 | |
4157aa09 | 181 | if(accsmart[0] != '\0') { |
25697a35 GS |
182 | smartfilter++; |
183 | strcpy(wdirname,dirname); | |
f2ec8c75 | 184 | grava_SmartFilter(wdirname,uinfo->id,accip,accdia,acchora,accurl,accsmart); |
25697a35 GS |
185 | } |
186 | ||
246c8489 | 187 | if(Ip2Name) { |
25697a35 GS |
188 | if(strcmp(accip,ipantes) != 0) { |
189 | strcpy(ipantes,accip); | |
a1c55d8c | 190 | ip2name(accip,sizeof(accip)); |
25697a35 GS |
191 | strcpy(nameantes,accip); |
192 | } else strcpy(accip,nameantes); | |
193 | } | |
48864d28 | 194 | |
25697a35 | 195 | strcpy(wdirname,dirname); |
f2ec8c75 | 196 | gravatmp_hora(wdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly); |
25697a35 GS |
197 | |
198 | if(iprel){ | |
199 | strcpy(wdirname,dirname); | |
f2ec8c75 | 200 | gravaporuser(uinfo,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); |
25697a35 GS |
201 | } |
202 | ||
203 | if(!rtotal){ | |
e5b2c6f0 FM |
204 | url_len=strlen(accurl); |
205 | if (!oldurl || url_len>=ourl_size) { | |
206 | ourl_size=url_len+1; | |
207 | oldurl=realloc(oldurl,ourl_size); | |
208 | if (!oldurl) { | |
10210234 | 209 | debuga(_("Not enough memory to store the url\n")); |
e5b2c6f0 FM |
210 | exit(1); |
211 | } | |
212 | } | |
25697a35 GS |
213 | strcpy(oldurl,accurl); |
214 | strcpy(oldacccode,acccode); | |
f2ec8c75 | 215 | puinfo=uinfo; |
25697a35 GS |
216 | strcpy(oldaccip,accip); |
217 | strcpy(oldaccdia,accdia); | |
218 | strcpy(oldacchora,acchora); | |
f2ec8c75 | 219 | new_user=0; |
25697a35 GS |
220 | rtotal++; |
221 | } | |
1bafebef | 222 | same_url=(strcmp(oldurl,accurl) == 0); |
25697a35 GS |
223 | |
224 | if(site[0] != '\0') { | |
f2ec8c75 | 225 | if(new_user){ |
25697a35 GS |
226 | strcpy(oldmsg,"OK"); |
227 | if(strstr(oldacccode,"DENIED") != 0) | |
c36c7384 | 228 | sprintf(oldmsg,"%s",_("DENIED")); |
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) |
c36c7384 | 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)); |
f2ec8c75 | 261 | snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,uinfo->filename); |
5f3cfd1d FM |
262 | if(access(arqtt, R_OK) != 0) |
263 | my_mkdir(arqtt); | |
f2ec8c75 | 264 | snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,uinfo->filename,uinfo->filename,siteind); |
5f3cfd1d | 265 | if ((fp_tt = fopen(arqtt, "w")) == 0) { |
c36c7384 | 266 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),arqtt); |
5f3cfd1d FM |
267 | exit(1); |
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")); |
c36c7384 FM |
280 | fprintf(fp_tt,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",_("Period"),period); |
281 | fprintf(fp_tt,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",_("User"),uinfo->label); | |
282 | fprintf(fp_tt,"<tr><td class=\"header_l\">%s: %s, %s</td></tr>\n",_("Sort"),UserSortField,UserSortOrder); | |
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); | |
5f3cfd1d | 287 | fputs("<tr><td></td><td></td></tr>",fp_tt); |
c36c7384 | 288 | strncpy(tmp4,_("DATE/TIME"),4); |
2240dcea | 289 | tmp4[4]='\0'; |
c36c7384 | 290 | 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 |
291 | } |
292 | ||
e5b2c6f0 FM |
293 | fputs("<tr><td class=\"data\">",fp_tt); |
294 | output_html_string(fp_tt,accurl,100); | |
295 | fprintf(fp_tt,"</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora); | |
25697a35 | 296 | |
e5b2c6f0 FM |
297 | url_len=strlen(accurl); |
298 | if (!oldurltt || url_len>=ourltt_size) { | |
299 | ourltt_size=url_len+1; | |
300 | oldurltt=realloc(oldurltt,ourltt_size); | |
301 | if (!oldurltt) { | |
10210234 | 302 | debuga(_("Not enough memory to store the url\n")); |
e5b2c6f0 FM |
303 | exit(1); |
304 | } | |
305 | } | |
ac422f9b FM |
306 | strcpy(oldurltt,accurl); |
307 | strcpy(oldaccdiatt,accdia); | |
308 | strcpy(oldacchoratt,acchora); | |
309 | } | |
25697a35 | 310 | |
9c7c6346 FM |
311 | strcpy(crc2,acccode); |
312 | str=strchr(crc2,'/'); | |
313 | if (str) *str='\0'; | |
5f3cfd1d | 314 | if(strstr(crc2,"MISS") != 0) |
6e792ade FM |
315 | oucache+=accbytes; |
316 | else incache+=accbytes; | |
25697a35 | 317 | |
f2ec8c75 FM |
318 | if(new_user) { |
319 | new_user=0; | |
5f3cfd1d | 320 | strcpy(wdirname,dirname); |
f2ec8c75 | 321 | day_totalize(tmp,puinfo,indexonly); |
5f3cfd1d FM |
322 | } |
323 | ||
f2ec8c75 | 324 | puinfo=uinfo; |
5f3cfd1d | 325 | strcpy(oldacccode,acccode); |
5f3cfd1d | 326 | strcpy(oldaccip,accip); |
1bafebef FM |
327 | if (!same_url) { |
328 | url_len=strlen(accurl); | |
329 | if (url_len>=ourl_size) { | |
330 | ourl_size=url_len+1; | |
331 | oldurl=realloc(oldurl,ourl_size); | |
332 | if (!oldurl) { | |
10210234 | 333 | debuga(_("Not enough memory to store the url\n")); |
1bafebef FM |
334 | exit(1); |
335 | } | |
e5b2c6f0 | 336 | } |
1bafebef | 337 | strcpy(oldurl,accurl); |
e5b2c6f0 | 338 | } |
5f3cfd1d FM |
339 | strcpy(oldaccdia,accdia); |
340 | strcpy(oldacchora,acchora); | |
25697a35 | 341 | |
5f3cfd1d | 342 | } |
5f3cfd1d | 343 | fclose(fp_in); |
ac422f9b | 344 | longline_free(&line); |
e5b2c6f0 | 345 | if (oldurltt) free(oldurltt); |
1bafebef | 346 | unlink(tmp3); |
25697a35 | 347 | } |
05b90947 | 348 | closedir(dirp); |
25697a35 | 349 | |
e5b2c6f0 FM |
350 | if (oldurl) { |
351 | if(strstr(oldacccode,"DENIED") != 0) | |
c36c7384 | 352 | strcpy(oldmsg,_("DENIED")); |
e5b2c6f0 FM |
353 | else |
354 | strcpy(oldmsg,"OK"); | |
355 | strcpy(wdirname,dirname); | |
f2ec8c75 | 356 | gravatmpf(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
e5b2c6f0 | 357 | strcpy(wdirname,dirname); |
f2ec8c75 | 358 | gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); |
e5b2c6f0 FM |
359 | free(oldurl); |
360 | } | |
0a4e18e1 | 361 | fclose(fp_gen); |
f2ec8c75 | 362 | if (puinfo) day_totalize(tmp,puinfo,indexonly); |
25697a35 GS |
363 | |
364 | tmpsort(); | |
365 | ||
366 | strcpy(wdirname,dirname); | |
367 | totalger(wdirname, debug, outdir); | |
368 | ||
5542cb59 | 369 | if(email[0] == '\0') { |
085c1e1f | 370 | if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report(); |
25697a35 | 371 | |
65740c50 | 372 | if(DansGuardianConf[0] != '\0') { |
25697a35 GS |
373 | strcpy(wdirname,dirname); |
374 | dansguardian_log(); | |
375 | } | |
376 | ||
491b862f GS |
377 | strcpy(wdirname,dirname); |
378 | squidguard_log(); | |
25697a35 GS |
379 | |
380 | strcpy(wdirname,dirname); | |
381 | topuser(); | |
382 | ||
085c1e1f | 383 | if((ReportType & REPORT_TYPE_TOPSITES) != 0) topsites(); |
25697a35 | 384 | |
085c1e1f | 385 | if((ReportType & REPORT_TYPE_SITES_USERS) != 0) siteuser(); |
25697a35 GS |
386 | gen_denied_report(); |
387 | ||
388 | strcpy(wdirname,dirname); | |
389 | authfail_report(); | |
390 | ||
d6e703cc | 391 | if(smartfilter) smartfilter_report(); |
25697a35 | 392 | |
65740c50 | 393 | if(DansGuardianConf[0] != '\0') dansguardian_report(); |
25697a35 | 394 | |
491b862f | 395 | squidguard_report(); |
25697a35 | 396 | |
085c1e1f | 397 | if((ReportType & REPORT_TYPE_USERS_SITES) != 0) htmlrel(); |
25697a35 | 398 | |
491b862f | 399 | make_index(); |
25697a35 | 400 | |
c36c7384 | 401 | if(SuccessfulMsg) fprintf(stderr, "SARG: %s %s\n",_("Successful report generated on"),dirname); |
25697a35 GS |
402 | } else { |
403 | strcpy(wdirname,dirname); | |
404 | geramail(wdirname, debug, outdir, userip, email, TempDir); | |
405 | ||
e6414a9d | 406 | if((strcmp(email,"stdout") != 0) && SuccessfulMsg) |
c36c7384 | 407 | fprintf(stderr, "SARG: %s %s\n",_("Successful report generated and sent to"),email); |
25697a35 GS |
408 | } |
409 | ||
410 | if(indexonly) { | |
411 | strcpy(wdirname,dirname); | |
412 | index_only(wdirname, debug); | |
413 | } | |
414 | ||
c274f011 FM |
415 | /* |
416 | 2009-10-13(Frederic) This piece of code is never called so it is commented out for good. | |
d6e703cc FM |
417 | if(strlen(email) < 0) |
418 | removetmp(dirname); | |
c274f011 | 419 | */ |
25697a35 GS |
420 | |
421 | return; | |
422 | } | |
423 | ||
5f3cfd1d | 424 | static void maketmp(const char *user, const char *dirname, int debug, int indexonly) |
25697a35 GS |
425 | { |
426 | ||
427 | FILE *fp_ou; | |
428 | ||
429 | char wdirname[MAXLEN]; | |
430 | ||
431 | if(indexonly) return; | |
085c1e1f | 432 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 433 | |
10210234 | 434 | if(debug) debuga(_("Making file: %s/%s\n"),tmp,user); |
2240dcea | 435 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,user)>=sizeof(wdirname)) { |
10210234 | 436 | debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,user); |
2240dcea | 437 | exit(1); |
25697a35 GS |
438 | } |
439 | ||
25697a35 | 440 | if((fp_ou=fopen(wdirname,"w"))==NULL){ |
c36c7384 | 441 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
25697a35 GS |
442 | exit(1); |
443 | } | |
444 | ||
445 | fclose(fp_ou); | |
446 | return; | |
447 | } | |
448 | ||
449 | ||
5f3cfd1d | 450 | static void maketmp_hour(const char *user, const char *dirname, int indexonly) |
25697a35 GS |
451 | { |
452 | ||
453 | FILE *fp_ou; | |
454 | ||
455 | char wdirname[MAXLEN]; | |
456 | ||
457 | if(indexonly) return; | |
085c1e1f | 458 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 459 | |
2240dcea | 460 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { |
10210234 | 461 | debuga(_("Temporary file name too long: %s/%s.htmp\n"),tmp,user); |
2240dcea FM |
462 | exit(1); |
463 | } | |
25697a35 | 464 | |
25697a35 | 465 | if((fp_ou=fopen(wdirname,"w"))==NULL){ |
c36c7384 | 466 | fprintf(stderr, "SARG: (report-1) %s: %s - %s\n",_("Cannot open file"),wdirname,strerror(errno)); |
25697a35 GS |
467 | exit(1); |
468 | } | |
469 | ||
470 | fclose(fp_ou); | |
471 | return; | |
472 | } | |
473 | ||
474 | ||
f2ec8c75 | 475 | 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 | 476 | { |
25697a35 | 477 | FILE *fp_ou; |
25697a35 GS |
478 | char wdirname[MAXLEN]; |
479 | ||
480 | if(indexonly) return; | |
085c1e1f | 481 | if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 482 | |
f2ec8c75 | 483 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 484 | debuga(_("Temporary file name too long: %s/%s.utmp\n"),tmp,uinfo->filename); |
0a4e18e1 FM |
485 | exit(1); |
486 | } | |
25697a35 | 487 | |
b6d3adea | 488 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
c36c7384 | 489 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
25697a35 | 490 | exit(1); |
4157aa09 | 491 | } |
25697a35 | 492 | |
e5b2c6f0 | 493 | 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 |
494 | |
495 | fclose(fp_ou); | |
496 | ttopen=0; | |
497 | ||
498 | if(fp_tt) { | |
c0ec9cc7 | 499 | fputs("</table>\n</div>\n",fp_tt); |
25697a35 GS |
500 | fputs("</body>\n</html>\n",fp_tt); |
501 | fclose(fp_tt); | |
e5b2c6f0 | 502 | fp_tt=NULL; |
25697a35 GS |
503 | } |
504 | ||
505 | return; | |
25697a35 GS |
506 | } |
507 | ||
f2ec8c75 | 508 | 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 | 509 | { |
25697a35 | 510 | FILE *fp_ou; |
25697a35 GS |
511 | char wdirname[MAXLEN]; |
512 | ||
f2ec8c75 | 513 | if(indexonly || (ReportType & REPORT_TYPE_USERS_SITES) == 0) return; |
25697a35 | 514 | |
f2ec8c75 | 515 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 516 | debuga(_("Path too long %s/%s.utmp\n"),tmp,uinfo->filename); |
0a4e18e1 FM |
517 | exit(1); |
518 | } | |
25697a35 | 519 | |
b6d3adea | 520 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
c36c7384 | 521 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
25697a35 GS |
522 | exit(1); |
523 | } | |
524 | ||
f2ec8c75 | 525 | 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 |
526 | |
527 | fclose(fp_ou); | |
f2ec8c75 FM |
528 | ttopen=0; |
529 | ||
530 | if(fp_tt) { | |
531 | fputs("</table>\n",fp_tt); | |
532 | fputs("</body>\n</html>\n",fp_tt); | |
533 | fclose(fp_tt); | |
534 | fp_tt=NULL; | |
535 | } | |
25697a35 GS |
536 | |
537 | return; | |
538 | } | |
539 | ||
540 | ||
f2ec8c75 | 541 | 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 |
542 | { |
543 | ||
544 | FILE *fp_ou; | |
25697a35 GS |
545 | char wdirname[MAXLEN]; |
546 | ||
085c1e1f | 547 | if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; |
25697a35 | 548 | |
f2ec8c75 | 549 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 550 | debuga(_("Path too long %s/%s.htmp\n"),tmp,uinfo->filename); |
0a4e18e1 FM |
551 | exit(1); |
552 | } | |
25697a35 | 553 | |
b6d3adea | 554 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
10210234 | 555 | debuga(_("(report-2) Cannot open file: %s - %s\n"),wdirname,strerror(errno)); |
25697a35 | 556 | exit(1); |
4157aa09 | 557 | } |
25697a35 | 558 | |
f2ec8c75 FM |
559 | if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); |
560 | else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); | |
25697a35 GS |
561 | |
562 | fclose(fp_ou); | |
563 | ||
564 | return; | |
25697a35 GS |
565 | } |
566 | ||
567 | ||
f2ec8c75 | 568 | 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 |
569 | { |
570 | ||
571 | FILE *fp_ou; | |
25697a35 GS |
572 | char wdirname[MAXLEN]; |
573 | ||
085c1e1f | 574 | if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; |
25697a35 | 575 | |
f2ec8c75 | 576 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) { |
10210234 | 577 | debuga(_("Path too long %s/%s.ip\n"),tmp,uinfo->filename); |
0a4e18e1 FM |
578 | exit(1); |
579 | } | |
25697a35 | 580 | |
b6d3adea | 581 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
c36c7384 | 582 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
25697a35 GS |
583 | exit(1); |
584 | } | |
585 | ||
f2ec8c75 | 586 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); |
25697a35 GS |
587 | |
588 | fclose(fp_ou); | |
25697a35 GS |
589 | |
590 | return; | |
4157aa09 | 591 | |
25697a35 GS |
592 | } |
593 | ||
594 | ||
f2ec8c75 | 595 | 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 | 596 | { |
f2ec8c75 | 597 | 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 | 598 | return; |
25697a35 GS |
599 | } |
600 | ||
2240dcea FM |
601 | int ger_read(char *buffer,struct generalitemstruct *item,const char *filename) |
602 | { | |
603 | int i; | |
604 | int sign; | |
605 | long long int number; | |
606 | ||
607 | if (strncmp(buffer,"TOTAL\t",6)==0) { | |
608 | item->total=1; | |
609 | buffer+=6; | |
610 | ||
611 | sign=+1; | |
612 | if (*buffer == '-') { | |
613 | buffer++; | |
614 | sign=-1; | |
615 | } else if (*buffer == '+') { | |
616 | buffer++; | |
617 | } | |
618 | number=0LL; | |
619 | while (isdigit(*buffer)) | |
620 | number=(number * 10) + (*buffer++)-'0'; | |
621 | if (*buffer!='\t') { | |
10210234 | 622 | debuga(_("Invalid total number of accesses in %s\n"),filename); |
2240dcea FM |
623 | exit(1); |
624 | } | |
625 | buffer++; | |
626 | item->nacc=number*sign; | |
627 | ||
628 | sign=+1; | |
629 | if (*buffer == '-') { | |
630 | buffer++; | |
631 | sign=-1; | |
632 | } else if (*buffer == '+') { | |
633 | buffer++; | |
634 | } | |
635 | number=0LL; | |
636 | while (isdigit(*buffer)) | |
637 | number=(number * 10) + (*buffer++)-'0'; | |
638 | if (*buffer!='\t') { | |
10210234 | 639 | debuga(_("Invalid total size in %s\n"),filename); |
2240dcea FM |
640 | exit(1); |
641 | } | |
642 | buffer++; | |
643 | item->nbytes=number*sign; | |
644 | ||
645 | sign=+1; | |
646 | if (*buffer == '-') { | |
647 | buffer++; | |
648 | sign=-1; | |
649 | } else if (*buffer == '+') { | |
650 | buffer++; | |
651 | } | |
652 | number=0LL; | |
653 | while (isdigit(*buffer)) | |
654 | number=(number * 10) + (*buffer++)-'0'; | |
655 | if (*buffer!='\t') { | |
10210234 | 656 | debuga(_("Invalid total elapsed time in %s\n"),filename); |
2240dcea FM |
657 | exit(1); |
658 | } | |
659 | buffer++; | |
660 | item->nelap=number*sign; | |
661 | ||
662 | sign=+1; | |
663 | if (*buffer == '-') { | |
664 | buffer++; | |
665 | sign=-1; | |
666 | } else if (*buffer == '+') { | |
667 | buffer++; | |
668 | } | |
669 | number=0LL; | |
670 | while (isdigit(*buffer)) | |
671 | number=(number * 10) + (*buffer++)-'0'; | |
672 | if (*buffer!='\t') { | |
10210234 | 673 | debuga(_("Invalid total cache hit in %s\n"),filename); |
2240dcea FM |
674 | exit(1); |
675 | } | |
676 | buffer++; | |
677 | item->incache=number*sign; | |
678 | ||
679 | sign=+1; | |
680 | if (*buffer == '-') { | |
681 | buffer++; | |
682 | sign=-1; | |
683 | } else if (*buffer == '+') { | |
684 | buffer++; | |
685 | } | |
686 | number=0LL; | |
687 | while (isdigit(*buffer)) | |
688 | number=(number * 10) + (*buffer++)-'0'; | |
689 | if (*buffer!='\0') { | |
10210234 | 690 | debuga(_("Invalid total cache miss in %s\n"),filename); |
2240dcea FM |
691 | exit(1); |
692 | } | |
693 | item->oucache=number*sign; | |
694 | } else { | |
695 | item->total=0; | |
696 | ||
697 | item->user=buffer; | |
698 | for (i=0 ; i<MAX_USER_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
699 | if (*buffer!='\t') { | |
10210234 | 700 | debuga(_("User name too long or invalid in %s\n"),filename); |
2240dcea FM |
701 | exit(1); |
702 | } | |
703 | *buffer++='\0'; | |
704 | ||
705 | sign=+1; | |
706 | if (*buffer == '-') { | |
707 | buffer++; | |
708 | sign=-1; | |
709 | } else if (*buffer == '+') { | |
710 | buffer++; | |
711 | } | |
712 | number=0LL; | |
713 | while (isdigit(*buffer)) | |
714 | number=(number * 10) + (*buffer++)-'0'; | |
715 | if (*buffer!='\t') { | |
10210234 | 716 | debuga(_("Invalid number of accesses in %s\n"),filename); |
2240dcea FM |
717 | exit(1); |
718 | } | |
719 | buffer++; | |
720 | item->nacc=number*sign; | |
721 | ||
722 | sign=+1; | |
723 | if (*buffer == '-') { | |
724 | buffer++; | |
725 | sign=-1; | |
726 | } else if (*buffer == '+') { | |
727 | buffer++; | |
728 | } | |
729 | number=0LL; | |
730 | while (isdigit(*buffer)) | |
731 | number=(number * 10) + (*buffer++)-'0'; | |
732 | if (*buffer!='\t') { | |
10210234 | 733 | debuga(_("Invalid number of bytes in %s\n"),filename); |
2240dcea FM |
734 | exit(1); |
735 | } | |
736 | buffer++; | |
737 | item->nbytes=number*sign; | |
738 | ||
739 | item->url=buffer; | |
740 | while ((unsigned char)*buffer>=' ') buffer++; | |
741 | if (*buffer!='\t') { | |
10210234 | 742 | debuga(_("URL too long or invalid in %s\n"),filename); |
2240dcea FM |
743 | exit(1); |
744 | } | |
745 | *buffer++='\0'; | |
746 | ||
747 | item->ip=buffer; | |
748 | for (i=0 ; i<MAX_IP_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
749 | if (*buffer!='\t') { | |
10210234 | 750 | debuga(_("IP address too long or invalid in %s\n"),filename); |
2240dcea FM |
751 | exit(1); |
752 | } | |
753 | *buffer++='\0'; | |
754 | ||
755 | item->time=buffer; | |
756 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
757 | if (*buffer!='\t') { | |
10210234 | 758 | debuga(_("Time too long or invalid in %s\n"),filename); |
2240dcea FM |
759 | exit(1); |
760 | } | |
761 | *buffer++='\0'; | |
762 | ||
763 | item->date=buffer; | |
764 | for (i=0 ; i<MAX_DATETIME_LEN-1 && (unsigned char)*buffer>=' ' ; i++) buffer++; | |
765 | if (*buffer!='\t') { | |
10210234 | 766 | debuga(_("Date too long or invalid in %s\n"),filename); |
2240dcea FM |
767 | exit(1); |
768 | } | |
769 | *buffer++='\0'; | |
770 | ||
771 | sign=+1; | |
772 | if (*buffer == '-') { | |
773 | buffer++; | |
774 | sign=-1; | |
775 | } else if (*buffer == '+') { | |
776 | buffer++; | |
777 | } | |
778 | number=0LL; | |
779 | while (isdigit(*buffer)) | |
780 | number=(number * 10) + (*buffer++)-'0'; | |
781 | if (*buffer!='\t') { | |
10210234 | 782 | debuga(_("Invalid elapsed time in %s\n"),filename); |
2240dcea FM |
783 | exit(1); |
784 | } | |
785 | buffer++; | |
786 | item->nelap=number*sign; | |
787 | ||
788 | sign=+1; | |
789 | if (*buffer == '-') { | |
790 | buffer++; | |
791 | sign=-1; | |
792 | } else if (*buffer == '+') { | |
793 | buffer++; | |
794 | } | |
795 | number=0LL; | |
796 | while (isdigit(*buffer)) | |
797 | number=(number * 10) + (*buffer++)-'0'; | |
798 | if (*buffer!='\t') { | |
10210234 | 799 | debuga(_("Invalid cache hit size in %s\n"),filename); |
2240dcea FM |
800 | exit(1); |
801 | } | |
802 | buffer++; | |
803 | item->incache=number*sign; | |
804 | ||
805 | sign=+1; | |
806 | if (*buffer == '-') { | |
807 | buffer++; | |
808 | sign=-1; | |
809 | } else if (*buffer == '+') { | |
810 | buffer++; | |
811 | } | |
812 | number=0LL; | |
813 | while (isdigit(*buffer)) | |
814 | number=(number * 10) + (*buffer++)-'0'; | |
815 | if (*buffer!='\0') { | |
10210234 | 816 | debuga(_("Invalid cache miss size in %s\n"),filename); |
2240dcea FM |
817 | exit(1); |
818 | } | |
819 | item->oucache=number*sign; | |
820 | } | |
821 | return(0); | |
822 | } | |
823 | ||
5160b452 | 824 | 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 |
825 | { |
826 | ||
827 | FILE *fp_ou; | |
25697a35 GS |
828 | char wdirname[MAXLEN]; |
829 | ||
830 | sprintf(wdirname,"%s/smartfilter.unsort",dirname); | |
831 | ||
b6d3adea | 832 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
c36c7384 | 833 | fprintf(stderr, "SARG: (report) %s: %s\n",_("Cannot open file"),wdirname); |
25697a35 GS |
834 | exit(1); |
835 | } | |
836 | ||
120d768c | 837 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart); |
25697a35 GS |
838 | fputs("</body>\n</html>\n",fp_tt); |
839 | ||
840 | fclose(fp_ou); | |
841 | ||
842 | return; | |
843 | ||
844 | } |