]> git.ipfire.org Git - thirdparty/sarg.git/blame - squidguard_report.c
Use a lower case message and avoid the extra processing
[thirdparty/sarg.git] / squidguard_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 squidguard_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 squidguard_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 data[15];
45 char data2[15];
46 char hora[15];
06b39c87 47 char ouser2[255];
987e8375
FM
48 char oname[MAXLEN];
49 bool z=false;
25697a35 50 int count=0;
987e8375 51 bool new_user;
9c7c6346 52 struct getwordstruct gwarea;
987e8375 53 const struct userinfostruct *uinfo;
25697a35
GS
54
55 ouser[0]='\0';
56
987e8375 57 sprintf(squidguard_in,"%s/redirector.log",tmp);
25697a35
GS
58 if(!squidguard_count) {
59 unlink(squidguard_in);
60 return;
61 }
62
987e8375 63 snprintf(report,sizeof(report),"%s/redirector.html",outdirname);
25697a35 64
25697a35 65 if((fp_in=fopen(squidguard_in,"r"))==NULL) {
fcdc0918 66 debuga(_("(squidguard) Cannot open log file %s\n"),squidguard_in);
06b39c87 67 exit(EXIT_FAILURE);
25697a35
GS
68 }
69
70 if((fp_ou=fopen(report,"w"))==NULL) {
fcdc0918 71 debuga(_("(squidguard) Cannot open log file %s\n"),report);
06b39c87 72 exit(EXIT_FAILURE);
25697a35
GS
73 }
74
987e8375 75 write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 3 : 1,_("Redirector report"));
94558017 76 fputs("<tr><td class=\"header_c\">",fp_ou);
fd46f082 77 fprintf(fp_ou,_("Period: %s"),period.html);
fa6552b0 78 fputs("</td></tr>\n",fp_ou);
987e8375 79 fprintf(fp_ou,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Redirector report"));
c0ec9cc7 80 close_html_header(fp_ou);
25697a35 81
c0ec9cc7 82 fputs("<div class=\"report\"><table cellpadding=1 cellspacing=2>\n",fp_ou);
c36c7384 83 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"),_("RULE"));
25697a35
GS
84
85 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
9c7c6346
FM
86 getword_start(&gwarea,buf);
87 if (getword(user,sizeof(user),&gwarea,'\t')<0 || getword(data2,sizeof(data2),&gwarea,'\t')<0 ||
e5b2c6f0 88 getword(hora,sizeof(hora),&gwarea,'\t')<0 || getword(ip,sizeof(ip),&gwarea,'\t')<0) {
10210234 89 debuga(_("There is a broken record or garbage in file %s\n"),squidguard_in);
06b39c87 90 exit(EXIT_FAILURE);
e5b2c6f0
FM
91 }
92 if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
10210234 93 debuga(_("There is a broken url in file %s\n"),squidguard_in);
06b39c87 94 exit(EXIT_FAILURE);
e5b2c6f0
FM
95 }
96 if (getword(rule,sizeof(rule),&gwarea,'\n')<0) {
10210234 97 debuga(_("There is a broken rule in file %s\n"),squidguard_in);
06b39c87 98 exit(EXIT_FAILURE);
4bcb77cf 99 }
25697a35 100
987e8375
FM
101 uinfo=userinfo_find_from_id(user);
102 if (!uinfo) {
103 debuga(_("Unknown user ID %s in file %s\n"),user,squidguard_in);
104 exit(EXIT_FAILURE);
105 }
25697a35
GS
106
107 bzero(data, 15);
987e8375 108 if(df[0] == 'u') {
25697a35
GS
109 strncpy(data,data2+6,2);
110 strcat(data,"/");
111 strncat(data,data2+4,2);
112 strcat(data,"/");
113 strncat(data,data2,4);
114 } else {
115 strncpy(data,data2+4,2);
116 strcat(data,"/");
117 strncat(data,data2+6,2);
118 strcat(data,"/");
119 strncat(data,data2,4);
120 }
121
987e8375 122 new_user=false;
25697a35
GS
123 if(!z) {
124 strcpy(ouser,user);
125 strcpy(oip,ip);
987e8375
FM
126 strcpy(oname,ip);
127 if (Ip2Name && !uinfo->id_is_ip) ip2name(oname,sizeof(oname));
128 z=true;
129 new_user=true;
25697a35 130 } else {
987e8375 131 if(strcmp(ouser,user) != 0) {
25697a35 132 strcpy(ouser,user);
987e8375
FM
133 new_user=true;
134 }
135 if(strcmp(oip,ip) != 0) {
25697a35 136 strcpy(oip,ip);
987e8375
FM
137 strcpy(oname,ip);
138 if (Ip2Name && !uinfo->id_is_ip) ip2name(oname,sizeof(oname));
139 new_user=true;
140 }
25697a35
GS
141 }
142
987e8375
FM
143 if(SquidGuardReportLimit) {
144 if(strcmp(ouser2,uinfo->label) == 0) {
25697a35
GS
145 count++;
146 } else {
147 count=1;
987e8375 148 strcpy(ouser2,uinfo->label);
25697a35
GS
149 }
150 if(count >= SquidGuardReportLimit)
151 continue;
152 }
153
987e8375
FM
154 if (new_user)
155 fprintf(fp_ou,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo->label,ip);
156 else
157 fputs("<tr><td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou);
158 fprintf(fp_ou,"<td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",data,hora);
e5b2c6f0
FM
159 output_html_url(fp_ou,url);
160 fputs("\">",fp_ou);
161 output_html_string(fp_ou,url,100);
162 fprintf(fp_ou,"</a></td><td class=\"data2\">%s</td></th>\n",rule);
25697a35 163 }
25697a35 164 fclose(fp_in);
c0ec9cc7
FM
165
166 fputs("</table></div>\n",fp_ou);
fa6552b0
FM
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));
25697a35
GS
171
172 unlink(squidguard_in);
173
174 return;
175}