]>
git.ipfire.org Git - thirdparty/sarg.git/blob - squidguard_report.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
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.
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.
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.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 void squidguard_report(void)
33 FILE *fp_in
= NULL
, *fp_ou
= NULL
;
37 char squidguard_in
[MAXLEN
];
52 struct getwordstruct gwarea
;
53 const struct userinfostruct
*uinfo
;
60 sprintf(squidguard_in
,"%s/redirector.log",tmp
);
61 if(!squidguard_count
) {
62 unlink(squidguard_in
);
66 snprintf(report
,sizeof(report
),"%s/redirector.html",outdirname
);
68 if((fp_in
=fopen(squidguard_in
,"r"))==NULL
) {
69 debuga(_("(squidguard) Cannot open log file %s\n"),squidguard_in
);
73 if((fp_ou
=fopen(report
,"w"))==NULL
) {
74 debuga(_("(squidguard) Cannot open log file %s\n"),report
);
78 if ((line
=longline_create())==NULL
) {
79 debuga(_("Not enough memory to read the processed redirector log\n"));
83 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("Redirector report"));
84 fputs("<tr><td class=\"header_c\">",fp_ou
);
85 fprintf(fp_ou
,_("Period: %s"),period
.html
);
86 fputs("</td></tr>\n",fp_ou
);
87 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("Redirector report"));
88 close_html_header(fp_ou
);
90 fputs("<div class=\"report\"><table cellpadding=1 cellspacing=2>\n",fp_ou
);
91 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"));
93 while((buf
=longline_read(fp_in
,line
))!=NULL
) {
94 getword_start(&gwarea
,buf
);
95 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0) {
96 debuga(_("Invalid user in file %s\n"),squidguard_in
);
99 if (getword_atoll(&data2
,&gwarea
,'\t')<0) {
100 debuga(_("Invalid date in file %s\n"),squidguard_in
);
103 if (getword(hora
,sizeof(hora
),&gwarea
,'\t')<0) {
104 debuga(_("Invalid time in file %s\n"),squidguard_in
);
107 if (getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
108 debuga(_("Invalid IP address in file %s\n"),squidguard_in
);
111 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
112 debuga(_("Invalid URL in file %s\n"),squidguard_in
);
115 if (getword(rule
,sizeof(rule
),&gwarea
,'\n')<0) {
116 debuga(_("Invalid rule in file %s\n"),squidguard_in
);
120 uinfo
=userinfo_find_from_id(user
);
122 debuga(_("Unknown user ID %s in file %s\n"),user
,squidguard_in
);
126 computedate(data2
/10000,(data2
/100)%10,data2
%100,&t
);
127 strftime(data
,sizeof(data
),"%x",&t
);
134 if (Ip2Name
&& !uinfo
->id_is_ip
) ip2name(oname
,sizeof(oname
));
138 if(strcmp(ouser
,user
) != 0) {
142 if(strcmp(oip
,ip
) != 0) {
145 if (Ip2Name
&& !uinfo
->id_is_ip
) ip2name(oname
,sizeof(oname
));
150 if(SquidGuardReportLimit
) {
151 if(strcmp(ouser2
,uinfo
->label
) == 0) {
155 strcpy(ouser2
,uinfo
->label
);
157 if(count
>= SquidGuardReportLimit
)
162 fprintf(fp_ou
,"<tr><td class=\"data2\">%s</td><td class=\"data2\">%s</td>",uinfo
->label
,ip
);
164 fputs("<tr><td class=\"data2\"></td><td class=\"data2\"></td>",fp_ou
);
165 fprintf(fp_ou
,"<td class=\"data2\">%s-%s</td><td class=\"data2\"><a href=\"http://",data
,hora
);
166 output_html_url(fp_ou
,url
);
168 output_html_string(fp_ou
,url
,100);
169 fprintf(fp_ou
,"</a></td><td class=\"data2\">%s</td></th>\n",rule
);
172 longline_destroy(&line
);
174 fputs("</table></div>\n",fp_ou
);
175 if (write_html_trailer(fp_ou
)<0)
176 debuga(_("Write error in file %s\n"),report
);
177 if (fclose(fp_ou
)==EOF
)
178 debuga(_("Failed to close file %s - %s\n"),report
,strerror(errno
));
180 unlink(squidguard_in
);