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 REPORT_EVERY_X_LINES 5000
36 numlist weekdays
= { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
37 numlist hours
= { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
38 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
40 static void getusers(const char *pwdfile
, int debug
);
41 static void gethexclude(const char *hexfile
, int debug
);
42 static void getuexclude(const char *uexfile
, int debug
);
44 int main(int argc
,char *argv
[])
55 ISACOL_Last
//last entry of the list !
63 ILF_Last
//last entry of the list !
66 FILE *fp_in
= NULL
, *fp_denied
=NULL
, *fp_authfail
=NULL
, *fp_log
=NULL
;
68 char sz_Download_Unsort
[ 20000 ] ;
69 FILE * fp_Download_Unsort
= NULL
;
70 FILE * fp_Write_User
= NULL
;
83 char smartfilter
[MAXLEN
];
94 char hm
[15], hmf
[15], hmr
[15];
97 char hexclude
[MAXLEN
];
107 enum InputLogFormat ilf
;
108 int ilf_count
[ILF_Last
];
120 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
;
133 char download_url
[MAXLEN
];
134 char sz_Last_User
[MAXLEN
]="";
135 struct getwordstruct gwarea
;
142 UserAgentLog
[0]='\0';
143 ExcludeHosts
[0]='\0';
144 ExcludeUsers
[0]='\0';
151 ExternalCSSFile
[0]='\0';
152 SquidGuardLogFormat
[0]='\0';
153 SquidGuardLogAlternate
[0]='\0';
154 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) ilf_count
[ilf
]=0;
156 sprintf(ExcludeCodes
,"%s/exclude_codes",SYSCONFDIR
);
157 strcpy(GraphDaysBytesBarColor
,"orange");
158 strcpy(BgColor
,"#ffffff");
159 strcpy(TxColor
,"#000000");
160 strcpy(TxBgColor
,"lavender");
161 strcpy(TiColor
,"darkblue");
164 strcpy(LogoTextColor
,"#000000");
165 strcpy(HeaderColor
,"darkblue");
166 strcpy(HeaderBgColor
,"#dddddd");
167 strcpy(LogoTextColor
,"#006699");
168 strcpy(FontSize
,"9px");
169 strcpy(TempDir
,"/tmp");
170 strcpy(OutputDir
,"/var/www/html/squid-reports");
172 strcpy(DateFormat
,"u");
175 strcpy(ReplaceIndex
,"index.html");
177 strcpy(RecordsWithoutUser
,"ip");
179 strcpy(MailUtility
,"mailx");
180 strcpy(TopSitesNum
,"100");
182 strcpy(TopuserSortField
,"BYTES");
183 strcpy(UserSortField
,"BYTES");
184 strcpy(TopuserSortOrder
,"reverse");
185 strcpy(UserSortOrder
,"reverse");
186 strcpy(TopsitesSortField
,"CONNECT");
187 strcpy(TopsitesSortType
,"D");
189 strcpy(language
,"English");
190 strcpy(FontFace
,"Verdana,Tahoma,Arial");
191 strcpy(datetimeby
,"elap");
192 strcpy(CharSet
,"ISO-8859-1");
194 strcpy(PrivacyString
,"***.***.***.***");
195 strcpy(PrivacyStringColor
,"blue");
197 strcpy(TopUserFields
,"NUM DATE_TIME USERID CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
198 strcpy(UserReportFields
,"CONNECT BYTES %BYTES IN-CACHE-OUT USED_TIME MILISEC %TIME TOTAL AVERAGE");
199 strcpy(DataFileDelimiter
,";");
200 strcpy(DataFileFields
,"user;date;time;url;connect;bytes;in_cache;out_cache;elapsed");
201 strcpy(SiteUserTimeDateType
,"table");
202 ShowReadStatistics
=1;
203 strcpy(IndexSortOrder
,"D");
206 strcpy(ParsedOutputLog
,"no");
207 strcpy(ParsedOutputLogCompress
,"/bin/gzip");
208 strcpy(DisplayedValues
,"abbreviation");
209 strcpy(HeaderFontSize
,"9px");
210 strcpy(TitleFontSize
,"11px");
211 strcpy(AuthUserFile
,"/usr/local/sarg/passwd");
212 strcpy(AuthName
,"SARG, Restricted Access");
213 strcpy(AuthType
,"basic");
214 strcpy(Require
,"require user admin %u");
215 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");
217 strcpy(Ulimit
,"20000");
218 strcpy(NtlmUserFormat
,"domainname+username");
219 strcpy(IndexTree
,"file");
220 strcpy(RealtimeTypes
,"GET,PUT,CONNECT");
221 strcpy(RealtimeUnauthRec
,"show");
222 SquidguardIgnoreDate
=0;
223 DansguardianIgnoreDate
=0;
224 strcpy(DataFileUrl
,"ip");
225 strcpy(MaxElapsed
,"28800000");
226 BytesInSitesUsersReport
=0;
227 UserAuthentication
=0;
251 UserInvalidChar
[0]='\0';
253 SquidGuardConf
[0]='\0';
254 DansGuardianConf
[0]='\0';
259 dansguardian_count
=0;
261 DeniedReportLimit
=10;
262 AuthfailReportLimit
=10;
263 DansGuardianReportLimit
=10;
264 SquidGuardReportLimit
=10;
265 DownloadReportLimit
=50;
278 realtime_access_log_lines
=1000;
284 bzero(IncludeUsers
, MAXLEN
);
285 bzero(ExcludeString
, MAXLEN
);
288 setlocale(LC_TIME
,"");
292 for(x
=0; x
<=MAXLOGS
; x
++)
293 AccessLog
[x
][0]='\0';
294 AccessLogFromCmdLine
=0;
296 language_load(language
);
297 strcpy(Title
,text
[88]);
299 while((ch
= getopt(argc
, argv
, "a:b:c:d:e:f:g:u:l:L:o:s:t:w:hijmnprvxyz")) != -1){
306 strcpy(uagent
,optarg
);
309 strcpy(hexclude
,optarg
);
312 strncpy(date
,optarg
,sizeof(date
)-1);
313 date
[sizeof(date
)-1]='\0';
314 getword_start(&gwarea
,optarg
);
315 if (getword(cdfrom
,sizeof(cdfrom
),&gwarea
,'-')<0 || getword(cduntil
,sizeof(cduntil
),&gwarea
,0)<0) {
316 printf("SARG: Maybe you have a broken record or garbage in your date range.\n");
319 date_from(date
, cdfrom
, cduntil
);
321 duntil
=atoi(cduntil
);
324 strcpy(email
,optarg
);
327 strcpy(ConfigFile
,optarg
);
340 if (NAccessLog
>=MAXLOGS
) {
341 printf("SARG: Too many log files.\n");
344 strcpy(AccessLog
[NAccessLog
],optarg
);
346 AccessLogFromCmdLine
++;
349 strcpy(SquidGuardLogAlternate
,optarg
);
358 strcpy(outdir
,optarg
);
373 if(strstr(optarg
,"-") == 0) {
377 getword_start(&gwarea
,optarg
);
378 if (getword(hm
,sizeof(hm
),&gwarea
,'-')<0 || getword(hmf
,sizeof(hmf
),&gwarea
,0)<0) {
379 fprintf(stderr
,"SARG: Maybe you have a broken record or garbage in your time range.\n");
383 if(sscanf(hm
,"%d:%d",&h
,&m
)!=2) {
384 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
387 sprintf(hm
,"%02d%02d",h
,m
);
388 if(sscanf(hmf
,"%d:%d",&h
,&m
)!=2) {
389 fprintf(stderr
,"SARG: time period must be MM or MM:SS. Exit.\n");
392 sprintf(hmf
,"%02d%02d",h
,m
);
414 fprintf(stderr
, "Option -%c require an argument\n",optopt
);
430 if(debug
) debuga("Init");
432 if(ConfigFile
[0] == '\0') sprintf(ConfigFile
,"%s/sarg.conf",SYSCONFDIR
);
433 if(access(ConfigFile
, R_OK
) != 0) {
434 debuga("Cannot open config file: %s - %s",ConfigFile
,strerror(errno
));
438 if(access(ConfigFile
, R_OK
) == 0)
446 if(strcmp(IndexTree
,"file") == 0)
447 strcpy(ImageFile
,"../images");
449 strcpy(ImageFile
,"../../../images");
452 if(DataFile
[0] != '\0')
455 subs(TopUserFields
,sizeof(TopUserFields
),"%BYTES","SETYB");
457 subs(UserReportFields
,sizeof(UserReportFields
),"%BYTES","SETYB");
460 strcpy(AccessLog
[0],"/var/log/squid/access.log");
464 if(strcmp(hexclude
,"onvert") == 0 && strcmp(site
,"plit") != 0) {
465 convlog(AccessLog
[0], df
, dfrom
, duntil
);
469 if(strcmp(site
,"plit") == 0) {
470 splitlog(AccessLog
[0], df
, dfrom
, duntil
, hexclude
);
474 load_excludecodes(ExcludeCodes
);
476 if(access(PasswdFile
, R_OK
) == 0) {
477 getusers(PasswdFile
,debug
);
481 if(hexclude
[0] == '\0')
482 strcpy(hexclude
,ExcludeHosts
);
483 if(strlen(hexclude
) > 0) {
484 if(access(hexclude
, R_OK
) != 0) {
485 debuga("Cannot open exclude_hosts file: %s - %s",hexclude
,strerror(errno
));
488 gethexclude(hexclude
,debug
);
492 if(ReportType
[0] == '\0')
493 strcpy(ReportType
,"topusers topsites users_sites sites_users date_time denied auth_failures site_user_time_date downloads");
495 if(access(ExcludeUsers
, R_OK
) == 0) {
496 getuexclude(ExcludeUsers
,debug
);
502 if(strstr(excludeuser
,"indexonly") != 0)
505 if(strcmp(ExcludeUsers
,"indexonly") == 0) indexonly
++;
506 if(strcmp(Index
,"only") == 0) indexonly
++;
512 if(strlen(MaxElapsed
)>1) max_elapsed
=atol(MaxElapsed
);
514 if(strlen(outdir
)<1) strcpy(outdir
,OutputDir
);
517 if(uagent
[0] == '\0') strcpy(uagent
,UserAgentLog
);
519 if(tmp
[0] == '\0') strcpy(tmp
,TempDir
);
520 else strcpy(TempDir
,tmp
);
522 if(df
[0] == '\0') strcpy(df
,DateFormat
);
523 else strcpy(DateFormat
,df
);
527 strcpy(DateFormat
,"u");
530 if(email
[0] == '\0' && OutputEmail
[0] != '\0') strcpy(email
,OutputEmail
);
534 if(email
[0] != '\0') {
535 sprintf(wtemp2
,"%s/sarg",tmp2
);
537 strcat(tmp2
,"/sarg");
542 strcat(tmp2
,"/sarg.log");
544 sprintf(tmp3
,"%s/sarg",tmp
);
545 if(access(tmp3
, R_OK
) == 0) {
552 strcat(tmp4
,"/denied.log.unsort");
553 strcat(tmp5
,"/denied.log");
554 strcat(tmp6
,"/authfail.log.unsort");
557 fprintf(stderr
, "SARG: %s:\nSARG:\n",text
[22]);
558 fprintf(stderr
, "SARG: %35s (-a) = %s\n",text
[23],addr
);
559 fprintf(stderr
, "SARG: %35s (-b) = %s\n",text
[71],uagent
);
560 fprintf(stderr
, "SARG: %35s (-c) = %s\n",text
[69],hexclude
);
561 fprintf(stderr
, "SARG: %35s (-d) = %s\n",text
[24],date
);
562 fprintf(stderr
, "SARG: %35s (-e) = %s\n",text
[41],email
);
563 fprintf(stderr
, "SARG: %35s (-f) = %s\n",text
[70],ConfigFile
);
564 if(strcmp(df
,"e") == 0)
565 fprintf(stderr
, "SARG: %35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
566 if(strcmp(df
,"u") == 0)
567 fprintf(stderr
, "SARG: %35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
568 if(strcmp(df
,"w") == 0)
569 fprintf(stderr
, "SARG: %35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
571 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[1]);
573 fprintf(stderr
, "SARG: %35s (-i) = %s\n",text
[28],text
[2]);
574 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
575 fprintf(stderr
, "SARG: %35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
577 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[1]);
579 fprintf(stderr
, "SARG: %35s (-n) = %s\n",text
[65],text
[2]);
580 fprintf(stderr
, "SARG: %35s (-o) = %s\n",text
[38],outdir
);
582 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[1]);
584 fprintf(stderr
, "SARG: %35s (-p) = %s\n",text
[29],text
[2]);
585 fprintf(stderr
, "SARG: %35s (-s) = %s\n",text
[30],site
);
586 fprintf(stderr
, "SARG: %35s (-t) = %s\n",text
[31],hm
);
587 fprintf(stderr
, "SARG: %35s (-u) = %s\n",text
[32],us
);
588 fprintf(stderr
, "SARG: %35s (-w) = %s\n",text
[34],tmp
);
590 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[1]);
592 fprintf(stderr
, "SARG: %35s (-x) = %s\n",text
[35],text
[2]);
594 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[1]);
596 fprintf(stderr
, "SARG: %35s (-z) = %s\n",text
[36],text
[2]);
597 fprintf(stderr
, "SARG:\n");
601 printf("%s:\nSARG:\n",text
[22]);
602 printf("%35s (-a) = %s\n",text
[23],addr
);
603 printf("%35s (-b) = %s\n",text
[71],uagent
);
604 printf("%35s (-c) = %s\n",text
[69],hexclude
);
605 printf("%35s (-d) = %s\n",text
[24],date
);
606 printf("%35s (-e) = %s\n",text
[41],email
);
607 printf("%35s (-f) = %s\n",text
[70],ConfigFile
);
608 if(strcmp(df
,"e") == 0)
609 printf("%35s (-g) = %s (dd/mm/yyyy)\n",text
[25],text
[26]);
610 if(strcmp(df
,"u") == 0)
611 printf("%35s (-g) = %s (mm/dd/yyyy)\n",text
[25],text
[27]);
612 if(strcmp(df
,"w") == 0)
613 printf("%35s (-g) = %s (yyyy/ww)\n",text
[25],text
[85]);
615 printf("%35s (-i) = %s\n",text
[28],text
[1]);
617 printf("%35s (-i) = %s\n",text
[28],text
[2]);
618 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++)
619 printf("%35s (-l) = %s\n",text
[37],AccessLog
[iarq
]);
621 printf("%35s (-n) = %s\n",text
[65],text
[1]);
623 printf("%35s (-n) = %s\n",text
[65],text
[2]);
624 printf("%35s (-o) = %s\n",text
[38],outdir
);
626 printf("%35s (-p) = %s\n",text
[29],text
[1]);
628 printf("%35s (-p) = %s\n",text
[29],text
[2]);
629 printf("%35s (-s) = %s\n",text
[30],site
);
630 printf("%35s (-t) = %s\n",text
[31],hm
);
631 printf("%35s (-u) = %s\n",text
[32],us
);
632 printf("%35s (-w) = %s\n",text
[34],tmp
);
634 printf("%35s (-x) = %s\n",text
[35],text
[1]);
636 printf("%35s (-x) = %s\n",text
[35],text
[2]);
638 printf("%35s (-z) = %s\n",text
[36],text
[1]);
640 printf("%35s (-z) = %s\n",text
[36],text
[2]);
641 printf("sarg %s: %s\n",text
[73],VERSION
);
642 printf("Language=%s\n\n",text
[3]);
646 debuga("sarg %s: %s",text
[73],VERSION
);
649 if (Ulimit
[0] != '\0') {
654 #if defined(RLIMIT_NOFILE)
655 getrlimit (RLIMIT_NOFILE
, &rl
);
656 #elif defined(RLIMIT_OFILE)
657 getrlimit (RLIMIT_OFILE
, &rl
);
659 #warning "No rlimit resource for the number of open files"
664 rl
.rlim_cur
= atol(Ulimit
);
665 rl
.rlim_max
= atol(Ulimit
);
666 #if defined(RLIMIT_NOFILE)
667 rc
=setrlimit (RLIMIT_NOFILE
, &rl
);
668 #elif defined(RLIMIT_OFILE)
669 rc
=setrlimit (RLIMIT_OFILE
, &rl
);
671 #warning "No rlimit resource for the number of open files"
674 debuga("setrlimit error - %s\n",strerror(errno
));
678 debuga("Maximum file descriptor: cur=%ld max=%ld, changed to cur="RLIM_STRING
" max="RLIM_STRING
,l1
,l2
,rl
.rlim_cur
,rl
.rlim_max
);
682 read_usertab(UserTabFile
);
684 sprintf ( sz_Download_Unsort
, "%s/sarg/download.unsort", tmp
);
686 if(strstr(ReportType
,"denied") != 0) {
687 if((fp_denied
=MY_FOPEN(tmp4
,"w"))==NULL
) {
688 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp4
,strerror(errno
));
693 if(DataFile
[0]=='\0') {
694 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
695 if((fp_authfail
=MY_FOPEN(tmp6
,"w"))==NULL
) {
696 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[45],tmp6
,strerror(errno
));
702 for (iarq
=0 ; iarq
<NAccessLog
; iarq
++) {
703 strcpy(arq
,AccessLog
[iarq
]);
707 if(strcmp(arq
,"-")==0) {
709 debuga("%s: %s",text
[7],"stdin");
715 debuga("%s: %s",text
[7],arq
);
716 if((fp_in
=MY_FOPEN(arq
,"r"))==NULL
) {
717 fprintf(stderr
, "%s: (log) %s: %s - %s\n",argv
[0],text
[8],arq
,strerror(errno
));
723 // pre-Read the file only if I have to show stats
724 if(ShowReadStatistics
&& !from_stdin
) {
729 while( fgets(bufz
,sizeof(bufz
),fp_in
) != NULL
) recs1
++;
731 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,(float) 0);
735 while(fgets(bufz
,sizeof(bufz
),fp_in
)!=NULL
) {
737 if (ilf
==ILF_Unknown
) {
738 if(strncmp(bufz
,"#Software: Mic",14) == 0) {
740 debuga("%s: %s",text
[143],bufz
);
746 if(strncmp(bufz
,"*** SARG Log ***",16) == 0) {
747 getword_start(&gwarea
,arqtt
);
748 if (getword(val2
,sizeof(val2
),&gwarea
,'-')<0 || getword(val2
,sizeof(val2
),&gwarea
,'_')<0 ||
749 getword(val3
,sizeof(val3
),&gwarea
,'-')<0 || getword(val3
,sizeof(val3
),&gwarea
,'_')<0) {
750 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
753 sprintf(period
,"%s-%s",val2
,val3
);
760 if(strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
) {
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
=MY_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
);
774 if( ShowReadStatistics
&& !from_stdin
&& ! --OutputNonZero
) {
776 perc
= perc
/ recs1
;
777 printf("SARG: Records in file: %lu, reading: %3.2f%%\r",recs1
,perc
);
779 OutputNonZero
= REPORT_EVERY_X_LINES
;
781 if(strlen(bufz
) > MAXLEN
-1) continue;
782 if(!bufz
[0]) continue;
783 if(strstr(bufz
,"HTTP/0.0") != 0) continue;
784 if(strstr(bufz
,"logfile turned over") != 0) continue;
785 if(bufz
[0] == ' ') continue;
786 if(strlen(bufz
) < 58) continue;
788 // Record only hours usage which is required
789 tt
= (time_t) strtoul( bufz
, NULL
, 10 );
790 t
= localtime( &tt
);
792 if( bsearch( &( t
-> tm_wday
), weekdays
.list
, weekdays
.len
,
793 sizeof( int ), compar
) == NULL
)
796 if( bsearch( &( t
-> tm_hour
), hours
.list
, hours
.len
,
797 sizeof( int ), compar
) == NULL
)
802 if(ExcludeString
[0] != '\0') {
804 getword_start(&gwarea
,ExcludeString
);
805 while(strchr(gwarea
.current
,':') != 0) {
806 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,':')<0) {
807 printf("SARG: Maybe you have a broken record or garbage in your exclusion string.\n");
810 if((str
=(char *) strstr(warea
,val1
)) != (char *) NULL
)
813 if((str
=(char *) strstr(warea
,gwarea
.current
)) != (char *) NULL
)
816 if(exstring
) continue;
819 if ((str
= strchr(bufz
, '\n')) != NULL
)
820 *str
= '\0'; /* strip \n */
824 printf("BUF=%s\n",bufz
);
826 if (ilf
==ILF_Squid
|| ilf
==ILF_Common
|| ilf
==ILF_Unknown
) {
827 getword_start(&gwarea
,bufz
);
828 if (getword(data
,sizeof(data
),&gwarea
,' ')<0) {
829 printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n");
832 if((str
=(char *) strchr(data
, '.')) != (char *) NULL
) {
833 if((str
=(char *) strchr(str
+1, '.')) != (char *) NULL
) {
837 if (getword(user
,sizeof(user
),&gwarea
,' ')<0 || getword_skip(255,&gwarea
,' ')<0) {
838 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
842 if (getword_skip(255,&gwarea
,' ')<0 || getword(user
,sizeof(user
),&gwarea
,' ')<0) {
843 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
847 if (getword(data
,sizeof(data
),&gwarea
,']')<0 || getword_skip(MAXLEN
,&gwarea
,'"')<0 ||
848 getword(fun
,sizeof(fun
),&gwarea
,' ')<0 || getword(url
,sizeof(url
),&gwarea
,' ')<0 ||
849 getword_skip(MAXLEN
,&gwarea
,' ')<0 || getword(code2
,sizeof(code2
),&gwarea
,' ')<0 ||
850 getword(tam
,sizeof(tam
),&gwarea
,' ')<0) {
851 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
854 if((str
=(char *) strchr(gwarea
.current
, ' ')) != (char *) NULL
) {
855 if (getword(code
,sizeof(code
),&gwarea
,' ')<0) {
856 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
860 if (getword(code
,sizeof(code
),&gwarea
,'\0')<0) {
861 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
866 if ((str
= strchr(code
, ':')) != NULL
)
869 if(strcmp(tam
,"\0") == 0)
877 if(ilf
==ILF_Unknown
|| ilf
==ILF_Squid
) {
878 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
879 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
882 while(strcmp(elap
,"") == 0 && gwarea
.current
[0] != '\0')
883 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0) {
884 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
887 if(strlen(elap
) < 1) continue;
888 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0){
889 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
892 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
893 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
896 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
897 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
900 if (getword(fun
,sizeof(fun
),&gwarea
,' ')<0){
901 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
904 if (getword(url
,sizeof(url
),&gwarea
,' ')<0){
905 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
908 // while (strstr(bufz,"%20") != 0) {
909 // getword(warea,bufz,' ');
910 // strcat(url,warea);
912 if (getword(user
,sizeof(user
),&gwarea
,' ')<0){
913 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
921 getword_start(&gwarea
,bufz
);
922 if (getword(data
,sizeof(data
),&gwarea
,' ')<0){
923 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
926 if (getword(hora
,sizeof(hora
),&gwarea
,' ')<0) {
927 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
930 if (getword(user
,sizeof(user
),&gwarea
,' ')<0) {
931 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
934 if (getword(ip
,sizeof(ip
),&gwarea
,' ')<0) {
935 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
938 if (getword(url
,sizeof(url
),&gwarea
,' ')<0){
939 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
942 if (getword(tam
,sizeof(tam
),&gwarea
,' ')<0){
943 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
946 if (getword(code
,sizeof(code
),&gwarea
,' ')<0){
947 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
950 if (getword(elap
,sizeof(elap
),&gwarea
,' ')<0){
951 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
954 if (getword(smartfilter
,sizeof(smartfilter
),&gwarea
,' ')<0){
955 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
960 if (bufz
[0] == '#') {
961 int ncols
,cols
[ISACOL_Last
];
964 getword_start(&gwarea
,bufz
);
965 // remove the #Fields: column at the beginning of the line
966 if (getword_skip(1000,&gwarea
,' ')<0){
967 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
970 for (ncols
=0 ; ncols
<ISACOL_Last
; ncols
++) cols
[ncols
]=-1;
972 while(gwarea
.current
[0] != '\0') {
973 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0){
974 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
977 if(strcmp(val1
,"c-ip") == 0) cols
[ISACOL_Ip
]=ncols
;
978 if(strcmp(val1
,"cs-username") == 0) cols
[ISACOL_UserName
]=ncols
;
979 if(strcmp(val1
,"date") == 0) cols
[ISACOL_Date
]=ncols
;
980 if(strcmp(val1
,"time") == 0) cols
[ISACOL_Time
]=ncols
;
981 if(strcmp(val1
,"time-taken") == 0) cols
[ISACOL_TimeTaken
]=ncols
;
982 if(strcmp(val1
,"sc-bytes") == 0) cols
[ISACOL_Bytes
]=ncols
;
983 if(strcmp(val1
,"cs-uri") == 0) cols
[ISACOL_Uri
]=ncols
;
984 if(strcmp(val1
,"sc-status") == 0) cols
[ISACOL_Status
]=ncols
;
987 if (cols
[ISACOL_Ip
]>=0) {
989 for (isa_ncols
=0 ; isa_ncols
<ncols
; isa_ncols
++)
990 isa_cols
[isa_ncols
]=cols
[isa_ncols
];
994 if (!isa_ncols
) continue;
995 getword_start(&gwarea
,bufz
);
996 for (x
=0 ; x
<isa_ncols
; x
++) {
997 if (getword(val1
,sizeof(val1
),&gwarea
,'\t')<0) {
998 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1001 if (x
==isa_cols
[ISACOL_Ip
]) {
1002 if (strlen(val1
)>=sizeof(ip
)) {
1003 printf("SARG: Maybe you have a broken IP in your %s file.\n",arq
);
1007 } else if (x
==isa_cols
[ISACOL_UserName
]) {
1008 if (strlen(val1
)>=sizeof(user
)) {
1009 printf("SARG: Maybe you have a broken user in your %s file.\n",arq
);
1013 } else if (x
==isa_cols
[ISACOL_Date
]) {
1014 if (strlen(val1
)>=sizeof(data
)) {
1015 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1019 } else if (x
==isa_cols
[ISACOL_Time
]) {
1020 if (strlen(val1
)>=sizeof(hora
)) {
1021 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1025 } else if (x
==isa_cols
[ISACOL_TimeTaken
]) {
1026 if (strlen(val1
)>=sizeof(elap
)) {
1027 printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq
);
1031 } else if (x
==isa_cols
[ISACOL_Bytes
]) {
1032 if (strlen(val1
)>=sizeof(tam
)) {
1033 printf("SARG: Maybe you have a broken download size in your %s file.\n",arq
);
1037 } else if (x
==isa_cols
[ISACOL_Uri
]) {
1038 if (strlen(val1
)>=sizeof(url
)) {
1039 printf("SARG: Maybe you have a broken URL in your %s file.\n",arq
);
1043 } else if (x
==isa_cols
[ISACOL_Status
]) {
1044 if (strlen(val1
)>=sizeof(code
)) {
1045 printf("SARG: Maybe you have a broken access code in your %s file.\n",arq
);
1052 if(strcmp(code
,"401") == 0 || strcmp(code
,"403") == 0 || strcmp(code
,"407") == 0) {
1053 sprintf(val1
,"DENIED/%s",code
);
1056 getword_start(&gwarea
,data
);
1057 if (getword(ano
,sizeof(ano
),&gwarea
,'-')<0){
1058 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1061 if (getword(mes
,sizeof(mes
),&gwarea
,'-')<0){
1062 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1065 if (getword(dia
,sizeof(dia
),&gwarea
,'\0')<0){
1066 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq
);
1069 conv_month_name(mes
);
1070 sprintf(data
," %s/%s/%s:%s",dia
,mes
,ano
,hora
);
1073 if(strlen(user
) > 150) {
1074 if (debugm
) printf("User too long: %s\n",user
);
1080 if(IncludeUsers
[0] != '\0') {
1081 sprintf(val1
,":%s:",user
);
1082 if((str
=(char *) strstr(IncludeUsers
,val1
)) == (char *) NULL
)
1087 if (debugm
) printf("Excluded code: %s\n",code
);
1092 if(testvaliduserchar(user
))
1096 if((str
= strstr(user
,"%20")) != NULL
) {
1098 Why is it necessary to truncate the user name at the first space ?
1100 The old code used to truncate the user name at the first % if a %20 was
1101 found anywhere in the string. That means the string could be truncated
1102 at the wrong place if another % occured before the %20. This new code should
1103 avoid that problem and only truncate at the space. There is no bug
1104 report indicating that anybody noticed this.
1110 Code prior to 2.2.7 used to replace any %xx by a dot as long as a %5c was
1111 found in the user name.
1113 while((str
= strstr(user
,"%5c")) != NULL
) {
1115 for (x
=3 ; str
[x
] ; x
++) str
[x
-2]=str
[x
];
1119 for(str
=user
; *str
; str
++) {
1120 if(*str
=='.') dotinuser
++;
1121 if(*str
=='?' || *str
=='.' || *str
==':' || *str
=='/' || *str
=='\\')
1126 if(strncmp(NtlmUserFormat
,"user",4) == 0) {
1127 if((str
= strchr(user
,'_')) != 0) {
1128 strcpy(warea
,str
+1);
1131 if((str
= strchr(user
,'+')) != 0) {
1132 strcpy(warea
,str
+1);
1137 if(strstr(ReportType
,"denied") != 0)
1140 download_flag
=is_download_suffix(url
);
1141 if (download_flag
) {
1142 strcpy(download_url
,url
);
1146 // remove any protocol:// at the beginning of the URL
1147 if ((str
= strchr(url
,'/')) != NULL
&& str
[1] == '/') {
1151 for (i
=0 ; str
[i
] ; i
++)
1157 char *endofhost
=strchr(url
,'/');
1160 if(strlen(url
) > 512 && (endofhost
=strchr(url
,'%')) != NULL
) {
1165 if(ilf
==ILF_Squid
) {
1169 strftime(tbuf2
, sizeof(tbuf2
), "%H%M", t
);
1170 sprintf(mes
,"%d",t
->tm_mon
+1);
1171 conv_month_name(mes
);
1172 if(strncmp(df
,"u",1) == 0)
1173 sprintf(tbuf
, "%04d%s%02d", t
->tm_year
+1900, mes
, t
->tm_mday
);
1174 if(strncmp(df
,"e",1) == 0)
1175 sprintf(tbuf
, "%02d%s%04d", t
->tm_mday
, mes
, t
->tm_year
+1900);
1176 if(strncmp(df
,"w",1) == 0) {
1177 strcpy(IndexTree
,"file");
1178 strftime(tbuf
, sizeof(tbuf
), "%Y.%U", t
);
1181 strftime(wdata
, sizeof(wdata
), "%Y%m%d", t
);
1184 if(strncmp(df
,"u",1)==0)
1185 strftime(dia
, sizeof(dia
), "%m/%d/%Y", t
);
1187 strftime(dia
, sizeof(dia
), "%d/%m/%Y", t
);
1188 sprintf(hora
,"%02d:%02d:%02d",t
->tm_hour
,t
->tm_min
,t
->tm_sec
);
1189 } else if(ilf
==ILF_Common
|| ilf
==ILF_Isa
) {
1190 getword_start(&gwarea
,data
+1);
1191 if (getword_multisep(data
,sizeof(data
),&gwarea
,':')<0){
1192 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1195 if (getword_multisep(hora
,sizeof(hora
),&gwarea
,' ')<0){
1196 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1199 getword_start(&gwarea
,data
);
1200 if (getword_multisep(dia
,sizeof(dia
),&gwarea
,'/')<0){
1201 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1204 if (getword_multisep(mes
,sizeof(mes
),&gwarea
,'/')<0){
1205 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1208 if (getword_multisep(ano
,sizeof(ano
),&gwarea
,'/')<0){
1209 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1213 if(strcmp(df
,"u") == 0)
1214 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",ano
,mes
,dia
);
1215 if(strcmp(df
,"e") == 0)
1216 snprintf(tbuf
,sizeof(tbuf
),"%s%s%s",dia
,mes
,ano
);
1217 builddia(dia
,mes
,ano
,df
,wdata
);
1219 } else if (ilf
==ILF_Sarg
) {
1220 getword_start(&gwarea
,data
);
1221 if (getword_multisep(mes
,sizeof(mes
),&gwarea
,'/')<0){
1222 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1225 if (getword_multisep(dia
,sizeof(dia
),&gwarea
,'/')<0){
1226 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1229 if (getword_multisep(ano
,sizeof(ano
),&gwarea
,0)<0){
1230 printf("SARG: Maybe you have a broken date in your %s file.\n",arq
);
1236 printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date
,idata
,dfrom
,duntil
);
1240 if(addr
[0] != '\0'){
1241 if(strcmp(addr
,ip
)==0)
1245 // l=vhexclude(excludefile,ip);
1246 l
=vhexclude(excludefile
,url
);
1248 if (debugm
) printf("Excluded site: %s\n",url
);
1255 if(date
[0] != '\0'){
1256 if(idata
>= dfrom
&& idata
<= duntil
)
1262 bzero(hmr
,sizeof(hmr
));
1264 getword_start(&gwarea
,hora
);
1266 if (getword_multisep(warea
,sizeof(warea
),&gwarea
,':')<0){
1267 printf("SARG: Maybe you have a broken time in your %s file.\n",arq
);
1270 strncat(hmr
,warea
,2);
1273 strncat(hmr
,gwarea
.current
,2);
1275 if(atoi(hmr
) >= atoi(hm
) && atoi(hmr
) <= atoi(hmf
))
1280 if(site
[0] != '\0'){
1281 if(strstr(url
,site
)!=0)
1289 if(strcmp(user
,"-") == 0 || strcmp(user
," ") == 0 || strcmp(user
,"") == 0) {
1290 if(strcmp(RecordsWithoutUser
,"ip") == 0)
1292 if(strcmp(RecordsWithoutUser
,"ignore") == 0)
1294 if(strcmp(RecordsWithoutUser
,"everybody") == 0)
1295 strcpy(user
,"everybody");
1298 if(strcmp(user
,us
)==0)
1305 subs(user
,sizeof(user
),"_",".");
1310 sprintf(wuser
,":%s:",user
);
1311 if(strstr(userfile
, wuser
) == 0)
1317 l
=vuexclude(excludeuser
,user
);
1319 if (debugm
) printf("Excluded user: %s\n",user
);
1330 if(l
&& max_elapsed
) {
1331 if(atol(elap
)>max_elapsed
) {
1338 if(strcmp(user
,"-") !=0 && url
[0] != '\0' && strcmp(user
," ") !=0 && strcmp(user
,"") !=0 && strcmp(user
,":") !=0){
1339 if((str
=(char *) strstr(bufz
, "[SmartFilter:")) != (char *) NULL
) {
1341 sprintf(smartfilter
,"\"%s\"",str
+1);
1342 } else sprintf(smartfilter
,"\"\"");
1344 sprintf(bufz
, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,url
,tam
,code
,elap
,smartfilter
);
1346 if ( strcmp ( user
, sz_Last_User
) != 0 ) {
1347 if ( fp_Write_User
)
1348 fclose( fp_Write_User
) ;
1349 sprintf (tmp3
, "%s/sarg/%s.unsort", tmp
, user
);
1351 if ((fp_Write_User
= MY_FOPEN (tmp3
, "a")) == NULL
) {
1352 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1355 strcpy( sz_Last_User
, user
) ;
1357 fputs (bufz
, fp_Write_User
);
1359 if(strcmp(ParsedOutputLog
, "no") != 0 && ilf
!=ILF_Sarg
)
1364 if(download_flag
&& strstr(code
,"DENIED") == 0) {
1367 if ( ! fp_Download_Unsort
) {
1368 if ((fp_Download_Unsort
= MY_FOPEN ( sz_Download_Unsort
, "a")) == NULL
) {
1369 fprintf (stderr
, "%s: (log) %s: %s - %s\n", argv
[0], text
[9], tmp3
, strerror(errno
));
1373 fprintf(fp_Download_Unsort
,"%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,download_url
);
1376 if(strstr(ReportType
,"denied") != 0 || strstr(ReportType
,"auth_failures") != 0) {
1377 if(strstr(code
,"DENIED/403") != 0) {
1378 fprintf(fp_denied
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1381 if(strstr(code
,"DENIED/401") != 0 || strstr(code
,"DENIED/407") != 0) {
1383 fprintf(fp_authfail
, "%s\t%s\t%s\t%s\t%s\n",dia
,hora
,user
,ip
,urly
);
1388 if((!totper
|| idata
<mindate
) && ilf
!=ILF_Sarg
){
1391 sprintf(period
,"%s-",tbuf
);
1392 sprintf(per_hour
,"%s-",tbuf2
);
1394 fixper(tbuf
, period
, cduntil
);
1396 debugaz("tbuf",tbuf
);
1397 debugaz("period",period
);
1403 printf("IP=\t%s\n",ip
);
1404 printf("USER=\t%s\n",user
);
1405 printf("ELAP=\t%s\n",elap
);
1406 printf("DATE=\t%s\n",dia
);
1407 printf("TIME=\t%s\n",hora
);
1408 printf("FUNC=\t%s\n",fun
);
1409 printf("URL=\t%s\n",url
);
1410 printf("CODE=\t%s\n",code
);
1411 printf("LEN=\t%s\n",tam
);
1417 if( ShowReadStatistics
)
1418 printf("SARG: Records in file: %lu, reading: %3.2f%%\n",recs1
, (float) 100 );
1422 if ( fp_Download_Unsort
)
1423 fclose (fp_Download_Unsort
);
1426 fclose (fp_Write_User
);
1431 for (ilf
=0 ; ilf
<ILF_Last
; ilf
++) totalcount
+=ilf_count
[ilf
];
1433 debuga(" %s: %ld, %s: %ld, %s: %ld",text
[10],totregsl
,text
[11],totregsg
,text
[68],totregsx
);
1435 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]>0)
1436 debuga("%s",text
[12]);
1438 if(ilf_count
[ILF_Common
]>0 && ilf_count
[ILF_Squid
]==0)
1439 debuga("%s",text
[13]);
1441 if(ilf_count
[ILF_Common
]==0 && ilf_count
[ILF_Squid
]>0)
1442 debuga("%s",text
[14]);
1444 if(ilf_count
[ILF_Sarg
]>0)
1445 debuga("%s",text
[124]);
1449 fprintf(stderr
, "SARG: %s\n",text
[16]);
1450 fprintf(stderr
, "SARG: %s\n",text
[21]);
1451 } else fprintf(stderr
, "SARG: %s\n",text
[15]);
1452 bzero(msg
,sizeof(msg
));
1456 fclose(fp_authfail
);
1457 free_excludecodes();
1473 fprintf(stderr
, "SARG: %s\n",text
[16]);
1474 fprintf(stderr
, "SARG: %s\n",text
[21]);
1479 fclose(fp_authfail
);
1480 free_excludecodes();
1491 if(date
[0] == '\0' && ilf_count
[ILF_Sarg
]==0) {
1492 strcat(period
,tbuf
);
1493 strcat(per_hour
,tbuf2
);
1497 debugaz("data",dia
);
1498 debugaz("tbuf",tbuf
);
1499 debugaz("period",period
);
1503 debuga("%s: %s",text
[17],period
);
1509 fclose(fp_authfail
);
1511 if(fp_log
!= NULL
) {
1513 getword_start(&gwarea
,period
);
1514 if (getword_multisep(val2
,sizeof(val2
),&gwarea
,'-')<0){
1515 printf("SARG: Maybe you have a broken date range definition.\n");
1518 if (getword_multisep(val1
,sizeof(val1
),&gwarea
,'\0')<0){
1519 printf("SARG: Maybe you have a broken date range definition.\n");
1522 getword_start(&gwarea
,per_hour
);
1523 if (getword_multisep(val3
,sizeof(val3
),&gwarea
,'-')<0){
1524 printf("SARG: Maybe you have a broken date range definition.\n");
1527 sprintf(val4
,"%s/sarg-%s_%s-%s_%s.log",ParsedOutputLog
,val2
,val3
,val1
,gwarea
.current
);
1528 rename(arq_log
,val4
);
1529 strcpy(arq_log
,val4
);
1531 if(strcmp(ParsedOutputLogCompress
,"nocompress") != 0) {
1532 sprintf(val1
,"\"%s\" \"%s\"",ParsedOutputLogCompress
,arq_log
);
1533 cstatus
=system(val1
);
1534 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1535 fprintf(stderr
, "SARG: command return status %d\n",WEXITSTATUS(cstatus
));
1536 fprintf(stderr
, "SARG: command: %s\n",val1
);
1542 debuga("%s %s",text
[123],arq_log
);
1545 if(strstr(ReportType
,"denied") != 0) {
1546 sprintf(csort
,"sort -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"",tmp
,tmp5
,tmp4
);
1547 cstatus
=system(csort
);
1548 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
1549 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
1550 fprintf(stderr
, "SARG: sort command: %s\n",csort
);
1556 sort_users_log(tmp
, debug
);
1558 if(DataFile
[0] != '\0')
1564 if(strstr(ReportType
,"denied") != 0)
1567 if(zip
[0] != '\0' && strcmp(zip
,"zcat") !=0) {
1570 // else unlink(arq);
1572 if(strcmp(tmp
,"/tmp") != 0) {
1576 free_excludecodes();
1586 debuga("%s",text
[21]);
1593 static void getusers(const char *pwdfile
, int debug
)
1602 debuga("%s: %s",text
[60],pwdfile
);
1604 if ((fp_usr
= fopen(pwdfile
, "r")) == NULL
) {
1605 fprintf(stderr
, "SARG: (getusers) %s: %s - %s\n",text
[45],pwdfile
,strerror(errno
));
1609 fseek(fp_usr
, 0, SEEK_END
);
1610 nreg
= ftell(fp_usr
);
1612 printf("SARG: Cannot get the size of file %s",pwdfile
);
1616 fseek(fp_usr
, 0, SEEK_SET
);
1618 if((userfile
=(char *) malloc(nreg
))==NULL
){
1619 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1623 bzero(userfile
,nreg
);
1624 strcpy(userfile
,":");
1626 while(fgets(buf
,sizeof(buf
),fp_usr
)!=NULL
) {
1627 str
=strchr(buf
,':');
1629 printf("SARG: You have an invalid user in your %s file.\n",pwdfile
);
1633 strcat(userfile
,buf
);
1642 static void gethexclude(const char *hexfile
, int debug
)
1650 debuga("%s: %s",text
[67],hexfile
);
1652 if ((fp_ex
= fopen(hexfile
, "r")) == NULL
) {
1653 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],hexfile
,strerror(errno
));
1657 fseek(fp_ex
, 0, SEEK_END
);
1658 nreg
= ftell(fp_ex
);
1660 printf("SARG: Cannot get the size of file %s",hexfile
);
1664 fseek(fp_ex
, 0, SEEK_SET
);
1666 if((excludefile
=(char *) malloc(nreg
))==NULL
){
1667 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1671 bzero(excludefile
,nreg
);
1673 while(fgets(buf
,sizeof(buf
),fp_ex
)!=NULL
){
1674 if(strchr(buf
,'#') != NULL
)
1677 strcat(excludefile
,buf
);
1678 strcat(excludefile
," ");
1681 strcat(excludefile
,"*END* ");
1689 static void getuexclude(const char *uexfile
, int debug
)
1697 debuga("%s: %s",text
[67],uexfile
);
1699 if ((fp_ex
= fopen(uexfile
, "r")) == NULL
) {
1700 fprintf(stderr
, "SARG: (gethexclude) %s: %s - %s\n",text
[45],uexfile
,strerror(errno
));
1704 fseek(fp_ex
, 0, SEEK_END
);
1705 nreg
= ftell(fp_ex
);
1707 printf("SARG: Cannot get the size of file %s",uexfile
);
1711 fseek(fp_ex
, 0, SEEK_SET
);
1713 if((excludeuser
=(char *) malloc(nreg
))==NULL
){
1714 fprintf(stderr
, "SARG: %s (%ld):\n",text
[59],nreg
);
1718 bzero(excludeuser
,nreg
);
1720 while(fgets(buf
,sizeof(buf
),fp_ex
)!=NULL
){
1721 if(strchr(buf
,'#') != NULL
)
1724 strcat(excludeuser
,buf
);
1725 strcat(excludeuser
," ");
1728 strcat(excludeuser
,"*END* ");