]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Fix the links of the URL in the reports
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 20:12:34 +0000 (21:12 +0100)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 1 Feb 2012 20:12:34 +0000 (21:12 +0100)
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.

authfail.c
dansguardian_report.c
denied.c
download.c
html.c
include/defs.h
redirector.c
siteuser.c
topsites.c
url.c
util.c

index fd3d99d9ecd873538d1dec64c95f1422b79372e2..8e74f78487f339c16765e08a38f1662c724cc48e 100644 (file)
@@ -189,7 +189,7 @@ void authfail_report(void)
                        output_html_url(fp_ou,url);
                        fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",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("</td></th>\n",fp_ou);
        }
        fclose(fp_in);
index 93b80d76c73ab060d8afb7abd98b3e58cc356505..0bf7b48f374a5ff021fb237c0298caf81b0d05fa 100644 (file)
@@ -155,7 +155,7 @@ void dansguardian_report(void)
                }
 
                fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",name,ip,date,hour);
-               output_html_link(fp_ou,NULL,url,100);
+               output_html_link(fp_ou,url,100);
                fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
        }
        fclose(fp_in);
index db49aa78d94f6001f35e9fbd68e42303cd586dc4..ec8505cc294b59dd25710920875730979e3fd2aa 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -158,7 +158,7 @@ void gen_denied_report(void)
                        output_html_url(fp_ou,url);
                        fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
                }
-               output_html_link(fp_ou,"",url,100); //the URL contains the scheme
+               output_html_link(fp_ou,url,100);
                fputs("</td></tr>\n",fp_ou);
        }
        fclose(fp_in);
index 51cb098c32840d22ee13c3cfe2428acc43f9d9b7..75421a6d20529278bef6df5564b5eac77b88a576 100644 (file)
@@ -156,7 +156,7 @@ void download_report(void)
                        output_html_url(fp_ou,url);
                        fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
                }
-               output_html_link(fp_ou,"",url,100);//scheme is kept from the log file
+               output_html_link(fp_ou,url,100);
                fputs("</td></tr>\n",fp_ou);
        }
        fclose(fp_in);
diff --git a/html.c b/html.c
index b38d81e19a4329cb8e7f196c122059eb4e0225a3..84db764f4caa1d5bf654533009f0397e32671cd3 100644 (file)
--- a/html.c
+++ b/html.c
@@ -285,7 +285,7 @@ void htmlrel(void)
                                                output_html_url(fp_ou,url);
                                                fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
                                        }
-                                       output_html_link(fp_ou,NULL,url,100);
+                                       output_html_link(fp_ou,url,100);
                                        fputs("</td>",fp_ou);
                                }
 
index 690973bf043c49ff8c1760918ed14aa1b2832550..694dca1e7d4acc43c57a0c964f9a83f3a851b547 100755 (executable)
@@ -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);
index 9e1ca674fb49011822864ec37012f2346a107fb7..b8ab00de98fbd0987dec757b6559ebbe614abf1d 100644 (file)
@@ -552,7 +552,7 @@ void redirector_report(void)
                else
                        fputs("<tr><td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou);
                fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data,hora);
-               output_html_link(fp_ou,NULL,url,100);
+               output_html_link(fp_ou,url,100);
                fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
        }
        fclose(fp_in);
index a1c874373f47cf8a9356d3d9128fb75e2c2bb75b..997b27193567efcb6c3dd3fa32c73c79c6ec5769 100644 (file)
@@ -146,7 +146,7 @@ void siteuser(void)
                                output_html_url(fp_ou,ourl);
                                fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                        }
-                       output_html_link(fp_ou,NULL,ourl,100);
+                       output_html_link(fp_ou,ourl,100);
                        fputs("</td>",fp_ou);
 
                        if (BytesInSitesUsersReport) {
index 6ca2cfe8eee804798b3afc3dc0bbb7afbe9ca417..81c248555020b4466d99086b96d57effc0222743 100644 (file)
@@ -272,7 +272,7 @@ void topsites(void)
                        fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                }
 
-               output_html_link(fp_ou,NULL,url,100);
+               output_html_link(fp_ou,url,100);
                fputs("</td><td class=\"data\"",fp_ou);
                if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(uint64_t)twork1);
                fprintf(fp_ou,">%s</td>",fixnum(twork1,1));
diff --git a/url.c b/url.c
index 803274c95d00ff8e37c8f6d1fa76db867640320d..da66df59245004e09877f6d7b98f78cbcee9c0e5 100644 (file)
--- 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 7fa2a256eae519f0ac41df6b8c7387ecccc99928..15b354c24d3b6051edb13779846e40ff2c6f87f3 100644 (file)
--- 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,"<a href=\"%s",scheme);
+               if (skip_scheme(url)==url)
+                       fputs("<a href=\"http://",fp_ou);//no scheme in the url, assume http:// to make the link clickable
+               else
+                       fputs("<a href=\"",fp_ou);//the scheme is in the url, no need to add one
                output_html_url(fp_ou,url);
                fputs("\">",fp_ou);
                output_html_string(fp_ou,url,100);