]> git.ipfire.org Git - thirdparty/sarg.git/blame - dansguardian_report.c
Output the period as an HTML text in the HTML reports
[thirdparty/sarg.git] / dansguardian_report.c
CommitLineData
25697a35 1/*
94ff9470 2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
1164c474 3 * 1998, 2010
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
32e71fa4 30void dansguardian_report(void)
25697a35
GS
31{
32
33 FILE *fp_in = NULL, *fp_ou = NULL;
120d768c 34
06b39c87 35 char buf[MAXLEN];
e5b2c6f0 36 char *url;
25697a35 37 char dansguardian_in[MAXLEN];
25697a35 38 char report[MAXLEN];
25697a35
GS
39 char ip[MAXLEN];
40 char rule[255];
41 char oip[MAXLEN];
42 char user[MAXLEN];
43 char ouser[MAXLEN];
44 char date[15];
45 char date2[15];
46 char hour[15];
06b39c87 47 char ouser2[255];
25697a35
GS
48 int z=0;
49 int count=0;
9c7c6346 50 struct getwordstruct gwarea;
25697a35
GS
51
52 ouser[0]='\0';
53
06b39c87 54 snprintf(dansguardian_in,sizeof(dansguardian_in),"%s/dansguardian.log",tmp);
25697a35
GS
55 if(!dansguardian_count) {
56 unlink(dansguardian_in);
57 return;
58 }
59
d5d021c5 60 sprintf(report,"%s/dansguardian.html",outdirname);
25697a35 61
936c9905 62 if((fp_in=MY_FOPEN(dansguardian_in,"r"))==NULL) {
bc877ad2 63 debuga(_("(dansguardian_report) Cannot open log file %s\n"),dansguardian_in);
06b39c87 64 exit(EXIT_FAILURE);
25697a35
GS
65 }
66
936c9905 67 if((fp_ou=MY_FOPEN(report,"w"))==NULL) {
bc877ad2 68 debuga(_("(dansguardian_report) Cannot open log file %s\n"),report);
06b39c87 69 exit(EXIT_FAILURE);
25697a35
GS
70 }
71
c0ec9cc7 72 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("DansGuardian"));
fa6552b0 73 fputs("<tr><td class=\"header_l\">",fp_ou);
fd46f082 74 fprintf(fp_ou,_("Period: %s"),period.html);
fa6552b0 75 fputs("</td></tr>\n",fp_ou);
c36c7384 76 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("DansGuardian"));
c0ec9cc7 77 close_html_header(fp_ou);
25697a35 78
c0ec9cc7 79 fputs("<div class=\"report\"><table cellpadding=\"1\" cellspacing=\"2\">\n",fp_ou);
25697a35 80 fputs("<tr><td></td></tr>\n",fp_ou);
c36c7384 81 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"));
25697a35
GS
82
83 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
84 getword_start(&gwarea,buf);
85 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(date2,sizeof(date2),&gwarea,'\t')<0 ||
e5b2c6f0 86 getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
10210234 87 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),dansguardian_in);
06b39c87 88 exit(EXIT_FAILURE);
e5b2c6f0
FM
89 }
90 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
10210234 91 debuga(_("Maybe you have a broken url in your %s file\n"),dansguardian_in);
06b39c87 92 exit(EXIT_FAILURE);
e5b2c6f0
FM
93 }
94 if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
10210234 95 debuga(_("Maybe you have a broken rule in your %s file\n"),dansguardian_in);
06b39c87 96 exit(EXIT_FAILURE);
4bcb77cf 97 }
25697a35 98
246c8489 99 if(UserIp)
25697a35
GS
100 strcpy(user,ip);
101
102 bzero(date, 15);
103 if(strncmp(df,"u",1) != 0) {
104 strncpy(date,date2+6,2);
105 strcat(date,"/");
106 strncat(date,date2+4,2);
107 strcat(date,"/");
108 strncat(date,date2,4);
109 } else {
110 strncpy(date,date2+4,2);
111 strcat(date,"/");
112 strncat(date,date2+6,2);
113 strcat(date,"/");
114 strncat(date,date2,4);
115 }
116
246c8489 117 if(Ip2Name)
a1c55d8c 118 ip2name(ip,sizeof(ip));
25697a35
GS
119
120 if(!z) {
121 strcpy(ouser,user);
122 strcpy(oip,ip);
123 z++;
124 } else {
125 if(strcmp(ouser,user) == 0)
126 user[0]='\0';
127 if(user[0] != '\0')
128 strcpy(ouser,user);
120d768c 129 if(strcmp(oip,ip) == 0)
25697a35
GS
130 ip[0]='\0';
131 if(ip[0] != '\0')
132 strcpy(oip,ip);
133 }
134
965c4a6f 135 user_find(name, sizeof(name), user);
25697a35
GS
136
137 if(DansGuardianReportLimit) {
138 if(strcmp(ouser2,name) == 0) {
139 count++;
140 } else {
141 count=1;
142 strcpy(ouser2,name);
143 }
144 if(count >= DansGuardianReportLimit)
145 continue;
146 }
147
543b3b89 148 fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td><td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",name,ip,date,hour);
e5b2c6f0
FM
149 output_html_url(fp_ou,url);
150 fputs("\">",fp_ou);
151 output_html_string(fp_ou,url,100);
543b3b89 152 fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></tr>\n",rule);
25697a35 153 }
25697a35 154 fclose(fp_in);
c0ec9cc7
FM
155
156 fputs("</table></div>\n",fp_ou);
fa6552b0
FM
157 if (write_html_trailer(fp_ou)<0)
158 debuga(_("Write error in file %s\n"),report);
159 if (fclose(fp_ou)==EOF)
160 debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
25697a35
GS
161
162 unlink(dansguardian_in);
163
164 return;
165}