]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
Update po files
[thirdparty/sarg.git] / dansguardian_report.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
61d965f3 3 * 1998, 2012
25697a35
GS
4 *
5 * SARG donations:
6 * please look at http://sarg.sourceforge.net/donations.php
1164c474
FM
7 * Support:
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
25697a35
GS
9 * ---------------------------------------------------------------------
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
24 *
25 */
26
27#include "include/conf.h"
5f3cfd1d 28#include "include/defs.h"
25697a35 29
7ae50eee
FM
30static void show_ignored_dansguardian(FILE *fp_ou,int count)
31{
32 char ignored[80];
33
34 snprintf(ignored,sizeof(ignored),ngettext("%d more dansguardian entry not shown here…","%d more dansguardian entries not shown here…",count),count);
35 fprintf(fp_ou,"<tr><td class=\"data\"></td><td class=\"data\"></td><td class=\"data\"></td><td class=\"data2 more\">%s</td><td class=\"data\"></td></tr>\n",ignored);
36}
37
32e71fa4 38void dansguardian_report(void)
25697a35 39{
9bd92830
FM
40 FILE *fp_in = NULL, *fp_ou = NULL;
41
42 char buf[MAXLEN];
43 char *url;
44 char dansguardian_in[MAXLEN];
45 char report[MAXLEN];
46 char ip[MAXLEN];
47 char rule[255];
48 char oip[MAXLEN];
49 char user[MAXLEN];
50 char ouser[MAXLEN];
51 char date[15];
52 char date2[15];
53 char hour[15];
54 char ouser2[255];
55 int z=0;
56 int count=0;
57 struct getwordstruct gwarea;
58
59 ouser[0]='\0';
60
c98d6a0f 61 snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.int_log",tmp);
9bd92830
FM
62 if(!dansguardian_count) {
63 unlink(dansguardian_in);
9f93fec3 64 if (debugz) debugaz(_("Dansguardian report not generated because it is empty\n"));
9bd92830
FM
65 return;
66 }
67
68 sprintf(report,"%s/dansguardian.html",outdirname);
69
70 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
007905af
FM
71 debuga(_("(dansguardian_report) Cannot open log file %s\n"),dansguardian_in);
72 exit(EXIT_FAILURE);
9bd92830
FM
73 }
74
75 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
007905af
FM
76 debuga(_("(dansguardian_report) Cannot open log file %s\n"),report);
77 exit(EXIT_FAILURE);
9bd92830
FM
78 }
79
80 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian"),HTML_JS_NONE);
81 fputs("<tr><td class=\"header_c\">",fp_ou);
82 fprintf(fp_ou,_("Period: %s"),period.html);
83 fputs("</td></tr>\n",fp_ou);
84 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("DansGuardian"));
85 close_html_header(fp_ou);
86
87 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
88 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=\"header_l\">%s</th></tr>\n",_("USERID"),_("IP/NAME"),_("DATE/TIME"),_("ACCESSED SITE"),_("CAUSE"));
89
90 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
91 getword_start(&gwarea,buf);
92 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
007905af 93 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
9bd92830
FM
94 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),dansguardian_in);
95 exit(EXIT_FAILURE);
96 }
97 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
98 debuga(_("Maybe you have a broken url in your %s file\n"),dansguardian_in);
99 exit(EXIT_FAILURE);
100 }
101 if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
102 debuga(_("Maybe you have a broken rule in your %s file\n"),dansguardian_in);
103 exit(EXIT_FAILURE);
104 }
105
106 if(UserIp)
107 strcpy(user,ip);
108
109 bzero(date, 15);
110 if(strncmp(df,"u",1) != 0) {
111 strncpy(date,date2+6,2);
112 strcat(date,"/");
113 strncat(date,date2+4,2);
114 strcat(date,"/");
115 strncat(date,date2,4);
116 } else {
117 strncpy(date,date2+4,2);
118 strcat(date,"/");
119 strncat(date,date2+6,2);
120 strcat(date,"/");
121 strncat(date,date2,4);
122 }
123
124 if(Ip2Name)
125 ip2name(ip,sizeof(ip));
126
127 if(!z) {
128 strcpy(ouser,user);
129 strcpy(oip,ip);
130 z++;
131 } else {
132 if(strcmp(ouser,user) == 0)
133 user[0]='\0';
134 if(user[0] != '\0')
135 strcpy(ouser,user);
136 if(strcmp(oip,ip) == 0)
137 ip[0]='\0';
138 if(ip[0] != '\0')
139 strcpy(oip,ip);
140 }
141
142 user_find(name, sizeof(name), user);
143
007905af 144 if(DansGuardianReportLimit) {
9bd92830
FM
145 if(strcmp(ouser2,name) == 0) {
146 count++;
147 } else {
7ae50eee
FM
148 if(count>DansGuardianReportLimit && DansGuardianReportLimit>0)
149 show_ignored_dansguardian(fp_ou,count-DansGuardianReportLimit);
9bd92830
FM
150 count=1;
151 strcpy(ouser2,name);
152 }
7ae50eee 153 if(count > DansGuardianReportLimit)
9bd92830
FM
154 continue;
155 }
156
67a93701 157 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);
6fa33a32 158 output_html_link(fp_ou,url,100);
67a93701 159 fprintf(fp_ou,"</td><td class=\"data2\">%s</td></tr>\n",rule);
9bd92830
FM
160 }
161 fclose(fp_in);
162
7ae50eee
FM
163 if(count>DansGuardianReportLimit && DansGuardianReportLimit>0)
164 show_ignored_dansguardian(fp_ou,count-DansGuardianReportLimit);
165
9bd92830
FM
166 fputs("</table></div>\n",fp_ou);
167 if (write_html_trailer(fp_ou)<0)
168 debuga(_("Write error in file %s\n"),report);
169 if (fclose(fp_ou)==EOF)
170 debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
171
08f9b029
FM
172 if (unlink(dansguardian_in)) {
173 debuga(_("Cannot delete %s - %s\n"),dansguardian_in,strerror(errno));
174 exit(EXIT_FAILURE);
175 }
9bd92830
FM
176
177 return;
25697a35 178}