From 67a9370101ab777a2285f8352a1a5770d0094425 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Sun, 19 Jun 2011 18:32:18 +0000 Subject: [PATCH] Don't report clickable link for aliased url The HTML reports contain A tags to link to the page visited by the users but if the host name is aliased, the link is meaningless and must not be reported. --- authfail.c | 9 +++------ dansguardian_report.c | 8 +++----- denied.c | 9 +++------ download.c | 9 +++------ html.c | 9 +++------ include/conf.h | 3 +++ include/defs.h | 1 + siteuser.c | 18 ++++++------------ squidguard_report.c | 8 +++----- topsites.c | 11 ++++------- url.c | 18 +++++++++++------- util.c | 23 +++++++++++++++++++++++ 12 files changed, 66 insertions(+), 60 deletions(-) diff --git a/authfail.c b/authfail.c index f33b76e..6aa3b49 100644 --- a/authfail.c +++ b/authfail.c @@ -173,16 +173,13 @@ void authfail_report(void) else fputs("",fp_ou); fprintf(fp_ou,"%s-%s",data,hora); - if(BlockIt[0]!='\0') { + if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",fp_ou); } - fputs("",fp_ou); - output_html_string(fp_ou,url,100); - fputs("\n",fp_ou); + output_html_link(fp_ou,url,100); + fputs("\n",fp_ou); } fclose(fp_in); longline_destroy(&line); diff --git a/dansguardian_report.c b/dansguardian_report.c index 632fb80..b03525a 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -143,11 +143,9 @@ void dansguardian_report(void) continue; } - fprintf(fp_ou,"%s%s%s-%s",fp_ou); - output_html_string(fp_ou,url,100); - fprintf(fp_ou,"%s\n",rule); + fprintf(fp_ou,"%s%s%s-%s",name,ip,date,hour); + output_html_link(fp_ou,url,100); + fprintf(fp_ou,"%s\n",rule); } fclose(fp_in); diff --git a/denied.c b/denied.c index b542e59..0934b1a 100644 --- a/denied.c +++ b/denied.c @@ -152,16 +152,13 @@ void gen_denied_report(void) else fputs("",fp_ou); fprintf(fp_ou,"%s-%s",data,hora); - if(BlockIt[0] != '\0') { + if(BlockIt[0] != '\0' && url[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",ImageFile); } - fputs("http://",fp_ou); - output_html_string(fp_ou,url,100); - fputs("\n",fp_ou); + output_html_link(fp_ou,url,100); + fputs("\n",fp_ou); } fclose(fp_in); longline_destroy(&line); diff --git a/download.c b/download.c index 70cabb2..192b29b 100644 --- a/download.c +++ b/download.c @@ -146,16 +146,13 @@ void download_report(void) else fputs("",fp_ou); fprintf(fp_ou,"%s-%s",data,hora); - if(BlockIt[0]!='\0') { + if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",ImageFile); } - fputs("http://",fp_ou); - output_html_string(fp_ou,url,100); - fputs("\n",fp_ou); + output_html_link(fp_ou,url,100); + fputs("\n",fp_ou); } fclose(fp_in); longline_destroy(&line); diff --git a/html.c b/html.c index 545733d..aa08c02 100644 --- a/html.c +++ b/html.c @@ -287,16 +287,13 @@ void htmlrel(void) fprintf(fp_ou,"%s",PrivacyStringColor,PrivacyString); else { fputs("",fp_ou); - if(BlockIt[0]!='\0') { + if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",tmp6); } - fputs("",fp_ou); - output_html_string(fp_ou,url,100); - fputs("",fp_ou); + output_html_link(fp_ou,url,100); + fputs("",fp_ou); } if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) { diff --git a/include/conf.h b/include/conf.h index c138501..4247761 100755 --- a/include/conf.h +++ b/include/conf.h @@ -270,6 +270,9 @@ int mkstemps(char *template, int suffixlen); //! Bit to include sorttable.js in the html plage. #define HTML_JS_SORTTABLE 0x0001 +//! The character prefixed in front of the host names that are aliased. +#define ALIAS_PREFIX '*' + struct periodstruct { //! The first date of the period. diff --git a/include/defs.h b/include/defs.h index 4fdd093..440948b 100755 --- a/include/defs.h +++ b/include/defs.h @@ -247,6 +247,7 @@ void close_html_header(FILE *fp_ou); __attribute__((warn_unused_result)) int write_html_trailer(FILE *fp_ou); void output_html_string(FILE *fp_ou,const char *str,int maxlen); void output_html_url(FILE *fp_ou,const char *url); +void output_html_link(FILE *fp_ou,const char *url,int maxlen); void debuga(const char *msg,...) __attribute__((format(printf,1,2))); void debugaz(const char *head, const char *msg); void my_lltoa(unsigned long long int n, char *s, int ssize, int len); diff --git a/siteuser.c b/siteuser.c index d64af48..09c220b 100644 --- a/siteuser.c +++ b/siteuser.c @@ -157,16 +157,13 @@ void siteuser(void) if(strcmp(item.url,ourl) != 0 && nsitesusers) { fprintf(fp_ou,"%d",regs); - if(BlockIt[0]!='\0') { + if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",fp_ou); } - fputs("",fp_ou); - output_html_string(fp_ou,ourl,100); - fputs("",fp_ou); + output_html_link(fp_ou,ourl,100); + fputs("",fp_ou); if (BytesInSitesUsersReport) { fputs("%d",regs); - if(BlockIt[0]!='\0') { + if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",fp_ou); } - fputs("",fp_ou); - output_html_string(fp_ou,ourl,100); - fputs("",fp_ou); + output_html_link(fp_ou,ourl,100); + fputs("",fp_ou); if (BytesInSitesUsersReport) { fputs("%s%s",uinfo->label,ip); else fputs("",fp_ou); - fprintf(fp_ou,"%s-%s",fp_ou); - output_html_string(fp_ou,url,100); - fprintf(fp_ou,"%s\n",rule); + fprintf(fp_ou,"%s-%s",data,hora); + output_html_link(fp_ou,url,100); + fprintf(fp_ou,"%s\n",rule); } fclose(fp_in); longline_destroy(&line); diff --git a/topsites.c b/topsites.c index 60d2c09..9ab48de 100644 --- a/topsites.c +++ b/topsites.c @@ -265,19 +265,16 @@ void topsites(void) twork2=nbytes; twork3=ntime; - fprintf(fp_ou,"%d",++regs); + fprintf(fp_ou,"%d",++regs); - if(BlockIt[0] != '\0') { + if(BlockIt[0] != '\0' && url[0]!=ALIAS_PREFIX) { fprintf(fp_ou," ",fp_ou); } - fputs("",fp_ou); - output_html_string(fp_ou,url,100); - fputs("%s",fixnum(twork1,1)); fputs("SuffixLen=0; } if (Replace) { - new_alias->Alias=strdup(Replace); - if (!new_alias->Alias) { + tmp=malloc(strlen(Replace)+2); + if (!tmp) { debuga(_("Not enough memory to store the host name aliasing directives read in \"%s\""),Filename); exit(EXIT_FAILURE); } + tmp[0]=ALIAS_PREFIX; + strcpy(tmp+1,Replace); + new_alias->Alias=tmp; } else { - char *tmp; - tmp=malloc(new_alias->MinLen); + tmp=malloc(new_alias->MinLen+2); if (!tmp) { debuga(_("Not enough memory to store the host name aliasing directives read in \"%s\""),Filename); exit(EXIT_FAILURE); } - if (new_alias->HostName_Prefix) strcpy(tmp,new_alias->HostName_Prefix); + tmp[0]=ALIAS_PREFIX; + if (new_alias->HostName_Prefix) strcpy(tmp+1,new_alias->HostName_Prefix); if (new_alias->HostName_Suffix) { - tmp[new_alias->PrefixLen]='*'; - strcpy(tmp+new_alias->PrefixLen+1,new_alias->HostName_Suffix); + tmp[new_alias->PrefixLen+1]='*'; + strcpy(tmp+new_alias->PrefixLen+2,new_alias->HostName_Suffix); } new_alias->Alias=tmp; } diff --git a/util.c b/util.c index 2bbb650..8bebb43 100644 --- a/util.c +++ b/util.c @@ -1639,6 +1639,29 @@ void output_html_url(FILE *fp_ou,const char *url) } } +/*! + Write a host name inside an A tag of a HTML file. If the host name starts + with a star, it is assumed to be an alias that cannot be put inside a link + so the A tag is not written around the host name. + + \param fp_ou The handle of the HTML file. + \param url The host to display in the HTML file. + \param maxlen The maximum number of characters to print into the host name. + */ +void output_html_link(FILE *fp_ou,const char *url,int maxlen) +{ + if (url[0]==ALIAS_PREFIX) { + // this is an alias, no need for a A tag + output_html_string(fp_ou,url+1,100); + } else { + fputs("",fp_ou); + output_html_string(fp_ou,url,100); + fputs("",fp_ou); + } +} + void url_module(const char *url, char *w2) { int x, y; -- 2.47.2