dansguardian_report.c (sarg-2.3.11) | : | dansguardian_report.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 61 | skipping to change at line 61 | |||
char date[15]; | char date[15]; | |||
char date2[15]; | char date2[15]; | |||
char hour[15]; | char hour[15]; | |||
char ouser2[255]; | char ouser2[255]; | |||
int z=0; | int z=0; | |||
int count=0; | int count=0; | |||
struct getwordstruct gwarea; | struct getwordstruct gwarea; | |||
ouser[0]='\0'; | ouser[0]='\0'; | |||
snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.int_log | format_path(__FILE__, __LINE__, dansguardian_in, sizeof(dansguardian_in), | |||
",tmp); | "%s/dansguardian.int_log", tmp); | |||
if(!dansguardian_count) { | if (!dansguardian_count) { | |||
if (!KeepTempLog && unlink(dansguardian_in)) | if (!KeepTempLog && unlink(dansguardian_in)) | |||
debuga(_("Cannot delete \"%s\": %s\n"),dansguardian_in,st | debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"), | |||
rerror(errno)); | dansguardian_in,strerror(errno)); | |||
if (debugz) debugaz(_("Dansguardian report not generated because | if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Dansgu | |||
it is empty\n")); | ardian report not generated because it is empty\n")); | |||
return; | return; | |||
} | } | |||
sprintf(report,"%s/dansguardian.html",outdirname); | format_path(__FILE__, __LINE__, report, sizeof(report), "%s/dansguardian. html", outdirname); | |||
if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) { | if ((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) { | |||
debugapos("dansguardian_report",_("Cannot open file \"%s\": %s\n" | debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),dansg | |||
),dansguardian_in,strerror(errno)); | uardian_in,strerror(errno)); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
if((fp_ou=MY_FOPEN(report,"w"))==NULL) { | if ((fp_ou=MY_FOPEN(report,"w"))==NULL) { | |||
debugapos("dansguardian_report",_("Cannot open file \"%s\": %s\n" | debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),repor | |||
),report,strerror(errno)); | t,strerror(errno)); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGua rdian"),HTML_JS_NONE); | write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGua rdian"),HTML_JS_NONE); | |||
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",_("DansGuardian ")); | fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("DansGuardian ")); | |||
close_html_header(fp_ou); | close_html_header(fp_ou); | |||
fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\ n",fp_ou); | fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\ n",fp_ou); | |||
fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">% s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"he ader_l\">%s</th></tr>\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SIT E"),_("CAUSE")); | fprintf(fp_ou,"<tr><th class=\"header_l\">%s</th><th class=\"header_l\">% s</th><th class=\"header_l\">%s</th><th class=\"header_l\">%s</th><th class=\"he ader_l\">%s</th></tr>\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SIT E"),_("CAUSE")); | |||
while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | while(fgets(buf,sizeof(buf),fp_in)!=NULL) { | |||
getword_start(&gwarea,buf); | getword_start(&gwarea,buf); | |||
if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,si zeof(date2),&gwarea,'\t')<0 || | if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,si zeof(date2),&gwarea,'\t')<0 || | |||
getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeo f(ip),&gwarea,'\t')<0) { | getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeo f(ip),&gwarea,'\t')<0) { | |||
debuga(_("Invalid record in file \"%s\"\n"),dansguardian_ in); | debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\" \n"),dansguardian_in); | |||
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"),dansguardian_in) ; | debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n" ),dansguardian_in); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
if (getword(rule,sizeof(rule),&gwarea,'\n')<0) { | if (getword(rule,sizeof(rule),&gwarea,'\n')<0) { | |||
debuga(_("Invalid rule in file \"%s\"\n"),dansguardian_in ); | debuga(__FILE__,__LINE__,_("Invalid rule in file \"%s\"\n "),dansguardian_in); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
if(UserIp) | if (UserIp) | |||
strcpy(user,ip); | strcpy(user,ip); | |||
bzero(date, 15); | memset(date,0,sizeof(date)); | |||
if(strncmp(df,"u",1) != 0) { | if (df!='u') { | |||
strncpy(date,date2+6,2); | strncpy(date,date2+6,2); | |||
strcat(date,"/"); | strcat(date,"/"); | |||
strncat(date,date2+4,2); | strncat(date,date2+4,2); | |||
strcat(date,"/"); | strcat(date,"/"); | |||
strncat(date,date2,4); | strncat(date,date2,4); | |||
} else { | } else { | |||
strncpy(date,date2+4,2); | strncpy(date,date2+4,2); | |||
strcat(date,"/"); | strcat(date,"/"); | |||
strncat(date,date2+6,2); | strncat(date,date2+6,2); | |||
strcat(date,"/"); | strcat(date,"/"); | |||
strncat(date,date2,4); | strncat(date,date2,4); | |||
} | } | |||
if(Ip2Name) | if (Ip2Name) | |||
ip2name(ip,sizeof(ip)); | ip2name(ip,sizeof(ip)); | |||
if(!z) { | if (!z) { | |||
strcpy(ouser,user); | strcpy(ouser,user); | |||
strcpy(oip,ip); | strcpy(oip,ip); | |||
z++; | z++; | |||
} else { | } else { | |||
if(strcmp(ouser,user) == 0) | if (strcmp(ouser,user) == 0) | |||
user[0]='\0'; | user[0]='\0'; | |||
if(user[0] != '\0') | if (user[0] != '\0') | |||
strcpy(ouser,user); | strcpy(ouser,user); | |||
if(strcmp(oip,ip) == 0) | if (strcmp(oip,ip) == 0) | |||
ip[0]='\0'; | ip[0]='\0'; | |||
if(ip[0] != '\0') | if (ip[0] != '\0') | |||
strcpy(oip,ip); | strcpy(oip,ip); | |||
} | } | |||
user_find(name, sizeof(name), user); | user_find(name, sizeof(name), user); | |||
if(DansGuardianReportLimit) { | if (DansGuardianReportLimit) { | |||
if(strcmp(ouser2,name) == 0) { | if (strcmp(ouser2,name) == 0) { | |||
count++; | count++; | |||
} else { | } else { | |||
if(count>DansGuardianReportLimit && DansGuardianR eportLimit>0) | if (count>DansGuardianReportLimit && DansGuardian ReportLimit>0) | |||
show_ignored_dansguardian(fp_ou,count-Dan sGuardianReportLimit); | show_ignored_dansguardian(fp_ou,count-Dan sGuardianReportLimit); | |||
count=1; | count=1; | |||
strcpy(ouser2,name); | strcpy(ouser2,name); | |||
} | } | |||
if(count > DansGuardianReportLimit) | if (count > DansGuardianReportLimit) | |||
continue; | continue; | |||
} | } | |||
fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\" >%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",name,ip,date,hour); | fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\" >%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\">",name,ip,date,hour); | |||
output_html_link(fp_ou,url,100); | output_html_link(fp_ou,url,100); | |||
fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule); | fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule); | |||
} | } | |||
fclose(fp_in); | if (fclose(fp_in)==EOF) { | |||
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),dansguar | ||||
dian_in,strerror(errno)); | ||||
exit(EXIT_FAILURE); | ||||
} | ||||
if(count>DansGuardianReportLimit && DansGuardianReportLimit>0) | if (count>DansGuardianReportLimit && DansGuardianReportLimit>0) | |||
show_ignored_dansguardian(fp_ou,count-DansGuardianReportLimit); | show_ignored_dansguardian(fp_ou,count-DansGuardianReportLimit); | |||
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); | |||
} | ||||
if (!KeepTempLog && unlink(dansguardian_in)) { | if (!KeepTempLog && unlink(dansguardian_in)) { | |||
debuga(_("Cannot delete \"%s\": %s\n"),dansguardian_in,strerror(e rrno)); | debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),dansguar dian_in,strerror(errno)); | |||
exit(EXIT_FAILURE); | exit(EXIT_FAILURE); | |||
} | } | |||
return; | return; | |||
} | } | |||
End of changes. 24 change blocks. | ||||
39 lines changed or deleted | 44 lines changed or added |