]>
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 | ||
5f3cfd1d FM |
30 | static void maketmp(const char *user, const char *dirname, int debug, int indexonly); |
31 | static void maketmp_hour(const char *user, const char *dirname, int indexonly); | |
6e792ade | 32 | static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); |
5160b452 | 33 | static void gravatmpf(const char *oldaccuser, const char *dirname, 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); |
6e792ade | 34 | static void gravaporuser(const char *user, 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); |
0a4e18e1 | 35 | static void gravager(FILE *fp_gen, const char *user, 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 | 36 | 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 | 37 | |
32e71fa4 | 38 | void gerarel(void) |
25697a35 GS |
39 | { |
40 | ||
d6e703cc | 41 | FILE *fp_in; |
0a4e18e1 | 42 | FILE *fp_gen; |
25697a35 | 43 | |
6e792ade | 44 | char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN]; |
e6414a9d | 45 | char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN]; |
25697a35 | 46 | char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; |
6e792ade | 47 | char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAXLEN]; |
4157aa09 | 48 | char ipantes[MAXLEN], nameantes[MAXLEN]; |
25697a35 | 49 | char accsmart[MAXLEN]; |
623c04aa | 50 | char crc2[MAXLEN/2 -1]; |
4157aa09 FM |
51 | long long int nbytes=0; |
52 | long long int nelap=0; | |
25697a35 GS |
53 | long long int nacc=0; |
54 | long long int rtotal=0; | |
55 | long long int incache=0; | |
56 | long long int oucache=0; | |
6e792ade | 57 | long long int accbytes, accelap; |
9c7c6346 | 58 | char *str; |
25697a35 GS |
59 | DIR *dirp; |
60 | struct dirent *direntp; | |
8db846b0 FM |
61 | const char logext[]=".log"; |
62 | int dlen; | |
4157aa09 | 63 | char siteind[MAXLEN]; |
9c7c6346 | 64 | struct getwordstruct gwarea; |
25697a35 GS |
65 | |
66 | ipantes[0]='\0'; | |
67 | nameantes[0]='\0'; | |
68 | smartfilter=0; | |
69 | ||
d6e703cc | 70 | sprintf(dirname, "%s%s", outdir, period); |
e6414a9d | 71 | vrfydir(period, addr, site, us, email); |
25697a35 GS |
72 | |
73 | if(debugz){ | |
74 | debugaz("dirname",dirname); | |
25697a35 | 75 | } |
48864d28 FM |
76 | |
77 | gperiod(dirname,period); | |
25697a35 | 78 | |
4157aa09 | 79 | if(UserAgentLog[0] != '\0' && email[0] == '\0') useragent(); |
25697a35 | 80 | |
0a4e18e1 FM |
81 | sprintf(wdirname,"%s/sarg-general",dirname); |
82 | if((fp_gen=MY_FOPEN(wdirname,"a"))==NULL){ | |
83 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
84 | exit(1); | |
85 | } | |
86 | ||
25697a35 GS |
87 | olduser[0]='\0'; |
88 | strncat(tmp,"/sarg",5); | |
89 | ||
90 | dirp = opendir(tmp); | |
91 | while ((direntp = readdir( dirp )) != NULL ) { | |
8db846b0 FM |
92 | dlen=strlen(direntp->d_name)-(sizeof(logext)-1); |
93 | if (dlen<0) continue; | |
94 | if((strcmp(direntp->d_name+dlen,logext) != 0) || | |
d6e703cc FM |
95 | (strncmp(direntp->d_name,"download.log",12) == 0) || |
96 | (strncmp(direntp->d_name,"denied.log",10) == 0) || | |
5f3cfd1d | 97 | (strncmp(direntp->d_name,"authfail.log.unsort",19) == 0)) |
25697a35 | 98 | continue; |
8db846b0 FM |
99 | if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) { |
100 | fprintf(stderr, "SARG: (report) directory entry too long: %s/%s\n",tmp,direntp->d_name); | |
25697a35 GS |
101 | exit(1); |
102 | } | |
b6d3adea | 103 | if((fp_in=MY_FOPEN(tmp3,"r"))==NULL){ |
8db846b0 | 104 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],tmp); |
4bcb77cf FM |
105 | exit(1); |
106 | } | |
48864d28 | 107 | |
8db846b0 FM |
108 | if (dlen>0) { |
109 | if (dlen>=sizeof(user)) continue; | |
110 | strncpy(user,direntp->d_name,dlen); | |
111 | user[dlen]=0; | |
112 | } else { | |
113 | user[0]='\0'; | |
25697a35 | 114 | } |
48864d28 | 115 | |
25697a35 GS |
116 | strcpy(wdirname,dirname); |
117 | maketmp(user,tmp,debug,indexonly); | |
118 | maketmp_hour(user,tmp,indexonly); | |
48864d28 | 119 | |
936c9905 | 120 | strcpy(u2,user); |
246c8489 | 121 | if(Ip2Name) |
936c9905 FM |
122 | ip2name(u2,sizeof(u2)); |
123 | get_usertab_name(u2,name,sizeof(name)); | |
124 | ||
48864d28 FM |
125 | if(dotinuser && strchr(name,'_')) { |
126 | subs(name,sizeof(name),"_","."); | |
936c9905 FM |
127 | } |
128 | ||
25697a35 GS |
129 | ttopen=0; |
130 | bzero(html_old, MAXLEN); | |
48864d28 | 131 | |
25697a35 | 132 | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { |
9c7c6346 FM |
133 | getword_start(&gwarea,buf); |
134 | if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || | |
135 | getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 || | |
6e792ade | 136 | getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || |
9c7c6346 | 137 | getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { |
e6414a9d | 138 | printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",tmp3,__LINE__); |
4bcb77cf FM |
139 | exit(1); |
140 | } | |
d6e703cc | 141 | if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; |
e6414a9d FM |
142 | if (getword_atoll(&accelap,&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0) { |
143 | printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__); | |
144 | exit(1); | |
145 | } | |
146 | if (getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { | |
147 | printf("SARG: Maybe you have a broken smart info in your %s file (%d).\n",tmp3,__LINE__); | |
4bcb77cf FM |
148 | exit(1); |
149 | } | |
48864d28 | 150 | |
4157aa09 | 151 | if(accsmart[0] != '\0') { |
25697a35 GS |
152 | smartfilter++; |
153 | strcpy(wdirname,dirname); | |
154 | grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart); | |
155 | } | |
156 | ||
246c8489 | 157 | if(Ip2Name) { |
25697a35 GS |
158 | if(strcmp(accip,ipantes) != 0) { |
159 | strcpy(ipantes,accip); | |
a1c55d8c | 160 | ip2name(accip,sizeof(accip)); |
25697a35 GS |
161 | strcpy(nameantes,accip); |
162 | } else strcpy(accip,nameantes); | |
163 | } | |
48864d28 | 164 | |
25697a35 GS |
165 | strcpy(wdirname,dirname); |
166 | gravatmp_hora(wdirname,accuser,accdia,acchora,accelap,accbytes,indexonly); | |
167 | ||
168 | if(iprel){ | |
169 | strcpy(wdirname,dirname); | |
170 | gravaporuser(accuser,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); | |
171 | } | |
172 | ||
173 | if(!rtotal){ | |
174 | strcpy(oldurl,accurl); | |
175 | strcpy(oldacccode,acccode); | |
25697a35 GS |
176 | strcpy(oldaccuser,accuser); |
177 | strcpy(oldaccip,accip); | |
178 | strcpy(oldaccdia,accdia); | |
179 | strcpy(oldacchora,acchora); | |
180 | rtotal++; | |
181 | } | |
182 | ||
183 | if(site[0] != '\0') { | |
184 | if(strcmp(oldaccuser,accuser) != 0){ | |
185 | strcpy(oldmsg,"OK"); | |
186 | if(strstr(oldacccode,"DENIED") != 0) | |
187 | sprintf(oldmsg,"%s",text[46]); | |
0a4e18e1 FM |
188 | gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
189 | gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
25697a35 GS |
190 | nacc=0; |
191 | nbytes=0; | |
192 | nelap=0; | |
193 | incache=0; | |
194 | oucache=0; | |
195 | } | |
5f3cfd1d | 196 | } else { |
25697a35 GS |
197 | if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){ |
198 | strcpy(oldmsg,"OK"); | |
199 | if(strstr(oldacccode,"DENIED") != 0) | |
200 | sprintf(oldmsg,"%s",text[46]); | |
0a4e18e1 FM |
201 | gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
202 | gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); | |
25697a35 GS |
203 | nacc=0; |
204 | nbytes=0; | |
205 | nelap=0; | |
206 | incache=0; | |
207 | oucache=0; | |
5f3cfd1d FM |
208 | if(strcmp(oldaccuser,accuser) != 0) |
209 | ind2=0; | |
32e71fa4 | 210 | } |
5f3cfd1d FM |
211 | } |
212 | nacc++; | |
6e792ade FM |
213 | nbytes+=accbytes; |
214 | nelap+=accelap; | |
5f3cfd1d FM |
215 | |
216 | if(strstr(ReportType,"site_user_time_date") != 0) { | |
217 | if(!ttopen) { | |
218 | ind2++; | |
219 | strcpy(siteind,accurl); | |
4157aa09 FM |
220 | for(str=siteind; *str; str++) { |
221 | if(*str=='?' || *str=='-' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='*' || | |
392760b3 | 222 | *str=='\'' || *str=='\"' || *str=='$' || *str=='@') |
4157aa09 | 223 | *str='_'; |
5f3cfd1d FM |
224 | } |
225 | sprintf(arqtt,"%s/%s",dirname,accuser); | |
226 | if(access(arqtt, R_OK) != 0) | |
227 | my_mkdir(arqtt); | |
228 | sprintf(arqtt,"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind); | |
229 | if(strlen(arqtt) > 255) { | |
b3695c67 | 230 | arqtt[255]='\0'; |
5f3cfd1d FM |
231 | } |
232 | if ((fp_tt = fopen(arqtt, "w")) == 0) { | |
233 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt); | |
234 | exit(1); | |
235 | } | |
236 | ttopen=1; | |
237 | ||
24977ddb | 238 | /* |
e6414a9d | 239 | if(Privacy) |
5f3cfd1d FM |
240 | sprintf(httplink,"<font size=%s color=%s><href=http://%s>%s", \ |
241 | FontSize,PrivacyStringColor,PrivacyString,PrivacyString); | |
242 | else | |
4157aa09 | 243 | sprintf(httplink,"<font size=%s><a href=\"http://%s\">%s</a>",FontSize,accurl,accurl); |
24977ddb | 244 | */ |
5f3cfd1d FM |
245 | |
246 | sprintf(ltext110,"%s",text[110]); | |
9c7c6346 FM |
247 | for(str=ltext110; *str; ++str) |
248 | *str=tolower(*str); | |
5f3cfd1d FM |
249 | |
250 | fprintf(fp_tt, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n<head>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet); | |
251 | css(fp_tt); | |
252 | fputs("</head>\n",fp_tt); | |
dfb337be FM |
253 | fprintf(fp_tt,"<body bgcolor=\"%s\" text=\"%s\" background=\"%s\">\n",BgColor,TxColor,BgImage); |
254 | write_logo_image(fp_tt); | |
5f3cfd1d FM |
255 | |
256 | if(strcmp(IndexTree,"date") == 0) | |
257 | show_sarg(fp_tt, "../../../.."); | |
258 | else | |
259 | show_sarg(fp_tt, "../.."); | |
260 | ||
dfb337be | 261 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_tt); |
5f3cfd1d FM |
262 | fprintf(fp_tt,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title); |
263 | ||
5f3cfd1d FM |
264 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[89],period); |
265 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[90],name); | |
266 | fprintf(fp_tt,"<tr><td class=\"header\" colspan=\"2\">%s: %s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder); | |
4157aa09 | 267 | fprintf(fp_tt,"<tr><th class=\"header3\" colspan=\"2\">%s</th></tr>\n",text[32]); |
5f3cfd1d | 268 | |
dfb337be FM |
269 | fputs("</table></div>\n",fp_tt); |
270 | fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt); | |
5f3cfd1d FM |
271 | fputs("<tr><td></td><td></td></tr>",fp_tt); |
272 | bzero(tmp4, MAXLEN); | |
273 | strncpy(tmp4,text[110],4); | |
274 | fprintf(fp_tt,"<tr><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[91],tmp4,text[110]+5); | |
94ff9470 GS |
275 | } |
276 | ||
5f3cfd1d | 277 | sprintf(html,"<tr><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accurl,accdia,acchora); |
25697a35 | 278 | |
5f3cfd1d FM |
279 | if(strcmp(html,html_old) != 0) |
280 | fputs(html,fp_tt); | |
281 | strcpy(html_old, html); | |
282 | } else bzero(ltext110, 50); | |
25697a35 | 283 | |
9c7c6346 FM |
284 | strcpy(crc2,acccode); |
285 | str=strchr(crc2,'/'); | |
286 | if (str) *str='\0'; | |
25697a35 | 287 | |
5f3cfd1d | 288 | if(strstr(crc2,"MISS") != 0) |
6e792ade FM |
289 | oucache+=accbytes; |
290 | else incache+=accbytes; | |
25697a35 | 291 | |
5f3cfd1d FM |
292 | strcpy(oldurl,accurl); |
293 | ||
294 | if(strcmp(accuser,oldaccuser) != 0) { | |
295 | strcpy(wdirname,dirname); | |
296 | day_totalize(tmp,oldaccuser,indexonly); | |
297 | } | |
298 | ||
299 | strcpy(oldaccuser,accuser); | |
300 | strcpy(oldacccode,acccode); | |
5f3cfd1d FM |
301 | strcpy(oldaccip,accip); |
302 | strcpy(oldaccdia,accdia); | |
303 | strcpy(oldacchora,acchora); | |
25697a35 | 304 | |
5f3cfd1d FM |
305 | } |
306 | bzero(user,MAXLEN); | |
307 | fclose(fp_in); | |
308 | unlink(tmp3); | |
25697a35 | 309 | } |
05b90947 | 310 | closedir(dirp); |
25697a35 GS |
311 | |
312 | strcpy(oldmsg,"OK"); | |
313 | if(strstr(oldacccode,"DENIED") != 0) | |
314 | sprintf(oldmsg,"%s",text[46]); | |
315 | strcpy(wdirname,dirname); | |
d6e703cc FM |
316 | if(strlen(oldaccuser) == 0) |
317 | strcpy(oldaccuser,accuser); | |
25697a35 GS |
318 | gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); |
319 | strcpy(wdirname,dirname); | |
0a4e18e1 FM |
320 | gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); |
321 | fclose(fp_gen); | |
d6e703cc | 322 | day_totalize(tmp,oldaccuser,indexonly); |
25697a35 GS |
323 | |
324 | tmpsort(); | |
325 | ||
326 | strcpy(wdirname,dirname); | |
327 | totalger(wdirname, debug, outdir); | |
328 | ||
5542cb59 | 329 | if(email[0] == '\0') { |
d6e703cc | 330 | if(strstr(ReportType,"downloads") != 0) download_report(); |
25697a35 | 331 | |
65740c50 | 332 | if(DansGuardianConf[0] != '\0') { |
25697a35 GS |
333 | strcpy(wdirname,dirname); |
334 | dansguardian_log(); | |
335 | } | |
336 | ||
491b862f GS |
337 | strcpy(wdirname,dirname); |
338 | squidguard_log(); | |
25697a35 GS |
339 | |
340 | strcpy(wdirname,dirname); | |
341 | topuser(); | |
342 | ||
d6e703cc | 343 | if(strstr(ReportType,"topsites") != 0) topsites(); |
25697a35 | 344 | |
d6e703cc | 345 | if(strstr(ReportType,"sites_users") != 0) siteuser(); |
25697a35 GS |
346 | gen_denied_report(); |
347 | ||
348 | strcpy(wdirname,dirname); | |
349 | authfail_report(); | |
350 | ||
d6e703cc | 351 | if(smartfilter) smartfilter_report(); |
25697a35 | 352 | |
65740c50 | 353 | if(DansGuardianConf[0] != '\0') dansguardian_report(); |
25697a35 | 354 | |
491b862f | 355 | squidguard_report(); |
25697a35 | 356 | |
d6e703cc | 357 | if(strstr(ReportType,"users_sites") != 0) htmlrel(); |
25697a35 | 358 | |
491b862f | 359 | make_index(); |
25697a35 | 360 | |
e6414a9d | 361 | if(SuccessfulMsg) fprintf(stderr, "SARG: %s %s\n",text[47],dirname); |
25697a35 GS |
362 | } else { |
363 | strcpy(wdirname,dirname); | |
364 | geramail(wdirname, debug, outdir, userip, email, TempDir); | |
365 | ||
e6414a9d | 366 | if((strcmp(email,"stdout") != 0) && SuccessfulMsg) |
25697a35 | 367 | fprintf(stderr, "SARG: %s %s\n",text[48],email); |
25697a35 GS |
368 | } |
369 | ||
370 | if(indexonly) { | |
371 | strcpy(wdirname,dirname); | |
372 | index_only(wdirname, debug); | |
373 | } | |
374 | ||
c274f011 FM |
375 | /* |
376 | 2009-10-13(Frederic) This piece of code is never called so it is commented out for good. | |
d6e703cc FM |
377 | if(strlen(email) < 0) |
378 | removetmp(dirname); | |
c274f011 | 379 | */ |
25697a35 GS |
380 | |
381 | return; | |
382 | } | |
383 | ||
5f3cfd1d | 384 | static void maketmp(const char *user, const char *dirname, int debug, int indexonly) |
25697a35 GS |
385 | { |
386 | ||
387 | FILE *fp_ou; | |
388 | ||
389 | char wdirname[MAXLEN]; | |
390 | ||
391 | if(indexonly) return; | |
392 | if(strstr(ReportType,"users_sites") == 0) return; | |
393 | ||
394 | strcpy(wdirname,tmp); | |
395 | strcat(wdirname,"/"); | |
396 | strcat(wdirname,user); | |
397 | ||
398 | if(debug){ | |
d2fe0c32 | 399 | debuga("%s: %s",text[49],wdirname); |
25697a35 GS |
400 | } |
401 | ||
402 | strcat(wdirname,".utmp"); | |
403 | if((fp_ou=fopen(wdirname,"w"))==NULL){ | |
404 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); | |
405 | exit(1); | |
406 | } | |
407 | ||
408 | fclose(fp_ou); | |
409 | return; | |
410 | } | |
411 | ||
412 | ||
5f3cfd1d | 413 | static void maketmp_hour(const char *user, const char *dirname, int indexonly) |
25697a35 GS |
414 | { |
415 | ||
416 | FILE *fp_ou; | |
417 | ||
418 | char wdirname[MAXLEN]; | |
419 | ||
420 | if(indexonly) return; | |
421 | if(strstr(ReportType,"users_sites") == 0) return; | |
422 | ||
423 | strcpy(wdirname,tmp); | |
424 | strcat(wdirname,"/"); | |
425 | strcat(wdirname,user); | |
426 | ||
427 | strcat(wdirname,".htmp"); | |
428 | if((fp_ou=fopen(wdirname,"w"))==NULL){ | |
429 | fprintf(stderr, "SARG: (report-1) %s: %s - %s\n",text[45],wdirname,strerror(errno)); | |
430 | exit(1); | |
431 | } | |
432 | ||
433 | fclose(fp_ou); | |
434 | return; | |
435 | } | |
436 | ||
437 | ||
0a4e18e1 | 438 | void gravatmp(const char *oldaccuser, 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 GS |
439 | { |
440 | ||
441 | FILE *fp_ou; | |
4157aa09 FM |
442 | char val1[16]; |
443 | char val2[16]; | |
444 | char val3[16]; | |
445 | char val4[16]; | |
446 | char val5[16]; | |
25697a35 GS |
447 | char wdirname[MAXLEN]; |
448 | ||
449 | if(indexonly) return; | |
450 | if(strstr(ReportType,"users_sites") == 0) return; | |
451 | ||
0a4e18e1 FM |
452 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { |
453 | fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); | |
454 | exit(1); | |
455 | } | |
25697a35 | 456 | |
b6d3adea | 457 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
25697a35 GS |
458 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); |
459 | exit(1); | |
4157aa09 | 460 | } |
25697a35 | 461 | |
0a4e18e1 FM |
462 | my_lltoa(nacc,val1,0); |
463 | my_lltoa(nbytes,val2,0); | |
464 | my_lltoa(nelap,val3,0); | |
465 | my_lltoa(incache,val4,0); | |
466 | my_lltoa(oucache,val5,0); | |
120d768c | 467 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); |
25697a35 GS |
468 | |
469 | fclose(fp_ou); | |
470 | ttopen=0; | |
471 | ||
472 | if(fp_tt) { | |
473 | fputs("</table>\n",fp_tt); | |
474 | fputs("</body>\n</html>\n",fp_tt); | |
475 | fclose(fp_tt); | |
476 | } | |
477 | ||
478 | return; | |
479 | ||
480 | } | |
481 | ||
482 | ||
6e792ade | 483 | static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) |
25697a35 GS |
484 | { |
485 | ||
486 | FILE *fp_ou; | |
25697a35 GS |
487 | char wdirname[MAXLEN]; |
488 | ||
d6e703cc | 489 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 | 490 | |
0a4e18e1 FM |
491 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { |
492 | fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user); | |
493 | exit(1); | |
494 | } | |
25697a35 | 495 | |
b6d3adea | 496 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
25697a35 GS |
497 | fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno)); |
498 | exit(1); | |
499 | } | |
500 | ||
6e792ade FM |
501 | if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); |
502 | else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); | |
25697a35 GS |
503 | |
504 | fclose(fp_ou); | |
505 | ||
506 | return; | |
507 | } | |
508 | ||
509 | ||
6e792ade | 510 | static void gravaporuser(const char *user, 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 |
511 | { |
512 | ||
513 | FILE *fp_ou; | |
25697a35 GS |
514 | char wdirname[MAXLEN]; |
515 | ||
d6e703cc | 516 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 | 517 | |
0a4e18e1 FM |
518 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) { |
519 | fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user); | |
520 | exit(1); | |
521 | } | |
25697a35 | 522 | |
b6d3adea | 523 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
25697a35 GS |
524 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); |
525 | exit(1); | |
4157aa09 | 526 | } |
25697a35 | 527 | |
6e792ade | 528 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); |
25697a35 GS |
529 | |
530 | fclose(fp_ou); | |
531 | ||
532 | return; | |
533 | ||
534 | } | |
535 | ||
536 | ||
5160b452 | 537 | static void gravatmpf(const char *oldaccuser, const char *dirname, 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 GS |
538 | { |
539 | ||
540 | FILE *fp_ou; | |
25697a35 GS |
541 | char wdirname[MAXLEN]; |
542 | ||
d6e703cc | 543 | if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; |
25697a35 | 544 | |
0a4e18e1 FM |
545 | if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { |
546 | fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); | |
547 | exit(1); | |
548 | } | |
25697a35 | 549 | |
b6d3adea | 550 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
25697a35 GS |
551 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); |
552 | exit(1); | |
553 | } | |
554 | ||
0a4e18e1 FM |
555 | my_lltoa(nacc,val1,0); |
556 | my_lltoa(nbytes,val2,0); | |
557 | my_lltoa(nelap,val3,0); | |
558 | my_lltoa(incache,val4,0); | |
559 | my_lltoa(oucache,val5,0); | |
120d768c | 560 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); |
25697a35 GS |
561 | |
562 | fclose(fp_ou); | |
563 | ttopen=0; | |
564 | ind2=0; | |
565 | ||
566 | if(fp_tt) { | |
567 | fputs("</table>\n",fp_tt); | |
5160b452 | 568 | fputs("</body>\n</html>\n",fp_tt); |
25697a35 GS |
569 | fclose(fp_tt); |
570 | } | |
571 | ||
572 | return; | |
4157aa09 | 573 | |
25697a35 GS |
574 | } |
575 | ||
576 | ||
0a4e18e1 | 577 | static void gravager(FILE *fp_gen, const char *user, 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 | 578 | { |
0a4e18e1 FM |
579 | my_lltoa(nacc,val1,0); |
580 | my_lltoa(nbytes,val2,0); | |
581 | my_lltoa(nelap,val3,0); | |
582 | my_lltoa(incache,val4,0); | |
583 | my_lltoa(oucache,val5,0); | |
584 | fprintf(fp_gen,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5); | |
25697a35 GS |
585 | return; |
586 | ||
587 | } | |
588 | ||
5160b452 | 589 | 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 |
590 | { |
591 | ||
592 | FILE *fp_ou; | |
25697a35 GS |
593 | char wdirname[MAXLEN]; |
594 | ||
595 | sprintf(wdirname,"%s/smartfilter.unsort",dirname); | |
596 | ||
b6d3adea | 597 | if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ |
25697a35 GS |
598 | fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); |
599 | exit(1); | |
600 | } | |
601 | ||
120d768c | 602 | fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",user,data,hora,ip,url,smart); |
25697a35 GS |
603 | fputs("</body>\n</html>\n",fp_tt); |
604 | ||
605 | fclose(fp_ou); | |
606 | ||
607 | return; | |
608 | ||
609 | } |