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> ",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);
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);
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> ",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);
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> ",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);
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> ",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) {
//! 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.
__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);
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> ",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(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> ",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);
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);
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> ",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);
char *NameBegin;
char *NameEnd;
char *Replace;
+ char *tmp;
struct hostalias *alias;
struct hostalias *prev_alias;
struct hostalias *new_alias;
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;
}
}
}
+/*!
+ 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;