From: Frederic Marchal Date: Thu, 24 Jan 2013 21:17:23 +0000 (+0100) Subject: Write the access times in one html page X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f72b484ad4c51d08e4d950ae2faa275869ac45cb;p=thirdparty%2Fsarg.git Write the access times in one html page 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. --- diff --git a/css.c b/css.c index 1be5c41..a5d0541 100644 --- 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"); diff --git a/documentation/util.txt b/documentation/util.txt index cfdc9af..40b49ba 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -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 00dac80..d9b310c 100644 --- 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,"\"T\"",uinfo->filename,siteind,tmp6,_("date/time report")); + url_to_anchor(url,siteind,sizeof(siteind)); + fprintf(fp_ou,"\"T\"",siteind,tmp6,_("date/time report")); } else { fprintf(fp_ou,""); } @@ -323,8 +323,7 @@ void htmlrel(void) fputs("\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)); } diff --git a/include/conf.h b/include/conf.h index 07acf54..cd58831 100755 --- a/include/conf.h +++ b/include/conf.h @@ -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 diff --git a/include/defs.h b/include/defs.h index 1161793..5b26370 100755 --- a/include/defs.h +++ b/include/defs.h @@ -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); diff --git a/report.c b/report.c index ae84696..211bdcb 100644 --- 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("
\n",fp_tt); - fprintf(fp_tt,"",_("ACCESSED SITE")); - fprintf(fp_tt,"",_("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,"\n",fp_tt); + fprintf(fp_tt,"",_("IP")); fprintf(fp_tt,"\n",_("DATE"),_("TIME")); } - fputs("",fp_tt); - fprintf(fp_tt,"",accip); + fprintf(fp_tt,"",accip); fprintf(fp_tt,"\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 c7481e1..6ff809b 100644 --- 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 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; i0 && 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)
%s%s
",siteind); + fprintf(fp_tt,"%s",_("Accessed site: ")); + output_html_string(fp_tt,url,100); + fputs("
%s%s%s
",fp_tt); - output_html_string(fp_tt,accurl,100); - fputs("%s
%s%s%s