2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
27 #include "include/defs.h"
29 #define LEGACY_WRITE_USER
30 #define LEGACY_WRITE_DOWNLOAD
31 #define REPORT_EVERY_X_LINES 5000
38 char sz_Last_User
[ MAXLEN
] = { 0 } ;
39 int bool_ShowReadStatistics
;
41 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
42 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
43 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
45 static void getusers(const char *pwdfile
, int debug
);
46 static void gethexclude(const char *hexfile
, int debug
);
47 static void getuexclude(const char *uexfile
, int debug
);
49 int main(int argc
,char *argv
[])
52 FILE *fp_in
= NULL
, *fp_ou
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
54 char sz_Download_Unsort
[ 20000 ] ;
55 FILE * fp_Download_Unsort
= NULL
;
56 FILE * fp_Write_User
= NULL
;
71 char smartfilter
[MAXLEN
];
83 char hm
[15], hmf
[15], hmr
[15], whm
[15];
86 char hexclude
[MAXLEN
];
110 int i0
=0,i1
=-1,i2
=-1,i3
=-1,i4
=-1,i5
=-1,i6
=-1,i7
=-1,i8
=-1;
115 long int max_elapsed
=0;
119 unsigned long recs2
=0;
121 int OutputNonZero
= REPORT_EVERY_X_LINES
;
123 char download_url
[MAXLEN
];
131 UserAgentLog
[0]='\0';
132 ExcludeHosts
[0]='\0';
133 ExcludeUsers
[0]='\0';
141 ExternalCSSFile
[0]='\0';
142 SquidGuardLogFormat
[0]='\0';
143 SquidGuardLogAlternate
[0]='\0';
146 strcpy(AccessLog
,"/usr/local/squid/var/logs/access.log");
147 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
148 strcpy(GraphDaysBytesBarColor
,"orange");
149 strcpy(BgColor
,"#ffffff");
150 strcpy(TxColor
,"#000000");
151 strcpy(TxBgColor
,"lavender");
152 strcpy(TiColor
,"darkblue");
155 strcpy(LogoTextColor
,"#000000");
156 strcpy(HeaderColor
,"darkblue");
157 strcpy(HeaderBgColor
,"#dddddd");
158 strcpy(LogoTextColor
,"#006699");
159 strcpy(FontSize
,"9px");
160 strcpy(TempDir
,"/tmp");
161 strcpy(OutputDir
,"/var/www/html/squid-reports");
162 strcpy(Ip2Name
,"no");
163 strcpy(DateFormat
,"u");
164 strcpy(OverwriteReport
,"no");
165 strcpy(RemoveTempFiles
,"yes");
166 strcpy(ReplaceIndex
,"index.html");
168 strcpy(RecordsWithoutUser
,"ip");
169 strcpy(UseComma
,"no");
170 strcpy(MailUtility
,"mailx");
171 strcpy(TopSitesNum
,"100");
173 strcpy(TopuserSortField
,"BYTES");
174 strcpy(UserSortField
,"BYTES");
175 strcpy(TopuserSortOrder
,"reverse");
176 strcpy(UserSortOrder
,"reverse");
177 strcpy(TopsitesSortField
,"CONNECT");
178 strcpy(TopsitesSortType
,"D");
179 strcpy(LongUrl
,"no");
180 strcpy(language
,"English");
181 strcpy(FontFace
,"Verdana,Tahoma,Arial");
182 strcpy(datetimeby
,"elap");
183 strcpy(CharSet
,"ISO-8859-1");
184 strcpy(Privacy
,"no");
185 strcpy(PrivacyString
,"***.***.***.***");
186 strcpy(PrivacyStringColor
,"blue");
187 strcpy(SuccessfulMsg
,"yes");
188 strcpy(TopUserFields
,"NUM DATE_TIME USERID CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
189 strcpy(UserReportFields
,"CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
190 strcpy(DataFileDelimiter
,";");
191 strcpy(DataFileFields
,"user;date;time;url;connect;bytes;in_cache;out_cache;elapsed");
192 strcpy(SiteUserTimeDateType
,"table");
193 strcpy(ShowReadStatistics
,"yes");
194 strcpy(IndexSortOrder
,"D");
195 strcpy(ShowSargInfo
,"yes");
196 strcpy(ShowSargLogo
,"yes");
197 strcpy(ParsedOutputLog
,"no");
198 strcpy(ParsedOutputLogCompress
,"/bin/gzip");
199 strcpy(DisplayedValues
,"abbreviation");
200 strcpy(HeaderFontSize
,"9px");
201 strcpy(TitleFontSize
,"11px");
202 strcpy(AuthUserFile
,"/usr/local/sarg/passwd");
203 strcpy(AuthName
,"SARG, Restricted Access");
204 strcpy(AuthType
,"basic");
205 strcpy(Require
,"require user admin %u");
206 strcpy(DownloadSuffix
,"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");
207 strcpy(Graphs
,"yes");
208 strcpy(Ulimit
,"20000");
209 strcpy(NtlmUserFormat
,"domainname+username");
210 strcpy(IndexTree
,"file");
211 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
212 strcpy(RealtimeUnauthRec
,"show");
213 strcpy(SquidguardIgnoreDate
,"off");
214 strcpy(DansguardianIgnoreDate
,"off");
215 strcpy(DataFileUrl
,"ip");
216 strcpy(MaxElapsed
,"28800000");
217 strcpy(BytesInSitesUsersReport
,"no");
241 UserInvalidChar
[0]='\0';
243 SquidGuardConf
[0]='\0';
244 DansGuardianConf
[0]='\0';
249 dansguardian_count
=0;
251 DeniedReportLimit
=10;
252 AuthfailReportLimit
=10;
253 DansGuardianReportLimit
=10;
254 SquidGuardReportLimit
=10;
255 DownloadReportLimit
=50;
270 realtime_access_log_lines
=1000;
276 bzero(IncludeUsers
, MAXLEN
);
277 bzero(ExcludeString
, MAXLEN
);
279 for(x
=0; x
<=254; x
++)
282 language_load(language
);
283 strcpy(Title
,text
[88]);
285 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
292 strcpy(uagent
,optarg
);
295 strcpy(hexclude
,optarg
);
299 strcpy(cduntil
,optarg
);
300 if (getword(cdfrom
,sizeof(cdfrom
),cduntil
,'-')<0) {
301 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
304 date_from(date
, cdfrom
, cduntil
);
306 duntil
=atoi(cduntil
);
309 strcpy(email
,optarg
);
312 strcpy(ConfigFile
,optarg
);
325 if (narq
>=sizeof(warq
)/sizeof(warq
[0])) {
326 printf("SARG: Too many log files.\n");
329 strcpy(warq
[narq
],optarg
);
333 strcpy(SquidGuardLogAlternate
,optarg
);
342 strcpy(outdir
,optarg
);
354 if(strstr(optarg
,"-") == 0) {
358 if (getword(hm
,sizeof(hm
),optarg
,'-')<0) {
359 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
365 printf("SARG: time period must be MM or MM:SS. Exit.\n");
369 if(strstr(hm
,":") != 0) {
370 if (getword(warea
,sizeof(warea
),hm
,':')<0) {
371 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
374 sprintf(whm
,"%s%s",warea
,hm
);
378 if(strstr(hmf
,":") != 0) {
379 if (getword(warea
,sizeof(warea
),hmf
,':')<0) {
380 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
383 sprintf(whm
,"%s%s",warea
,hmf
);
406 fprintf(stderr
, "Option -%c require an argument\n",optopt
);
422 if(debug
) debuga("Init");
424 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
425 if(access(ConfigFile
, R_OK
) != 0) {
426 debuga("Cannot open config file: %s - %s",ConfigFile
,strerror(errno
));
430 if(access(ConfigFile
, R_OK
) == 0)
438 if(strcmp(IndexTree
,"file") == 0)
439 strcpy(ImageFile
,"../images");
441 strcpy(ImageFile
,"../../../images");
444 if(DataFile
[0] != '\0');
447 subs(TopUserFields
,sizeof(TopUserFields
),"%BYTES","SETYB");
449 subs(UserReportFields
,sizeof(UserReportFields
),"%BYTES","SETYB");
452 strcpy(warq
[0],AccessLog
);
456 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
457 convlog(warq
[0], df
, dfrom
, duntil
);
461 if(strcmp(site
,"plit") == 0) {
462 splitlog(warq
[0], df
, dfrom
, duntil
, hexclude
);
466 load_excludecodes(ExcludeCodes
);
468 if(access(PasswdFile
, R_OK
) == 0) {
469 getusers(PasswdFile
,debug
);
473 if(hexclude
[0] == '\0')
474 strcpy(hexclude
,ExcludeHosts
);
475 if(strlen(hexclude
) > 0) {
476 if(access(hexclude
, R_OK
) != 0) {
477 debuga("Cannot open exclude_hosts file: %s - %s",hexclude
,strerror(errno
));
480 gethexclude(hexclude
,debug
);
484 if(ReportType
[0] == '\0')
485 strcpy(ReportType
,"topusers topsites users_sites sites_users date_time denied auth_failures site_user_time_date downloads");
487 if(access(ExcludeUsers
, R_OK
) == 0) {
488 getuexclude(ExcludeUsers
,debug
);
494 if(strstr(excludeuser
,"indexonly") != 0)
497 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
498 if(strcmp(Index
,"only") == 0) indexonly
++;
500 if(dns
) strcpy(Ip2Name
,"yes");
502 if(strcmp(UserIp
,"yes") == 0) userip
++;
504 if(strlen(MaxElapsed
)>1) max_elapsed
=atol(MaxElapsed
);
506 if(strlen(outdir
)<1) strcpy(outdir
,OutputDir
);
510 if(arq
[0] == '\0') strcpy(arq
,AccessLog
);
512 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
514 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
515 else strcpy(TempDir
,tmp
);
517 if(df
[0] == '\0') strcpy(df
,DateFormat
);
518 else strcpy(DateFormat
,df
);
522 strcpy(DateFormat
,"u");
525 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
529 if(strlen(email
) > 0) {
530 sprintf(wtemp2
,"%s/sarg",tmp2
);
532 strcat(tmp2
,"/sarg");
537 strcat(tmp2
,"/sarg.log");
539 sprintf(warea
,"%s/sarg",tmp
);
540 if(access(warea
, R_OK
) == 0) {
541 sprintf(tmp3
,"rm -rf %s",warea
);
545 sprintf(tmp3
,"%s/sarg",tmp
);
550 strcat(tmp4
,"/denied.log.unsort");
551 strcat(tmp5
,"/denied.log");
552 strcat(tmp6
,"/authfail.log.unsort");
555 fprintf(stderr
, "SARG: %s:\nSARG:\n",text
[22]);
556 fprintf(stderr
, "SARG: %35s (-a) = %s\n",text
[23],addr
);
557 fprintf(stderr
, "SARG: %35s (-b) = %s\n",text
[71],uagent
);
558 fprintf(stderr
, "SARG: %35s (-c) = %s\n",text
[69],hexclude
);
559 fprintf(stderr
, "SARG: %35s (-d) = %s\n",text
[24],date
);
560 fprintf(stderr
, "SARG: %35s (-e) = %s\n",text
[41],email
);
561 fprintf(stderr
, "SARG: %35s (-f) = %s\n",text
[70],ConfigFile
);
562 if(strcmp(df
,"e") == 0)
563 fprintf(stderr
, "SARG: %35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
564 if(strcmp(df
,"u") == 0)
565 fprintf(stderr
, "SARG: %35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
566 if(strcmp(df
,"w") == 0)
567 fprintf(stderr
, "SARG: %35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
569 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[1]);
571 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[2]);
572 fprintf(stderr
, "SARG: %35s (-l) = %s\n",text
[37],arq
);
573 if(strcmp(Ip2Name
,"yes") == 0)
574 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[1]);
576 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[2]);
577 fprintf(stderr
, "SARG: %35s (-o) = %s\n",text
[38],outdir
);
578 if(strcmp(UserIp
,"yes") == 0)
579 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[1]);
581 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[2]);
582 fprintf(stderr
, "SARG: %35s (-s) = %s\n",text
[30],site
);
583 fprintf(stderr
, "SARG: %35s (-t) = %s\n",text
[31],hm
);
584 fprintf(stderr
, "SARG: %35s (-u) = %s\n",text
[32],us
);
585 fprintf(stderr
, "SARG: %35s (-w) = %s\n",text
[34],tmp
);
587 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[1]);
589 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[2]);
591 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[1]);
593 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[2]);
594 fprintf(stderr
, "SARG:\n");
598 printf("%s:\nSARG:\n",text
[22]);
599 printf("%35s (-a) = %s\n",text
[23],addr
);
600 printf("%35s (-b) = %s\n",text
[71],uagent
);
601 printf("%35s (-c) = %s\n",text
[69],hexclude
);
602 printf("%35s (-d) = %s\n",text
[24],date
);
603 printf("%35s (-e) = %s\n",text
[41],email
);
604 printf("%35s (-f) = %s\n",text
[70],ConfigFile
);
605 if(strcmp(df
,"e") == 0)
606 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
607 if(strcmp(df
,"u") == 0)
608 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
609 if(strcmp(df
,"w") == 0)
610 printf("%35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
612 printf("%35s (-i) = %s\n",text
[28],text
[1]);
614 printf("%35s (-i) = %s\n",text
[28],text
[2]);
615 printf("%35s (-l) = %s\n",text
[37],arq
);
616 if(strcmp(Ip2Name
,"yes") == 0)
617 printf("%35s (-n) = %s\n",text
[65],text
[1]);
619 printf("%35s (-n) = %s\n",text
[65],text
[2]);
620 printf("%35s (-o) = %s\n",text
[38],outdir
);
621 if(strcmp(UserIp
,"yes") == 0)
622 printf("%35s (-p) = %s\n",text
[29],text
[1]);
624 printf("%35s (-p) = %s\n",text
[29],text
[2]);
625 printf("%35s (-s) = %s\n",text
[30],site
);
626 printf("%35s (-t) = %s\n",text
[31],hm
);
627 printf("%35s (-u) = %s\n",text
[32],us
);
628 printf("%35s (-w) = %s\n",text
[34],tmp
);
630 printf("%35s (-x) = %s\n",text
[35],text
[1]);
632 printf("%35s (-x) = %s\n",text
[35],text
[2]);
634 printf("%35s (-z) = %s\n",text
[36],text
[1]);
636 printf("%35s (-z) = %s\n",text
[36],text
[2]);
637 printf("sarg %s: %s\n",text
[73],VERSION
);
638 printf("Language=%s\n\n",text
[3]);
642 debuga("sarg %s: %s",text
[73],VERSION
);
644 if (Ulimit
[0] != '\0') {
648 #if defined(RLIMIT_NOFILE)
649 getrlimit (RLIMIT_NOFILE
, &rl
);
650 #elif defined(RLIMIT_OFILE)
651 getrlimit (RLIMIT_OFILE
, &rl
);
653 #warning "No rlimit resource for the number of open files"
658 rl
.rlim_cur
= atol(Ulimit
);
659 rl
.rlim_max
= atol(Ulimit
);
660 #if defined(RLIMIT_NOFILE)
661 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
662 #elif defined(RLIMIT_OFILE)
663 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
665 #warning "No rlimit resource for the number of open files"
668 debuga("setrlimit error - %s\n",strerror(errno
));
672 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
675 read_usertab(UserTabFile
);
677 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
678 bool_ShowReadStatistics
= ( strcmp(ShowReadStatistics
,"yes") == 0 ) ;
681 strcpy(arq
,warq
[iarq
]);
687 debuga("%s: %s",text
[7],arq
);
689 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
690 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq
,strerror(errno
));
693 fgets(bufz
,sizeof(bufz
),fp_in
);
694 if(!isalog
&& strncmp(bufz
,"#Software: Mic",14) == 0) isalog
++;
696 if(strncmp(bufz
,"*** SARG Log ***",16) == 0) {
697 if (getword(val2
,sizeof(val2
),arqtt
,'-')<0 || getword(val2
,sizeof(val2
),arqtt
,'_')<0 ||
698 getword(val3
,sizeof(val3
),arqtt
,'-')<0 || getword(val3
,sizeof(val3
),arqtt
,'_')<0) {
699 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
702 sprintf(period
,"%s-%s",val2
,val3
);
704 } else fseek(fp_in
, 0, SEEK_SET
);
706 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
) {
707 if(access(ParsedOutputLog
,R_OK
) != 0) {
708 sprintf(csort
,"%s",ParsedOutputLog
);
711 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
712 if((fp_log
=MY_FOPEN(arq_log
,"w"))==NULL
) {
713 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq_log
,strerror(errno
));
716 fputs("*** SARG Log ***\n",fp_log
);
719 if(strstr(ReportType
,"denied") != 0) {
720 if((fp_denied
=MY_FOPEN(tmp4
,"w"))==NULL
) {
721 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp4
,strerror(errno
));
726 if(DataFile
[0]=='\0') {
727 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
728 if((fp_authfail
=MY_FOPEN(tmp6
,"w"))==NULL
) {
729 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp6
,strerror(errno
));
735 // pre-Read the file only if I have to show stats
736 if(bool_ShowReadStatistics
) {
741 while( fgets(bufz
,sizeof(bufz
),fp_in
) != NULL
) recs1
++;
743 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\r",recs1
,(float) 0);
747 while(fgets(bufz
,sizeof(bufz
),fp_in
)!=NULL
) {
749 if( bool_ShowReadStatistics
&& ! --OutputNonZero
) {
751 perc
= perc
/ recs1
;
752 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\r",recs1
,perc
);
754 OutputNonZero
= REPORT_EVERY_X_LINES
;
756 if(strlen(bufz
) > MAXLEN
-1) continue;
757 if(!bufz
[0]) continue;
758 if(strstr(bufz
,"HTTP/0.0") != 0) continue;
759 if(strstr(bufz
,"logfile turned over") != 0) continue;
760 if(bufz
[0] == ' ') continue;
761 if(strlen(bufz
) < 58) continue;
763 // Record only hours usage which is required
764 tt
= (time_t) strtoul( bufz
, NULL
, 10 );
765 t
= localtime( &tt
);
767 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
768 sizeof( int ), compar
) == NULL
)
771 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
772 sizeof( int ), compar
) == NULL
)
777 if(strlen(ExcludeString
) > 0) {
779 strcpy(html
,ExcludeString
);
780 while(strstr(html
,":") != 0) {
781 if (getword_multisep(val1
,sizeof(val1
),html
,':')<0) {
782 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
785 if((str
=(char *) strstr(warea
,val1
)) != (char *) NULL
)
788 if((str
=(char *) strstr(warea
,html
)) != (char *) NULL
)
791 if(exstring
) continue;
794 if ((str
= strchr(bufz
, '\n')) != NULL
)
795 *str
= '\0'; /* strip \n */
800 printf("BUF=%s\n",bufz
);
802 if(!sarglog
&& !isalog
) {
803 if (getword(data
,sizeof(data
),bufz
,' ')<0) {
804 printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
807 if((str
=(char *) strstr(data
, ".")) != (char *) NULL
) {
808 if((str
=(char *) strstr(str
+1, ".")) != (char *) NULL
) {
812 if (getword(user
,sizeof(user
),bufz
,' ')<0 || getword(none
,sizeof(none
),bufz
,' ')<0) {
813 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
817 if (getword(none
,sizeof(none
),bufz
,' ')<0 || getword(user
,sizeof(user
),bufz
,' ')<0) {
818 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
822 if (getword(data
,sizeof(data
),bufz
,']')<0 || getword(fun
,sizeof(fun
),bufz
,'"')<0 ||
823 getword(fun
,sizeof(fun
),bufz
,' ')<0 || getword(url
,sizeof(url
),bufz
,' ')<0 ||
824 getword(code2
,sizeof(code2
),bufz
,' ')<0 || getword(code2
,sizeof(code2
),bufz
,' ')<0 ||
825 getword(tam
,sizeof(tam
),bufz
,' ')<0) {
826 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
829 if((str
=(char *) strstr(bufz
, " ")) != (char *) NULL
) {
830 if (getword(code
,sizeof(code
),bufz
,' ')<0) {
831 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
835 else strcpy(code
,bufz
);
837 if ((str
= strchr(code
, ':')) != NULL
)
840 if(strcmp(tam
,"\0") == 0)
849 if (getword(elap
,sizeof(elap
),bufz
,' ')<0) {
850 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
853 while(strcmp(elap
,"") == 0 && strlen(bufz
) > 0)
854 if (getword(elap
,sizeof(elap
),bufz
,' ')<0) {
855 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
858 if(strlen(elap
) < 1) continue;
859 if (getword(ip
,sizeof(ip
),bufz
,' ')<0){
860 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
863 if (getword(code
,sizeof(code
),bufz
,' ')<0){
864 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
867 if (getword(tam
,sizeof(tam
),bufz
,' ')<0){
868 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
871 if (getword(fun
,sizeof(fun
),bufz
,' ')<0){
872 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
875 if (getword(url
,sizeof(url
),bufz
,' ')<0){
876 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
879 // while (strstr(bufz,"%20") != 0) {
880 // getword(warea,bufz,' ');
881 // strcat(url,warea);
883 if (getword(user
,sizeof(user
),bufz
,' ')<0){
884 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
890 if (getword(data
,sizeof(data
),bufz
,' ')<0){
891 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
894 if (getword(hora
,sizeof(hora
),bufz
,' ')<0) {
895 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
898 if (getword(user
,sizeof(user
),bufz
,' ')<0) {
899 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
902 if (getword(ip
,sizeof(ip
),bufz
,' ')<0) {
903 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
906 if (getword(url
,sizeof(url
),bufz
,' ')<0){
907 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
910 if (getword(tam
,sizeof(tam
),bufz
,' ')<0){
911 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
914 if (getword(code
,sizeof(code
),bufz
,' ')<0){
915 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
918 if (getword(elap
,sizeof(elap
),bufz
,' ')<0){
919 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
922 if (getword(smartfilter
,sizeof(smartfilter
),bufz
,' ')<0){
923 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
928 if (getword(val1
,sizeof(val1
),bufz
,' ')<0){
929 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
933 while(bufz
[0] != '\0') {
934 if (getword(val1
,sizeof(val1
),bufz
,'\t')<0){
935 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
938 if(strcmp(val1
,"c-ip") == 0) i1
=i0
;
939 if(strcmp(val1
,"cs-username") == 0) i2
=i0
;
940 if(strcmp(val1
,"date") == 0) i3
=i0
;
941 if(strcmp(val1
,"time") == 0) i4
=i0
;
942 if(strcmp(val1
,"time-taken") == 0) i5
=i0
;
943 if(strcmp(val1
,"sc-bytes") == 0) i6
=i0
;
944 if(strcmp(val1
,"cs-uri") == 0) i7
=i0
;
945 if(strcmp(val1
,"sc-status") == 0) i8
=i0
;
949 // not the line we are looking for
953 fgets(bufz
,sizeof(bufz
),fp_in
);
954 for (x
=0 ; x
<i0
; x
++) {
955 if (getword3(val1
,sizeof(val1
),bufz
,'\t')<0) {
956 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
960 if (strlen(val1
)>=sizeof(ip
)) {
961 printf("SARG: Maybe you have a broken IP in your %s file.\n",arq
);
966 if (strlen(val1
)>=sizeof(user
)) {
967 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
972 if (strlen(val1
)>=sizeof(data
)) {
973 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
978 if (strlen(val1
)>=sizeof(hora
)) {
979 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
984 if (strlen(val1
)>=sizeof(elap
)) {
985 printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq
);
990 if (strlen(val1
)>=sizeof(tam
)) {
991 printf("SARG: Maybe you have a broken download size in your %s file.\n",arq
);
996 if (strlen(val1
)>=sizeof(url
)) {
997 printf("SARG: Maybe you have a broken URL in your %s file.\n",arq
);
1002 if (strlen(val1
)>=sizeof(code
)) {
1003 printf("SARG: Maybe you have a broken access code in your %s file.\n",arq
);
1010 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1011 sprintf(val1
,"DENIED/%s",code
);
1014 if (getword(ano
,sizeof(ano
),data
,'-')<0){
1015 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1018 if (getword(mes
,sizeof(mes
),data
,'-')<0){
1019 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1023 conv_month_name(mes
);
1024 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1027 if(strlen(user
) > 150) {
1028 if (debugm
) printf("User too long: %s\n",user
);
1034 if(IncludeUsers
[0] != '\0') {
1035 sprintf(val1
,":%s:",user
);
1036 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1041 if (debugm
) printf("Excluded code: %s\n",code
);
1046 if(testvaliduserchar(user
))
1049 if(strstr(user
,"%20") != 0) {
1050 if (getword(w
,sizeof(w
),user
,'%')<0) {
1051 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1057 while(strstr(user
,"%5c") != 0) {
1058 if (getword_multisep(w
,sizeof(w
),user
,'%')<0){
1059 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1062 strcpy(wuser
,user
+2);
1063 sprintf(user
,"%s.%s",w
,wuser
);
1066 for(str
=user
; *str
; str
++) {
1067 if(*str
=='.') dotinuser
++;
1068 if(*str
=='?' || *str
=='.' || *str
==':' || *str
=='/' || *str
=='\\')
1073 if(strncmp(NtlmUserFormat
,"user",4) == 0) {
1074 if(strchr(user
,'_') != 0)
1075 if (getword_multisep(warea
,sizeof(warea
),user
,'_')<0){
1076 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1079 if(strchr(user
,'+') != 0)
1080 if (getword_multisep(warea
,sizeof(warea
),user
,'+')<0){
1081 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1086 if(strstr(ReportType
,"denied") != 0)
1089 download_flag
=is_download_suffix(url
);
1090 if (download_flag
) {
1091 strcpy(download_url
,url
);
1095 if (strchr(url
,'/')) {
1096 // remove any protocol:// at the beginning of the URL
1097 if (getword(w
,sizeof(w
),url
,'/')<0){
1098 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1101 if (getword(w
,sizeof(w
),url
,'/')<0){
1102 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1105 if (!strchr(url
,'/')) {
1106 if (debugm
) printf("URL without directory: %s\n",url
);
1112 if(strcmp(LongUrl
,"no") == 0) {
1113 char *endofhost
=strchr(url
,'/');
1116 if(strlen(url
) > 512 && (endofhost
=strchr(url
,'%')) != NULL
) {
1122 if(!common
&& !isalog
) {
1126 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1127 if(strncmp(df
,"u",1) == 0)
1128 strftime(tbuf
, sizeof(tbuf
), "%Y%b%d", t
);
1129 if(strncmp(df
,"e",1) == 0)
1130 strftime(tbuf
, sizeof(tbuf
), "%d%b%Y", t
);
1131 if(strncmp(df
,"w",1) == 0) {
1132 strcpy(IndexTree
,"file");
1133 strftime(tbuf
, sizeof(tbuf
), "%Y.%U", t
);
1136 strftime(wdata
, sizeof(wdata
), "%Y%m%d", t
);
1139 if(strncmp(df
,"u",1)==0)
1140 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
1142 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1143 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1145 strcpy(wtemp
,data
+1);
1146 if (getword_multisep(data
,sizeof(data
),wtemp
,':')<0){
1147 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1150 if (getword_multisep(hora
,sizeof(hora
),wtemp
,' ')<0){
1151 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1154 if (getword_multisep(dia
,sizeof(dia
),data
,'/')<0){
1155 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1158 if (getword_multisep(mes
,sizeof(mes
),data
,'/')<0){
1159 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1162 if (getword_multisep(ano
,sizeof(ano
),data
,'/')<0){
1163 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1167 if(strcmp(df
,"u") == 0)
1168 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",ano
,mes
,dia
);
1169 if(strcmp(df
,"e") == 0)
1170 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",dia
,mes
,ano
);
1171 builddia(dia
,mes
,ano
,df
,wdata
);
1175 if (getword_multisep(mes
,sizeof(mes
),data
,'/')<0){
1176 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1179 if (getword_multisep(dia
,sizeof(dia
),data
,'/')<0){
1180 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1183 if (getword_multisep(ano
,sizeof(ano
),data
,0)<0){
1184 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1190 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1194 if(strcmp(user
,us
)==0)
1201 if(addr
[0] != '\0'){
1202 if(strcmp(addr
,ip
)==0)
1206 // l=vhexclude(excludefile,ip);
1207 l
=vhexclude(excludefile
,url
);
1209 if (debugm
) printf("Excluded site: %s\n",url
);
1216 if(date
[0] != '\0'){
1217 if(idata
>= dfrom
&& idata
<= duntil
)
1227 if (getword_multisep(warea
,sizeof(warea
),whm
,':')<0){
1228 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1231 strncat(hmr
,warea
,2);
1236 if(atoi(hmr
) >= atoi(hm
) && atoi(hmr
) <= atoi(hmf
))
1241 if(site
[0] != '\0'){
1242 if(strstr(url
,site
)!=0)
1250 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1251 if(strcmp(RecordsWithoutUser
,"ip") == 0)
1253 if(strcmp(RecordsWithoutUser
,"ignore") == 0)
1255 if(strcmp(RecordsWithoutUser
,"everybody") == 0)
1256 strcpy(user
,"everybody");
1260 subs(user
,sizeof(user
),"_",".");
1265 sprintf(wuser
,":%s:",user
);
1266 if(strstr(userfile
, wuser
) == 0)
1272 l
=vuexclude(excludeuser
,user
);
1274 if (debugm
) printf("Excluded user: %s\n",user
);
1285 if(l
&& max_elapsed
) {
1286 if(atol(elap
)>max_elapsed
) {
1293 if(strcmp(user
,"-") !=0 && url
[0] != '\0' && strcmp(user
," ") !=0 && strcmp(user
,"") !=0 && strcmp(user
,":") !=0){
1294 if((str
=(char *) strstr(bufz
, "[SmartFilter:")) != (char *) NULL
) {
1295 str
[strlen(str
)-1]='\0';
1296 sprintf(smartfilter
,"\"%s\"",str
+1);
1297 } else sprintf(smartfilter
,"\"\"");
1299 sprintf(bufz
, "%s %s %s %s %s %s %s %s %s\n",dia
,hora
,user
,ip
,url
,tam
,code
,elap
,smartfilter
);
1301 #ifdef LEGACY_WRITE_USER
1302 sprintf(tmp3
,"%s/sarg/%s.unsort",tmp
,user
);
1303 if((fp_ou
=MY_FOPEN(tmp3
,"a"))==NULL
) {
1304 fprintf(stderr
, "%s: (zzzlog) %s: %s - %s\n",argv
[0],text
[9],tmp3
,strerror(errno
));
1310 if ( strcmp ( user
, sz_Last_User
) != 0 ) {
1311 if ( fp_Write_User
)
1312 fclose( fp_Write_User
) ;
1313 sprintf (tmp3
, "%s/sarg/%s.unsort", tmp
, user
);
1315 if ((fp_Write_User
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1316 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1319 strcpy( sz_Last_User
, user
) ;
1321 fputs (bufz
, fp_Write_User
);
1324 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
)
1327 #ifdef LEGACY_WRITE_USER
1332 if(download_flag
&& strstr(code
,"DENIED") == 0) {
1334 sprintf(bufz
, "%s %s %s %s %s\n",dia
,hora
,user
,ip
,download_url
);
1336 #ifdef LEGACY_WRITE_DOWNLOAD
1337 sprintf(tmp3
,"%s/sarg/download.unsort",tmp
);
1338 if((fp_ou
=MY_FOPEN(tmp3
,"a"))==NULL
) {
1339 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[9],tmp3
,strerror(errno
));
1345 if ( ! fp_Download_Unsort
) {
1346 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1347 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1351 fputs (bufz
, fp_Download_Unsort
);
1355 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
1356 if(strstr(code
,"DENIED/403") != 0) {
1357 fprintf(fp_denied
, "%s %s %s %s %s\n",dia
,hora
,user
,ip
,urly
);
1360 if(strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0) {
1362 fprintf(fp_authfail
, "%s %s %s %s %s\n",dia
,hora
,user
,ip
,urly
);
1367 if((!totper
|| idata
<mindate
) && !sarglog
){
1370 sprintf(period
,"%s-",tbuf
);
1371 sprintf(per_hour
,"%s-",tbuf2
);
1373 fixper(tbuf
, period
, cduntil
);
1375 debugaz("tbuf",tbuf
);
1376 debugaz("period",period
);
1382 printf("IP=\t%s\n",ip
);
1383 printf("USER=\t%s\n",user
);
1384 printf("ELAP=\t%s\n",elap
);
1385 printf("DATE=\t%s\n",dia
);
1386 printf("TIME=\t%s\n",hora
);
1387 printf("FUNC=\t%s\n",fun
);
1388 printf("URL=\t%s\n",url
);
1389 printf("CODE=\t%s\n",code
);
1390 printf("LEN=\t%s\n",tam
);
1394 if( bool_ShowReadStatistics
)
1395 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\n",recs1
, (float) 100 );
1398 if ( fp_Download_Unsort
)
1399 fclose (fp_Download_Unsort
);
1402 fclose (fp_Write_User
);
1405 debuga(" %s: %ld, %s: %ld, %s: %ld",text
[10],totregsl
,text
[11],totregsg
,text
[68],totregsx
);
1407 if((common_log
) && (squid_log
))
1408 debuga("%s",text
[12]);
1410 if((common_log
) && (!squid_log
))
1411 debuga("%s",text
[13]);
1413 if((!common_log
) && (squid_log
))
1414 debuga("%s",text
[14]);
1417 debuga("%s",text
[124]);
1419 if((!common_log
) && (!squid_log
) && (!sarglog
) && (!isalog
)) {
1421 fprintf(stderr
, "SARG: %s\n",text
[16]);
1422 fprintf(stderr
, "SARG: %s\n",text
[21]);
1423 } else fprintf(stderr
, "SARG: %s\n",text
[15]);
1424 bzero(msg
,sizeof(msg
));
1430 fclose(fp_authfail
);
1439 fprintf(stderr
, "SARG: %s\n",text
[16]);
1440 fprintf(stderr
, "SARG: %s\n",text
[21]);
1446 fclose(fp_authfail
);
1450 if(date
[0] == '\0' && !sarglog
) {
1451 strcat(period
,tbuf
);
1452 strcat(per_hour
,tbuf2
);
1456 debugaz("data",dia
);
1457 debugaz("tbuf",tbuf
);
1458 debugaz("period",period
);
1462 debuga("%s: %s",text
[17],period
);
1469 fclose(fp_authfail
);
1471 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
) {
1473 strcpy(val1
,period
);
1474 if (getword_multisep(val2
,sizeof(val2
),val1
,'-')<0){
1475 printf("SARG: Maybe you have a broken date range definition.\n");
1478 if (getword_multisep(val3
,sizeof(val3
),per_hour
,'-')<0){
1479 printf("SARG: Maybe you have a broken date range definition.\n");
1482 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,val3
,val1
,per_hour
);
1483 rename(arq_log
,val4
);
1484 strcpy(arq_log
,val4
);
1486 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0) {
1487 sprintf(val1
,"%s %s",ParsedOutputLogCompress
,arq_log
);
1488 cstatus
=system(val1
);
1489 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1490 fprintf(stderr
, "SARG: command return status %d\n",WEXITSTATUS(cstatus
));
1491 fprintf(stderr
, "SARG: command: %s\n",val1
);
1497 debuga("%s %s",text
[123],arq_log
);
1500 if(strstr(ReportType
,"denied") != 0) {
1501 sprintf(csort
,"sort -T %s -k 3,3 -k 5,5 -o '%s' '%s'",tmp
,tmp5
,tmp4
);
1502 cstatus
=system(csort
);
1503 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1504 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
1505 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
1511 sort_users_log(tmp
, debug
);
1513 if(DataFile
[0] != '\0')
1519 if(strstr(ReportType
,"denied") != 0)
1522 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1525 // else unlink(arq);
1527 if(strcmp(tmp
,"/tmp") != 0) {
1528 sprintf(tmp4
,"rm -rf %s",tmp
);
1532 free_excludecodes();
1541 debuga("%s",text
[21]);
1548 static void getusers(const char *pwdfile
, int debug
)
1554 unsigned long int nreg
=0;
1557 debuga("%s: %s",text
[60],pwdfile
);
1559 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1560 fprintf(stderr
, "SARG: (getusers) %s: %s - %s\n",text
[45],pwdfile
,strerror(errno
));
1564 fseek(fp_usr
, (off_t
)0, SEEK_END
);
1565 nreg
= ftell(fp_usr
);
1567 printf("SARG: Cannot get the size of file %s",pwdfile
);
1571 fseek(fp_usr
, (off_t
)0, SEEK_SET
);
1573 if((userfile
=(char *) malloc(nreg
))==NULL
){
1574 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1578 bzero(userfile
,nreg
);
1579 strcpy(userfile
,":");
1581 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1582 str
=strchr(buf
,':');
1584 printf("SARG: You have an invalid user in your %s file.\n",pwdfile
);
1588 strcat(userfile
,buf
);
1597 static void gethexclude(const char *hexfile
, int debug
)
1602 unsigned long int nreg
=0;
1605 debuga("%s: %s",text
[67],hexfile
);
1607 if ((fp_ex
= fopen(hexfile
, "r")) == NULL
) {
1608 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],hexfile
,strerror(errno
));
1612 fseek(fp_ex
, (off_t
)0, SEEK_END
);
1613 nreg
= ftell(fp_ex
);
1615 printf("SARG: Cannot get the size of file %s",hexfile
);
1619 fseek(fp_ex
, (off_t
)0, SEEK_SET
);
1621 if((excludefile
=(char *) malloc(nreg
))==NULL
){
1622 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1626 bzero(excludefile
,nreg
);
1628 while(fgets(buf
,sizeof(buf
),fp_ex
)!=NULL
){
1629 if(strchr(buf
,'#') != NULL
)
1632 strcat(excludefile
,buf
);
1633 strcat(excludefile
," ");
1636 strcat(excludefile
,"*END* ");
1644 static void getuexclude(const char *uexfile
, int debug
)
1649 unsigned long int nreg
=0;
1652 debuga("%s: %s",text
[67],uexfile
);
1654 if ((fp_ex
= fopen(uexfile
, "r")) == NULL
) {
1655 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],uexfile
,strerror(errno
));
1659 fseek(fp_ex
, (off_t
)0, SEEK_END
);
1660 nreg
= ftell(fp_ex
);
1662 printf("SARG: Cannot get the size of file %s",uexfile
);
1666 fseek(fp_ex
, (off_t
)0, SEEK_SET
);
1668 if((excludeuser
=(char *) malloc(nreg
))==NULL
){
1669 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1673 bzero(excludeuser
,nreg
);
1675 while(fgets(buf
,sizeof(buf
),fp_ex
)!=NULL
){
1676 if(strchr(buf
,'#') != NULL
)
1679 strcat(excludeuser
,buf
);
1680 strcat(excludeuser
," ");
1683 strcat(excludeuser
,"*END* ");