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
32 static char *userfile
=NULL
;
34 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
35 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
36 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
38 static void getusers(const char *pwdfile
, int debug
);
40 int main(int argc
,char *argv
[])
51 ISACOL_Last
//last entry of the list !
59 ILF_Last
//last entry of the list !
62 FILE *fp_in
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
64 char sz_Download_Unsort
[ 20000 ] ;
65 FILE * fp_Download_Unsort
= NULL
;
66 FILE * fp_Write_User
= NULL
;
78 char smartfilter
[MAXLEN
];
89 char hm
[15], hmf
[15], hmr
[15];
92 char hexclude
[MAXLEN
];
100 char start_hour
[128];
106 enum InputLogFormat ilf
;
107 int ilf_count
[ILF_Last
];
119 int isa_ncols
=0,isa_cols
[ISACOL_Last
];
126 long int max_elapsed
=0;
129 unsigned long recs1
=0UL;
130 unsigned long recs2
=0UL;
131 int OutputNonZero
= REPORT_EVERY_X_LINES
;
134 char sz_Last_User
[MAXLEN
]="";
135 struct getwordstruct gwarea
;
136 struct longlinestruct line
;
143 UserAgentLog
[0]='\0';
144 ExcludeHosts
[0]='\0';
145 ExcludeUsers
[0]='\0';
152 ExternalCSSFile
[0]='\0';
153 SquidGuardLogFormat
[0]='\0';
154 SquidGuardLogAlternate
[0]='\0';
155 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
157 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
158 strcpy(GraphDaysBytesBarColor
,"orange");
159 strcpy(BgColor
,"#ffffff");
160 strcpy(TxColor
,"#000000");
161 strcpy(TxBgColor
,"lavender");
162 strcpy(TiColor
,"darkblue");
165 strcpy(LogoTextColor
,"#000000");
166 strcpy(HeaderColor
,"darkblue");
167 strcpy(HeaderBgColor
,"#dddddd");
168 strcpy(LogoTextColor
,"#006699");
169 strcpy(FontSize
,"9px");
170 strcpy(TempDir
,"/tmp");
171 strcpy(OutputDir
,"/var/www/html/squid-reports");
173 strcpy(DateFormat
,"u");
176 strcpy(ReplaceIndex
,"index.html");
178 strcpy(RecordsWithoutUser
,"ip");
180 strcpy(MailUtility
,"mailx");
184 strcpy(TopuserSortField
,"BYTES");
185 strcpy(UserSortField
,"BYTES");
186 strcpy(TopuserSortOrder
,"reverse");
187 strcpy(UserSortOrder
,"reverse");
188 strcpy(TopsitesSortField
,"CONNECT");
189 strcpy(TopsitesSortType
,"D");
191 strcpy(language
,"English");
192 strcpy(FontFace
,"Verdana,Tahoma,Arial");
193 strcpy(datetimeby
,"elap");
194 strcpy(CharSet
,"ISO-8859-1");
196 strcpy(PrivacyString
,"***.***.***.***");
197 strcpy(PrivacyStringColor
,"blue");
199 TopUserFields
=TOPUSERFIELDS_NUM
| TOPUSERFIELDS_DATE_TIME
| TOPUSERFIELDS_USERID
| TOPUSERFIELDS_CONNECT
|
200 TOPUSERFIELDS_BYTES
| TOPUSERFIELDS_SETYB
| TOPUSERFIELDS_IN_CACHE_OUT
|
201 TOPUSERFIELDS_USED_TIME
| TOPUSERFIELDS_MILISEC
| TOPUSERFIELDS_PTIME
|
202 TOPUSERFIELDS_TOTAL
| TOPUSERFIELDS_AVERAGE
;
203 UserReportFields
=USERREPORTFIELDS_CONNECT
| USERREPORTFIELDS_BYTES
| USERREPORTFIELDS_SETYB
|
204 USERREPORTFIELDS_IN_CACHE_OUT
| USERREPORTFIELDS_USED_TIME
| USERREPORTFIELDS_MILISEC
|
205 USERREPORTFIELDS_PTIME
| USERREPORTFIELDS_TOTAL
| USERREPORTFIELDS_AVERAGE
;
206 strcpy(DataFileDelimiter
,";");
207 DataFileFields
=DATA_FIELD_USER
| DATA_FIELD_DATE
| DATA_FIELD_TIME
| DATA_FIELD_URL
| DATA_FIELD_CONNECT
|
208 DATA_FIELD_BYTES
| DATA_FIELD_IN_CACHE
| DATA_FIELD_OUT_CACHE
| DATA_FIELD_ELAPSED
;
209 ShowReadStatistics
=1;
210 strcpy(IndexSortOrder
,"D");
213 strcpy(ParsedOutputLog
,"no");
214 strcpy(ParsedOutputLogCompress
,"/bin/gzip -f");
215 strcpy(DisplayedValues
,"abbreviation");
216 strcpy(HeaderFontSize
,"9px");
217 strcpy(TitleFontSize
,"11px");
218 strcpy(AuthUserFile
,"/usr/local/sarg/passwd");
219 strcpy(AuthName
,"SARG, Restricted Access");
220 strcpy(AuthType
,"basic");
221 strcpy(Require
,"require user admin %u");
222 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");
225 strcpy(GraphFont
,FONTDIR
"/DejaVuSans.ttf");
229 strcpy(Ulimit
,"20000");
230 strcpy(NtlmUserFormat
,"domainname+username");
231 IndexTree
=INDEX_TREE_FILE
;
232 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
233 strcpy(RealtimeUnauthRec
,"show");
234 SquidguardIgnoreDate
=0;
235 DansguardianIgnoreDate
=0;
236 strcpy(DataFileUrl
,"ip");
237 strcpy(MaxElapsed
,"28800000");
238 BytesInSitesUsersReport
=0;
239 UserAuthentication
=0;
240 strcpy(LDAPHost
,"127.0.0.1");
242 LDAPProtocolVersion
=3;
245 LDAPBaseSearch
[0]='\0';
246 strcpy(LDAPFilterSearch
, "uid=%s");
247 strcpy(LDAPTargetAttr
, "cn");
271 UserInvalidChar
[0]='\0';
273 SquidGuardConf
[0]='\0';
274 DansGuardianConf
[0]='\0';
281 dansguardian_count
=0;
284 DeniedReportLimit
=10;
285 AuthfailReportLimit
=10;
286 DansGuardianReportLimit
=10;
287 SquidGuardReportLimit
=10;
288 DownloadReportLimit
=50;
301 realtime_access_log_lines
=1000;
307 bzero(IncludeUsers
, MAXLEN
);
308 bzero(ExcludeString
, MAXLEN
);
311 setlocale(LC_TIME
,"");
312 setlocale (LC_MESSAGES
, "");
314 bindtextdomain (PACKAGE_NAME
, LOCALEDIR
);
315 textdomain (PACKAGE_NAME
);
318 for(x
=0; x
<MAXLOGS
; x
++)
319 AccessLog
[x
][0]='\0';
320 AccessLogFromCmdLine
=0;
322 language_load(language
);
323 strcpy(Title
,text
[88]);
325 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
332 strcpy(uagent
,optarg
);
335 strcpy(hexclude
,optarg
);
338 strncpy(date
,optarg
,sizeof(date
)-1);
339 date
[sizeof(date
)-1]='\0';
340 getword_start(&gwarea
,optarg
);
341 if (getword(cdfrom
,sizeof(cdfrom
),&gwarea
,'-')<0 || getword(cduntil
,sizeof(cduntil
),&gwarea
,0)<0) {
342 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
345 date_from(date
, cdfrom
, cduntil
);
347 duntil
=atoi(cduntil
);
350 strcpy(email
,optarg
);
353 strcpy(ConfigFile
,optarg
);
366 if (NAccessLog
>=MAXLOGS
) {
367 printf("SARG: Too many log files.\n");
370 strcpy(AccessLog
[NAccessLog
],optarg
);
372 AccessLogFromCmdLine
++;
375 strcpy(SquidGuardLogAlternate
,optarg
);
384 strcpy(outdir
,optarg
);
399 if(strstr(optarg
,"-") == 0) {
403 getword_start(&gwarea
,optarg
);
404 if (getword(hm
,sizeof(hm
),&gwarea
,'-')<0 || getword(hmf
,sizeof(hmf
),&gwarea
,0)<0) {
405 fprintf(stderr
,"SARG: Maybe you have a broken record or garbage in your time range.\n");
409 if(sscanf(hm
,"%d:%d",&h
,&m
)!=2) {
410 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
413 sprintf(hm
,"%02d%02d",h
,m
);
414 if(sscanf(hmf
,"%d:%d",&h
,&m
)!=2) {
415 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
418 sprintf(hmf
,"%02d%02d",h
,m
);
440 fprintf(stderr
, "Option -%c require an argument\n",optopt
);
456 if(debug
) debuga("Init");
458 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
459 if(access(ConfigFile
, R_OK
) != 0) {
460 debuga("Cannot open config file: %s - %s",ConfigFile
,strerror(errno
));
464 if(access(ConfigFile
, R_OK
) == 0)
476 if(IndexTree
== INDEX_TREE_FILE
)
477 strcpy(ImageFile
,"../images");
479 strcpy(ImageFile
,"../../../images");
482 if(DataFile
[0] != '\0')
486 strcpy(AccessLog
[0],"/var/log/squid/access.log");
490 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
491 convlog(AccessLog
[0], df
, dfrom
, duntil
);
495 if(strcmp(site
,"plit") == 0) {
496 splitlog(AccessLog
[0], df
, dfrom
, duntil
, hexclude
);
500 load_excludecodes(ExcludeCodes
);
502 if(access(PasswdFile
, R_OK
) == 0) {
503 getusers(PasswdFile
,debug
);
507 if(hexclude
[0] == '\0')
508 strcpy(hexclude
,ExcludeHosts
);
509 if(hexclude
[0] != '\0') {
510 gethexclude(hexclude
,debug
);
514 if(ReportType
== 0) {
515 ReportType
=REPORT_TYPE_TOPUSERS
| REPORT_TYPE_TOPSITES
| REPORT_TYPE_USERS_SITES
|
516 REPORT_TYPE_SITES_USERS
| REPORT_TYPE_DATE_TIME
| REPORT_TYPE_DENIED
|
517 REPORT_TYPE_AUTH_FAILURES
| REPORT_TYPE_SITE_USER_TIME_DATE
| REPORT_TYPE_DOWNLOADS
;
520 if(access(ExcludeUsers
, R_OK
) == 0) {
521 getuexclude(ExcludeUsers
,debug
);
530 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
531 if(Index
== INDEX_ONLY
) indexonly
++;
533 if(MaxElapsed
[0] != '\0') max_elapsed
=atol(MaxElapsed
);
535 if(outdir
[0] == '\0') strcpy(outdir
,OutputDir
);
538 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
540 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
541 else strcpy(TempDir
,tmp
);
543 if(df
[0] == '\0') strcpy(df
,DateFormat
);
544 else strcpy(DateFormat
,df
);
548 strcpy(DateFormat
,"u");
551 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
555 if(email
[0] != '\0') {
556 sprintf(wtemp2
,"%s/sarg",tmp2
);
558 strcat(tmp2
,"/sarg");
563 strcat(tmp2
,"/sarg.log");
565 sprintf(tmp3
,"%s/sarg",tmp
);
566 if(access(tmp3
, R_OK
) == 0) {
573 strcat(tmp4
,"/denied.log.unsort");
574 strcat(tmp5
,"/denied.log");
575 strcat(tmp6
,"/authfail.log.unsort");
578 fprintf(stderr
, "SARG: %s:\nSARG:\n",text
[22]);
579 fprintf(stderr
, "SARG: %35s (-a) = %s\n",text
[23],addr
);
580 fprintf(stderr
, "SARG: %35s (-b) = %s\n",text
[71],uagent
);
581 fprintf(stderr
, "SARG: %35s (-c) = %s\n",text
[69],hexclude
);
582 fprintf(stderr
, "SARG: %35s (-d) = %s\n",text
[24],date
);
583 fprintf(stderr
, "SARG: %35s (-e) = %s\n",text
[41],email
);
584 fprintf(stderr
, "SARG: %35s (-f) = %s\n",text
[70],ConfigFile
);
585 if(strcmp(df
,"e") == 0)
586 fprintf(stderr
, "SARG: %35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
587 if(strcmp(df
,"u") == 0)
588 fprintf(stderr
, "SARG: %35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
589 if(strcmp(df
,"w") == 0)
590 fprintf(stderr
, "SARG: %35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
592 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[1]);
594 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[2]);
595 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
596 fprintf(stderr
, "SARG: %35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
598 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[1]);
600 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[2]);
601 fprintf(stderr
, "SARG: %35s (-o) = %s\n",text
[38],outdir
);
603 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[1]);
605 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[2]);
606 fprintf(stderr
, "SARG: %35s (-s) = %s\n",text
[30],site
);
607 fprintf(stderr
, "SARG: %35s (-t) = %s\n",text
[31],hm
);
608 fprintf(stderr
, "SARG: %35s (-u) = %s\n",text
[32],us
);
609 fprintf(stderr
, "SARG: %35s (-w) = %s\n",text
[34],tmp
);
611 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[1]);
613 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[2]);
615 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[1]);
617 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[2]);
618 fprintf(stderr
, "SARG:\n");
622 printf("%s:\nSARG:\n",text
[22]);
623 printf("%35s (-a) = %s\n",text
[23],addr
);
624 printf("%35s (-b) = %s\n",text
[71],uagent
);
625 printf("%35s (-c) = %s\n",text
[69],hexclude
);
626 printf("%35s (-d) = %s\n",text
[24],date
);
627 printf("%35s (-e) = %s\n",text
[41],email
);
628 printf("%35s (-f) = %s\n",text
[70],ConfigFile
);
629 if(strcmp(df
,"e") == 0)
630 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
631 if(strcmp(df
,"u") == 0)
632 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
633 if(strcmp(df
,"w") == 0)
634 printf("%35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
636 printf("%35s (-i) = %s\n",text
[28],text
[1]);
638 printf("%35s (-i) = %s\n",text
[28],text
[2]);
639 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
640 printf("%35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
642 printf("%35s (-n) = %s\n",text
[65],text
[1]);
644 printf("%35s (-n) = %s\n",text
[65],text
[2]);
645 printf("%35s (-o) = %s\n",text
[38],outdir
);
647 printf("%35s (-p) = %s\n",text
[29],text
[1]);
649 printf("%35s (-p) = %s\n",text
[29],text
[2]);
650 printf("%35s (-s) = %s\n",text
[30],site
);
651 printf("%35s (-t) = %s\n",text
[31],hm
);
652 printf("%35s (-u) = %s\n",text
[32],us
);
653 printf("%35s (-w) = %s\n",text
[34],tmp
);
655 printf("%35s (-x) = %s\n",text
[35],text
[1]);
657 printf("%35s (-x) = %s\n",text
[35],text
[2]);
659 printf("%35s (-z) = %s\n",text
[36],text
[1]);
661 printf("%35s (-z) = %s\n",text
[36],text
[2]);
662 printf("sarg %s: %s\n",text
[73],VERSION
);
663 printf("Language=%s\n\n",text
[3]);
667 debuga("sarg %s: %s",text
[73],VERSION
);
670 if (Ulimit
[0] != '\0') {
675 #if defined(RLIMIT_NOFILE)
676 getrlimit (RLIMIT_NOFILE
, &rl
);
677 #elif defined(RLIMIT_OFILE)
678 getrlimit (RLIMIT_OFILE
, &rl
);
680 #warning "No rlimit resource for the number of open files"
685 rl
.rlim_cur
= atol(Ulimit
);
686 rl
.rlim_max
= atol(Ulimit
);
687 #if defined(RLIMIT_NOFILE)
688 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
689 #elif defined(RLIMIT_OFILE)
690 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
692 #warning "No rlimit resource for the number of open files"
695 debuga("setrlimit error - %s\n",strerror(errno
));
699 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
703 init_usertab(UserTabFile
);
705 if (longline_prepare(&line
)<0) {
706 debuga(_("Not enough memory to read a log file"));
710 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
712 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
713 if((fp_denied
=MY_FOPEN(tmp4
,"w"))==NULL
) {
714 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp4
,strerror(errno
));
719 if(DataFile
[0]=='\0') {
720 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
721 if((fp_authfail
=MY_FOPEN(tmp6
,"w"))==NULL
) {
722 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp6
,strerror(errno
));
728 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
729 strcpy(arq
,AccessLog
[iarq
]);
733 if(strcmp(arq
,"-")==0) {
735 debuga("%s: %s",text
[7],"stdin");
741 debuga("%s: %s",text
[7],arq
);
742 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
743 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq
,strerror(errno
));
750 // pre-read the file only if we have to show stats
751 if(ShowReadStatistics
&& !from_stdin
) {
758 while ((nread
=fread(line
.buffer
,1,line
.size
,fp_in
))>0) {
759 for (i
=0 ; i
<nread
; i
++)
761 if (line
.buffer
[i
]!='\n' && line
.buffer
[i
]!='\r') {
765 if (line
.buffer
[i
]=='\n' || line
.buffer
[i
]=='\r') {
772 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,(float) 0);
780 while ((linebuf
=longline_read(fp_in
,&line
))!=NULL
) {
781 blen
=strlen(linebuf
);
783 if (ilf
==ILF_Unknown
) {
784 if(strncmp(linebuf
,"#Software: Mic",14) == 0) {
785 fixendofline(linebuf
);
787 debuga("%s: %s",text
[143],linebuf
);
793 if(strncmp(linebuf
,"*** SARG Log ***",16) == 0) {
794 getword_start(&gwarea
,arqtt
);
795 if (getword_skip(2000,&gwarea
,'-')<0 || getword(val2
,sizeof(val2
),&gwarea
,'_')<0 ||
796 getword_skip(10,&gwarea
,'-')<0 || getword(val3
,sizeof(val3
),&gwarea
,'_')<0) {
797 printf("SARG: The name of the file is invalid: %s\n",arq
);
800 sprintf(period
,"%s-%s",val2
,val3
);
807 if(!fp_log
&& strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
808 if(access(ParsedOutputLog
,R_OK
) != 0) {
809 my_mkdir(ParsedOutputLog
);
811 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
812 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
813 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq_log
,strerror(errno
));
816 fputs("*** SARG Log ***\n",fp_log
);
820 if( ShowReadStatistics
&& !from_stdin
&& ! --OutputNonZero
) {
822 perc
= perc
/ recs1
;
823 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,perc
);
825 OutputNonZero
= REPORT_EVERY_X_LINES
;
827 if(blen
< 58) continue;
828 if(strstr(linebuf
,"HTTP/0.0") != 0) continue;
829 if(strstr(linebuf
,"logfile turned over") != 0) continue;
830 if(linebuf
[0] == ' ') continue;
832 // Record only hours usage which is required
833 tt
= (time_t) strtoul( linebuf
, NULL
, 10 );
834 t
= localtime( &tt
);
836 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
837 sizeof( int ), compar
) == NULL
)
840 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
841 sizeof( int ), compar
) == NULL
)
846 if(ExcludeString
[0] != '\0') {
847 getword_start(&gwarea
,ExcludeString
);
848 while(strchr(gwarea
.current
,':') != 0) {
849 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
850 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
853 if((str
=(char *) strstr(linebuf
,val1
)) != (char *) NULL
)
856 if((str
=(char *) strstr(linebuf
,gwarea
.current
)) != (char *) NULL
)
859 if(exstring
) continue;
861 if ((str
= strchr(linebuf
, '\n')) != NULL
)
862 *str
= '\0'; /* strip \n */
866 printf("BUF=%s\n",linebuf
);
868 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
869 getword_start(&gwarea
,linebuf
);
870 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
871 printf("SARG: Maybe you have a broken time in your access.log file.\n");
874 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
) {
875 if((str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
879 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
880 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
884 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
885 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
889 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
890 getword(fun
,sizeof(fun
),&gwarea
,' ')<0) {
891 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
894 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0) {
895 debuga(_("Maybe you have a broken url in your %s file"),arq
);
898 if (getword_skip(MAXLEN
,&gwarea
,' ')<0 || getword(code2
,sizeof(code2
),&gwarea
,' ')<0 ||
899 getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
900 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
903 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
904 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
905 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
909 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
910 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
915 if ((str
= strchr(code
, ':')) != NULL
)
918 if(strcmp(tam
,"\0") == 0)
926 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
927 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
928 printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arq
);
931 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
932 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
933 printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arq
);
936 if(strlen(elap
) < 1) continue;
937 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
938 printf("SARG: Maybe you have a broken client IP address in your %s file.\n",arq
);
941 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
942 printf("SARG: Maybe you have a broken result code in your %s file.\n",arq
);
945 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
946 printf("SARG: Maybe you have a broken amount of data in your %s file.\n",arq
);
949 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
950 printf("SARG: Maybe you have a broken request method in your %s file.\n",arq
);
953 if (getword_ptr(linebuf
,&url
,&gwarea
,' ')<0){
954 debuga(_("Maybe you have a broken url in your %s file"),arq
);
957 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
958 printf("SARG: Maybe you have a broken user ID in your %s file.\n",arq
);
966 getword_start(&gwarea
,linebuf
);
967 if (getword(data
,sizeof(data
),&gwarea
,'\t')<0){
968 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
971 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
972 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
975 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
976 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
979 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
980 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
983 if (getword_ptr(linebuf
,&url
,&gwarea
,'\t')<0){
984 debuga(_("Maybe you have a broken record or garbage in your %s file"),arq
);
987 if (getword(tam
,sizeof(tam
),&gwarea
,'\t')<0){
988 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
991 if (getword(code
,sizeof(code
),&gwarea
,'\t')<0){
992 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
995 if (getword(elap
,sizeof(elap
),&gwarea
,'\t')<0){
996 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
999 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,'\0')<0){
1000 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1005 if (linebuf
[0] == '#') {
1006 int ncols
,cols
[ISACOL_Last
];
1008 fixendofline(linebuf
);
1009 getword_start(&gwarea
,linebuf
);
1010 // remove the #Fields: column at the beginning of the line
1011 if (getword_skip(1000,&gwarea
,' ')<0){
1012 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1015 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
1017 while(gwarea
.current
[0] != '\0') {
1018 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
1019 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1022 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
1023 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
1024 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
1025 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
1026 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
1027 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
1028 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
1029 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
1032 if (cols
[ISACOL_Ip
]>=0) {
1034 for (isa_ncols
=0 ; isa_ncols
<ncols
; isa_ncols
++)
1035 isa_cols
[isa_ncols
]=cols
[isa_ncols
];
1039 if (!isa_ncols
) continue;
1040 getword_start(&gwarea
,linebuf
);
1041 for (x
=0 ; x
<isa_ncols
; x
++) {
1042 if (getword_ptr(linebuf
,&str
,&gwarea
,'\t')<0) {
1043 debuga(_("Maybe you have a broken record or garbage in your %s file"),arq
);
1046 if (x
==isa_cols
[ISACOL_Ip
]) {
1047 if (strlen(str
)>=sizeof(ip
)) {
1048 printf("SARG: Maybe you have a broken IP in your %s file.\n",arq
);
1052 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1053 if (strlen(str
)>=sizeof(user
)) {
1054 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1058 } else if (x
==isa_cols
[ISACOL_Date
]) {
1059 if (strlen(str
)>=sizeof(data
)) {
1060 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1064 } else if (x
==isa_cols
[ISACOL_Time
]) {
1065 if (strlen(str
)>=sizeof(hora
)) {
1066 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1070 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1071 if (strlen(str
)>=sizeof(elap
)) {
1072 printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq
);
1076 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1077 if (strlen(str
)>=sizeof(tam
)) {
1078 printf("SARG: Maybe you have a broken download size in your %s file.\n",arq
);
1082 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1084 } else if (x
==isa_cols
[ISACOL_Status
]) {
1085 if (strlen(str
)>=sizeof(code
)) {
1086 printf("SARG: Maybe you have a broken access code in your %s file.\n",arq
);
1093 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1094 sprintf(val1
,"DENIED/%s",code
);
1097 getword_start(&gwarea
,data
);
1098 if (getword(ano
,sizeof(ano
),&gwarea
,'-')<0){
1099 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1102 if (getword(mes
,sizeof(mes
),&gwarea
,'-')<0){
1103 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1106 if (getword(dia
,sizeof(dia
),&gwarea
,'\0')<0){
1107 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1110 conv_month_name(mes
);
1111 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1114 if(strlen(user
) > 150) {
1115 if (debugm
) printf("User too long: %s\n",user
);
1121 if(IncludeUsers
[0] != '\0') {
1122 sprintf(val1
,":%s:",user
);
1123 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1128 if (debugm
) printf("Excluded code: %s\n",code
);
1133 if(testvaliduserchar(user
))
1137 if((str
= strstr(user
,"%20")) != NULL
) {
1139 This is a patch introduced to solve bug #1624251 reported at sourceforge but
1140 the side effect is to truncate the name at the first space and merge the reports
1141 of people whose name is identical up to the first space.
1143 The old code used to truncate the user name at the first % if a %20 was
1144 found anywhere in the string. That means the string could be truncated
1145 at the wrong place if another % occured before the %20. This new code should
1146 avoid that problem and only truncate at the space. There is no bug
1147 report indicating that anybody noticed this.
1153 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1154 found in the user name.
1156 while((str
= strstr(user
,"%5c")) != NULL
) {
1158 for (x
=3 ; str
[x
] ; x
++) str
[x
-2]=str
[x
];
1162 for(str
=user
; *str
; str
++) {
1163 if(*str
=='.') dotinuser
++;
1164 if(*str
=='?' || *str
=='.' || *str
==':' || *str
=='/' || *str
=='\\' || *str
=='\'' || *str
=='$' || *str
=='@' ||
1165 *str
=='\"' || *str
=='*')
1170 if(strncmp(NtlmUserFormat
,"user",4) == 0) {
1171 if((str
= strchr(user
,'_')) != 0) {
1172 strcpy(warea
,str
+1);
1175 if((str
= strchr(user
,'+')) != 0) {
1176 strcpy(warea
,str
+1);
1185 The full URL is not saved in sarg log. There is no point in testing the URL to detect
1188 download_flag
=is_download_suffix(url
);
1189 if (download_flag
) {
1195 // remove any protocol:// at the beginning of the URL
1196 if ((str
= strchr(url
,'/')) != NULL
&& str
[1] == '/') {
1200 for (i
=0 ; str
[i
] ; i
++)
1208 for (i
=0 ; i
<sizeof(hostname
)-1 && url
[i
] && url
[i
]!='/' ; i
++)
1214 if(ilf
==ILF_Squid
) {
1218 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1219 sprintf(mes
,"%d",t
->tm_mon
+1);
1220 conv_month_name(mes
);
1221 if(strncmp(df
,"u",1) == 0)
1222 sprintf(tbuf
, "%04d%s%02d", t
->tm_year
+1900, mes
, t
->tm_mday
);
1223 if(strncmp(df
,"e",1) == 0)
1224 sprintf(tbuf
, "%02d%s%04d", t
->tm_mday
, mes
, t
->tm_year
+1900);
1225 if(strncmp(df
,"w",1) == 0) {
1226 IndexTree
=INDEX_TREE_FILE
;
1227 strftime(tbuf
, sizeof(tbuf
), "%Y.%U", t
);
1230 strftime(wdata
, sizeof(wdata
), "%Y%m%d", t
);
1233 if(strncmp(df
,"u",1)==0)
1234 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
1236 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1237 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1238 } else if(ilf
==ILF_Common
|| ilf
==ILF_Isa
) {
1239 getword_start(&gwarea
,data
+1);
1240 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
1241 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1244 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
1245 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1248 getword_start(&gwarea
,data
);
1249 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1250 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1253 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1254 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1257 if (getword(ano
,sizeof(ano
),&gwarea
,'/')<0){
1258 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1262 if(strcmp(df
,"u") == 0)
1263 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",ano
,mes
,dia
);
1264 if(strcmp(df
,"e") == 0)
1265 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",dia
,mes
,ano
);
1266 builddia(dia
,mes
,ano
,df
,wdata
);
1268 } else if (ilf
==ILF_Sarg
) {
1269 getword_start(&gwarea
,data
);
1270 if(strcmp(df
,"u") == 0) {
1271 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1272 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1275 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1276 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1280 if (getword(dia
,sizeof(dia
),&gwarea
,'/')<0){
1281 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1284 if (getword(mes
,sizeof(mes
),&gwarea
,'/')<0){
1285 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1289 if (getword(ano
,sizeof(ano
),&gwarea
,0)<0){
1290 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1293 snprintf(wdata
,9,"%s%s%s",ano
,mes
,dia
);
1298 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1302 if(addr
[0] != '\0'){
1303 if(strcmp(addr
,ip
)==0)
1310 if (debugm
) printf("Excluded site: %s\n",url
);
1317 if(date
[0] != '\0'){
1318 if(idata
>= dfrom
&& idata
<= duntil
)
1324 bzero(hmr
,sizeof(hmr
));
1326 getword_start(&gwarea
,hora
);
1328 if (getword_multisep(warea
,sizeof(warea
),&gwarea
,':')<0){
1329 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1332 strncat(hmr
,warea
,2);
1335 strncat(hmr
,gwarea
.current
,2);
1337 if(atoi(hmr
) >= atoi(hm
) && atoi(hmr
) <= atoi(hmf
))
1342 if(site
[0] != '\0'){
1343 if(strstr(url
,site
)!=0)
1351 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1352 if(strcmp(RecordsWithoutUser
,"ip") == 0)
1354 if(strcmp(RecordsWithoutUser
,"ignore") == 0)
1356 if(strcmp(RecordsWithoutUser
,"everybody") == 0)
1357 strcpy(user
,"everybody");
1360 if(strcmp(user
,us
)==0)
1367 subs(user
,sizeof(user
),"_",".");
1372 sprintf(wuser
,":%s:",user
);
1373 if(strstr(userfile
, wuser
) == 0)
1381 if (debugm
) printf("Excluded user: %s\n",user
);
1392 if(l
&& max_elapsed
) {
1393 if(atol(elap
)>max_elapsed
) {
1400 if(strcmp(user
,"-") !=0 && url
[0] != '\0' && strcmp(user
," ") !=0 && strcmp(user
,"") !=0 && strcmp(user
,":") !=0){
1401 if((str
=(char *) strstr(linebuf
, "[SmartFilter:")) != (char *) NULL
) {
1403 sprintf(smartfilter
,"\"%s\"",str
+1);
1404 } else sprintf(smartfilter
,"\"\"");
1406 if ( strcmp ( user
, sz_Last_User
) != 0 ) {
1407 if ( fp_Write_User
)
1408 fclose( fp_Write_User
) ;
1409 sprintf (tmp3
, "%s/sarg/%s.unsort", tmp
, user
);
1411 if ((fp_Write_User
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1412 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1415 strcpy( sz_Last_User
, user
) ;
1417 fprintf(fp_Write_User
, "%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
);
1419 if(fp_log
&& ilf
!=ILF_Sarg
)
1420 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
);
1424 if(download_flag
&& strstr(code
,"DENIED") == 0) {
1427 if ( ! fp_Download_Unsort
) {
1428 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1429 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1433 fprintf(fp_Download_Unsort
,"%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,download_url
);
1436 if((ReportType
& REPORT_TYPE_DENIED
) != 0 || (ReportType
& REPORT_TYPE_AUTH_FAILURES
) != 0) {
1437 if(strstr(code
,"DENIED/403") != 0) {
1438 fprintf(fp_denied
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1441 if(strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0) {
1443 fprintf(fp_authfail
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1448 if((!totper
|| idata
<mindate
) && ilf
!=ILF_Sarg
){
1451 sprintf(period
,"%s-",tbuf
);
1452 strcpy(start_hour
,tbuf2
);
1454 fixper(tbuf
, period
, cduntil
);
1456 debugaz("tbuf",tbuf
);
1457 debugaz("period",period
);
1463 printf("IP=\t%s\n",ip
);
1464 printf("USER=\t%s\n",user
);
1465 printf("ELAP=\t%s\n",elap
);
1466 printf("DATE=\t%s\n",dia
);
1467 printf("TIME=\t%s\n",hora
);
1468 printf("FUNC=\t%s\n",fun
);
1469 printf("URL=\t%s\n",url
);
1470 printf("CODE=\t%s\n",code
);
1471 printf("LEN=\t%s\n",tam
);
1477 if( ShowReadStatistics
)
1478 printf("SARG: Records in file: %lu, reading: %3.2f%%\n",recs1
, (float) 100 );
1482 longline_free(&line
);
1483 if ( fp_Download_Unsort
)
1484 fclose (fp_Download_Unsort
);
1487 fclose (fp_Write_User
);
1490 free_excludecodes();
1496 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1498 debuga(" %s: %ld, %s: %ld, %s: %ld",text
[10],totregsl
,text
[11],totregsg
,text
[68],totregsx
);
1500 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1501 debuga("%s",text
[12]);
1503 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1504 debuga("%s",text
[13]);
1506 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1507 debuga("%s",text
[14]);
1509 if(ilf_count
[ILF_Sarg
]>0)
1510 debuga("%s",text
[124]);
1514 fprintf(stderr
, "SARG: %s\n",text
[16]);
1515 fprintf(stderr
, "SARG: %s\n",text
[21]);
1516 } else fprintf(stderr
, "SARG: %s\n",text
[15]);
1520 fclose(fp_authfail
);
1532 fprintf(stderr
, "SARG: %s\n",text
[16]);
1533 fprintf(stderr
, "SARG: %s\n",text
[21]);
1538 fclose(fp_authfail
);
1545 if(date
[0] == '\0' && ilf_count
[ILF_Sarg
]==0) {
1546 strcat(period
,tbuf
);
1550 debugaz("data",dia
);
1551 debugaz("tbuf",tbuf
);
1552 debugaz("period",period
);
1556 debuga("%s: %s",text
[17],period
);
1562 fclose(fp_authfail
);
1564 if(fp_log
!= NULL
) {
1566 strcpy(end_hour
,tbuf2
);
1567 getword_start(&gwarea
,period
);
1568 if (getword(val2
,sizeof(val2
),&gwarea
,'-')<0){
1569 printf("SARG: Maybe you have a broken date range definition.\n");
1572 if (getword(val1
,sizeof(val1
),&gwarea
,'\0')<0){
1573 printf("SARG: Maybe you have a broken date range definition.\n");
1576 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,start_hour
,val1
,end_hour
);
1577 if (rename(arq_log
,val4
)) {
1578 fprintf(stderr
,"SARG: failed to rename %s to %s - %s\n",arq_log
,val4
,strerror(errno
));
1580 strcpy(arq_log
,val4
);
1582 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0 && ParsedOutputLogCompress
[0] != '\0') {
1584 No double quotes around ParsedOutputLogCompress because it may contain command line options. If double quotes are
1585 necessary around the command name, put them in the configuration file.
1587 sprintf(val1
,"%s \"%s\"",ParsedOutputLogCompress
,arq_log
);
1588 cstatus
=system(val1
);
1589 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1590 fprintf(stderr
, "SARG: command return status %d\n",WEXITSTATUS(cstatus
));
1591 fprintf(stderr
, "SARG: command: %s\n",val1
);
1597 debuga("%s %s",text
[123],arq_log
);
1600 if((ReportType
& REPORT_TYPE_DENIED
) != 0) {
1601 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,tmp5
,tmp4
);
1602 cstatus
=system(csort
);
1603 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1604 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
1605 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
1611 sort_users_log(tmp
, debug
);
1613 if(DataFile
[0] != '\0')
1619 if((ReportType
& REPORT_TYPE_DENIED
) != 0)
1622 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1625 // else unlink(arq);
1627 if(strcmp(tmp
,"/tmp") != 0) {
1636 debuga("%s",text
[21]);
1643 static void getusers(const char *pwdfile
, int debug
)
1652 debuga("%s: %s",text
[60],pwdfile
);
1654 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1655 fprintf(stderr
, "SARG: (getusers) %s: %s - %s\n",text
[45],pwdfile
,strerror(errno
));
1659 fseek(fp_usr
, 0, SEEK_END
);
1660 nreg
= ftell(fp_usr
);
1662 printf("SARG: Cannot get the size of file %s",pwdfile
);
1666 fseek(fp_usr
, 0, SEEK_SET
);
1668 if((userfile
=(char *) malloc(nreg
))==NULL
){
1669 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1673 bzero(userfile
,nreg
);
1674 strcpy(userfile
,":");
1676 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1677 str
=strchr(buf
,':');
1679 printf("SARG: You have an invalid user in your %s file.\n",pwdfile
);
1683 strcat(userfile
,buf
);