]> git.ipfire.org Git - thirdparty/sarg.git/blob - log.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / log.c
1 /*
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
3 * 1998, 2015
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
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 #include "include/readlog.h"
30 #include "include/filelist.h"
31
32 #ifdef HAVE_GETOPT_H
33 #include <getopt.h>
34 #endif
35
36 //! The log file filtering.
37 struct ReadLogDataStruct ReadFilter;
38
39 //! The list of the system users.
40 /*@null@*/char *userfile=NULL;
41
42 //! List of the input log files to process.
43 FileListObject AccessLog=NULL;
44
45
46 //! Selected locale set through the environment variable.
47 char *CurrentLocale=NULL;
48
49 static void getusers(const char *pwdfile, int debug);
50
51 int main(int argc,char *argv[])
52 {
53 extern int optind;
54 extern int optopt;
55 extern char *optarg;
56
57 char hm_str[15];
58 char uagent[MAXLEN];
59 char hexclude[MAXLEN];
60 char splitprefix[MAXLEN];
61 int ch;
62 int errflg=0;
63 bool dns=false;
64 int iarq=0;
65 int lastlog=-1;
66 int LogStatus;
67 bool realt;
68 bool userip;
69 time_t start_time;
70 time_t end_time;
71 time_t read_start_time;
72 time_t read_end_time;
73 time_t process_start_time;
74 time_t process_end_time;
75 double read_elapsed;
76 double process_elapsed;
77 FileListIterator FIter;
78 static int split=0;
79 static int convert=0;
80 static int output_css=0;
81 static int show_statis=0;
82 int option_index;
83 static struct option long_options[]=
84 {
85 {"convert",no_argument,&convert,1},
86 {"css",no_argument,&output_css,1},
87 {"help",no_argument,NULL,'h'},
88 {"lastlog",required_argument,NULL,2},
89 {"keeplogs",no_argument,NULL,3},
90 {"split",no_argument,&split,1},
91 {"splitprefix",required_argument,NULL,'P'},
92 {"statistics",no_argument,&show_statis,1},
93 {"version",no_argument,NULL,'V'},
94 {0,0,0,0}
95 };
96
97 start_time=time(NULL);
98
99 #ifdef HAVE_LOCALE_H
100 setlocale(LC_TIME,"");
101 #endif
102
103 #if defined(ENABLE_NLS) && defined(HAVE_LOCALE_H)
104 CurrentLocale=setlocale (LC_ALL, "");
105 if (!CurrentLocale) {
106 fprintf(stderr,"SARG: Cannot set the locale LC_ALL to the environment variable\n");
107 exit(EXIT_FAILURE);
108 }
109 if (!bindtextdomain (PACKAGE_NAME, LOCALEDIR)) {
110 fprintf(stderr,"SARG: Cannot bind to text domain %s in directory %s (%s)\n",PACKAGE_NAME,LOCALEDIR,strerror(errno));
111 exit(EXIT_FAILURE);
112 }
113 if (!textdomain (PACKAGE_NAME)) {
114 fprintf(stderr,"SARG: Cannot set gettext domain for %s PACKAGE_NAME (%s)\n",PACKAGE_NAME,strerror(errno));
115 exit(EXIT_FAILURE);
116 }
117 #endif //ENABLE_NLS
118
119 BgImage[0]='\0';
120 LogoImage[0]='\0';
121 LogoText[0]='\0';
122 PasswdFile[0]='\0';
123 OutputEmail[0]='\0';
124 UserAgentLog[0]='\0';
125 ExcludeHosts[0]='\0';
126 ExcludeUsers[0]='\0';
127 ConfigFile[0]='\0';
128 code[0]='\0';
129 LastLog=0;
130 ReportType=0UL;
131 UserTabFile[0]='\0';
132 BlockIt[0]='\0';
133 ExternalCSSFile[0]='\0';
134 RedirectorLogFormat[0]='\0';
135 NRedirectorLogs=0;
136
137 snprintf(ExcludeCodes,sizeof(ExcludeCodes),"%s/exclude_codes",SYSCONFDIR);
138 strcpy(GraphDaysBytesBarColor,"orange");
139 strcpy(BgColor,"#ffffff");
140 strcpy(TxColor,"#000000");
141 strcpy(TxBgColor,"lavender");
142 strcpy(TiColor,"darkblue");
143 strcpy(Width,"80");
144 strcpy(Height,"45");
145 strcpy(LogoTextColor,"#000000");
146 strcpy(HeaderColor,"darkblue");
147 strcpy(HeaderBgColor,"#dddddd");
148 strcpy(LogoTextColor,"#006699");
149 strcpy(FontSize,"9px");
150 strcpy(TempDir,"/tmp");
151 strcpy(OutputDir,"/var/www/html/squid-reports");
152 AnonymousOutputFiles=false;
153 Ip2Name=false;
154 DateFormat='u';
155 OverwriteReport=false;
156 RemoveTempFiles=true;
157 strcpy(ReplaceIndex,INDEX_HTML_FILE);
158 Index=INDEX_YES;
159 RecordsWithoutUser=RECORDWITHOUTUSER_IP;
160 UseComma=0;
161 strcpy(MailUtility,"mailx");
162 TopSitesNum=100;
163 TopUsersNum=0;
164 UserIp=0;
165 TopuserSort=TOPUSER_SORT_BYTES | TOPUSER_SORT_REVERSE;
166 UserSort=USER_SORT_BYTES | USER_SORT_REVERSE;
167 TopsitesSort=TOPSITE_SORT_CONNECT | TOPSITE_SORT_REVERSE;
168 LongUrl=0;
169 strcpy(FontFace,"Verdana,Tahoma,Arial");
170 datetimeby=DATETIME_BYTE;
171 strcpy(CharSet,"ISO-8859-1");
172 Privacy=0;
173 strcpy(PrivacyString,"***.***.***.***");
174 strcpy(PrivacyStringColor,"blue");
175 SuccessfulMsg=true;
176 TopUserFields=TOPUSERFIELDS_NUM | TOPUSERFIELDS_DATE_TIME | TOPUSERFIELDS_USERID | TOPUSERFIELDS_CONNECT |
177 TOPUSERFIELDS_BYTES | TOPUSERFIELDS_SETYB | TOPUSERFIELDS_IN_CACHE_OUT |
178 TOPUSERFIELDS_USED_TIME | TOPUSERFIELDS_MILISEC | TOPUSERFIELDS_PTIME |
179 TOPUSERFIELDS_TOTAL | TOPUSERFIELDS_AVERAGE;
180 UserReportFields=USERREPORTFIELDS_CONNECT | USERREPORTFIELDS_BYTES | USERREPORTFIELDS_SETYB |
181 USERREPORTFIELDS_IN_CACHE_OUT | USERREPORTFIELDS_USED_TIME | USERREPORTFIELDS_MILISEC |
182 USERREPORTFIELDS_PTIME | USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE;
183 strcpy(DataFileDelimiter,";");
184 DataFileFields=DATA_FIELD_USER | DATA_FIELD_DATE | DATA_FIELD_TIME | DATA_FIELD_URL | DATA_FIELD_CONNECT |
185 DATA_FIELD_BYTES | DATA_FIELD_IN_CACHE | DATA_FIELD_OUT_CACHE | DATA_FIELD_ELAPSED;
186 ShowReadStatistics=true;
187 ShowReadPercent=false;
188 strcpy(IndexSortOrder,"D");
189 ShowSargInfo=true;
190 ShowSargLogo=true;
191 ParsedOutputLog[0]='\0';
192 strcpy(ParsedOutputLogCompress,"/bin/gzip -f");
193 DisplayedValues=DISPLAY_ABBREV;
194 strcpy(HeaderFontSize,"9px");
195 strcpy(TitleFontSize,"11px");
196 strcpy(AuthUserTemplateFile,"sarg_htaccess");
197 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");
198 Graphs=true;
199 #if defined(FONTDIR)
200 strcpy(GraphFont,FONTDIR"/DejaVuSans.ttf");
201 #else
202 GraphFont[0]='\0';
203 #endif
204 strcpy(Ulimit,"20000");
205 NtlmUserFormat=NTLMUSERFORMAT_DOMAINUSER;
206 IndexTree=INDEX_TREE_FILE;
207 IndexFields=INDEXFIELDS_DIRSIZE;
208 strcpy(RealtimeTypes,"GET,PUT,CONNECT,POST");
209 RealtimeUnauthRec=REALTIME_UNAUTH_REC_SHOW;
210 RedirectorFilterOutDate=true;
211 DansguardianFilterOutDate=true;
212 DataFileUrl=DATAFILEURL_IP;
213 strcpy(MaxElapsed,"28800000");
214 BytesInSitesUsersReport=0;
215 UserAuthentication=0;
216 strcpy(LDAPHost,"127.0.0.1");
217 LDAPPort=389;
218 LDAPProtocolVersion=3;
219 LDAPBindDN[0]='\0';
220 LDAPBindPW[0]='\0';
221 LDAPBaseSearch[0]='\0';
222 strcpy(LDAPFilterSearch, "(uid=%s)");
223 strcpy(LDAPTargetAttr, "cn");
224 LDAPNativeCharset[0]='\0';
225 SortTableJs[0]='\0';
226
227 tmp[0]='\0';
228 us[0]='\0';
229 ReadFilter.DateRange[0]='\0';
230 df='\0';
231 uagent[0]='\0';
232 hexclude[0]='\0';
233 addr[0]='\0';
234 ReadFilter.StartTime=-1;
235 ReadFilter.EndTime=-1;
236 site[0]='\0';
237 outdir[0]='\0';
238 splitprefix[0]='\0';
239 email[0]='\0';
240 UserInvalidChar[0]='\0';
241 DataFile[0]='\0';
242 SquidGuardConf[0]='\0';
243 DansGuardianConf[0]='\0';
244 hm_str[0]='\0';
245 HostAliasFile[0]='\0';
246 UserAliasFile[0]='\0';
247
248 dansguardian_count=0;
249 redirector_count=0;
250 useragent_count=0;
251 DeniedReportLimit=10;
252 AuthfailReportLimit=10;
253 DansGuardianReportLimit=10;
254 SquidGuardReportLimit=10;
255 DownloadReportLimit=50;
256 UserReportLimit=0;
257 debug=0;
258 debugz=0;
259 iprel=false;
260 userip=false;
261 realt=false;
262 realtime_refresh=3;
263 realtime_access_log_lines=1000;
264 cost=0.01;
265 nocost=50000000;
266 squid24=false;
267 dfrom=0;
268 duntil=0;
269 KeepTempLog=false;
270 NumLogSuccessiveErrors=3;
271 NumLogTotalErrors=50;
272 lines_read=0UL;
273 records_kept=0UL;
274 nusers=0UL;
275
276 memset(IncludeUsers,0,sizeof(IncludeUsers));
277 memset(ExcludeString,0,sizeof(ExcludeString));
278 memset(&period,0,sizeof(period));
279
280 AccessLogFromCmdLine=0;
281 RedirectorLogFromCmdLine=0;
282
283 strcpy(Title,_("Squid User Access Report"));
284
285 while((ch = getopt_long(argc, argv, "a:b:c:d:e:f:g:hikl:L:no:P:prs:t:u:Vw:xyz",long_options,&option_index)) != -1){
286 switch(ch)
287 {
288 case 0:
289 break;
290 case 2:
291 lastlog=atoi(optarg);
292 break;
293 case 3:
294 lastlog=0;
295 break;
296 case 'a':
297 safe_strcpy(addr,optarg,sizeof(addr));
298 break;
299 case 'b': //unused option
300 safe_strcpy(uagent,optarg,sizeof(uagent));
301 break;
302 case 'c':
303 safe_strcpy(hexclude,optarg,sizeof(hexclude));
304 break;
305 case 'd':
306 safe_strcpy(ReadFilter.DateRange,optarg,sizeof(ReadFilter.DateRange));
307 date_from(ReadFilter.DateRange,sizeof(ReadFilter.DateRange), &dfrom, &duntil);
308 break;
309 case 'e':
310 safe_strcpy(email,optarg,sizeof(email));
311 break;
312 case 'f':
313 safe_strcpy(ConfigFile,optarg,sizeof(ConfigFile));
314 break;
315 case 'g':
316 df=*optarg;
317 break;
318 case 'h':
319 usage(argv[0]);
320 exit(EXIT_SUCCESS);
321 case 'i':
322 iprel=true;
323 break;
324 case 'k':
325 KeepTempLog=true;
326 break;
327 case 'l':
328 if (!AccessLog)
329 AccessLog=FileList_Create();
330 if (!FileList_AddFile(AccessLog,optarg)) {
331 debuga(__FILE__,__LINE__,_("Not enough memory to store the input log file names\n"));
332 exit(EXIT_FAILURE);
333 }
334 AccessLogFromCmdLine++;
335 break;
336 case 'L':
337 if (NRedirectorLogs>MAX_REDIRECTOR_LOGS) {
338 debuga(__FILE__,__LINE__,_("Too many redirector logs passed on command line with option -L.\n"));
339 exit(EXIT_FAILURE);
340 }
341 if (strlen(optarg)>=MAX_REDIRECTOR_FILELEN) {
342 debuga(__FILE__,__LINE__,_("Redirector log file name too long passed on command line with opton -L: %s\n"),optarg);
343 exit(EXIT_FAILURE);
344 }
345 strcpy(RedirectorLogs[NRedirectorLogs],optarg);
346 NRedirectorLogs++;
347 RedirectorLogFromCmdLine++;
348 break;
349 case 'n':
350 dns=true;
351 break;
352 case 'o':
353 safe_strcpy(outdir,optarg,sizeof(outdir));
354 break;
355 case 'p':
356 userip=true;
357 break;
358 case 'P':
359 safe_strcpy(splitprefix,optarg,sizeof(splitprefix));
360 break;
361 case 'r':
362 realt=true;
363 break;
364 case 's':
365 safe_strcpy(site,optarg,sizeof(site));
366 break;
367 case 't':
368 {
369 int h1,m1,h2,m2;
370
371 if(strstr(optarg,"-") == 0) {
372 if(sscanf(optarg,"%d:%d",&h1,&m1)!=2) {
373 debuga(__FILE__,__LINE__,_("Time period passed on the command line with option -t must be HH:MM\n"));
374 exit(EXIT_FAILURE);
375 }
376 ReadFilter.StartTime=h1*100+m1;
377 ReadFilter.EndTime=ReadFilter.StartTime;
378 snprintf(hm_str,sizeof(hm_str),"%02d:%02d",h1,m1);
379 } else {
380 if(sscanf(optarg,"%d:%d-%d:%d",&h1,&m1,&h2,&m2)!=4) {
381 debuga(__FILE__,__LINE__,_("Time range passed on the command line with option -t must be HH:MM-HH:MM\n"));
382 exit(EXIT_FAILURE);
383 }
384 ReadFilter.StartTime=h1*100+m1;
385 ReadFilter.EndTime=h2*100+m2;
386 snprintf(hm_str,sizeof(hm_str),"%02d:%02d-%02d:%02d",h1,m1,h2,m2);
387 }
388 break;
389 }
390 case 'u':
391 safe_strcpy(us,optarg,sizeof(us));
392 break;
393 case 'V':
394 version();
395 break;
396 case 'w':
397 safe_strcpy(tmp,optarg,sizeof(tmp));
398 break;
399 case 'x':
400 debug++;
401 break;
402 case 'y': //unused option
403 langcode++;
404 break;
405 case 'z':
406 debugz++;
407 break;
408 case ':':
409 debuga(__FILE__,__LINE__,_("Option -%c requires an argument\n"),optopt);
410 exit(EXIT_FAILURE);
411 case '?':
412 usage(argv[0]);
413 exit(EXIT_FAILURE);
414 default:
415 abort();
416 }
417 }
418
419 if (errflg>0) {
420 usage(argv[0]);
421 exit(2);
422 }
423
424 if(output_css) {
425 css_content(stdout);
426 exit(EXIT_SUCCESS);
427 }
428
429 if (optind<argc) {
430 if (!AccessLog)
431 AccessLog=FileList_Create();
432 for (iarq=optind ; iarq<argc ; iarq++) {
433 if (!FileList_AddFile(AccessLog,argv[iarq])) {
434 debuga(__FILE__,__LINE__,_("Not enough memory to store the input log file names\n"));
435 exit(EXIT_FAILURE);
436 }
437 AccessLogFromCmdLine++;
438 }
439 }
440
441 if(debug) debuga(__FILE__,__LINE__,_("Init\n"));
442
443 if(ConfigFile[0] == '\0') snprintf(ConfigFile,sizeof(ConfigFile),"%s/sarg.conf",SYSCONFDIR);
444 if(access(ConfigFile, R_OK) != 0) {
445 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),ConfigFile,strerror(errno));
446 exit(EXIT_FAILURE);
447 }
448
449 if(access(ConfigFile, R_OK) == 0)
450 getconf();
451
452 if(userip) UserIp=true;
453
454 if(dns) ip2name_forcedns();
455
456 if (lastlog>=0) LastLog=lastlog;
457
458 if(outdir[0] == '\0') strcpy(outdir,OutputDir);
459 if(outdir[0] != '\0') strcat(outdir,"/");
460
461 if(IndexTree == INDEX_TREE_FILE)
462 strcpy(ImageFile,"../images");
463 else
464 strcpy(ImageFile,"../../../images");
465
466 dataonly=(DataFile[0] != '\0');
467
468 if (df=='\0') df=DateFormat;
469 if (df=='\0') df='u';
470 if (df=='w')
471 IndexTree=INDEX_TREE_FILE;
472
473 if(AccessLog==NULL) {
474 AccessLog=FileList_Create();
475 if (!FileList_AddFile(AccessLog,"/var/log/squid/access.log")) {
476 debuga(__FILE__,__LINE__,_("Not enough memory to store the input log file names\n"));
477 exit(EXIT_FAILURE);
478 }
479 }
480
481 if(realt) {
482 realtime();
483 exit(EXIT_SUCCESS);
484 }
485 if(split) {
486 const char *file;
487
488 FIter=FileListIter_Open(AccessLog);
489 while ((file=FileListIter_Next(FIter))!=NULL)
490 splitlog(file, df, dfrom, duntil, convert, splitprefix);
491 FileListIter_Close(FIter);
492 exit(EXIT_SUCCESS);
493 }
494 if(convert) {
495 const char *file;
496
497 FIter=FileListIter_Open(AccessLog);
498 while ((file=FileListIter_Next(FIter))!=NULL)
499 convlog(file, df, dfrom, duntil);
500 FileListIter_Close(FIter);
501 exit(EXIT_SUCCESS);
502 }
503
504 load_excludecodes(ExcludeCodes);
505
506 if(access(PasswdFile, R_OK) == 0) {
507 getusers(PasswdFile,debug);
508 ReadFilter.SysUsers=true;
509 } else {
510 ReadFilter.SysUsers=false;
511 }
512
513 if(hexclude[0] == '\0')
514 strcpy(hexclude,ExcludeHosts);
515 if(hexclude[0] != '\0') {
516 gethexclude(hexclude,debug);
517 ReadFilter.HostFilter=true;
518 } else {
519 ReadFilter.HostFilter=false;
520 }
521
522 if(ReportType == 0) {
523 ReportType=REPORT_TYPE_TOPUSERS | REPORT_TYPE_TOPSITES | REPORT_TYPE_USERS_SITES |
524 REPORT_TYPE_SITES_USERS | REPORT_TYPE_DATE_TIME | REPORT_TYPE_DENIED |
525 REPORT_TYPE_AUTH_FAILURES | REPORT_TYPE_SITE_USER_TIME_DATE | REPORT_TYPE_DOWNLOADS;
526 }
527
528 if(access(ExcludeUsers, R_OK) == 0) {
529 getuexclude(ExcludeUsers,debug);
530 ReadFilter.UserFilter=true;
531 } else {
532 ReadFilter.UserFilter=false;
533 }
534 if (HostAliasFile[0] != '\0')
535 read_hostalias(HostAliasFile);
536 if (UserAliasFile[0] != '\0')
537 read_useralias(UserAliasFile);
538
539 indexonly=false;
540 if(ReadFilter.UserFilter) {
541 if(is_indexonly())
542 indexonly=true;
543 }
544 if(strcmp(ExcludeUsers,"indexonly") == 0) indexonly=true;
545 if(Index == INDEX_ONLY) indexonly=true;
546
547 if(MaxElapsed[0] != '\0')
548 ReadFilter.max_elapsed=atol(MaxElapsed);
549 else
550 ReadFilter.max_elapsed=0;
551
552 if(uagent[0] != '\0') strcpy(UserAgentLog,uagent);
553
554 if(tmp[0] == '\0') strcpy(tmp,TempDir);
555 else strcpy(TempDir,tmp);
556 /*
557 For historical reasons, the temporary directory is the subdirectory "sarg" of the path
558 provided by the user.
559 */
560 strcat(tmp,"/sarg");
561
562 if (tmp[0]!='\0' && strncmp(outdir,tmp,strlen(tmp))==0) {
563 debuga(__FILE__,__LINE__,_("The output directory \"%s\" must be outside of the temporary directory \"%s\"\n"),outdir,tmp);
564 exit(EXIT_FAILURE);
565 }
566
567 if(email[0] == '\0' && OutputEmail[0] != '\0') strcpy(email,OutputEmail);
568
569 if(email[0] != '\0') {
570 my_mkdir(tmp);
571 strcpy(outdir,tmp);
572 strcat(outdir,"/");
573 }
574
575 if(access(tmp, R_OK) == 0) {
576 if (debug) debuga(__FILE__,__LINE__,_("Deleting temporary directory \"%s\"\n"),tmp);
577 emptytmpdir(tmp);
578 }
579 my_mkdir(tmp);
580
581 if(debug) {
582 const char *file;
583
584 debuga(__FILE__,__LINE__,_("Parameters:\n"));
585 debuga(__FILE__,__LINE__,_(" Hostname or IP address (-a) = %s\n"),addr);
586 debuga(__FILE__,__LINE__,_(" Useragent log (-b) = %s\n"),uagent);
587 debuga(__FILE__,__LINE__,_(" Exclude file (-c) = %s\n"),hexclude);
588 debuga(__FILE__,__LINE__,_(" Date from-until (-d) = %s\n"),ReadFilter.DateRange);
589 debuga(__FILE__,__LINE__,_(" Email address to send reports (-e) = %s\n"),email);
590 debuga(__FILE__,__LINE__,_(" Config file (-f) = %s\n"),ConfigFile);
591 if (df=='e')
592 debuga(__FILE__,__LINE__,_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
593 else if (df=='u')
594 debuga(__FILE__,__LINE__,_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
595 else if (df=='w')
596 debuga(__FILE__,__LINE__,_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
597 debuga(__FILE__,__LINE__,_(" IP report (-i) = %s\n"),(iprel) ? _("Yes") : _("No"));
598 debuga(__FILE__,__LINE__,_(" Keep temporary files (-k) = %s\n"),(KeepTempLog) ? _("Yes") : _("No"));
599 FIter=FileListIter_Open(AccessLog);
600 while ((file=FileListIter_NextWithMask(FIter))!=NULL)
601 debuga(__FILE__,__LINE__,_(" Input log (-l) = %s\n"),file);
602 FileListIter_Close(FIter);
603 for (iarq=0 ; iarq<NRedirectorLogs ; iarq++)
604 debuga(__FILE__,__LINE__,_(" Redirector log (-L) = %s\n"),RedirectorLogs[iarq]);
605 debuga(__FILE__,__LINE__,_(" Resolve IP Address (-n) = %s\n"),(Ip2Name) ? _("Yes") : _("No"));
606 debuga(__FILE__,__LINE__,_(" Output dir (-o) = %s\n"),outdir);
607 debuga(__FILE__,__LINE__,_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp) ? _("Yes") : _("No"));
608 debuga(__FILE__,__LINE__,_(" Accessed site (-s) = %s\n"),site);
609 debuga(__FILE__,__LINE__,_(" Time (-t) = %s\n"),hm_str);
610 debuga(__FILE__,__LINE__,_(" User (-u) = %s\n"),us);
611 debuga(__FILE__,__LINE__,_(" Temporary dir (-w) = %s\n"),tmp);
612 debuga(__FILE__,__LINE__,_(" Debug messages (-x) = %s\n"),(debug) ? _("Yes") : _("No"));
613 debuga(__FILE__,__LINE__,_(" Process messages (-z) = %d\n"),debugz);
614 debuga(__FILE__,__LINE__,_(" Previous reports to keep (--lastlog) = %d\n"),LastLog);
615 debuga(__FILE__,__LINE__,"\n");
616 }
617
618 if(debug)
619 debuga(__FILE__,__LINE__,_("sarg version: %s\n"),VERSION);
620
621 #ifdef ENABLE_DOUBLE_CHECK_DATA
622 debuga(__FILE__,__LINE__,_("Sarg compiled to report warnings if the output is inconsistent\n"));
623 #endif
624
625 #ifdef HAVE_RLIM_T
626 if (Ulimit[0] != '\0') {
627 struct rlimit rl;
628 long l1, l2;
629 int rc=0;
630
631 #if defined(RLIMIT_NOFILE)
632 getrlimit (RLIMIT_NOFILE, &rl);
633 #elif defined(RLIMIT_OFILE)
634 getrlimit (RLIMIT_OFILE, &rl);
635 #else
636 #warning "No rlimit resource for the number of open files"
637 #endif
638 l1 = rl.rlim_cur;
639 l2 = rl.rlim_max;
640
641 rl.rlim_cur = atol(Ulimit);
642 rl.rlim_max = atol(Ulimit);
643 #if defined(RLIMIT_NOFILE)
644 rc=setrlimit (RLIMIT_NOFILE, &rl);
645 #elif defined(RLIMIT_OFILE)
646 rc=setrlimit (RLIMIT_OFILE, &rl);
647 #else
648 #warning "No rlimit resource for the number of open files"
649 #endif
650 if(rc == -1) {
651 debuga(_("setrlimit error: %s\n"),strerror(errno));
652 }
653
654 if(debug)
655 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING" max="RLIM_STRING"\n",l1,l2,rl.rlim_cur,rl.rlim_max);
656 }
657 #endif
658
659 init_usertab(UserTabFile);
660
661 read_start_time=time(NULL);
662 LogStatus=ReadLogFile(&ReadFilter);
663 read_end_time=time(NULL);
664 read_elapsed=(double)read_end_time-(double)read_start_time;
665
666 FileList_Destroy(&AccessLog);
667 free_download();
668 free_excludecodes();
669 free_exclude();
670
671 if (debug) {
672 char date0[30], date1[30];
673 struct tm Start,End;
674
675 GetLogPeriod(&Start,&End);
676 strftime(date0,sizeof(date0),"%x",&Start);
677 strftime(date1,sizeof(date1),"%x",&End);
678 // TRANSLATORS: The %s are the start and end dates in locale format.
679 debuga(__FILE__,__LINE__,_("Period covered by log files: %s-%s\n"),date0,date1);
680 }
681
682 if (!LogStatus){
683 debuga(__FILE__,__LINE__,_("No records found\n"));
684 debuga(__FILE__,__LINE__,_("End\n"));
685 userinfo_free();
686 if(userfile) free(userfile);
687 close_usertab();
688 exit(EXIT_SUCCESS);
689 }
690
691 if (debug) {
692 char date0[30], date1[30];
693
694 strftime(date0,sizeof(date0),"%x",&period.start);
695 strftime(date1,sizeof(date1),"%x",&period.end);
696 // TRANSLATORS: The %s are the start and end dates in locale format.
697 debuga(__FILE__,__LINE__,_("Period extracted from log files: %s-%s\n"),date0,date1);
698 }
699 if (ReadFilter.DateRange[0] != '\0') {
700 getperiod_fromrange(&period,dfrom,duntil);
701 }
702 if (getperiod_buildtext(&period)<0) {
703 debuga(__FILE__,__LINE__,_("Failed to build the string representation of the date range\n"));
704 exit(EXIT_FAILURE);
705 }
706
707 process_start_time=time(NULL);
708 if(DataFile[0] != '\0')
709 data_file(tmp);
710 else
711 gerarel();
712 process_end_time=time(NULL);
713 process_elapsed=(double)process_end_time-(double)process_start_time;
714
715 denied_cleanup();
716 authfail_cleanup();
717 download_cleanup();
718
719 if(!KeepTempLog && strcmp(tmp,"/tmp") != 0) {
720 unlinkdir(tmp,0);
721 }
722
723 ip2name_cleanup();
724 free_hostalias();
725 free_useralias();
726 userinfo_free();
727 if(userfile)
728 free(userfile);
729 close_usertab();
730
731 end_time=time(NULL);
732
733 if (show_statis) {
734 double elapsed=(double)end_time-(double)start_time;
735 debuga(__FILE__,__LINE__,_("Total execution time: %.0lf seconds\n"),elapsed);
736 if (read_elapsed>0.) {
737 debuga(__FILE__,__LINE__,_("Lines read: %lu lines in %.0lf seconds (%.0lf lines/s)\n"),lines_read,read_elapsed,(double)lines_read/read_elapsed);
738 }
739 if (process_elapsed>0.) {
740 debuga(__FILE__,__LINE__,_("Processed records: %lu records in %.0lf seconds (%.0lf records/s)\n"),records_kept,process_elapsed,(double)records_kept/process_elapsed);
741 debuga(__FILE__,__LINE__,_("Users: %lu users in %.0lf seconds (%.0lf users/s)\n"),nusers,process_elapsed,(double)nusers/process_elapsed);
742 }
743 }
744
745 if(debug)
746 debuga(__FILE__,__LINE__,_("End\n"));
747
748 exit(EXIT_SUCCESS);
749 }
750
751
752 static void getusers(const char *pwdfile, int debug)
753 {
754 FILE *fp_usr;
755 char buf[255];
756 char *str;
757 long int nreg=0;
758
759 if(debug)
760 debuga(__FILE__,__LINE__,_("Loading password file \"%s\"\n"),pwdfile);
761
762 if ((fp_usr = fopen(pwdfile, "r")) == NULL) {
763 debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),pwdfile,strerror(errno));
764 exit(EXIT_FAILURE);
765 }
766
767 if (fseek(fp_usr, 0, SEEK_END)==-1) {
768 debuga(__FILE__,__LINE__,_("Failed to move till the end of file \"%s\": %s\n"),pwdfile,strerror(errno));
769 exit(EXIT_FAILURE);
770 }
771 nreg = ftell(fp_usr);
772 if (nreg<0) {
773 debuga(__FILE__,__LINE__,_("Cannot get the size of file \"%s\"\n"),pwdfile);
774 exit(EXIT_FAILURE);
775 }
776 nreg = nreg+5000;
777 if (fseek(fp_usr, 0, SEEK_SET)==-1) {
778 debuga(__FILE__,__LINE__,_("Failed to rewind file \"%s\": %s\n"),pwdfile,strerror(errno));
779 exit(EXIT_FAILURE);
780 }
781
782 if((userfile=(char *) malloc(nreg))==NULL){
783 debuga(__FILE__,__LINE__,_("malloc error (%ld bytes required)\n"),nreg);
784 exit(EXIT_FAILURE);
785 }
786
787 memset(userfile,0,nreg);
788 strcpy(userfile,":");
789
790 while(fgets(buf,sizeof(buf),fp_usr)!=NULL) {
791 str=strchr(buf,':');
792 if (!str) {
793 debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),pwdfile);
794 exit(EXIT_FAILURE);
795 }
796 str[1]='\0';
797 strcat(userfile,buf);
798 }
799
800 if (fclose(fp_usr)==EOF) {
801 debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),pwdfile,strerror(errno));
802 exit(EXIT_FAILURE);
803 }
804
805 return;
806 }