]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't report clickable link for aliased url
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 18:32:18 +0000 (18:32 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 19 Jun 2011 18:32:18 +0000 (18:32 +0000)
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.

12 files changed:
authfail.c
dansguardian_report.c
denied.c
download.c
html.c
include/conf.h
include/defs.h
siteuser.c
squidguard_report.c
topsites.c
url.c
util.c

index f33b76e999599b13712d816a4b7316a00c120e3e..6aa3b4919ddfd7fea0f94a3b72538c33cf823511 100644 (file)
@@ -173,16 +173,13 @@ void authfail_report(void)
                else
                        fputs("<td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou);
                fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data,hora);
-               if(BlockIt[0]!='\0') {
+               if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) {
                        fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                        output_html_url(fp_ou,url);
                        fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                }
-               fputs("<a href=\"",fp_ou);
-               output_html_url(fp_ou,url);
-               fputs("\">",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fputs("</a></td></th>\n",fp_ou);
+               output_html_link(fp_ou,url,100);
+               fputs("</td></th>\n",fp_ou);
        }
        fclose(fp_in);
        longline_destroy(&line);
index 632fb804574c5fccc0e1f3e26f3c71673e0b5d01..b03525ac33dcce481b9e8f94af539da9652446d9 100644 (file)
@@ -143,11 +143,9 @@ void dansguardian_report(void)
                                continue;
                }
 
-               fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",name,ip,date,hour);
-               output_html_url(fp_ou,url);
-               fputs("\">",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",rule);
+               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,url,100);
+               fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
        }
        fclose(fp_in);
 
index b542e59f773bf730ef36983da19c8a08c2a28e5f..0934b1a5c92554cbea68d3bb79814ac1f0c4b2b5 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -152,16 +152,13 @@ void gen_denied_report(void)
                else
                        fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou);
                fprintf(fp_ou,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data,hora);
-               if(BlockIt[0] != '\0') {
+               if(BlockIt[0] != '\0' && url[0]!=ALIAS_PREFIX) {
                        fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                        output_html_url(fp_ou,url);
                        fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
                }
-               fputs("<a href=\"http://",fp_ou);
-               output_html_url(fp_ou,url);
-               fputs("\">http://",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fputs("</a></td></tr>\n",fp_ou);
+               output_html_link(fp_ou,url,100);
+               fputs("</td></tr>\n",fp_ou);
        }
        fclose(fp_in);
        longline_destroy(&line);
index 70cabb261e33f2200926a479e5af7fe21aa8bbbd..192b29b63be9479c75a860e08a849d32cdf5ec8b 100644 (file)
@@ -146,16 +146,13 @@ void download_report(void)
                else
                        fputs("<td class=\"data\"></td><td class=\"data\"></td>",fp_ou);
                fprintf(fp_ou,"<td class=\"data\">%s-%s</td><td class=\"data2\">",data,hora);
-               if(BlockIt[0]!='\0') {
+               if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) {
                        fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
                        output_html_url(fp_ou,url);
                        fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",ImageFile);
                }
-               fputs("<a href=\"http://",fp_ou);
-               output_html_url(fp_ou,url);
-               fputs("\">http://",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fputs("</a></td></tr>\n",fp_ou);
+               output_html_link(fp_ou,url,100);
+               fputs("</td></tr>\n",fp_ou);
        }
        fclose(fp_in);
        longline_destroy(&line);
diff --git a/html.c b/html.c
index 545733ddb2bcde4f3406f966163ad8c792ea6792..aa08c02928744f2c51d829967c994f3920466228 100644 (file)
--- a/html.c
+++ b/html.c
@@ -287,16 +287,13 @@ void htmlrel(void)
                                        fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
                                else {
                                        fputs("<td class=\"data2\">",fp_ou);
-                                       if(BlockIt[0]!='\0') {
+                                       if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREFIX) {
                                                fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                                                output_html_url(fp_ou,url);
                                                fprintf(fp_ou,"\"><img src=\"%s/sarg-squidguard-block.png\"></a>&nbsp;",tmp6);
                                        }
-                                       fputs("<a href=\"http://",fp_ou);
-                                       output_html_url(fp_ou,url);
-                                       fputs("\">",fp_ou);
-                                       output_html_string(fp_ou,url,100);
-                                       fputs("</a></td>",fp_ou);
+                                       output_html_link(fp_ou,url,100);
+                                       fputs("</td>",fp_ou);
                                }
 
                                if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) {
index c138501b5ccb6b1be68dc2602ca936de42d58a15..4247761ad9ecca2c089f0827fadd8b370567069c 100755 (executable)
@@ -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.
index 4fdd093741a91d8652f514912cff96e930750904..440948b5b5e08933fa65d7c162dd841087a424aa 100755 (executable)
@@ -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);
index d64af48a5fdf56e57ab023c5d23be9e2dcba0f04..09c220b4a17c2332d61019e9ccd8a472d73d8e7b 100644 (file)
@@ -157,16 +157,13 @@ void siteuser(void)
 
                if(strcmp(item.url,ourl) != 0 && nsitesusers) {
                        fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
-                       if(BlockIt[0]!='\0') {
+                       if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
                                fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                                output_html_url(fp_ou,ourl);
                                fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                        }
-                       fputs("<a href=\"http://",fp_ou);
-                       output_html_url(fp_ou,ourl);
-                       fputs("\">",fp_ou);
-                       output_html_string(fp_ou,ourl,100);
-                       fputs("</a></td>",fp_ou);
+                       output_html_link(fp_ou,ourl,100);
+                       fputs("</td>",fp_ou);
 
                        if (BytesInSitesUsersReport) {
                                fputs("<td class=\"data\"",fp_ou);
@@ -197,16 +194,13 @@ void siteuser(void)
 
        if(nsitesusers) {
                fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",regs);
-               if(BlockIt[0]!='\0') {
+               if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
                        fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                        output_html_url(fp_ou,ourl);
                        fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                }
-               fputs("<a href=\"http://",fp_ou);
-               output_html_url(fp_ou,ourl);
-               fputs("\">",fp_ou);
-               output_html_string(fp_ou,ourl,100);
-               fputs("</a></td>",fp_ou);
+               output_html_link(fp_ou,ourl,100);
+               fputs("</td>",fp_ou);
                if (BytesInSitesUsersReport) {
                        fputs("<td class=\"data\"",fp_ou);
                        if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)obytes);
index 111cd70f6c819876c98a6625fbd65e9c59153899..9d5d797e85937f71e869bd55ec5b313d59d8a8db 100644 (file)
@@ -161,11 +161,9 @@ void squidguard_report(void)
                        fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo->label,ip);
                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\"><a href=\"http://",data,hora);
