From: Frédéric Marchal Date: Mon, 1 Mar 2010 21:01:32 +0000 (+0000) Subject: Keep the user name intact in the report. X-Git-Tag: v2.3-pre2~79 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2ec8c750f9e9b4d44ffe3d9a906640156bdbf9a;p=thirdparty%2Fsarg.git Keep the user name intact in the report. Speed up the processing of the access.log by keeping more temporary files open. Replace more gettext macros. Reduce the number of IP addresses resolutions. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f360f3..4b26815 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ SET(SRC util.c log.c report.c topuser.c email.c sort.c html.c smartfilter.c denied.c authfail.c language.c charset.c squidguard_log.c squidguard_report.c auth.c download.c grepday.c dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c - usertab.c) + usertab.c userinfo.c) FOREACH(f ${SRC}) ADD_FILE_DEPENDENCIES(${f} ${CMAKE_BINARY_DIR}/config.h ${CMAKE_SOURCE_DIR}/include/conf.h ${CMAKE_SOURCE_DIR}/include/info.h ${CMAKE_SOURCE_DIR}/include/defs.h) diff --git a/Makefile.in b/Makefile.in index 618bd26..e6d13e8 100644 --- a/Makefile.in +++ b/Makefile.in @@ -39,14 +39,17 @@ SRCS = util.c log.c report.c topuser.c email.c sort.c html.c \ indexonly.c splitlog.c lastlog.c topsites.c siteuser.c css.c \ smartfilter.c denied.cauthfail.c language.c charset.c \ squidguard_log.c squidguard_report.c auth.c download.c grepday.c \ - dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c usertab.c + dansguardian_log.c dansguardian_report.c realtime.c btree_cache.c \ + usertab.c userinfo.c + OBJS = util.o log.o report.o topuser.o email.o sort.o html.o \ totger.o index.o getconf.o usage.o decomp.o ip2name.o \ useragent.o exclude.o convlog.o totday.o repday.o datafile.o \ indexonly.o splitlog.o lastlog.o topsites.o siteuser.o css.o \ smartfilter.o denied.o authfail.o language.o charset.o \ squidguard_log.o squidguard_report.o auth.o download.o grepday.o \ - dansguardian_log.o dansguardian_report.o realtime.o btree_cache.o usertab.o + dansguardian_log.o dansguardian_report.o realtime.o btree_cache.o \ + usertab.o userinfo.o DISTFILES = $(SRCS) ABOUT-NLS @@ -129,3 +132,5 @@ distclean: clean realclean: distclean rm -f TAGS +update-po: + $(MAKE) -C po update-po diff --git a/authfail.c b/authfail.c index ff82801..cdfa854 100644 --- a/authfail.c +++ b/authfail.c @@ -45,7 +45,6 @@ void authfail_report(void) char ouser2[MAXLEN]; char data[15]; char hora[15]; - char *str; char tmp4[MAXLEN]; char csort[MAXLEN]; int z=0; @@ -53,6 +52,7 @@ void authfail_report(void) int cstatus; struct getwordstruct gwarea; struct longlinestruct line; + struct userinfostruct *uinfo; if(DataFile[0] != '\0') return; @@ -75,7 +75,7 @@ void authfail_report(void) exit(1); } if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (authfail) read error in %s\n",per); + debuga(_("(authfail) read error in %s"),per); exit(1); } fclose(fp_in); @@ -83,13 +83,13 @@ void authfail_report(void) sprintf(csort,"sort -b -T \"%s\" -k 3,3 -k 5,5 -o \"%s\" \"%s\"", TempDir, authfail_in, tmp4); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } if((fp_in=MY_FOPEN(authfail_in,"r"))==NULL) { fprintf(stderr, "SARG: (authfail) %s: %s\n",text[45],authfail_in); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command: %s"),csort); exit(1); } unlink(tmp4); @@ -119,22 +119,20 @@ void authfail_report(void) getword_start(&gwarea,buf); if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file"),authfail_in); + debuga(_("There is a broken record or garbage in file %s"),authfail_in); exit(1); } if (getword_ptr(buf,&url,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken url in your %s file"),authfail_in); + debuga(_("There is a broken url in file %s"),authfail_in); exit(1); } - if((str=(char *) strstr(user, "_")) != (char *) NULL ) { - if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) - fixip(user); + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s"),user,authfail_in); + exit(1); } - if(Ip2Name) - ip2name(ip,sizeof(ip)); - if(!z) { strcpy(ouser,user); strcpy(oip,ip); @@ -150,24 +148,18 @@ void authfail_report(void) strcpy(oip,ip); } - user_find(name,sizeof(name), user); - - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - if(AuthfailReportLimit) { - if(strcmp(ouser2,name) == 0) { + if(strcmp(ouser2,uinfo->label) == 0) { count++; } else { count=1; - strcpy(ouser2,name); + strcpy(ouser2,uinfo->label); } if(count >= AuthfailReportLimit) continue; } - fprintf(fp_ou,"%s%s%s-%s",name,ip,data,hora); + fprintf(fp_ou,"%s%s%s-%s",uinfo->label,ip,data,hora); if(BlockIt[0]!='\0') { fprintf(fp_ou,"d_name+dlen,logext) != 0) continue; + if (dlen>0) { + if (dlen>=sizeof(user)) continue; + strncpy(user,direntp->d_name,dlen); + user[dlen]=0; + } else { + user[0]='\0'; + } + + uinfo=userinfo_find_from_file(user); + if (!uinfo) { + debuga(_("Ignoring unknown user file %s"),user); + continue; + } + strcpy(u2,uinfo->id); + if(Ip2Name && uinfo->id_is_ip) ip2name(u2,sizeof(u2)); + user_find(uinfo->label,MAX_USER_LEN, u2); + if (snprintf(tmp3,sizeof(tmp3),"%s/%s",tmp,direntp->d_name)>=sizeof(tmp3)) { - fprintf(stderr,"SARG: (datafile) directory path too long: %s/%s\n",tmp,direntp->d_name); + debuga(_("(datafile) directory path too long: %s/%s"),tmp,direntp->d_name); exit(1); } @@ -81,14 +102,15 @@ void data_file(char *tmp) } ttopen=0; + new_user=1; while(fgets(buf,sizeof(buf),fp_in)!=NULL) { getword_start(&gwarea,buf); if (getword(accdia,sizeof(accdia),&gwarea,' ')<0 || getword(acchora,sizeof(acchora),&gwarea,' ')<0 || - getword(accuser,sizeof(accuser),&gwarea,' ')<0 || getword(accip,sizeof(accip),&gwarea,' ')<0 || + getword(accip,sizeof(accip),&gwarea,' ')<0 || getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword_atoll(&accbytes,&gwarea,' ')<0 || getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword_atoll(&accelap,&gwarea,' ')<0 || getword_skip(20000,&gwarea,' ')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); + debuga(_("There is a broken record or garbage in file %s"),tmp3); exit(1); } @@ -104,25 +126,23 @@ void data_file(char *tmp) if(!rtotal){ strcpy(oldurl,accurl); strcpy(oldacccode,acccode); - strcpy(oldaccuser,accuser); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); strcpy(oldacchora,acchora); rtotal++; } - if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){ + if(strcmp(oldurl,accurl) != 0 || new_user){ strcpy(oldmsg,"OK"); if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]); - gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + gravatmp(uinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); strcpy(wdirname,dirname); - saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); + saverecs(wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; nbytes=0; nelap=0; incache=0; oucache=0; - if(strcmp(oldaccuser,accuser) != 0) ind2=0; } nacc++; @@ -137,7 +157,7 @@ void data_file(char *tmp) else incache+=accbytes; strcpy(oldurl,accurl); - strcpy(oldaccuser,accuser); + new_user=0; strcpy(oldacccode,acccode); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); @@ -152,10 +172,9 @@ void data_file(char *tmp) debuga("Datafile %s successfully",DataFile); } -void saverecs(char *dirname, char *user, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache) +void saverecs(char *dirname, const struct userinfostruct *uinfo, long long int nacc, char *url, long long int nbytes, char *ip, char *hora, char *dia, long long int nelap, long long int incache, long long int oucache) { FILE *fp_ou; - char reg[MAXLEN]; char val[20]; if((fp_ou=MY_FOPEN(DataFile,"a"))==NULL){ @@ -164,51 +183,50 @@ void saverecs(char *dirname, char *user, long long int nacc, char *url, long lon } if((DataFileFields & DATA_FIELD_USER) != 0) { - strcpy(reg,user); - strncat(reg,DataFileDelimiter,1); + fputs(uinfo->label,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_DATE) != 0) { - strncat(reg,dia,strlen(dia)); - strncat(reg,DataFileDelimiter,1); + fputs(dia,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_TIME) != 0) { - strncat(reg,hora,strlen(hora)); - strncat(reg,DataFileDelimiter,1); + fputs(hora,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_URL) != 0) { strcpy(name,url); if (strcmp(DataFileUrl,"ip") == 0) name2ip(name); - strncat(reg,name,strlen(name)); - strncat(reg,DataFileDelimiter,1); + fputs(name,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_CONNECT) != 0) { my_lltoa(nacc,val,sizeof(val),0); - strcat(reg,val); - strncat(reg,DataFileDelimiter,1); + fputs(val,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_BYTES) != 0) { my_lltoa(nbytes,val,sizeof(val),0); - strcat(reg,val); - strncat(reg,DataFileDelimiter,1); + fputs(val,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_IN_CACHE) != 0) { my_lltoa(incache,val,sizeof(val),0); - strcat(reg,val); - strncat(reg,DataFileDelimiter,1); + fputs(val,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_OUT_CACHE) != 0) { my_lltoa(oucache,val,sizeof(val),0); - strcat(reg,val); - strncat(reg,DataFileDelimiter,1); + fputs(val,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } if((DataFileFields & DATA_FIELD_ELAPSED) != 0) { my_lltoa(nelap,val,sizeof(val),0); - strcat(reg,val); - strncat(reg,DataFileDelimiter,1); + fputs(val,fp_ou); + fputc(DataFileDelimiter[0],fp_ou); } - reg[strlen(reg)-1]='\n'; - fputs(reg,fp_ou); + fputc('\n',fp_ou); fclose(fp_ou); } diff --git a/denied.c b/denied.c index 5239001..3bdda55 100644 --- a/denied.c +++ b/denied.c @@ -45,11 +45,12 @@ void gen_denied_report(void) char ouser2[MAXLEN]; char data[15]; char hora[15]; - char *str; int z=0; int count=0; + int new_user; struct getwordstruct gwarea; struct longlinestruct line; + struct userinfostruct *uinfo; ouser[0]='\0'; ouser2[0]='\0'; @@ -69,7 +70,7 @@ void gen_denied_report(void) } if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (denied) read error in %s\n",per); + debuga(_("(denied) read error in %s"),per); exit(1); } fclose(fp_in); @@ -102,55 +103,54 @@ void gen_denied_report(void) getword_start(&gwarea,buf); if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(user,sizeof(user),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",denied_in); + debuga(_("There is a broken record or garbage in file %s"),denied_in); exit(1); } if (getword_ptr(buf,&url,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken url in your %s file"),denied_in); + debuga(_("There is a broken url in file %s"),denied_in); exit(1); } - if((str=(char *) strstr(user, "_")) != (char *) NULL ) { - if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) - fixip(user); + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s"),user,denied_in); + exit(1); } - if(Ip2Name) - ip2name(ip,sizeof(ip)); - + new_user=0; if(!z) { strcpy(ouser,user); strcpy(oip,ip); z++; + new_user=1; } else { - if(strcmp(ouser,user) == 0) - user[0]='\0'; - if(user[0] != '\0') + if(strcmp(ouser,user) != 0) { strcpy(ouser,user); - if(strcmp(oip,ip) == 0) - ip[0]='\0'; - if(ip[0] != '\0') + new_user=1; + } + if(strcmp(oip,ip) != 0) { strcpy(oip,ip); - } - - user_find(name, sizeof(name), user); - - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); + new_user=1; + } } if(DeniedReportLimit) { - if(strcmp(ouser2,name) == 0) { + if(strcmp(ouser2,uinfo->label) == 0) { count++; } else { count=1; - strcpy(ouser2,name); + strcpy(ouser2,uinfo->label); } if(count >= DeniedReportLimit) continue; } - fprintf(fp_ou,"%s%s%s-%s",name,ip,data,hora); + fputs("",fp_ou); + if (new_user) + fprintf(fp_ou,"%s%s",uinfo->label,ip); + else + fputs("",fp_ou); + fprintf(fp_ou,"%s-%s",data,hora); if(BlockIt[0] != '\0') { fprintf(fp_ou,"label) == 0) { count++; } else { count=1; - strcpy(ouser2,name); + strcpy(ouser2,uinfo->label); } if(count >= DownloadReportLimit) continue; @@ -157,15 +151,20 @@ void download_report(void) for (i=strlen(url)-1 ; i>=0 && (unsigned char)url[i]<' ' ; i--) url[i]=0; - fprintf(fp_ou,"%s%s%s-%s",name,ip,data,hora); + fputs("",fp_ou); + if (new_user) + fprintf(fp_ou,"%s%s",uinfo->label,ip); + else + fputs("",fp_ou); + fprintf(fp_ou,"%s-%s",data,hora); if(BlockIt[0]!='\0') { fprintf(fp_ou," ",ImageFile); } - fputs("",fp_ou); + fputs("\">http://",fp_ou); output_html_string(fp_ou,url,100); fputs("\n",fp_ou); } diff --git a/email.c b/email.c index 63c7b8c..7ec36a9 100644 --- a/email.c +++ b/email.c @@ -39,7 +39,6 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con int posicao=0; char olduser[MAX_USER_LEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN]; char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN], user[MAX_USER_LEN], tusr[MAXLEN]; - char user2[MAX_USER_LEN]; char strip1[MAXLEN], strip2[MAXLEN], strip3[MAXLEN], strip4[MAXLEN], strip5[MAXLEN], strip6[MAXLEN], strip7[MAXLEN]; int totuser=0; time_t t; @@ -208,27 +207,22 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con { getword_start(&gwarea,warea); if (getword(user,sizeof(user),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken user in your %s file.\n",top1); + debuga(_("There may be a broken user in file %s"),top1); exit(1); } if (getword_atoll(&nbytes,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1); + debuga(_("There may be a broken number of bytes in file %s"),top1); exit(1); } if (getword_atoll(&nacc,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1); + debuga(_("There is a broken number of access in file %s"),top1); exit(1); } if (getword_atoll(&elap,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",top1); + debuga(_("There is a broken elapsed time in file %s"),top1); exit(1); } - if(strchr(user,'_') != NULL) - fixip(user); - - strcpy(user2,user); - perc=(ttnbytes) ? nbytes * 100. / ttnbytes : 0; perc2=(ttnelap) ? elap * 100. / ttnelap : 0; @@ -245,11 +239,11 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con #endif } else { #if defined(__FreeBSD__) - fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10qu %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); + fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10qu %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); #elif defined(__alpha) || __ALPHA - fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10ld %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); + fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10ld %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); #else - fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10lld %3.2lf%%\n",posicao,user2,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); + fprintf(fp_top3,"%7d %20s %8lld %15s %3.2lf%% %10s %10lld %3.2lf%%\n",posicao,user,nacc,fixnum(nbytes,1),perc,buildtime(elap),elap,perc2); #endif } } @@ -282,7 +276,7 @@ int geramail(const char *dirname, int debug, const char *outdir, int userip, con } while(fgets(buf,sizeof(buf),fp_top3)!=NULL) - printf("%s",buf); + fputs(buf,stdout); } else { sprintf(buf,"\"%s\" -s \"SARG %s, %s\" \"%s\" <\"%s\"",MailUtility,text[55],asctime(local),email,top3); cstatus=system(buf); diff --git a/getconf.c b/getconf.c index fe65246..2a41a35 100644 --- a/getconf.c +++ b/getconf.c @@ -111,6 +111,19 @@ struct param_list index_tree_values[]= {"file",INDEX_TREE_FILE,~INDEX_TREE_FILE}, }; +struct param_list ntml_userformat_values[]= +{ + {"user",NTLMUSERFORMAT_USER,~NTLMUSERFORMAT_USER}, + {"domainname+username",NTLMUSERFORMAT_DOMAINUSER,~NTLMUSERFORMAT_DOMAINUSER}, +}; + +struct param_list recnouser_values[]= +{ + {"ip",RECORDWITHOUTUSER_IP,~RECORDWITHOUTUSER_IP}, + {"ignore",RECORDWITHOUTUSER_IGNORE,~RECORDWITHOUTUSER_IGNORE}, + {"everybody",RECORDWITHOUTUSER_EVERYBODY,~RECORDWITHOUTUSER_EVERYBODY}, +}; + static int is_param(const char *param,const char *buf) { int plen; @@ -419,7 +432,7 @@ static void parmtest(char *buf) if (getparam_bool("overwrite_report",buf,&OverwriteReport)>0) return; - if (getparam_string("records_without_userid",buf,RecordsWithoutUser,sizeof(RecordsWithoutUser))>0) return; + if (getparam_list("records_without_userid",SET_LIST(recnouser_values),buf,&RecordsWithoutUser)>0) return; if (getparam_bool("use_comma",buf,&UseComma)>0) return; @@ -540,7 +553,7 @@ static void parmtest(char *buf) if (getparam_string("ulimit",buf,Ulimit,sizeof(Ulimit))>0) return; - if (getparam_string("ntlm_user_format",buf,NtlmUserFormat,sizeof(NtlmUserFormat))>0) return; + if (getparam_list("ntlm_user_format",SET_LIST(ntml_userformat_values),buf,&NtlmUserFormat)>0) return; if (getparam_string("realtime_types",buf,RealtimeTypes,sizeof(RealtimeTypes))>0) return; diff --git a/grepday.c b/grepday.c index c70a790..bdb0623 100644 --- a/grepday.c +++ b/grepday.c @@ -234,7 +234,7 @@ static void bar(int x1,long long int n) } #endif //HAVE_GD -void greport_day(const char *user) +void greport_day(const struct userinfostruct *uinfo) { #ifdef HAVE_GD FILE *fp_in, *pngout; @@ -244,7 +244,6 @@ void greport_day(const char *user) char wdirname[MAXLEN]; char graph[MAXLEN]; char buf[MAXLEN]; - char wuser[255]; char csort[255]; char data[20]; char s[15]; @@ -267,7 +266,7 @@ void greport_day(const char *user) return; } if(access(GraphFont, R_OK) != 0) { - fprintf(stderr, "SARG: (grepday) Fontname: %s not found.\n",GraphFont); + debuga(_("(grepday) Fontname: %s not found"),GraphFont); exit(1); } @@ -339,16 +338,12 @@ void greport_day(const char *user) if(strcmp(DateFormat,"e") == 0) strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local); - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,7,0.0,620,470,ftime); if(ShowSargInfo) SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,257,15,"SARG, "); SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,10,0.0,300,15,Title); sprintf(warea,"%s: %s",text[89],period); SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,27,warea); - sprintf(warea,"%s: %s",text[90],name); + sprintf(warea,"%s: %s",text[90],uinfo->label); SARGgdImageStringFT(im,&brect[0],darkblue,GraphFont,9,0.0,300,38,warea); SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,418," 50K"); SARGgdImageStringFT(im,&brect[0],dimgray,GraphFont,7,0.0,23,408,"250K"); @@ -392,16 +387,16 @@ void greport_day(const char *user) SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,3.14/2,20,248,text[94]); SARGgdImageStringFT(im,&brect[0],black,GraphFont,10,0.0,330,460,text[127]); - if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,user)>=sizeof(graph)) { - fprintf(stderr, "SARG: user name too long for: %s/%s/graph_day.png\n",dirname,user); + if (snprintf(graph,sizeof(graph),"%s/%s/graph_day.png",dirname,uinfo->filename)>=sizeof(graph)) { + debuga(_("user name too long for: %s/%s/graph_day.png"),dirname,uinfo->filename); exit(1); } - if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,user)>=sizeof(wdirname)) { - fprintf(stderr, "SARG: user name too long for: %s/%s.day\n",tmp,user); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) { + debuga(_("user name too long for: %s/%s.day"),tmp,uinfo->filename); exit(1); } - if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,user)>=sizeof(tmp5)) { - fprintf(stderr, "SARG: user name too long for: %s/%s.graph\n",tmp,user); + if (snprintf(tmp5,sizeof(tmp5),"%s/%s.graph",tmp,uinfo->filename)>=sizeof(tmp5)) { + debuga(_("user name too long for: %s/%s.graph"),tmp,uinfo->filename); exit(1); } @@ -417,8 +412,8 @@ void greport_day(const char *user) cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } @@ -432,18 +427,6 @@ void greport_day(const char *user) exit(1); } - strcpy(wuser,user); - if(strstr(wuser,"_") != 0) - fixip(wuser); - - if(Ip2Name) - if((str=(char *) strstr(name, ".")) != (char *) NULL) { - if((str=(char *) strstr(str+1, ".")) != (char *) NULL) - ip2name(wuser,sizeof(wuser)); - } - - user_find(name, sizeof(name), wuser); - while(fgets(buf,sizeof(buf),fp_in)!=NULL) { fixendofline(buf); getword_start(&gwarea,buf); diff --git a/html.c b/html.c index 82a393b..ca965e2 100644 --- a/html.c +++ b/html.c @@ -42,10 +42,10 @@ void htmlrel(void) char *buf; char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; char *url, tmsg[50], csort[MAXLEN]; - char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN]; + char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], duser[MAXLEN]; char userhora[9], userdia[9]; char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; - char denied_report[255], name2[MAXLEN]; + char denied_report[255]; char *str; char warea[MAXLEN]; char totuser[8]; @@ -62,6 +62,7 @@ void htmlrel(void) struct getwordstruct gwarea; struct longlinestruct line,line1; struct generalitemstruct item; + const struct userinfostruct *uinfo; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; @@ -136,6 +137,12 @@ void htmlrel(void) } else { wusuario[0]=0; } + + uinfo=userinfo_find_from_file(wusuario); + if (!uinfo) { + debuga(_("Unknown user ID %s in directory %s"),wusuario,tmp); + exit(1); + } str=strrchr(wusuario,'.'); if (str) strcpy(denied_report,str+1); @@ -143,48 +150,30 @@ void htmlrel(void) strcpy(denied_report,wusuario); if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) { - fprintf(stderr,"SARG: destination directory too long: %s/%s\n",dirname,wusuario); + debuga(_("Destination directory too long: %s/%s"),dirname,wusuario); exit(1); } mkdir(warea,0755); - report_day(wusuario); - greport_day(wusuario); + report_day(uinfo); + greport_day(uinfo); strcpy(usuario,wusuario); - strcpy(arqin,tmp); - strcat(arqin,"/"); - strcpy(arqou,dirname); - strcat(arqou,"/"); - strcat(arqou,usuario); - strcat(arqou,"/"); - strcat(arqou,usuario); - strcat(arqou,".html"); - strcpy(duser,arqin); - strcat(duser,"denied_"); - strcat(arqin,direntp->d_name); - - if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) { - if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) - fixip(denied_report); + if (snprintf(arqin,sizeof(arqin),"%s/%s",tmp,direntp->d_name)>=sizeof(arqin)) { + debuga(_("Input file name too long: %s/%s"),tmp,direntp->d_name); + exit(1); + } + if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) { + debuga(_("Output file name too long: %s/%s/%s.html"),dirname,uinfo->filename,uinfo->filename); + exit(1); + } + if (snprintf(duser,sizeof(duser),"%s/%s/denied_%s.html",tmp,direntp->d_name,denied_report)>=sizeof(duser)) { + debuga(_("File name too long: %s/%s/denied_%s.html"),tmp,direntp->d_name,denied_report); + exit(1); } - strcat(duser,denied_report); - strcat(duser,".html"); if(access(duser, R_OK) != 0) denied_report[0]='\0'; - strcpy(u2,usuario); - if(userip) - fixip(u2); - if(Ip2Name) - ip2name(u2,sizeof(u2)); - - user_find(name2, sizeof(name2), u2); - - if(dotinuser && strchr(name2,'_')) { - subs(name2,sizeof(name2),"_","."); - } - if ((fp_in = fopen(arqin, "r")) == 0){ fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin); exit(1); @@ -203,35 +192,35 @@ void htmlrel(void) while((buf=longline_read(fp_in,&line))!=NULL) { getword_start(&gwarea,buf); if (getword_atoll(<emp,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin); + debuga(_("There is a broken number of access in file %s"),arqin); exit(1); } tnacc+=ltemp; if (getword_atoll(<emp,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken downloaded size in your %s file.\n",arqin); + debuga(_("There is a broken downloaded size in file %s"),arqin); exit(1); } tnbytes+=ltemp; if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken url in your %s file"),arqin); + debuga(_("There is a broken url in file %s"),arqin); exit(1); } if (getword_skip(MAXLEN,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); + debuga(_("There is a broken access code in file %s"),arqin); exit(1); } if (getword_atoll(<emp,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin); + debuga(_("There is a broken elapsed time in file %s"),arqin); exit(1); } tnelap+=ltemp; if (getword_atoll(<emp,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken in-cache volume in your %s file.\n",arqin); + debuga(_("There is a broken in-cache volume in file %s"),arqin); exit(1); } tnincache+=ltemp; if (getword_atoll(<emp,&gwarea,'\n')<0) { - printf("SARG: Maybe you have a broken out-cache volume in your %s file (%d).\n",arqin,__LINE__); + debuga(_("There is a broken out-cache volume in file %s"),arqin); exit(1); } tnoucache+=ltemp; @@ -246,7 +235,7 @@ void htmlrel(void) write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("User report")); fprintf(fp_ou,"%s: %s\n",text[89],period); - fprintf(fp_ou,"%s: %s\n",text[90],name2); + fprintf(fp_ou,"%s: %s\n",text[90],uinfo->label); fprintf(fp_ou,"%s: %s, %s\n",text[104],UserSortField,UserSortOrder); fprintf(fp_ou,"%s %s\n",text[32],text[55]); //fputs("\n",fp_ou); @@ -278,12 +267,7 @@ void htmlrel(void) fputs("\n",fp_ou); if(debug) { - if(userip) { - strcpy(u2,usuario); - fixip(u2); - debuga("%s: %s",text[61],u2); - } else - debuga("%s: %s",text[61],usuario); + debuga("%s: %s",text[61],usuario); } while((buf=longline_read(fp_in,&line))!=NULL) { @@ -527,7 +511,7 @@ void htmlrel(void) } while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) { fixendofline(tmp6); - if(strcmp(tmp6,u2) == 0) { + if(strcmp(tmp6,uinfo->label) == 0) { limit_flag=1; break; } @@ -540,11 +524,11 @@ void htmlrel(void) fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile); exit(1); } - fprintf(fp_usr,"%s\n",u2); + fprintf(fp_usr,"%s\n",uinfo->label); fclose(fp_usr); if(debug) - debuga("%s %s %s (%d MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile); + debuga("%s %s %s (%d MB). %s %s",text[32],uinfo->label,text[74],PerUserLimit,text[75],PerUserLimitFile); } } } diff --git a/include/conf.h b/include/conf.h index 623e7e4..8cdd5a4 100755 --- a/include/conf.h +++ b/include/conf.h @@ -152,7 +152,8 @@ int mkstemps(char *template, int suffixlen); #define MAXLEN 20000 #define MAX_URL_LEN 40000 #define MAX_TRUNCATED_URL 512 -#define MAX_USER_LEN 512 +#define MAX_USER_LEN 256 +#define MAX_USER_FNAME_LEN 128 #define MAX_IP_LEN 64 #define MAX_DATETIME_LEN 32 #define MAXLOGS 255 @@ -207,6 +208,13 @@ int mkstemps(char *template, int suffixlen); #define INDEX_TREE_DATE 0x0001UL #define INDEX_TREE_FILE 0x0002UL +#define NTLMUSERFORMAT_USER 0x0001UL +#define NTLMUSERFORMAT_DOMAINUSER 0x0002UL + +#define RECORDWITHOUTUSER_IP 0x0001UL +#define RECORDWITHOUTUSER_IGNORE 0x0002UL +#define RECORDWITHOUTUSER_EVERYBODY 0x0004UL + char outdir[MAXLEN]; char dirname[MAXLEN]; char buf[MAXLEN]; @@ -226,7 +234,7 @@ int RemoveTempFiles; char ReplaceIndex[256]; unsigned long int Index; int OverwriteReport; -char RecordsWithoutUser[20]; +unsigned long int RecordsWithoutUser; int UseComma; char MailUtility[PATH_MAX]; int TopSitesNum; @@ -313,7 +321,7 @@ char TitleFontSize[5]; char wwwDocumentRoot[MAXLEN]; char ExternalCSSFile[MAXLEN]; char BlockIt[255]; -char NtlmUserFormat[30]; +unsigned long int NtlmUserFormat; unsigned long int IndexTree; int UserAuthentication; char AuthUserFile[255]; @@ -377,7 +385,6 @@ int color2; int color3; int z1, z2, z3; int ttopen; -int ind2; int sarglog; int isalog; int dfrom; @@ -397,7 +404,6 @@ int SiteUsersReportLimit; int DansGuardianReportLimit; int SquidGuardReportLimit; int UserReportLimit; -int dotinuser; int realtime_refresh; int realtime_access_log_lines; int realt; diff --git a/include/defs.h b/include/defs.h index f4c8a7c..addee80 100755 --- a/include/defs.h +++ b/include/defs.h @@ -1,3 +1,6 @@ +/*!\file +\brief Declaration of the structures and functions. +*/ struct getwordstruct { @@ -46,6 +49,18 @@ struct generalitemstruct long long oucache; }; +struct userinfostruct +{ + //! The ID of the user as found in the input file. + char id[MAX_USER_LEN]; + //! \c True if the ID is in fact the IP address from which the user connected. + int id_is_ip; + //! The name of the user to display in the report. + char label[MAX_USER_LEN]; + //! The mangled name to use in file names of that user. + char filename[MAX_USER_FNAME_LEN]; +}; + // auth.c void htaccess(const char *name); @@ -98,7 +113,7 @@ void free_exclude(void); void getconf(void); // grepday.c -void greport_day(const char *user); +void greport_day(const struct userinfostruct *user); void greport_cleanup(void); // html.c @@ -124,10 +139,10 @@ void make_index(void); void realtime(void); // repday.c -void report_day(const char *user); +void report_day(const struct userinfostruct *user); // report.c -void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); +void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); void gerarel(void); int ger_read(char *buffer,struct generalitemstruct *item,const char *filename); @@ -157,7 +172,7 @@ void topsites(void); void topuser(void); // totday.c -void day_totalize(const char *tmp, const char *user, int indexonly); +void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly); // totger.c int totalger(const char *dirname, int debug, const char *outdir); @@ -168,6 +183,12 @@ void usage(const char *prog); // useragent.c void useragent(void); +// userinfo.c +struct userinfostruct *userinfo_create(const char *userid); +void userinfo_free(void); +struct userinfostruct *userinfo_find_from_file(const char *filename); +struct userinfostruct *userinfo_find_from_id(const char *id); + // usertab.c void init_usertab(const char *UserTabFile); void user_find(char *mappedname, int namelen, const char *userlogin); @@ -189,7 +210,6 @@ void name_month(char *month,int month_len); void conv_month_name(char *month); void buildymd(const char *dia, const char *mes, const char *ano, char *wdata); void date_from(char *date, char *dfrom, char *duntil); -void fixip(char *ip); char *fixnum(long long int value, int n); char *fixnum2(long long int value, int n); void fixnone(char *str); diff --git a/log.c b/log.c index 4ca2b7e..80fb0a2 100644 --- a/log.c +++ b/log.c @@ -28,6 +28,14 @@ #include "include/defs.h" #define REPORT_EVERY_X_LINES 5000 +#define MAX_OPEN_USER_FILES 10 + +struct userfilestruct +{ + struct userfilestruct *next; + struct userinfostruct *user; + FILE *file; +}; static char *userfile=NULL; @@ -63,7 +71,6 @@ int main(int argc,char *argv[]) char sz_Download_Unsort[ 20000 ] ; FILE * fp_Download_Unsort = NULL ; - FILE * fp_Write_User = NULL ; extern int optind; extern int optopt; @@ -111,7 +118,7 @@ int main(int argc,char *argv[]) enum InputLogFormat ilf; int ilf_count[ILF_Last]; int ch; - int x, l; + int x; int errflg=0; int puser=0; int fhost=0; @@ -124,6 +131,9 @@ int main(int argc,char *argv[]) int isa_ncols=0,isa_cols[ISACOL_Last]; int from_stdin; int blen; + int maxopenfiles; + int nopen; + int id_is_ip; long totregsl=0; long totregsg=0; long totregsx=0; @@ -136,9 +146,10 @@ int main(int argc,char *argv[]) int OutputNonZero = REPORT_EVERY_X_LINES ; int download_flag=0; char *download_url; - char sz_Last_User[MAXLEN]=""; struct getwordstruct gwarea; struct longlinestruct line; + struct userinfostruct *uinfo; + struct userfilestruct *first_user_file, *ufile, *ufile1, *prev_ufile; BgImage[0]='\0'; LogoImage[0]='\0'; @@ -180,7 +191,7 @@ int main(int argc,char *argv[]) RemoveTempFiles=1; strcpy(ReplaceIndex,"index.html"); Index=INDEX_YES; - strcpy(RecordsWithoutUser,"ip"); + RecordsWithoutUser=RECORDWITHOUTUSER_IP; UseComma=0; strcpy(MailUtility,"mailx"); TopSitesNum=100; @@ -232,7 +243,7 @@ int main(int argc,char *argv[]) GraphFont[0]='\0'; #endif strcpy(Ulimit,"20000"); - strcpy(NtlmUserFormat,"domainname+username"); + NtlmUserFormat=NTLMUSERFORMAT_DOMAINUSER; IndexTree=INDEX_TREE_FILE; strcpy(RealtimeTypes,"GET,PUT,CONNECT"); strcpy(RealtimeUnauthRec,"show"); @@ -300,7 +311,6 @@ int main(int argc,char *argv[]) color1=0; color2=0; color3=0; - dotinuser=0; realt=0; realtime_refresh=3; realtime_access_log_lines=1000; @@ -309,8 +319,9 @@ int main(int argc,char *argv[]) ndownload=0; squid24=0; - bzero(IncludeUsers, MAXLEN); - bzero(ExcludeString, MAXLEN); + bzero(IncludeUsers, sizeof(IncludeUsers)); + bzero(ExcludeString, sizeof(ExcludeString)); + first_user_file=NULL; #ifdef HAVE_LOCALE_H setlocale(LC_TIME,""); @@ -674,6 +685,7 @@ int main(int argc,char *argv[]) if(debug) debuga("sarg %s: %s",text[73],VERSION); + maxopenfiles=MAX_OPEN_USER_FILES; #ifdef HAVE_RLIM_T if (Ulimit[0] != '\0') { struct rlimit rl; @@ -700,7 +712,7 @@ int main(int argc,char *argv[]) #warning "No rlimit resource for the number of open files" #endif if(rc == -1) { - debuga("setrlimit error - %s\n",strerror(errno)); + debuga(_("setrlimit error - %s\n"),strerror(errno)); } if(debug) @@ -1119,7 +1131,7 @@ int main(int argc,char *argv[]) sprintf(data," %s/%s/%s:%s",dia,mes,ano,hora); } - if(strlen(user) > 150) { + if(strlen(user) > MAX_USER_LEN) { if (debugm) printf("User too long: %s\n",user); totregsx++; continue; @@ -1167,25 +1179,6 @@ int main(int argc,char *argv[]) } #endif - for(str=user; *str; str++) { - if(*str=='.') dotinuser++; - if(*str=='?' || *str=='.' || *str==':' || *str=='/' || *str=='\\' || *str=='\'' || *str=='$' || *str=='@' || - *str=='\"' || *str=='*') - *str='_'; - } - - strlow(user); - if(strncmp(NtlmUserFormat,"user",4) == 0) { - if((str = strchr(user,'_')) != 0) { - strcpy(warea,str+1); - strcpy(user,warea); - } - if((str = strchr(user,'+')) != 0) { - strcpy(warea,str+1); - strcpy(user,warea); - } - } - urly=url; if(ilf!=ILF_Sarg) { @@ -1305,75 +1298,74 @@ int main(int argc,char *argv[]) if(debugm) printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",date,idata,dfrom,duntil); - l=1; - if(l){ - if(addr[0] != '\0'){ - if(strcmp(addr,ip)==0) - l=1;else l=0; - } - if(fhost) { -// l=vhexclude(ip); - l=vhexclude(url); - if(!l) { - if (debugm) printf("Excluded site: %s\n",url); - totregsx++; - } + if(addr[0] != '\0'){ + if(strcmp(addr,ip)!=0) continue; + } + if(fhost) { + if(!vhexclude(url)) { + if (debugm) printf(_("Excluded site: %s\n"),url); + totregsx++; + continue; } } + if(url[0] == '\0') continue; - if(l){ - if(date[0] != '\0'){ - if(idata >= dfrom && idata <= duntil) - l=1;else l=0; - } + if(date[0] != '\0'){ + if(idata < dfrom || idata > duntil) continue; } - if(l){ - if(hm[0] != '\0') { - bzero(hmr,sizeof(hmr)); - chm++; - getword_start(&gwarea,hora); - while(chm) { - if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){ - printf("SARG: Maybe you have a broken time in your %s file.\n",arq); - exit(1); - } - strncat(hmr,warea,2); - chm--; - } - strncat(hmr,gwarea.current,2); - if(atoi(hmr) >= atoi(hm) && atoi(hmr) <= atoi(hmf)) - l=1;else l=0; + if(hm[0] != '\0') { + bzero(hmr,sizeof(hmr)); + chm++; + getword_start(&gwarea,hora); + while(chm) { + if (getword_multisep(warea,sizeof(warea),&gwarea,':')<0){ + printf("SARG: Maybe you have a broken time in your %s file.\n",arq); + exit(1); + } + strncat(hmr,warea,2); + chm--; } + strncat(hmr,gwarea.current,2); + + if(atoi(hmr) < atoi(hm) || atoi(hmr) > atoi(hmf)) continue; } - if(l){ - if(site[0] != '\0'){ - if(strstr(url,site)!=0) - l=1;else l=0; - } + + if(site[0] != '\0'){ + if(strstr(url,site)==0) continue; } - if(userip) + if(userip) { strcpy(user,ip); - - if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) { - if(strcmp(RecordsWithoutUser,"ip") == 0) - strcpy(user,ip); - if(strcmp(RecordsWithoutUser,"ignore") == 0) - continue; - if(strcmp(RecordsWithoutUser,"everybody") == 0) - strcpy(user,"everybody"); - } - if(us[0] != '\0'){ - if(strcmp(user,us)==0) - l=1; - else - l=0; + id_is_ip=1; + } else { + id_is_ip=0; + if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) { + if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) { + strcpy(user,ip); + id_is_ip=1; + } + if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) + continue; + if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY) + strcpy(user,"everybody"); + } else { + strlow(user); + if(NtlmUserFormat == NTLMUSERFORMAT_USER) { + if((str = strchr(user,'_')) != 0) { + strcpy(warea,str+1); + strcpy(user,warea); + } + if((str = strchr(user,'+')) != 0) { + strcpy(warea,str+1); + strcpy(user,warea); + } + } + } } - if(dotinuser) { - subs(user,sizeof(user),"_","."); - dotinuser=0; + if(us[0] != '\0'){ + if(strcmp(user,us)!=0) continue; } if(puser) { @@ -1382,103 +1374,141 @@ int main(int argc,char *argv[]) continue; } - if(l) { - if(fuser) { - l=vuexclude(user); - if(!l) { - if (debugm) printf("Excluded user: %s\n",user); - totregsx++; - } + if(fuser) { + if(!vuexclude(user)) { + if (debugm) printf(_("Excluded user: %s\n"),user); + totregsx++; + continue; } } - if(l) { - if(userip) - fixip(user); - } + if(strcmp(user,"-") ==0 || strcmp(user," ") ==0 || strcmp(user,"") ==0 || strcmp(user,":") ==0) + continue; - if(l && max_elapsed) { + if(max_elapsed) { if(atol(elap)>max_elapsed) { elap[0]='0'; elap[1]='\0'; } } - if(l) { - if(strcmp(user,"-") !=0 && url[0] != '\0' && strcmp(user," ") !=0 && strcmp(user,"") !=0 && strcmp(user,":") !=0){ - if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) { - fixendofline(str); - sprintf(smartfilter,"\"%s\"",str+1); - } else sprintf(smartfilter,"\"\""); - - if ( strcmp ( user , sz_Last_User ) != 0 ) { - if ( fp_Write_User ) - fclose( fp_Write_User ) ; - sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user); - - if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) { - fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno)); - exit (1); + if((str=(char *) strstr(linebuf, "[SmartFilter:")) != (char *) NULL ) { + fixendofline(str); + sprintf(smartfilter,"\"%s\"",str+1); + } else sprintf(smartfilter,"\"\""); + + nopen=0; + prev_ufile=NULL; + for (ufile=first_user_file ; ufile && strcmp(user,ufile->user->id)!=0 ; ufile=ufile->next) { + prev_ufile=ufile; + if (ufile->file) nopen++; + } + if (!ufile) { + ufile=malloc(sizeof(*ufile)); + if (!ufile) { + debuga(_("Not enough memory to store the user %s"),user); + exit(1); + } + memset(ufile,0,sizeof(*ufile)); + ufile->next=first_user_file; + first_user_file=ufile; + uinfo=userinfo_create(user); + ufile->user=uinfo; + uinfo->id_is_ip=id_is_ip; + } else { + if (prev_ufile) { + prev_ufile->next=ufile->next; + ufile->next=first_user_file; + first_user_file=ufile; + } + } + + if (ufile->file==NULL) { + if (nopen>=maxopenfiles) { + x=0; + for (ufile1=first_user_file ; ufile1 ; ufile1=ufile1->next) { + if (ufile1->file!=NULL) { + if (x>=maxopenfiles) { + fclose(ufile1->file); + ufile1->file=NULL; + } + x++; } - strcpy( sz_Last_User , user ) ; } - fprintf(fp_Write_User, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter); + } + sprintf (tmp3, "%s/sarg/%s.unsort", tmp, ufile->user->filename); + if ((ufile->file = MY_FOPEN (tmp3, "a")) == NULL) { + fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno)); + exit (1); + } + } - if(fp_log && ilf!=ILF_Sarg) - fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter); + /*if ( strcmp ( user , sz_Last_User ) != 0 ) { + if ( fp_Write_User ) + fclose( fp_Write_User ) ; + sprintf (tmp3, "%s/sarg/%s.unsort", tmp, user); - totregsg++; + if ((fp_Write_User = MY_FOPEN (tmp3, "a")) == NULL) { + fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno)); + exit (1); + } + strcpy( sz_Last_User , user ) ; + }*/ + fprintf(ufile->file, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,ip,url,tam,code,elap,smartfilter); - if(download_flag && strstr(code,"DENIED") == 0) { - ndownload = 1; + if(fp_log && ilf!=ILF_Sarg) + fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,url,tam,code,elap,smartfilter); - if ( ! fp_Download_Unsort ) { - if ((fp_Download_Unsort = MY_FOPEN ( sz_Download_Unsort, "a")) == NULL) { - fprintf (stderr, "%s: (log) %s: %s - %s\n", argv[0], text[9], tmp3, strerror(errno)); - exit (1); - } - } - fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url); - } + totregsg++; - if((ReportType & REPORT_TYPE_DENIED) != 0 || (ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) { - if(strstr(code,"DENIED/403") != 0) { - fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly); - denied_count++; - } - if(strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0) { - if(fp_authfail) - fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,urly); - authfail_count++; - } - } + if(download_flag && strstr(code,"DENIED") == 0) { + ndownload = 1; - if((!totper || idatanext; + if (ufile->file!=NULL) fclose(ufile->file); + free(ufile); + } free_download(); free_excludecodes(); @@ -1526,6 +1559,7 @@ int main(int argc,char *argv[]) fclose(fp_denied); if(fp_authfail) fclose(fp_authfail); + userinfo_free(); if(userfile) free(userfile); close_usertab(); @@ -1544,6 +1578,7 @@ int main(int argc,char *argv[]) fclose(fp_denied); if(fp_authfail) fclose(fp_authfail); + userinfo_free(); if(userfile) free(userfile); close_usertab(); @@ -1636,6 +1671,7 @@ int main(int argc,char *argv[]) unlinkdir(tmp,0); } + userinfo_free(); if(userfile) free(userfile); close_usertab(); diff --git a/po/fr.po b/po/fr.po index b2d8e3a..b5e38a4 100644 --- a/po/fr.po +++ b/po/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: @PACKAGE@ @VERSION@\n" "Report-Msgid-Bugs-To: fmarchal@users.sourceforge.net\n" -"POT-Creation-Date: 2010-02-09 14:07+0100\n" +"POT-Creation-Date: 2010-02-28 15:56+0100\n" "PO-Revision-Date: 2010-02-09 14:23+0100\n" "Last-Translator: Frederic Marchal \n" "Language-Team: French\n" @@ -16,65 +16,641 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: authfail.c:97 +#: authfail.c:78 +#, c-format +msgid "(authfail) read error in %s" +msgstr "" + +#: authfail.c:86 grepday.c:415 realtime.c:82 siteuser.c:80 smartfilter.c:85 +#: topuser.c:172 +#, c-format +msgid "sort command return status %d" +msgstr "" + +#: authfail.c:87 authfail.c:92 grepday.c:416 realtime.c:83 siteuser.c:81 +#: siteuser.c:87 smartfilter.c:86 smartfilter.c:91 topuser.c:173 +#, c-format +msgid "sort command: %s" +msgstr "" + +#: authfail.c:102 msgid "Authentication Failures" msgstr "Erreur d'authentification" -#: dansguardian_report.c:85 +#: authfail.c:114 html.c:94 html.c:183 html.c:385 html.c:413 siteuser.c:119 +#: topsites.c:108 topsites.c:215 +#, c-format +msgid "Not enough memory to read file %s" +msgstr "" + +#: authfail.c:122 denied.c:105 download.c:110 squidguard_report.c:97 +#, c-format +msgid "There is a broken record or garbage in file %s" +msgstr "" + +#: authfail.c:126 denied.c:109 download.c:114 html.c:205 +#: squidguard_report.c:101 +#, c-format +msgid "There is a broken url in file %s" +msgstr "" + +#: authfail.c:132 denied.c:115 download.c:120 siteuser.c:128 smartfilter.c:130 +#: topuser.c:284 +#, c-format +msgid "Unknown user ID %s in file %s" +msgstr "" + +#: dansguardian_log.c:135 dansguardian_log.c:144 dansguardian_report.c:97 +#: log.c:1004 log.c:1063 realtime.c:210 realtime.c:214 realtime.c:218 +#: realtime.c:222 util.c:790 util.c:794 +#, c-format +msgid "Maybe you have a broken record or garbage in your %s file" +msgstr "" + +#: dansguardian_log.c:139 dansguardian_report.c:101 html.c:284 log.c:915 +#: log.c:974 realtime.c:227 topsites.c:231 +#, c-format +msgid "Maybe you have a broken url in your %s file" +msgstr "" + +#: dansguardian_report.c:69 +#, c-format +msgid "(dansguardian_report) read error in %s" +msgstr "" + +#: dansguardian_report.c:84 msgid "DansGuardian" msgstr "DansGuardian" -#: denied.c:85 +#: dansguardian_report.c:105 +#, c-format +msgid "Maybe you have a broken rule in your %s file" +msgstr "" + +#: denied.c:72 +#, c-format +msgid "(denied) read error in %s" +msgstr "" + +#: denied.c:87 msgid "DENIED" msgstr "DENIED" -#: download.c:90 +#: denied.c:97 +#, c-format +msgid "Not enough memory to read the denied accesses" +msgstr "" + +#: download.c:77 +#, c-format +msgid "(download) read error in %s" +msgstr "" + +#: download.c:92 msgid "Downloads" msgstr "Téléchargements" -#: html.c:238 +#: download.c:102 topuser.c:245 +#, c-format +msgid "Not enough memory to read the downloaded files" +msgstr "" + +#: email.c:210 +#, c-format +msgid "There may be a broken user in file %s" +msgstr "" + +#: email.c:214 +#, c-format +msgid "There may be a broken number of bytes in file %s" +msgstr "" + +#: email.c:218 html.c:195 +#, c-format +msgid "There is a broken number of access in file %s" +msgstr "" + +#: email.c:222 html.c:213 +#, c-format +msgid "There is a broken elapsed time in file %s" +msgstr "" + +#: grepday.c:391 +#, c-format +msgid "user name too long for: %s/%s/graph_day.png" +msgstr "" + +#: grepday.c:395 +#, c-format +msgid "user name too long for: %s/%s.day" +msgstr "" + +#: grepday.c:399 +#, c-format +msgid "user name too long for: %s/%s.graph" +msgstr "" + +#: html.c:143 +#, c-format +msgid "Unknown user ID %s in directory %s" +msgstr "" + +#: html.c:153 +#, c-format +msgid "Destination directory too long: %s/%s" +msgstr "" + +#: html.c:163 +#, c-format +msgid "Input file name too long: %s/%s" +msgstr "" + +#: html.c:167 +#, c-format +msgid "Output file name too long: %s/%s/%s.html" +msgstr "" + +#: html.c:171 +#, c-format +msgid "File name too long: %s/%s/denied_%s.html" +msgstr "" + +#: html.c:200 +#, c-format +msgid "There is a broken downloaded size in file %s" +msgstr "" + +#: html.c:209 +#, c-format +msgid "There is a broken access code in file %s" +msgstr "" + +#: html.c:218 +#, c-format +msgid "There is a broken in-cache volume in file %s" +msgstr "" + +#: html.c:223 +#, c-format +msgid "There is a broken out-cache volume in file %s" +msgstr "" + +#: html.c:236 msgid "User report" msgstr "Rapport par utilisateur" -#: repday.c:72 +#: html.c:423 +#, c-format +msgid "Maybe you have a broken user url in your %s file" +msgstr "" + +#: index.c:339 +#, c-format +msgid "Maybe you have a broken week day in your %s%s/sarg-date file" +msgstr "" + +#: index.c:343 +#, c-format +msgid "Maybe you have a broken month in your %s%s/sarg-date file" +msgstr "" + +#: index.c:347 +#, c-format +msgid "Maybe you have a broken day in your %s%s/sarg-date file" +msgstr "" + +#: index.c:351 index.c:361 +#, c-format +msgid "Maybe you have a broken time in your %s%s/sarg-date file" +msgstr "" + +#: index.c:356 +#, c-format +msgid "Maybe you have a broken year in your %s%s/sarg-date file" +msgstr "" + +#: log.c:715 +#, c-format +msgid "setrlimit error - %s\n" +msgstr "" + +#: log.c:726 +#, c-format +msgid "Not enough memory to read a log file" +msgstr "" + +#: log.c:1306 +#, c-format +msgid "Excluded site: %s\n" +msgstr "" + +#: log.c:1379 +#, c-format +msgid "Excluded user: %s\n" +msgstr "" + +#: log.c:1409 +#, c-format +msgid "SARG: Not enough memory to store the user %s\n" +msgstr "" + +#: realtime.c:59 +#, c-format +msgid "(realtime) mkstemp error - %s" +msgstr "" + +#: realtime.c:64 realtime.c:202 +#, c-format +msgid "Not enough memory to read the log file" +msgstr "" + +#: realtime.c:72 +#, c-format +msgid "Maybe a broken record or garbage was returned by %s" +msgstr "" + +#: realtime.c:104 +#, c-format +msgid "The time stamp at column 1 is too long." +msgstr "" + +#: realtime.c:108 +#, c-format +msgid "The connection duration at column 2 is too long." +msgstr "" + +#: realtime.c:116 +#, c-format +msgid "The IP address at column 3 is too long." +msgstr "" + +#: realtime.c:120 +#, c-format +msgid "The status at column 4 is too long." +msgstr "" + +#: realtime.c:124 +#, c-format +msgid "The size at column 5 is too long." +msgstr "" + +#: realtime.c:128 +#, c-format +msgid "The action at column 6 is too long." +msgstr "" + +#: realtime.c:133 realtime.c:142 realtime.c:146 +#, c-format +msgid "The URL at column 7 is too long." +msgstr "" + +#: realtime.c:137 +#, c-format +msgid "The user ID at column 8 is too long." +msgstr "" + +#: realtime.c:150 +#, c-format +msgid "The URL at column 7 is too long" +msgstr "" + +#: realtime.c:154 +#, c-format +msgid "The data at column 8 is too long" +msgstr "" + +#: realtime.c:158 +#, c-format +msgid "The user at column 9 is too long" +msgstr "" + +#: realtime.c:195 +#, c-format +msgid "(realtime) open error %s - %s" +msgstr "" + +#: realtime.c:255 report.c:203 report.c:298 report.c:328 siteuser.c:139 +#: siteuser.c:190 topsites.c:122 topsites.c:137 +#, c-format +msgid "Not enough memory to store the url" +msgstr "" + +#: repday.c:56 +#, c-format +msgid "Output file name too long: %s/%s/d%s.html" +msgstr "" + +#: repday.c:74 msgid "Day report" msgstr "Rapport journalier" -#: report.c:250 +#: repday.c:103 +#, c-format +msgid "There is a broken date in file %s" +msgstr "" + +#: repday.c:112 +#, c-format +msgid "There is a broken time in file %s" +msgstr "" + +#: repday.c:116 +#, c-format +msgid "There is a broken quantity in file %s" +msgstr "" + +#: report.c:134 +#, c-format +msgid "Ignoring unknown user file %s" +msgstr "" + +#: report.c:152 +#, c-format +msgid "Not enough memory to read the downloaded files." +msgstr "" + +#: report.c:162 +#, c-format +msgid "Maybe you have a broken record or garbage in your %s file (%d)." +msgstr "" + +#: report.c:167 +#, c-format +msgid "Maybe you have a broken elapsed time in your %s file (%d)." +msgstr "" + +#: report.c:171 +#, c-format +msgid "Maybe you have a broken smart info in your %s file (%d)." +msgstr "" + +#: report.c:275 msgid "Site access report" msgstr "Rapport des sites visités" -#: siteuser.c:95 +#: report.c:433 report.c:482 +#, c-format +msgid "Temporary file name too long: %s/%s.utmp" +msgstr "" + +#: report.c:458 +#, c-format +msgid "Temporary file name too long: %s/%s.htmp" +msgstr "" + +#: report.c:625 +#, c-format +msgid "Invalid total number of accesses in %s" +msgstr "" + +#: report.c:642 +#, c-format +msgid "Invalid total size in %s" +msgstr "" + +#: report.c:659 +#, c-format +msgid "Invalid total elapsed time in %s" +msgstr "" + +#: report.c:676 +#, c-format +msgid "Invalid total cache hit in %s" +msgstr "" + +#: report.c:693 +#, c-format +msgid "Invalid total cache miss in %s" +msgstr "" + +#: report.c:703 +#, c-format +msgid "User name too long or invalid in %s" +msgstr "" + +#: report.c:719 +#, c-format +msgid "Invalid number of accesses in %s" +msgstr "" + +#: report.c:736 +#, c-format +msgid "Invalid number of bytes in %s" +msgstr "" + +#: report.c:745 +#, c-format +msgid "URL too long or invalid in %s" +msgstr "" + +#: report.c:753 +#, c-format +msgid "IP address too long or invalid in %s" +msgstr "" + +#: report.c:761 +#, c-format +msgid "Time too long or invalid in %s" +msgstr "" + +#: report.c:769 +#, c-format +msgid "Date too long or invalid in %s" +msgstr "" + +#: report.c:785 +#, c-format +msgid "Invalid elapsed time in %s" +msgstr "" + +#: report.c:802 +#, c-format +msgid "Invalid cache hit size in %s" +msgstr "" + +#: report.c:819 +#, c-format +msgid "Invalid cache miss size in %s" +msgstr "" + +#: siteuser.c:72 +#, c-format +msgid "(siteuser) read error in %s" +msgstr "" + +#: siteuser.c:96 msgid "Sites & Users" msgstr "Sites & Utilisateurs" -#: squidguard_report.c:85 +#: smartfilter.c:74 +#, c-format +msgid "(smartfilter) read error in %s" +msgstr "" + +#: smartfilter.c:80 +#, c-format +msgid "cannot build the sort command to sort file %s" +msgstr "" + +#: smartfilter.c:124 +#, c-format +msgid "There is e a broken record or garbage in file %s" +msgstr "" + +#: squidguard_log.c:102 squidguard_log.c:107 squidguard_log.c:112 +#: squidguard_log.c:173 +#, c-format +msgid "Maybe you have a broken record or garbage in your %s file." +msgstr "" + +#: squidguard_log.c:117 +#, c-format +msgid "Year string too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:123 +#, c-format +msgid "Month string too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:129 +#, c-format +msgid "Day string too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:135 +#, c-format +msgid "Hour string too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:141 +#, c-format +msgid "Banning list name too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:147 +#, c-format +msgid "IP address too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:153 +#, c-format +msgid "User ID too long in squidGuard log file %s" +msgstr "" + +#: squidguard_log.c:159 +#, c-format +msgid "URL too long in squidGuard log file %s" +msgstr "" + +#: squidguard_report.c:69 +#, c-format +msgid "(squidguard) read error in %s" +msgstr "" + +#: squidguard_report.c:84 msgid "SQUIDGUARD" msgstr "SQUIDGUARD" -#: topsites.c:219 +#: squidguard_report.c:105 +#, c-format +msgid "There is a broken rule in file %s" +msgstr "" + +#: topsites.c:199 msgid "Top sites" msgstr "Sites les plus visités" -#: topuser.c:233 +#: topuser.c:107 util.c:771 +#, c-format +msgid "Not enough memory to read the file %s" +msgstr "" + +#: topuser.c:189 #, c-format msgid "SARG report for %s" msgstr "Rapport pour %s" -#: topuser.c:251 +#: topuser.c:207 msgid "Useragent" msgstr "Useragent" -#: useragent.c:158 +#: topuser.c:252 +#, c-format +msgid "There may be a broken user in file %s." +msgstr "" + +#: topuser.c:256 +#, c-format +msgid "There may be a broken number of bytes in file %s." +msgstr "" + +#: topuser.c:260 +#, c-format +msgid "There may be a broken number of access in file %s." +msgstr "" + +#: topuser.c:264 +#, c-format +msgid "There may be a broken elpased time in file %s." +msgstr "" + +#: topuser.c:268 +#, c-format +msgid "There may be a broken in-cache size in file %s." +msgstr "" + +#: topuser.c:272 +#, c-format +msgid "There may be a broken out-of-cache size in file %s." +msgstr "" + +#: totger.c:51 +#, c-format +msgid "Not enough memory to read the temporary file %s" +msgstr "" + +#: useragent.c:160 msgid "Squid Useragent's Report" msgstr "Rapport des useragents de Squid" -#: util.c:77 +#: util.c:79 #, c-format msgid "getword backtrace:" msgstr "getword backtrace" -#: util.c:1584 +#: util.c:98 +#, c-format +msgid "Cannot parse again the line as it was modified" +msgstr "" + +#: util.c:242 +#, c-format +msgid "Invalid buffer passed to getword_ptr" +msgstr "" + +#: util.c:340 +#, c-format +msgid "" +"The requested number length passed to my_lltoa (%d) is bigger than the " +"output buffer size (%d)" +msgstr "" + +#: util.c:478 +msgid "SARG: " +msgstr "" + +#: util.c:784 +#, c-format +msgid "Maybe you have a invalid user in your %s file" +msgstr "" + +#: util.c:1651 #, c-format msgid "cannot stat %s" msgstr "Impossible d'obtenir les stat de %s" + +#: util.c:1710 util.c:1723 +#, c-format +msgid "Not enough memory to read one more line from the input log file" +msgstr "" diff --git a/realtime.c b/realtime.c index 43127b8..f3d0a5b 100755 --- a/realtime.c +++ b/realtime.c @@ -56,7 +56,7 @@ static void getlog(void) fd2 = mkstemp(template2); if((fd1 == -1 ) || ((tmp = fdopen (fd1, "w+" )) == NULL) ) { /* failure, bail out */ - fprintf(stderr, "SARG: (realtime) mkstemp error - %s\n",strerror(errno)); + debuga(_("(realtime) mkstemp error - %s"),strerror(errno)); exit(1); } @@ -69,7 +69,7 @@ static void getlog(void) fp = popen(cmd, "r"); while((buf=longline_read(fp,&line)) != NULL ) if (getdata(buf,tmp)<0) { - fprintf(stderr,"SARG: Maybe a broken record or garbage was returned by %s.\n",cmd); + debuga(_("Maybe a broken record or garbage was returned by %s"),cmd); exit(1); } pclose(fp); @@ -79,8 +79,8 @@ static void getlog(void) sprintf(cmd,"sort -r -k 1,1 -k 2,2 -o \"%s\" \"%s\"",template2,template1); cstatus=system(cmd); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",cmd); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),cmd); exit(1); } unlink(template1); @@ -101,11 +101,11 @@ static int getdata(char *rec, FILE *ftmp) getword_start(&gwarea,rec); if (getword(dat,sizeof(dat),&gwarea,' ')<0) { - fprintf(stderr,"SARG: The time stamp at column 1 is too long.\n"); + debuga(_("The time stamp at column 1 is too long.")); return(-1); } if (getword(warea,sizeof(warea),&gwarea,' ')<0) { - fprintf(stderr,"SARG: The connection duration at column 2 is too long.\n"); + debuga(_("The connection duration at column 2 is too long.")); return(-1); } while(strcmp(warea,"") == 0 && gwarea.current[0] != '\0') @@ -113,19 +113,19 @@ static int getdata(char *rec, FILE *ftmp) return(-1); } if (getword(ip,sizeof(ip),&gwarea,' ')<0) { - fprintf(stderr,"SARG: The IP address at column 3 is too long.\n"); + debuga(_("The IP address at column 3 is too long.")); return(-1); } if (getword_skip(MAXLEN,&gwarea,' ')<0) { - fprintf(stderr,"SARG: The status at column 4 is too long.\n"); + debuga(_("The status at column 4 is too long.")); return(-1); } if (getword_skip(MAXLEN,&gwarea,' ')<0) { - fprintf(stderr,"SARG: The size at column 5 is too long.\n"); + debuga(_("The size at column 5 is too long.")); return(-1); } if (getword(typ,sizeof(typ),&gwarea,' ')<0) { - fprintf(stderr,"SARG: The action at column 6 is too long.\n"); + debuga(_("The action at column 6 is too long.")); return(-1); } if(strncmp(typ,"CONNECT",7) == 0) { @@ -139,11 +139,11 @@ static int getdata(char *rec, FILE *ftmp) } }else { if (getword_skip(MAXLEN,&gwarea,'/')<0) { - fprintf(stderr,"SARG: The URL at column 7 is too long.\n"); + debuga(_("The URL at column 7 is too long.")); return(-1); } if (getword_skip(MAXLEN,&gwarea,'/')<0) { - fprintf(stderr,"SARG: The URL at column 7 is too long.\n"); + debuga(_("The URL at column 7 is too long.")); return(-1); } if (getword_ptr(rec,&url,&gwarea,'/')<0) { @@ -192,7 +192,7 @@ static void datashow(const char *tmp) struct longlinestruct line; if((fin=fopen(tmp,"r"))==NULL) { - fprintf(stderr, "SARG: (realtime) open error %s - %s\n",tmp,strerror(errno)); + debuga(_("(realtime) open error %s - %s"),tmp,strerror(errno)); exit(1); } @@ -244,10 +244,6 @@ static void datashow(const char *tmp) ip2name(u2,sizeof(u2)); user_find(name, sizeof(name), u2); - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - printf("%s %s%s%s%s%s\n",dat,tim,ip,name,typ,url,url); strcpy(ouser,user); diff --git a/repday.c b/repday.c index 218ad01..606978b 100644 --- a/repday.c +++ b/repday.c @@ -29,7 +29,7 @@ extern numlist hours; -void report_day(const char *user) +void report_day(const struct userinfostruct *uinfo) { FILE *fp_in, *fp_ou; @@ -40,7 +40,6 @@ void report_day(const char *user) char html[8000]; char arqout[MAXLEN]; char wdirname[MAXLEN]; - char wuser[255]; char c[ 24 ][20]; int count=0; int ihour=0; @@ -53,8 +52,11 @@ void report_day(const char *user) int i; struct getwordstruct gwarea; - sprintf(arqout,"%s/%s/d%s.html",dirname,user,user); - sprintf(wdirname,"%s/%s.day",tmp,user); + if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",dirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) { + debuga(_("Output file name too long: %s/%s/d%s.html"),dirname,uinfo->filename,uinfo->filename); + exit(1); + } + snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename); if(access(wdirname, R_OK) != 0) return; @@ -75,23 +77,7 @@ void report_day(const char *user) fprintf(fp_ou,"%s: %s\n",text[89],period); - strcpy(wuser,user); - if(strstr(wuser,"_") != 0) - fixip(wuser); - - if(Ip2Name) - if((str=(char *) strstr(name, ".")) != (char *) NULL) { - if((str=(char *) strstr(str+1, ".")) != (char *) NULL) - ip2name(wuser,sizeof(wuser)); - } - - user_find(name, sizeof(name), wuser); - - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - - fprintf(fp_ou,"%s: %s\n",text[90],name); + fprintf(fp_ou,"%s: %s\n",text[90],uinfo->label); fputs("\n",fp_ou); fputs("\n",fp_ou); @@ -114,7 +100,7 @@ void report_day(const char *user) fixendofline(buf); getword_start(&gwarea,buf); if (getword(data,sizeof(data),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname); + debuga(_("There is a broken date in file %s"),wdirname); exit(1); } if(!count) { @@ -122,8 +108,12 @@ void report_day(const char *user) count++; } - if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname); + if (getword(hour,sizeof(hour),&gwarea,'\t')<0) { + debuga(_("There is a broken time in file %s"),wdirname); + exit(1); + } + if (getword_atoll(&elap,&gwarea,'\t')<0) { + debuga(_("There is a broken quantity in file %s"),wdirname); exit(1); } diff --git a/report.c b/report.c index 5730be2..f05ae73 100644 --- a/report.c +++ b/report.c @@ -31,10 +31,10 @@ static FILE *fp_tt=NULL; static void maketmp(const char *user, const char *dirname, int debug, int indexonly); static void maketmp_hour(const char *user, const char *dirname, int indexonly); -static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); -static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); -static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly); -static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache); +static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); +static void gravatmpf(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); +static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly); +static void gravager(FILE *fp_gen, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache); static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart); void gerarel(void) @@ -44,11 +44,11 @@ void gerarel(void) FILE *fp_gen; char *buf; - char accdia[11], acchora[9], accuser[MAX_USER_LEN], accip[MAXLEN], *accurl; + char accdia[11], acchora[9], accip[MAXLEN], *accurl; char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN]; - char wdirname[MAXLEN], oldaccuser[MAX_USER_LEN]; + char wdirname[MAXLEN]; char *oldurl=NULL; - char olduser[MAX_USER_LEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAX_USER_LEN]; + char oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAX_USER_LEN]; char ipantes[MAXLEN], nameantes[MAXLEN]; char accsmart[MAXLEN]; char crc2[MAXLEN/2 -1]; @@ -56,9 +56,9 @@ void gerarel(void) char arqtt[256]; char *oldurltt=NULL; char oldaccdiatt[11],oldacchoratt[9]; - char u2[MAX_USER_LEN]; char tmp3[MAXLEN]; char tmp4[5]; + char u2[MAX_USER_LEN]; long long int nbytes=0; long long int nelap=0; long long int nacc=0; @@ -75,11 +75,12 @@ void gerarel(void) int ourl_size=0; int ourltt_size=0; int same_url; + int new_user; struct getwordstruct gwarea; struct longlinestruct line; + struct userinfostruct *uinfo,*puinfo; ipantes[0]='\0'; - nameantes[0]='\0'; smartfilter=0; sprintf(dirname, "%s%s", outdir, period); @@ -99,7 +100,7 @@ void gerarel(void) exit(1); } - olduser[0]='\0'; + puinfo=NULL; strncat(tmp,"/sarg",5); fp_tt=NULL; @@ -129,53 +130,54 @@ void gerarel(void) user[0]='\0'; } + uinfo=userinfo_find_from_file(user); + if (!uinfo) { + debuga(_("Ignoring unknown user file %s"),user); + continue; + } + strcpy(u2,uinfo->id); + if(Ip2Name && uinfo->id_is_ip) ip2name(u2,sizeof(u2)); + user_find(uinfo->label,MAX_USER_LEN, u2); + strcpy(wdirname,dirname); maketmp(user,tmp,debug,indexonly); maketmp_hour(user,tmp,indexonly); - strcpy(u2,user); - if(Ip2Name) - ip2name(u2,sizeof(u2)); - user_find(name,sizeof(name), u2); - - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - ttopen=0; oldurltt=NULL; ourltt_size=0; memset(oldaccdiatt,0,sizeof(oldaccdiatt)); memset(oldacchoratt,0,sizeof(oldacchoratt)); + new_user=1; if (longline_prepare(&line)<0) { - debuga(_("Not enough memory to read the downloaded files")); + debuga(_("Not enough memory to read the downloaded files.")); exit(1); } while((buf=longline_read(fp_in,&line))!=NULL) { getword_start(&gwarea,buf); if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || - getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 || + getword(accip,sizeof(accip),&gwarea,'\t')<0 || getword_ptr(buf,&accurl,&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file (%d)"),tmp3,__LINE__); + debuga(_("There is a broken record or garbage in file %s"),tmp3); exit(1); } if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; if (getword_atoll(&accelap,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken elapsed time in your %s file (%d)"),tmp3,__LINE__); + debuga(_("There is a broken elapsed time in file %s"),tmp3); exit(1); } if (getword_skip(20000,&gwarea,'"')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { - debuga(_("Maybe you have a broken smart info in your %s file (%d)"),tmp3,__LINE__); + debuga(_("There is a broken smart info in file %s"),tmp3); exit(1); } if(accsmart[0] != '\0') { smartfilter++; strcpy(wdirname,dirname); - grava_SmartFilter(wdirname,accuser,accip,accdia,acchora,accurl,accsmart); + grava_SmartFilter(wdirname,uinfo->id,accip,accdia,acchora,accurl,accsmart); } if(Ip2Name) { @@ -187,11 +189,11 @@ void gerarel(void) } strcpy(wdirname,dirname); - gravatmp_hora(wdirname,accuser,accdia,acchora,accelap,accbytes,indexonly); + gravatmp_hora(wdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly); if(iprel){ strcpy(wdirname,dirname); - gravaporuser(accuser,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); + gravaporuser(uinfo,wdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); } if(!rtotal){ @@ -206,21 +208,22 @@ void gerarel(void) } strcpy(oldurl,accurl); strcpy(oldacccode,acccode); - strcpy(oldaccuser,accuser); + puinfo=uinfo; strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); strcpy(oldacchora,acchora); + new_user=0; rtotal++; } same_url=(strcmp(oldurl,accurl) == 0); if(site[0] != '\0') { - if(strcmp(oldaccuser,accuser) != 0){ + if(new_user){ strcpy(oldmsg,"OK"); if(strstr(oldacccode,"DENIED") != 0) sprintf(oldmsg,"%s",text[46]); - gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); - gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); + gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; nbytes=0; nelap=0; @@ -228,20 +231,18 @@ void gerarel(void) oucache=0; } } else { - if(!same_url || strcmp(oldaccuser,accuser) != 0){ + if(!same_url || new_user){ if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]); else strcpy(oldmsg,"OK"); - gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); - gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); + gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; nbytes=0; nelap=0; incache=0; oucache=0; - if(strcmp(oldaccuser,accuser) != 0) - ind2=0; } } nacc++; @@ -252,12 +253,11 @@ void gerarel(void) (!oldurltt || strcmp(oldurltt,accurl) || strcmp(oldaccdiatt,accdia) || strcmp(oldacchoratt,acchora))) { if(!ttopen) { - ind2++; url_to_file(accurl,siteind,sizeof(siteind)); - snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,accuser); + snprintf(arqtt,sizeof(arqtt),"%s/%s",dirname,uinfo->filename); if(access(arqtt, R_OK) != 0) my_mkdir(arqtt); - snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,accuser,accuser,siteind); + snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",dirname,uinfo->filename,uinfo->filename,siteind); if ((fp_tt = fopen(arqtt, "w")) == 0) { fprintf(stderr, "SARG: (report) %s: %s\n",text[45],arqtt); exit(1); @@ -274,7 +274,7 @@ void gerarel(void) write_html_header(fp_tt,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Site access report")); fprintf(fp_tt,"%s: %s\n",text[89],period); - fprintf(fp_tt,"%s: %s\n",text[90],name); + fprintf(fp_tt,"%s: %s\n",text[90],uinfo->label); fprintf(fp_tt,"%s: %s, %s\n",text[104],UserSortField,UserSortOrder); fprintf(fp_tt,"%s\n",text[32]); close_html_header(fp_tt); @@ -311,12 +311,13 @@ void gerarel(void) oucache+=accbytes; else incache+=accbytes; - if(strcmp(accuser,oldaccuser) != 0) { + if(new_user) { + new_user=0; strcpy(wdirname,dirname); - day_totalize(tmp,oldaccuser,indexonly); - strcpy(oldaccuser,accuser); + day_totalize(tmp,puinfo,indexonly); } + puinfo=uinfo; strcpy(oldacccode,acccode); strcpy(oldaccip,accip); if (!same_url) { @@ -339,7 +340,6 @@ void gerarel(void) longline_free(&line); if (oldurltt) free(oldurltt); unlink(tmp3); - bzero(user,sizeof(user)); } closedir(dirp); @@ -349,15 +349,13 @@ void gerarel(void) else strcpy(oldmsg,"OK"); strcpy(wdirname,dirname); - if(oldaccuser[0] == '\0') - strcpy(oldaccuser,accuser); - gravatmpf(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + gravatmpf(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); strcpy(wdirname,dirname); - gravager(fp_gen,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); + gravager(fp_gen,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); free(oldurl); } fclose(fp_gen); - day_totalize(tmp,oldaccuser,indexonly); + if (puinfo) day_totalize(tmp,puinfo,indexonly); tmpsort(); @@ -470,17 +468,16 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly) } -void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) +void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) { - FILE *fp_ou; char wdirname[MAXLEN]; if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; - if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { - debuga(_("Temporary file name too long: %s/%s.utmp"),tmp,oldaccuser); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { + debuga(_("Temporary file name too long: %s/%s.utmp"),tmp,uinfo->filename); exit(1); } @@ -502,38 +499,42 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo } return; - } - -static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) +static void gravatmpf(const struct userinfostruct *uinfo,const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) { - FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; + if(indexonly || (ReportType & REPORT_TYPE_USERS_SITES) == 0) return; - if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { - fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { + debuga(_("Path too long %s/%s.utmp"),tmp,uinfo->filename); exit(1); } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ - fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno)); + fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); exit(1); } - if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); - else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); + fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache); fclose(fp_ou); + ttopen=0; + + if(fp_tt) { + fputs("\n",fp_tt); + fputs("\n\n",fp_tt); + fclose(fp_tt); + fp_tt=NULL; + } return; } -static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly) +static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) { FILE *fp_ou; @@ -541,26 +542,26 @@ static void gravaporuser(const char *user, const char *dirname, const char *url, if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; - if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) { - fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) { + debuga(_("Path too long %s/%s.htmp"),tmp,uinfo->filename); exit(1); } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ - fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); + fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno)); exit(1); } - fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); + if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); + else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); fclose(fp_ou); return; - } -static void gravatmpf(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache) +static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly) { FILE *fp_ou; @@ -568,8 +569,8 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; - if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { - fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) { + fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,uinfo->filename); exit(1); } @@ -578,27 +579,18 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o exit(1); } - fprintf(fp_ou,"%lld\t%lld\t%s\t%s\t%lld\t%lld\t%lld\n",nacc,nbytes,oldurl,oldmsg,nelap,incache,oucache); + fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); fclose(fp_ou); - ttopen=0; - ind2=0; - - if(fp_tt) { - fputs("\n",fp_tt); - fputs("\n\n",fp_tt); - fclose(fp_tt); - fp_tt=NULL; - } return; } -static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache) +static void gravager(FILE *fp_gen, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache) { - fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",user,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache); + fprintf(fp_gen,"%s\t%lld\t%lld\t%s\t%s\t%s\t%s\t%lld\t%lld\t%lld\n",uinfo->id,nacc,nbytes,url,ip,hora,dia,nelap,incache,oucache); return; } diff --git a/siteuser.c b/siteuser.c index 1959773..a8915c6 100644 --- a/siteuser.c +++ b/siteuser.c @@ -51,6 +51,7 @@ void siteuser(void) int cstatus; struct longlinestruct line; struct generalitemstruct item; + const struct userinfostruct *uinfo; if(Privacy) return; @@ -68,7 +69,7 @@ void siteuser(void) } if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (siteuser) read error in %s\n",per); + debuga(_("(siteuser) read error in %s"),per); exit(1); } fclose(fp_in); @@ -76,14 +77,14 @@ void siteuser(void) sprintf(csort,"sort -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } if((fp_in=fopen(general2,"r"))==NULL) { fprintf(stderr, "SARG: (topsite) %s: %s\n",text[8],general2); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command: %s"),csort); exit(1); } @@ -122,13 +123,10 @@ void siteuser(void) while((buf=longline_read(fp_in,&line))!=NULL) { ger_read(buf,&item,general2); if(item.total) continue; - if(userip) - fixip(item.user); - - user_find(name, sizeof(name), item.user); - - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); + uinfo=userinfo_find_from_id(item.user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s"),item.user,general2); + exit(1); } if (item.nacc > 0) nsitesusers = 1; @@ -147,9 +145,9 @@ void siteuser(void) regs++; } - sprintf(wuser," %s ",name); + sprintf(wuser," %s ",uinfo->label); if(strstr(users,wuser) == 0 && strcmp(item.url,ourl) == 0) { - strcat(users,name); + strcat(users,uinfo->label); strcat(users," "); ucount++; if(ucount>4) { @@ -182,7 +180,7 @@ void siteuser(void) regs++; ucount=0; - strcpy(users,name); + strcpy(users,uinfo->label); strcat(users," "); url_len=strlen(item.url); if (url_len>=ourl_size) { diff --git a/smartfilter.c b/smartfilter.c index 9a60be5..bc1f259 100644 --- a/smartfilter.c +++ b/smartfilter.c @@ -49,10 +49,10 @@ void smartfilter_report(void) char smartheader[15]; char ftime[128]; char smartuser[MAXLEN]; - char *str; int fuser=0; int cstatus; struct getwordstruct gwarea; + const struct userinfostruct *uinfo; ouser[0]='\0'; @@ -71,24 +71,24 @@ void smartfilter_report(void) } if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (smartfilter) read error in %s\n",per); + debuga(_("(smartfilter) read error in %s"),per); exit(1); } fclose(fp_in); if (snprintf(csort,sizeof(csort),"sort -n -k 1,1 -k 2,2 -k 3,3 -o \"%s\" \"%s\"",smart_ou,smart_in)>=sizeof(csort)) { - fprintf(stderr,"SARG: cannot sort file %s\n",smart_in); + debuga(_("cannot build the sort command to sort file %s"),smart_in); exit(1); } cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } if((fp_in=fopen(smart_ou,"r"))==NULL) { fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],smart_ou); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command: %s"),csort); exit(1); } unlink(smart_in); @@ -121,18 +121,18 @@ void smartfilter_report(void) if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0 || getword(smartcat,sizeof(smartcat),&gwarea,'\n')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",smart_ou); + debuga(_("There is e a broken record or garbage in file %s"),smart_ou); exit(1); } - if((str=(char *) strstr(user, "_")) != (char *) NULL ) { - if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) - fixip(user); + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s"),user,smart_ou); + exit(1); } - if(strcmp(ouser,user) != 0) { strcpy(ouser,user); - sprintf(smartuser,"%s/denied_%s.html",dirname,user); + sprintf(smartuser,"%s/denied_%s.html",dirname,uinfo->filename); if(fuser) { fuser=0; fputs("\n",fp_user); @@ -173,7 +173,7 @@ void smartfilter_report(void) if(LogoImage[0]!='\0') fprintf(fp_user,"%s\n",LogoImage,Width,Height,LogoTextColor,LogoText); fprintf(fp_user,"%s\n",TiColor,Title); fprintf(fp_user,"%s: %s\n",HeaderBgColor,FontSize,text[89],period); - fprintf(fp_user,"%s: %s\n",HeaderBgColor,FontSize,text[90],FontSize,user); + fprintf(fp_user,"%s: %s\n",HeaderBgColor,FontSize,text[90],FontSize,uinfo->label); fputs("\n",fp_user); fputs("
\n",fp_user); fputs("\n",fp_user); @@ -181,9 +181,9 @@ void smartfilter_report(void) fputs("\n",fp_user); fprintf(fp_user,"\n",HeaderBgColor,FontSize,text[98],HeaderBgColor,FontSize,text[111],HeaderBgColor,FontSize,text[110],HeaderBgColor,FontSize,text[91],HeaderBgColor,FontSize,smartheader); } - fprintf(fp_user,"\n",TxBgColor,FontSize,user,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat); + fprintf(fp_user,"\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat); - fprintf(fp_ou,"\n",TxBgColor,FontSize,user,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat); + fprintf(fp_ou,"\n",TxBgColor,FontSize,uinfo->label,TxBgColor,FontSize,ip,TxBgColor,FontSize,data,hora,TxBgColor,FontSize,url,TxBgColor,FontSize,smartcat); } fputs("
%s%s%s%s%s
%s%s%s-%s%s%s
%s%s%s-%s%s%s
%s%s%s-%s%s%s
%s%s%s-%s%s%s
\n",fp_ou); diff --git a/sort.c b/sort.c index e03cf09..f664349 100644 --- a/sort.c +++ b/sort.c @@ -146,7 +146,7 @@ void sort_users_log(const char *tmp, int debug) clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"", tmp, wtmp, user, wtmp, user); else - clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 5,5 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"", + clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"", tmp, wtmp, user, wtmp, user); if (clen>=sizeof(csort)) { fprintf(stderr, "SARG: user name too long to sort %s\n",csort); diff --git a/squidguard_report.c b/squidguard_report.c index 49aca08..b63a489 100644 --- a/squidguard_report.c +++ b/squidguard_report.c @@ -45,7 +45,6 @@ void squidguard_report(void) char data[15]; char data2[15]; char hora[15]; - char *str; int z=0; int count=0; struct getwordstruct gwarea; @@ -67,7 +66,7 @@ void squidguard_report(void) } if (!fgets(period,sizeof(period),fp_in)) { - fprintf(stderr,"SARG: (squidguard) read error in %s\n",per); + debuga(_("(squidguard) read error in %s"),per); exit(1); } fclose(fp_in); @@ -95,15 +94,15 @@ void squidguard_report(void) getword_start(&gwarea,buf); if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken record or garbage in your %s file"),squidguard_in); + debuga(_("There is a broken record or garbage in file %s"),squidguard_in); exit(1); } if (getword_ptr(buf,&url,&gwarea,'\t')<0) { - debuga(_("Maybe you have a broken url in your %s file"),squidguard_in); + debuga(_("There is a broken url in file %s"),squidguard_in); exit(1); } if (getword(rule,sizeof(rule),&gwarea,'\n')<0) { - debuga(_("Maybe you have a broken rule in your %s file"),squidguard_in); + debuga(_("There is a broken rule in file %s"),squidguard_in); exit(1); } @@ -125,11 +124,6 @@ void squidguard_report(void) strncat(data,data2,4); } - if((str=(char *) strstr(user, "_")) != (char *) NULL ) { - if((str=(char *) strstr(str+1, "_")) != (char *) NULL ) - fixip(user); - } - if(Ip2Name) ip2name(ip,sizeof(ip)); @@ -150,10 +144,6 @@ void squidguard_report(void) user_find(name, sizeof(name), user); - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - if(SquidGuardReportLimit) { if(strcmp(ouser2,name) == 0) { count++; diff --git a/topuser.c b/topuser.c index 52c08cc..f3d9648 100644 --- a/topuser.c +++ b/topuser.c @@ -45,12 +45,10 @@ void topuser(void) char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; char user[MAX_USER_LEN], tusr[MAXLEN]; char ipantes[MAXLEN], nameantes[MAXLEN]; - char sfield[10]="2,2"; - char order[255]="-r"; + const char *sfield="-n -k 2,2"; + const char *order="-r"; char title[80]; char *warea; - char user2[MAXLEN]; - char name[MAXLEN]; char ltext110[100]; int totuser=0; int topcount=0; @@ -60,6 +58,7 @@ void topuser(void) struct getwordstruct gwarea; struct longlinestruct line; struct generalitemstruct item; + const struct userinfostruct *uinfo; ipantes[0]='\0'; nameantes[0]='\0'; @@ -116,7 +115,7 @@ void topuser(void) totuser++; if (olduser[0] != '\0') { - fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache); + fprintf(fp_top2,"%s\t%lld\t%lld\t%lld\t%lld\t%lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache); ttnbytes+=tnbytes; ttnacc+=tnacc; @@ -142,7 +141,7 @@ void topuser(void) longline_free(&line); if (olduser[0] != '\0') { - fprintf(fp_top2,"%s\t%015lld\t%015lld\t%015lld\t%015lld\t%015lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache); + fprintf(fp_top2,"%s\t%lld\t%lld\t%lld\t%lld\t%lld\n",olduser,tnbytes,tnacc,tnelap,tnincache,tnoucache); ttnbytes+=tnbytes; ttnacc+=tnacc; @@ -156,27 +155,27 @@ void topuser(void) strlow(TopuserSortOrder); if(strcmp(TopuserSortField,"USER") == 0) - strcpy(sfield,"1,1"); + sfield="-k 1,1"; if(strcmp(TopuserSortField,"CONNECT") == 0) - strcpy(sfield,"3,3"); + sfield="-n -k 3,3"; if(strcmp(TopuserSortField,"TIME") == 0) - strcpy(sfield,"4,4"); + sfield="-n -k 4,4"; if(strcmp(TopuserSortOrder,"normal") == 0) - order[0]='\0'; + order=""; - sprintf(csort,"sort -n -T \"%s\" %s -k %s -o \"%s\" \"%s\"", TempDir, order, sfield, top1, top2); + sprintf(csort,"sort -T \"%s\" %s %s -o \"%s\" \"%s\"", TempDir, order, sfield, top1, top2); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } if((fp_top1=fopen(top1,"r"))==NULL) { - fprintf(stderr, "SARG: (topuser) %s: %s\n",text[45],top1); + debuga("SARG: (topuser) %s: %s\n",text[45],top1); exit(1); } @@ -250,27 +249,27 @@ void topuser(void) while((warea=longline_read(fp_top1,&line))!=NULL) { getword_start(&gwarea,warea); if (getword(user,sizeof(user),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken user in your %s file.\n",top1); + debuga(_("There may be a broken user in file %s."),top1); exit(1); } if (getword_atoll(&nbytes,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1); + debuga(_("There may be a broken number of bytes in file %s."),top1); exit(1); } if (getword_atoll(&nacc,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1); + debuga(_("There may be a broken number of access in file %s."),top1); exit(1); } if (getword_atoll(&elap,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken elpased time in your %s file.\n",top1); + debuga(_("There may be a broken elpased time in file %s."),top1); exit(1); } if (getword_atoll(&incac,&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",top1); + debuga(_("There may be a broken in-cache size in file %s."),top1); exit(1); } if (getword_atoll(&oucac,&gwarea,'\n')<0) { - printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",top1); + debuga(_("There may be a broken out-of-cache size in file %s."),top1); exit(1); } if(nacc < 1) @@ -280,16 +279,10 @@ void topuser(void) tnbytes=nbytes; tnelap=elap; - strcpy(user2,user); - if(userip) { - fixip(user2); - if(Ip2Name) { - if(strcmp(user2,ipantes) != 0) { - strcpy(ipantes,user2); - ip2name(user2,sizeof(user2)); - strcpy(nameantes,user2); - } else strcpy(user2,nameantes); - } + uinfo=userinfo_find_from_id(user); + if (!uinfo) { + debuga(_("Unknown user ID %s in file %s"),user,top1); + exit(1); } fputs("",fp_top3); @@ -298,15 +291,6 @@ void topuser(void) if((TopUserFields & TOPUSERFIELDS_NUM) != 0) fprintf(fp_top3,"%d",posicao); - user_find(name, sizeof(name), user2); - if(Ip2Name && - ((str=(char *) strstr(name, ".")) != (char *) NULL) && - ((str=(char *) strstr(str+1, ".")) != (char *) NULL)) - ip2name(name,sizeof(name)); - if(dotinuser && strchr(name,'_')) { - subs(name,sizeof(name),"_","."); - } - if((TopUserFields & TOPUSERFIELDS_DATE_TIME) !=0 && (ReportType & REPORT_TYPE_DATE_TIME) != 0) { s=text[110]; for(i=0 ; i",fp_top3); #ifdef HAVE_GD if(Graphs && GraphFont[0]!='\0') { - fprintf(fp_top3,"
\"G\" ",user,ImageFile,text[126]); + fprintf(fp_top3,"\"G\" ",uinfo->filename,ImageFile,text[126]); } #endif - fprintf(fp_top3,"filename,uinfo->filename,ImageFile,ltext110); #ifdef HAVE_GD fprintf(fp_top3," %s",text[55]); #endif fputs("\" alt=\"T\">",fp_top3); } else { - sprintf(val1,"%s/d%s.html",dirname,user); + sprintf(val1,"%s/d%s.html",dirname,uinfo->filename); unlink(val1); } if((TopUserFields & TOPUSERFIELDS_USERID) != 0) { if((ReportType & REPORT_TYPE_USERS_SITES) == 0) fprintf(fp_top3,"%s",name); else - fprintf(fp_top3,"%s",user,user,name); + fprintf(fp_top3,"%s",uinfo->filename,uinfo->filename,uinfo->label); } if((TopUserFields & TOPUSERFIELDS_CONNECT) != 0) fprintf(fp_top3,"%s",fixnum(nacc,1)); diff --git a/totday.c b/totday.c index d24cec4..b00aa4c 100644 --- a/totday.c +++ b/totday.c @@ -27,7 +27,7 @@ #include "include/conf.h" #include "include/defs.h" -void day_totalize(const char *tmp, const char *user, int indexonly) +void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly) { FILE *fp_in, *fp_ou; @@ -51,20 +51,20 @@ void day_totalize(const char *tmp, const char *user, int indexonly) if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; - sprintf(wdirname,"%s/%s.htmp",tmp,user); - sprintf(arqout,"%s/%s.day",tmp,user); - sprintf(sortout,"%s/%s.sort",tmp,user); + sprintf(wdirname,"%s/%s.htmp",tmp,uinfo->filename); + sprintf(arqout,"%s/%s.day",tmp,uinfo->filename); + sprintf(sortout,"%s/%s.sort",tmp,uinfo->filename); sprintf(csort,"sort -k 1,1 -k 2,2 -o \"%s\" \"%s\"",sortout,wdirname); cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus)); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command return status %d"),WEXITSTATUS(cstatus)); + debuga(_("sort command: %s"),csort); exit(1); } if((fp_in=fopen(sortout,"r"))==NULL) { fprintf(stderr, "SARG: (totday) %s: %s\n",text[8],sortout); - fprintf(stderr, "SARG: sort command: %s\n",csort); + debuga(_("sort command: %s"),csort); exit(1); } @@ -81,7 +81,7 @@ void day_totalize(const char *tmp, const char *user, int indexonly) if (getword(data,sizeof(data),&gwarea,'\t')<0 || getword(hora,sizeof(hora),&gwarea,':')<0 || getword(min,sizeof(min),&gwarea,':')<0 || getword_skip(20,&gwarea,'\t')<0 || getword(elap,sizeof(elap),&gwarea,0)<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sortout); + debuga(_("There is a broken record or garbage in file %s"),sortout); exit(1); } diff --git a/userinfo.c b/userinfo.c new file mode 100644 index 0000000..8caa5ee --- /dev/null +++ b/userinfo.c @@ -0,0 +1,151 @@ +/* + * SARG Squid Analysis Report Generator http://sarg.sourceforge.net + * 1998, 2010 + * + * SARG donations: + * please look at http://sarg.sourceforge.net/donations.php + * Support: + * http://sourceforge.net/projects/sarg/forums/forum/363374 + * --------------------------------------------------------------------- + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "include/conf.h" +#include "include/defs.h" + +//! The number of users to group in one unit. +#define USERS_PER_GROUP 50 + +/*! \brief Group the users in one allocation unit. +Structure to store a group of users and reduce the number of memory +allocations. +*/ +struct usergroupstruct +{ + //! The next group of users. + struct usergroupstruct *next; + //! A group of users. + struct userinfostruct list[USERS_PER_GROUP]; + //! The number of users stored in the list. + int nusers; +}; + +//! The first group of users. +static struct usergroupstruct *first_user_group=NULL; + +struct userinfostruct *userinfo_create(const char *userid) +{ + struct usergroupstruct *group, *last; + struct userinfostruct *user; + int i, lastuser; + int skip; + int flen; + int count, clen; + char cstr[9]; + + last=NULL; + for (group=first_user_group ; group ; group=group->next) { + if (group->nusersnext=group; + else + first_user_group=group; + } + user=group->list+group->nusers++; + + strncpy(user->id,userid,MAX_USER_LEN-1); + user->id[MAX_USER_LEN-1]='\0'; + + skip=0; + for(i=0 ; userid[i] && ifilename[i]='_'; + skip=1; + } + } else { + user->filename[i]=userid[i]; + skip=0; + } + } + user->filename[i]='\0'; + flen=i; + + count=0; + for (group=first_user_group ; group ; group=group->next) { + lastuser=(group->next) ? group->nusers : group->nusers-1; + for (i=0 ; ifilename,group->list[i].filename)==0) { + clen=sprintf(cstr,"-%04X",count++); + if (flen+clenfilename+flen,cstr); + else + strcpy(user->filename+MAX_USER_FNAME_LEN-clen,cstr); + } + } + } + + return(user); +} + +void userinfo_free(void) +{ + struct usergroupstruct *group, *next; + + for (group=first_user_group ; group ; group=next) { + next=group->next; + free(group); + } + first_user_group=NULL; +} + +struct userinfostruct *userinfo_find_from_file(const char *filename) +{ + struct usergroupstruct *group; + int i; + + for (group=first_user_group ; group ; group=group->next) { + for (i=0 ; inusers ; i++) + if (strcmp(filename,group->list[i].filename)==0) + return(group->list+i); + } + return(NULL); +} + +struct userinfostruct *userinfo_find_from_id(const char *id) +{ + struct usergroupstruct *group; + int i; + + for (group=first_user_group ; group ; group=group->next) { + for (i=0 ; inusers ; i++) + if (strcmp(id,group->list[i].id)==0) + return(group->list+i); + } + return(NULL); +} diff --git a/util.c b/util.c index 7e963f3..a185741 100644 --- a/util.c +++ b/util.c @@ -475,7 +475,7 @@ void debuga(const char *msg,...) { va_list ap; - fputs("SARG: ",stderr); + fputs(_("SARG: "),stderr); va_start(ap,msg); vfprintf(stderr,msg,ap); va_end(ap); @@ -490,35 +490,6 @@ void debugaz(const char *head, const char *msg) } -void fixip(char *ip) -{ - int i; - char sep='_'; - char search=0; - int nrepl=0; - - for (i=0; ip[i]; i++) { - if (ip[i]=='.') { - search='.'; - sep='_'; - break; - } - if (ip[i]=='_') { - search='_'; - sep='.'; - break; - } - } - for (; ip[i]; i++) { - if (ip[i]==search) { - ip[i]=sep; - nrepl++; - if (nrepl>=3) break; - } - } -} - - char *fixnum(long long int value, int n) { #define MAXLEN_FIXNUM 1024