"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "html.c" between
sarg-2.3.11.tar.gz and sarg-2.4.0.tar.gz

About: SARG ia a Squid Analysis Report Generator.

html.c  (sarg-2.3.11):html.c  (sarg-2.4.0)
/* /*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
* 1998, 2013 * 1998, 2015
* *
* SARG donations: * SARG donations:
* please look at http://sarg.sourceforge.net/donations.php * please look at http://sarg.sourceforge.net/donations.php
* Support: * Support:
* http://sourceforge.net/projects/sarg/forums/forum/363374 * http://sourceforge.net/projects/sarg/forums/forum/363374
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
skipping to change at line 30 skipping to change at line 30
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
* *
*/ */
#include "include/conf.h" #include "include/conf.h"
#include "include/defs.h" #include "include/defs.h"
//! Number of limits.
int PerUserLimitsNumber=0;
//! Log user's who downloaded more than the limit.
struct PerUserLimitStruct PerUserLimits[MAX_USER_LIMITS];
//! How to create a per user file.
enum PerUserFileCreationEnum PerUserFileCreation=PUFC_Always;
extern struct globalstatstruct globstat; extern struct globalstatstruct globstat;
void htmlrel(void) void htmlrel(void)
{ {
FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr; FileObject *fp_in;
FileObject *fp_ip;
FILE *fp_ou;
FILE *fp_ip2;
long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0; long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0;
long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0;
long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0; long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
long long int ltemp; long long int ltemp;
long long int ntotuser; long long int ntotuser;
long long int userbytes, userelap; long long int userbytes, userelap;
char *buf; char *buf;
char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN]; char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN];
char *url, tmsg[50], csort[MAXLEN]; char *url, tmsg[50], csort[MAXLEN];
char duser[MAXLEN]; char duser[MAXLEN];
char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
char warea[MAXLEN]; char warea[MAXLEN];
char tmp6[MAXLEN]; char tmp6[MAXLEN];
char *user_url; char *user_url;
long long int tnacc=0, ttnacc=0; long long int tnacc=0, ttnacc=0;
double perc=0, perc2=0, ouperc=0, inperc=0; double perc=0, perc2=0, ouperc=0, inperc=0;
int count; int count;
int cstatus; int cstatus;
int i;
unsigned int user_limit[(MAX_USER_LIMITS+sizeof(unsigned int)-1)/sizeof(u
nsigned int)];
bool have_denied_report; bool have_denied_report;
const char *sort_field; const char *sort_field;
const char *sort_order; const char *sort_order;
char siteind[MAX_TRUNCATED_URL]; char siteind[MAX_TRUNCATED_URL];
struct getwordstruct gwarea; struct getwordstruct gwarea;
longline line,line1; longline line,line1;
const struct userinfostruct *uinfo; const struct userinfostruct *uinfo;
userscan uscan; userscan uscan;
if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.int_unsort",tmp)>=sizeof(tmp2) ) { if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.int_unsort",tmp)>=sizeof(tmp2) ) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/sargtmp.int_unsort\n",tmp); debuga_more("%s/sargtmp.int_unsort\n",tmp);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (snprintf(tmp3,sizeof(tmp3),"%s/sargtmp.int_log",tmp)>=sizeof(tmp3)) { if (snprintf(tmp3,sizeof(tmp3),"%s/sargtmp.int_log",tmp)>=sizeof(tmp3)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/sargtmp.int_log\n",tmp); debuga_more("%s/sargtmp.int_log\n",tmp);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnacc=globstat.nacc; tnacc=globstat.nacc;
totbytes=globstat.nbytes; totbytes=globstat.nbytes;
totelap=globstat.elap; totelap=globstat.elap;
ntotuser=globstat.totuser; ntotuser=globstat.totuser;
sort_labels(&sort_field,&sort_order); sort_labels(&sort_field,&sort_order);
switch (PerUserFileCreation)
{
case PUFC_Always:
for (i=0 ; i<PerUserLimitsNumber ; i++) {
FILE *fp_usr=fopen(PerUserLimits[i].File,"wt");
if (fp_usr==NULL) {
debuga(__FILE__,__LINE__,_("Cannot create
empty per_user_limit file \"%s\": %s\n"),PerUserLimits[i].File,
strerror(errno));
exit(EXIT_FAILURE);
}
if (fclose(fp_usr)==EOF) {
debuga(__FILE__,__LINE__,_("Write error i
n \"%s\": %s\n"),PerUserLimits[i].File,strerror(errno));
exit(EXIT_FAILURE);
}
}
break;
case PUFC_AsRequired:
for (i=0 ; i<PerUserLimitsNumber ; i++) {
if (access(PerUserLimits[i].File,R_OK)==0 && unli
nk(PerUserLimits[i].File)==-1) {
debuga(__FILE__,__LINE__,_("Cannot delete
\"%s\": %s\n"),PerUserLimits[i].File,
strerror(errno));
exit(EXIT_FAILURE);
}
}
break;
}
uscan=userinfo_startscan(); uscan=userinfo_startscan();
if (uscan == NULL) { if (uscan == NULL) {
debuga(_("Cannot enumerate the user list\n")); debuga(__FILE__,__LINE__,_("Cannot enumerate the user list\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) { while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) {
if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filena me)>=sizeof(warea)) { if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filena me)>=sizeof(warea)) {
debuga(_("Destination directory too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s\n",outdirname,uinfo->filename); debuga_more("%s/%s\n",outdirname,uinfo->filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!uinfo->topuser) { if (!uinfo->topuser) {
//! \todo Instead of deleting the supernumerary directori es, don't create them in the first place. //! \todo Instead of deleting the supernumerary directori es, don't create them in the first place.
unlinkdir(warea,0); unlinkdir(warea,0);
continue; continue;
} }
if (access(warea, R_OK) != 0) { if (access(warea, R_OK) != 0) {
if (mkdir(warea,0755)) { if (PortableMkDir(warea,0755)) {
debuga(_("Cannot create directory \"%s\": %s\n"), debuga(__FILE__,__LINE__,_("Cannot create directo
warea,strerror(errno)); ry \"%s\": %s\n"),warea,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
tmpsort(uinfo); tmpsort(uinfo);
if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(ar qin)) { if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(ar qin)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Input file name too long: %s/
debuga_more("%s/htmlrel.txt\n",tmp); htmlrel.txt\n"),tmp);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fp_in = fopen(arqin, "r")) == 0){ if ((fp_in = FileObject_Open(arqin)) == 0){
if (uinfo->no_report) continue; if (uinfo->no_report) continue;
debugapos("html3",_("Cannot open file \"%s\": %s\n"),arqi n,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n "),arqin,FileObject_GetLastOpenError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo ->filename,uinfo->filename)>=sizeof(arqou)) { if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo ->filename,uinfo->filename)>=sizeof(arqou)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s/%s.html\n",outdirname,uinfo->filename, uinfo->filename); debuga_more("%s/%s/%s.html\n",outdirname,uinfo->filename, uinfo->filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (snprintf(duser,sizeof(duser),"%s/denied_%s.html",outdirname,u info->filename)>=sizeof(duser)) { if (snprintf(duser,sizeof(duser),"%s/denied_%s.html",outdirname,u info->filename)>=sizeof(duser)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/denied_%s.html\n",outdirname,uinfo->filen ame); debuga_more("%s/denied_%s.html\n",outdirname,uinfo->filen ame);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(access(duser, R_OK) != 0) if (access(duser, R_OK) != 0)
have_denied_report=false; have_denied_report=false;
else else
have_denied_report=true; have_denied_report=true;
if ((line=longline_create())==NULL) { if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file \"%s\"\n"),arqin ); debuga(__FILE__,__LINE__,_("Not enough memory to read fil e \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (i=0 ; i<sizeof(user_limit)/sizeof(user_limit[0]) ; i++)
user_limit[i]=0;
tnacc=0; tnacc=0;
tnbytes=0; tnbytes=0;
tnelap=0; tnelap=0;
tnincache=0; tnincache=0;
tnoucache=0; tnoucache=0;
while((buf=longline_read(fp_in,line))!=NULL) { while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf); getword_start(&gwarea,buf);
if (getword_atoll(&ltemp,&gwarea,'\t')<0) { if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
debuga(_("Invalid number of accesses in file \"%s \"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid number of acc esses in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnacc+=ltemp; tnacc+=ltemp;
if (getword_atoll(&ltemp,&gwarea,'\t')<0) { if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
debuga(_("Invalid download size in file \"%s\"\n" ),arqin); debuga(__FILE__,__LINE__,_("Invalid downloaded si ze in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnbytes+=ltemp; tnbytes+=ltemp;
if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) { if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
debuga(_("Invalid url in file \"%s\"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid url in file \ "%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_skip(MAXLEN,&gwarea,'\t')<0) { if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
debuga(_("Invalid access code in file \"%s\"\n"), arqin); debuga(__FILE__,__LINE__,_("Invalid access code i n file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&ltemp,&gwarea,'\t')<0) { if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
debuga(_("Invalid elapsed time in file \"%s\"\n") ,arqin); debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnelap+=ltemp; tnelap+=ltemp;
if (getword_atoll(&ltemp,&gwarea,'\t')<0) { if (getword_atoll(&ltemp,&gwarea,'\t')<0) {
debuga(_("Invalid in-cache volume in file \"%s\"\ n"),arqin); debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnincache+=ltemp; tnincache+=ltemp;
if (getword_atoll(&ltemp,&gwarea,'\n')<0) { if (getword_atoll(&ltemp,&gwarea,'\n')<0) {
debuga(_("Invalid out-of-cache volume in file \"% s\"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
tnoucache+=ltemp; tnoucache+=ltemp;
} }
rewind(fp_in); FileObject_Rewind(fp_in);
if ((fp_ou = fopen(arqou, "w")) == 0){ if ((fp_ou = fopen(arqou, "w")) == 0){
debugapos("html5",_("Cannot open file \"%s\": %s\n"),arqo u,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n "),arqou,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_( "User report"),HTML_JS_SORTTABLE); write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_( "User report"),HTML_JS_SORTTABLE);
fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n ",_("Period"),period.html); fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n ",_("Period"),period.html);
fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n ",_("User"),uinfo->label); fprintf(fp_ou,"<tr><td class=\"header_c\">%s:&nbsp;%s</td></tr>\n ",_("User"),uinfo->label);
fputs("<tr><td class=\"header_c\">",fp_ou); fputs("<tr><td class=\"header_c\">",fp_ou);
fprintf(fp_ou,_("Sort:&nbsp;%s, %s"),sort_field,sort_order); fprintf(fp_ou,_("Sort:&nbsp;%s, %s"),sort_field,sort_order);
fputs("</td></tr>\n",fp_ou); fputs("</td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report")); fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
skipping to change at line 210 skipping to change at line 252
} }
fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing =\"1\"",fp_ou); fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing =\"1\"",fp_ou);
if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou); if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
fputs(">\n",fp_ou); fputs(">\n",fp_ou);
fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\ "header_l",fp_ou); fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\ "header_l",fp_ou);
if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou); if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE")); fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE"));
if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) if ((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT ")); fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT "));
if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) if ((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES") ); fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES") );
if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) if ((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("%BYTES"
")); ));
if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) if ((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</t h><th style=\"display:none;\"></th>",_("IN-CACHE-OUT")); fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</t h><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) if ((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME")); fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) if ((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISE C")); fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISE C"));
if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) if ((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME" fprintf(fp_ou,"<th class=\"header_l\">%s</th>",pgettext("
)); duration","%TIME"));
fputs("</tr></thead>\n",fp_ou); fputs("</tr></thead>\n",fp_ou);
if(debug) { if (debug) {
debuga(_("Making report %s\n"),uinfo->id); debuga(__FILE__,__LINE__,_("Making report %s\n"),uinfo->i
d);
} }
count=0; count=0;
arqip[0]='\0'; arqip[0]='\0';
while((buf=longline_read(fp_in,line))!=NULL) { while((buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf); getword_start(&gwarea,buf);
if (getword_atoll(&twork,&gwarea,'\t')<0) { if (getword_atoll(&twork,&gwarea,'\t')<0) {
debuga(_("Invalid number of accesses in file \"%s \"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid number of acc esses in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&nnbytes,&gwarea,'\t')<0) { if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
debuga(_("Invalid number of bytes in file \"%s\"\ n"),arqin); debuga(__FILE__,__LINE__,_("Invalid number of byt es in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_ptr(buf,&url,&gwarea,'\t')<0) { if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
debuga(_("Invalid url in file \"%s\"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid url in file \ "%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) { if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
debuga(_("Invalid access code in file \"%s\"\n"), arqin); debuga(__FILE__,__LINE__,_("Invalid access code i n file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&nnelap,&gwarea,'\t')<0) { if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
debuga(_("Invalid elapsed time in file \"%s\"\n") ,arqin); debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&incache,&gwarea,'\t')<0) { if (getword_atoll(&incache,&gwarea,'\t')<0) {
debuga(_("Invalid in-cache column in file \"%s\"\ n"),arqin); debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&oucache,&gwarea,'\n')<0) { if (getword_atoll(&oucache,&gwarea,'\n')<0) {
debuga(_("Invalid out-of-cache column in file \"% s\"\n"),arqin); debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),arqin);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(UserReportLimit<=0 || count<=UserReportLimit) { if (UserReportLimit<=0 || count<=UserReportLimit) {
fputs("<tr>",fp_ou); fputs("<tr>",fp_ou);
if(IndexTree == INDEX_TREE_DATE) if (IndexTree == INDEX_TREE_DATE)
sprintf(tmp6,"../%s",ImageFile); sprintf(tmp6,"../%s",ImageFile);
else else
strcpy(tmp6,"../../images"); strcpy(tmp6,"../../images");
if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE
!= 0) { ) != 0) {
url_to_file(url,siteind,sizeof(siteind)); url_to_anchor(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>" fprintf(fp_ou,"<td class=\"data\"><a href
,uinfo->filename,siteind,tmp6,_("date/time report")); =\"tt.html#%s\"><img src=\"%s/datetime.png\" title=\"%s\" alt=\"T\"></a></td>",s
iteind,tmp6,_("date/time report"));
} else { } else {
fprintf(fp_ou,"<td class=\"data\"></td>") ; fprintf(fp_ou,"<td class=\"data\"></td>") ;
} }
if(Privacy) if (Privacy)
fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString); fprintf(fp_ou,"<td class=\"data2\"><span style=\"color:%s;\">%s</span></td>",PrivacyStringColor,PrivacyString);
else { else {
fputs("<td class=\"data2\">",fp_ou); fputs("<td class=\"data2\">",fp_ou);
if(BlockIt[0]!='\0' && url[0]!=ALIAS_PREF IX) { if (BlockIt[0]!='\0' && url[0]!=ALIAS_PRE FIX) {
fprintf(fp_ou,"<a href=\"%s%s?url =",wwwDocumentRoot,BlockIt); fprintf(fp_ou,"<a href=\"%s%s?url =",wwwDocumentRoot,BlockIt);
output_html_url(fp_ou,url); output_html_url(fp_ou,url);
fprintf(fp_ou,"\"><img src=\"%s/s arg-squidguard-block.png\"></a>&nbsp;",tmp6); fprintf(fp_ou,"\"><img src=\"%s/s arg-squidguard-block.png\"></a>&nbsp;",tmp6);
} }
output_html_link(fp_ou,url,100); output_html_link(fp_ou,url,100);
fputs("</td>",fp_ou); fputs("</td>",fp_ou);
} }
if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) { if ((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) {
fputs("<td class=\"data\"",fp_ou); fputs("<td class=\"data\"",fp_ou);
if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)twork); if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)twork);
fprintf(fp_ou,">%s</td>",fixnum(twork,1)) ; fprintf(fp_ou,">%s</td>",fixnum(twork,1)) ;
} }
if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) { if ((UserReportFields & USERREPORTFIELDS_BYTES) ! = 0) {
fputs("<td class=\"data\"",fp_ou); fputs("<td class=\"data\"",fp_ou);
if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnbytes); if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnbytes);
fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1 )); fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1 ));
} }
if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) { if ((UserReportFields & USERREPORTFIELDS_SETYB) ! = 0) {
perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.; perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td>",perc); fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td>",perc);
} }
if((UserReportFields & USERREPORTFIELDS_IN_CACHE_ OUT) != 0) { if ((UserReportFields & USERREPORTFIELDS_IN_CACHE _OUT) != 0) {
inperc=(nnbytes) ? incache * 100. / nnbyt es : 0.; inperc=(nnbytes) ? incache * 100. / nnbyt es : 0.;
ouperc=(nnbytes) ? oucache * 100. / nnbyt es : 0.; ouperc=(nnbytes) ? oucache * 100. / nnbyt es : 0.;
fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc); fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
} }
if((UserReportFields & USERREPORTFIELDS_USED_TIME ) != 0) { if ((UserReportFields & USERREPORTFIELDS_USED_TIM E) != 0) {
fputs("<td class=\"data\"",fp_ou); fputs("<td class=\"data\"",fp_ou);
if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnelap); if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnelap);
fprintf(fp_ou,">%s</td>",buildtime(nnelap )); fprintf(fp_ou,">%s</td>",buildtime(nnelap ));
} }
if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) { if ((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) {
fputs("<td class=\"data\"",fp_ou); fputs("<td class=\"data\"",fp_ou);
if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnelap); if (SortTableJs[0]) fprintf(fp_ou," sortt able_customkey=\"%"PRId64"\"",(int64_t)nnelap);
fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1 )); fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1 ));
} }
if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { if ((UserReportFields & USERREPORTFIELDS_PTIME) ! = 0) {
perc2=(tnelap) ? nnelap * 100. / tnelap : 0.; perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td>",perc2); fprintf(fp_ou,"<td class=\"data\">%3.2lf% %</td>",perc2);
} }
if(strncmp(tmsg,"OK",2) != 0) if (strncmp(tmsg,"OK",2) != 0)
fprintf(fp_ou,"<td class=\"data\">%s</td> ",_("DENIED")); fprintf(fp_ou,"<td class=\"data\">%s</td> ",_("DENIED"));
fputs("</tr>\n",fp_ou); fputs("</tr>\n",fp_ou);
count++; count++;
} else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) { } else if ((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
url_to_file(url,siteind,sizeof(siteind)); format_path(__FILE__, __LINE__, warea,sizeof(ware
snprintf(warea,sizeof(warea),"%s/%s/tt%s-%s.html" a), "%s/%s/tt.html", outdirname, uinfo->filename);
,outdirname,uinfo->filename,uinfo->filename,siteind);
if (unlink(warea)!=0) { if (unlink(warea)!=0) {
debuga(_("Cannot delete \"%s\": %s\n"),wa rea,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),warea,strerror(errno));
} }
} }
if(iprel) { if (iprel) {
if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,u info->filename)>=sizeof(arqip)) { if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,u info->filename)>=sizeof(arqip)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long : "));
debuga_more("%s/%s.ip\n",tmp,uinfo->filen ame); debuga_more("%s/%s.ip\n",tmp,uinfo->filen ame);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fp_ip = fopen(arqip, "r")) == 0){ if ((fp_ip = FileObject_Open(arqip)) == 0){
debugapos("html6",_("Cannot open file \"% debuga(__FILE__,__LINE__,_("Cannot open f
s\": %s\n"),arqip,strerror(errno)); ile \"%s\": %s\n"),arqip,FileObject_GetLastOpenError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){ if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
debugapos("html7",_("Cannot open file \"% s\": %s\n"),tmp2,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open f ile \"%s\": %s\n"),tmp2,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((line1=longline_create())==NULL) { if ((line1=longline_create())==NULL) {
debuga(_("Not enough memory to read file \"%s\"\n"),arqip); debuga(__FILE__,__LINE__,_("Not enough me mory to read file \"%s\"\n"),arqip);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while((buf=longline_read(fp_ip,line1))!=NULL) { while((buf=longline_read(fp_ip,line1))!=NULL) {
getword_start(&gwarea,buf); getword_start(&gwarea,buf);
if (getword(user_ip,sizeof(user_ip),&gwar ea,'\t')<0) { if (getword(user_ip,sizeof(user_ip),&gwar ea,'\t')<0) {
debuga(_("Invalid user IP in file \"%s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id user IP in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_ptr(buf,&user_url,&gwarea,'\t ')<0) { if (getword_ptr(buf,&user_url,&gwarea,'\t ')<0) {
debuga(_("Invalid url in file \"% s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id url in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (strncmp(user_url,url,strlen(url))!=0) continue; if (strncmp(user_url,url,strlen(url))!=0) continue;
if (getword_skip(15,&gwarea,'\t')<0) { if (getword_skip(15,&gwarea,'\t')<0) {
debuga(_("Invalid day in file \"% s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id day in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_skip(15,&gwarea,'\t')<0) { if (getword_skip(15,&gwarea,'\t')<0) {
debuga(_("Invalid time in file \" %s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id time in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&userbytes,&gwarea,'\t' )<0) { if (getword_atoll(&userbytes,&gwarea,'\t' )<0) {
debuga(_("Invalid size in file \" %s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id size in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&userelap,&gwarea,'\0') <0) { if (getword_atoll(&userelap,&gwarea,'\0') <0) {
debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id elapsed time in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\ n",user_ip,(uint64_t)userbytes,(uint64_t)userelap); fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\ n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
} }
longline_destroy(&line1); longline_destroy(&line1);
fclose(fp_ip); if (fclose(fp_ip2)==EOF) {
fclose(fp_ip2); debuga(__FILE__,__LINE__,_("Write error i
n \"%s\": %s\n"),tmp2,strerror(errno));
exit(EXIT_FAILURE);
}
if (FileObject_Close(fp_ip)) {
debuga(__FILE__,__LINE__,_("Read error in
\"%s\": %s\n"),arqip,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
if (snprintf(csort,sizeof(csort),"sort -n -t \"\t \" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2)>=sizeof(csort)) { if (snprintf(csort,sizeof(csort),"sort -n -t \"\t \" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2)>=sizeof(csort)) {
debuga(_("Command too long: ")); debuga(__FILE__,__LINE__,_("Sort command
debuga_more("sort -n -t \"\t\" -T \"%s\" too long when sorting file \"%s\" to \"%s\"\n"),tmp2,tmp3);
-k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
cstatus=system(csort); cstatus=system(csort);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
debuga(_("sort command return status %d\n debuga(__FILE__,__LINE__,_("sort command
"),WEXITSTATUS(cstatus)); return status %d\n"),WEXITSTATUS(cstatus));
debuga(_("sort command: %s\n"),csort); debuga(__FILE__,__LINE__,_("sort command:
%s\n"),csort);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) { if ((fp_ip = FileObject_Open(tmp3)) == 0) {
debugapos("html8",_("Cannot open file \"% debuga(__FILE__,__LINE__,_("Cannot open f
s\": %s\n"),tmp3,strerror(errno)); ile \"%s\": %s\n"),tmp3,FileObject_GetLastOpenError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (unlink(tmp2)) { if (unlink(tmp2)) {
debuga(_("Cannot delete \"%s\": %s\n"),tm p2,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
olduserip[0]='\0'; olduserip[0]='\0';
if ((line1=longline_create())==NULL) { if ((line1=longline_create())==NULL) {
debuga(_("Not enough memory to read file \"%s\"\n"),arqip); debuga(__FILE__,__LINE__,_("Not enough me mory to read file \"%s\"\n"),arqip);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while((buf=longline_read(fp_ip,line1))!=NULL) { while((buf=longline_read(fp_ip,line1))!=NULL) {
getword_start(&gwarea,buf); getword_start(&gwarea,buf);
if (getword(user_ip,sizeof(user_ip),&gwar ea,'\t')<0) { if (getword(user_ip,sizeof(user_ip),&gwar ea,'\t')<0) {
debuga(_("Invalid user IP in file \"%s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id user IP in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&userbytes,&gwarea,'\t' )<0) { if (getword_atoll(&userbytes,&gwarea,'\t' )<0) {
debuga(_("Invalid size in file \" %s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id size in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getword_atoll(&userelap,&gwarea,'\0') <0) { if (getword_atoll(&userelap,&gwarea,'\0') <0) {
debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3); debuga(__FILE__,__LINE__,_("Inval id elapsed time in file \"%s\"\n"),tmp3);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(strcmp(user_ip,olduserip) != 0) { if (strcmp(user_ip,olduserip) != 0) {
if (olduserip[0]!='\0') { if (olduserip[0]!='\0') {
fprintf(fp_ou,"<tr><td></ td><td class=\"data\">%s</td>",olduserip); fprintf(fp_ou,"<tr><td></ td><td class=\"data\">%s</td>",olduserip);
if((UserReportFields & US ERREPORTFIELDS_CONNECT) != 0) if ((UserReportFields & U SERREPORTFIELDS_CONNECT) != 0)
fputs("<td></td>" ,fp_ou); fputs("<td></td>" ,fp_ou);
if((UserReportFields & US ERREPORTFIELDS_BYTES) != 0) if ((UserReportFields & U SERREPORTFIELDS_BYTES) != 0)
fprintf(fp_ou,"<t d class=\"data\">%s</td>",fixnum(unbytes,1)); fprintf(fp_ou,"<t d class=\"data\">%s</td>",fixnum(unbytes,1));
if((UserReportFields & US ERREPORTFIELDS_SETYB) != 0) if ((UserReportFields & U SERREPORTFIELDS_SETYB) != 0)
fputs("<td></td>" ,fp_ou); fputs("<td></td>" ,fp_ou);
if((UserReportFields & US ERREPORTFIELDS_IN_CACHE_OUT) != 0) if ((UserReportFields & U SERREPORTFIELDS_IN_CACHE_OUT) != 0)
fputs("</td><td>< /td><td></td>",fp_ou); fputs("</td><td>< /td><td></td>",fp_ou);
if((UserReportFields & US ERREPORTFIELDS_USED_TIME) != 0) if ((UserReportFields & U SERREPORTFIELDS_USED_TIME) != 0)
fprintf(fp_ou,"<t d class=\"data\">%s</td>",buildtime(unelap)); fprintf(fp_ou,"<t d class=\"data\">%s</td>",buildtime(unelap));
if((UserReportFields & US ERREPORTFIELDS_MILISEC) != 0) if ((UserReportFields & U SERREPORTFIELDS_MILISEC) != 0)
fprintf(fp_ou,"<t d class=\"data\">%s</td>",fixnum2(unelap,1)); fprintf(fp_ou,"<t d class=\"data\">%s</td>",fixnum2(unelap,1));
fputs("</tr>\n",fp_ou); fputs("</tr>\n",fp_ou);
} }
strcpy(olduserip,user_ip); strcpy(olduserip,user_ip);
unbytes=0; unbytes=0;
unelap=0; unelap=0;
} }
unbytes+=userbytes; unbytes+=userbytes;
unelap+=userelap; unelap+=userelap;
} }
fclose(fp_ip); if (FileObject_Close(fp_ip)) {
debuga(__FILE__,__LINE__,_("Read error in
\"%s\": %s\n"),tmp3,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
longline_destroy(&line1); longline_destroy(&line1);
if (unlink(tmp3)) { if (unlink(tmp3)) {
debuga(_("Cannot delete \"%s\": %s\n"),tm p3,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (olduserip[0]!='\0') { if (olduserip[0]!='\0') {
fprintf(fp_ou,"<tr><td></td><td class=\"d ata\">%s</td>",olduserip); fprintf(fp_ou,"<tr><td></td><td class=\"d ata\">%s</td>",olduserip);
if((UserReportFields & USERREPORTFIELDS_C ONNECT) != 0) if ((UserReportFields & USERREPORTFIELDS_ CONNECT) != 0)
fputs("<td></td>",fp_ou); fputs("<td></td>",fp_ou);
if((UserReportFields & USERREPORTFIELDS_B YTES) != 0) if ((UserReportFields & USERREPORTFIELDS_ BYTES) != 0)
fprintf(fp_ou,"<td class=\"data\" >%s</td>",fixnum(unbytes,1)); fprintf(fp_ou,"<td class=\"data\" >%s</td>",fixnum(unbytes,1));
if((UserReportFields & USERREPORTFIELDS_S ETYB) != 0) if ((UserReportFields & USERREPORTFIELDS_ SETYB) != 0)
fputs("<td></td>",fp_ou); fputs("<td></td>",fp_ou);
if((UserReportFields & USERREPORTFIELDS_I N_CACHE_OUT) != 0) if ((UserReportFields & USERREPORTFIELDS_ IN_CACHE_OUT) != 0)
fputs("</td><td></td><td></td>",f p_ou); fputs("</td><td></td><td></td>",f p_ou);
if((UserReportFields & USERREPORTFIELDS_U SED_TIME) != 0) if ((UserReportFields & USERREPORTFIELDS_ USED_TIME) != 0)
fprintf(fp_ou,"<td class=\"data\" >%s</td>",buildtime(unelap)); fprintf(fp_ou,"<td class=\"data\" >%s</td>",buildtime(unelap));
if((UserReportFields & USERREPORTFIELDS_M ILISEC) != 0) if ((UserReportFields & USERREPORTFIELDS_ MILISEC) != 0)
fprintf(fp_ou,"<td class=\"data\" >%s</td>",fixnum2(unelap,1)); fprintf(fp_ou,"<td class=\"data\" >%s</td>",fixnum2(unelap,1));
fputs("</tr>\n",fp_ou); fputs("</tr>\n",fp_ou);
} }
} }
unbytes=0; unbytes=0;
unelap=0; unelap=0;
} }
fclose(fp_in); if (FileObject_Close(fp_in)) {
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),
arqin,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
longline_destroy(&line); longline_destroy(&line);
if (iprel && arqip[0]) { if (iprel && arqip[0]) {
if (!KeepTempLog && unlink(arqip)) { if (!KeepTempLog && unlink(arqip)) {
debuga(_("Cannot delete \"%s\": %s\n"),arqip,stre rror(errno)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),arqip,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
if (!KeepTempLog && unlink(arqin)) { if (!KeepTempLog && unlink(arqin)) {
debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(err no)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"), arqin,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELD S_AVERAGE)) != 0) if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELD S_AVERAGE)) != 0)
fputs("<tfoot>",fp_ou); fputs("<tfoot>",fp_ou);
if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) { if ((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th >",_("TOTAL")); fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th >",_("TOTAL"));
if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) if ((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(tnacc,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(tnacc,1));
if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) if ((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(tnbytes,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(tnbytes,1));
if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) { if ((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
perc=(totbytes) ? tnbytes *100. / totbytes :0.; perc=(totbytes) ? tnbytes *100. / totbytes :0.;
fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc); fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc);
} }
if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) { if ((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0 .; inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0 .;
ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0 .; ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0 .;
fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc); fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
} }
if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) if ((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",bu ildtime(tnelap)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",bu ildtime(tnelap));
if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) if ((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum2(tnelap,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum2(tnelap,1));
if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { if ((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
perc2=(totelap) ? tnelap * 100. / totelap : 0.; perc2=(totelap) ? tnelap * 100. / totelap : 0.;
fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc2); fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc2);
} }
fputs("</tr>\n",fp_ou); fputs("</tr>\n",fp_ou);
} }
if(PerUserLimit > 0) { if (PerUserLimitsNumber>0) {
if ((int)(tnbytes/1000000LLU) > PerUserLimit) { int limit=(int)(tnbytes/1000000LLU);
limit_flag=0; int maskid;
if(access(PerUserLimitFile, R_OK) == 0) { int mask;
if((fp_usr = fopen(PerUserLimitFile, "r") for (i=0 ; i<PerUserLimitsNumber ; i++) {
) == 0) { maskid=i/sizeof(unsigned int);
debugapos("html9",_("Cannot open mask=0x1U << (i % sizeof(unsigned int));
file \"%s\": %s\n"),PerUserLimitFile,strerror(errno)); if (limit>PerUserLimits[i].Limit && (user_limit[m
exit(EXIT_FAILURE); askid] & mask)==0) {
} FILE *fp_usr;
while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NU
LL) { if ((fp_usr = fopen(PerUserLimits[i].File
fixendofline(tmp6); , "at")) == 0) {
if(strcmp(tmp6,uinfo->ip) == 0) { debuga(__FILE__,__LINE__,_("Canno
limit_flag=1; t open file \"%s\": %s\n"),PerUserLimits[i].File,strerror(errno));
exit(EXIT_FAILURE);
}
switch (PerUserLimits[i].Output)
{
case PUOE_UserId:
fprintf(fp_usr,"%s\n",uin
fo->label);
break;
case PUOE_UserIp:
fprintf(fp_usr,"%s\n",uin
fo->ip);
break; break;
}
} }
fclose(fp_usr); if (fclose(fp_usr)==EOF) {
} debuga(__FILE__,__LINE__,_("Write
error in \"%s\": %s\n"),PerUserLimits[i].File,strerror(errno));
if(!limit_flag) {
if((fp_usr = fopen(PerUserLimitFile, "a")
) == 0) {
debugapos("html10",_("Cannot open
file \"%s\": %s\n"),PerUserLimitFile,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fprintf(fp_usr,"%s\n",uinfo->ip); user_limit[maskid]|=mask;
fclose(fp_usr);
if(debug) if (debug)
debuga(_("User %s limit exceeded debuga(__FILE__,__LINE__,_("Limit
(%d MB). Added to file \"%s\"\n"),uinfo->label,PerUserLimit,PerUserLimitFile); exceeded for user %s (%d MB). Added to file \"%s\"\n"),uinfo->label,
PerUserLimits[i].Limit
,PerUserLimits[i].File);
} }
} }
} }
if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) { if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
totbytes2=totbytes/ntotuser; totbytes2=totbytes/ntotuser;
totelap2=totelap/ntotuser; totelap2=totelap/ntotuser;
fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th >",_("AVERAGE")); fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th >",_("AVERAGE"));
if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) if ((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(ttnacc/ntotuser,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(ttnacc/ntotuser,1));
if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) if ((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(totbytes2,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum(totbytes2,1));
fprintf(fp_ou,"<th></th><th></th><th></th>"); fprintf(fp_ou,"<th></th><th></th><th></th>");
if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) if ((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",bu ildtime(totelap2)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",bu ildtime(totelap2));
if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) if ((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum2(totelap2,1)); fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fi xnum2(totelap2,1));
if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) { if ((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
perc2 = (totelap) ? totelap2 * 100. / totelap : 0 .; perc2 = (totelap) ? totelap2 * 100. / totelap : 0 .;
fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc2); fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</t h>",perc2);
} }
fputs("</tr>\n",fp_ou); fputs("</tr>\n",fp_ou);
} }
if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELD S_AVERAGE)) != 0) if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELD S_AVERAGE)) != 0)
fputs("</tfoot>",fp_ou); fputs("</tfoot>",fp_ou);
fputs("</table></div>\n",fp_ou); fputs("</table></div>\n",fp_ou);
if (write_html_trailer(fp_ou)<0) write_html_trailer(fp_ou);
debuga(_("Write error in file \"%s\"\n"),arqou); if (fclose(fp_ou)==EOF) {
if (fclose(fp_ou)==EOF) debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n")
debuga(_("Failed to close file \"%s\": %s\n"),arqou,strer ,arqou,strerror(errno));
ror(errno)); exit(EXIT_FAILURE);
}
htaccess(uinfo); htaccess(uinfo);
} }
userinfo_stopscan(uscan); userinfo_stopscan(uscan);
return; return;
} }
 End of changes. 113 change blocks. 
162 lines changed or deleted 234 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)