]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Write the access times in one html page
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 24 Jan 2013 21:17:23 +0000 (22:17 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Thu, 24 Jan 2013 21:17:23 +0000 (22:17 +0100)
Web sites access times were written in a file named after the user's name
and the visited site URL. There were one file per site, they were small and
numerous. In fact, they could be so numerous that they could fill the disk
inode table.

Moreover, with a file name made of the user's name and the visited site
URL, the manufactured file name could be more than 256 characters resulting
in an OS error on Windows and Linux.

To fix these two problems, the access times are all grouped inside one web
page with anchors to directly scroll to the relevant site. The html file
name is fixed (tt.html) and doesn't depend on the user's name or web
site URL.

css.c
documentation/util.txt
html.c
include/conf.h
include/defs.h
report.c
util.c

diff --git a/css.c b/css.c
index 1be5c418f09b5a2247a4cd76c7f65fca5f0765fc..a5d0541459c48bf57250bdc3f48df911a06eb322 100644 (file)
--- a/css.c
+++ b/css.c
@@ -71,6 +71,8 @@ void css_content(FILE *fp_css)
        fputs(".warn {margin:0.5em;}\n",fp_css);
        fprintf(fp_css,".warn > span {padding:0.5em;border:2px solid black;background-color:orange;font-family:%s;font-size:%s;}\n",FontFace,FontSize);
 
+       fprintf(fp_css,"tr.tt > td {font-family:%s;color:%s;font-size:%s;text-align:left;border-right:1px solid #6A5ACD;border-bottom:1px solid #6A5ACD;padding-top:0.5em;border:none;}\n", FontFace, TxColor, FontSize);
+
        if (SortTableJs[0]) {
                fprintf(fp_css,".sorttable_nosort {cursor:default !important;}\n");
                fprintf(fp_css,".sortable thead th {cursor:pointer;}\n");
index cfdc9af455d5bd9971f15db961873b71c9d921fe..40b49ba6c6d7eb9259583534b4db5f8de9c7c790 100644 (file)
@@ -744,18 +744,6 @@ be at least 255 characters long.
 
 
 
-/*! \fn void url_to_file(const char *url,char *file,int filesize)
-Mangle an URL to produce a part that can be included in a file.
-
-\param url The URL to mangle.
-\param file The buffer to write the mangled URL.
-\param filesize The size of the buffer.
-*/
-
-
-
-
-
 /*! \fn int write_html_trailer(FILE *fp_ou)
 End the HTML file by closing the centered table that was opened by write_html_header(), writting
 the informations of show_info() and closing the body and html tag. After this function returns, the
diff --git a/html.c b/html.c
index 00dac809ff406a84dc523eb668fb3dda7f68fe73..d9b310cd234f6595ef6a09ac516d13ff76837aa4 100644 (file)
--- a/html.c
+++ b/html.c
@@ -264,8 +264,8 @@ void htmlrel(void)
                                        strcpy(tmp6,"../../images");
 
                                if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
-                                       url_to_file(url,siteind,sizeof(siteind));
-                                       fprintf(fp_ou,"<td class=\"data\"><a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",uinfo->filename,siteind,tmp6,_("date/time report"));
+                                       url_to_anchor(url,siteind,sizeof(siteind));
+                                       fprintf(fp_ou,"<td class=\"data\"><a href=\"tt.html#%s\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",siteind,tmp6,_("date/time report"));
                                } else {
                                        fprintf(fp_ou,"<td class=\"data\"></td>");
                                }
@@ -323,8 +323,7 @@ void htmlrel(void)
                                fputs("</tr>\n",fp_ou);
                                count++;
                        } else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
-                               url_to_file(url,siteind,sizeof(siteind));
-                               snprintf(warea,sizeof(warea),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind);
+                               snprintf(warea,sizeof(warea),"%s/%s/tt.html",outdirname,uinfo->filename);
                                if (unlink(warea)!=0) {
                                        debuga(_("Cannot delete \"%s\": %s\n"),warea,strerror(errno));
                                }
index 07acf54b6bbf74cd2ca72c9c5505e903f5d3c47d..cd58831c2661e13e07ac353a524b232561c15da5 100755 (executable)
@@ -170,7 +170,7 @@ int mkstemps(char *template, int suffixlen);
 
 #define MAXLEN 20000
 #define MAX_URL_LEN 40000
-#define MAX_TRUNCATED_URL 512
+#define MAX_TRUNCATED_URL 250
 #define MAX_USER_LEN 256
 #define MAX_USER_FNAME_LEN 128
 #define MAX_IP_LEN 64
index 1161793ed7b1b12f592afa2aaea3e3de03000746..5b26370ada2f519f6651a358c29491091b2acfe0 100755 (executable)
@@ -325,7 +325,7 @@ void debugaz(const char *msg,...) __attribute__((format(printf,1,2)));
 void my_lltoa(unsigned long long int n, char *s, int ssize, int len);
 char *get_size(const char *path, const char *file);
 void url_module(const char *url, char *w2);
-void url_to_file(const char *url,char *file,int filesize);
+void url_to_anchor(const char *url,char *anchor,int size);
 void safe_strcpy(char *dest,const char *src,int length);
 void strip_latin(char *line);
 char *buildtime(long long int elap);
index ae84696243ab93ee05e7cec0c4fb58854c50be24..211bdcb98bec16c1230aa6214c38efce5feea84b 100644 (file)
--- a/report.c
+++ b/report.c
@@ -39,6 +39,7 @@ static char arqtt[4096]="";
 
 static FILE *maketmp(const char *user, const char *dirname, int debug);
 static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache);
+static void closett(void);
 static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap);
 static void gravager(FILE *fp_gen,const char *filename, const struct userinfostruct *uinfo, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache);
 static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart);
@@ -248,8 +249,7 @@ void gerarel(void)
                                        snprintf(arqtt,sizeof(arqtt),"%s/%s",outdirname,uinfo->filename);
                                        if(access(arqtt, R_OK) != 0)
                                                my_mkdir(arqtt);
-                                       url_to_file(accurl,siteind,sizeof(siteind));
-                                       snprintf(arqtt,sizeof(arqtt),"%s/%s/tt%s-%s.html",outdirname,uinfo->filename,uinfo->filename,siteind);
+                                       snprintf(arqtt,sizeof(arqtt),"%s/%s/tt.html",outdirname,uinfo->filename);
                                        if ((fp_tt = fopen(arqtt, "w")) == 0) {
                                                debuga(_("(report) Cannot open file %s: %s\n"),arqtt,strerror(errno));
                                                exit(EXIT_FAILURE);
@@ -273,15 +273,20 @@ void gerarel(void)
                                        close_html_header(fp_tt);
 
                                        fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\">\n",fp_tt);
-                                       fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th>",_("ACCESSED SITE"));
-                                       fprintf(fp_tt,"<th class=\"header_l\">%s</th>",_("IP"));
+                               }
+                               if (!oldurltt || strcmp(oldurltt,accurl)) {
+                                       const char *url=accurl;
+                                       if (*url==ALIAS_PREFIX) url++;
+                                       url_to_anchor(accurl,siteind,sizeof(siteind));
+                                       fprintf(fp_tt,"<tr class=\"tt\"><td colspan=\"3\"><a name=\"%s\">",siteind);
+                                       fprintf(fp_tt,"<b>%s</b>",_("Accessed site: "));
+                                       output_html_string(fp_tt,url,100);
+                                       fputs("</a></td></tr>\n",fp_tt);
+                                       fprintf(fp_tt,"<tr><th class=\"header_l\">%s</th>",_("IP"));
                                        fprintf(fp_tt,"<th class=\"header_l\">%s</th><th class=\"header_l\">%s</th></tr>\n",_("DATE"),_("TIME"));
                                }
 
-                               fputs("<tr><td class=\"data\">",fp_tt);
-                               output_html_string(fp_tt,accurl,100);
-                               fputs("</td>",fp_tt);
-                               fprintf(fp_tt,"<td class=\"data\">%s</td>",accip);
+                               fprintf(fp_tt,"<tr><td class=\"data2\">%s</td>",accip);
                                fprintf(fp_tt,"<td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",accdia,acchora);
 
                                url_len=strlen(accurl);
@@ -333,6 +338,7 @@ void gerarel(void)
                        else
                                strcpy(oldmsg,"OK");
                        if (fp_tmp) gravatmp(fp_tmp,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache);
+                       closett();
                        gravager(fp_gen,wdirname,uinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache);
                        free(oldurl);
                        oldurl=NULL;
@@ -459,6 +465,11 @@ static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long l
        */
        fprintf(fp_ou,"%"PRIu64"\t%"PRIu64"\t%s\t%s\t%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n",(uint64_t)nacc,(uint64_t)nbytes,oldurl,oldmsg,(uint64_t)nelap,(uint64_t)incache,(uint64_t)oucache);
 
+       return;
+}
+
+static void closett(void)
+{
        ttopen=0;
 
        if(fp_tt) {
@@ -470,8 +481,6 @@ static void gravatmp(FILE *fp_ou, const char *oldurl, long long int nacc, long l
                }
                fp_tt=NULL;
        }
-
-       return;
 }
 
 static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap)
