]> git.ipfire.org Git - thirdparty/sarg.git/blame - log.c
Output w3c compliant strict html (almost every output).
[thirdparty/sarg.git] / log.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
ad500baa 3 * 1998, 2010
94ff9470 4 *
25697a35 5 * SARG donations:
94ff9470 6 * please look at http://sarg.sourceforge.net/donations.php
ad500baa
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"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
25697a35
GS
30#define REPORT_EVERY_X_LINES 5000
31
32
33char *userfile;
25697a35
GS
34
35numlist weekdays = { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
36numlist hours = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
37 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
38
936c9905 39static void getusers(const char *pwdfile, int debug);
25697a35 40
25f0793f 41int main(int argc,char *argv[])
25697a35 42{
076cbab8
FM
43 enum isa_col_id {
44 ISACOL_Ip,
45 ISACOL_UserName,
46 ISACOL_Date,
47 ISACOL_Time,
48 ISACOL_TimeTaken,
49 ISACOL_Bytes,
50 ISACOL_Uri,
51 ISACOL_Status,
52 ISACOL_Last //last entry of the list !
53 };
58d7d8fe
FM
54 enum InputLogFormat {
55 ILF_Unknown,
56 ILF_Squid,
57 ILF_Common,
58 ILF_Sarg,
59 ILF_Isa,
60 ILF_Last //last entry of the list !
61 };
25697a35 62
120d768c 63 FILE *fp_in = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL;
25697a35
GS
64
65 char sz_Download_Unsort[ 20000 ] ;
66 FILE * fp_Download_Unsort = NULL ;
67 FILE * fp_Write_User = NULL ;
68
69 extern int optind;
70 extern int optopt;
71 extern char *optarg;
72
25f0793f 73 char data[255];
25697a35 74 char elap[255];
25697a35 75 char ip[MAXLEN];
25697a35 76 char tam[255];
25f0793f
FM
77 char fun[MAXLEN];
78 char wuser[MAXLEN];
25697a35 79 char smartfilter[MAXLEN];
2357ef77 80 char dia[128];
25697a35
GS
81 char wdata[128];
82 char mes[30];
83 char ano[30];
84 char hora[30];
85 char wtemp[MAXLEN];
86 char wtemp2[255];
87 char date[255];
88 char arq[255];
89 char arq_log[255];
9c7c6346 90 char hm[15], hmf[15], hmr[15];
25697a35
GS
91 int chm=0;
92 char uagent[MAXLEN];
93 char hexclude[MAXLEN];
456d78a5
FM
94 char csort[MAXLEN];
95 int cstatus;
25697a35
GS
96 char tbuf[128];
97 char tbuf2[128];
98 char zip[20];
99 char *str;
100 char bufz[MAXLEN];
101 char bufy[MAXLEN];
06ced858 102 char tmp2[MAXLEN];
ff8d5836
FM
103 char start_hour[128];
104 char end_hour[128];
58d7d8fe
FM
105 enum InputLogFormat ilf;
106 int ilf_count[ILF_Last];
25697a35 107 int ch;
d6e703cc 108 int x, l;
25697a35
GS
109 int errflg=0;
110 int puser=0;
111 int fhost=0;
112 int dns=0;
113 int fuser=0;
114 int idata=0;
ed1ac52f 115 int mindate=0;
25697a35
GS
116 int iarq=0;
117 int exstring=0;
076cbab8 118 int isa_ncols=0,isa_cols[ISACOL_Last];
58d7d8fe 119 int from_stdin;
2357ef77 120 long totregsl=0;
25697a35
GS
121 long totregsg=0;
122 long totregsx=0;
123 long totper=0;
58d7d8fe 124 long int max_elapsed=0;
25697a35
GS
125 time_t tt;
126 struct tm *t;
7c0b0078
FM
127 unsigned long recs1=0UL;
128 unsigned long recs2=0UL;
25697a35 129 int OutputNonZero = REPORT_EVERY_X_LINES ;
ff8d5836 130 int download_flag=0;
304a739d 131 char download_url[MAXLEN];
120d768c 132 char sz_Last_User[MAXLEN]="";
9c7c6346 133 struct getwordstruct gwarea;
25697a35
GS
134
135 BgImage[0]='\0';
136 LogoImage[0]='\0';
137 LogoText[0]='\0';
138 PasswdFile[0]='\0';
139 OutputEmail[0]='\0';
25697a35
GS
140 UserAgentLog[0]='\0';
141 ExcludeHosts[0]='\0';
142 ExcludeUsers[0]='\0';
143 ConfigFile[0]='\0';
144 code[0]='\0';
0511cf2d 145 LastLog=0;
085c1e1f 146 ReportType=0UL;
25697a35
GS
147 UserTabFile[0]='\0';
148 BlockIt[0]='\0';
149 ExternalCSSFile[0]='\0';
150 SquidGuardLogFormat[0]='\0';
491b862f 151 SquidGuardLogAlternate[0]='\0';
58d7d8fe 152 for (ilf=0 ; ilf<ILF_Last ; ilf++) ilf_count[ilf]=0;
25697a35 153
25697a35
GS
154 sprintf(ExcludeCodes,"%s/exclude_codes",SYSCONFDIR);
155 strcpy(GraphDaysBytesBarColor,"orange");
491b862f 156 strcpy(BgColor,"#ffffff");
25697a35
GS
157 strcpy(TxColor,"#000000");
158 strcpy(TxBgColor,"lavender");
159 strcpy(TiColor,"darkblue");
160 strcpy(Width,"80");
161 strcpy(Height,"45");
162 strcpy(LogoTextColor,"#000000");
163 strcpy(HeaderColor,"darkblue");
491b862f 164 strcpy(HeaderBgColor,"#dddddd");
94ff9470 165 strcpy(LogoTextColor,"#006699");
25697a35
GS
166 strcpy(FontSize,"9px");
167 strcpy(TempDir,"/tmp");
d6e703cc 168 strcpy(OutputDir,"/var/www/html/squid-reports");
246c8489 169 Ip2Name=0;
25697a35 170 strcpy(DateFormat,"u");
e6414a9d
FM
171 OverwriteReport=0;
172 RemoveTempFiles=1;
25697a35 173 strcpy(ReplaceIndex,"index.html");
0349fa24 174 Index=INDEX_YES;
25697a35 175 strcpy(RecordsWithoutUser,"ip");
e6414a9d 176 UseComma=0;
25697a35 177 strcpy(MailUtility,"mailx");
c0ec9cc7 178 TopSitesNum=100;
246c8489 179 UserIp=0;
25697a35
GS
180 strcpy(TopuserSortField,"BYTES");
181 strcpy(UserSortField,"BYTES");
182 strcpy(TopuserSortOrder,"reverse");
183 strcpy(UserSortOrder,"reverse");
184 strcpy(TopsitesSortField,"CONNECT");
185 strcpy(TopsitesSortType,"D");
246c8489 186 LongUrl=0;
25697a35
GS
187 strcpy(language,"English");
188 strcpy(FontFace,"Verdana,Tahoma,Arial");
d6e703cc 189 strcpy(datetimeby,"elap");
25697a35 190 strcpy(CharSet,"ISO-8859-1");
e6414a9d 191 Privacy=0;
25697a35
GS
192 strcpy(PrivacyString,"***.***.***.***");
193 strcpy(PrivacyStringColor,"blue");
e6414a9d 194 SuccessfulMsg=1;
085c1e1f
FM
195 TopUserFields=TOPUSERFIELDS_NUM | TOPUSERFIELDS_DATE_TIME | TOPUSERFIELDS_USERID | TOPUSERFIELDS_CONNECT |
196 TOPUSERFIELDS_BYTES | TOPUSERFIELDS_SETYB | TOPUSERFIELDS_IN_CACHE_OUT |
197 TOPUSERFIELDS_USED_TIME | TOPUSERFIELDS_MILISEC | TOPUSERFIELDS_PTIME |
198 TOPUSERFIELDS_TOTAL | TOPUSERFIELDS_AVERAGE;
199 UserReportFields=USERREPORTFIELDS_CONNECT | USERREPORTFIELDS_BYTES | USERREPORTFIELDS_SETYB |
200 USERREPORTFIELDS_IN_CACHE_OUT | USERREPORTFIELDS_USED_TIME | USERREPORTFIELDS_MILISEC |
201 USERREPORTFIELDS_PTIME | USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE;
25697a35 202 strcpy(DataFileDelimiter,";");
085c1e1f
FM
203 DataFileFields=DATA_FIELD_USER | DATA_FIELD_DATE | DATA_FIELD_TIME | DATA_FIELD_URL | DATA_FIELD_CONNECT |
204 DATA_FIELD_BYTES | DATA_FIELD_IN_CACHE | DATA_FIELD_OUT_CACHE | DATA_FIELD_ELAPSED;
25697a35 205 strcpy(SiteUserTimeDateType,"table");
e6414a9d 206 ShowReadStatistics=1;
25697a35 207 strcpy(IndexSortOrder,"D");
e6414a9d
FM
208 ShowSargInfo=1;
209 ShowSargLogo=1;
25697a35 210 strcpy(ParsedOutputLog,"no");
ff8d5836 211 strcpy(ParsedOutputLogCompress,"/bin/gzip -f");
25697a35
GS
212 strcpy(DisplayedValues,"abbreviation");
213 strcpy(HeaderFontSize,"9px");
214 strcpy(TitleFontSize,"11px");
215 strcpy(AuthUserFile,"/usr/local/sarg/passwd");
216 strcpy(AuthName,"SARG, Restricted Access");
217 strcpy(AuthType,"basic");
218 strcpy(Require,"require user admin %u");
6e792ade 219 set_download_suffix("7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip");
e6414a9d 220 Graphs=1;
25697a35
GS
221 strcpy(Ulimit,"20000");
222 strcpy(NtlmUserFormat,"domainname+username");
0349fa24 223 IndexTree=INDEX_TREE_FILE;
491b862f 224 strcpy(RealtimeTypes,"GET,PUT,CONNECT");
d6e703cc 225 strcpy(RealtimeUnauthRec,"show");
e6414a9d
FM
226 SquidguardIgnoreDate=0;
227 DansguardianIgnoreDate=0;
491b862f 228 strcpy(DataFileUrl,"ip");
d6e703cc 229 strcpy(MaxElapsed,"28800000");
e6414a9d
FM
230 BytesInSitesUsersReport=0;
231 UserAuthentication=0;
e3af0ae9 232 strcpy(LDAPHost,"127.0.0.1");
965c4a6f
FM
233 LDAPPort=389;
234 LDAPProtocolVersion=3;
e3af0ae9
PO
235 LDAPBindDN[0]='\0';
236 LDAPBindPW[0]='\0';
237 LDAPBaseSearch[0]='\0';
238 strcpy(LDAPFilterSearch, "uid=%s");
239 strcpy(LDAPTargetAttr, "cn");
25697a35
GS
240
241 dia[0]='\0';
242 mes[0]='\0';
243 ano[0]='\0';
244 hora[0]='\0';
245 tmp[0]='\0';
246 tmp2[0]='\0';
247 tmp3[0]='\0';
248 wtemp[0]='\0';
249 wtemp2[0]='\0';
250 us[0]='\0';
251 date[0]='\0';
252 df[0]='\0';
253 uagent[0]='\0';
254 hexclude[0]='\0';
255 addr[0]='\0';
256 hm[0]='\0';
257 hmf[0]='\0';
258 site[0]='\0';
259 outdir[0]='\0';
260 elap[0]='\0';
261 email[0]='\0';
262 zip[0]='\0';
263 UserInvalidChar[0]='\0';
264 DataFile[0]='\0';
265 SquidGuardConf[0]='\0';
266 DansGuardianConf[0]='\0';
ff8d5836
FM
267 start_hour[0]='\0';
268 end_hour[0]='\0';
25697a35 269
25697a35
GS
270 denied_count=0;
271 download_count=0;
272 authfail_count=0;
273 dansguardian_count=0;
274 squidguard_count=0;
c0ec9cc7 275 useragent_count=0;
25697a35
GS
276 DeniedReportLimit=10;
277 AuthfailReportLimit=10;
278 DansGuardianReportLimit=10;
279 SquidGuardReportLimit=10;
94ff9470 280 DownloadReportLimit=50;
25697a35
GS
281 UserReportLimit=0;
282 debug=0;
283 debugz=0;
284 debugm=0;
285 iprel=0;
286 userip=0;
287 color1=0;
288 color2=0;
289 color3=0;
491b862f
GS
290 dotinuser=0;
291 realt=0;
292 realtime_refresh=3;
293 realtime_access_log_lines=1000;
294 cost=0.01;
295 nocost=50000000;
d6e703cc
FM
296 ndownload=0;
297 squid24=0;
25697a35
GS
298
299 bzero(IncludeUsers, MAXLEN);
300 bzero(ExcludeString, MAXLEN);
301
a1de61fe
FM
302#ifdef HAVE_LOCALE_H
303 setlocale(LC_TIME,"");
c0ec9cc7 304 setlocale (LC_MESSAGES, "");
a1de61fe 305#endif
c0ec9cc7
FM
306 bindtextdomain (PACKAGE_NAME, LOCALEDIR);
307 textdomain (PACKAGE_NAME);
a1de61fe 308
0a4e18e1
FM
309 NAccessLog=0;
310 for(x=0; x<=MAXLOGS; x++)
311 AccessLog[x][0]='\0';
312 AccessLogFromCmdLine=0;
25697a35
GS
313
314 language_load(language);
315 strcpy(Title,text[88]);
316
491b862f 317 while((ch = getopt(argc, argv, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
25697a35
GS
318 switch(ch)
319 {
320 case 'a':
321 strcpy(addr,optarg);
322 break;
323 case 'b':
324 strcpy(uagent,optarg);
325 break;
326 case 'c':
327 strcpy(hexclude,optarg);
328 break;
329 case 'd':
9c7c6346
FM
330 strncpy(date,optarg,sizeof(date)-1);
331 date[sizeof(date)-1]='\0';
332 getword_start(&gwarea,optarg);
333 if (getword(cdfrom,sizeof(cdfrom),&gwarea,'-')<0 || getword(cduntil,sizeof(cduntil),&gwarea,0)<0) {
4bcb77cf
FM
334 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
335 exit(1);
336 }
25697a35
GS
337 date_from(date, cdfrom, cduntil);
338 dfrom=atoi(cdfrom);
339 duntil=atoi(cduntil);
340 break;
341 case 'e':
342 strcpy(email,optarg);
343 break;
344 case 'f':
345 strcpy(ConfigFile,optarg);
346 break;
347 case 'g':
348 strcpy(df,optarg);
349 break;
936c9905
FM
350 case 'h':
351 usage(argv[0]);
25697a35 352 exit(0);
936c9905 353 break;
25697a35
GS
354 case 'i':
355 iprel++;
356 break;
357 case 'l':
0a4e18e1 358 if (NAccessLog>=MAXLOGS) {
4af2f8ff
FM
359 printf("SARG: Too many log files.\n");
360 exit(1);
361 }
0a4e18e1
FM
362 strcpy(AccessLog[NAccessLog],optarg);
363 NAccessLog++;
364 AccessLogFromCmdLine++;
25697a35 365 break;
491b862f
GS
366 case 'L':
367 strcpy(SquidGuardLogAlternate,optarg);
368 break;
25697a35
GS
369 case 'm':
370 debugm++;
371 break;
372 case 'n':
373 dns++;
374 break;
375 case 'o':
376 strcpy(outdir,optarg);
377 break;
378 case 'p':
379 userip++;
380 break;
491b862f
GS
381 case 'r':
382 realt++;
383 break;
25697a35
GS
384 case 's':
385 strcpy(site,optarg);
386 break;
387 case 't':
9c7c6346
FM
388 {
389 int h,m;
390
25697a35
GS
391 if(strstr(optarg,"-") == 0) {
392 strcpy(hm,optarg);
393 strcpy(hmf,optarg);
394 } else {
9c7c6346
FM
395 getword_start(&gwarea,optarg);
396 if (getword(hm,sizeof(hm),&gwarea,'-')<0 || getword(hmf,sizeof(hmf),&gwarea,0)<0) {
397 fprintf(stderr,"SARG: Maybe you have a broken record or garbage in your time range.\n");
4bcb77cf
FM
398 exit(1);
399 }
25697a35 400 }
9c7c6346
FM
401 if(sscanf(hm,"%d:%d",&h,&m)!=2) {
402 fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
936c9905 403 exit(1);
25697a35 404 }
9c7c6346
FM
405 sprintf(hm,"%02d%02d",h,m);
406 if(sscanf(hmf,"%d:%d",&h,&m)!=2) {
407 fprintf(stderr,"SARG: time period must be MM or MM:SS. Exit.\n");
408 exit(1);
25697a35 409 }
9c7c6346 410 sprintf(hmf,"%02d%02d",h,m);
25697a35 411 break;
9c7c6346 412 }
25697a35
GS
413 case 'u':
414 strcpy(us,optarg);
415 break;
416 case 'v':
417 version();
418 break;
419 case 'w':
420 strcpy(tmp,optarg);
421 break;
422 case 'x':
423 debug++;
424 break;
425 case 'y':
426 langcode++;
427 break;
428 case 'z':
429 debugz++;
430 break;
431 case ':':
936c9905
FM
432 fprintf(stderr, "Option -%c require an argument\n",optopt);
433 errflg++;
434 break;
25697a35
GS
435 case '?':
436 usage(argv[0]);
437 exit(1);
438 break;
439 }
440
441 }
442
443 if (errflg) {
444 usage(argv[0]);
445 exit(2);
446 }
447
d6e703cc 448 if(debug) debuga("Init");
25697a35 449
d6e703cc 450 if(ConfigFile[0] == '\0') sprintf(ConfigFile,"%s/sarg.conf",SYSCONFDIR);
936c9905 451 if(access(ConfigFile, R_OK) != 0) {
d2fe0c32 452 debuga("Cannot open config file: %s - %s",ConfigFile,strerror(errno));
936c9905
FM
453 exit(1);
454 }
455
25697a35 456 if(access(ConfigFile, R_OK) == 0)
d6e703cc 457 getconf();
936c9905 458
be081e85
FM
459 if(UserIp) userip++;
460
461 if(dns) Ip2Name=1;
462
491b862f
GS
463 if(realt) {
464 realtime();
465 exit(0);
466 }
25697a35 467
0349fa24 468 if(IndexTree == INDEX_TREE_FILE)
491b862f
GS
469 strcpy(ImageFile,"../images");
470 else
471 strcpy(ImageFile,"../../../images");
472
25697a35 473 dataonly=0;
c274f011 474 if(DataFile[0] != '\0')
25697a35 475 dataonly++;
936c9905 476
0a4e18e1
FM
477 if(!NAccessLog) {
478 strcpy(AccessLog[0],"/var/log/squid/access.log");
479 NAccessLog++;
25697a35
GS
480 }
481
482 if(strcmp(hexclude,"onvert") == 0 && strcmp(site,"plit") != 0) {
0a4e18e1 483 convlog(AccessLog[0], df, dfrom, duntil);
25697a35
GS
484 exit(0);
485 }
936c9905 486
25697a35 487 if(strcmp(site,"plit") == 0) {
0a4e18e1 488 splitlog(AccessLog[0], df, dfrom, duntil, hexclude);
25697a35
GS
489 exit(0);
490 }
491
48864d28 492 load_excludecodes(ExcludeCodes);
25697a35
GS
493
494 if(access(PasswdFile, R_OK) == 0) {
495 getusers(PasswdFile,debug);
496 puser++;
497 }
498
499 if(hexclude[0] == '\0')
500 strcpy(hexclude,ExcludeHosts);
43f18f45 501 if(hexclude[0] != '\0') {
936c9905
FM
502 gethexclude(hexclude,debug);
503 fhost++;
25697a35
GS
504 }
505
085c1e1f
FM
506 if(ReportType == 0) {
507 ReportType=REPORT_TYPE_TOPUSERS | REPORT_TYPE_TOPSITES | REPORT_TYPE_USERS_SITES |
508 REPORT_TYPE_SITES_USERS | REPORT_TYPE_DATE_TIME | REPORT_TYPE_DENIED |
509 REPORT_TYPE_AUTH_FAILURES | REPORT_TYPE_SITE_USER_TIME_DATE | REPORT_TYPE_DOWNLOADS;
510 }
25697a35
GS
511
512 if(access(ExcludeUsers, R_OK) == 0) {
513 getuexclude(ExcludeUsers,debug);
514 fuser++;
515 }
516
517 indexonly=0;
518 if(fuser) {
43f18f45 519 if(is_indexonly())
25697a35
GS
520 indexonly++;
521 }
d6e703cc 522 if(strcmp(ExcludeUsers,"indexonly") == 0) indexonly++;
0349fa24 523 if(Index == INDEX_ONLY) indexonly++;
25697a35 524
db5151ed 525 if(MaxElapsed[0] != '\0') max_elapsed=atol(MaxElapsed);
25697a35 526
db5151ed 527 if(outdir[0] == '\0') strcpy(outdir,OutputDir);
25697a35
GS
528 strcat(outdir,"/");
529
d6e703cc 530 if(uagent[0] == '\0') strcpy(uagent,UserAgentLog);
25697a35 531
d6e703cc
FM
532 if(tmp[0] == '\0') strcpy(tmp,TempDir);
533 else strcpy(TempDir,tmp);
25697a35 534
d6e703cc
FM
535 if(df[0] == '\0') strcpy(df,DateFormat);
536 else strcpy(DateFormat,df);
25697a35
GS
537
538 if(df[0] == '\0') {
539 strcpy(df,"u");
540 strcpy(DateFormat,"u");
541 }
542
4af2f8ff 543 if(email[0] == '\0' && OutputEmail[0] != '\0') strcpy(email,OutputEmail);
25697a35
GS
544
545 strcpy(tmp2,tmp);
25697a35 546
e6414a9d 547 if(email[0] != '\0') {
d6e703cc 548 sprintf(wtemp2,"%s/sarg",tmp2);
25697a35 549 my_mkdir(wtemp2);
d6e703cc 550 strcat(tmp2,"/sarg");
25697a35
GS
551 strcpy(outdir,tmp2);
552 strcat(outdir,"/");
d6e703cc 553 }
25697a35
GS
554
555 strcat(tmp2,"/sarg.log");
556
25697a35 557 sprintf(tmp3,"%s/sarg",tmp);
51465d08
FM
558 if(access(tmp3, R_OK) == 0) {
559 unlinkdir(tmp3,1);
560 }
25697a35 561 my_mkdir(tmp3);
491b862f
GS
562 strcpy(tmp4,tmp3);
563 strcpy(tmp5,tmp3);
564 strcpy(tmp6,tmp3);
25697a35
GS
565 strcat(tmp4,"/denied.log.unsort");
566 strcat(tmp5,"/denied.log");
567 strcat(tmp6,"/authfail.log.unsort");
568
569 if(debug) {
570 fprintf(stderr, "SARG: %s:\nSARG:\n",text[22]);
571 fprintf(stderr, "SARG: %35s (-a) = %s\n",text[23],addr);
572 fprintf(stderr, "SARG: %35s (-b) = %s\n",text[71],uagent);
573 fprintf(stderr, "SARG: %35s (-c) = %s\n",text[69],hexclude);
574 fprintf(stderr, "SARG: %35s (-d) = %s\n",text[24],date);
575 fprintf(stderr, "SARG: %35s (-e) = %s\n",text[41],email);
576 fprintf(stderr, "SARG: %35s (-f) = %s\n",text[70],ConfigFile);
577 if(strcmp(df,"e") == 0)
578 fprintf(stderr, "SARG: %35s (-g) = %s (dd/mm/yyyy)\n",text[25],text[26]);
579 if(strcmp(df,"u") == 0)
580 fprintf(stderr, "SARG: %35s (-g) = %s (mm/dd/yyyy)\n",text[25],text[27]);
581 if(strcmp(df,"w") == 0)
582 fprintf(stderr, "SARG: %35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
583 if(iprel)
584 fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[1]);
0a4e18e1 585 else
25697a35 586 fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[2]);
0a4e18e1
FM
587 for (iarq=0 ; iarq<NAccessLog ; iarq++)
588 fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],AccessLog[iarq]);
246c8489 589 if(Ip2Name)
25697a35
GS
590 fprintf(stderr, "SARG: %35s (-n) = %s\n",text[65],text[1]);
591 else
592 fprintf(stderr, "SARG: %35s (-n) = %s\n",text[65],text[2]);
593 fprintf(stderr, "SARG: %35s (-o) = %s\n",text[38],outdir);
246c8489 594 if(UserIp)
25697a35
GS
595 fprintf(stderr, "SARG: %35s (-p) = %s\n",text[29],text[1]);
596 else
597 fprintf(stderr, "SARG: %35s (-p) = %s\n",text[29],text[2]);
598 fprintf(stderr, "SARG: %35s (-s) = %s\n",text[30],site);
599 fprintf(stderr, "SARG: %35s (-t) = %s\n",text[31],hm);
600 fprintf(stderr, "SARG: %35s (-u) = %s\n",text[32],us);
601 fprintf(stderr, "SARG: %35s (-w) = %s\n",text[34],tmp);
602 if(debug)
603 fprintf(stderr, "SARG: %35s (-x) = %s\n",text[35],text[1]);
604 else
605 fprintf(stderr, "SARG: %35s (-x) = %s\n",text[35],text[2]);
606 if(debugz)
607 fprintf(stderr, "SARG: %35s (-z) = %s\n",text[36],text[1]);
608 else
609 fprintf(stderr, "SARG: %35s (-z) = %s\n",text[36],text[2]);
610 fprintf(stderr, "SARG:\n");
611 }
612
613 if(debugm) {
614 printf("%s:\nSARG:\n",text[22]);
615 printf("%35s (-a) = %s\n",text[23],addr);
616 printf("%35s (-b) = %s\n",text[71],uagent);
617 printf("%35s (-c) = %s\n",text[69],hexclude);
618 printf("%35s (-d) = %s\n",text[24],date);
619 printf("%35s (-e) = %s\n",text[41],email);
620 printf("%35s (-f) = %s\n",text[70],ConfigFile);
621 if(strcmp(df,"e") == 0)
622 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text[25],text[26]);
623 if(strcmp(df,"u") == 0)
624 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text[25],text[27]);
625 if(strcmp(df,"w") == 0)
626 printf("%35s (-g) = %s (yyyy/ww)\n",text[25],text[85]);
627 if(iprel)
628 printf("%35s (-i) = %s\n",text[28],text[1]);
0a4e18e1 629 else
25697a35 630 printf("%35s (-i) = %s\n",text[28],text[2]);
0a4e18e1
FM
631 for (iarq=0 ; iarq<NAccessLog ; iarq++)
632 printf("%35s (-l) = %s\n",text[37],AccessLog[iarq]);
246c8489 633 if(Ip2Name)
25697a35
GS
634 printf("%35s (-n) = %s\n",text[65],text[1]);
635 else
636 printf("%35s (-n) = %s\n",text[65],text[2]);
637 printf("%35s (-o) = %s\n",text[38],outdir);
246c8489 638 if(UserIp)
25697a35
GS
639 printf("%35s (-p) = %s\n",text[29],text[1]);
640 else
641 printf("%35s (-p) = %s\n",text[29],text[2]);
642 printf("%35s (-s) = %s\n",text[30],site);
643 printf("%35s (-t) = %s\n",text[31],hm);
644 printf("%35s (-u) = %s\n",text[32],us);
645 printf("%35s (-w) = %s\n",text[34],tmp);
646 if(debug)
647 printf("%35s (-x) = %s\n",text[35],text[1]);
648 else
649 printf("%35s (-x) = %s\n",text[35],text[2]);
650 if(debugz)
651 printf("%35s (-z) = %s\n",text[36],text[1]);
652 else
653 printf("%35s (-z) = %s\n",text[36],text[2]);
654 printf("sarg %s: %s\n",text[73],VERSION);
655 printf("Language=%s\n\n",text[3]);
656 }
657
d2fe0c32
FM
658 if(debug)
659 debuga("sarg %s: %s",text[73],VERSION);
25697a35 660
e112fa1f 661#ifdef HAVE_RLIM_T
eee60323 662 if (Ulimit[0] != '\0') {
e112fa1f 663 struct rlimit rl;
243a9fab
FM
664 long l1, l2;
665 int rc=0;
666
25697a35 667#if defined(RLIMIT_NOFILE)
d6e703cc 668 getrlimit (RLIMIT_NOFILE, &rl);
ed1ac52f 669#elif defined(RLIMIT_OFILE)
d6e703cc 670 getrlimit (RLIMIT_OFILE, &rl);
243a9fab
FM
671#else
672#warning "No rlimit resource for the number of open files"
25697a35 673#endif
d6e703cc
FM
674 l1 = rl.rlim_cur;
675 l2 = rl.rlim_max;
676
eee60323
FM
677 rl.rlim_cur = atol(Ulimit);
678 rl.rlim_max = atol(Ulimit);
243a9fab 679#if defined(RLIMIT_NOFILE)
eee60323 680 rc=setrlimit (RLIMIT_NOFILE, &rl);
243a9fab 681#elif defined(RLIMIT_OFILE)
eee60323 682 rc=setrlimit (RLIMIT_OFILE, &rl);
243a9fab
FM
683#else
684#warning "No rlimit resource for the number of open files"
685#endif
eee60323
FM
686 if(rc == -1) {
687 debuga("setrlimit error - %s\n",strerror(errno));
d6e703cc 688 }
25697a35 689
d2fe0c32
FM
690 if(debug)
691 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING,l1,l2,rl.rlim_cur,rl.rlim_max);
25697a35 692 }
e112fa1f 693#endif
25697a35 694
965c4a6f 695 init_usertab(UserTabFile);
25697a35
GS
696
697 sprintf ( sz_Download_Unsort , "%s/sarg/download.unsort", tmp);
25697a35 698
085c1e1f 699 if((ReportType & REPORT_TYPE_DENIED) != 0) {
294cb3d7
FM
700 if((fp_denied=MY_FOPEN(tmp4,"w"))==NULL) {
701 fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp4,strerror(errno));
702 exit(1);
703 }
704 }
705
706 if(DataFile[0]=='\0') {
085c1e1f 707 if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
294cb3d7
FM
708 if((fp_authfail=MY_FOPEN(tmp6,"w"))==NULL) {
709 fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[45],tmp6,strerror(errno));
710 exit(1);
711 }
712 }
713 }
714
0a4e18e1
FM
715 for (iarq=0 ; iarq<NAccessLog ; iarq++) {
716 strcpy(arq,AccessLog[iarq]);
25697a35 717
936c9905 718 strcpy(arqtt,arq);
d6e703cc 719
58d7d8fe
FM
720 if(strcmp(arq,"-")==0) {
721 if(debug)
722 debuga("%s: %s",text[7],"stdin");
723 fp_in=stdin;
724 from_stdin=1;
725 } else {
726 decomp(arq,zip,tmp);
727 if(debug)
728 debuga("%s: %s",text[7],arq);
729 if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
730 fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq,strerror(errno));
936c9905
FM
731 exit(1);
732 }
58d7d8fe 733 from_stdin=0;
25697a35 734 }
58d7d8fe 735 ilf=ILF_Unknown;
ff8d5836 736 download_flag=0;
936c9905 737 // pre-Read the file only if I have to show stats
e6414a9d 738 if(ShowReadStatistics && !from_stdin) {
936c9905 739 rewind(fp_in);
7c0b0078
FM
740 recs1=0UL;
741 recs2=0UL;
25697a35 742
936c9905
FM
743 while( fgets(bufz,sizeof(bufz),fp_in) != NULL ) recs1++;
744 rewind(fp_in);
7c0b0078 745 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1,(float) 0);
936c9905
FM
746 fflush( stdout ) ;
747 }
748
749 while(fgets(bufz,sizeof(bufz),fp_in)!=NULL) {
58d7d8fe
FM
750
751 if (ilf==ILF_Unknown) {
752 if(strncmp(bufz,"#Software: Mic",14) == 0) {
753 fixendofline(bufz);
f8ed23e3
FM
754 if (debug)
755 debuga("%s: %s",text[143],bufz);
58d7d8fe
FM
756 ilf=ILF_Isa;
757 ilf_count[ilf]++;
758 continue;
759 }
760
761 if(strncmp(bufz,"*** SARG Log ***",16) == 0) {
9c7c6346 762 getword_start(&gwarea,arqtt);
ff8d5836
FM
763 if (getword_skip(2000,&gwarea,'-')<0 || getword(val2,sizeof(val2),&gwarea,'_')<0 ||
764 getword_skip(10,&gwarea,'-')<0 || getword(val3,sizeof(val3),&gwarea,'_')<0) {
765 printf("SARG: The name of the file is invalid: %s\n",arq);
58d7d8fe
FM
766 exit(1);
767 }
768 sprintf(period,"%s-%s",val2,val3);
769 ilf=ILF_Sarg;
770 ilf_count[ilf]++;
771 continue;
772 }
773 }
774
ff8d5836 775 if(!fp_log && strcmp(ParsedOutputLog, "no") != 0 && ilf!=ILF_Sarg) {
58d7d8fe 776 if(access(ParsedOutputLog,R_OK) != 0) {
ff8d5836 777 my_mkdir(ParsedOutputLog);
58d7d8fe
FM
778 }
779 sprintf(arq_log,"%s/sarg_temp.log",ParsedOutputLog);
780 if((fp_log=MY_FOPEN(arq_log,"w"))==NULL) {
781 fprintf(stderr, "%s: (log) %s: %s - %s\n",argv[0],text[8],arq_log,strerror(errno));
782 exit(1);
783 }
784 fputs("*** SARG Log ***\n",fp_log);
785 }
786
936c9905 787 recs2++;
e6414a9d 788 if( ShowReadStatistics && !from_stdin && ! --OutputNonZero) {
25697a35
GS
789 perc = recs2 * 100 ;
790 perc = perc / recs1 ;
7c0b0078 791 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1,perc);
25697a35
GS
792 fflush (stdout);
793 OutputNonZero = REPORT_EVERY_X_LINES ;
936c9905
FM
794 }
795 if(strlen(bufz) > MAXLEN-1) continue;
796 if(!bufz[0]) continue;
797 if(strstr(bufz,"HTTP/0.0") != 0) continue;
798 if(strstr(bufz,"logfile turned over") != 0) continue;
799 if(bufz[0] == ' ') continue;
800 if(strlen(bufz) < 58) continue;
801
802 // Record only hours usage which is required
803 tt = (time_t) strtoul( bufz, NULL, 10 );
804 t = localtime( &tt );
805
806 if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len,
807 sizeof( int ), compar ) == NULL )
808 continue;
809
810 if( bsearch( &( t -> tm_hour ), hours.list, hours.len,
811 sizeof( int ), compar ) == NULL )
812 continue;
813
814 // exclude_string
815 exstring=0;
9c7c6346 816 if(ExcludeString[0] != '\0') {
936c9905 817 strcpy(warea,bufz);
9c7c6346
FM
818 getword_start(&gwarea,ExcludeString);
819 while(strchr(gwarea.current,':') != 0) {
820 if (getword_multisep(val1,sizeof(val1),&gwarea,':')<0) {
936c9905
FM
821 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
822 exit(1);
823 }
824 if((str=(char *) strstr(warea,val1)) != (char *) NULL )
825 exstring++;
826 }
9c7c6346 827 if((str=(char *) strstr(warea,gwarea.current)) != (char *) NULL )
936c9905
FM
828 exstring++;
829 }
830 if(exstring) continue;
831
832 strcpy(bufy,bufz);
833 if ((str = strchr(bufz, '\n')) != NULL)
2357ef77 834 *str = '\0'; /* strip \n */
936c9905
FM
835
836 totregsl++;
936c9905
FM
837 if(debugm)
838 printf("BUF=%s\n",bufz);
839
58d7d8fe 840 if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
9c7c6346
FM
841 getword_start(&gwarea,bufz);
842 if (getword(data,sizeof(data),&gwarea,' ')<0) {
936c9905
FM
843 printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
844 exit(1);
845 }
0ff563a2
FM
846 if((str=(char *) strchr(data, '.')) != (char *) NULL ) {
847 if((str=(char *) strchr(str+1, '.')) != (char *) NULL ) {
936c9905
FM
848 strcpy(ip,data);
849 strcpy(elap,"0");
850 if(squid24) {
9c7c6346 851 if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
936c9905
FM
852 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
853 exit(1);
854 }
855 } else {
9c7c6346 856 if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
936c9905
FM
857 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
858 exit(1);
859 }
860 }
9c7c6346
FM
861 if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
862 getword(fun,sizeof(fun),&gwarea,' ')<0 || getword(url,sizeof(url),&gwarea,' ')<0 ||
863 getword_skip(MAXLEN,&gwarea,' ')<0 || getword(code2,sizeof(code2),&gwarea,' ')<0 ||
864 getword(tam,sizeof(tam),&gwarea,' ')<0) {
936c9905
FM
865 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
866 exit(1);
867 }
9c7c6346
FM
868 if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) {
869 if (getword(code,sizeof(code),&gwarea,' ')<0) {
870 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
871 exit(1);
872 }
873 } else {
874 if (getword(code,sizeof(code),&gwarea,'\0')<0) {
936c9905
FM
875 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
876 exit(1);
877 }
878 }
936c9905
FM
879
880 if ((str = strchr(code, ':')) != NULL)
2357ef77 881 *str = '/';
936c9905
FM
882
883 if(strcmp(tam,"\0") == 0)
884 strcpy(tam,"0");
885
58d7d8fe
FM
886 ilf=ILF_Common;
887 ilf_count[ilf]++;
936c9905
FM
888 }
889 }
890
58d7d8fe 891 if(ilf==ILF_Unknown || ilf==ILF_Squid) {
9c7c6346 892 if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
936c9905
FM
893 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
894 exit(1);
895 }
9c7c6346
FM
896 while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0')
897 if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
936c9905
FM
898 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
899 exit(1);
900 }
901 if(strlen(elap) < 1) continue;
9c7c6346 902 if (getword(ip,sizeof(ip),&gwarea,' ')<0){
936c9905
FM
903 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
904 exit(1);
905 }
9c7c6346 906 if (getword(code,sizeof(code),&gwarea,' ')<0){
936c9905
FM
907 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
908 exit(1);
909 }
9c7c6346 910 if (getword(tam,sizeof(tam),&gwarea,' ')<0){
936c9905
FM
911 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
912 exit(1);
913 }
9c7c6346 914 if (getword(fun,sizeof(fun),&gwarea,' ')<0){
936c9905
FM
915 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
916 exit(1);
917 }
9c7c6346 918 if (getword(url,sizeof(url),&gwarea,' ')<0){
936c9905
FM
919 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
920 exit(1);
921 }
d6e703cc
FM
922// while (strstr(bufz,"%20") != 0) {
923// getword(warea,bufz,' ');
924// strcat(url,warea);
925// }
9c7c6346 926 if (getword(user,sizeof(user),&gwarea,' ')<0){
936c9905
FM
927 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
928 exit(1);
929 }
58d7d8fe
FM
930 ilf=ILF_Squid;
931 ilf_count[ilf]++;
936c9905 932 }
58d7d8fe
FM
933 }
934 if (ilf==ILF_Sarg) {
9c7c6346 935 getword_start(&gwarea,bufz);
ff8d5836 936 if (getword(data,sizeof(data),&gwarea,'\t')<0){
936c9905
FM
937 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
938 exit(1);
939 }
ff8d5836 940 if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
936c9905
FM
941 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
942 exit(1);
943 }
ff8d5836 944 if (getword(user,sizeof(user),&gwarea,'\t')<0) {
936c9905
FM
945 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
946 exit(1);
947 }
ff8d5836 948 if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
936c9905
FM
949 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
950 exit(1);
951 }
ff8d5836 952 if (getword(url,sizeof(url),&gwarea,'\t')<0){
936c9905
FM
953 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
954 exit(1);
955 }
ff8d5836 956 if (getword(tam,sizeof(tam),&gwarea,'\t')<0){
936c9905
FM
957 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
958 exit(1);
959 }
ff8d5836 960 if (getword(code,sizeof(code),&gwarea,'\t')<0){
936c9905
FM
961 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
962 exit(1);
963 }
ff8d5836 964 if (getword(elap,sizeof(elap),&gwarea,'\t')<0){
936c9905
FM
965 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
966 exit(1);
967 }
ff8d5836 968 if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){
936c9905
FM
969 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
970 exit(1);
971 }
58d7d8fe
FM
972 }
973 if (ilf==ILF_Isa) {
076cbab8
FM
974 if (bufz[0] == '#') {
975 int ncols,cols[ISACOL_Last];
976
977 fixendofline(bufz);
9c7c6346 978 getword_start(&gwarea,bufz);
076cbab8 979 // remove the #Fields: column at the beginning of the line
9c7c6346 980 if (getword_skip(1000,&gwarea,' ')<0){
936c9905
FM
981 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
982 exit(1);
983 }
076cbab8
FM
984 for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
985 ncols=0;
9c7c6346
FM
986 while(gwarea.current[0] != '\0') {
987 if (getword(val1,sizeof(val1),&gwarea,'\t')<0){
936c9905
FM
988 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
989 exit(1);
990 }
076cbab8
FM
991 if(strcmp(val1,"c-ip") == 0) cols[ISACOL_Ip]=ncols;
992 if(strcmp(val1,"cs-username") == 0) cols[ISACOL_UserName]=ncols;
993 if(strcmp(val1,"date") == 0) cols[ISACOL_Date]=ncols;
994 if(strcmp(val1,"time") == 0) cols[ISACOL_Time]=ncols;
995 if(strcmp(val1,"time-taken") == 0) cols[ISACOL_TimeTaken]=ncols;
996 if(strcmp(val1,"sc-bytes") == 0) cols[ISACOL_Bytes]=ncols;
997 if(strcmp(val1,"cs-uri") == 0) cols[ISACOL_Uri]=ncols;
998 if(strcmp(val1,"sc-status") == 0) cols[ISACOL_Status]=ncols;
999 ncols++;
936c9905 1000 }
076cbab8
FM
1001 if (cols[ISACOL_Ip]>=0) {
1002 isa_ncols=ncols;
1003 for (isa_ncols=0 ; isa_ncols<ncols ; isa_ncols++)
1004 isa_cols[isa_ncols]=cols[isa_ncols];
936c9905 1005 }
076cbab8 1006 continue;
936c9905 1007 }
076cbab8 1008 if (!isa_ncols) continue;
9c7c6346 1009 getword_start(&gwarea,bufz);
076cbab8 1010 for (x=0 ; x<isa_ncols ; x++) {
9c7c6346 1011 if (getword(val1,sizeof(val1),&gwarea,'\t')<0) {
936c9905
FM
1012 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
1013 exit(1);
1014 }
076cbab8 1015 if (x==isa_cols[ISACOL_Ip]) {
5160b452
FM
1016 if (strlen(val1)>=sizeof(ip)) {
1017 printf("SARG: Maybe you have a broken IP in your %s file.\n",arq);
1018 exit(1);
1019 }
1020 strcpy(ip,val1);
076cbab8 1021 } else if (x==isa_cols[ISACOL_UserName]) {
5160b452
FM
1022 if (strlen(val1)>=sizeof(user)) {
1023 printf("SARG: Maybe you have a broken user in your %s file.\n",arq);
1024 exit(1);
1025 }
1026 strcpy(user,val1);
076cbab8 1027 } else if (x==isa_cols[ISACOL_Date]) {
5160b452
FM
1028 if (strlen(val1)>=sizeof(data)) {
1029 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1030 exit(1);
1031 }
1032 strcpy(data,val1);
076cbab8 1033 } else if (x==isa_cols[ISACOL_Time]) {
5160b452
FM
1034 if (strlen(val1)>=sizeof(hora)) {
1035 printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
1036 exit(1);
1037 }
1038 strcpy(hora,val1);
076cbab8 1039 } else if (x==isa_cols[ISACOL_TimeTaken]) {
5160b452
FM
1040 if (strlen(val1)>=sizeof(elap)) {
1041 printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq);
1042 exit(1);
1043 }
1044 strcpy(elap,val1);
076cbab8 1045 } else if (x==isa_cols[ISACOL_Bytes]) {
5160b452
FM
1046 if (strlen(val1)>=sizeof(tam)) {
1047 printf("SARG: Maybe you have a broken download size in your %s file.\n",arq);
1048 exit(1);
1049 }
1050 strcpy(tam,val1);
076cbab8 1051 } else if (x==isa_cols[ISACOL_Uri]) {
5160b452
FM
1052 if (strlen(val1)>=sizeof(url)) {
1053 printf("SARG: Maybe you have a broken URL in your %s file.\n",arq);
1054 exit(1);
1055 }
1056 strcpy(url,val1);
076cbab8 1057 } else if (x==isa_cols[ISACOL_Status]) {
5160b452
FM
1058 if (strlen(val1)>=sizeof(code)) {
1059 printf("SARG: Maybe you have a broken access code in your %s file.\n",arq);
1060 exit(1);
1061 }
1062 strcpy(code,val1);
936c9905
FM
1063 }
1064 }
1065
1066 if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
1067 sprintf(val1,"DENIED/%s",code);
1068 strcpy(code,val1);
1069 }
9c7c6346
FM
1070 getword_start(&gwarea,data);
1071 if (getword(ano,sizeof(ano),&gwarea,'-')<0){
936c9905
FM
1072 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
1073 exit(1);
1074 }
9c7c6346 1075 if (getword(mes,sizeof(mes),&gwarea,'-')<0){
936c9905
FM
1076 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
1077 exit(1);
1078 }
9c7c6346 1079 if (getword(dia,sizeof(dia),&gwarea,'\0')<0){
936c9905
FM
1080 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq);
1081 exit(1);
1082 }
936c9905
FM
1083 conv_month_name(mes);
1084 sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora);
1085 }
1086
1087 if(strlen(user) > 150) {
5160b452 1088 if (debugm) printf("User too long: %s\n",user);
936c9905
FM
1089 totregsx++;
1090 continue;
1091 }
1092
1093 // include_users
4af2f8ff 1094 if(IncludeUsers[0] != '\0') {
936c9905
FM
1095 sprintf(val1,":%s:",user);
1096 if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL )
1097 continue;
1098 }
1099
48864d28 1100 if(vercode(code)) {
5160b452 1101 if (debugm) printf("Excluded code: %s\n",code);
48864d28
FM
1102 totregsx++;
1103 continue;
936c9905
FM
1104 }
1105
1106 if(testvaliduserchar(user))
1107 continue;
1108
06ced858 1109#if 0
0ff563a2
FM
1110 if((str = strstr(user,"%20")) != NULL) {
1111 /*
697028cc
FM
1112 This is a patch introduced to solve bug #1624251 reported at sourceforge but
1113 the side effect is to truncate the name at the first space and merge the reports
1114 of people whose name is identical up to the first space.
0ff563a2
FM
1115
1116 The old code used to truncate the user name at the first % if a %20 was
1117 found anywhere in the string. That means the string could be truncated
1118 at the wrong place if another % occured before the %20. This new code should
1119 avoid that problem and only truncate at the space. There is no bug
1120 report indicating that anybody noticed this.
1121 */
1122 *str='\0';
936c9905
FM
1123 }
1124
9c7c6346
FM
1125 /*
1126 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1127 found in the user name.
1128 */
1129 while((str = strstr(user,"%5c")) != NULL) {
1130 *str='.';
1131 for (x=3 ; str[x] ; x++) str[x-2]=str[x];
936c9905 1132 }
06ced858 1133#endif
936c9905 1134
5542cb59
FM
1135 for(str=user; *str; str++) {
1136 if(*str=='.') dotinuser++;
392760b3
FM
1137 if(*str=='?' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='\'' || *str=='$' || *str=='@' ||
1138 *str=='\"' || *str=='*')
5542cb59 1139 *str='_';
936c9905
FM
1140 }
1141
1142 strlow(user);
1143 if(strncmp(NtlmUserFormat,"user",4) == 0) {
9c7c6346
FM
1144 if((str = strchr(user,'_')) != 0) {
1145 strcpy(warea,str+1);
1146 strcpy(user,warea);
1147 }
1148 if((str = strchr(user,'+')) != 0) {
1149 strcpy(warea,str+1);
1150 strcpy(user,warea);
1151 }
936c9905
FM
1152 }
1153
085c1e1f 1154 if((ReportType & REPORT_TYPE_DENIED) != 0)
936c9905
FM
1155 strcpy(urly,url);
1156
ff8d5836
FM
1157 if(ilf!=ILF_Sarg) {
1158 /*
1159 The full URL is not saved in sarg log. There is no point in testing the URL to detect
1160 a downloaded file.
1161 */
1162 download_flag=is_download_suffix(url);
1163 if (download_flag) {
1164 strcpy(download_url,url);
1165 download_count++;
1166 }
936c9905
FM
1167 }
1168
9c7c6346
FM
1169 // remove any protocol:// at the beginning of the URL
1170 if ((str = strchr(url,'/')) != NULL && str[1] == '/') {
1171 int i;
1172
1173 str+=2;
1174 for (i=0 ; str[i] ; i++)
1175 url[i]=str[i];
1176 url[i]='\0';
936c9905
FM
1177 }
1178
246c8489 1179 if(!LongUrl) {
4157aa09
FM
1180 char *endofhost=strchr(url,'/');
1181 if (endofhost)
1182 *endofhost='\0';
1183 if(strlen(url) > 512 && (endofhost=strchr(url,'%')) != NULL) {
1184 *endofhost='\0';
936c9905
FM
1185 }
1186 }
1187
58d7d8fe
FM
1188 if(ilf==ILF_Squid) {
1189 tt=atoi(data);
1190 t=localtime(&tt);
1191
1192 strftime(tbuf2, sizeof(tbuf2), "%H%M", t);
e6414a9d
FM
1193 sprintf(mes,"%d",t->tm_mon+1);
1194 conv_month_name(mes);
58d7d8fe 1195 if(strncmp(df,"u",1) == 0)
e6414a9d 1196 sprintf(tbuf, "%04d%s%02d", t->tm_year+1900, mes, t->tm_mday);
58d7d8fe 1197 if(strncmp(df,"e",1) == 0)
e6414a9d 1198 sprintf(tbuf, "%02d%s%04d", t->tm_mday, mes, t->tm_year+1900);
58d7d8fe 1199 if(strncmp(df,"w",1) == 0) {
0349fa24 1200 IndexTree=INDEX_TREE_FILE;
58d7d8fe
FM
1201 strftime(tbuf, sizeof(tbuf), "%Y.%U", t);
1202 }
936c9905 1203
58d7d8fe
FM
1204 strftime(wdata, sizeof(wdata), "%Y%m%d", t);
1205 idata=atoi(wdata);
936c9905 1206
58d7d8fe
FM
1207 if(strncmp(df,"u",1)==0)
1208 strftime(dia, sizeof(dia), "%m/%d/%Y", t);
1209 else
1210 strftime(dia, sizeof(dia), "%d/%m/%Y", t);
1211 sprintf(hora,"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
1212 } else if(ilf==ILF_Common || ilf==ILF_Isa) {
9c7c6346
FM
1213 getword_start(&gwarea,data+1);
1214 if (getword_multisep(data,sizeof(data),&gwarea,':')<0){
58d7d8fe
FM
1215 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1216 exit(1);
1217 }
9c7c6346 1218 if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){
58d7d8fe
FM
1219 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1220 exit(1);
1221 }
9c7c6346 1222 getword_start(&gwarea,data);
ff8d5836 1223 if (getword(dia,sizeof(dia),&gwarea,'/')<0){
58d7d8fe
FM
1224 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1225 exit(1);
936c9905 1226 }
ff8d5836 1227 if (getword(mes,sizeof(mes),&gwarea,'/')<0){
58d7d8fe
FM
1228 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1229 exit(1);
1230 }
ff8d5836 1231 if (getword(ano,sizeof(ano),&gwarea,'/')<0){
58d7d8fe
FM
1232 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1233 exit(1);
1234 }
1235
1236 if(strcmp(df,"u") == 0)
1237 snprintf(tbuf,sizeof(tbuf),"%s%s%s",ano,mes,dia);
1238 if(strcmp(df,"e") == 0)
1239 snprintf(tbuf,sizeof(tbuf),"%s%s%s",dia,mes,ano);
1240 builddia(dia,mes,ano,df,wdata);
1241 idata=atoi(wdata);
1242 } else if (ilf==ILF_Sarg) {
9c7c6346 1243 getword_start(&gwarea,data);
ff8d5836
FM
1244 if(strcmp(df,"u") == 0) {
1245 if (getword(mes,sizeof(mes),&gwarea,'/')<0){
1246 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1247 exit(1);
1248 }
1249 if (getword(dia,sizeof(dia),&gwarea,'/')<0){
1250 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1251 exit(1);
1252 }
1253 } else {
1254 if (getword(dia,sizeof(dia),&gwarea,'/')<0){
1255 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1256 exit(1);
1257 }
1258 if (getword(mes,sizeof(mes),&gwarea,'/')<0){
1259 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1260 exit(1);
1261 }
936c9905 1262 }
ff8d5836 1263 if (getword(ano,sizeof(ano),&gwarea,0)<0){
936c9905
FM
1264 printf("SARG: Maybe you have a broken date in your %s file.\n",arq);
1265 exit(1);
1266 }
ff8d5836
FM
1267 snprintf(wdata,9,"%s%s%s",ano,mes,dia);
1268 idata=atoi(wdata);
936c9905
FM
1269 }
1270
1271 if(debugm)
1272 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil);
1273
1274 l=1;
936c9905 1275 if(l){
5542cb59 1276 if(addr[0] != '\0'){
936c9905
FM
1277 if(strcmp(addr,ip)==0)
1278 l=1;else l=0;
1279 }
1280 if(fhost) {
43f18f45
FM
1281// l=vhexclude(ip);
1282 l=vhexclude(url);
5160b452
FM
1283 if(!l) {
1284 if (debugm) printf("Excluded site: %s\n",url);
936c9905 1285 totregsx++;
5160b452 1286 }
936c9905
FM
1287 }
1288 }
25697a35 1289
936c9905 1290 if(l){
5542cb59 1291 if(date[0] != '\0'){
936c9905
FM
1292 if(idata >= dfrom && idata <= duntil)
1293 l=1;else l=0;
1294 }
1295 }
1296 if(l){
5542cb59 1297 if(hm[0] != '\0') {
9c7c6346 1298 bzero(hmr,sizeof(hmr));
936c9905 1299 chm++;
9c7c6346 1300 getword_start(&gwarea,hora);
936c9905 1301 while(chm) {
9c7c6346 1302 if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){
936c9905
FM
1303 printf("SARG: Maybe you have a broken time in your %s file.\n",arq);
1304 exit(1);
1305 }
1306 strncat(hmr,warea,2);
1307 chm--;
1308 }
9c7c6346 1309 strncat(hmr,gwarea.current,2);
25697a35 1310
936c9905
FM
1311 if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf))
1312 l=1;else l=0;
1313 }
1314 }
1315 if(l){
5542cb59 1316 if(site[0] != '\0'){
936c9905
FM
1317 if(strstr(url,site)!=0)
1318 l=1;else l=0;
1319 }
1320 }
1321
1322 if(userip)
1323 strcpy(user,ip);
1324
1325 if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
1326 if(strcmp(RecordsWithoutUser,"ip") == 0)
2357ef77 1327 strcpy(user,ip);
936c9905 1328 if(strcmp(RecordsWithoutUser,"ignore") == 0)
2357ef77 1329 continue;
936c9905 1330 if(strcmp(RecordsWithoutUser,"everybody") == 0)
2357ef77 1331 strcpy(user,"everybody");
936c9905 1332 }
120d768c
FM
1333 if(us[0] != '\0'){
1334 if(strcmp(user,us)==0)
1335 l=1;
1336 else
1337 l=0;
1338 }
936c9905
FM
1339
1340 if(dotinuser) {
48864d28 1341 subs(user,sizeof(user),"_",".");
936c9905
FM
1342 dotinuser=0;
1343 }
1344
1345 if(puser) {
1346 sprintf(wuser,":%s:",user);
1347 if(strstr(userfile, wuser) == 0)
1348 continue;
1349 }
1350
1351 if(l) {
1352 if(fuser) {
43f18f45 1353 l=vuexclude(user);
5160b452
FM
1354 if(!l) {
1355 if (debugm) printf("Excluded user: %s\n",user);
936c9905 1356 totregsx++;
5160b452 1357 }
936c9905
FM
1358 }
1359 }
1360
1361 if(l) {
1362 if(userip)
1363 fixip(user);
1364 }
1365
5542cb59 1366 if(l && max_elapsed) {
936c9905
FM
1367 if(atol(elap)>max_elapsed) {
1368 elap[0]='0';
1369 elap[1]='\0';
1370 }
1371 }
1372
1373 if(l) {
5542cb59 1374 if(strcmp(user,"-") !=0 && url[0] != '\0' && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){
936c9905 1375 if((str=(char *) strstr(bufz, "[SmartFilter:")) != (char *) NULL ) {
120d768c 1376 fixendofline(str);
936c9905
FM
1377 sprintf(smartfilter,"\"%s\"",str+1);
1378 } else sprintf(smartfilter,"\"\"");
1379
120d768c 1380 sprintf(bufz, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter);
25697a35 1381
936c9905
FM
1382 if ( strcmp ( user , sz_Last_User ) != 0 ) {
1383 if ( fp_Write_User )
1384 fclose( fp_Write_User ) ;
1385 sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
1386
1387 if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
1388 fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
1389 exit (1);
25697a35 1390 }
936c9905
FM
1391 strcpy( sz_Last_User , user ) ;
1392 }
1393 fputs (bufz, fp_Write_User);
25697a35 1394
ff8d5836 1395 if(fp_log && ilf!=ILF_Sarg) fputs(bufz,fp_log);
25697a35 1396
936c9905 1397 totregsg++;
25697a35 1398
936c9905
FM
1399 if(download_flag && strstr(code,"DENIED") == 0) {
1400 ndownload = 1;
25697a35 1401
936c9905
FM
1402 if ( ! fp_Download_Unsort ) {
1403 if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) {
1404 fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno));
1405 exit (1);
1406 }
1407 }
120d768c 1408 fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url);
936c9905
FM
1409 }
1410
085c1e1f 1411 if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
936c9905 1412 if(strstr(code,"DENIED/403") != 0) {
120d768c 1413 fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
936c9905
FM
1414 denied_count++;
1415 }
1416 if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) {
1417 if(fp_authfail)
120d768c 1418 fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly);
936c9905
FM
1419 authfail_count++;
1420 }
1421 }
1422
58d7d8fe 1423 if((!totper || idata<mindate) && ilf!=ILF_Sarg){
936c9905
FM
1424 totper++;
1425 mindate=idata;
1426 sprintf(period,"%s-",tbuf);
ff8d5836 1427 strcpy(start_hour,tbuf2);
120d768c 1428 if(date[0] != '\0')
936c9905
FM
1429 fixper(tbuf, period, cduntil);
1430 if(debugz){
1431 debugaz("tbuf",tbuf);
1432 debugaz("period",period);
1433 }
1434 }
1435 }
1436
1437 if(debugm){
1438 printf("IP=\t%s\n",ip);
1439 printf("USER=\t%s\n",user);
1440 printf("ELAP=\t%s\n",elap);
1441 printf("DATE=\t%s\n",dia);
1442 printf("TIME=\t%s\n",hora);
1443 printf("FUNC=\t%s\n",fun);
1444 printf("URL=\t%s\n",url);
1445 printf("CODE=\t%s\n",code);
1446 printf("LEN=\t%s\n",tam);
1447 }
1448 }
25697a35 1449 }
58d7d8fe
FM
1450 if (!from_stdin) {
1451 fclose(fp_in);
e6414a9d 1452 if( ShowReadStatistics )
7c0b0078 1453 printf("SARG: Records in file: %lu, reading: %3.2f%%\n",recs1, (float) 100 );
58d7d8fe 1454 }
25697a35
GS
1455 }
1456
2357ef77 1457 if ( fp_Download_Unsort )
25697a35
GS
1458 fclose (fp_Download_Unsort);
1459
2357ef77 1460 if (fp_Write_User)
25697a35
GS
1461 fclose (fp_Write_User);
1462
43f18f45
FM
1463 free_download();
1464 free_excludecodes();
1465 free_exclude();
1466
25697a35 1467 if(debug) {
58d7d8fe
FM
1468 int totalcount=0;
1469
1470 for (ilf=0 ; ilf<ILF_Last ; ilf++) totalcount+=ilf_count[ilf];
1471
d2fe0c32 1472 debuga(" %s: %ld, %s: %ld, %s: %ld",text[10],totregsl,text[11],totregsg,text[68],totregsx);
936c9905 1473
58d7d8fe 1474 if(ilf_count[ILF_Common]>0 && ilf_count[ILF_Squid]>0)
d2fe0c32 1475 debuga("%s",text[12]);
936c9905 1476
58d7d8fe 1477 if(ilf_count[ILF_Common]>0 && ilf_count[ILF_Squid]==0)
d2fe0c32 1478 debuga("%s",text[13]);
936c9905 1479
58d7d8fe 1480 if(ilf_count[ILF_Common]==0 && ilf_count[ILF_Squid]>0)
d2fe0c32 1481 debuga("%s",text[14]);
25697a35 1482
58d7d8fe 1483 if(ilf_count[ILF_Sarg]>0)
d2fe0c32 1484 debuga("%s",text[124]);
936c9905 1485
58d7d8fe 1486 if(totalcount==0) {
25697a35
GS
1487 if(!totregsg) {
1488 fprintf(stderr, "SARG: %s\n",text[16]);
1489 fprintf(stderr, "SARG: %s\n",text[21]);
936c9905 1490 } else fprintf(stderr, "SARG: %s\n",text[15]);
25697a35
GS
1491 if(fp_denied)
1492 fclose(fp_denied);
1493 if(fp_authfail)
1494 fclose(fp_authfail);
e3af0ae9
PO
1495// if(userfile)
1496//// free(userfile);
32e71fa4
FM
1497 unlink(tmp4);
1498 unlink(tmp6);
25697a35
GS
1499 unlink(tmp3);
1500 exit(0);
1501 }
1502 }
936c9905 1503
25697a35
GS
1504 if(!totregsg){
1505 fprintf(stderr, "SARG: %s\n",text[16]);
1506 fprintf(stderr, "SARG: %s\n",text[21]);
25697a35
GS
1507// fclose(fp_ou);
1508 if(fp_denied)
1509 fclose(fp_denied);
1510 if(fp_authfail)
1511 fclose(fp_authfail);
3d254696
FM
1512 if(userfile)
1513 free(userfile);
25697a35
GS
1514 exit(0);
1515 }
1516
58d7d8fe 1517 if(date[0] == '\0' && ilf_count[ILF_Sarg]==0) {
d6e703cc 1518 strcat(period,tbuf);
25697a35
GS
1519 }
1520
1521 if(debugz){
1522 debugaz("data",dia);
1523 debugaz("tbuf",tbuf);
d6e703cc 1524 debugaz("period",period);
25697a35
GS
1525 }
1526
d2fe0c32
FM
1527 if(debug)
1528 debuga("%s: %s",text[17],period);
25697a35 1529
25697a35
GS
1530// fclose(fp_ou);
1531 if(fp_denied)
1532 fclose(fp_denied);
1533 if(fp_authfail)
1534 fclose(fp_authfail);
1535
58d7d8fe 1536 if(fp_log != NULL) {
2357ef77 1537 fclose(fp_log);
ff8d5836 1538 strcpy(end_hour,tbuf2);
9c7c6346 1539 getword_start(&gwarea,period);
ff8d5836 1540 if (getword(val2,sizeof(val2),&gwarea,'-')<0){
4bcb77cf
FM
1541 printf("SARG: Maybe you have a broken date range definition.\n");
1542 exit(1);
1543 }
ff8d5836 1544 if (getword(val1,sizeof(val1),&gwarea,'\0')<0){
4bcb77cf
FM
1545 printf("SARG: Maybe you have a broken date range definition.\n");
1546 exit(1);
1547 }
ff8d5836
FM
1548 sprintf(val4,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog,val2,start_hour,val1,end_hour);
1549 if (rename(arq_log,val4)) {
1550 fprintf(stderr,"SARG: failed to rename %s to %s - %s\n",arq_log,val4,strerror(errno));
1551 } else {
1552 strcpy(arq_log,val4);
1553
1554 if(strcmp(ParsedOutputLogCompress,"nocompress") != 0 && ParsedOutputLogCompress[0] != '\0') {
1555 /*
1556 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1557 necessary around the command name, put them in the configuration file.
1558 */
1559 sprintf(val1,"%s \"%s\"",ParsedOutputLogCompress,arq_log);
1560 cstatus=system(val1);
1561 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
1562 fprintf(stderr, "SARG: command return status %d\n",WEXITSTATUS(cstatus));
1563 fprintf(stderr, "SARG: command: %s\n",val1);
1564 exit(1);
1565 }
456d78a5 1566 }
25697a35 1567 }
d2fe0c32
FM
1568 if(debug)
1569 debuga("%s %s",text[123],arq_log);
25697a35 1570 }
25697a35 1571
085c1e1f 1572 if((ReportType & REPORT_TYPE_DENIED) != 0) {
9a2efbd0 1573 sprintf(csort,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp,tmp5,tmp4);
456d78a5
FM
1574 cstatus=system(csort);
1575 if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
1576 fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
1577 fprintf(stderr, "SARG: sort command: %s\n",csort);
1578 exit(1);
1579 }
25697a35
GS
1580 unlink(tmp4);
1581 }
936c9905 1582
491b862f 1583 sort_users_log(tmp, debug);
25697a35 1584
4157aa09 1585 if(DataFile[0] != '\0')
25697a35
GS
1586 data_file(tmp);
1587 else
1588 gerarel();
1589
1590 unlink(tmp2);
085c1e1f 1591 if((ReportType & REPORT_TYPE_DENIED) != 0)
25697a35 1592 unlink(tmp5);
936c9905 1593
5542cb59 1594 if(zip[0] != '\0' && strcmp(zip,"zcat") !=0) {
936c9905
FM
1595 recomp(arq, zip);
1596 }
25697a35
GS
1597// else unlink(arq);
1598
d6e703cc 1599 if(strcmp(tmp,"/tmp") != 0) {
51465d08 1600 unlinkdir(tmp,0);
d6e703cc 1601 }
25697a35 1602
491b862f
GS
1603 if(userfile)
1604 free(userfile);
491b862f 1605
d6e703cc 1606 if(debug)
d2fe0c32 1607 debuga("%s",text[21]);
d6e703cc 1608
25697a35
GS
1609 exit(0);
1610
1611}
1612
1613
936c9905 1614static void getusers(const char *pwdfile, int debug)
25697a35
GS
1615{
1616
1617 FILE *fp_usr;
1618 char buf[255];
936c9905 1619 char *str;
39186a2f 1620 long int nreg=0;
25697a35 1621
d2fe0c32
FM
1622 if(debug)
1623 debuga("%s: %s",text[60],pwdfile);
25697a35
GS
1624
1625 if ((fp_usr = fopen(pwdfile, "r")) == NULL) {
1626 fprintf(stderr, "SARG: (getusers) %s: %s - %s\n",text[45],pwdfile,strerror(errno));
1627 exit(1);
1628 }
1629
ddd6ce01 1630 fseek(fp_usr, 0, SEEK_END);
d6dfc139 1631 nreg = ftell(fp_usr);
5355d243
FM
1632 if (nreg<0) {
1633 printf("SARG: Cannot get the size of file %s",pwdfile);
1634 exit(1);
1635 }
936c9905 1636 nreg = nreg+5000;
ddd6ce01 1637 fseek(fp_usr, 0, SEEK_SET);
25697a35
GS
1638
1639 if((userfile=(char *) malloc(nreg))==NULL){
1640 fprintf(stderr, "SARG: %s (%ld):\n",text[59],nreg);
1641 exit(1);
1642 }
1643
1644 bzero(userfile,nreg);
936c9905
FM
1645 strcpy(userfile,":");
1646
1647 while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
1648 str=strchr(buf,':');
1649 if (!str) {
1650 printf("SARG: You have an invalid user in your %s file.\n",pwdfile);
1651 exit(1);
1652 }
1653 str[1]=0;
1654 strcat(userfile,buf);
25697a35
GS
1655 }
1656
1657 fclose(fp_usr);
1658
1659 return;
1660}