From: Frédéric Marchal Date: Wed, 1 Feb 2012 20:12:34 +0000 (+0100) Subject: Fix the links of the URL in the reports X-Git-Tag: v2.3.3-pre1~36 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fa33a32899716d79fdd6d40ba24f02d5fa547d9;p=thirdparty%2Fsarg.git Fix the links of the URL in the reports Some URL are stripped of the scheme and others are not. Some have a scheme in the access.log while others don't. The function writing the URL in the report detects the presence of the scheme and add "http://" before the link if no schemes are detected. --- diff --git a/authfail.c b/authfail.c index fd3d99d..8e74f78 100644 --- a/authfail.c +++ b/authfail.c @@ -189,7 +189,7 @@ void authfail_report(void) output_html_url(fp_ou,url); fputs("\"> ",fp_ou); } - output_html_link(fp_ou,"",url,100); //the original scheme is left in the URL + output_html_link(fp_ou,url,100); fputs("\n",fp_ou); } fclose(fp_in); diff --git a/dansguardian_report.c b/dansguardian_report.c index 93b80d7..0bf7b48 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -155,7 +155,7 @@ void dansguardian_report(void) } fprintf(fp_ou,"%s%s%s-%s",name,ip,date,hour); - output_html_link(fp_ou,NULL,url,100); + 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 db49aa7..ec8505c 100644 --- a/denied.c +++ b/denied.c @@ -158,7 +158,7 @@ void gen_denied_report(void) output_html_url(fp_ou,url); fprintf(fp_ou,"\"> ",ImageFile); } - output_html_link(fp_ou,"",url,100); //the URL contains the scheme + output_html_link(fp_ou,url,100); fputs("\n",fp_ou); } fclose(fp_in); diff --git a/download.c b/download.c index 51cb098..75421a6 100644 --- a/download.c +++ b/download.c @@ -156,7 +156,7 @@ void download_report(void) output_html_url(fp_ou,url); fprintf(fp_ou,"\"> ",ImageFile); } - output_html_link(fp_ou,"",url,100);//scheme is kept from the log file + output_html_link(fp_ou,url,100); fputs("\n",fp_ou); } fclose(fp_in); diff --git a/html.c b/html.c index b38d81e..84db764 100644 --- a/html.c +++ b/html.c @@ -285,7 +285,7 @@ void htmlrel(void) output_html_url(fp_ou,url); fprintf(fp_ou,"\"> ",tmp6); } - output_html_link(fp_ou,NULL,url,100); + output_html_link(fp_ou,url,100); fputs("",fp_ou); } diff --git a/include/defs.h b/include/defs.h index 690973b..694dca1 100755 --- a/include/defs.h +++ b/include/defs.h @@ -203,6 +203,7 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo); // url.c void read_hostalias(const char *Filename); void free_hostalias(void); +const char *skip_scheme(const char *url); const char *process_url(char *url,bool full_url); void url_hostname(const char *url,char *hostname,int hostsize); @@ -259,7 +260,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 *scheme,const char *url,int maxlen); +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 *msg,...) __attribute__((format(printf,1,2))); void my_lltoa(unsigned long long int n, char *s, int ssize, int len); diff --git a/redirector.c b/redirector.c index 9e1ca67..b8ab00d 100644 --- a/redirector.c +++ b/redirector.c @@ -552,7 +552,7 @@ void redirector_report(void) else fputs("",fp_ou); fprintf(fp_ou,"%s-%s",data,hora); - output_html_link(fp_ou,NULL,url,100); + output_html_link(fp_ou,url,100); fprintf(fp_ou,"%s\n",rule); } fclose(fp_in); diff --git a/siteuser.c b/siteuser.c index a1c8743..997b271 100644 --- a/siteuser.c +++ b/siteuser.c @@ -146,7 +146,7 @@ void siteuser(void) output_html_url(fp_ou,ourl); fputs("\"> ",fp_ou); } - output_html_link(fp_ou,NULL,ourl,100); + output_html_link(fp_ou,ourl,100); fputs("",fp_ou); if (BytesInSitesUsersReport) { diff --git a/topsites.c b/topsites.c index 6ca2cfe..81c2485 100644 --- a/topsites.c +++ b/topsites.c @@ -272,7 +272,7 @@ void topsites(void) fputs("\"> ",fp_ou); } - output_html_link(fp_ou,NULL,url,100); + output_html_link(fp_ou,url,100); fputs("%s",fixnum(twork1,1)); diff --git a/url.c b/url.c index 803274c..da66df5 100644 --- a/url.c +++ b/url.c @@ -597,6 +597,29 @@ const char *alias_url_ipv6(const char *url,unsigned short int *ipv6) return(url); } +/*! +Find the beginning of the URL beyond the scheme:// + +\param url The url possibly containing a scheme. + +\return The beginning of the url beyond the scheme. +*/ +const char *skip_scheme(const char *url) +{ + const char *str; + + /* + Skip any scheme:// at the beginning of the URL (see rfc2396 section 3.1). + The underscore is not part of the standard but is found in the squid logs as cache_object://. + */ + for (str=url ; *str && (isalnum(*str) || *str=='+' || *str=='-' || *str=='.' || *str=='_') ; str++); + if (str[0]==':' && str[1]=='/' && str[2]=='/') { + url=str+3; + while (*url=='/') url++; + } + return(url); +} + /*! Get the part of the URL necessary to generate the report. @@ -614,21 +637,11 @@ const char *process_url(char *url,bool full_url) unsigned short int ipv6[8]; const char *next; - /* - Remove any scheme:// at the beginning of the URL (see rfc2396 section 3.1). - The underscore is not part of the standard but is found in the squid logs as cache_object://. - */ - for (str=url ; *str && (isalnum(*str) || *str=='+' || *str=='-' || *str=='.' || *str=='_') ; str++); - if (*str==':' && str[1]=='/' && str[2]=='/') { - url=str+3; - while (*url=='/') url++; - } - - start=url; + start=skip_scheme(url); if (!full_url) { - for (str=url ; *str && *str!='/' && *str!='?' ; str++); + for (str=(char *)start ; *str && *str!='/' && *str!='?' ; str++); *str='\0'; - type=extract_address_mask(url,&address,ipv4,ipv6,NULL,&next); + type=extract_address_mask(start,&address,ipv4,ipv6,NULL,&next); if (type==1) { if (FirstAliasName) start=alias_url_name(start,next); diff --git a/util.c b/util.c index 7fa2a25..15b354c 100644 --- a/util.c +++ b/util.c @@ -1724,18 +1724,19 @@ void output_html_url(FILE *fp_ou,const char *url) so the A tag is not written around the host name. \param fp_ou The handle of the HTML file. - \param scheme The scheme to print in the link (http:// if the pointer is null). \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 *scheme,const char *url,int maxlen) +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 { - if (scheme==NULL) scheme="http://"; - fprintf(fp_ou,"",fp_ou); output_html_string(fp_ou,url,100);