diff --git a/util.c b/util.c
index c7481e144c7c74e28a5591d9bac7b123252b8a8d..6ff809bb7f8309556a7e19454650f200fc30598b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1889,22 +1889,51 @@ void url_module(const char *url, char *w2)
        w2[x]='\0';
 }
 
-void url_to_file(const char *url,char *file,int filesize)
+/*!
+Mangle an URL to produce a part that can be used as an anchor in
+a html <a name=""> tag.
+
+\param url The URL to mangle.
+\param anchor The buffer to write the mangled URL.
+\param size The size of the buffer.
+*/
+void url_to_anchor(const char *url,char *anchor,int size)
 {
-       int i,skip;
+       int i,j;
+       bool skip;
 
-       filesize--;
-       skip=0;
-       for(i=0; i<filesize && *url; url++) {
-               if(isalnum(*url) || *url=='-' || *url=='_' || *url=='.') {
-                       file[i++]=*url;
-                       skip=0;
+       // find url end
+       for (i=0 ; url[i] && url[i]!='/' && url[i]!='?' ; i++);
+       i--;
+       if (i<=0) {
+               anchor[0]='\0';
+               return;
+       }
+
+       // only keep really safe characters
+       skip=false;
+       j=size-1;
+       anchor[j]='\0';
+       while (j>0 && i>=0)
+       {
+               if(isalnum(url[i]) || url[i]=='-' || url[i]=='_' || url[i]=='.') {
+                       anchor[--j]=url[i];
+                       skip=false;
                } else {
-                       if (!skip) file[i++]='_';
-                       skip=1;
+                       if (!skip) anchor[--j]='_';
+                       skip=true;
+               }
+               i--;
+       }
+       if (j>0)
+       {
+               while ( anchor[j])
+               {
+                       *anchor=anchor[j];
+                       anchor++;
                }
+               *anchor='\0';
        }
-       file[i]='\0';
 }
 
 void version(void)