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
35 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
36 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
37 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
39 static void getusers(const char *pwdfile
, int debug
);
41 int main(int argc
,char *argv
[])
52 ISACOL_Last
//last entry of the list !
60 ILF_Last
//last entry of the list !
63 FILE *fp_in
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
65 char sz_Download_Unsort
[ 20000 ] ;
66 FILE * fp_Download_Unsort
= NULL
;
67 FILE * fp_Write_User
= NULL
;
79 char smartfilter
[MAXLEN
];
90 char hm
[15], hmf
[15], hmr
[15];
93 char hexclude
[MAXLEN
];
103 char start_hour
[128];
105 enum InputLogFormat ilf
;
106 int ilf_count
[ILF_Last
];
118 int isa_ncols
=0,isa_cols
[ISACOL_Last
];
124 long int max_elapsed
=0;
127 unsigned long recs1
=0UL;
128 unsigned long recs2
=0UL;
129 int OutputNonZero
= REPORT_EVERY_X_LINES
;
131 char download_url
[MAXLEN
];
132 char sz_Last_User
[MAXLEN
]="";
133 struct getwordstruct gwarea
;
140 UserAgentLog
[0]='\0';
141 ExcludeHosts
[0]='\0';
142 ExcludeUsers
[0]='\0';
149 ExternalCSSFile
[0]='\0';
150 SquidGuardLogFormat
[0]='\0';
151 SquidGuardLogAlternate
[0]='\0';
152 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
154 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
155 strcpy(GraphDaysBytesBarColor
,"orange");
156 strcpy(BgColor
,"#ffffff");
157 strcpy(TxColor
,"#000000");
158 strcpy(TxBgColor
,"lavender");
159 strcpy(TiColor
,"darkblue");
162 strcpy(LogoTextColor
,"#000000");
163 strcpy(HeaderColor
,"darkblue");
164 strcpy(HeaderBgColor
,"#dddddd");
165 strcpy(LogoTextColor
,"#006699");
166 strcpy(FontSize
,"9px");
167 strcpy(TempDir
,"/tmp");
168 strcpy(OutputDir
,"/var/www/html/squid-reports");
170 strcpy(DateFormat
,"u");
173 strcpy(ReplaceIndex
,"index.html");
175 strcpy(RecordsWithoutUser
,"ip");
177 strcpy(MailUtility
,"mailx");
178 strcpy(TopSitesNum
,"100");
180 strcpy(TopuserSortField
,"BYTES");
181 strcpy(UserSortField
,"BYTES");
182 strcpy(TopuserSortOrder
,"reverse");
183 strcpy(UserSortOrder
,"reverse");
184 strcpy(TopsitesSortField
,"CONNECT");
185 strcpy(TopsitesSortType
,"D");
187 strcpy(language
,"English");
188 strcpy(FontFace
,"Verdana,Tahoma,Arial");
189 strcpy(datetimeby
,"elap");
190 strcpy(CharSet
,"ISO-8859-1");
192 strcpy(PrivacyString
,"***.***.***.***");
193 strcpy(PrivacyStringColor
,"blue");
195 TopUserFields
=TOPUSERFIELDS_NUM
| TOPUSERFIELDS_DATE_TIME
| TOPUSERFIELDS_USERID
| TOPUSERFIELDS_CONNECT
|
196 TOPUSERFIELDS_BYTES
| TOPUSERFIELDS_SETYB
| TOPUSERFIELDS_IN_CACHE_OUT
|
197 TOPUSERFIELDS_USED_TIME
| TOPUSERFIELDS_MILISEC
| TOPUSERFIELDS_PTIME
|
198 TOPUSERFIELDS_TOTAL
| TOPUSERFIELDS_AVERAGE
;
199 UserReportFields
=USERREPORTFIELDS_CONNECT
| USERREPORTFIELDS_BYTES
| USERREPORTFIELDS_SETYB
|
200 USERREPORTFIELDS_IN_CACHE_OUT
| USERREPORTFIELDS_USED_TIME
| USERREPORTFIELDS_MILISEC
|
201 USERREPORTFIELDS_PTIME
| USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
;
202 strcpy(DataFileDelimiter
,";");
203 DataFileFields
=DATA_FIELD_USER
| DATA_FIELD_DATE
| DATA_FIELD_TIME
| DATA_FIELD_URL
| DATA_FIELD_CONNECT
|
204 DATA_FIELD_BYTES
| DATA_FIELD_IN_CACHE
| DATA_FIELD_OUT_CACHE
| DATA_FIELD_ELAPSED
;
205 strcpy(SiteUserTimeDateType
,"table");
206 ShowReadStatistics
=1;
207 strcpy(IndexSortOrder
,"D");
210 strcpy(ParsedOutputLog
,"no");
211 strcpy(ParsedOutputLogCompress
,"/bin/gzip -f");
212 strcpy(DisplayedValues
,"abbreviation");
213 strcpy(HeaderFontSize
,"9px");
214 strcpy(TitleFontSize
,"11px");
215 strcpy(AuthUserFile
,"/usr/local/sarg/passwd");
216 strcpy(AuthName
,"SARG, Restricted Access");
217 strcpy(AuthType
,"basic");
218 strcpy(Require
,"require user admin %u");
219 set_download_suffix("7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip");
221 strcpy(Ulimit
,"20000");
222 strcpy(NtlmUserFormat
,"domainname+username");
223 IndexTree
=INDEX_TREE_FILE
;
224 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
225 strcpy(RealtimeUnauthRec
,"show");
226 SquidguardIgnoreDate
=0;
227 DansguardianIgnoreDate
=0;
228 strcpy(DataFileUrl
,"ip");
229 strcpy(MaxElapsed
,"28800000");
230 BytesInSitesUsersReport
=0;
231 UserAuthentication
=0;
232 strcpy(LDAPHost
,"127.0.0.1");
234 LDAPProtocolVersion
=3;
237 LDAPBaseSearch
[0]='\0';
238 strcpy(LDAPFilterSearch
, "uid=%s");
239 strcpy(LDAPTargetAttr
, "cn");
263 UserInvalidChar
[0]='\0';
265 SquidGuardConf
[0]='\0';
266 DansGuardianConf
[0]='\0';
273 dansguardian_count
=0;
275 DeniedReportLimit
=10;
276 AuthfailReportLimit
=10;
277 DansGuardianReportLimit
=10;
278 SquidGuardReportLimit
=10;
279 DownloadReportLimit
=50;
292 realtime_access_log_lines
=1000;
298 bzero(IncludeUsers
, MAXLEN
);
299 bzero(ExcludeString
, MAXLEN
);
302 setlocale(LC_TIME
,"");
306 for(x
=0; x
<=MAXLOGS
; x
++)
307 AccessLog
[x
][0]='\0';
308 AccessLogFromCmdLine
=0;
310 language_load(language
);
311 strcpy(Title
,text
[88]);
313 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
320 strcpy(uagent
,optarg
);
323 strcpy(hexclude
,optarg
);
326 strncpy(date
,optarg
,sizeof(date
)-1);
327 date
[sizeof(date
)-1]='\0';
328 getword_start(&gwarea
,optarg
);
329 if (getword(cdfrom
,sizeof(cdfrom
),&gwarea
,'-')<0 || getword(cduntil
,sizeof(cduntil
),&gwarea
,0)<0) {
330 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
333 date_from(date
, cdfrom
, cduntil
);
335 duntil
=atoi(cduntil
);
338 strcpy(email
,optarg
);
341 strcpy(ConfigFile
,optarg
);
354 if (NAccessLog
>=MAXLOGS
) {
355 printf("SARG: Too many log files.\n");
358 strcpy(AccessLog
[NAccessLog
],optarg
);
360 AccessLogFromCmdLine
++;
363 strcpy(SquidGuardLogAlternate
,optarg
);
372 strcpy(outdir
,optarg
);
387 if(strstr(optarg
,"-") == 0) {
391 getword_start(&gwarea
,optarg
);
392 if (getword(hm
,sizeof(hm
),&gwarea
,'-')<0 || getword(hmf
,sizeof(hmf
),&gwarea
,0)<0) {
393 fprintf(stderr
,"SARG: Maybe you have a broken record or garbage in your time range.\n");
397 if(sscanf(hm
,"%d:%d",&h
,&m
)!=2) {
398 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
401 sprintf(hm
,"%02d%02d",h
,m
);
402 if(sscanf(hmf
,"%d:%d",&h
,&m
)!=2) {
403 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
406 sprintf(hmf
,"%02d%02d",h
,m
);
428 fprintf(stderr
, "Option -%c require an argument\n",optopt
);
444 if(debug
) debuga("Init");
446 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
447 if(access(ConfigFile
, R_OK
) != 0) {
448 debuga("Cannot open config file: %s - %s",ConfigFile
,strerror(errno
));
452 if(access(ConfigFile
, R_OK
) == 0)
464 if(IndexTree
== INDEX_TREE_FILE
)
465 strcpy(ImageFile
,"../images");
467 strcpy(ImageFile
,"../../../images");
470 if(DataFile
[0] != '\0')
474 strcpy(AccessLog
[0],"/var/log/squid/access.log");
478 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
479 convlog(AccessLog
[0], df
, dfrom
, duntil
);
483 if(strcmp(site
,"plit") == 0) {
484 splitlog(AccessLog
[0], df
, dfrom
, duntil
, hexclude
);
488 load_excludecodes(ExcludeCodes
);
490 if(access(PasswdFile
, R_OK
) == 0) {
491 getusers(PasswdFile
,debug
);
495 if(hexclude
[0] == '\0')
496 strcpy(hexclude
,ExcludeHosts
);
497 if(hexclude
[0] != '\0') {
498 gethexclude(hexclude
,debug
);
502 if(ReportType
== 0) {
503 ReportType
=REPORT_TYPE_TOPUSERS
| REPORT_TYPE_TOPSITES
| REPORT_TYPE_USERS_SITES
|
504 REPORT_TYPE_SITES_USERS
| REPORT_TYPE_DATE_TIME
| REPORT_TYPE_DENIED
|
505 REPORT_TYPE_AUTH_FAILURES
| REPORT_TYPE_SITE_USER_TIME_DATE
| REPORT_TYPE_DOWNLOADS
;
508 if(access(ExcludeUsers
, R_OK
) == 0) {
509 getuexclude(ExcludeUsers
,debug
);
518 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
519 if(Index
== INDEX_ONLY
) indexonly
++;
521 if(MaxElapsed
[0] != '\0') max_elapsed
=atol(MaxElapsed
);
523 if(outdir
[0] == '\0') strcpy(outdir
,OutputDir
);
526 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
528 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
529 else strcpy(TempDir
,tmp
);
531 if(df
[0] == '\0') strcpy(df
,DateFormat
);
532 else strcpy(DateFormat
,df
);
536 strcpy(DateFormat
,"u");
539 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
543 if(email
[0] != '\0') {
544 sprintf(wtemp2
,"%s/sarg",tmp2
);
546 strcat(tmp2
,"/sarg");
551 strcat(tmp2
,"/sarg.log");
553 sprintf(tmp3
,"%s/sarg",tmp
);
554 if(access(tmp3
, R_OK
) == 0) {
561 strcat(tmp4
,"/denied.log.unsort");
562 strcat(tmp5
,"/denied.log");
563 strcat(tmp6
,"/authfail.log.unsort");
566 fprintf(stderr
, "SARG: %s:\nSARG:\n",text
[22]);
567 fprintf(stderr
, "SARG: %35s (-a) = %s\n",text
[23],addr
);
568 fprintf(stderr
, "SARG: %35s (-b) = %s\n",text
[71],uagent
);
569 fprintf(stderr
, "SARG: %35s (-c) = %s\n",text
[69],hexclude
);
570 fprintf(stderr
, "SARG: %35s (-d) = %s\n",text
[24],date
);
571 fprintf(stderr
, "SARG: %35s (-e) = %s\n",text
[41],email
);
572 fprintf(stderr
, "SARG: %35s (-f) = %s\n",text
[70],ConfigFile
);
573 if(strcmp(df
,"e") == 0)
574 fprintf(stderr
, "SARG: %35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
575 if(strcmp(df
,"u") == 0)
576 fprintf(stderr
, "SARG: %35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
577 if(strcmp(df
,"w") == 0)
578 fprintf(stderr
, "SARG: %35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
580 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[1]);
582 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[2]);
583 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
584 fprintf(stderr
, "SARG: %35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
586 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[1]);
588 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[2]);
589 fprintf(stderr
, "SARG: %35s (-o) = %s\n",text
[38],outdir
);
591 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[1]);
593 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[2]);
594 fprintf(stderr
, "SARG: %35s (-s) = %s\n",text
[30],site
);
595 fprintf(stderr
, "SARG: %35s (-t) = %s\n",text
[31],hm
);
596 fprintf(stderr
, "SARG: %35s (-u) = %s\n",text
[32],us
);
597 fprintf(stderr
, "SARG: %35s (-w) = %s\n",text
[34],tmp
);
599 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[1]);
601 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[2]);
603 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[1]);
605 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[2]);
606 fprintf(stderr
, "SARG:\n");
610 printf("%s:\nSARG:\n",text
[22]);
611 printf("%35s (-a) = %s\n",text
[23],addr
);
612 printf("%35s (-b) = %s\n",text
[71],uagent
);
613 printf("%35s (-c) = %s\n",text
[69],hexclude
);
614 printf("%35s (-d) = %s\n",text
[24],date
);
615 printf("%35s (-e) = %s\n",text
[41],email
);
616 printf("%35s (-f) = %s\n",text
[70],ConfigFile
);
617 if(strcmp(df
,"e") == 0)
618 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
619 if(strcmp(df
,"u") == 0)
620 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
621 if(strcmp(df
,"w") == 0)
622 printf("%35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
624 printf("%35s (-i) = %s\n",text
[28],text
[1]);
626 printf("%35s (-i) = %s\n",text
[28],text
[2]);
627 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
628 printf("%35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
630 printf("%35s (-n) = %s\n",text
[65],text
[1]);
632 printf("%35s (-n) = %s\n",text
[65],text
[2]);
633 printf("%35s (-o) = %s\n",text
[38],outdir
);
635 printf("%35s (-p) = %s\n",text
[29],text
[1]);
637 printf("%35s (-p) = %s\n",text
[29],text
[2]);
638 printf("%35s (-s) = %s\n",text
[30],site
);
639 printf("%35s (-t) = %s\n",text
[31],hm
);
640 printf("%35s (-u) = %s\n",text
[32],us
);
641 printf("%35s (-w) = %s\n",text
[34],tmp
);
643 printf("%35s (-x) = %s\n",text
[35],text
[1]);
645 printf("%35s (-x) = %s\n",text
[35],text
[2]);
647 printf("%35s (-z) = %s\n",text
[36],text
[1]);
649 printf("%35s (-z) = %s\n",text
[36],text
[2]);
650 printf("sarg %s: %s\n",text
[73],VERSION
);
651 printf("Language=%s\n\n",text
[3]);
655 debuga("sarg %s: %s",text
[73],VERSION
);
658 if (Ulimit
[0] != '\0') {
663 #if defined(RLIMIT_NOFILE)
664 getrlimit (RLIMIT_NOFILE
, &rl
);
665 #elif defined(RLIMIT_OFILE)
666 getrlimit (RLIMIT_OFILE
, &rl
);
668 #warning "No rlimit resource for the number of open files"
673 rl
.rlim_cur
= atol(Ulimit
);
674 rl
.rlim_max
= atol(Ulimit
);
675 #if defined(RLIMIT_NOFILE)
676 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
677 #elif defined(RLIMIT_OFILE)
678 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
680 #warning "No rlimit resource for the number of open files"
683 debuga("setrlimit error - %s\n",strerror(errno
));
687 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
691 init_usertab(UserTabFile
);
693 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
695 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
696 if((fp_denied
=MY_FOPEN(tmp4
,"w"))==NULL
) {
697 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp4
,strerror(errno
));
702 if(DataFile
[0]=='\0') {
703 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
704 if((fp_authfail
=MY_FOPEN(tmp6
,"w"))==NULL
) {
705 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp6
,strerror(errno
));
711 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
712 strcpy(arq
,AccessLog
[iarq
]);
716 if(strcmp(arq
,"-")==0) {
718 debuga("%s: %s",text
[7],"stdin");
724 debuga("%s: %s",text
[7],arq
);
725 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
726 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq
,strerror(errno
));
733 // pre-Read the file only if I have to show stats
734 if(ShowReadStatistics
&& !from_stdin
) {
739 while( fgets(bufz
,sizeof(bufz
),fp_in
) != NULL
) recs1
++;
741 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,(float) 0);
745 while(fgets(bufz
,sizeof(bufz
),fp_in
)!=NULL
) {
747 if (ilf
==ILF_Unknown
) {
748 if(strncmp(bufz
,"#Software: Mic",14) == 0) {
751 debuga("%s: %s",text
[143],bufz
);
757 if(strncmp(bufz
,"*** SARG Log ***",16) == 0) {
758 getword_start(&gwarea
,arqtt
);
759 if (getword_skip(2000,&gwarea
,'-')<0 || getword(val2
,sizeof(val2
),&gwarea
,'_')<0 ||
760 getword_skip(10,&gwarea
,'-')<0 || getword(val3
,sizeof(val3
),&gwarea
,'_')<0) {
761 printf("SARG: The name of the file is invalid: %s\n",arq
);
764 sprintf(period
,"%s-%s",val2
,val3
);
771 if(!fp_log
&& strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
772 if(access(ParsedOutputLog
,R_OK
) != 0) {
773 my_mkdir(ParsedOutputLog
);
775 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
776 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
777 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq_log
,strerror(errno
));
780 fputs("*** SARG Log ***\n",fp_log
);
784 if( ShowReadStatistics
&& !from_stdin
&& ! --OutputNonZero
) {
786 perc
= perc
/ recs1
;
787 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,perc
);
789 OutputNonZero
= REPORT_EVERY_X_LINES
;
791 if(strlen(bufz
) > MAXLEN
-1) continue;
792 if(!bufz
[0]) continue;
793 if(strstr(bufz
,"HTTP/0.0") != 0) continue;
794 if(strstr(bufz
,"logfile turned over") != 0) continue;
795 if(bufz
[0] == ' ') continue;
796 if(strlen(bufz
) < 58) continue;
798 // Record only hours usage which is required
799 tt
= (time_t) strtoul( bufz
, NULL
, 10 );
800 t
= localtime( &tt
);
802 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
803 sizeof( int ), compar
) == NULL
)
806 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
807 sizeof( int ), compar
) == NULL
)
812 if(ExcludeString
[0] != '\0') {
814 getword_start(&gwarea
,ExcludeString
);
815 while(strchr(gwarea
.current
,':') != 0) {
816 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
817 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
820 if((str
=(char *) strstr(warea
,val1
)) != (char *) NULL
)
823 if((str
=(char *) strstr(warea
,gwarea
.current
)) != (char *) NULL
)
826 if(exstring
) continue;
829 if ((str
= strchr(bufz
, '\n')) != NULL
)
830 *str
= '\0'; /* strip \n */
834 printf("BUF=%s\n",bufz
);
836 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
837 getword_start(&gwarea
,bufz
);
838 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
839 printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
842 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
) {
843 if((str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
847 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
848 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
852 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
853 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
857 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
858 getword(fun
,sizeof(fun
),&gwarea
,' ')<0 || getword(url
,sizeof(url
),&gwarea
,' ')<0 ||
859 getword_skip(MAXLEN
,&gwarea
,' ')<0 || getword(code2
,sizeof(code2
),&gwarea
,' ')<0 ||
860 getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
861 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
864 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
865 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
866 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
870 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
871 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
876 if ((str
= strchr(code
, ':')) != NULL
)
879 if(strcmp(tam
,"\0") == 0)
887 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
888 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
889 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
892 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
893 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
894 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
897 if(strlen(elap
) < 1) continue;
898 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
899 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
902 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
903 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
906 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
907 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
910 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
911 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
914 if (getword(url
,sizeof(url
),&gwarea
,' ')<0){
915 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
918 // while (strstr(bufz,"%20") != 0) {
919 // getword(warea,bufz,' ');
920 // strcat(url,warea);
922 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
923 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
931 getword_start(&gwarea
,bufz
);
932 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0){
933 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
936 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
937 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
940 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
941 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
944 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
945 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
948 if (getword(url
,sizeof(url
),&gwarea
,'\t')<0){
949 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
952 if (getword(tam
,sizeof(tam
),&gwarea
,'\t')<0){
953 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
956 if (getword(code
,sizeof(code
),&gwarea
,'\t')<0){
957 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
960 if (getword(elap
,sizeof(elap
),&gwarea
,'\t')<0){
961 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
964 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,'\0')<0){
965 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
970 if (bufz
[0] == '#') {
971 int ncols
,cols
[ISACOL_Last
];
974 getword_start(&gwarea
,bufz
);
975 // remove the #Fields: column at the beginning of the line
976 if (getword_skip(1000,&gwarea
,' ')<0){
977 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
980 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
982 while(gwarea
.current
[0] != '\0') {
983 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
984 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
987 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
988 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
989 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
990 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
991 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
992 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
993 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
994 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
997 if (cols
[ISACOL_Ip
]>=0) {
999 for (isa_ncols
=0 ; isa_ncols
<ncols
; isa_ncols
++)
1000 isa_cols
[isa_ncols
]=cols
[isa_ncols
];
1004 if (!isa_ncols
) continue;
1005 getword_start(&gwarea
,bufz
);
1006 for (x
=0 ; x
<isa_ncols
; x
++) {
1007 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0) {
1008 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1011 if (x
==isa_cols
[ISACOL_Ip
]) {
1012 if (strlen(val1
)>=sizeof(ip
)) {
1013 printf("SARG: Maybe you have a broken IP in your %s file.\n",arq
);
1017 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1018 if (strlen(val1
)>=sizeof(user
)) {
1019 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1023 } else if (x
==isa_cols
[ISACOL_Date
]) {
1024 if (strlen(val1
)>=sizeof(data
)) {
1025 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1029 } else if (x
==isa_cols
[ISACOL_Time
]) {
1030 if (strlen(val1
)>=sizeof(hora
)) {
1031 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1035 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1036 if (strlen(val1
)>=sizeof(elap
)) {
1037 printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq
);
1041 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1042 if (strlen(val1
)>=sizeof(tam
)) {
1043 printf("SARG: Maybe you have a broken download size in your %s file.\n",arq
);
1047 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1048 if (strlen(val1
)>=sizeof(url
)) {
1049 printf("SARG: Maybe you have a broken URL in your %s file.\n",arq
);
1053 } else if (x
==isa_cols
[ISACOL_Status
]) {
1054 if (strlen(val1
)>=sizeof(code
)) {
1055 printf("SARG: Maybe you have a broken access code in your %s file.\n",arq
);
1062 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1063 sprintf(val1
,"DENIED/%s",code
);
1066 getword_start(&gwarea
,data
);
1067 if (getword(ano
,sizeof(ano
),&gwarea
,'-')<0){
1068 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1071 if (getword(mes
,sizeof(mes
),&gwarea
,'-')<0){
1072 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1075 if (getword(dia
,sizeof(dia
),&gwarea
,'\0')<0){
1076 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1079 conv_month_name(mes
);
1080 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1083 if(strlen(user
) > 150) {
1084 if (debugm
) printf("User too long: %s\n",user
);
1090 if(IncludeUsers
[0] != '\0') {
1091 sprintf(val1
,":%s:",user
);
1092 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1097 if (debugm
) printf("Excluded code: %s\n",code
);
1102 if(testvaliduserchar(user
))
1106 if((str
= strstr(user
,"%20")) != NULL
) {
1108 This is a patch introduced to solve bug #1624251 reported at sourceforge but
1109 the side effect is to truncate the name at the first space and merge the reports
1110 of people whose name is identical up to the first space.
1112 The old code used to truncate the user name at the first % if a %20 was
1113 found anywhere in the string. That means the string could be truncated
1114 at the wrong place if another % occured before the %20. This new code should
1115 avoid that problem and only truncate at the space. There is no bug
1116 report indicating that anybody noticed this.
1122 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1123 found in the user name.
1125 while((str
= strstr(user
,"%5c")) != NULL
) {
1127 for (x
=3 ; str
[x
] ; x
++) str
[x
-2]=str
[x
];
1131 for(str
=user
; *str
; str
++) {
1132 if(*str
=='.') dotinuser
++;
1133 if(*str
=='?' || *str
=='.' || *str
==':' || *str
=='/' || *str
=='\\' || *str
=='\'' || *str
=='$' || *str
=='@' ||
1134 *str
=='\"' || *str
=='*')
1139 if(strncmp(NtlmUserFormat
,"user",4) == 0) {
1140 if((str
= strchr(user
,'_')) != 0) {
1141 strcpy(warea
,str
+1);
1144 if((str
= strchr(user
,'+')) != 0) {
1145 strcpy(warea
,str
+1);
1150 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1155 The full URL is not saved in sarg log. There is no point in testing the URL to detect
1158 download_flag
=is_download_suffix(url
);
1159 if (download_flag
) {
1160 strcpy(download_url
,url
);
1165 // remove any protocol:// at the beginning of the URL
1166 if ((str
= strchr(url
,'/')) != NULL
&& str
[1] == '/') {
1170 for (i
=0 ; str
[i
] ; i
++)
1176 char *endofhost
=strchr(url
,'/');
1179 if(strlen(url
) > 512 && (endofhost
=strchr(url
,'%')) != NULL
) {
1184 if(ilf
==ILF_Squid
) {
1188 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1189 sprintf(mes
,"%d",t
->tm_mon
+1);
1190 conv_month_name(mes
);
1191 if(strncmp(df
,"u",1) == 0)
1192 sprintf(tbuf
, "%04d%s%02d", t
->tm_year
+1900, mes
, t
->tm_mday
);
1193 if(strncmp(df
,"e",1) == 0)
1194 sprintf(tbuf
, "%02d%s%04d", t
->tm_mday
, mes
, t
->tm_year
+1900);
1195 if(strncmp(df
,"w",1) == 0) {
1196 IndexTree
=INDEX_TREE_FILE
;
1197 strftime(tbuf
, sizeof(tbuf
), "%Y.%U", t
);
1200 strftime(wdata
, sizeof(wdata
), "%Y%m%d", t
);
1203 if(strncmp(df
,"u",1)==0)
1204 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
1206 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1207 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1208 } else if(ilf
==ILF_Common
|| ilf
==ILF_Isa
) {
1209 getword_start(&gwarea
,data
+1);
1210 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
1211 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1214 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
1215 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1218 getword_start(&gwarea
,data
);
1219 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1220 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1223 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1224 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1227 if (getword(ano
,sizeof(ano
),&gwarea
,'/')<0){
1228 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1232 if(strcmp(df
,"u") == 0)
1233 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",ano
,mes
,dia
);
1234 if(strcmp(df
,"e") == 0)
1235 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",dia
,mes
,ano
);
1236 builddia(dia
,mes
,ano
,df
,wdata
);
1238 } else if (ilf
==ILF_Sarg
) {
1239 getword_start(&gwarea
,data
);
1240 if(strcmp(df
,"u") == 0) {
1241 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1242 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1245 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1246 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1250 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1251 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1254 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1255 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1259 if (getword(ano
,sizeof(ano
),&gwarea
,0)<0){
1260 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1263 snprintf(wdata
,9,"%s%s%s",ano
,mes
,dia
);
1268 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1272 if(addr
[0] != '\0'){
1273 if(strcmp(addr
,ip
)==0)
1280 if (debugm
) printf("Excluded site: %s\n",url
);
1287 if(date
[0] != '\0'){
1288 if(idata
>= dfrom
&& idata
<= duntil
)
1294 bzero(hmr
,sizeof(hmr
));
1296 getword_start(&gwarea
,hora
);
1298 if (getword_multisep(warea
,sizeof(warea
),&gwarea
,':')<0){
1299 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1302 strncat(hmr
,warea
,2);
1305 strncat(hmr
,gwarea
.current
,2);
1307 if(atoi(hmr
) >= atoi(hm
) && atoi(hmr
) <= atoi(hmf
))
1312 if(site
[0] != '\0'){
1313 if(strstr(url
,site
)!=0)
1321 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1322 if(strcmp(RecordsWithoutUser
,"ip") == 0)
1324 if(strcmp(RecordsWithoutUser
,"ignore") == 0)
1326 if(strcmp(RecordsWithoutUser
,"everybody") == 0)
1327 strcpy(user
,"everybody");
1330 if(strcmp(user
,us
)==0)
1337 subs(user
,sizeof(user
),"_",".");
1342 sprintf(wuser
,":%s:",user
);
1343 if(strstr(userfile
, wuser
) == 0)
1351 if (debugm
) printf("Excluded user: %s\n",user
);
1362 if(l
&& max_elapsed
) {
1363 if(atol(elap
)>max_elapsed
) {
1370 if(strcmp(user
,"-") !=0 && url
[0] != '\0' && strcmp(user
," ") !=0 && strcmp(user
,"") !=0 && strcmp(user
,":") !=0){
1371 if((str
=(char *) strstr(bufz
, "[SmartFilter:")) != (char *) NULL
) {
1373 sprintf(smartfilter
,"\"%s\"",str
+1);
1374 } else sprintf(smartfilter
,"\"\"");
1376 sprintf(bufz
, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,url
,tam
,code
,elap
,smartfilter
);
1378 if ( strcmp ( user
, sz_Last_User
) != 0 ) {
1379 if ( fp_Write_User
)
1380 fclose( fp_Write_User
) ;
1381 sprintf (tmp3
, "%s/sarg/%s.unsort", tmp
, user
);
1383 if ((fp_Write_User
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1384 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1387 strcpy( sz_Last_User
, user
) ;
1389 fputs (bufz
, fp_Write_User
);
1391 if(fp_log
&& ilf
!=ILF_Sarg
) fputs(bufz
,fp_log
);
1395 if(download_flag
&& strstr(code
,"DENIED") == 0) {
1398 if ( ! fp_Download_Unsort
) {
1399 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1400 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1404 fprintf(fp_Download_Unsort
,"%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,download_url
);
1407 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
1408 if(strstr(code
,"DENIED/403") != 0) {
1409 fprintf(fp_denied
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1412 if(strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0) {
1414 fprintf(fp_authfail
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1419 if((!totper
|| idata
<mindate
) && ilf
!=ILF_Sarg
){
1422 sprintf(period
,"%s-",tbuf
);
1423 strcpy(start_hour
,tbuf2
);
1425 fixper(tbuf
, period
, cduntil
);
1427 debugaz("tbuf",tbuf
);
1428 debugaz("period",period
);
1434 printf("IP=\t%s\n",ip
);
1435 printf("USER=\t%s\n",user
);
1436 printf("ELAP=\t%s\n",elap
);
1437 printf("DATE=\t%s\n",dia
);
1438 printf("TIME=\t%s\n",hora
);
1439 printf("FUNC=\t%s\n",fun
);
1440 printf("URL=\t%s\n",url
);
1441 printf("CODE=\t%s\n",code
);
1442 printf("LEN=\t%s\n",tam
);
1448 if( ShowReadStatistics
)
1449 printf("SARG: Records in file: %lu, reading: %3.2f%%\n",recs1
, (float) 100 );
1453 if ( fp_Download_Unsort
)
1454 fclose (fp_Download_Unsort
);
1457 fclose (fp_Write_User
);
1460 free_excludecodes();
1466 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1468 debuga(" %s: %ld, %s: %ld, %s: %ld",text
[10],totregsl
,text
[11],totregsg
,text
[68],totregsx
);
1470 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1471 debuga("%s",text
[12]);
1473 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1474 debuga("%s",text
[13]);
1476 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1477 debuga("%s",text
[14]);
1479 if(ilf_count
[ILF_Sarg
]>0)
1480 debuga("%s",text
[124]);
1484 fprintf(stderr
, "SARG: %s\n",text
[16]);
1485 fprintf(stderr
, "SARG: %s\n",text
[21]);
1486 } else fprintf(stderr
, "SARG: %s\n",text
[15]);
1490 fclose(fp_authfail
);
1492 //// free(userfile);
1501 fprintf(stderr
, "SARG: %s\n",text
[16]);
1502 fprintf(stderr
, "SARG: %s\n",text
[21]);
1507 fclose(fp_authfail
);
1513 if(date
[0] == '\0' && ilf_count
[ILF_Sarg
]==0) {
1514 strcat(period
,tbuf
);
1518 debugaz("data",dia
);
1519 debugaz("tbuf",tbuf
);
1520 debugaz("period",period
);
1524 debuga("%s: %s",text
[17],period
);
1530 fclose(fp_authfail
);
1532 if(fp_log
!= NULL
) {
1534 strcpy(end_hour
,tbuf2
);
1535 getword_start(&gwarea
,period
);
1536 if (getword(val2
,sizeof(val2
),&gwarea
,'-')<0){
1537 printf("SARG: Maybe you have a broken date range definition.\n");
1540 if (getword(val1
,sizeof(val1
),&gwarea
,'\0')<0){
1541 printf("SARG: Maybe you have a broken date range definition.\n");
1544 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,start_hour
,val1
,end_hour
);
1545 if (rename(arq_log
,val4
)) {
1546 fprintf(stderr
,"SARG: failed to rename %s to %s - %s\n",arq_log
,val4
,strerror(errno
));
1548 strcpy(arq_log
,val4
);
1550 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0 && ParsedOutputLogCompress
[0] != '\0') {
1552 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1553 necessary around the command name, put them in the configuration file.
1555 sprintf(val1
,"%s \"%s\"",ParsedOutputLogCompress
,arq_log
);
1556 cstatus
=system(val1
);
1557 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1558 fprintf(stderr
, "SARG: command return status %d\n",WEXITSTATUS(cstatus
));
1559 fprintf(stderr
, "SARG: command: %s\n",val1
);
1565 debuga("%s %s",text
[123],arq_log
);
1568 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
1569 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,tmp5
,tmp4
);
1570 cstatus
=system(csort
);
1571 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1572 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
1573 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
1579 sort_users_log(tmp
, debug
);
1581 if(DataFile
[0] != '\0')
1587 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1590 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1593 // else unlink(arq);
1595 if(strcmp(tmp
,"/tmp") != 0) {
1603 debuga("%s",text
[21]);
1610 static void getusers(const char *pwdfile
, int debug
)
1619 debuga("%s: %s",text
[60],pwdfile
);
1621 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1622 fprintf(stderr
, "SARG: (getusers) %s: %s - %s\n",text
[45],pwdfile
,strerror(errno
));
1626 fseek(fp_usr
, 0, SEEK_END
);
1627 nreg
= ftell(fp_usr
);
1629 printf("SARG: Cannot get the size of file %s",pwdfile
);
1633 fseek(fp_usr
, 0, SEEK_SET
);
1635 if((userfile
=(char *) malloc(nreg
))==NULL
){
1636 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1640 bzero(userfile
,nreg
);
1641 strcpy(userfile
,":");
1643 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1644 str
=strchr(buf
,':');
1646 printf("SARG: You have an invalid user in your %s file.\n",pwdfile
);
1650 strcat(userfile
,buf
);