/*
- * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
- * 1998, 2010
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
+ * 1998, 2013
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
+ * Support:
+ * http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
#include "include/conf.h"
#include "include/defs.h"
+extern struct globalstatstruct globstat;
+
void htmlrel(void)
{
- DIR *dirp;
- FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
-
- struct dirent *direntp;
- 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 incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0;
- long long int ltemp;
- long long int ntotuser;
- long long int userbytes, userelap;
- char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN];
- char url[MAXLEN], tmsg[50], csort[MAXLEN];
- char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN];
- char userurl[1024], userhora[9], userdia[9];
- char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
- char denied_report[255], name2[MAXLEN];
- //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3];
- char *str;
- char warea[MAXLEN];
- char totuser[8];
- long long int tnacc=0, ttnacc=0, unacc=0;
- float perc=0, perc2=0, ouperc=0, inperc=0;
- char *s;
- int count;
- int cstatus;
- const char txtext[]=".txt";
- int dlen;
- char href2[MAXLEN];
- char urly[MAXLEN];
- char siteind[MAXLEN];
- struct getwordstruct gwarea;
-
- if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return;
-
- strcpy(tmp2,TempDir);
- strcat(tmp2,"/sargtmp.unsort");
-
- strcpy(tmp3,TempDir);
- strcat(tmp3,"/sargtmp.log");
-
- strcpy(arqper,dirname);
- strcat(arqper,"/sarg-period");
-
- if ((fp_in = fopen(arqper, "r")) == 0){
- fprintf(stderr, "SARG: (html1) %s: %s\n",text[45],arqper);
- exit(1);
- }
-
- if (!fgets(period,sizeof(period),fp_in)) {
- fprintf(stderr,"SARG: (html1) read error in %s\n",arqper);
- exit(1);
- }
- fclose(fp_in);
-
- strcpy(arqper,dirname);
- strcat(arqper,"/sarg-general");
-
- if ((fp_in = fopen(arqper, "r")) == 0){
- fprintf(stderr, "SARG: (html2) %s: %s\n",text[45],arqper);
- exit(1);
- }
-
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- if(strstr(buf,"TOTAL") == 0) {
- getword_start(&gwarea,buf);
- if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
- exit(1);
- }
- ttnacc+=ltemp;
- if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper);
- exit(1);
- }
- totbytes+=ltemp;
- if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__);
- exit(1);
- }
- totelap+=ltemp;
- }
- }
-
- fclose(fp_in);
-
- dirp = opendir(tmp);
- while ( (direntp = readdir( dirp )) != NULL ) {
- dlen=strlen(direntp->d_name)-(sizeof(txtext)-1);
- if (dlen<0) continue;
- if(strcmp(direntp->d_name+dlen,txtext) != 0)
- continue;
-
- count=1;
- if (dlen>0) {
- if (dlen>=sizeof(wusuario)) continue;
- strncpy(wusuario,direntp->d_name,dlen);
- wusuario[dlen]=0;
- } else {
- wusuario[0]=0;
- }
- str=strrchr(wusuario,'.');
- if (str)
- strcpy(denied_report,str+1);
- else
- strcpy(denied_report,wusuario);
-
- if (snprintf(warea,sizeof(warea),"%s/%s",dirname,wusuario)>=sizeof(warea)) {
- fprintf(stderr,"SARG: destination directory too long: %s/%s\n",dirname,wusuario);
- exit(1);
- }
- mkdir(warea,0755);
-
- report_day(wusuario);
- greport_day(wusuario);
-
- strcpy(usuario,wusuario);
- strcpy(arqin,tmp);
- strcat(arqin,"/");
- strcpy(arqou,dirname);
- strcat(arqou,"/");
- strcat(arqou,usuario);
- strcat(arqou,"/");
- strcat(arqou,usuario);
- strcat(arqou,".html");
- strcpy(duser,arqin);
- strcat(duser,"denied_");
- strcat(arqin,direntp->d_name);
-
- if((str=(char *) strstr(denied_report, "_")) != (char *) NULL ) {
- if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
- fixip(denied_report);
- }
- strcat(duser,denied_report);
- strcat(duser,".html");
- if(access(duser, R_OK) != 0)
- denied_report[0]='\0';
-
- strcpy(u2,usuario);
- if(userip)
- fixip(u2);
- if(Ip2Name)
- ip2name(u2,sizeof(u2));
-
- user_find(name2, sizeof(name2), u2);
-
- if(dotinuser && strchr(name2,'_')) {
- subs(name2,sizeof(name2),"_",".");
- }
-
- if ((fp_in = fopen(arqin, "r")) == 0){
- fprintf(stderr, "SARG: (html3) %s: %s\n",text[45],arqin);
- exit(1);
- }
-
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- getword_start(&gwarea,buf);
- if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
- exit(1);
- }
- tnacc+=ltemp;
- if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
- exit(1);
- }
- tnbytes+=ltemp;
- if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 ||
- getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
- exit(1);
- }
- tnelap+=ltemp;
- if (getword_atoll(<emp,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin);
- exit(1);
- }
- tnincache+=ltemp;
- if (getword_atoll(<emp,&gwarea,'\n')<0) {
- printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__);
- exit(1);
- }
- tnoucache+=ltemp;
- }
-
- rewind(fp_in);
-
- if ((fp_ou = fopen(arqou, "w")) == 0){
- fprintf(stderr, "SARG: (html5) %s: %s\n",text[45],arqou);
- exit(1);
- }
-
- fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou);
- fputs("<html>\n",fp_ou);
- fputs("<head>\n",fp_ou);
- fprintf(fp_ou," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
- css(fp_ou);
- fputs("</head>\n",fp_ou);
-
- fprintf(fp_ou,"<body style=\"font-family:%s;font-size:%s;background-color:%s; \
- background-image:url(%s)\">\n",FontFace,TitleFontSize,BgColor,BgImage);
-
- write_logo_image(fp_ou);
-
- if(IndexTree == INDEX_TREE_DATE)
- show_sarg(fp_ou, "../../../..");
- else
- show_sarg(fp_ou, "../..");
-
- fputs("<div align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou);
- fprintf(fp_ou,"<tr><th class=\"title\" colspan=\"2\">%s</th></tr>\n",Title);
-
- fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[89],period);
- fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s</td></tr>\n",text[90],name2);
- fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"2\">%s: %s, %s</td></tr>\n",text[104],UserSortField,UserSortOrder);
- fprintf(fp_ou,"<tr><td class=\"header3\" colspan=\"2\">%s %s</td></tr>\n",text[32],text[55]);
- fputs("<tr><td></td></tr>\n",fp_ou);
-
- fputs("</table></div>\n",fp_ou);
- fputs("<div align=\"center\"><table cellpadding=\"2\" cellspacing=\"1\">\n",fp_ou);
-
- if(denied_report[0]!='\0') {
- fprintf(fp_ou,"<tr><td class=\"header\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a> %s</td></tr>\n",denied_report,text[116],text[55]);
- }
-
- strcpy(val3,text[92]);
- strcpy(val4,text[93]);
- sprintf(val11,"%%%s",text[93]);
- sprintf(val5,"%s-%s-%s",text[113],text[114],text[112]);
- strcpy(val6,text[94]);
- strcpy(val7,text[95]);
- sprintf(val8,"%%%s",text[99]);
- strcpy(val9,"colspan=\"2\"");
- bzero(val10, 255);
-
- if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0)
- bzero(val3, 255);
- if((UserReportFields & USERREPORTFIELDS_BYTES) == 0)
- bzero(val4, 255);
- if((UserReportFields & USERREPORTFIELDS_SETYB) == 0)
- bzero(val11, 255);
- if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) {
- bzero(val5, 255);
- bzero(val9, 255);
- strcpy(val10,"<td></td>");
- }
- if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0)
- bzero(val6, 255);
- if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0)
- bzero(val7, 255);
- if((UserReportFields & USERREPORTFIELDS_PTIME) == 0)
- bzero(val8, 255);
-
- fprintf(fp_ou,"<tr><th></th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header3\" %s>%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th><th class=\"header\">%s</th></tr>\n",text[91],val3,val4,val11,val9,val5,val6,val7,val8);
-
- if(debug) {
- if(userip) {
- strcpy(u2,usuario);
- fixip(u2);
- debuga("%s: %s",text[61],u2);
- } else
- debuga("%s: %s",text[61],usuario);
- }
-
- while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
- getword_start(&gwarea,buf);
- if (getword_atoll(&twork,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin);
- exit(1);
- }
- if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin);
- exit(1);
- }
- if (getword(url,sizeof(url),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken url in your %s file.\n",arqin);
- exit(1);
- }
- if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken status in your %s file.\n",arqin);
- exit(1);
- }
- if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin);
- exit(1);
- }
- if (getword_atoll(&incache,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin);
- exit(1);
- }
- if (getword_atoll(&oucache,&gwarea,'\n')<0) {
- printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__);
- exit(1);
- }
-
- if(strncmp(tmsg,"OK",2) != 0)
- sprintf(tmsg,"<td class=\"data\">%s</td>",text[46]);
- else bzero(tmsg, 50);
-
- if(nnbytes) {
- perc=nnbytes * 100;
- perc=perc / tnbytes;
- } else {
- perc=0;
- ouperc=0;
- }
-
- if(nnelap) {
- perc2=nnelap * 100;
- perc2=perc2 / tnelap;
- } else perc2=0;
-
- if(incache) {
- inperc=incache * 100;
- inperc=inperc / nnbytes;
- } else inperc=0;
-
- if(oucache) {
- ouperc=oucache * 100;
- ouperc=ouperc / nnbytes;
- } else ouperc=0;
-
- strcpy(wwork1,fixnum(twork,1));
- strcpy(wwork2,fixnum(nnbytes,1));
- strcpy(wwork3,fixnum2(nnelap,1));
-
- if(!LongUrl) {
- char *endofhost=strchr(url,'/');
- if (endofhost) *endofhost='\0';
- strcpy(urly,url);
- } else {
- strcpy(urly,url);
- url_module(url, module);
- str=strchr(url,'/');
- if (str){
- *str='\0';
- strcat(url,"...");
- strcat(url,module);
- }
- }
-
- if(Privacy)
- sprintf(httplink,"<span style=\"color:%s;\">%s</span>",PrivacyStringColor,PrivacyString);
- else {
- if(IndexTree == INDEX_TREE_DATE)
- sprintf(tmp6,"../%s",ImageFile);
- else
- strcpy(tmp6,"../../images");
- if(BlockIt[0]!='\0')
- snprintf(httplink,sizeof(httplink),"<a href=\"%s%s?url=%s\"><img src=\"%s/sarg-squidguard-block.png\" border=\"0\"></a><a href=http://%s> %s</a>",wwwDocumentRoot,BlockIt,urly,tmp6,urly,urly);
- else
- snprintf(httplink,sizeof(httplink),"<a href=\"http://%s\" title=\"%s\">%s</a>",urly,urly,url);
- }
-
- if((ReportType & REPORT_TYPE_SITE_USER_TIME_DATE) != 0) {
- strcpy(ltext110,text[110]);
- for(s=ltext110; *s; ++s)
- *s=tolower(*s);
- strcpy(siteind,urly);
- str=siteind;
- for(z1=0; str[z1]; z1++) {
- if(str[z1]=='?' || str[z1]=='-' || str[z1]=='.' || str[z1]==':' || str[z1]=='/' || str[z1]=='\\' || str[z1]=='*' ||
- str[z1]=='\'' || str[z1]=='\"' || str[z1]=='$' || str[z1]=='@')
- str[z1]='_';
- }
- sprintf(href2,"<a href=\"tt%s-%s.html\"><img src=\"%s/datetime.png\" border=\"0\" title=\"%s %s\" alt=\"T\"></a>",usuario,siteind,tmp6,ltext110,text[55]);
- } else {
- bzero(href2, MAXLEN);
- bzero(ltext110, 50);
- }
-
- sprintf(val2,"%s",href2);
- sprintf(val3,"%3.2f%%",perc);
- sprintf(val4,"%3.2f%%",inperc);
- sprintf(val5,"%3.2f%%",ouperc);
- sprintf(val6,"%s",buildtime(nnelap));
- sprintf(val7,"%3.2f%%",perc2);
-
- if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) {
- bzero(wwork1, 255);
- bzero(hbc1, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) {
- bzero(wwork2, 255);
- bzero(hbc2, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) {
- bzero(wwork3, 255);
- bzero(hbc3, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_SETYB) == 0) {
- bzero(val3, 255);
- bzero(hbc4, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) {
- bzero(val4, 255);
- bzero(val5, 255);
- bzero(hbc5, 30);
- bzero(hbc6, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) {
- bzero(val6, 255);
- bzero(hbc7, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) {
- bzero(val7, 255);
- bzero(hbc8, 30);
- }
- if(strncmp(tmsg," ",1) == 0)
- bzero(hbc9, 30);
-
-
- if(UserReportLimit<=0 || count<=UserReportLimit) {
- fprintf(fp_ou,"<tr><td class=\"data\">%s</td><td class=\"data2\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td><td class=\"data\">%s</td>%s</tr>\n",val2,httplink,wwork1,wwork2,val3,val4,val5,val6,wwork3,val7,tmsg);
- count++;
- }
-
- if(iprel) {
- strcpy(arqip,tmp);
- strcat(arqip,"/");
- strcat(arqip,usuario);
- strcat(arqip,".ip");
-
- if ((fp_ip = fopen(arqip, "r")) == 0){
- fprintf(stderr, "SARG: (html6) %s: %s\n",text[45],arqip);
- exit(1);
- }
-
- if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
- fprintf(stderr, "SARG: (html7) %s: %s\n",text[45],tmp2);
- exit(1);
- }
-
- while(fgets(buf,sizeof(buf),fp_ip)!=NULL) {
- if(strstr(buf,url) != 0)
- fputs(buf,fp_ip2);
- }
-
- fclose(fp_ip);
- fclose(fp_ip2);
-
- sprintf(csort,"sort -n -T \"%s\" -k 1,1 -k 5,5 -o \"%s\" \"%s\"",TempDir,tmp3,tmp2);
- cstatus=system(csort);
- if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- fprintf(stderr, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus));
- fprintf(stderr, "SARG: sort command: %s\n",csort);
- exit(1);
- }
-
- if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
- fprintf(stderr, "SARG: (html8) %s: %s\n",text[45],tmp3);
- exit(1);
- }
-
- olduserip[0]='\0';
-
- while(fgets(buf,sizeof(buf),fp_ip)) {
- getword_start(&gwarea,buf);
- if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken user IP in your %s file.\n",tmp3);
- exit(1);
- }
- if (getword(userurl,sizeof(userurl),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken user URL in your %s file.\n",tmp3);
- exit(1);
- }
- if (getword(userdia,sizeof(userdia),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken day in your %s file.\n",tmp3);
- exit(1);
- }
- if (getword(userhora,sizeof(userhora),&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3);
- exit(1);
- }
- if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3);
- exit(1);
- }
- if (getword_atoll(&userelap,&gwarea,'\t')<0) {
- printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__);
- exit(1);
- }
- if(strcmp(user_ip,olduserip) != 0) {
- my_lltoa(unelap,val2,0);
- sprintf(wwork1,"%s",fixnum(unbytes,1));
- fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val2);
-
- strcpy(olduserip,user_ip);
- unacc=0;
- unbytes=0;
- unelap=0;
- }
-
- unbytes=unbytes+userbytes;
- unelap=unelap+userelap;
- }
-
- fclose(fp_ip);
-
- unlink(tmp2);
- unlink(tmp3);
-
- my_lltoa(unelap,val3,0);
- sprintf(wwork1,"%s",fixnum(unbytes,1));
- fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td><td></td><td class=\"data\">%s</td><td></td><td></td><td></td><td class=\"data\">%s</td><td class=\"data\">%s</td></tr>\n",olduserip,wwork1,buildtime(unelap),val3);
- }
-
- unacc=0;
- unbytes=0;
- unelap=0;
-
- }
-
- if(iprel)
- unlink(arqip);
- unlink(arqin);
-
- if(tnbytes) {
- perc=totbytes / 100;
- perc=tnbytes / perc;
- } else perc=0;
-
- if(tnelap) {
- perc2=totelap / 100;
- perc2=tnelap / perc2;
- } else perc2=0;
-
- if(tnoucache) {
- ouperc=tnoucache * 100;
- ouperc=ouperc / tnbytes;
- } else ouperc=0;
-
- if(tnincache) {
- inperc=tnincache * 100;
- inperc=inperc / tnbytes;
- } else inperc=0;
-
- sprintf(wwork1,"%s",fixnum(tnacc,1));
- sprintf(wwork2,"%s",fixnum(tnbytes,1));
- sprintf(wwork3,"%s",fixnum2(tnelap,1));
-
- sprintf(val2,"%s%s",href2,ltext110);
- sprintf(val3,"%3.2f%%",perc);
- sprintf(val4,"%3.2f%%",inperc);
- sprintf(val5,"%3.2f%%",ouperc);
- sprintf(val6,"%s",buildtime(tnelap));
- sprintf(val7,"%3.2f%%",perc2);
-
- strcpy(hbc1,"class=\"header2\"");
- strcpy(hbc2,"class=\"header2\"");
- strcpy(hbc3,"class=\"header2\"");
- strcpy(hbc4,"class=\"header2\"");
- strcpy(hbc5,"class=\"header2\"");
- strcpy(hbc6,"class=\"header2\"");
- strcpy(hbc7,"class=\"header2\"");
- strcpy(hbc8,"class=\"header2\"");
- strcpy(hbc9,"class=\"header\"");
-
- if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) {
- bzero(wwork1, 255);
- bzero(hbc1, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) {
- bzero(wwork2, 255);
- bzero(hbc2, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) {
- bzero(wwork3, 255);
- bzero(hbc3, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_SETYB) == 0) {
- bzero(val3, 255);
- bzero(hbc4, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) == 0) {
- bzero(val4, 255);
- bzero(hbc5, 30);
- bzero(val5, 255);
- bzero(hbc6, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) {
- bzero(val6, 255);
- bzero(hbc7, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) {
- bzero(val7, 255);
- bzero(hbc8, 30);
- }
-
- if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
- fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc9,text[107],hbc1,wwork1,hbc2,wwork2,hbc4,val3,hbc5,val4,hbc6,val5,hbc7,val6,hbc3,wwork3,hbc8,val7);
- }
-
- fclose(fp_in);
-
- if(PerUserLimit > 0) {
- if(tnbytes > (PerUserLimit*1000000)) {
- limit_flag=0;
- if(access(PerUserLimitFile, R_OK) == 0) {
- if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
- fprintf(stderr, "SARG: (html9) %s: %s\n",text[45],PerUserLimitFile);
- exit(1);
- }
- while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
- if(strstr(tmp6,"\n") != 0)
- tmp6[strlen(tmp6)-1]='\0';
- if(strcmp(tmp6,u2) == 0) {
- limit_flag=1;
- break;
- }
- }
- fclose(fp_usr);
- }
-
- if(!limit_flag) {
- if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
- fprintf(stderr, "SARG: (html10) %s: %s\n",text[45],PerUserLimitFile);
- exit(1);
- }
- fprintf(fp_usr,"%s\n",u2);
- fclose(fp_usr);
-
- if(debug)
- debuga("%s %s %s (%d MB). %s %s",text[32],u2,text[74],PerUserLimit,text[75],PerUserLimitFile);
- }
- }
- }
-
-// if(indexonly) {
-// unlink(arqou);
-// continue;
-// }
-
- if ((ReportType & REPORT_TYPE_TOPUSERS) != 0) {
- strcpy(arqper,dirname);
- strcat(arqper,"/sarg-users");
-
- if ((fp_in = fopen(arqper, "r")) == 0){
- fprintf(stderr, "SARG: (html11) %s: %s\n",text[45],arqper);
- exit(1);
- }
-
- if (!fgets(totuser,sizeof(totuser),fp_in)) {
- fprintf(stderr,"SARG: (html11) read error in %s\n",arqper);
- exit(1);
- }
- fclose(fp_in);
-
- ntotuser=my_atoll(totuser);
- if (ntotuser<=0) ntotuser=1;
- totbytes2=totbytes/ntotuser;
- totelap2=totelap/ntotuser;
-
- if(totbytes2) {
- perc = totbytes / 100;
- perc = totbytes2 / perc;
- } else perc=0;
-
- if(totelap2) {
- perc2 = totelap / 100;
- perc2 = totelap2 / perc2;
- } else perc2=0;
-
- twork2=ntotuser;
- twork=ttnacc/twork2;
-
- strcpy(wwork1,fixnum(twork,1));
- strcpy(wwork2,fixnum(totbytes2,1));
- strcpy(wwork3,fixnum2(totelap2,1));
-
- sprintf(val6,"%s",buildtime(totelap2));
- sprintf(val7,"%3.2f%%",perc2);
-
- strcpy(hbc1,"class=\"header2\"");
- strcpy(hbc2,"class=\"header2\"");
- strcpy(hbc3,"class=\"header2\"");
- strcpy(hbc4,"class=\"header2\"");
- strcpy(hbc5,"class=\"header2\"");
- strcpy(hbc6,"class=\"header\"");
-
- if((UserReportFields & USERREPORTFIELDS_CONNECT) == 0) {
- bzero(wwork1, 255);
- bzero(hbc1, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_BYTES) == 0) {
- bzero(wwork2, 255);
- bzero(hbc2, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_MILISEC) == 0) {
- bzero(wwork3, 255);
- bzero(hbc3, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_USED_TIME) == 0) {
- bzero(val6, 255);
- bzero(hbc4, 30);
- }
- if((UserReportFields & USERREPORTFIELDS_PTIME) == 0) {
- bzero(val7, 255);
- bzero(hbc5, 30);
- }
-
- if((UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
- fprintf(fp_ou,"<tr><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th><th></th><th></th><th></th><th %s>%s</th><th %s>%s</th><th %s>%s</th></tr>\n",hbc6,text[96],hbc1,wwork1,hbc2,wwork2,hbc4,val6,hbc3,wwork3,hbc5,val7);
- }
- } /* added */
- tnacc=0;
- tnbytes=0;
- tnelap=0;
- tnincache=0;
- tnoucache=0;
-
- fputs("</table></div>\n",fp_ou);
-
- show_info(fp_ou);
-
- fputs("</body>\n</html>\n",fp_ou);
-
- fclose(fp_ou);
-
- htaccess(wusuario);
-
- }
-
- (void)rewinddir(dirp);
- (void)closedir(dirp);
- greport_cleanup();
-
- return;
+ FILE *fp_in, *fp_ou, *fp_ip, *fp_ip2, *fp_usr;
+
+ 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 incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0;
+ long long int ltemp;
+ long long int ntotuser;
+ long long int userbytes, userelap;
+ char *buf;
+ char arqin[MAXLEN], arqou[MAXLEN], arqip[MAXLEN];
+ char *url, tmsg[50], csort[MAXLEN];
+ char duser[MAXLEN];
+ char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN];
+ char warea[MAXLEN];
+ char tmp6[MAXLEN];
+ char *user_url;
+ long long int tnacc=0, ttnacc=0;
+ double perc=0, perc2=0, ouperc=0, inperc=0;
+ int count;
+ int cstatus;
+ bool have_denied_report;
+ const char *sort_field;
+ const char *sort_order;
+ char siteind[MAX_TRUNCATED_URL];
+ struct getwordstruct gwarea;
+ longline line,line1;
+ const struct userinfostruct *uinfo;
+ userscan uscan;
+
+ if (snprintf(tmp2,sizeof(tmp2),"%s/sargtmp.int_unsort",tmp)>=sizeof(tmp2)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/sargtmp.int_unsort\n",tmp);
+ exit(EXIT_FAILURE);
+ }
+
+ if (snprintf(tmp3,sizeof(tmp3),"%s/sargtmp.int_log",tmp)>=sizeof(tmp3)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/sargtmp.int_log\n",tmp);
+ exit(EXIT_FAILURE);
+ }
+
+ tnacc=globstat.nacc;
+ totbytes=globstat.nbytes;
+ totelap=globstat.elap;
+ ntotuser=globstat.totuser;
+
+ sort_labels(&sort_field,&sort_order);
+
+ uscan=userinfo_startscan();
+ if (uscan == NULL) {
+ debuga(_("Cannot enumerate the user list\n"));
+ exit(EXIT_FAILURE);
+ }
+ while ( (uinfo = userinfo_advancescan(uscan)) != NULL ) {
+ if (snprintf(warea,sizeof(warea),"%s/%s",outdirname,uinfo->filename)>=sizeof(warea)) {
+ debuga(_("Destination directory too long: "));
+ debuga_more("%s/%s\n",outdirname,uinfo->filename);
+ exit(EXIT_FAILURE);
+ }
+ if (!uinfo->topuser) {
+ //! \todo Instead of deleting the supernumerary directories, don't create them in the first place.
+ unlinkdir(warea,0);
+ continue;
+ }
+
+ if (access(warea, R_OK) != 0) {
+ if (mkdir(warea,0755)) {
+ debuga(_("Cannot create directory \"%s\": %s\n"),warea,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+ tmpsort(uinfo);
+
+ if (snprintf(arqin,sizeof(arqin),"%s/htmlrel.txt",tmp)>=sizeof(arqin)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/htmlrel.txt\n",tmp);
+ exit(EXIT_FAILURE);
+ }
+ if ((fp_in = fopen(arqin, "r")) == 0){
+ if (uinfo->no_report) continue;
+ debugapos("html3",_("Cannot open file \"%s\": %s\n"),arqin,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (snprintf(arqou,sizeof(arqou),"%s/%s/%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqou)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/%s/%s.html\n",outdirname,uinfo->filename,uinfo->filename);
+ exit(EXIT_FAILURE);
+ }
+ if (snprintf(duser,sizeof(duser),"%s/denied_%s.html",outdirname,uinfo->filename)>=sizeof(duser)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/denied_%s.html\n",outdirname,uinfo->filename);
+ exit(EXIT_FAILURE);
+ }
+ if(access(duser, R_OK) != 0)
+ have_denied_report=false;
+ else
+ have_denied_report=true;
+
+ if ((line=longline_create())==NULL) {
+ debuga(_("Not enough memory to read file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+
+ tnacc=0;
+ tnbytes=0;
+ tnelap=0;
+ tnincache=0;
+ tnoucache=0;
+ while((buf=longline_read(fp_in,line))!=NULL) {
+ getword_start(&gwarea,buf);
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
+ debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ tnacc+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
+ debuga(_("Invalid download size in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ tnbytes+=ltemp;
+ if (getword_ptr(NULL,NULL,&gwarea,'\t')<0) {
+ debuga(_("Invalid url in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_skip(MAXLEN,&gwarea,'\t')<0) {
+ debuga(_("Invalid access code in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
+ debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ tnelap+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\t')<0) {
+ debuga(_("Invalid in-cache volume in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ tnincache+=ltemp;
+ if (getword_atoll(<emp,&gwarea,'\n')<0) {
+ debuga(_("Invalid out-of-cache volume in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ tnoucache+=ltemp;
+ }
+
+ rewind(fp_in);
+
+ if ((fp_ou = fopen(arqou, "w")) == 0){
+ debugapos("html5",_("Cannot open file \"%s\": %s\n"),arqou,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ 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: %s</td></tr>\n",_("Period"),period.html);
+ fprintf(fp_ou,"<tr><td class=\"header_c\">%s: %s</td></tr>\n",_("User"),uinfo->label);
+ fputs("<tr><td class=\"header_c\">",fp_ou);
+ fprintf(fp_ou,_("Sort: %s, %s"),sort_field,sort_order);
+ fputs("</td></tr>\n",fp_ou);
+ fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("User report"));
+ close_html_header(fp_ou);
+
+ if (have_denied_report) {
+ fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
+ fprintf(fp_ou,"<tr><td class=\"header_l\" colspan=\"11\"><a href=\"denied_%s.html\">%s</a></td></tr>\n",uinfo->filename,_("SmartFilter report"));
+ fputs("<tr><td></td></tr>\n</table></div>\n",fp_ou);
+ }
+
+ fputs("<div class=\"report\"><table cellpadding=\"2\" cellspacing=\"1\"",fp_ou);
+ if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
+ fputs(">\n",fp_ou);
+
+ fputs("<thead><tr><th class=\"sorttable_nosort\"></th><th class=\"header_l",fp_ou);
+ if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
+ fprintf(fp_ou,"\">%s</th>",_("ACCESSED SITE"));
+
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("CONNECT"));
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
+ if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("BYTES"));
+ if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
+ fprintf(fp_ou,"<th class=\"header_c\" colspan=\"2\">%s</th><th style=\"display:none;\"></th>",_("IN-CACHE-OUT"));
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("ELAPSED TIME"));
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("MILLISEC"));
+ if((UserReportFields & USERREPORTFIELDS_PTIME) != 0)
+ fprintf(fp_ou,"<th class=\"header_l\">%%%s</th>",_("TIME"));
+
+ fputs("</tr></thead>\n",fp_ou);
+
+ if(debug) {
+ debuga(_("Making report %s\n"),uinfo->id);
+ }
+ count=0;
+ arqip[0]='\0';
+
+ while((buf=longline_read(fp_in,line))!=NULL) {
+ getword_start(&gwarea,buf);
+ if (getword_atoll(&twork,&gwarea,'\t')<0) {
+ debuga(_("Invalid number of accesses in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&nnbytes,&gwarea,'\t')<0) {
+ debuga(_("Invalid number of bytes in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
+ debuga(_("Invalid url in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword(tmsg,sizeof(tmsg),&gwarea,'\t')<0) {
+ debuga(_("Invalid access code in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&nnelap,&gwarea,'\t')<0) {
+ debuga(_("Invalid elapsed time in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&incache,&gwarea,'\t')<0) {
+ debuga(_("Invalid in-cache column in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&oucache,&gwarea,'\n')<0) {
+ debuga(_("Invalid out-of-cache column in file \"%s\"\n"),arqin);
+ exit(EXIT_FAILURE);
+ }
+
+ if(UserReportLimit<=0 || count<=UserReportLimit) {
+ fputs("<tr>",fp_ou);
+
+ if(IndexTree == INDEX_TREE_DATE)
+ sprintf(tmp6,"../%s",ImageFile);
+ else
+ 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"));
+ } else {
+ fprintf(fp_ou,"<td class=\"data\"></td>");
+ }
+
+ if(Privacy)
+ 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' && 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);
+ }
+ output_html_link(fp_ou,url,100);
+ fputs("</td>",fp_ou);
+ }
+
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0) {
+ fputs("<td class=\"data\"",fp_ou);
+ if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)twork);
+ fprintf(fp_ou,">%s</td>",fixnum(twork,1));
+ }
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0) {
+ fputs("<td class=\"data\"",fp_ou);
+ if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnbytes);
+ fprintf(fp_ou,">%s</td>",fixnum(nnbytes,1));
+ }
+ if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
+ perc=(tnbytes) ? nnbytes * 100. / tnbytes : 0.;
+ fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc);
+ }
+ if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
+ inperc=(nnbytes) ? incache * 100. / nnbytes : 0.;
+ ouperc=(nnbytes) ? oucache * 100. / nnbytes : 0.;
+ fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
+ }
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0) {
+ fputs("<td class=\"data\"",fp_ou);
+ if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
+ fprintf(fp_ou,">%s</td>",buildtime(nnelap));
+ }
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0) {
+ fputs("<td class=\"data\"",fp_ou);
+ if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%"PRId64"\"",(int64_t)nnelap);
+ fprintf(fp_ou,">%s</td>",fixnum2(nnelap,1));
+ }
+ if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+ perc2=(tnelap) ? nnelap * 100. / tnelap : 0.;
+ fprintf(fp_ou,"<td class=\"data\">%3.2lf%%</td>",perc2);
+ }
+
+ if(strncmp(tmsg,"OK",2) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",_("DENIED"));
+
+ 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);
+ if (unlink(warea)!=0) {
+ debuga(_("Cannot delete \"%s\": %s\n"),warea,strerror(errno));
+ }
+ }
+
+ if(iprel) {
+ if (snprintf(arqip,sizeof(arqip),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(arqip)) {
+ debuga(_("Path too long: "));
+ debuga_more("%s/%s.ip\n",tmp,uinfo->filename);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((fp_ip = fopen(arqip, "r")) == 0){
+ debugapos("html6",_("Cannot open file \"%s\": %s\n"),arqip,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if ((fp_ip2 = MY_FOPEN(tmp2, "a")) == 0){
+ debugapos("html7",_("Cannot open file \"%s\": %s\n"),tmp2,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if ((line1=longline_create())==NULL) {
+ debuga(_("Not enough memory to read file \"%s\"\n"),arqip);
+ exit(EXIT_FAILURE);
+ }
+ while((buf=longline_read(fp_ip,line1))!=NULL) {
+ getword_start(&gwarea,buf);
+ if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
+ debuga(_("Invalid user IP in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_ptr(buf,&user_url,&gwarea,'\t')<0) {
+ debuga(_("Invalid url in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (strncmp(user_url,url,strlen(url))!=0) continue;
+ if (getword_skip(15,&gwarea,'\t')<0) {
+ debuga(_("Invalid day in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_skip(15,&gwarea,'\t')<0) {
+ debuga(_("Invalid time in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
+ debuga(_("Invalid size in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&userelap,&gwarea,'\0')<0) {
+ debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ fprintf(fp_ip2,"%s\t%"PRIu64"\t%"PRIu64"\n",user_ip,(uint64_t)userbytes,(uint64_t)userelap);
+ }
+ longline_destroy(&line1);
+
+ fclose(fp_ip);
+ fclose(fp_ip2);
+
+ 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_more("sort -n -t \"\t\" -T \"%s\" -k 1,1 -k 2,2 -o \"%s\" \"%s\"",tmp,tmp3,tmp2);
+ exit(EXIT_FAILURE);
+ }
+ cstatus=system(csort);
+ if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+ debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(_("sort command: %s\n"),csort);
+ exit(EXIT_FAILURE);
+ }
+
+ if ((fp_ip = MY_FOPEN(tmp3, "r")) == 0) {
+ debugapos("html8",_("Cannot open file \"%s\": %s\n"),tmp3,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (unlink(tmp2)) {
+ debuga(_("Cannot delete \"%s\": %s\n"),tmp2,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ olduserip[0]='\0';
+
+ if ((line1=longline_create())==NULL) {
+ debuga(_("Not enough memory to read file \"%s\"\n"),arqip);
+ exit(EXIT_FAILURE);
+ }
+ while((buf=longline_read(fp_ip,line1))!=NULL) {
+ getword_start(&gwarea,buf);
+ if (getword(user_ip,sizeof(user_ip),&gwarea,'\t')<0) {
+ debuga(_("Invalid user IP in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&userbytes,&gwarea,'\t')<0) {
+ debuga(_("Invalid size in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if (getword_atoll(&userelap,&gwarea,'\0')<0) {
+ debuga(_("Invalid elapsed time in file \"%s\"\n"),tmp3);
+ exit(EXIT_FAILURE);
+ }
+ if(strcmp(user_ip,olduserip) != 0) {
+ if (olduserip[0]!='\0') {
+ fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+ fputs("<td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
+ if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
+ fputs("<td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
+ fputs("</td><td></td><td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
+ fputs("</tr>\n",fp_ou);
+ }
+
+ strcpy(olduserip,user_ip);
+ unbytes=0;
+ unelap=0;
+ }
+
+ unbytes+=userbytes;
+ unelap+=userelap;
+ }
+
+ fclose(fp_ip);
+ longline_destroy(&line1);
+
+ if (unlink(tmp3)) {
+ debuga(_("Cannot delete \"%s\": %s\n"),tmp3,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if (olduserip[0]!='\0') {
+ fprintf(fp_ou,"<tr><td></td><td class=\"data\">%s</td>",olduserip);
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+ fputs("<td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum(unbytes,1));
+ if((UserReportFields & USERREPORTFIELDS_SETYB) != 0)
+ fputs("<td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0)
+ fputs("</td><td></td><td></td>",fp_ou);
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",buildtime(unelap));
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+ fprintf(fp_ou,"<td class=\"data\">%s</td>",fixnum2(unelap,1));
+ fputs("</tr>\n",fp_ou);
+ }
+ }
+
+ unbytes=0;
+ unelap=0;
+ }
+
+ fclose(fp_in);
+ longline_destroy(&line);
+
+ if (iprel && arqip[0]) {
+ if (!KeepTempLog && unlink(arqip)) {
+ debuga(_("Cannot delete \"%s\": %s\n"),arqip,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ }
+ if (!KeepTempLog && unlink(arqin)) {
+ debuga(_("Cannot delete \"%s\": %s\n"),arqin,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
+ fputs("<tfoot>",fp_ou);
+
+ if((UserReportFields & USERREPORTFIELDS_TOTAL) != 0) {
+ fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("TOTAL"));
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnacc,1));
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(tnbytes,1));
+ if((UserReportFields & USERREPORTFIELDS_SETYB) != 0) {
+ perc=(totbytes) ? tnbytes *100. / totbytes :0.;
+ fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc);
+ }
+ if((UserReportFields & USERREPORTFIELDS_IN_CACHE_OUT) != 0) {
+ inperc=(tnbytes) ? tnincache * 100. / tnbytes : 0.;
+ ouperc=(tnbytes) ? tnoucache * 100. / tnbytes : 0.;
+ fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
+ }
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(tnelap));
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(tnelap,1));
+ if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+ perc2=(totelap) ? tnelap * 100. / totelap : 0.;
+ fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
+ }
+ fputs("</tr>\n",fp_ou);
+ }
+
+ if(PerUserLimit > 0) {
+ if ((int)(tnbytes/1000000LLU) > PerUserLimit) {
+ limit_flag=0;
+ if(access(PerUserLimitFile, R_OK) == 0) {
+ if((fp_usr = fopen(PerUserLimitFile, "r")) == 0) {
+ debugapos("html9",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ while(fgets(tmp6,sizeof(tmp6),fp_usr)!=NULL) {
+ fixendofline(tmp6);
+ if(strcmp(tmp6,uinfo->ip) == 0) {
+ limit_flag=1;
+ break;
+ }
+ }
+ fclose(fp_usr);
+ }
+
+ if(!limit_flag) {
+ if((fp_usr = fopen(PerUserLimitFile, "a")) == 0) {
+ debugapos("html10",_("Cannot open file \"%s\": %s\n"),PerUserLimitFile,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ fprintf(fp_usr,"%s\n",uinfo->ip);
+ fclose(fp_usr);
+
+ if(debug)
+ debuga(_("User %s limit exceeded (%d MB). Added to file \"%s\"\n"),uinfo->label,PerUserLimit,PerUserLimitFile);
+ }
+ }
+ }
+
+ if ((ReportType & REPORT_TYPE_TOPUSERS) != 0 && (UserReportFields & USERREPORTFIELDS_AVERAGE) != 0) {
+ totbytes2=totbytes/ntotuser;
+ totelap2=totelap/ntotuser;
+
+ fprintf(fp_ou,"<tr><th></th><th class=\"header_l\">%s</th>",_("AVERAGE"));
+ if((UserReportFields & USERREPORTFIELDS_CONNECT) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(ttnacc/ntotuser,1));
+ if((UserReportFields & USERREPORTFIELDS_BYTES) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum(totbytes2,1));
+ fprintf(fp_ou,"<th></th><th></th><th></th>");
+ if((UserReportFields & USERREPORTFIELDS_USED_TIME) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",buildtime(totelap2));
+ if((UserReportFields & USERREPORTFIELDS_MILISEC) != 0)
+ fprintf(fp_ou,"<th class=\"header_r\">%s</th>",fixnum2(totelap2,1));
+ if((UserReportFields & USERREPORTFIELDS_PTIME) != 0) {
+ perc2 = (totelap) ? totelap2 * 100. / totelap : 0.;
+ fprintf(fp_ou,"<th class=\"header_r\">%3.2lf%%</th>",perc2);
+ }
+ fputs("</tr>\n",fp_ou);
+ }
+
+ if ((UserReportFields & (USERREPORTFIELDS_TOTAL | USERREPORTFIELDS_AVERAGE)) != 0)
+ fputs("</tfoot>",fp_ou);
+
+ fputs("</table></div>\n",fp_ou);
+ if (write_html_trailer(fp_ou)<0)
+ debuga(_("Write error in file \"%s\"\n"),arqou);
+ if (fclose(fp_ou)==EOF)
+ debuga(_("Failed to close file \"%s\": %s\n"),arqou,strerror(errno));
+
+ htaccess(uinfo);
+ }
+
+ userinfo_stopscan(uscan);
+
+ return;
}