-               output_html_url(fp_ou,url);
-               fputs("\">",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",rule);
+               fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\">",data,hora);
+               output_html_link(fp_ou,url,100);
+               fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
        }
        fclose(fp_in);
        longline_destroy(&line);
index 60d2c092e0d906ad1432952a635259023b9895ce..9ab48de0c55fc271803e595e1ccf5eb894ba927e 100644 (file)
@@ -265,19 +265,16 @@ void topsites(void)
                twork2=nbytes;
                twork3=ntime;
 
-               fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2 link\">",++regs);
+               fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\"data2\">",++regs);
 
-               if(BlockIt[0] != '\0') {
+               if(BlockIt[0] != '\0' && url[0]!=ALIAS_PREFIX) {
                        fprintf(fp_ou,"<a href=\"%s%s?url=\"",wwwDocumentRoot,BlockIt);
                        output_html_url(fp_ou,url);
                        fputs("\"><img src=\"../images/sarg-squidguard-block.png\"></a>&nbsp;",fp_ou);
                }
 
-               fputs("<a href=\"http://",fp_ou);
-               output_html_url(fp_ou,url);
-               fputs("\">",fp_ou);
-               output_html_string(fp_ou,url,100);
-               fputs("</a></td><td class=\"data\"",fp_ou);
+               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));
                fputs("<td class=\"data\"",fp_ou);
diff --git a/url.c b/url.c
index 43df14d2c6900e8277ecf4b8ebd85e1547ce2d48..74324206872ddb13c8c9e2856adcc87e0c22dbe7 100644 (file)
--- a/url.c
+++ b/url.c
@@ -65,6 +65,7 @@ void read_hostalias(const char *Filename)
        char *NameBegin;
        char *NameEnd;
        char *Replace;
+       char *tmp;
        struct hostalias *alias;
        struct hostalias *prev_alias;
        struct hostalias *new_alias;
@@ -164,22 +165,25 @@ void read_hostalias(const char *Filename)
                        new_alias->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 2bbb6507cff73c4a6452b745fe82f7561432507d..8bebb439c40be72aeb412d8aa56f2641ab8cdd65 100644 (file)
--- 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("<a href=\"http://",fp_ou);
+               output_html_url(fp_ou,url);
+               fputs("\">",fp_ou);
+               output_html_string(fp_ou,url,100);
+               fputs("</a>",fp_ou);
+       }
+}
+
 void url_module(const char *url, char *w2)
 {
        int x, y;