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"
28 #define LEGACY_WRITE_USER
29 #define LEGACY_WRITE_DOWNLOAD
30 #define REPORT_EVERY_X_LINES 5000
37 char sz_Last_User
[ MAXLEN
] = { 0 } ;
38 int bool_ShowReadStatistics
;
40 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
41 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
42 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
44 void getusers(char *pwdfile
, int debug
);
45 void gethexclude(char *hexfile
, int debug
);
46 void getuexclude(char *uexfile
, int debug
);
48 int compar( const void *, const void * );
50 #define _FILE_OFFSET_BITS 64
57 FILE *fp_in
= NULL
, *fp_ou
= NULL
, *fp_denied
, *fp_usr
, *fp_authfail
, *fp_log
;
59 char sz_Download_Unsort
[ 20000 ] ;
60 FILE * fp_Download_Unsort
= NULL
;
61 FILE * fp_Write_User
= NULL
;
76 char smartfilter
[MAXLEN
];
88 char hm
[15], hmf
[15], hmr
[15], whm
[15];
91 char hexclude
[MAXLEN
];
113 int i0
=0,i1
=0,i2
=0,i3
=0,i4
=0,i5
=0,i6
=0,i7
=0,i8
=0;
118 long int max_elapsed
=0;
121 unsigned long nreg
=0;
123 unsigned long recs2
=0;
125 int OutputNonZero
= REPORT_EVERY_X_LINES
;
133 UserAgentLog
[0]='\0';
134 ExcludeHosts
[0]='\0';
135 ExcludeUsers
[0]='\0';
143 ExternalCSSFile
[0]='\0';
144 SquidGuardLogFormat
[0]='\0';
145 SquidGuardLogAlternate
[0]='\0';
148 strcpy(AccessLog
,"/usr/local/squid/var/logs/access.log");
149 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
150 strcpy(GraphDaysBytesBarColor
,"orange");
151 strcpy(BgColor
,"#ffffff");
152 strcpy(TxColor
,"#000000");
153 strcpy(TxBgColor
,"lavender");
154 strcpy(TiColor
,"darkblue");
157 strcpy(LogoTextColor
,"#000000");
158 strcpy(HeaderColor
,"darkblue");
159 strcpy(HeaderBgColor
,"#dddddd");
160 strcpy(LogoTextColor
,"#006699");
161 strcpy(FontSize
,"9px");
162 strcpy(TempDir
,"/tmp");
163 strcpy(OutputDir
,"/var/www/html/squid-reports");
164 strcpy(Ip2Name
,"no");
165 strcpy(DateFormat
,"u");
166 strcpy(OverwriteReport
,"no");
167 strcpy(RemoveTempFiles
,"yes");
168 strcpy(ReplaceIndex
,"index.html");
170 strcpy(RecordsWithoutUser
,"ip");
171 strcpy(UseComma
,"no");
172 strcpy(MailUtility
,"mailx");
173 strcpy(TopSitesNum
,"100");
175 strcpy(TopuserSortField
,"BYTES");
176 strcpy(UserSortField
,"BYTES");
177 strcpy(TopuserSortOrder
,"reverse");
178 strcpy(UserSortOrder
,"reverse");
179 strcpy(TopsitesSortField
,"CONNECT");
180 strcpy(TopsitesSortType
,"D");
181 strcpy(LongUrl
,"no");
182 strcpy(language
,"English");
183 strcpy(FontFace
,"Verdana,Tahoma,Arial");
184 strcpy(datetimeby
,"elap");
185 strcpy(CharSet
,"ISO-8859-1");
186 strcpy(Privacy
,"no");
187 strcpy(PrivacyString
,"***.***.***.***");
188 strcpy(PrivacyStringColor
,"blue");
189 strcpy(SuccessfulMsg
,"yes");
190 strcpy(TopUserFields
,"NUM DATE_TIME USERID CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
191 strcpy(UserReportFields
,"CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
192 strcpy(DataFileDelimiter
,";");
193 strcpy(DataFileFields
,"user;date;time;url;connect;bytes;in_cache;out_cache;elapsed");
194 strcpy(SiteUserTimeDateType
,"table");
195 strcpy(ShowReadStatistics
,"yes");
196 strcpy(IndexSortOrder
,"D");
197 strcpy(ShowSargInfo
,"yes");
198 strcpy(ShowSargLogo
,"yes");
199 strcpy(ParsedOutputLog
,"no");
200 strcpy(ParsedOutputLogCompress
,"/bin/gzip");
201 strcpy(DisplayedValues
,"abbreviation");
202 strcpy(HeaderFontSize
,"9px");
203 strcpy(TitleFontSize
,"11px");
204 strcpy(AuthUserFile
,"/usr/local/sarg/passwd");
205 strcpy(AuthName
,"SARG, Restricted Access");
206 strcpy(AuthType
,"basic");
207 strcpy(Require
,"require user admin %u");
208 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");
209 strcpy(Graphs
,"yes");
210 strcpy(Ulimit
,"20000");
211 strcpy(NtlmUserFormat
,"domainname+username");
212 strcpy(IndexTree
,"file");
213 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
214 strcpy(RealtimeUnauthRec
,"show");
215 strcpy(SquidguardIgnoreDate
,"off");
216 strcpy(DansguardianIgnoreDate
,"off");
217 strcpy(DataFileUrl
,"ip");
218 strcpy(MaxElapsed
,"28800000");
219 strcpy(BytesInSitesUsersReport
,"no");
243 UserInvalidChar
[0]='\0';
245 SquidGuardConf
[0]='\0';
246 DansGuardianConf
[0]='\0';
252 dansguardian_count
=0;
254 DeniedReportLimit
=10;
255 AuthfailReportLimit
=10;
256 DansGuardianReportLimit
=10;
257 SquidGuardReportLimit
=10;
258 DownloadReportLimit
=50;
273 realtime_access_log_lines
=1000;
279 bzero(IncludeUsers
, MAXLEN
);
280 bzero(ExcludeString
, MAXLEN
);
282 for(x
=0; x
<=254; x
++)
285 language_load(language
);
286 strcpy(Title
,text
[88]);
288 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
295 strcpy(uagent
,optarg
);
298 strcpy(hexclude
,optarg
);
302 strcpy(cduntil
,optarg
);
303 if (getword(cdfrom
,sizeof(cdfrom
),cduntil
,'-')<0) {
304 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
307 date_from(date
, cdfrom
, cduntil
);
309 duntil
=atoi(cduntil
);
312 strcpy(email
,optarg
);
315 strcpy(ConfigFile
,optarg
);
328 strcpy(warq
[narq
],optarg
);
332 strcpy(SquidGuardLogAlternate
,optarg
);
341 strcpy(outdir
,optarg
);
353 if(strstr(optarg
,"-") == 0) {
357 if (getword(hm
,sizeof(hm
),optarg
,'-')<0) {
358 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
364 printf("SARG: time period must be MM or MM:SS. Exit.\n");
368 if(strstr(hm
,":") != 0) {
369 if (getword(warea
,sizeof(warea
),hm
,':')<0) {
370 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
373 sprintf(whm
,"%s%s",warea
,hm
);
377 if(strstr(hmf
,":") != 0) {
378 if (getword(warea
,sizeof(warea
),hmf
,':')<0) {
379 printf("SARG: Maybe you have a broken record or garbage in your time range.\n");
382 sprintf(whm
,"%s%s",warea
,hmf
);
405 fprintf(stderr
, "Option -%c require an argument\n",optopt
);
421 if(debug
) debuga("Init");
423 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
424 else if(access(ConfigFile
, R_OK
) != 0) {
425 sprintf(msg
,"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 str2
=(char *)subs(TopUserFields
,"%BYTES","SETYB");
448 strcpy(TopUserFields
,str2
);
450 str2
=(char *)subs(UserReportFields
,"%BYTES","SETYB");
451 strcpy(UserReportFields
,str2
);
454 strcpy(warq
[0],AccessLog
);
458 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
459 convlog(warq
[0], df
, dfrom
, duntil
);
463 if(strcmp(site
,"plit") == 0) {
464 splitlog(warq
[0], df
, dfrom
, duntil
, hexclude
);
468 if(ExcludeCodes
[0] != '\0') {
469 if((excludecode
=(char *) malloc(1024))==NULL
) {
470 fprintf(stderr
, "SARG: %s (1024):\n",text
[59]);
473 bzero(excludecode
,1024);
477 if(access(PasswdFile
, R_OK
) == 0) {
478 getusers(PasswdFile
,debug
);
482 if(hexclude
[0] == '\0')
483 strcpy(hexclude
,ExcludeHosts
);
484 if(strlen(hexclude
) > 0) {
485 if(access(hexclude
, R_OK
) != 0) {
486 sprintf(msg
,"Cannot open exclude_hosts file: %s - %s",hexclude
,strerror(errno
));
490 gethexclude(hexclude
,debug
);
495 if(ReportType
[0] == '\0')
496 strcpy(ReportType
,"topusers topsites users_sites sites_users date_time denied auth_failures site_user_time_date downloads");
498 if(access(ExcludeUsers
, R_OK
) == 0) {
499 getuexclude(ExcludeUsers
,debug
);
505 if(strstr(excludeuser
,"indexonly") != 0)
508 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
509 if(strcmp(Index
,"only") == 0) indexonly
++;
511 if(dns
) strcpy(Ip2Name
,"yes");
513 if(strcmp(UserIp
,"yes") == 0) userip
++;
515 if(strlen(MaxElapsed
)>1) max_elapsed
=atol(MaxElapsed
);
517 if(strlen(outdir
)<1) strcpy(outdir
,OutputDir
);
521 if(arq
[0] == '\0') strcpy(arq
,AccessLog
);
523 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
525 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
526 else strcpy(TempDir
,tmp
);
528 if(df
[0] == '\0') strcpy(df
,DateFormat
);
529 else strcpy(DateFormat
,df
);
533 strcpy(DateFormat
,"u");
536 if(strlen(email
)<1 && strlen(OutputEmail
)>0) strcpy(email
,OutputEmail
);
540 if(strlen(email
) > 0) {
541 sprintf(wtemp2
,"%s/sarg",tmp2
);
543 strcat(tmp2
,"/sarg");
548 strcat(tmp2
,"/sarg.log");
550 sprintf(warea
,"%s/sarg",tmp
);
551 if(access(warea
, R_OK
) == 0) {
552 sprintf(tmp3
,"rm -rf %s",warea
);
556 sprintf(tmp3
,"%s/sarg",tmp
);
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 fprintf(stderr
, "SARG: %35s (-l) = %s\n",text
[37],arq
);
584 if(strcmp(Ip2Name
,"yes") == 0)
585 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[1]);
587 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[2]);
588 fprintf(stderr
, "SARG: %35s (-o) = %s\n",text
[38],outdir
);
589 if(strcmp(UserIp
,"yes") == 0)
590 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[1]);
592 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[2]);
593 fprintf(stderr
, "SARG: %35s (-s) = %s\n",text
[30],site
);
594 fprintf(stderr
, "SARG: %35s (-t) = %s\n",text
[31],hm
);
595 fprintf(stderr
, "SARG: %35s (-u) = %s\n",text
[32],us
);
596 fprintf(stderr
, "SARG: %35s (-w) = %s\n",text
[34],tmp
);
598 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[1]);
600 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[2]);
602 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[1]);
604 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[2]);
605 fprintf(stderr
, "SARG:\n");
609 printf("%s:\nSARG:\n",text
[22]);
610 printf("%35s (-a) = %s\n",text
[23],addr
);
611 printf("%35s (-b) = %s\n",text
[71],uagent
);
612 printf("%35s (-c) = %s\n",text
[69],hexclude
);
613 printf("%35s (-d) = %s\n",text
[24],date
);
614 printf("%35s (-e) = %s\n",text
[41],email
);
615 printf("%35s (-f) = %s\n",text
[70],ConfigFile
);
616 if(strcmp(df
,"e") == 0)
617 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
618 if(strcmp(df
,"u") == 0)
619 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
620 if(strcmp(df
,"w") == 0)
621 printf("%35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
623 printf("%35s (-i) = %s\n",text
[28],text
[1]);
625 printf("%35s (-i) = %s\n",text
[28],text
[2]);
626 printf("%35s (-l) = %s\n",text
[37],arq
);
627 if(strcmp(Ip2Name
,"yes") == 0)
628 printf("%35s (-n) = %s\n",text
[65],text
[1]);
630 printf("%35s (-n) = %s\n",text
[65],text
[2]);
631 printf("%35s (-o) = %s\n",text
[38],outdir
);
632 if(strcmp(UserIp
,"yes") == 0)
633 printf("%35s (-p) = %s\n",text
[29],text
[1]);
635 printf("%35s (-p) = %s\n",text
[29],text
[2]);
636 printf("%35s (-s) = %s\n",text
[30],site
);
637 printf("%35s (-t) = %s\n",text
[31],hm
);
638 printf("%35s (-u) = %s\n",text
[32],us
);
639 printf("%35s (-w) = %s\n",text
[34],tmp
);
641 printf("%35s (-x) = %s\n",text
[35],text
[1]);
643 printf("%35s (-x) = %s\n",text
[35],text
[2]);
645 printf("%35s (-z) = %s\n",text
[36],text
[1]);
647 printf("%35s (-z) = %s\n",text
[36],text
[2]);
648 printf("sarg %s: %s\n",text
[73],VERSION
);
649 printf("Language=%s\n\n",text
[3]);
653 sprintf(msg
,"sarg %s: %s",text
[73],VERSION
);
657 if (strlen(Ulimit
) > 0) {
658 #if defined(RLIMIT_NOFILE)
659 getrlimit (RLIMIT_NOFILE
, &rl
);
660 #else #if defined(RLIMIT_OFILE)
661 getrlimit (RLIMIT_OFILE
, &rl
);
666 if(Ulimit
[0] != '\0') {
667 rl
.rlim_cur
= atol(Ulimit
);
668 rl
.rlim_max
= atol(Ulimit
);
669 #if defined(RLIMIT_NOFILE)
670 if(setrlimit (RLIMIT_NOFILE
, &rl
) == -1) {
671 #else #if defined(RLIMIT_OFILE)
672 if(setrlimit (RLIMIT_OFILE
, &rl
) == -1) {
674 sprintf(msg
,"setrlimit error - %s\n",strerror(errno
));
680 sprintf(msg
,"Maximum file descriptor: cur=%ld max=%ld, changed to cur=%ld max=%ld",l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
685 if (UserTabFile
[0] != '\0') {
687 sprintf(msg
,"%s: %s",text
[86],UserTabFile
);
690 if((fp_usr
=fopen(UserTabFile
,"r"))==NULL
) {
691 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],UserTabFile
,strerror(errno
));
694 nreg
= lseek(fileno(fp_usr
), 0, SEEK_END
);
695 lseek(fileno(fp_usr
), 0, 0);
696 if((userfile
=(char *) malloc(nreg
+100))==NULL
){
697 fprintf(stderr
, "%s ERROR: %s",argv
[0],text
[87]);
700 bzero(userfile
,nreg
+100);
701 strncat(userfile
,":",1);
704 while(fgets(buf
,MAXLEN
,fp_usr
)!=NULL
) {
705 buf
[strlen(buf
)-1]='\0';
706 if(strstr(buf
,"\r") != 0) buf
[strlen(buf
)-1]='\0';
707 if (getword_multisep(bufy
,sizeof(bufy
),buf
,' ')<0) {
708 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",UserTabFile
);
711 for(z1
=0; z1
<=strlen(bufy
); z1
++) {
712 userfile
[z2
]=bufy
[z1
];
715 strncat(userfile
,":",1);
716 for(z1
=0; z1
<=strlen(buf
); z1
++) {
717 userfile
[z2
]=buf
[z1
];
720 strncat(userfile
,":",1);
725 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
726 bool_ShowReadStatistics
= ( strcmp(ShowReadStatistics
,"yes") == 0 ) ;
729 strcpy(arq
,warq
[iarq
]);
735 sprintf(msg
, "%s: %s",text
[7],arq
);
739 #if defined(HAVE_FOPEN64)
740 if((fp_in
=(long)fopen64(arq
,"r"))==NULL
) {
742 if((fp_in
=fopen(arq
,"r"))==NULL
) {
744 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq
,strerror(errno
));
747 fgets(bufz
,sizeof(bufz
),fp_in
);
748 if(!isalog
&& strncmp(bufz
,"#Software: Mic",14) == 0) isalog
++;
750 if(strncmp(bufz
,"*** SARG Log ***",16) == 0) {
751 if (getword(val2
,sizeof(val2
),arqtt
,'-')<0 || getword(val2
,sizeof(val2
),arqtt
,'_')<0 ||
752 getword(val3
,sizeof(val3
),arqtt
,'-')<0 || getword(val3
,sizeof(val3
),arqtt
,'_')<0) {
753 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
756 sprintf(period
,"%s-%s",val2
,val3
);
758 } else lseek(fileno(fp_in
), 0, 0);
760 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
) {
761 if(access(ParsedOutputLog
,R_OK
) != 0) {
762 sprintf(csort
,"%s",ParsedOutputLog
);
765 sprintf(arq_log
,"%s/sarg_temp.log",ParsedOutputLog
);
766 if((fp_log
=fopen(arq_log
,"w"))==NULL
) {
767 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq_log
,strerror(errno
));
770 fputs("*** SARG Log ***\n",fp_log
);
773 if(strstr(ReportType
,"denied") != 0) {
774 if((fp_denied
=fopen(tmp4
,"w"))==NULL
) {
775 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp4
,strerror(errno
));
780 if(DataFile
[0]=='\0') {
781 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
782 if((fp_authfail
=fopen(tmp6
,"w"))==NULL
) {
783 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp6
,strerror(errno
));
789 // pre-Read the file only if I have to show stats
790 if(bool_ShowReadStatistics
) {
795 while( fgets(bufz
,sizeof(bufz
),fp_in
) != NULL
) recs1
++;
797 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\r",recs1
,(float) 0);
801 while(fgets(bufz
,sizeof(bufz
),fp_in
)!=NULL
) {
803 if( bool_ShowReadStatistics
&& ! --OutputNonZero
) {
805 perc
= perc
/ recs1
;
806 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\r",recs1
,perc
);
808 OutputNonZero
= REPORT_EVERY_X_LINES
;
810 if(strlen(bufz
) > MAXLEN
-1) continue;
811 if(!bufz
[0]) continue;
812 if(strstr(bufz
,"HTTP/0.0") != 0) continue;
813 if(strstr(bufz
,"logfile turned over") != 0) continue;
814 if(bufz
[0] == ' ') continue;
815 if(strlen(bufz
) < 58) continue;
817 // Record only hours usage which is required
818 tt
= (time_t) strtoul( bufz
, NULL
, 10 );
819 t
= localtime( &tt
);
821 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
822 sizeof( int ), compar
) == NULL
)
825 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
826 sizeof( int ), compar
) == NULL
)
831 if(strlen(ExcludeString
) > 0) {
833 strcpy(html
,ExcludeString
);
834 while(strstr(html
,":") != 0) {
835 if (getword_multisep(val1
,sizeof(val1
),html
,':')<0) {
836 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
839 if((str
=(char *) strstr(warea
,val1
)) != (char *) NULL
)
842 if((str
=(char *) strstr(warea
,html
)) != (char *) NULL
)
845 if(exstring
) continue;
848 if ((str
= strchr(bufz
, '\n')) != NULL
)
849 *str
= '\0'; /* strip \n */
854 printf("BUF=%s\n",bufz
);
856 if(!sarglog
&& !isalog
) {
857 if (getword(data
,sizeof(data
),bufz
,' ')<0) {
858 printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
861 if((str
=(char *) strstr(data
, ".")) != (char *) NULL
) {
862 if((str
=(char *) strstr(str
+1, ".")) != (char *) NULL
) {
866 if (getword(user
,sizeof(user
),bufz
,' ')<0 || getword(none
,sizeof(none
),bufz
,' ')<0) {
867 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
871 if (getword(none
,sizeof(none
),bufz
,' ')<0 || getword(user
,sizeof(user
),bufz
,' ')<0) {
872 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
876 if (getword(data
,sizeof(data
),bufz
,']')<0 || getword(fun
,sizeof(fun
),bufz
,'"')<0 ||
877 getword(fun
,sizeof(fun
),bufz
,' ')<0 || getword(url
,sizeof(url
),bufz
,' ')<0 ||
878 getword(code2
,sizeof(code2
),bufz
,' ')<0 || getword(code2
,sizeof(code2
),bufz
,' ')<0 ||
879 getword(tam
,sizeof(tam
),bufz
,' ')<0) {
880 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
883 if((str
=(char *) strstr(bufz
, " ")) != (char *) NULL
) {
884 if (getword(code
,sizeof(code
),bufz
,' ')<0) {
885 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
889 else strcpy(code
,bufz
);
891 if ((str
= strchr(code
, ':')) != NULL
)
894 if(strcmp(tam
,"\0") == 0)
903 if (getword(elap
,sizeof(elap
),bufz
,' ')<0) {
904 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
907 while(strcmp(elap
,"") == 0 && strlen(bufz
) > 0)
908 if (getword(elap
,sizeof(elap
),bufz
,' ')<0) {
909 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
912 if(strlen(elap
) < 1) continue;
913 if (getword(ip
,sizeof(ip
),bufz
,' ')<0){
914 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
917 if (getword(code
,sizeof(code
),bufz
,' ')<0){
918 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
921 if (getword(tam
,sizeof(tam
),bufz
,' ')<0){
922 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
925 if (getword(fun
,sizeof(fun
),bufz
,' ')<0){
926 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
929 if (getword(url
,sizeof(url
),bufz
,' ')<0){
930 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
933 // while (strstr(bufz,"%20") != 0) {
934 // getword(warea,bufz,' ');
935 // strcat(url,warea);
937 if (getword(user
,sizeof(user
),bufz
,' ')<0){
938 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
944 if (getword(data
,sizeof(data
),bufz
,' ')<0){
945 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
948 if (getword(hora
,sizeof(hora
),bufz
,' ')<0) {
949 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
952 if (getword(user
,sizeof(user
),bufz
,' ')<0) {
953 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
956 if (getword(ip
,sizeof(ip
),bufz
,' ')<0) {
957 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
960 if (getword(url
,sizeof(url
),bufz
,' ')<0){
961 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
964 if (getword(tam
,sizeof(tam
),bufz
,' ')<0){
965 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
968 if (getword(code
,sizeof(code
),bufz
,' ')<0){
969 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
972 if (getword(elap
,sizeof(elap
),bufz
,' ')<0){
973 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
976 if (getword(smartfilter
,sizeof(smartfilter
),bufz
,' ')<0){
977 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
982 if (getword(val1
,sizeof(val1
),bufz
,' ')<0){
983 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
986 while(strstr(bufz
,"\t") != 0) {
987 if (getword(val1
,sizeof(val1
),bufz
,'\t')<0){
988 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
992 if(strcmp(val1
,"c-ip") == 0) i1
=i0
;
993 if(strcmp(val1
,"cs-username") == 0) i2
=i0
;
994 if(strcmp(val1
,"date") == 0) i3
=i0
;
995 if(strcmp(val1
,"time") == 0) i4
=i0
;
996 if(strcmp(val1
,"time-taken") == 0) i5
=i0
;
997 if(strcmp(val1
,"sc-bytes") == 0) i6
=i0
;
998 if(strcmp(val1
,"cs-uri") == 0) i7
=i0
;
999 if(strcmp(val1
,"sc-status") == 0) i8
=i0
;
1002 fgets(bufz
,sizeof(bufz
),fp_in
);
1004 for(x
=0; x
<=i1
-1; x
++) {
1005 if (getword3(ip
,sizeof(ip
),val1
,'\t')<0) {
1006 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1011 for(x
=0; x
<=i2
-1; x
++) {
1012 if (getword3(user
,sizeof(user
),val1
,'\t')<0) {
1013 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1018 for(x
=0; x
<=i3
-1; x
++) {
1019 if (getword3(data
,sizeof(data
),val1
,'\t')<0) {
1020 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1025 for(x
=0; x
<=i4
-1; x
++) {
1026 if (getword3(hora
,sizeof(hora
),val1
,'\t')<0) {
1027 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1032 for(x
=0; x
<=i5
-1; x
++) {
1033 if (getword3(elap
,sizeof(elap
),val1
,'\t')<0) {
1034 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1039 for(x
=0; x
<=i6
-1; x
++) {
1040 if (getword3(tam
,sizeof(tam
),val1
,'\t')<0) {
1041 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1046 for(x
=0; x
<=i7
-1; x
++) {
1047 if (getword3(url
,sizeof(url
),val1
,'\t')<0) {
1048 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1053 for(x
=0; x
<=i8
-1; x
++) {
1054 if (getword3(code
,sizeof(code
),val1
,'\t')<0) {
1055 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1060 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1061 sprintf(val1
,"DENIED/%s",code
);
1064 if (getword(ano
,sizeof(ano
),data
,'-')<0){
1065 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1068 if (getword(mes
,sizeof(mes
),data
,'-')<0){
1069 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1073 conv_month_name(mes
);
1074 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1077 if(strlen(user
) > 150) {
1083 if(strlen(IncludeUsers
) > 0) {
1084 sprintf(val1
,":%s:",user
);
1085 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1096 if(testvaliduserchar(user
))
1099 if(strstr(user
,"%20") != 0) {
1100 if (getword(w
,sizeof(w
),user
,'%')<0) {
1101 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1107 while(strstr(user
,"%5c") != 0) {
1108 if (getword_multisep(w
,sizeof(w
),user
,'%')<0){
1109 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1112 strcpy(wuser
,user
+2);
1113 sprintf(user
,"%s.%s",w
,wuser
);
1117 for(z1
=0; z1
<strlen(str
); z1
++) {
1118 if(isalnum(str
[z1
]) || ispunct(str
[z1
])) {
1119 if(str
[z1
]=='.') dotinuser
++;
1120 if(str
[z1
]=='?' || str
[z1
]=='.' || str
[z1
]==':' || str
[z1
]=='/' || str
[z1
]=='\\')
1126 if(strncmp(NtlmUserFormat
,"user",4) == 0) {
1127 if(strstr(user
,"_") != 0)
1128 if (getword_multisep(warea
,sizeof(warea
),user
,'_')<0){
1129 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1132 if(strstr(user
,"+") != 0)
1133 if (getword_multisep(warea
,sizeof(warea
),user
,'+')<0){
1134 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1139 if(strstr(ReportType
,"denied") != 0)
1142 if(strlen(DownloadSuffix
)) {
1145 if(strncmp(url
+strlen(url
)-4,".",1) == 0)
1146 strcpy(suffix
,url
+strlen(url
)-3);
1147 else strcpy(suffix
,url
+strlen(url
)-4);
1148 if(strstr(DownloadSuffix
,suffix
) != 0) {
1149 strcpy(download_url
,url
);
1155 if (strchr(url
,'/')) {
1156 if (getword(w
,sizeof(w
),url
,'/')<0){
1157 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1160 if (getword(w
,sizeof(w
),url
,'/')<0){
1161 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1164 if (!strchr(url
,'/')) {
1170 if(strcmp(LongUrl
,"no") == 0) {
1171 if (getword_multisep(w
,sizeof(w
),url
,'/')<0){
1172 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1176 if(strlen(url
) > 512 && strstr(url
,"%") != 0) {
1177 if (getword_multisep(w
,sizeof(w
),url
,'%')<0){
1178 printf("SARG: Maybe you have a broken url in your %s file.\n",arq
);
1186 if(!common
&& !isalog
) {
1190 strftime(tbuf2
, 127, "%H%M", t
);
1191 if(strncmp(df
,"u",1) == 0)
1192 strftime(tbuf
, 127, "%Y%b%d", t
);
1193 if(strncmp(df
,"e",1) == 0)
1194 strftime(tbuf
, 127, "%d%b%Y", t
);
1195 if(strncmp(df
,"w",1) == 0) {
1196 strcpy(IndexTree
,"file");
1197 strftime(tbuf
, 127, "%Y.%U", t
);
1200 strftime(dia
, 127, "%d/%m/%Y", t
);
1201 strftime(wdata
, 127, "%Y%m%d", t
);
1205 if(strncmp(df
,"u",1)==0)
1206 strftime(dia
, 127, "%m/%d/%Y", t
);
1207 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1209 strcpy(wtemp
,data
+1);
1210 if (getword_multisep(data
,sizeof(data
),wtemp
,':')<0){
1211 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1214 if (getword_multisep(hora
,sizeof(hora
),wtemp
,' ')<0){
1215 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1218 if (getword_multisep(dia
,sizeof(dia
),data
,'/')<0){
1219 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1222 if (getword_multisep(mes
,sizeof(mes
),data
,'/')<0){
1223 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1226 if (getword_multisep(ano
,sizeof(ano
),data
,'/')<0){
1227 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1231 if(strcmp(df
,"u") == 0)
1232 sprintf(tbuf
,"%s%s%s",ano
,mes
,dia
);
1233 if(strcmp(df
,"e") == 0)
1234 sprintf(tbuf
,"%s%s%s",dia
,mes
,ano
);
1235 builddia(dia
,mes
,ano
,df
,wdata
);
1239 if (getword_multisep(mes
,sizeof(mes
),data
,'/')<0){
1240 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1243 if (getword_multisep(dia
,sizeof(dia
),data
,'/')<0){
1244 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1247 if (getword_multisep(ano
,sizeof(ano
),data
,0)<0){
1248 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1254 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1258 if(strcmp(user
,us
)==0)
1264 if(strcmp(addr
,ip
)==0)
1268 // l=vhexclude(excludefile,ip);
1269 l
=vhexclude(excludefile
,url
);
1276 if(strlen(date
) > 0){
1277 if(idata
>= dfrom
&& idata
<= duntil
)
1287 if (getword_multisep(warea
,sizeof(warea
),whm
,':')<0){
1288 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1291 strncat(hmr
,warea
,2);
1296 if(atoi(hmr
) >= atoi(hm
) && atoi(hmr
) <= atoi(hmf
))
1302 if(strstr(url
,site
)!=0)
1310 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1311 if(strcmp(RecordsWithoutUser
,"ip") == 0)
1313 if(strcmp(RecordsWithoutUser
,"ignore") == 0)
1315 if(strcmp(RecordsWithoutUser
,"everybody") == 0)
1316 strcpy(user
,"everybody");
1320 str2
=(char *)subs(user
,"_",".");
1326 sprintf(wuser
,":%s:",user
);
1327 if(strstr(userfile
, wuser
) == 0)
1333 l
=vuexclude(excludeuser
,user
);
1344 if(l
&&max_elapsed
) {
1345 if(atol(elap
)>max_elapsed
) {
1352 if(strcmp(user
,"-") !=0 && strlen(url
) > 0 && strcmp(user
," ") !=0 && strcmp(user
,"") !=0 && strcmp(user
,":") !=0){
1353 if((str
=(char *) strstr(bufz
, "[SmartFilter:")) != (char *) NULL
) {
1354 str
[strlen(str
)-1]='\0';
1355 sprintf(smartfilter
,"\"%s\"",str
+1);
1356 } else sprintf(smartfilter
,"\"\"");
1358 sprintf(bufz
, "%s %s %s %s %s %s %s %s %s\n",dia
,hora
,user
,ip
,url
,tam
,code
,elap
,smartfilter
);
1360 #ifdef LEGACY_WRITE_USER
1361 sprintf(tmp3
,"%s/sarg/%s.unsort",tmp
,user
);
1362 #if defined(HAVE_FOPEN64)
1363 if((fp_ou
=fopen64(tmp3
,"a"))==NULL
) {
1365 if((fp_ou
=fopen(tmp3
,"a"))==NULL
) {
1367 fprintf(stderr
, "%s: (zzzlog) %s: %s - %s\n",argv
[0],text
[9],tmp3
,strerror(errno
));
1373 if ( strcmp ( user
, sz_Last_User
) != 0 ) {
1374 if ( fp_Write_User
)
1375 fclose( fp_Write_User
) ;
1376 sprintf (tmp3
, "%s/sarg/%s.unsort", tmp
, user
);
1378 #if defined(HAVE_FOPEN64)
1379 if ((fp_Write_User
= fopen64 (tmp3
, "a")) == NULL
) {
1381 if ((fp_Write_User
= fopen (tmp3
, "a")) == NULL
) {
1383 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1386 strcpy( sz_Last_User
, user
) ;
1388 fputs (bufz
, fp_Write_User
);
1391 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
)
1394 #ifdef LEGACY_WRITE_USER
1399 if(download_flag
&& strstr(code
,"DENIED") == 0) {
1401 sprintf(bufz
, "%s %s %s %s %s %s\n",dia
,hora
,user
,ip
,download_url
);
1403 #ifdef LEGACY_WRITE_DOWNLOAD
1404 sprintf(tmp3
,"%s/sarg/download.unsort",tmp
);
1405 #if defined(HAVE_FOPEN64)
1406 if((fp_ou
=fopen64(tmp3
,"a"))==NULL
) {
1408 if((fp_ou
=fopen(tmp3
,"a"))==NULL
) {
1410 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[9],tmp3
,strerror(errno
));
1416 if ( ! fp_Download_Unsort
) {
1417 #if defined(HAVE_FOPEN64)
1418 if ((fp_Download_Unsort
= fopen64 ( sz_Download_Unsort
, "a")) == NULL
) {
1420 if ((fp_Download_Unsort
= fopen (sz_Download_Unsort
, "a")) == NULL
) {
1422 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1426 fputs (bufz
, fp_Download_Unsort
);
1430 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
1431 if(strstr(code
,"DENIED/403") != 0) {
1432 sprintf(bufz
, "%s %s %s %s %s\n",dia
,hora
,user
,ip
,urly
);
1433 fputs(bufz
,fp_denied
);
1436 if(strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0) {
1437 sprintf(bufz
, "%s %s %s %s %s\n",dia
,hora
,user
,ip
,urly
);
1439 fputs(bufz
,fp_authfail
);
1444 if(!totper
&& !sarglog
){
1446 sprintf(period
,"%s-",tbuf
);
1447 sprintf(per_hour
,"%s-",tbuf2
);
1449 fixper(tbuf
, period
, cduntil
);
1451 debugaz("tbuf",tbuf
);
1452 debugaz("period",period
);
1458 printf("IP=\t%s\n",ip
);
1459 printf("USER=\t%s\n",user
);
1460 printf("ELAP=\t%s\n",elap
);
1461 printf("DATE=\t%s\n",dia
);
1462 printf("TIME=\t%s\n",hora
);
1463 printf("FUNC=\t%s\n",fun
);
1464 printf("URL=\t%s\n",url
);
1465 printf("CODE=\t%s\n",code
);
1466 printf("LEN=\t%s\n",tam
);
1470 if( bool_ShowReadStatistics
)
1471 printf("SARG: Records in file: " OFFSET_STRING
", reading: %3.2f%%\n",recs1
, (float) 100 );
1474 if ( fp_Download_Unsort
)
1475 fclose (fp_Download_Unsort
);
1478 fclose (fp_Write_User
);
1481 sprintf(msg
, " %s: %ld, %s: %ld, %s: %ld",text
[10],totregsl
,text
[11],totregsg
,text
[68],totregsx
);
1484 if((common_log
) && (squid_log
))
1487 if((common_log
) && (!squid_log
))
1490 if((!common_log
) && (squid_log
))
1496 if((!common_log
) && (!squid_log
) && (!sarglog
) && (!isalog
)) {
1498 fprintf(stderr
, "SARG: %s\n",text
[16]);
1499 fprintf(stderr
, "SARG: %s\n",text
[21]);
1500 } else fprintf(stderr
, "SARG: %s\n",text
[15]);
1501 bzero(msg
,sizeof(msg
));
1507 fclose(fp_authfail
);
1518 fprintf(stderr
, "SARG: %s\n",text
[16]);
1519 fprintf(stderr
, "SARG: %s\n",text
[21]);
1525 fclose(fp_authfail
);
1529 if(date
[0] == '\0' && !sarglog
) {
1530 strcat(period
,tbuf
);
1531 strcat(per_hour
,tbuf2
);
1535 debugaz("data",dia
);
1536 debugaz("tbuf",tbuf
);
1537 debugaz("period",period
);
1541 sprintf(msg
, "%s: %s",text
[17],period
);
1550 fclose(fp_authfail
);
1552 if(strcmp(ParsedOutputLog
, "no") != 0 && !sarglog
) {
1554 strcpy(val1
,period
);
1555 if (getword_multisep(val2
,sizeof(val2
),val1
,'-')<0){
1556 printf("SARG: Maybe you have a broken date range definition.\n");
1559 if (getword_multisep(val3
,sizeof(val3
),per_hour
,'-')<0){
1560 printf("SARG: Maybe you have a broken date range definition.\n");
1563 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,val3
,val1
,per_hour
);
1564 rename(arq_log
,val4
);
1565 strcpy(arq_log
,val4
);
1567 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0) {
1568 sprintf(val1
,"%s %s",ParsedOutputLogCompress
,arq_log
);
1573 sprintf(msg
,"%s %s",text
[123],arq_log
);
1578 if(strstr(ReportType
,"denied") != 0) {
1579 sprintf(csort
,"sort -T %s -k 3,3 -k 5,5 -o '%s' '%s'",tmp
,tmp5
,tmp4
);
1584 sort_users_log(tmp
, debug
);
1587 if(strlen(DataFile
) > 0)
1593 if(strstr(ReportType
,"denied") != 0)
1596 if((strlen(zip
) > 0 && strcmp(zip
,"zcat") !=0)) {
1598 // else unlink(arq);
1600 if(strcmp(tmp
,"/tmp") != 0) {
1601 sprintf(tmp4
,"rm -rf %s",tmp
);
1622 void getusers(char *pwdfile
, int debug
)
1629 unsigned long int nreg
=0;
1632 sprintf(Msg
,"%s: %s",text
[60],pwdfile
);
1636 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1637 fprintf(stderr
, "SARG: (getusers) %s: %s - %s\n",text
[45],pwdfile
,strerror(errno
));
1641 nreg
= lseek(fileno(fp_usr
), (off_t
)0, SEEK_END
);
1643 lseek(fileno(fp_usr
), (off_t
)0, 0);
1645 if((userfile
=(char *) malloc(nreg
))==NULL
){
1646 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1650 bzero(userfile
,nreg
);
1651 sprintf(userfile
,":");
1653 while(fgets(buf
,255,fp_usr
)!=NULL
) {
1654 if (getword_multisep(user
,sizeof(user
),buf
,':')<0){
1655 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",pwdfile
);
1658 strncat(userfile
,user
,strlen(user
));
1659 strncat(userfile
,":",1);
1668 void gethexclude(char *hexfile
, int debug
)
1674 unsigned long int nreg
=0;
1677 sprintf(Msg
,"%s: %s",text
[67],hexfile
);
1681 if ((fp_ex
= fopen(hexfile
, "r")) == NULL
) {
1682 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],hexfile
,strerror(errno
));
1686 nreg
= lseek(fileno(fp_ex
), (off_t
)0, SEEK_END
);
1687 lseek(fileno(fp_ex
), (off_t
)0, 0);
1689 if((excludefile
=(char *) malloc(nreg
+11))==NULL
){
1690 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1694 bzero(excludefile
,nreg
+11);
1696 while(fgets(buf
,255,fp_ex
)!=NULL
){
1697 if(strstr(buf
,"#") != 0)
1699 buf
[strlen(buf
)-1]='\0';
1700 strcat(excludefile
,buf
);
1701 strcat(excludefile
," ");
1704 strcat(excludefile
,"*END* ");
1712 void getuexclude(char *uexfile
, int debug
)
1718 unsigned long int nreg
=0;
1721 sprintf(Msg
,"%s: %s",text
[67],uexfile
);
1725 if ((fp_ex
= fopen(uexfile
, "r")) == NULL
) {
1726 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],uexfile
,strerror(errno
));
1730 nreg
= lseek(fileno(fp_ex
), (off_t
)0, SEEK_END
);
1731 lseek(fileno(fp_ex
), (off_t
)0, 0);
1733 if((excludeuser
=(char *) malloc(nreg
+11))==NULL
){
1734 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1738 bzero(excludeuser
,nreg
+11);
1740 while(fgets(buf
,255,fp_ex
)!=NULL
){
1741 if(strstr(buf
,"#") != 0)
1743 buf
[strlen(buf
)-1]='\0';
1744 strcat(excludeuser
,buf
);
1745 strcat(excludeuser
," ");
1748 strcat(excludeuser
,"*END* ");