2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 #define REPORT_EVERY_X_LINES 5000
31 #define MAX_OPEN_USER_FILES 10
35 struct userfilestruct
*next
;
36 struct userinfostruct
*user
;
40 /*@null@*/static char *userfile
=NULL
;
42 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
43 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
44 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
46 static void getusers(const char *pwdfile
, int debug
);
48 int main(int argc
,char *argv
[])
59 ISACOL_Last
//last entry of the list !
67 ILF_Last
//last entry of the list !
70 FILE *fp_in
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
72 char sz_Download_Unsort
[ 20000 ] ;
73 FILE * fp_Download_Unsort
= NULL
;
85 char smartfilter
[MAXLEN
];
95 char hm
[15], hmf
[15], hmr
[15];
98 char hexclude
[MAXLEN
];
106 char denied_unsort
[MAXLEN
];
107 char denied_sort
[MAXLEN
];
108 char authfail_unsort
[MAXLEN
];
109 char start_hour
[128];
115 char user
[MAX_USER_LEN
];
116 enum InputLogFormat ilf
;
117 int ilf_count
[ILF_Last
];
129 int isa_ncols
=0,isa_cols
[ISACOL_Last
];
139 long int max_elapsed
=0;
140 long long int iyear
, imonth
, iday
;
145 unsigned long recs1
=0UL;
146 unsigned long recs2
=0UL;
147 int OutputNonZero
= REPORT_EVERY_X_LINES
;
148 bool download_flag
=false;
149 char *download_url
=NULL
;
150 struct getwordstruct gwarea
;
153 struct userinfostruct
*uinfo
;
154 struct userfilestruct
*first_user_file
, *ufile
, *ufile1
, *prev_ufile
;
157 setlocale(LC_TIME
,"");
160 #if defined(ENABLE_NLS) && defined(HAVE_LOCALE_H)
161 if (!setlocale (LC_ALL
, "")) {
162 fprintf(stderr
,"SARG: Cannot set the locale LC_ALL to the environment variable\n");
165 if (!bindtextdomain (PACKAGE_NAME
, LOCALEDIR
)) {
166 fprintf(stderr
,"SARG: Cannot bind to text domain %s in directory %s (%s)\n",PACKAGE_NAME
,LOCALEDIR
,strerror(errno
));
169 if (!textdomain (PACKAGE_NAME
)) {
170 fprintf(stderr
,"SARG: Cannot set gettext domain for %s PACKAGE_NAME (%s)\n",PACKAGE_NAME
,strerror(errno
));
180 UserAgentLog
[0]='\0';
181 ExcludeHosts
[0]='\0';
182 ExcludeUsers
[0]='\0';
189 ExternalCSSFile
[0]='\0';
190 SquidGuardLogFormat
[0]='\0';
191 SquidGuardLogAlternate
[0]='\0';
192 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
194 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
195 strcpy(GraphDaysBytesBarColor
,"orange");
196 strcpy(BgColor
,"#ffffff");
197 strcpy(TxColor
,"#000000");
198 strcpy(TxBgColor
,"lavender");
199 strcpy(TiColor
,"darkblue");
202 strcpy(LogoTextColor
,"#000000");
203 strcpy(HeaderColor
,"darkblue");
204 strcpy(HeaderBgColor
,"#dddddd");
205 strcpy(LogoTextColor
,"#006699");
206 strcpy(FontSize
,"9px");
207 strcpy(TempDir
,"/tmp");
208 strcpy(OutputDir
,"/var/www/html/squid-reports");
210 strcpy(DateFormat
,"u");
211 OverwriteReport
=false;
212 RemoveTempFiles
=true;
213 strcpy(ReplaceIndex
,"index.html");
215 RecordsWithoutUser
=RECORDWITHOUTUSER_IP
;
217 strcpy(MailUtility
,"mailx");
221 strcpy(TopuserSortField
,"BYTES");
222 strcpy(UserSortField
,"BYTES");
223 strcpy(TopuserSortOrder
,"reverse");
224 strcpy(UserSortOrder
,"reverse");
225 strcpy(TopsitesSortField
,"CONNECT");
226 strcpy(TopsitesSortType
,"D");
228 strcpy(FontFace
,"Verdana,Tahoma,Arial");
229 strcpy(datetimeby
,"elap");
230 strcpy(CharSet
,"ISO-8859-1");
232 strcpy(PrivacyString
,"***.***.***.***");
233 strcpy(PrivacyStringColor
,"blue");
235 TopUserFields
=TOPUSERFIELDS_NUM
| TOPUSERFIELDS_DATE_TIME
| TOPUSERFIELDS_USERID
| TOPUSERFIELDS_CONNECT
|
236 TOPUSERFIELDS_BYTES
| TOPUSERFIELDS_SETYB
| TOPUSERFIELDS_IN_CACHE_OUT
|
237 TOPUSERFIELDS_USED_TIME
| TOPUSERFIELDS_MILISEC
| TOPUSERFIELDS_PTIME
|
238 TOPUSERFIELDS_TOTAL
| TOPUSERFIELDS_AVERAGE
;
239 UserReportFields
=USERREPORTFIELDS_CONNECT
| USERREPORTFIELDS_BYTES
| USERREPORTFIELDS_SETYB
|
240 USERREPORTFIELDS_IN_CACHE_OUT
| USERREPORTFIELDS_USED_TIME
| USERREPORTFIELDS_MILISEC
|
241 USERREPORTFIELDS_PTIME
| USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
;
242 strcpy(DataFileDelimiter
,";");
243 DataFileFields
=DATA_FIELD_USER
| DATA_FIELD_DATE
| DATA_FIELD_TIME
| DATA_FIELD_URL
| DATA_FIELD_CONNECT
|
244 DATA_FIELD_BYTES
| DATA_FIELD_IN_CACHE
| DATA_FIELD_OUT_CACHE
| DATA_FIELD_ELAPSED
;
245 ShowReadStatistics
=true;
246 strcpy(IndexSortOrder
,"D");
249 strcpy(ParsedOutputLog
,"no");
250 strcpy(ParsedOutputLogCompress
,"/bin/gzip -f");
251 strcpy(DisplayedValues
,"abbreviation");
252 strcpy(HeaderFontSize
,"9px");
253 strcpy(TitleFontSize
,"11px");
254 strcpy(AuthUserTemplateFile
,"sarg_htaccess");
255 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");
258 strcpy(GraphFont
,FONTDIR
"/DejaVuSans.ttf");
262 strcpy(Ulimit
,"20000");
263 NtlmUserFormat
=NTLMUSERFORMAT_DOMAINUSER
;
264 IndexTree
=INDEX_TREE_FILE
;
265 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
266 strcpy(RealtimeUnauthRec
,"show");
267 SquidguardIgnoreDate
=0;
268 DansguardianIgnoreDate
=0;
269 DataFileUrl
=DATAFILEURL_IP
;
270 strcpy(MaxElapsed
,"28800000");
271 BytesInSitesUsersReport
=0;
272 UserAuthentication
=0;
273 strcpy(LDAPHost
,"127.0.0.1");
275 LDAPProtocolVersion
=3;
278 LDAPBaseSearch
[0]='\0';
279 strcpy(LDAPFilterSearch
, "uid=%s");
280 strcpy(LDAPTargetAttr
, "cn");
304 UserInvalidChar
[0]='\0';
306 SquidGuardConf
[0]='\0';
307 DansGuardianConf
[0]='\0';
314 dansguardian_count
=0;
317 DeniedReportLimit
=10;
318 AuthfailReportLimit
=10;
319 DansGuardianReportLimit
=10;
320 SquidGuardReportLimit
=10;
321 DownloadReportLimit
=50;
333 realtime_access_log_lines
=1000;
341 bzero(IncludeUsers
, sizeof(IncludeUsers
));
342 bzero(ExcludeString
, sizeof(ExcludeString
));
343 first_user_file
=NULL
;
344 memset(&period
,0,sizeof(period
));
347 for(x
=0; x
<MAXLOGS
; x
++)
348 AccessLog
[x
][0]='\0';
349 AccessLogFromCmdLine
=0;
351 strcpy(Title
,_("Squid User Access Report"));
353 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
360 strcpy(uagent
,optarg
);
363 strcpy(hexclude
,optarg
);
366 strncpy(date
,optarg
,sizeof(date
)-1);
367 date
[sizeof(date
)-1]='\0';
368 date_from(date
, &dfrom
, &duntil
);
371 strcpy(email
,optarg
);
374 strcpy(ConfigFile
,optarg
);
386 if (NAccessLog
>=MAXLOGS
) {
387 printf(_("SARG: Too many log files passed on command line with option -l.\n"));
390 strcpy(AccessLog
[NAccessLog
],optarg
);
392 AccessLogFromCmdLine
++;
395 strcpy(SquidGuardLogAlternate
,optarg
);
404 strcpy(outdir
,optarg
);
419 if(strstr(optarg
,"-") == 0) {
423 getword_start(&gwarea
,optarg
);
424 if (getword(hm
,sizeof(hm
),&gwarea
,'-')<0 || getword(hmf
,sizeof(hmf
),&gwarea
,'\0')<0) {
425 debuga(_("The time range passed on the command line with option -t is invalid\n"));
429 if(sscanf(hm
,"%d:%d",&h
,&m
)!=2) {
430 debuga(_("Time period must be MM or MM:SS. Exit\n"));
433 sprintf(hm
,"%02d%02d",h
,m
);
434 if(sscanf(hmf
,"%d:%d",&h
,&m
)!=2) {
435 debuga(_("Time period must be MM or MM:SS. Exit\n"));
438 sprintf(hmf
,"%02d%02d",h
,m
);
460 debuga(_("Option -%c require an argument\n"),optopt
);
475 if(debug
) debuga(_("Init\n"));
477 if(ConfigFile
[0] == '\0') snprintf(ConfigFile
,sizeof(ConfigFile
),"%s/sarg.conf",SYSCONFDIR
);
478 if(access(ConfigFile
, R_OK
) != 0) {
479 debuga(_("Cannot open config file: %s - %s\n"),ConfigFile
,strerror(errno
));
483 if(access(ConfigFile
, R_OK
) == 0)
486 if(userip
) UserIp
=true;
488 if(dns
) Ip2Name
=true;
495 if(IndexTree
== INDEX_TREE_FILE
)
496 strcpy(ImageFile
,"../images");
498 strcpy(ImageFile
,"../../../images");
501 if(DataFile
[0] != '\0')
504 if(NAccessLog
== 0) {
505 strcpy(AccessLog
[0],"/var/log/squid/access.log");
509 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
510 convlog(AccessLog
[0], df
, dfrom
, duntil
);
514 if(strcmp(site
,"plit") == 0) {
515 splitlog(AccessLog
[0], df
, dfrom
, duntil
, hexclude
);
519 load_excludecodes(ExcludeCodes
);
521 if(access(PasswdFile
, R_OK
) == 0) {
522 getusers(PasswdFile
,debug
);
526 if(hexclude
[0] == '\0')
527 strcpy(hexclude
,ExcludeHosts
);
528 if(hexclude
[0] != '\0') {
529 gethexclude(hexclude
,debug
);
533 if(ReportType
== 0) {
534 ReportType
=REPORT_TYPE_TOPUSERS
| REPORT_TYPE_TOPSITES
| REPORT_TYPE_USERS_SITES
|
535 REPORT_TYPE_SITES_USERS
| REPORT_TYPE_DATE_TIME
| REPORT_TYPE_DENIED
|
536 REPORT_TYPE_AUTH_FAILURES
| REPORT_TYPE_SITE_USER_TIME_DATE
| REPORT_TYPE_DOWNLOADS
;
539 if(access(ExcludeUsers
, R_OK
) == 0) {
540 getuexclude(ExcludeUsers
,debug
);
549 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
550 if(Index
== INDEX_ONLY
) indexonly
++;
552 if(MaxElapsed
[0] != '\0') max_elapsed
=atol(MaxElapsed
);
554 if(outdir
[0] == '\0') strcpy(outdir
,OutputDir
);
557 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
559 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
560 else strcpy(TempDir
,tmp
);
562 if(df
[0] == '\0') strcpy(df
,DateFormat
);
563 else strcpy(DateFormat
,df
);
567 strcpy(DateFormat
,"u");
570 IndexTree
=INDEX_TREE_FILE
;
572 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
576 if(email
[0] != '\0') {
577 snprintf(wtemp2
,sizeof(wtemp2
),"%s/sarg",tmp2
);
579 strcat(tmp2
,"/sarg");
584 strcat(tmp2
,"/sarg.log");
586 sprintf(tmp3
,"%s/sarg",tmp
);
587 if(access(tmp3
, R_OK
) == 0) {
591 strcpy(denied_unsort
,tmp3
);
592 strcpy(denied_sort
,tmp3
);
593 strcpy(authfail_unsort
,tmp3
);
594 strcat(denied_unsort
,"/denied.log.unsort");
595 strcat(denied_sort
,"/denied.log");
596 strcat(authfail_unsort
,"/authfail.log.unsort");
599 debuga(_("Parameters:\n"));
600 debuga(_(" Hostname or IP address (-a) = %s\n"),addr
);
601 debuga(_(" Useragent log (-b) = %s\n"),uagent
);
602 debuga(_(" Exclude file (-c) = %s\n"),hexclude
);
603 debuga(_(" Date from-until (-d) = %s\n"),date
);
604 debuga(_(" Email address to send reports (-e) = %s\n"),email
);
605 debuga(_(" Config file (-f) = %s\n"),ConfigFile
);
606 if(strcmp(df
,"e") == 0)
607 debuga(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
608 if(strcmp(df
,"u") == 0)
609 debuga(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
610 if(strcmp(df
,"w") == 0)
611 debuga(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
612 debuga(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
613 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
614 debuga(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
615 debuga(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
616 debuga(_(" Output dir (-o) = %s\n"),outdir
);
617 debuga(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
618 debuga(_(" Accessed site (-s) = %s\n"),site
);
619 debuga(_(" Time (-t) = %s\n"),hm
);
620 debuga(_(" User (-u) = %s\n"),us
);
621 debuga(_(" Temporary dir (-w) = %s\n"),tmp
);
622 debuga(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
623 debuga(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
628 printf(_("Parameters:\n"));
629 printf(_(" Hostname or IP address (-a) = %s\n"),addr
);
630 printf(_(" Useragent log (-b) = %s\n"),uagent
);
631 printf(_(" Exclude file (-c) = %s\n"),hexclude
);
632 printf(_(" Date from-until (-d) = %s\n"),date
);
633 printf(_(" Email address to send reports (-e) = %s\n"),email
);
634 printf(_(" Config file (-f) = %s\n"),ConfigFile
);
635 if(strcmp(df
,"e") == 0)
636 printf(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
637 if(strcmp(df
,"u") == 0)
638 printf(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
639 if(strcmp(df
,"w") == 0)
640 printf(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
641 printf(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
642 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
643 printf(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
644 printf(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
645 printf(_(" Output dir (-o) = %s\n"),outdir
);
646 printf(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
647 printf(_(" Accessed site (-s) = %s\n"),site
);
648 printf(_(" Time (-t) = %s\n"),hm
);
649 printf(_(" User (-u) = %s\n"),us
);
650 printf(_(" Temporary dir (-w) = %s\n"),tmp
);
651 printf(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
652 printf(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
653 printf(_("sarg version: %s\n"),VERSION
);
657 debuga(_("sarg version: %s\n"),VERSION
);
659 maxopenfiles
=MAX_OPEN_USER_FILES
;
661 if (Ulimit
[0] != '\0') {
666 #if defined(RLIMIT_NOFILE)
667 getrlimit (RLIMIT_NOFILE
, &rl
);
668 #elif defined(RLIMIT_OFILE)
669 getrlimit (RLIMIT_OFILE
, &rl
);
671 #warning "No rlimit resource for the number of open files"
676 rl
.rlim_cur
= atol(Ulimit
);
677 rl
.rlim_max
= atol(Ulimit
);
678 #if defined(RLIMIT_NOFILE)
679 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
680 #elif defined(RLIMIT_OFILE)
681 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
683 #warning "No rlimit resource for the number of open files"
686 debuga(_("setrlimit error - %s\n"),strerror(errno
));
690 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
694 init_usertab(UserTabFile
);
696 if ((line
=longline_create())==NULL
) {
697 debuga(_("Not enough memory to read a log file\n"));
701 snprintf(sz_Download_Unsort
,sizeof(sz_Download_Unsort
),"%s/sarg/download.unsort", tmp
);
703 if(DataFile
[0]=='\0') {
704 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
705 if((fp_denied
=MY_FOPEN(denied_unsort
,"w"))==NULL
) {
706 debuga(_("(log) Cannot open file: %s - %s\n"),denied_unsort
,strerror(errno
));
711 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
712 if((fp_authfail
=MY_FOPEN(authfail_unsort
,"w"))==NULL
) {
713 debuga(_("(log) Cannot open file: %s - %s\n"),authfail_unsort
,strerror(errno
));
719 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
720 strcpy(arq
,AccessLog
[iarq
]);
724 if(strcmp(arq
,"-")==0) {
726 debuga(_("Reading access log file: from stdin\n"));
732 debuga(_("Reading access log file: %s\n"),arq
);
733 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
734 debuga(_("(log) Cannot open log file: %s - %s\n"),arq
,strerror(errno
));
741 // pre-read the file only if we have to show stats
742 if(ShowReadStatistics
&& !from_stdin
) {
750 while ((nread
=fread(tmp4
,1,sizeof(tmp4
),fp_in
))>0) {
751 for (i
=0 ; i
<nread
; i
++)
753 if (tmp4
[i
]!='\n' && tmp4
[i
]!='\r') {
757 if (tmp4
[i
]=='\n' || tmp4
[i
]=='\r') {
764 printf(_("SARG: Records in file: %lu, reading: %3.2f%%"),recs1
,(float) 0);
769 longline_reset(line
);
771 while ((linebuf
=longline_read(fp_in
,line
))!=NULL
) {
772 blen
=strlen(linebuf
);
774 if (ilf
==ILF_Unknown
) {
775 if(strncmp(linebuf
,"#Software: Mic",14) == 0) {
776 fixendofline(linebuf
);
778 debuga(_("Log is from Microsoft ISA: %s\n"),linebuf
);
784 if(strncmp(linebuf
,"*** SARG Log ***",16) == 0) {
785 if (getperiod_fromsarglog(arqtt
,&period
)<0) {
786 debuga(_("The name of the file is invalid: %s\n"),arq
);
795 if(!fp_log
&& strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
796 if(access(ParsedOutputLog
,R_OK
) != 0) {
797 my_mkdir(ParsedOutputLog
);
799 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
800 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
801 debuga(_("(log) Cannot open log file: %s - %s\n"),arq_log
,strerror(errno
));
804 fputs("*** SARG Log ***\n",fp_log
);
808 if( ShowReadStatistics
&& !from_stdin
&& --OutputNonZero
<=0) {
809 double perc
= recs2
* 100. / recs1
;
810 printf(_("SARG: Records in file: %lu, reading: %3.2lf%%"),recs1
,perc
);
813 OutputNonZero
= REPORT_EVERY_X_LINES
;
815 if(blen
< 58) continue;
816 if(strstr(linebuf
,"HTTP/0.0") != 0) continue;
817 if(strstr(linebuf
,"logfile turned over") != 0) continue;
818 if(linebuf
[0] == ' ') continue;
821 if(ExcludeString
[0] != '\0') {
823 getword_start(&gwarea
,ExcludeString
);
824 while(strchr(gwarea
.current
,':') != 0) {
825 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
826 debuga(_("Maybe you have a broken record or garbage in your exclusion string\n"));
829 if((str
=(char *) strstr(linebuf
,val1
)) != (char *) NULL
) {
834 if(!exstring
&& (str
=(char *) strstr(linebuf
,gwarea
.current
)) != (char *) NULL
)
836 if(exstring
) continue;
841 printf("BUF=%s\n",linebuf
);
844 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
845 getword_start(&gwarea
,linebuf
);
846 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
847 debuga(_("Maybe you have a broken time in your access.log file\n"));
850 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
&& (str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
854 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
855 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
859 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
860 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
864 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
865 getword(fun
,sizeof(fun
),&gwarea
,' ')<0) {
866 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
869 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0) {
870 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
873 if (getword_skip(MAXLEN
,&gwarea
,' ')<0) {
874 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
877 if (getword(code2
,sizeof(code2
),&gwarea
,' ')<0) {
878 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
881 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
882 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
885 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
886 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
887 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
891 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
892 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
897 if ((str
= strchr(code
, ':')) != NULL
)
900 if(strcmp(tam
,"\0") == 0)
906 getword_start(&gwarea
,data
+1);
907 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
908 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
911 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
912 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
915 getword_start(&gwarea
,data
);
916 if (getword_atoll(&iday
,&gwarea
,'/')<0){
917 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
920 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
921 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
924 if (getword_atoll(&iyear
,&gwarea
,'/')<0){
925 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
929 imonth
=month2num(mes
)+1;
930 idata
=builddia(iday
,imonth
,iyear
);
931 computedate(iyear
,imonth
,iday
,&tt
);
935 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
936 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
937 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
940 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
941 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
942 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
945 if(strlen(elap
) < 1) continue;
946 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
947 debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq
);
950 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
951 debuga(_("Maybe you have a broken result code in your %s file\n"),arq
);
954 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
955 debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq
);
958 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
959 debuga(_("Maybe you have a broken request method in your %s file\n"),arq
);
962 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0){
963 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
966 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
967 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
976 debuga(_("Cannot convert the timestamp from the squid log file\n"));
980 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
982 idata
=(t
->tm_year
+1900)*10000+(t
->tm_mon
+1)*100+t
->tm_mday
;
984 if(strncmp(df
,"u",1)==0)
985 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
987 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
988 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
992 getword_start(&gwarea
,linebuf
);
993 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0){
994 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
997 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
998 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1001 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
1002 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1005 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
1006 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1009 if (getword_ptr(linebuf
,&url
,&gwarea
,'\t')<0){
1010 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1013 if (getword(tam
,sizeof(tam
),&gwarea
,'\t')<0){
1014 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1017 if (getword(code
,sizeof(code
),&gwarea
,'\t')<0){
1018 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1021 if (getword(elap
,sizeof(elap
),&gwarea
,'\t')<0){
1022 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1025 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,'\0')<0){
1026 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1029 getword_start(&gwarea
,data
);
1030 if(strcmp(df
,"u") == 0) {
1031 if (getword_atoll(&imonth
,&gwarea
,'/')<0){
1032 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1035 if (getword_atoll(&iday
,&gwarea
,'/')<0){
1036 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1040 if (getword_atoll(&iday
,&gwarea
,'/')<0){
1041 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1044 if (getword_atoll(&imonth
,&gwarea
,'/')<0){
1045 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1049 if (getword_atoll(&iyear
,&gwarea
,'\0')<0){
1050 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1053 idata
=builddia(iday
,imonth
,iyear
);
1054 computedate(iyear
,imonth
,iday
,&tt
);
1058 if (linebuf
[0] == '#') {
1059 int ncols
,cols
[ISACOL_Last
];
1061 fixendofline(linebuf
);
1062 getword_start(&gwarea
,linebuf
);
1063 // remove the #Fields: column at the beginning of the line
1064 if (getword_skip(1000,&gwarea
,' ')<0){
1065 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1068 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
1070 while(gwarea
.current
[0] != '\0') {
1071 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
1072 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1075 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
1076 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
1077 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
1078 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
1079 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
1080 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
1081 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
1082 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
1085 if (cols
[ISACOL_Ip
]>=0) {
1087 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++)
1088 isa_cols
[ncols
]=cols
[ncols
];
1092 if (!isa_ncols
) continue;
1093 getword_start(&gwarea
,linebuf
);
1094 for (x
=0 ; x
<isa_ncols
; x
++) {
1095 if (getword_ptr(linebuf
,&str
,&gwarea
,'\t')<0) {
1096 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1099 if (x
==isa_cols
[ISACOL_Ip
]) {
1100 if (strlen(str
)>=sizeof(ip
)) {
1101 debuga(_("Maybe you have a broken IP in your %s file\n"),arq
);
1105 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1106 if (strlen(str
)>=sizeof(user
)) {
1107 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
1111 } else if (x
==isa_cols
[ISACOL_Date
]) {
1112 if (strlen(str
)>=sizeof(data
)) {
1113 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1117 } else if (x
==isa_cols
[ISACOL_Time
]) {
1118 if (strlen(str
)>=sizeof(hora
)) {
1119 debuga(_("Maybe you have a broken time in your %s file\n"),arq
);
1123 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1124 if (strlen(str
)>=sizeof(elap
)) {
1125 debuga(_("Maybe you have a broken download duration in your %s file\n"),arq
);
1129 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1130 if (strlen(str
)>=sizeof(tam
)) {
1131 debuga(_("Maybe you have a broken download size in your %s file\n"),arq
);
1135 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1137 } else if (x
==isa_cols
[ISACOL_Status
]) {
1138 if (strlen(str
)>=sizeof(code
)) {
1139 debuga(_("Maybe you have a broken access code in your %s file\n"),arq
);
1146 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1147 sprintf(val1
,"DENIED/%s",code
);
1150 getword_start(&gwarea
,data
);
1151 if (getword_atoll(&iyear
,&gwarea
,'-')<0){
1152 debuga(_("Maybe you have a broken year in your %s file\n"),arq
);
1155 if (getword_atoll(&imonth
,&gwarea
,'-')<0){
1156 debuga(_("Maybe you have a broken month in your %s file\n"),arq
);
1159 if (getword_atoll(&iday
,&gwarea
,'\0')<0){
1160 debuga(_("Maybe you have a broken day in your %s file\n"),arq
);
1164 idata
=builddia(iday
,imonth
,iyear
);
1165 computedate(iyear
,imonth
,iday
,&tt
);
1169 debuga(_("Unknown input log file format\n"));
1174 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1176 if(date
[0] != '\0'){
1177 if(idata
< dfrom
|| idata
> duntil
) continue;
1180 // Record only hours usage which is required
1182 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
1183 sizeof( int ), compar
) == NULL
)
1186 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
1187 sizeof( int ), compar
) == NULL
)
1192 if(strlen(user
) > MAX_USER_LEN
) {
1193 if (debugm
) printf(_("User ID too long: %s\n"),user
);
1199 if(IncludeUsers
[0] != '\0') {
1200 sprintf(val1
,":%s:",user
);
1201 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1206 if (debugm
) printf(_("Excluded code: %s\n"),code
);
1211 if(testvaliduserchar(user
))
1215 if((str
= strstr(user
,"%20")) != NULL
) {
1217 This is a patch introduced to solve bug #1624251 reported at sourceforge but
1218 the side effect is to truncate the name at the first space and merge the reports
1219 of people whose name is identical up to the first space.
1221 The old code used to truncate the user name at the first % if a %20 was
1222 found anywhere in the string. That means the string could be truncated
1223 at the wrong place if another % occured before the %20. This new code should
1224 avoid that problem and only truncate at the space. There is no bug
1225 report indicating that anybody noticed this.
1231 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1232 found in the user name.
1234 while((str
= strstr(user
,"%5c")) != NULL
) {
1236 for (x
=3 ; str
[x
] ; x
++) str
[x
-2]=str
[x
];
1244 The full URL is not saved in sarg log. There is no point in testing the URL to detect
1247 download_flag
=is_download_suffix(url
);
1248 if (download_flag
) {
1253 download_flag
=false;
1255 // remove any protocol:// at the beginning of the URL
1256 if ((str
= strchr(url
,'/')) != NULL
&& str
[1] == '/') {
1260 for (i
=0 ; str
[i
] ; i
++)
1266 url_hostname(url
,hostname
,sizeof(hostname
));
1270 if(url
[0] == '\0') continue;
1272 if(addr
[0] != '\0'){
1273 if(strcmp(addr
,ip
)!=0) continue;
1276 if(!vhexclude(url
)) {
1277 if (debugm
) printf(_("Excluded site: %s\n"),url
);
1286 getword_start(&gwarea
,hora
);
1288 if (getword_multisep(warea
,sizeof(warea
),&gwarea
,':')<0){
1289 debuga(_("Maybe you have a broken time in your %s file\n"),arq
);
1292 strncat(hmr
,warea
,2);
1295 strncat(hmr
,gwarea
.current
,2);
1297 if(atoi(hmr
) < atoi(hm
) || atoi(hmr
) > atoi(hmf
)) continue;
1300 if(site
[0] != '\0'){
1301 if(strstr(url
,site
)==0) continue;
1309 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1310 if(RecordsWithoutUser
== RECORDWITHOUTUSER_IP
) {
1314 if(RecordsWithoutUser
== RECORDWITHOUTUSER_IGNORE
)
1316 if(RecordsWithoutUser
== RECORDWITHOUTUSER_EVERYBODY
)
1317 strcpy(user
,"everybody");
1320 if(NtlmUserFormat
== NTLMUSERFORMAT_USER
) {
1321 if((str
= strchr(user
,'_')) != 0) {
1322 strcpy(warea
,str
+1);
1325 if((str
= strchr(user
,'+')) != 0) {
1326 strcpy(warea
,str
+1);
1334 if(strcmp(user
,us
)!=0) continue;
1338 sprintf(wuser
,":%s:",user
);
1339 if(strstr(userfile
, wuser
) == 0)
1344 if(!vuexclude(user
)) {
1345 if (debugm
) printf(_("Excluded user: %s\n"),user
);
1351 if(strcmp(user
,"-") ==0 || strcmp(user
," ") ==0 || strcmp(user
,"") ==0 || strcmp(user
,":") ==0)
1355 if(atol(elap
)>max_elapsed
) {
1361 if((str
=(char *) strstr(linebuf
, "[SmartFilter:")) != (char *) NULL
) {
1363 sprintf(smartfilter
,"\"%s\"",str
+1);
1364 } else sprintf(smartfilter
,"\"\"");
1368 for (ufile
=first_user_file
; ufile
&& strcmp(user
,ufile
->user
->id
)!=0 ; ufile
=ufile
->next
) {
1370 if (ufile
->file
) nopen
++;
1373 ufile
=malloc(sizeof(*ufile
));
1375 debuga(_("Not enough memory to store the user %s\n"),user
);
1378 memset(ufile
,0,sizeof(*ufile
));
1379 ufile
->next
=first_user_file
;
1380 first_user_file
=ufile
;
1381 uinfo
=userinfo_create(user
);
1383 uinfo
->id_is_ip
=id_is_ip
;
1386 prev_ufile
->next
=ufile
->next
;
1387 ufile
->next
=first_user_file
;
1388 first_user_file
=ufile
;
1392 if (ufile
->file
==NULL
) {
1393 if (nopen
>=maxopenfiles
) {
1395 for (ufile1
=first_user_file
; ufile1
; ufile1
=ufile1
->next
) {
1396 if (ufile1
->file
!=NULL
) {
1397 if (x
>=maxopenfiles
) {
1398 fclose(ufile1
->file
);
1405 if (snprintf (tmp3
, sizeof(tmp3
), "%s/sarg/%s.unsort", tmp
, ufile
->user
->filename
)>=sizeof(tmp3
)) {
1406 debuga(_("Temporary user file name too long: %s/sarg/%s.unsort\n"), tmp
, ufile
->user
->filename
);
1409 if ((ufile
->file
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1410 debuga(_("(log) Cannot open temporary file: %s - %s\n"), tmp3
, strerror(errno
));
1415 /*if ( strcmp ( user , sz_Last_User ) != 0 ) {
1416 if ( fp_Write_User )
1417 fclose( fp_Write_User ) ;
1418 sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user);
1420 if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
1421 fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], _("Cannot open temporary file"), tmp3, strerror(errno));
1424 strcpy( sz_Last_User , user ) ;
1426 fprintf(ufile
->file
, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia
,hora
,ip
,url
,tam
,code
,elap
,smartfilter
);
1428 if(fp_log
&& ilf
!=ILF_Sarg
)
1429 fprintf(fp_log
, "%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
);
1433 if(!dataonly
&& download_flag
&& download_url
&& strstr(code
,"DENIED") == 0) {
1436 if ( ! fp_Download_Unsort
) {
1437 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1438 debuga(_("(log) Cannot open temporary file: %s - %s\n"),tmp3
, strerror(errno
));
1442 fprintf(fp_Download_Unsort
,"%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,download_url
);
1445 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
1446 if(fp_denied
&& strstr(code
,"DENIED/403") != 0) {
1447 fprintf(fp_denied
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1450 if(fp_authfail
&& (strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0)) {
1451 fprintf(fp_authfail
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1456 if (ilf
!=ILF_Sarg
) {
1457 if(!totper
|| idata
<mindate
){
1459 memcpy(&period
.start
,t
,sizeof(*t
));
1460 strcpy(start_hour
,tbuf2
);
1462 if (!totper
|| idata
>maxdate
) {
1464 memcpy(&period
.end
,t
,sizeof(*t
));
1470 printf("IP=\t%s\n",ip
);
1471 printf("USER=\t%s\n",user
);
1472 printf("ELAP=\t%s\n",elap
);
1473 printf("DATE=\t%s\n",dia
);
1474 printf("TIME=\t%s\n",hora
);
1475 printf("FUNC=\t%s\n",fun
);
1476 printf("URL=\t%s\n",url
);
1477 printf("CODE=\t%s\n",code
);
1478 printf("LEN=\t%s\n",tam
);
1483 if( ShowReadStatistics
)
1484 printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs1
, (float) 100 );
1489 debuga(_(" Records read: %ld, written: %ld, excluded: %ld\n"),totregsl
,totregsg
,totregsx
);
1491 longline_destroy(&line
);
1492 if ( fp_Download_Unsort
)
1493 fclose (fp_Download_Unsort
);
1495 for (ufile
=first_user_file
; ufile
; ufile
=ufile1
) {
1497 if (ufile
->file
!=NULL
) fclose(ufile
->file
);
1502 free_excludecodes();
1508 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1510 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1511 debuga(_("Log with mixed records format (squid and common log)\n"));
1513 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1514 debuga(_("Common log format\n"));
1516 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1517 debuga(_("Squid log format\n"));
1519 if(ilf_count
[ILF_Sarg
]>0)
1520 debuga(_("Sarg log format\n"));
1522 if(totalcount
==0 && totregsg
)
1523 debuga(_("Log with invalid format\n"));
1527 debuga(_("No records found\n"));
1529 if(fp_denied
) fclose(fp_denied
);
1530 if(fp_authfail
) fclose(fp_authfail
);
1532 if(userfile
) free(userfile
);
1537 if (date
[0]!='\0') {
1538 char date0
[30], date1
[30];
1540 strftime(date0
,sizeof(date0
),"%d/%m/%Y",&period
.start
);
1541 strftime(date1
,sizeof(date1
),"%d/%m/%Y",&period
.end
);
1542 debuga(_("Period covered by log files: %s-%s\n"),date0
,date1
);
1543 getperiod_fromrange(&period
,dfrom
,duntil
);
1545 if (getperiod_buildtext(&period
)<0) {
1546 debuga(_("Failed to build the string representation of the date range\n"));
1551 debugaz("data",dia
);
1552 debugaz("period",period
.text
);
1556 debuga(_("Period: %s\n"),period
.text
);
1562 fclose(fp_authfail
);
1564 if(fp_log
!= NULL
) {
1566 strcpy(end_hour
,tbuf2
);
1567 strftime(val2
,sizeof(val2
),"%d%m%Y",&period
.start
);
1568 strftime(val1
,sizeof(val1
),"%d%m%Y",&period
.end
);
1569 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,start_hour
,val1
,end_hour
);
1570 if (rename(arq_log
,val4
)) {
1571 debuga(_("failed to rename %s to %s - %s\n"),arq_log
,val4
,strerror(errno
));
1573 strcpy(arq_log
,val4
);
1575 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0 && ParsedOutputLogCompress
[0] != '\0') {
1577 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1578 necessary around the command name, put them in the configuration file.
1580 sprintf(val1
,"%s \"%s\"",ParsedOutputLogCompress
,arq_log
);
1581 cstatus
=system(val1
);
1582 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1583 debuga(_("command return status %d\n"),WEXITSTATUS(cstatus
));
1584 debuga(_("command: %s\n"),val1
);
1590 debuga(_("Sarg parsed log saved as %s\n"),arq_log
);
1593 if(DataFile
[0] == '\0' && (ReportType
& REPORT_TYPE_DENIED
) != 0) {
1594 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,denied_sort
,denied_unsort
);
1595 cstatus
=system(csort
);
1596 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1597 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
1598 debuga(_("sort command: %s\n"),csort
);
1601 unlink(denied_unsort
);
1604 sort_users_log(tmp
, debug
);
1606 if(DataFile
[0] != '\0')
1612 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1613 unlink(denied_sort
);
1615 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1618 // else unlink(arq);
1620 if(strcmp(tmp
,"/tmp") != 0) {
1637 static void getusers(const char *pwdfile
, int debug
)
1646 debuga(_("Loading password file from %s\n"),pwdfile
);
1648 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1649 debuga(_("(getusers) Cannot open file %s - %s\n"),pwdfile
,strerror(errno
));
1653 fseek(fp_usr
, 0, SEEK_END
);
1654 nreg
= ftell(fp_usr
);
1656 debuga(_("Cannot get the size of file %s\n"),pwdfile
);
1660 fseek(fp_usr
, 0, SEEK_SET
);
1662 if((userfile
=(char *) malloc(nreg
))==NULL
){
1663 debuga(_("malloc error (%ld)\n"),nreg
);
1667 bzero(userfile
,nreg
);
1668 strcpy(userfile
,":");
1670 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1671 str
=strchr(buf
,':');
1673 debuga(_("You have an invalid user in your %s file\n"),pwdfile
);
1677 strcat(userfile
,buf
);