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