"Fossies" - the Fresh Open Source Software Archive  

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

About: SARG ia a Squid Analysis Report Generator.

siteuser.c  (sarg-2.3.11):siteuser.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 32 skipping to change at line 32
* 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"
void siteuser(void) void siteuser(void)
{ {
FILE *fp_in, *fp_ou; FileObject *fp_in;
FILE *fp_ou;
char *buf; char *buf;
char *ourl; char *ourl;
char csort[4096]; char csort[4096];
char general[MAXLEN]; char general[MAXLEN];
char general2[MAXLEN]; char general2[MAXLEN];
char sites[MAXLEN]; char sites[MAXLEN];
char report[MAXLEN]; char report[MAXLEN];
int regs=0; int regs=0;
int ourl_size; int ourl_size;
int url_len; int url_len;
int topuser_link; int topuser_link;
int nsitesusers; int nsitesusers;
int cstatus; int cstatus;
longline line; longline line;
struct generalitemstruct item; struct generalitemstruct item;
struct userinfostruct *uinfo; struct userinfostruct *uinfo;
if(Privacy) { if (Privacy) {
if (debugz) debugaz(_("Sites and users report not generated becau if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Sites
se privacy option is on\n")); & users report not generated because privacy option is on\n"));
return; return;
} }
if (debugz>=LogLevel_Process)
debuga(__FILE__,__LINE__,_("Creating report to list who visisted
what site...\n"));
nsitesusers = 0; nsitesusers = 0;
sprintf(general,"%s/sarg-general",outdirname); format_path(__FILE__, __LINE__, general, sizeof(general), "%s/sarg-genera
sprintf(sites,"%s/sarg-sites",outdirname); l", outdirname);
sprintf(general2,"%s/sarg-general2",outdirname); format_path(__FILE__, __LINE__, sites, sizeof(sites), "%s/sarg-sites", ou
sprintf(report,"%s/siteuser.html",outdirname); tdirname);
format_path(__FILE__, __LINE__, general2, sizeof(general2), "%s/sarg-gene
ral2", outdirname);
format_path(__FILE__, __LINE__, report, sizeof(report), "%s/siteuser.html
", outdirname);
if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) { if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) {
debuga(_("Command too long: ")); debuga(__FILE__,__LINE__,_("Sort command too long when sorting fi
debuga_more("sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",gener le \"%s\" to \"%s\"\n"),general,general2);
al2,general);
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"),WEXITSTATUS(cstatus)) debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEX
; ITSTATUS(cstatus));
debuga(_("sort command: %s\n"),csort); debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((fp_in=fopen(general2,"r"))==NULL) { if ((fp_in=FileObject_Open(general2))==NULL) {
debugapos("siteuser",_("Cannot open file \"%s\": %s\n"),general2, debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),gener
strerror(errno)); al2,FileObject_GetLastOpenError());
debuga(_("sort command: %s\n"),csort); debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((fp_ou=fopen(report,"w"))==NULL) { if ((fp_ou=fopen(report,"w"))==NULL) {
debugapos("siteuser",_("Cannot open file \"%s\": %s\n"),report,st debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),repor
rerror(errno)); t,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Sites & Users"),HTML_JS_SORTTABLE); write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Sites & Users"),HTML_JS_SORTTABLE);
fputs("<tr><td class=\"header_c\">",fp_ou); fputs("<tr><td class=\"header_c\">",fp_ou);
fprintf(fp_ou,_("Period: %s"),period.html); fprintf(fp_ou,_("Period: %s"),period.html);
fputs("</td></tr>\n",fp_ou); fputs("</td></tr>\n",fp_ou);
fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & User s")); fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Sites & User s"));
close_html_header(fp_ou); close_html_header(fp_ou);
fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\"", fp_ou); fputs("<div class=\"report\"><table cellpadding=\"0\" cellspacing=\"2\"", fp_ou);
if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou); if (SortTableJs[0]) fputs(" class=\"sortable\"",fp_ou);
fprintf(fp_ou,">\n<thead><tr><th class=\"header_l\">%s</th><th class=\"he ader_l",_("NUM")); fprintf(fp_ou,">\n<thead><tr><th class=\"header_l\">%s</th><th class=\"he ader_l",_("NUM"));
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(BytesInSitesUsersReport) if (BytesInSitesUsersReport)
fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES")); fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
fputs("<th class=\"header_l",fp_ou); fputs("<th class=\"header_l",fp_ou);
if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou); if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
/* TRANSLATORS: This is a column header showing the users who visited eac h site. */ /* TRANSLATORS: This is a column header showing the users who visited eac h site. */
fprintf(fp_ou,"\">%s</th></tr></thead>\n",_("USERS")); fprintf(fp_ou,"\">%s</th></tr></thead>\n",_("USERS"));
ourl=NULL; ourl=NULL;
ourl_size=0; ourl_size=0;
userinfo_clearflag(); userinfo_clearflag();
topuser_link=((ReportType & REPORT_TYPE_USERS_SITES) != 0 && !indexonly); topuser_link=((ReportType & REPORT_TYPE_USERS_SITES) != 0 && !indexonly);
if ((line=longline_create())==NULL) { if ((line=longline_create())==NULL) {
debuga(_("Not enough memory to read file \"%s\"\n"),general2); debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\" \n"),general2);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while((buf=longline_read(fp_in,line))!=NULL) { while((buf=longline_read(fp_in,line))!=NULL) {
ger_read(buf,&item,general2); ger_read(buf,&item,general2);
if(item.total) continue; if (item.total) continue;
uinfo=userinfo_find_from_id(item.user); uinfo=userinfo_find_from_id(item.user);
if (!uinfo) { if (!uinfo) {
debuga(_("Unknown user ID %s in file \"%s\"\n"),item.user ,general2); debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \" %s\"\n"),item.user,general2);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (item.nacc > 0) nsitesusers = 1; if (item.nacc > 0) nsitesusers = 1;
if (!nsitesusers) continue; if (!nsitesusers) continue;
if (ourl==NULL || strcmp(item.url,ourl) != 0) { if (ourl==NULL || strcmp(item.url,ourl) != 0) {
if (regs>0) fputs("</td></tr>\n",fp_ou); if (regs>0) fputs("</td></tr>\n",fp_ou);
regs++; regs++;
if (SiteUsersReportLimit && regs >= SiteUsersReportLimit) if (SiteUsersReportLimit && regs >= SiteUsersReportLimit)
break; break;
fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\" data2\">",regs); fprintf(fp_ou,"<tr><td class=\"data\">%d</td><td class=\" data2\">",regs);
url_len=strlen(item.url); url_len=strlen(item.url);
if (url_len>=ourl_size) { if (url_len>=ourl_size) {
ourl_size=url_len+1; ourl_size=url_len+1;
ourl=realloc(ourl,ourl_size); ourl=realloc(ourl,ourl_size);
if (!ourl) { if (!ourl) {
debuga(_("Not enough memory to store the url\n")); debuga(__FILE__,__LINE__,_("Not enough me mory to store the url\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
strcpy(ourl,item.url); strcpy(ourl,item.url);
if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) { if (BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRo ot,BlockIt); fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRo ot,BlockIt);
output_html_url(fp_ou,ourl); output_html_url(fp_ou,ourl);
fputs("\"><img src=\"../images/sarg-squidguard-bl ock.png\"></a>&nbsp;",fp_ou); fputs("\"><img src=\"../images/sarg-squidguard-bl ock.png\"></a>&nbsp;",fp_ou);
} }
output_html_link(fp_ou,ourl,100); output_html_link(fp_ou,ourl,100);
fputs("</td>",fp_ou); fputs("</td>",fp_ou);
if (BytesInSitesUsersReport) { if (BytesInSitesUsersReport) {
fputs("<td class=\"data\"",fp_ou); fputs("<td class=\"data\"",fp_ou);
if (SortTableJs[0]) fprintf(fp_ou," sorttable_cus tomkey=\"%"PRId64"\"",(int64_t)item.nbytes); if (SortTableJs[0]) fprintf(fp_ou," sorttable_cus tomkey=\"%"PRId64"\"",(int64_t)item.nbytes);
skipping to change at line 177 skipping to change at line 179
} }
else if (uinfo->flag==0) { else if (uinfo->flag==0) {
if (topuser_link && uinfo->topuser) if (topuser_link && uinfo->topuser)
fprintf(fp_ou," <a href=\"%s/%s.html\">%s</a>",ui nfo->filename,uinfo->filename,uinfo->label); fprintf(fp_ou," <a href=\"%s/%s.html\">%s</a>",ui nfo->filename,uinfo->filename,uinfo->label);
else else
fprintf(fp_ou," %s",uinfo->label); fprintf(fp_ou," %s",uinfo->label);
uinfo->flag=1; uinfo->flag=1;
} }
} }
fclose(fp_in); if (FileObject_Close(fp_in)) {
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),general2
,FileObject_GetLastCloseError());
exit(EXIT_FAILURE);
}
longline_destroy(&line); longline_destroy(&line);
if(regs>0) { if (regs>0) {
fputs("</td></tr>\n",fp_ou); fputs("</td></tr>\n",fp_ou);
} }
if (ourl) free(ourl); if (ourl) free(ourl);
if (!KeepTempLog && unlink(general2)) { if (!KeepTempLog && unlink(general2)) {
debuga(_("Cannot delete \"%s\": %s\n"),general2,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),general2 ,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
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"),report); if (fclose(fp_ou)==EOF) {
if (fclose(fp_ou)==EOF) debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),report,
debuga(_("Failed to close file \"%s\": %s\n"),report,strerror(err strerror(errno));
no)); exit(EXIT_FAILURE);
}
return; return;
} }
 End of changes. 19 change blocks. 
36 lines changed or deleted 48 lines changed or added

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