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 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
];
96 char hm
[15], hmf
[15], hmr
[15];
99 char hexclude
[MAXLEN
];
108 char denied_unsort
[MAXLEN
];
109 char denied_sort
[MAXLEN
];
110 char authfail_unsort
[MAXLEN
];
111 char start_hour
[128];
117 char user
[MAX_USER_LEN
];
118 enum InputLogFormat ilf
;
119 int ilf_count
[ILF_Last
];
131 int isa_ncols
=0,isa_cols
[ISACOL_Last
];
141 long int max_elapsed
=0;
144 unsigned long recs1
=0UL;
145 unsigned long recs2
=0UL;
146 int OutputNonZero
= REPORT_EVERY_X_LINES
;
148 char *download_url
=NULL
;
149 struct getwordstruct gwarea
;
151 struct userinfostruct
*uinfo
;
152 struct userfilestruct
*first_user_file
, *ufile
, *ufile1
, *prev_ufile
;
155 setlocale(LC_TIME
,"");
158 #if defined(ENABLE_NLS) && defined(HAVE_LOCALE_H)
159 setlocale (LC_ALL
, "");
160 bindtextdomain (PACKAGE_NAME
, LOCALEDIR
);
161 textdomain (PACKAGE_NAME
);
169 UserAgentLog
[0]='\0';
170 ExcludeHosts
[0]='\0';
171 ExcludeUsers
[0]='\0';
178 ExternalCSSFile
[0]='\0';
179 SquidGuardLogFormat
[0]='\0';
180 SquidGuardLogAlternate
[0]='\0';
181 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
183 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
184 strcpy(GraphDaysBytesBarColor
,"orange");
185 strcpy(BgColor
,"#ffffff");
186 strcpy(TxColor
,"#000000");
187 strcpy(TxBgColor
,"lavender");
188 strcpy(TiColor
,"darkblue");
191 strcpy(LogoTextColor
,"#000000");
192 strcpy(HeaderColor
,"darkblue");
193 strcpy(HeaderBgColor
,"#dddddd");
194 strcpy(LogoTextColor
,"#006699");
195 strcpy(FontSize
,"9px");
196 strcpy(TempDir
,"/tmp");
197 strcpy(OutputDir
,"/var/www/html/squid-reports");
199 strcpy(DateFormat
,"u");
202 strcpy(ReplaceIndex
,"index.html");
204 RecordsWithoutUser
=RECORDWITHOUTUSER_IP
;
206 strcpy(MailUtility
,"mailx");
210 strcpy(TopuserSortField
,"BYTES");
211 strcpy(UserSortField
,"BYTES");
212 strcpy(TopuserSortOrder
,"reverse");
213 strcpy(UserSortOrder
,"reverse");
214 strcpy(TopsitesSortField
,"CONNECT");
215 strcpy(TopsitesSortType
,"D");
217 strcpy(FontFace
,"Verdana,Tahoma,Arial");
218 strcpy(datetimeby
,"elap");
219 strcpy(CharSet
,"ISO-8859-1");
221 strcpy(PrivacyString
,"***.***.***.***");
222 strcpy(PrivacyStringColor
,"blue");
224 TopUserFields
=TOPUSERFIELDS_NUM
| TOPUSERFIELDS_DATE_TIME
| TOPUSERFIELDS_USERID
| TOPUSERFIELDS_CONNECT
|
225 TOPUSERFIELDS_BYTES
| TOPUSERFIELDS_SETYB
| TOPUSERFIELDS_IN_CACHE_OUT
|
226 TOPUSERFIELDS_USED_TIME
| TOPUSERFIELDS_MILISEC
| TOPUSERFIELDS_PTIME
|
227 TOPUSERFIELDS_TOTAL
| TOPUSERFIELDS_AVERAGE
;
228 UserReportFields
=USERREPORTFIELDS_CONNECT
| USERREPORTFIELDS_BYTES
| USERREPORTFIELDS_SETYB
|
229 USERREPORTFIELDS_IN_CACHE_OUT
| USERREPORTFIELDS_USED_TIME
| USERREPORTFIELDS_MILISEC
|
230 USERREPORTFIELDS_PTIME
| USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
;
231 strcpy(DataFileDelimiter
,";");
232 DataFileFields
=DATA_FIELD_USER
| DATA_FIELD_DATE
| DATA_FIELD_TIME
| DATA_FIELD_URL
| DATA_FIELD_CONNECT
|
233 DATA_FIELD_BYTES
| DATA_FIELD_IN_CACHE
| DATA_FIELD_OUT_CACHE
| DATA_FIELD_ELAPSED
;
234 ShowReadStatistics
=1;
235 strcpy(IndexSortOrder
,"D");
238 strcpy(ParsedOutputLog
,"no");
239 strcpy(ParsedOutputLogCompress
,"/bin/gzip -f");
240 strcpy(DisplayedValues
,"abbreviation");
241 strcpy(HeaderFontSize
,"9px");
242 strcpy(TitleFontSize
,"11px");
243 strcpy(AuthUserTemplateFile
,"sarg_htaccess");
244 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");
247 strcpy(GraphFont
,FONTDIR
"/DejaVuSans.ttf");
251 strcpy(Ulimit
,"20000");
252 NtlmUserFormat
=NTLMUSERFORMAT_DOMAINUSER
;
253 IndexTree
=INDEX_TREE_FILE
;
254 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
255 strcpy(RealtimeUnauthRec
,"show");
256 SquidguardIgnoreDate
=0;
257 DansguardianIgnoreDate
=0;
258 DataFileUrl
=DATAFILEURL_IP
;
259 strcpy(MaxElapsed
,"28800000");
260 BytesInSitesUsersReport
=0;
261 UserAuthentication
=0;
262 strcpy(LDAPHost
,"127.0.0.1");
264 LDAPProtocolVersion
=3;
267 LDAPBaseSearch
[0]='\0';
268 strcpy(LDAPFilterSearch
, "uid=%s");
269 strcpy(LDAPTargetAttr
, "cn");
293 UserInvalidChar
[0]='\0';
295 SquidGuardConf
[0]='\0';
296 DansGuardianConf
[0]='\0';
303 dansguardian_count
=0;
306 DeniedReportLimit
=10;
307 AuthfailReportLimit
=10;
308 DansGuardianReportLimit
=10;
309 SquidGuardReportLimit
=10;
310 DownloadReportLimit
=50;
322 realtime_access_log_lines
=1000;
328 bzero(IncludeUsers
, sizeof(IncludeUsers
));
329 bzero(ExcludeString
, sizeof(ExcludeString
));
330 first_user_file
=NULL
;
333 for(x
=0; x
<MAXLOGS
; x
++)
334 AccessLog
[x
][0]='\0';
335 AccessLogFromCmdLine
=0;
337 strcpy(Title
,_("Squid User Access Report"));
339 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
346 strcpy(uagent
,optarg
);
349 strcpy(hexclude
,optarg
);
352 strncpy(date
,optarg
,sizeof(date
)-1);
353 date
[sizeof(date
)-1]='\0';
354 getword_start(&gwarea
,optarg
);
355 if (getword(cdfrom
,sizeof(cdfrom
),&gwarea
,'-')<0 || getword(cduntil
,sizeof(cduntil
),&gwarea
,0)<0) {
356 printf(_("SARG: The date range requested on the command line by option -d is invalid.\n"));
359 date_from(date
, cdfrom
, cduntil
);
361 duntil
=atoi(cduntil
);
364 strcpy(email
,optarg
);
367 strcpy(ConfigFile
,optarg
);
380 if (NAccessLog
>=MAXLOGS
) {
381 printf(_("SARG: Too many log files passed on command line with option -l.\n"));
384 strcpy(AccessLog
[NAccessLog
],optarg
);
386 AccessLogFromCmdLine
++;
389 strcpy(SquidGuardLogAlternate
,optarg
);
398 strcpy(outdir
,optarg
);
413 if(strstr(optarg
,"-") == 0) {
417 getword_start(&gwarea
,optarg
);
418 if (getword(hm
,sizeof(hm
),&gwarea
,'-')<0 || getword(hmf
,sizeof(hmf
),&gwarea
,0)<0) {
419 debuga(_("The time range passed on the command line with option -t is invalid\n"));
423 if(sscanf(hm
,"%d:%d",&h
,&m
)!=2) {
424 debuga(_("Time period must be MM or MM:SS. Exit\n"));
427 sprintf(hm
,"%02d%02d",h
,m
);
428 if(sscanf(hmf
,"%d:%d",&h
,&m
)!=2) {
429 debuga(_("Time period must be MM or MM:SS. Exit\n"));
432 sprintf(hmf
,"%02d%02d",h
,m
);
454 debuga(_("Option -%c require an argument\n"),optopt
);
470 if(debug
) debuga(_("Init\n"));
472 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
473 if(access(ConfigFile
, R_OK
) != 0) {
474 debuga(_("Cannot open config file: %s - %s\n"),ConfigFile
,strerror(errno
));
478 if(access(ConfigFile
, R_OK
) == 0)
490 if(IndexTree
== INDEX_TREE_FILE
)
491 strcpy(ImageFile
,"../images");
493 strcpy(ImageFile
,"../../../images");
496 if(DataFile
[0] != '\0')
500 strcpy(AccessLog
[0],"/var/log/squid/access.log");
504 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
505 convlog(AccessLog
[0], df
, dfrom
, duntil
);
509 if(strcmp(site
,"plit") == 0) {
510 splitlog(AccessLog
[0], df
, dfrom
, duntil
, hexclude
);
514 load_excludecodes(ExcludeCodes
);
516 if(access(PasswdFile
, R_OK
) == 0) {
517 getusers(PasswdFile
,debug
);
521 if(hexclude
[0] == '\0')
522 strcpy(hexclude
,ExcludeHosts
);
523 if(hexclude
[0] != '\0') {
524 gethexclude(hexclude
,debug
);
528 if(ReportType
== 0) {
529 ReportType
=REPORT_TYPE_TOPUSERS
| REPORT_TYPE_TOPSITES
| REPORT_TYPE_USERS_SITES
|
530 REPORT_TYPE_SITES_USERS
| REPORT_TYPE_DATE_TIME
| REPORT_TYPE_DENIED
|
531 REPORT_TYPE_AUTH_FAILURES
| REPORT_TYPE_SITE_USER_TIME_DATE
| REPORT_TYPE_DOWNLOADS
;
534 if(access(ExcludeUsers
, R_OK
) == 0) {
535 getuexclude(ExcludeUsers
,debug
);
544 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
545 if(Index
== INDEX_ONLY
) indexonly
++;
547 if(MaxElapsed
[0] != '\0') max_elapsed
=atol(MaxElapsed
);
549 if(outdir
[0] == '\0') strcpy(outdir
,OutputDir
);
552 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
554 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
555 else strcpy(TempDir
,tmp
);
557 if(df
[0] == '\0') strcpy(df
,DateFormat
);
558 else strcpy(DateFormat
,df
);
562 strcpy(DateFormat
,"u");
565 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
569 if(email
[0] != '\0') {
570 sprintf(wtemp2
,"%s/sarg",tmp2
);
572 strcat(tmp2
,"/sarg");
577 strcat(tmp2
,"/sarg.log");
579 sprintf(tmp3
,"%s/sarg",tmp
);
580 if(access(tmp3
, R_OK
) == 0) {
584 strcpy(denied_unsort
,tmp3
);
585 strcpy(denied_sort
,tmp3
);
586 strcpy(authfail_unsort
,tmp3
);
587 strcat(denied_unsort
,"/denied.log.unsort");
588 strcat(denied_sort
,"/denied.log");
589 strcat(authfail_unsort
,"/authfail.log.unsort");
592 debuga(_("Parameters:\n"));
593 debuga(_(" Hostname or IP address (-a) = %s\n"),addr
);
594 debuga(_(" Useragent log (-b) = %s\n"),uagent
);
595 debuga(_(" Exclude file (-c) = %s\n"),hexclude
);
596 debuga(_(" Date from-until (-d) = %s\n"),date
);
597 debuga(_(" Email address to send reports (-e) = %s\n"),email
);
598 debuga(_(" Config file (-f) = %s\n"),ConfigFile
);
599 if(strcmp(df
,"e") == 0)
600 debuga(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
601 if(strcmp(df
,"u") == 0)
602 debuga(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
603 if(strcmp(df
,"w") == 0)
604 debuga(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
605 debuga(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
606 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
607 debuga(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
608 debuga(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
609 debuga(_(" Output dir (-o) = %s\n"),outdir
);
610 debuga(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
611 debuga(_(" Accessed site (-s) = %s\n"),site
);
612 debuga(_(" Time (-t) = %s\n"),hm
);
613 debuga(_(" User (-u) = %s\n"),us
);
614 debuga(_(" Temporary dir (-w) = %s\n"),tmp
);
615 debuga(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
616 debuga(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
621 printf(_("Parameters:\n"));
622 printf(_(" Hostname or IP address (-a) = %s\n"),addr
);
623 printf(_(" Useragent log (-b) = %s\n"),uagent
);
624 printf(_(" Exclude file (-c) = %s\n"),hexclude
);
625 printf(_(" Date from-until (-d) = %s\n"),date
);
626 printf(_(" Email address to send reports (-e) = %s\n"),email
);
627 printf(_(" Config file (-f) = %s\n"),ConfigFile
);
628 if(strcmp(df
,"e") == 0)
629 printf(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
630 if(strcmp(df
,"u") == 0)
631 printf(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
632 if(strcmp(df
,"w") == 0)
633 printf(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
634 printf(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
635 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
636 printf(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
637 printf(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
638 printf(_(" Output dir (-o) = %s\n"),outdir
);
639 printf(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
640 printf(_(" Accessed site (-s) = %s\n"),site
);
641 printf(_(" Time (-t) = %s\n"),hm
);
642 printf(_(" User (-u) = %s\n"),us
);
643 printf(_(" Temporary dir (-w) = %s\n"),tmp
);
644 printf(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
645 printf(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
646 printf(_("sarg version: %s\n"),VERSION
);
650 debuga(_("sarg version: %s\n"),VERSION
);
652 maxopenfiles
=MAX_OPEN_USER_FILES
;
654 if (Ulimit
[0] != '\0') {
659 #if defined(RLIMIT_NOFILE)
660 getrlimit (RLIMIT_NOFILE
, &rl
);
661 #elif defined(RLIMIT_OFILE)
662 getrlimit (RLIMIT_OFILE
, &rl
);
664 #warning "No rlimit resource for the number of open files"
669 rl
.rlim_cur
= atol(Ulimit
);
670 rl
.rlim_max
= atol(Ulimit
);
671 #if defined(RLIMIT_NOFILE)
672 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
673 #elif defined(RLIMIT_OFILE)
674 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
676 #warning "No rlimit resource for the number of open files"
679 debuga(_("setrlimit error - %s\n"),strerror(errno
));
683 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
687 init_usertab(UserTabFile
);
689 if ((line
=longline_create())==NULL
) {
690 debuga(_("Not enough memory to read a log file\n"));
694 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
696 if(DataFile
[0]=='\0') {
697 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
698 if((fp_denied
=MY_FOPEN(denied_unsort
,"w"))==NULL
) {
699 debuga(_("(log) Cannot open file: %s - %s\n"),denied_unsort
,strerror(errno
));
704 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
705 if((fp_authfail
=MY_FOPEN(authfail_unsort
,"w"))==NULL
) {
706 debuga(_("(log) Cannot open file: %s - %s\n"),authfail_unsort
,strerror(errno
));
712 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
713 strcpy(arq
,AccessLog
[iarq
]);
717 if(strcmp(arq
,"-")==0) {
719 debuga(_("Reading access log file: from stdin\n"));
725 debuga(_("Reading access log file: %s\n"),arq
);
726 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
727 debuga(_("(log) Cannot open log file: %s - %s\n"),arq
,strerror(errno
));
734 // pre-read the file only if we have to show stats
735 if(ShowReadStatistics
&& !from_stdin
) {
743 while ((nread
=fread(tmp4
,1,sizeof(tmp4
),fp_in
))>0) {
744 for (i
=0 ; i
<nread
; i
++)
746 if (tmp4
[i
]!='\n' && tmp4
[i
]!='\r') {
750 if (tmp4
[i
]=='\n' || tmp4
[i
]=='\r') {
757 printf(_("SARG: Records in file: %lu, reading: %3.2f%%"),recs1
,(float) 0);
762 longline_reset(line
);
764 while ((linebuf
=longline_read(fp_in
,line
))!=NULL
) {
765 blen
=strlen(linebuf
);
767 if (ilf
==ILF_Unknown
) {
768 if(strncmp(linebuf
,"#Software: Mic",14) == 0) {
769 fixendofline(linebuf
);
771 debuga(_("Log is from Microsoft ISA: %s\n"),linebuf
);
777 if(strncmp(linebuf
,"*** SARG Log ***",16) == 0) {
778 getword_start(&gwarea
,arqtt
);
779 if (getword_skip(2000,&gwarea
,'-')<0 || getword(val2
,sizeof(val2
),&gwarea
,'_')<0 ||
780 getword_skip(10,&gwarea
,'-')<0 || getword(val3
,sizeof(val3
),&gwarea
,'_')<0) {
781 debuga(_("The name of the file is invalid: %s\n"),arq
);
784 sprintf(period
,"%s-%s",val2
,val3
);
791 if(!fp_log
&& strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
792 if(access(ParsedOutputLog
,R_OK
) != 0) {
793 my_mkdir(ParsedOutputLog
);
795 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
796 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
797 debuga(_("(log) Cannot open log file: %s - %s\n"),arq_log
,strerror(errno
));
800 fputs("*** SARG Log ***\n",fp_log
);
804 if( ShowReadStatistics
&& !from_stdin
&& ! --OutputNonZero
) {
806 perc
= perc
/ recs1
;
807 printf(_("SARG: Records in file: %lu, reading: %3.2f%%"),recs1
,perc
);
810 OutputNonZero
= REPORT_EVERY_X_LINES
;
812 if(blen
< 58) continue;
813 if(strstr(linebuf
,"HTTP/0.0") != 0) continue;
814 if(strstr(linebuf
,"logfile turned over") != 0) continue;
815 if(linebuf
[0] == ' ') continue;
818 if(ExcludeString
[0] != '\0') {
820 getword_start(&gwarea
,ExcludeString
);
821 while(strchr(gwarea
.current
,':') != 0) {
822 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
823 debuga(_("Maybe you have a broken record or garbage in your exclusion string\n"));
826 if((str
=(char *) strstr(linebuf
,val1
)) != (char *) NULL
)
829 if((str
=(char *) strstr(linebuf
,gwarea
.current
)) != (char *) NULL
)
831 if(exstring
) continue;
836 printf("BUF=%s\n",linebuf
);
838 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
839 getword_start(&gwarea
,linebuf
);
840 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
841 debuga(_("Maybe you have a broken time in your access.log file\n"));
844 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
) {
845 if((str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
849 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
850 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
854 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
855 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
859 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
860 getword(fun
,sizeof(fun
),&gwarea
,' ')<0) {
861 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
864 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0) {
865 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
868 if (getword_skip(MAXLEN
,&gwarea
,' ')<0 || getword(code2
,sizeof(code2
),&gwarea
,' ')<0 ||
869 getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
870 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
873 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
874 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
875 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
879 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
880 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
885 if ((str
= strchr(code
, ':')) != NULL
)
888 if(strcmp(tam
,"\0") == 0)
896 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
897 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
898 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
901 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
902 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
903 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
906 if(strlen(elap
) < 1) continue;
907 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
908 debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq
);
911 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
912 debuga(_("Maybe you have a broken result code in your %s file\n"),arq
);
915 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
916 debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq
);
919 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
920 debuga(_("Maybe you have a broken request method in your %s file\n"),arq
);
923 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0){
924 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
927 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
928 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
936 getword_start(&gwarea
,linebuf
);
937 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0){
938 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
941 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
942 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
945 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
946 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
949 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
950 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
953 if (getword_ptr(linebuf
,&url
,&gwarea
,'\t')<0){
954 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
957 if (getword(tam
,sizeof(tam
),&gwarea
,'\t')<0){
958 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
961 if (getword(code
,sizeof(code
),&gwarea
,'\t')<0){
962 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
965 if (getword(elap
,sizeof(elap
),&gwarea
,'\t')<0){
966 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
969 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,'\0')<0){
970 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
975 if (linebuf
[0] == '#') {
976 int ncols
,cols
[ISACOL_Last
];
978 fixendofline(linebuf
);
979 getword_start(&gwarea
,linebuf
);
980 // remove the #Fields: column at the beginning of the line
981 if (getword_skip(1000,&gwarea
,' ')<0){
982 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
985 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
987 while(gwarea
.current
[0] != '\0') {
988 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
989 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
992 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
993 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
994 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
995 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
996 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
997 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
998 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
999 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
1002 if (cols
[ISACOL_Ip
]>=0) {
1004 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++)
1005 isa_cols
[ncols
]=cols
[ncols
];
1009 if (!isa_ncols
) continue;
1010 getword_start(&gwarea
,linebuf
);
1011 for (x
=0 ; x
<isa_ncols
; x
++) {
1012 if (getword_ptr(linebuf
,&str
,&gwarea
,'\t')<0) {
1013 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1016 if (x
==isa_cols
[ISACOL_Ip
]) {
1017 if (strlen(str
)>=sizeof(ip
)) {
1018 debuga(_("Maybe you have a broken IP in your %s file\n"),arq
);
1022 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1023 if (strlen(str
)>=sizeof(user
)) {
1024 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
1028 } else if (x
==isa_cols
[ISACOL_Date
]) {
1029 if (strlen(str
)>=sizeof(data
)) {
1030 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1034 } else if (x
==isa_cols
[ISACOL_Time
]) {
1035 if (strlen(str
)>=sizeof(hora
)) {
1036 debuga(_("Maybe you have a broken time in your %s file\n"),arq
);
1040 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1041 if (strlen(str
)>=sizeof(elap
)) {
1042 debuga(_("Maybe you have a broken download duration in your %s file\n"),arq
);
1046 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1047 if (strlen(str
)>=sizeof(tam
)) {
1048 debuga(_("Maybe you have a broken download size in your %s file\n"),arq
);
1052 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1054 } else if (x
==isa_cols
[ISACOL_Status
]) {
1055 if (strlen(str
)>=sizeof(code
)) {
1056 debuga(_("Maybe you have a broken access code in your %s file\n"),arq
);
1063 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1064 sprintf(val1
,"DENIED/%s",code
);
1067 getword_start(&gwarea
,data
);
1068 if (getword(ano
,sizeof(ano
),&gwarea
,'-')<0){
1069 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1072 if (getword(mes
,sizeof(mes
),&gwarea
,'-')<0){
1073 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1076 if (getword(dia
,sizeof(dia
),&gwarea
,'\0')<0){
1077 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1080 conv_month_name(mes
);
1081 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1084 if(ilf
==ILF_Squid
) {
1088 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1089 sprintf(mes
,"%d",t
->tm_mon
+1);
1090 conv_month_name(mes
);
1091 if(strncmp(df
,"u",1) == 0)
1092 sprintf(tbuf
, "%04d%s%02d", t
->tm_year
+1900, mes
, t
->tm_mday
);
1093 if(strncmp(df
,"e",1) == 0)
1094 sprintf(tbuf
, "%02d%s%04d", t
->tm_mday
, mes
, t
->tm_year
+1900);
1095 if(strncmp(df
,"w",1) == 0) {
1096 IndexTree
=INDEX_TREE_FILE
;
1097 strftime(tbuf
, sizeof(tbuf
), "%Y.%U", t
);
1100 strftime(wdata
, sizeof(wdata
), "%Y%m%d", t
);
1103 if(strncmp(df
,"u",1)==0)
1104 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
1106 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1107 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1108 } else if(ilf
==ILF_Common
|| ilf
==ILF_Isa
) {
1109 getword_start(&gwarea
,data
+1);
1110 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
1111 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1114 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
1115 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1118 getword_start(&gwarea
,data
);
1119 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1120 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1123 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1124 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1127 if (getword(ano
,sizeof(ano
),&gwarea
,'/')<0){
1128 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1132 if(strcmp(df
,"u") == 0)
1133 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",ano
,mes
,dia
);
1134 if(strcmp(df
,"e") == 0)
1135 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",dia
,mes
,ano
);
1136 builddia(dia
,mes
,ano
,df
,wdata
);
1138 tt
=computedate(ano
,mes
,dia
);
1140 } else if (ilf
==ILF_Sarg
) {
1141 getword_start(&gwarea
,data
);
1142 if(strcmp(df
,"u") == 0) {
1143 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1144 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1147 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1148 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1152 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1153 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1156 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1157 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1161 if (getword(ano
,sizeof(ano
),&gwarea
,0)<0){
1162 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1165 snprintf(wdata
,9,"%s%s%s",ano
,mes
,dia
);
1167 tt
=computedate(ano
,mes
,dia
);
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
) {
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((!totper
|| idata
<mindate
) && ilf
!=ILF_Sarg
){
1459 sprintf(period
,"%s-",tbuf
);
1460 strcpy(start_hour
,tbuf2
);
1462 fixper(tbuf
, period
, cduntil
);
1464 debugaz("tbuf",tbuf
);
1465 debugaz("period",period
);
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 );
1488 longline_destroy(&line
);
1489 if ( fp_Download_Unsort
)
1490 fclose (fp_Download_Unsort
);
1492 for (ufile
=first_user_file
; ufile
; ufile
=ufile1
) {
1494 if (ufile
->file
!=NULL
) fclose(ufile
->file
);
1499 free_excludecodes();
1505 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1507 debuga(_(" Records read: %ld, written: %ld, excluded: %ld\n"),totregsl
,totregsg
,totregsx
);
1509 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1510 debuga(_("Log with mixed records format (squid and common log)\n"));
1512 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1513 debuga(_("Common log format\n"));
1515 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1516 debuga(_("Squid log format\n"));
1518 if(ilf_count
[ILF_Sarg
]>0)
1519 debuga(_("Sarg log format\n"));
1523 debuga(_("No records found\n"));
1525 } else debuga(_("Log with invalid format\n"));
1529 fclose(fp_authfail
);
1534 unlink(denied_unsort
);
1535 unlink(authfail_unsort
);
1542 debuga(_("No records found\n"));
1548 fclose(fp_authfail
);
1556 if(date
[0] == '\0' && ilf_count
[ILF_Sarg
]==0) {
1557 strcat(period
,tbuf
);
1561 debugaz("data",dia
);
1562 debugaz("tbuf",tbuf
);
1563 debugaz("period",period
);
1567 debuga(_("Period: %s\n"),period
);
1573 fclose(fp_authfail
);
1575 if(fp_log
!= NULL
) {
1577 strcpy(end_hour
,tbuf2
);
1578 getword_start(&gwarea
,period
);
1579 if (getword(val2
,sizeof(val2
),&gwarea
,'-')<0){
1580 debuga(_("Maybe you have a broken date range definition.\n"));
1583 if (getword(val1
,sizeof(val1
),&gwarea
,'\0')<0){
1584 debuga(_("Maybe you have a broken date range definition.\n"));
1587 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,start_hour
,val1
,end_hour
);
1588 if (rename(arq_log
,val4
)) {
1589 debuga(_("failed to rename %s to %s - %s\n"),arq_log
,val4
,strerror(errno
));
1591 strcpy(arq_log
,val4
);
1593 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0 && ParsedOutputLogCompress
[0] != '\0') {
1595 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1596 necessary around the command name, put them in the configuration file.
1598 sprintf(val1
,"%s \"%s\"",ParsedOutputLogCompress
,arq_log
);
1599 cstatus
=system(val1
);
1600 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1601 debuga(_("command return status %d\n"),WEXITSTATUS(cstatus
));
1602 debuga(_("command: %s\n"),val1
);
1608 debuga(_("Sarg parsed log saved as %s\n"),arq_log
);
1611 if(DataFile
[0] == '\0' && (ReportType
& REPORT_TYPE_DENIED
) != 0) {
1612 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,denied_sort
,denied_unsort
);
1613 cstatus
=system(csort
);
1614 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1615 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
1616 debuga(_("sort command: %s\n"),csort
);
1619 unlink(denied_unsort
);
1622 sort_users_log(tmp
, debug
);
1624 if(DataFile
[0] != '\0')
1630 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1631 unlink(denied_sort
);
1633 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1636 // else unlink(arq);
1638 if(strcmp(tmp
,"/tmp") != 0) {
1655 static void getusers(const char *pwdfile
, int debug
)
1664 debuga(_("Loading password file from %s\n"),pwdfile
);
1666 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1667 debuga(_("(getusers) Cannot open file %s - %s\n"),pwdfile
,strerror(errno
));
1671 fseek(fp_usr
, 0, SEEK_END
);
1672 nreg
= ftell(fp_usr
);
1674 debuga(_("Cannot get the size of file %s\n"),pwdfile
);
1678 fseek(fp_usr
, 0, SEEK_SET
);
1680 if((userfile
=(char *) malloc(nreg
))==NULL
){
1681 debuga(_("malloc error (%ld)\n"),nreg
);
1685 bzero(userfile
,nreg
);
1686 strcpy(userfile
,":");
1688 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1689 str
=strchr(buf
,':');
1691 debuga(_("You have an invalid user in your %s file\n"),pwdfile
);
1695 strcat(userfile
,buf
);