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"
34 #define REPORT_EVERY_X_LINES 5000
35 #define MAX_OPEN_USER_FILES 10
39 struct userfilestruct
*next
;
40 struct userinfostruct
*user
;
44 /*@null@*/static char *userfile
=NULL
;
46 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
47 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
48 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
50 static void getusers(const char *pwdfile
, int debug
);
52 int main(int argc
,char *argv
[])
63 ISACOL_Last
//last entry of the list !
71 ILF_Last
//last entry of the list !
74 FILE *fp_in
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
76 char sz_Download_Unsort
[ 20000 ] ;
77 FILE * fp_Download_Unsort
= NULL
;
89 char smartfilter
[MAXLEN
];
101 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
];
142 long int max_elapsed
=0;
143 long long int iyear
, imonth
, iday
;
148 unsigned long recs1
=0UL;
149 unsigned long recs2
=0UL;
150 int OutputNonZero
= REPORT_EVERY_X_LINES
;
151 bool download_flag
=false;
152 char *download_url
=NULL
;
153 struct getwordstruct gwarea
;
157 struct userinfostruct
*uinfo
;
158 struct userfilestruct
*first_user_file
, *ufile
, *ufile1
, *prev_ufile
;
160 static int convert
=0;
161 static int output_css
=0;
163 static struct option long_options
[]=
165 {"convert",no_argument
,&convert
,1},
166 {"css",no_argument
,&output_css
,1},
167 {"split",no_argument
,&split
,1},
172 setlocale(LC_TIME
,"");
175 #if defined(ENABLE_NLS) && defined(HAVE_LOCALE_H)
176 if (!setlocale (LC_ALL
, "")) {
177 fprintf(stderr
,"SARG: Cannot set the locale LC_ALL to the environment variable\n");
180 if (!bindtextdomain (PACKAGE_NAME
, LOCALEDIR
)) {
181 fprintf(stderr
,"SARG: Cannot bind to text domain %s in directory %s (%s)\n",PACKAGE_NAME
,LOCALEDIR
,strerror(errno
));
184 if (!textdomain (PACKAGE_NAME
)) {
185 fprintf(stderr
,"SARG: Cannot set gettext domain for %s PACKAGE_NAME (%s)\n",PACKAGE_NAME
,strerror(errno
));
195 UserAgentLog
[0]='\0';
196 ExcludeHosts
[0]='\0';
197 ExcludeUsers
[0]='\0';
204 ExternalCSSFile
[0]='\0';
205 RedirectorLogFormat
[0]='\0';
207 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
209 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
210 strcpy(GraphDaysBytesBarColor
,"orange");
211 strcpy(BgColor
,"#ffffff");
212 strcpy(TxColor
,"#000000");
213 strcpy(TxBgColor
,"lavender");
214 strcpy(TiColor
,"darkblue");
217 strcpy(LogoTextColor
,"#000000");
218 strcpy(HeaderColor
,"darkblue");
219 strcpy(HeaderBgColor
,"#dddddd");
220 strcpy(LogoTextColor
,"#006699");
221 strcpy(FontSize
,"9px");
222 strcpy(TempDir
,"/tmp");
223 strcpy(OutputDir
,"/var/www/html/squid-reports");
225 strcpy(DateFormat
,"u");
226 OverwriteReport
=false;
227 RemoveTempFiles
=true;
228 strcpy(ReplaceIndex
,"index.html");
230 RecordsWithoutUser
=RECORDWITHOUTUSER_IP
;
232 strcpy(MailUtility
,"mailx");
236 TopuserSort
=TOPUSER_SORT_BYTES
| TOPUSER_SORT_REVERSE
;
237 UserSort
=USER_SORT_BYTES
| USER_SORT_REVERSE
;
238 TopsitesSort
=TOPSITE_SORT_CONNECT
| TOPSITE_SORT_REVERSE
;
240 strcpy(FontFace
,"Verdana,Tahoma,Arial");
241 datetimeby
=DATETIME_BYTE
;
242 strcpy(CharSet
,"ISO-8859-1");
244 strcpy(PrivacyString
,"***.***.***.***");
245 strcpy(PrivacyStringColor
,"blue");
247 TopUserFields
=TOPUSERFIELDS_NUM
| TOPUSERFIELDS_DATE_TIME
| TOPUSERFIELDS_USERID
| TOPUSERFIELDS_CONNECT
|
248 TOPUSERFIELDS_BYTES
| TOPUSERFIELDS_SETYB
| TOPUSERFIELDS_IN_CACHE_OUT
|
249 TOPUSERFIELDS_USED_TIME
| TOPUSERFIELDS_MILISEC
| TOPUSERFIELDS_PTIME
|
250 TOPUSERFIELDS_TOTAL
| TOPUSERFIELDS_AVERAGE
;
251 UserReportFields
=USERREPORTFIELDS_CONNECT
| USERREPORTFIELDS_BYTES
| USERREPORTFIELDS_SETYB
|
252 USERREPORTFIELDS_IN_CACHE_OUT
| USERREPORTFIELDS_USED_TIME
| USERREPORTFIELDS_MILISEC
|
253 USERREPORTFIELDS_PTIME
| USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
;
254 strcpy(DataFileDelimiter
,";");
255 DataFileFields
=DATA_FIELD_USER
| DATA_FIELD_DATE
| DATA_FIELD_TIME
| DATA_FIELD_URL
| DATA_FIELD_CONNECT
|
256 DATA_FIELD_BYTES
| DATA_FIELD_IN_CACHE
| DATA_FIELD_OUT_CACHE
| DATA_FIELD_ELAPSED
;
257 ShowReadStatistics
=true;
258 strcpy(IndexSortOrder
,"D");
261 strcpy(ParsedOutputLog
,"no");
262 strcpy(ParsedOutputLogCompress
,"/bin/gzip -f");
263 DisplayedValues
=DISPLAY_ABBREV
;
264 strcpy(HeaderFontSize
,"9px");
265 strcpy(TitleFontSize
,"11px");
266 strcpy(AuthUserTemplateFile
,"sarg_htaccess");
267 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");
270 strcpy(GraphFont
,FONTDIR
"/DejaVuSans.ttf");
274 strcpy(Ulimit
,"20000");
275 NtlmUserFormat
=NTLMUSERFORMAT_DOMAINUSER
;
276 IndexTree
=INDEX_TREE_FILE
;
277 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
278 RealtimeUnauthRec
=REALTIME_UNAUTH_REC_SHOW
;
279 RedirectorFilterOutDate
=true;
280 DansguardianFilterOutDate
=true;
281 DataFileUrl
=DATAFILEURL_IP
;
282 strcpy(MaxElapsed
,"28800000");
283 BytesInSitesUsersReport
=0;
284 UserAuthentication
=0;
285 strcpy(LDAPHost
,"127.0.0.1");
287 LDAPProtocolVersion
=3;
290 LDAPBaseSearch
[0]='\0';
291 strcpy(LDAPFilterSearch
, "(uid=%s)");
292 strcpy(LDAPTargetAttr
, "cn");
314 UserInvalidChar
[0]='\0';
316 SquidGuardConf
[0]='\0';
317 DansGuardianConf
[0]='\0';
324 dansguardian_count
=0;
327 DeniedReportLimit
=10;
328 AuthfailReportLimit
=10;
329 DansGuardianReportLimit
=10;
330 SquidGuardReportLimit
=10;
331 DownloadReportLimit
=50;
340 realtime_access_log_lines
=1000;
348 bzero(IncludeUsers
, sizeof(IncludeUsers
));
349 bzero(ExcludeString
, sizeof(ExcludeString
));
350 first_user_file
=NULL
;
351 memset(&period
,0,sizeof(period
));
354 for(x
=0; x
<MAXLOGS
; x
++)
355 AccessLog
[x
][0]='\0';
356 AccessLogFromCmdLine
=0;
357 RedirectorLogFromCmdLine
=0;
359 strcpy(Title
,_("Squid User Access Report"));
361 while((ch
= getopt_long_only(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz",long_options
,&option_index
)) != -1){
370 strcpy(uagent
,optarg
);
373 strcpy(hexclude
,optarg
);
376 strncpy(date
,optarg
,sizeof(date
)-1);
377 date
[sizeof(date
)-1]='\0';
378 date_from(date
, &dfrom
, &duntil
);
381 strcpy(email
,optarg
);
384 strcpy(ConfigFile
,optarg
);
396 if (NAccessLog
>=MAXLOGS
) {
397 debuga(_("Too many log files passed on command line with option -l.\n"));
400 if (strlen(optarg
)>=MAX_LOG_FILELEN
) {
401 debuga(_("Log file name too long passed on command line with option -l: %s\n"),optarg
);
404 strcpy(AccessLog
[NAccessLog
],optarg
);
406 AccessLogFromCmdLine
++;
409 if (NRedirectorLogs
>MAX_REDIRECTOR_LOGS
) {
410 debuga(_("Too many redirector logs passed on command line with option -L.\n"));
413 if (strlen(optarg
)>=MAX_REDIRECTOR_FILELEN
) {
414 debuga(_("Redirector log file name too long passed on command line with opton -L: %s\n"),optarg
);
417 strcpy(RedirectorLogs
[NRedirectorLogs
],optarg
);
419 RedirectorLogFromCmdLine
++;
428 strcpy(outdir
,optarg
);
443 if(strstr(optarg
,"-") == 0) {
444 if(sscanf(optarg
,"%d:%d",&h1
,&m1
)!=2) {
445 debuga(_("Time period passed on the command line with option -t must be MM:SS\n"));
450 snprintf(hm_str
,sizeof(hm_str
),"%02d:%02d",h1
,m1
);
452 if(sscanf(optarg
,"%d:%d-%d:%d",&h1
,&m1
,&h2
,&m2
)!=4) {
453 debuga(_("Time range passed on the command line with option -t must be MM:SS-MM:SS\n"));
458 snprintf(hm_str
,sizeof(hm_str
),"%02d:%02d-%02d:%02d",h1
,m1
,h2
,m2
);
481 debuga(_("Option -%c require an argument\n"),optopt);
498 for (iarq
=optind
; iarq
<argc
; iarq
++) {
499 if (NAccessLog
>=MAXLOGS
) {
500 debuga(_("Too many log files passed on command line.\n"));
503 if (strlen(argv
[iarq
])>=MAX_LOG_FILELEN
) {
504 debuga(_("Log file name too long passed on command line: %s\n"),argv
[iarq
]);
507 strcpy(AccessLog
[NAccessLog
],argv
[iarq
]);
509 AccessLogFromCmdLine
++;
513 if(debug
) debuga(_("Init\n"));
515 if(ConfigFile
[0] == '\0') snprintf(ConfigFile
,sizeof(ConfigFile
),"%s/sarg.conf",SYSCONFDIR
);
516 if(access(ConfigFile
, R_OK
) != 0) {
517 debuga(_("Cannot open config file: %s - %s\n"),ConfigFile
,strerror(errno
));
521 if(access(ConfigFile
, R_OK
) == 0)
524 if(userip
) UserIp
=true;
526 if(dns
) Ip2Name
=true;
533 if(IndexTree
== INDEX_TREE_FILE
)
534 strcpy(ImageFile
,"../images");
536 strcpy(ImageFile
,"../../../images");
539 if(DataFile
[0] != '\0')
542 if(NAccessLog
== 0) {
543 strcpy(AccessLog
[0],"/var/log/squid/access.log");
552 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
553 splitlog(AccessLog
[iarq
], df
, dfrom
, duntil
, convert
);
557 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
558 convlog(AccessLog
[iarq
], df
, dfrom
, duntil
);
562 load_excludecodes(ExcludeCodes
);
564 if(access(PasswdFile
, R_OK
) == 0) {
565 getusers(PasswdFile
,debug
);
569 if(hexclude
[0] == '\0')
570 strcpy(hexclude
,ExcludeHosts
);
571 if(hexclude
[0] != '\0') {
572 gethexclude(hexclude
,debug
);
576 if(ReportType
== 0) {
577 ReportType
=REPORT_TYPE_TOPUSERS
| REPORT_TYPE_TOPSITES
| REPORT_TYPE_USERS_SITES
|
578 REPORT_TYPE_SITES_USERS
| REPORT_TYPE_DATE_TIME
| REPORT_TYPE_DENIED
|
579 REPORT_TYPE_AUTH_FAILURES
| REPORT_TYPE_SITE_USER_TIME_DATE
| REPORT_TYPE_DOWNLOADS
;
582 if(access(ExcludeUsers
, R_OK
) == 0) {
583 getuexclude(ExcludeUsers
,debug
);
592 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
593 if(Index
== INDEX_ONLY
) indexonly
++;
595 if(MaxElapsed
[0] != '\0') max_elapsed
=atol(MaxElapsed
);
597 if(outdir
[0] == '\0') strcpy(outdir
,OutputDir
);
600 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
602 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
603 else strcpy(TempDir
,tmp
);
605 For historical reasons, the temporary directory is the subdirectory "sarg" of the path
606 provided by the user.
610 if (tmp
[0]!='\0' && strncmp(outdir
,tmp
,strlen(tmp
))==0) {
611 debuga(_("The output directory \"%s\" must be outside of the temporary directory \"%s\"\n"),outdir
,tmp
);
615 if(df
[0] == '\0') strcpy(df
,DateFormat
);
616 else strcpy(DateFormat
,df
);
620 strcpy(DateFormat
,"u");
623 IndexTree
=INDEX_TREE_FILE
;
625 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
627 if(email
[0] != '\0') {
633 if(access(tmp
, R_OK
) == 0) {
637 snprintf(denied_unsort
,sizeof(denied_unsort
),"%s/denied.log.unsort",tmp
);
638 snprintf(denied_sort
,sizeof(denied_sort
),"%s/denied.log",tmp
);
639 snprintf(authfail_unsort
,sizeof(authfail_unsort
),"%s/authfail.log.unsort",tmp
);
642 debuga(_("Parameters:\n"));
643 debuga(_(" Hostname or IP address (-a) = %s\n"),addr
);
644 debuga(_(" Useragent log (-b) = %s\n"),uagent
);
645 debuga(_(" Exclude file (-c) = %s\n"),hexclude
);
646 debuga(_(" Date from-until (-d) = %s\n"),date
);
647 debuga(_(" Email address to send reports (-e) = %s\n"),email
);
648 debuga(_(" Config file (-f) = %s\n"),ConfigFile
);
649 if(strcmp(df
,"e") == 0)
650 debuga(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
651 if(strcmp(df
,"u") == 0)
652 debuga(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
653 if(strcmp(df
,"w") == 0)
654 debuga(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
655 debuga(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
656 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
657 debuga(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
658 for (iarq
=0 ; iarq
<NRedirectorLogs
; iarq
++)
659 debuga(_(" Redirector log (-L) = %s\n"),RedirectorLogs
[iarq
]);
660 debuga(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
661 debuga(_(" Output dir (-o) = %s\n"),outdir
);
662 debuga(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
663 debuga(_(" Accessed site (-s) = %s\n"),site
);
664 debuga(_(" Time (-t) = %s\n"),hm_str
);
665 debuga(_(" User (-u) = %s\n"),us
);
666 debuga(_(" Temporary dir (-w) = %s\n"),tmp
);
667 debuga(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
668 debuga(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
673 printf(_("Parameters:\n"));
674 printf(_(" Hostname or IP address (-a) = %s\n"),addr
);
675 printf(_(" Useragent log (-b) = %s\n"),uagent
);
676 printf(_(" Exclude file (-c) = %s\n"),hexclude
);
677 printf(_(" Date from-until (-d) = %s\n"),date
);
678 printf(_(" Email address to send reports (-e) = %s\n"),email
);
679 printf(_(" Config file (-f) = %s\n"),ConfigFile
);
680 if(strcmp(df
,"e") == 0)
681 printf(_(" Date format (-g) = Europe (dd/mm/yyyy)\n"));
682 if(strcmp(df
,"u") == 0)
683 printf(_(" Date format (-g) = USA (mm/dd/yyyy)\n"));
684 if(strcmp(df
,"w") == 0)
685 printf(_(" Date format (-g) = Sites & Users (yyyy/ww)\n"));
686 printf(_(" IP report (-i) = %s\n"),(iprel
) ? _("Yes") : _("No"));
687 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
688 printf(_(" Input log (-l) = %s\n"),AccessLog
[iarq
]);
689 for (iarq
=0 ; iarq
<NRedirectorLogs
; iarq
++)
690 printf(_(" Redirector log (-L) = %s\n"),RedirectorLogs
[iarq
]);
691 printf(_(" Resolve IP Address (-n) = %s\n"),(Ip2Name
) ? _("Yes") : _("No"));
692 printf(_(" Output dir (-o) = %s\n"),outdir
);
693 printf(_("Use Ip Address instead of userid (-p) = %s\n"),(UserIp
) ? _("Yes") : _("No"));
694 printf(_(" Accessed site (-s) = %s\n"),site
);
695 printf(_(" Time (-t) = %s\n"),hm_str
);
696 printf(_(" User (-u) = %s\n"),us
);
697 printf(_(" Temporary dir (-w) = %s\n"),tmp
);
698 printf(_(" Debug messages (-x) = %s\n"),(debug
) ? _("Yes") : _("No"));
699 printf(_(" Process messages (-z) = %s\n"),(debugz
) ? _("Yes") : _("No"));
700 printf(_("sarg version: %s\n"),VERSION
);
704 debuga(_("sarg version: %s\n"),VERSION
);
706 #ifdef ENABLE_DOUBLE_CHECK_DATA
707 debuga(_("Sarg compiled to report warnings if the output is inconsistent\n"));
710 maxopenfiles
=MAX_OPEN_USER_FILES
;
712 if (Ulimit
[0] != '\0') {
717 #if defined(RLIMIT_NOFILE)
718 getrlimit (RLIMIT_NOFILE
, &rl
);
719 #elif defined(RLIMIT_OFILE)
720 getrlimit (RLIMIT_OFILE
, &rl
);
722 #warning "No rlimit resource for the number of open files"
727 rl
.rlim_cur
= atol(Ulimit
);
728 rl
.rlim_max
= atol(Ulimit
);
729 #if defined(RLIMIT_NOFILE)
730 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
731 #elif defined(RLIMIT_OFILE)
732 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
734 #warning "No rlimit resource for the number of open files"
737 debuga(_("setrlimit error - %s\n"),strerror(errno
));
741 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
745 init_usertab(UserTabFile
);
747 if ((line
=longline_create())==NULL
) {
748 debuga(_("Not enough memory to read a log file\n"));
752 snprintf(sz_Download_Unsort
,sizeof(sz_Download_Unsort
),"%s/download.unsort", tmp
);
754 if(DataFile
[0]=='\0') {
755 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
756 if((fp_denied
=MY_FOPEN(denied_unsort
,"w"))==NULL
) {
757 debuga(_("(log) Cannot open file: %s - %s\n"),denied_unsort
,strerror(errno
));
762 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
763 if((fp_authfail
=MY_FOPEN(authfail_unsort
,"w"))==NULL
) {
764 debuga(_("(log) Cannot open file: %s - %s\n"),authfail_unsort
,strerror(errno
));
770 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
771 strcpy(arq
,AccessLog
[iarq
]);
775 if(strcmp(arq
,"-")==0) {
777 debuga(_("Reading access log file: from stdin\n"));
782 if (stat(arq
,&logstat
)!=0) {
783 debuga(_("Cannot get the modification time of input log file %s (%s). Processing it anyway\n"),arq
,strerror(errno
));
785 struct tm
*logtime
=localtime(&logstat
.st_mtime
);
786 if ((logtime
->tm_year
+1900)*10000+(logtime
->tm_mon
+1)*100+logtime
->tm_mday
<dfrom
) {
787 debuga(_("Ignoring old log file %s\n"),arq
);
792 fp_in
=decomp(arq
,&from_pipe
);
794 debuga(_("(log) Cannot open log file: %s - %s\n"),arq
,strerror(errno
));
797 if(debug
) debuga(_("Reading access log file: %s\n"),arq
);
802 // pre-read the file only if we have to show stats
803 if(ShowReadStatistics
&& !from_stdin
&& !from_pipe
) {
811 while ((nread
=fread(tmp4
,1,sizeof(tmp4
),fp_in
))>0) {
812 for (i
=0 ; i
<nread
; i
++)
814 if (tmp4
[i
]!='\n' && tmp4
[i
]!='\r') {
818 if (tmp4
[i
]=='\n' || tmp4
[i
]=='\r') {
825 printf(_("SARG: Records in file: %lu, reading: %3.2f%%"),recs1
,(float) 0);
830 longline_reset(line
);
832 while ((linebuf
=longline_read(fp_in
,line
))!=NULL
) {
833 blen
=strlen(linebuf
);
835 if (ilf
==ILF_Unknown
) {
836 if(strncmp(linebuf
,"#Software: Mic",14) == 0) {
837 fixendofline(linebuf
);
839 debuga(_("Log is from Microsoft ISA: %s\n"),linebuf
);
845 if(strncmp(linebuf
,"*** SARG Log ***",16) == 0) {
846 if (getperiod_fromsarglog(arqtt
,&period
)<0) {
847 debuga(_("The name of the file is invalid: %s\n"),arq
);
856 if(!fp_log
&& strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
857 if(access(ParsedOutputLog
,R_OK
) != 0) {
858 my_mkdir(ParsedOutputLog
);
860 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
861 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
862 debuga(_("(log) Cannot open log file: %s - %s\n"),arq_log
,strerror(errno
));
865 fputs("*** SARG Log ***\n",fp_log
);
869 if( ShowReadStatistics
&& !from_stdin
&& !from_pipe
&& --OutputNonZero
<=0) {
870 double perc
= recs2
* 100. / recs1
;
871 printf(_("SARG: Records in file: %lu, reading: %3.2lf%%"),recs2
,perc
);
874 OutputNonZero
= REPORT_EVERY_X_LINES
;
876 if(blen
< 58) continue;
877 if(strstr(linebuf
,"HTTP/0.0") != 0) continue;
878 if(strstr(linebuf
,"logfile turned over") != 0) continue;
879 if(linebuf
[0] == ' ') continue;
882 if(ExcludeString
[0] != '\0') {
884 getword_start(&gwarea
,ExcludeString
);
885 while(strchr(gwarea
.current
,':') != 0) {
886 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
887 debuga(_("Maybe you have a broken record or garbage in your exclusion string\n"));
890 if((str
=(char *) strstr(linebuf
,val1
)) != (char *) NULL
) {
895 if(!exstring
&& (str
=(char *) strstr(linebuf
,gwarea
.current
)) != (char *) NULL
)
897 if(exstring
) continue;
902 printf("BUF=%s\n",linebuf
);
905 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
906 getword_start(&gwarea
,linebuf
);
907 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
908 debuga(_("Maybe you have a broken time in your access.log file\n"));
911 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
&& (str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
915 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
916 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
920 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
921 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
925 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
926 getword(fun
,sizeof(fun
),&gwarea
,' ')<0) {
927 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
930 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0) {
931 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
934 if (getword_skip(MAXLEN
,&gwarea
,' ')<0) {
935 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
938 if (getword(code2
,sizeof(code2
),&gwarea
,' ')<0) {
939 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
942 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
943 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
946 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
947 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
948 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
952 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
953 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
958 if ((str
= strchr(code
, ':')) != NULL
)
961 if(strcmp(tam
,"\0") == 0)
967 getword_start(&gwarea
,data
+1);
968 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
969 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
972 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
973 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
976 getword_start(&gwarea
,data
);
977 if (getword_atoll(&iday
,&gwarea
,'/')<0){
978 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
981 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
982 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
985 if (getword_atoll(&iyear
,&gwarea
,'/')<0){
986 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
990 imonth
=month2num(mes
)+1;
991 idata
=builddia(iday
,imonth
,iyear
);
992 computedate(iyear
,imonth
,iday
,&tt
);
996 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
997 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
998 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
1001 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
1002 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
1003 debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq
);
1006 if(strlen(elap
) < 1) continue;
1007 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
1008 debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq
);
1011 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
1012 debuga(_("Maybe you have a broken result code in your %s file\n"),arq
);
1015 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
1016 debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq
);
1019 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
1020 debuga(_("Maybe you have a broken request method in your %s file\n"),arq
);
1023 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0){
1024 debuga(_("Maybe you have a broken url in your %s file\n"),arq
);
1027 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
1028 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
1037 debuga(_("Cannot convert the timestamp from the squid log file\n"));
1041 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1043 idata
=(t
->tm_year
+1900)*10000+(t
->tm_mon
+1)*100+t
->tm_mday
;
1046 if (ilf
==ILF_Sarg
) {
1047 getword_start(&gwarea
,linebuf
);
1048 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0){
1049 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1052 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
1053 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1056 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
1057 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1060 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
1061 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1064 if (getword_ptr(linebuf
,&url
,&gwarea
,'\t')<0){
1065 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1068 if (getword(tam
,sizeof(tam
),&gwarea
,'\t')<0){
1069 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1072 if (getword(code
,sizeof(code
),&gwarea
,'\t')<0){
1073 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1076 if (getword(elap
,sizeof(elap
),&gwarea
,'\t')<0){
1077 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1080 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,'\0')<0){
1081 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1084 getword_start(&gwarea
,data
);
1085 if (getword_atoll(&iday
,&gwarea
,'/')<0 || iday
<1 || iday
>31){
1086 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1089 if (getword_atoll(&imonth
,&gwarea
,'/')<0 || imonth
<1 || imonth
>12){
1090 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1093 if (getword_atoll(&iyear
,&gwarea
,'\0')<0){
1094 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1097 idata
=builddia(iday
,imonth
,iyear
);
1098 computedate(iyear
,imonth
,iday
,&tt
);
1102 if (linebuf
[0] == '#') {
1103 int ncols
,cols
[ISACOL_Last
];
1105 fixendofline(linebuf
);
1106 getword_start(&gwarea
,linebuf
);
1107 // remove the #Fields: column at the beginning of the line
1108 if (getword_skip(1000,&gwarea
,' ')<0){
1109 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1112 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
1114 while(gwarea
.current
[0] != '\0') {
1115 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
1116 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1119 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
1120 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
1121 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
1122 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
1123 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
1124 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
1125 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
1126 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
1129 if (cols
[ISACOL_Ip
]>=0) {
1131 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++)
1132 isa_cols
[ncols
]=cols
[ncols
];
1136 if (!isa_ncols
) continue;
1137 getword_start(&gwarea
,linebuf
);
1138 for (x
=0 ; x
<isa_ncols
; x
++) {
1139 if (getword_ptr(linebuf
,&str
,&gwarea
,'\t')<0) {
1140 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq
);
1143 if (x
==isa_cols
[ISACOL_Ip
]) {
1144 if (strlen(str
)>=sizeof(ip
)) {
1145 debuga(_("Maybe you have a broken IP in your %s file\n"),arq
);
1149 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1150 if (strlen(str
)>=sizeof(user
)) {
1151 debuga(_("Maybe you have a broken user ID in your %s file\n"),arq
);
1155 } else if (x
==isa_cols
[ISACOL_Date
]) {
1156 if (strlen(str
)>=sizeof(data
)) {
1157 debuga(_("Maybe you have a broken date in your %s file\n"),arq
);
1161 } else if (x
==isa_cols
[ISACOL_Time
]) {
1162 if (strlen(str
)>=sizeof(hora
)) {
1163 debuga(_("Maybe you have a broken time in your %s file\n"),arq
);
1167 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1168 if (strlen(str
)>=sizeof(elap
)) {
1169 debuga(_("Maybe you have a broken download duration in your %s file\n"),arq
);
1173 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1174 if (strlen(str
)>=sizeof(tam
)) {
1175 debuga(_("Maybe you have a broken download size in your %s file\n"),arq
);
1179 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1181 } else if (x
==isa_cols
[ISACOL_Status
]) {
1182 if (strlen(str
)>=sizeof(code
)) {
1183 debuga(_("Maybe you have a broken access code in your %s file\n"),arq
);
1190 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1191 sprintf(val1
,"DENIED/%s",code
);
1194 getword_start(&gwarea
,data
);
1195 if (getword_atoll(&iyear
,&gwarea
,'-')<0){
1196 debuga(_("Maybe you have a broken year in your %s file\n"),arq
);
1199 if (getword_atoll(&imonth
,&gwarea
,'-')<0){
1200 debuga(_("Maybe you have a broken month in your %s file\n"),arq
);
1203 if (getword_atoll(&iday
,&gwarea
,'\0')<0){
1204 debuga(_("Maybe you have a broken day in your %s file\n"),arq
);
1208 idata
=builddia(iday
,imonth
,iyear
);
1209 computedate(iyear
,imonth
,iday
,&tt
);
1213 debuga(_("Unknown input log file format\n"));
1217 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1218 snprintf(hora
,sizeof(hora
),"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1221 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1223 if(date
[0] != '\0'){
1224 if(idata
< dfrom
|| idata
> duntil
) continue;
1227 // Record only hours usage which is required
1229 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
1230 sizeof( int ), compar
) == NULL
)
1233 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
1234 sizeof( int ), compar
) == NULL
)
1239 if(strlen(user
) > MAX_USER_LEN
) {
1240 if (debugm
) printf(_("User ID too long: %s\n"),user
);
1246 if(IncludeUsers
[0] != '\0') {
1247 sprintf(val1
,":%s:",user
);
1248 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1253 if (debugm
) printf(_("Excluded code: %s\n"),code
);
1258 if(testvaliduserchar(user
))
1262 if((str
= strstr(user
,"%20")) != NULL
) {
1264 This is a patch introduced to solve bug #1624251 reported at sourceforge but
1265 the side effect is to truncate the name at the first space and merge the reports
1266 of people whose name is identical up to the first space.
1268 The old code used to truncate the user name at the first % if a %20 was
1269 found anywhere in the string. That means the string could be truncated
1270 at the wrong place if another % occured before the %20. This new code should
1271 avoid that problem and only truncate at the space. There is no bug
1272 report indicating that anybody noticed this.
1278 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1279 found in the user name.
1281 while((str
= strstr(user
,"%5c")) != NULL
) {
1283 for (x
=3 ; str
[x
] ; x
++) str
[x
-2]=str
[x
];
1291 The full URL is not saved in sarg log. There is no point in testing the URL to detect
1294 download_flag
=is_download_suffix(url
);
1295 if (download_flag
) {
1300 download_flag
=false;
1302 // remove any protocol:// at the beginning of the URL
1303 if ((str
= strchr(url
,'/')) != NULL
&& str
[1] == '/') {
1307 for (i
=0 ; str
[i
] ; i
++)
1313 url_hostname(url
,hostname
,sizeof(hostname
));
1317 if(url
[0] == '\0') continue;
1319 if(addr
[0] != '\0'){
1320 if(strcmp(addr
,ip
)!=0) continue;
1323 if(!vhexclude(url
)) {
1324 if (debugm
) printf(_("Excluded site: %s\n"),url
);
1330 if(hm
>= 0 && hmf
>= 0) {
1331 hmr
=t
->tm_hour
*100+t
->tm_min
;
1332 if(hmr
< hm
|| hmr
> hmf
) continue;
1335 if(site
[0] != '\0'){
1336 if(strstr(url
,site
)==0) continue;
1344 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1345 if(RecordsWithoutUser
== RECORDWITHOUTUSER_IP
) {
1349 if(RecordsWithoutUser
== RECORDWITHOUTUSER_IGNORE
)
1351 if(RecordsWithoutUser
== RECORDWITHOUTUSER_EVERYBODY
)
1352 strcpy(user
,"everybody");
1355 if(NtlmUserFormat
== NTLMUSERFORMAT_USER
) {
1356 if((str
= strchr(user
,'_')) != 0) {
1357 strcpy(warea
,str
+1);
1360 if((str
= strchr(user
,'+')) != 0) {
1361 strcpy(warea
,str
+1);
1369 if(strcmp(user
,us
)!=0) continue;
1373 sprintf(wuser
,":%s:",user
);
1374 if(strstr(userfile
, wuser
) == 0)
1379 if(!vuexclude(user
)) {
1380 if (debugm
) printf(_("Excluded user: %s\n"),user
);
1386 if(strcmp(user
,"-") ==0 || strcmp(user
," ") ==0 || strcmp(user
,"") ==0 || strcmp(user
,":") ==0)
1390 if(atol(elap
)>max_elapsed
) {
1396 if((str
=(char *) strstr(linebuf
, "[SmartFilter:")) != (char *) NULL
) {
1398 sprintf(smartfilter
,"\"%s\"",str
+1);
1399 } else sprintf(smartfilter
,"\"\"");
1403 for (ufile
=first_user_file
; ufile
&& strcmp(user
,ufile
->user
->id
)!=0 ; ufile
=ufile
->next
) {
1405 if (ufile
->file
) nopen
++;
1408 ufile
=malloc(sizeof(*ufile
));
1410 debuga(_("Not enough memory to store the user %s\n"),user
);
1413 memset(ufile
,0,sizeof(*ufile
));
1414 ufile
->next
=first_user_file
;
1415 first_user_file
=ufile
;
1416 uinfo
=userinfo_create(user
);
1418 uinfo
->id_is_ip
=id_is_ip
;
1421 prev_ufile
->next
=ufile
->next
;
1422 ufile
->next
=first_user_file
;
1423 first_user_file
=ufile
;
1427 if (ufile
->file
==NULL
) {
1428 if (nopen
>=maxopenfiles
) {
1430 for (ufile1
=first_user_file
; ufile1
; ufile1
=ufile1
->next
) {
1431 if (ufile1
->file
!=NULL
) {
1432 if (x
>=maxopenfiles
) {
1433 if (fclose(ufile1
->file
)==EOF
) {
1434 debuga(_("Failed to close the log file of user %s - %s\n"),ufile1
->user
->id
,strerror(errno
));
1443 if (snprintf (tmp3
, sizeof(tmp3
), "%s/%s.unsort", tmp
, ufile
->user
->filename
)>=sizeof(tmp3
)) {
1444 debuga(_("Temporary user file name too long: %s/%s.unsort\n"), tmp
, ufile
->user
->filename
);
1447 if ((ufile
->file
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1448 debuga(_("(log) Cannot open temporary file: %s - %s\n"), tmp3
, strerror(errno
));
1453 /*if ( strcmp ( user , sz_Last_User ) != 0 ) {
1454 if ( fp_Write_User )
1455 fclose( fp_Write_User ) ;
1456 sprintf (tmp3, "%s/%s.unsort", tmp, user);
1458 if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) {
1459 fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], _("Cannot open temporary file"), tmp3, strerror(errno));
1462 strcpy( sz_Last_User , user ) ;
1464 if (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
)<=0) {
1465 debuga(_("Write error in the log file of user %s\n"),user
);
1469 if(fp_log
&& ilf
!=ILF_Sarg
)
1470 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
);
1474 if(!dataonly
&& download_flag
&& download_url
&& strstr(code
,"DENIED") == 0) {
1477 if ( ! fp_Download_Unsort
) {
1478 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1479 debuga(_("(log) Cannot open temporary file: %s - %s\n"),sz_Download_Unsort
, strerror(errno
));
1483 fprintf(fp_Download_Unsort
,"%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,download_url
);
1486 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
1487 if(fp_denied
&& strstr(code
,"DENIED/403") != 0) {
1488 fprintf(fp_denied
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1491 if(fp_authfail
&& (strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0)) {
1492 fprintf(fp_authfail
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1497 if (ilf
!=ILF_Sarg
) {
1498 if(!totper
|| idata
<mindate
){
1500 memcpy(&period
.start
,t
,sizeof(*t
));
1501 strcpy(start_hour
,tbuf2
);
1503 if (!totper
|| idata
>maxdate
) {
1505 memcpy(&period
.end
,t
,sizeof(*t
));
1511 printf("IP=\t%s\n",ip
);
1512 printf("USER=\t%s\n",user
);
1513 printf("ELAP=\t%s\n",elap
);
1514 printf("DATE=\t%s\n",dia
);
1515 printf("TIME=\t%s\n",hora
);
1516 printf("FUNC=\t%s\n",fun
);
1517 printf("URL=\t%s\n",url
);
1518 printf("CODE=\t%s\n",code
);
1519 printf("LEN=\t%s\n",tam
);
1527 if( ShowReadStatistics
)
1528 printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs1
, (float) 100 );
1534 debuga(_(" Records read: %ld, written: %ld, excluded: %ld\n"),totregsl
,totregsg
,totregsx
);
1536 longline_destroy(&line
);
1537 if ( fp_Download_Unsort
)
1538 fclose (fp_Download_Unsort
);
1540 for (ufile
=first_user_file
; ufile
; ufile
=ufile1
) {
1542 if (ufile
->file
!=NULL
) fclose(ufile
->file
);
1547 free_excludecodes();
1553 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1555 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1556 debuga(_("Log with mixed records format (squid and common log)\n"));
1558 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1559 debuga(_("Common log format\n"));
1561 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1562 debuga(_("Squid log format\n"));
1564 if(ilf_count
[ILF_Sarg
]>0)
1565 debuga(_("Sarg log format\n"));
1567 if(totalcount
==0 && totregsg
)
1568 debuga(_("Log with invalid format\n"));
1572 debuga(_("No records found\n"));
1574 if(fp_denied
) fclose(fp_denied
);
1575 if(fp_authfail
) fclose(fp_authfail
);
1577 if(userfile
) free(userfile
);
1582 if (date
[0]!='\0') {
1583 char date0
[30], date1
[30];
1585 strftime(date0
,sizeof(date0
),"%d/%m/%Y",&period
.start
);
1586 strftime(date1
,sizeof(date1
),"%d/%m/%Y",&period
.end
);
1587 debuga(_("Period covered by log files: %s-%s\n"),date0
,date1
);
1588 getperiod_fromrange(&period
,dfrom
,duntil
);
1590 if (getperiod_buildtext(&period
)<0) {
1591 debuga(_("Failed to build the string representation of the date range\n"));
1596 debugaz("data",dia
);
1597 debugaz("period",period
.text
);
1601 debuga(_("Period: %s\n"),period
.text
);
1607 fclose(fp_authfail
);
1609 if(fp_log
!= NULL
) {
1611 strcpy(end_hour
,tbuf2
);
1612 strftime(val2
,sizeof(val2
),"%d%m%Y",&period
.start
);
1613 strftime(val1
,sizeof(val1
),"%d%m%Y",&period
.end
);
1614 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,start_hour
,val1
,end_hour
);
1615 if (rename(arq_log
,val4
)) {
1616 debuga(_("failed to rename %s to %s - %s\n"),arq_log
,val4
,strerror(errno
));
1618 strcpy(arq_log
,val4
);
1620 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0 && ParsedOutputLogCompress
[0] != '\0') {
1622 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1623 necessary around the command name, put them in the configuration file.
1625 sprintf(val1
,"%s \"%s\"",ParsedOutputLogCompress
,arq_log
);
1626 cstatus
=system(val1
);
1627 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1628 debuga(_("command return status %d\n"),WEXITSTATUS(cstatus
));
1629 debuga(_("command: %s\n"),val1
);
1635 debuga(_("Sarg parsed log saved as %s\n"),arq_log
);
1638 if(DataFile
[0] == '\0' && (ReportType
& REPORT_TYPE_DENIED
) != 0) {
1639 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,denied_sort
,denied_unsort
);
1640 cstatus
=system(csort
);
1641 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1642 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
1643 debuga(_("sort command: %s\n"),csort
);
1646 unlink(denied_unsort
);
1649 sort_users_log(tmp
, debug
);
1651 if(DataFile
[0] != '\0')
1656 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1657 unlink(denied_sort
);
1659 if(strcmp(tmp
,"/tmp") != 0) {
1676 static void getusers(const char *pwdfile
, int debug
)
1685 debuga(_("Loading password file from %s\n"),pwdfile
);
1687 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1688 debuga(_("(getusers) Cannot open file %s - %s\n"),pwdfile
,strerror(errno
));
1692 if (fseek(fp_usr
, 0, SEEK_END
)==-1) {
1693 debuga(_("Failed to move till the end of the users file %s: %s\n"),pwdfile
,strerror(errno
));
1696 nreg
= ftell(fp_usr
);
1698 debuga(_("Cannot get the size of file %s\n"),pwdfile
);
1702 if (fseek(fp_usr
, 0, SEEK_SET
)==-1) {
1703 debuga(_("Failed to rewind the users file %s: %s\n"),pwdfile
,strerror(errno
));
1707 if((userfile
=(char *) malloc(nreg
))==NULL
){
1708 debuga(_("malloc error (%ld)\n"),nreg
);
1712 bzero(userfile
,nreg
);
1713 strcpy(userfile
,":");
1715 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1716 str
=strchr(buf
,':');
1718 debuga(_("You have an invalid user in your %s file\n"),pwdfile
);
1722 strcat(userfile
,buf
);