]>
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
;
56 sprintf(squidguard_in
,"%s/squidguard.log",tmp
);
57 if(!squidguard_count
) {
58 unlink(squidguard_in
);
62 snprintf(per
,sizeof(per
),"%s/sarg-period",outdirname
);
63 snprintf(report
,sizeof(report
),"%s/squidguard.html",outdirname
);
65 if ((fp_in
= fopen(per
, "r")) == 0) {
66 debuga(_("(squidguard) Cannot open file %s\n"),per
);
70 if (!fgets(period
,sizeof(period
),fp_in
)) {
71 debuga(_("(squidguard) read error in %s\n"),per
);
76 if((fp_in
=fopen(squidguard_in
,"r"))==NULL
) {
77 debuga(_("(squidguard) Cannot open log file %s\n"),squidguard_in
);
81 if((fp_ou
=fopen(report
,"w"))==NULL
) {
82 debuga(_("(squidguard) Cannot open log file %s\n"),report
);
86 write_html_header(fp_ou
,(IndexTree
== INDEX_TREE_DATE
) ? 3 : 1,_("SQUIDGUARD"));
87 fprintf(fp_ou
,"<tr><td class=\"header_l\">%s: %s</td></tr>\n",_("Period"),period
);
88 fprintf(fp_ou
,"<tr><th class=\"header_c\">%s</th></tr>\n",_("SQUIDGUARD"));
89 close_html_header(fp_ou
);
91 fputs("<div class=\"report\"><table cellpadding=1 cellspacing=2>\n",fp_ou
);
92 fputs("<tr><td></td></tr>\n",fp_ou
);
93 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"));
95 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
96 getword_start(&gwarea
,buf
);
97 if (getword(user
,sizeof(user
),&gwarea
,'\t')<0 || getword(data2
,sizeof(data2
),&gwarea
,'\t')<0 ||
98 getword(hora
,sizeof(hora
),&gwarea
,'\t')<0 || getword(ip
,sizeof(ip
),&gwarea
,'\t')<0) {
99 debuga(_("There is a broken record or garbage in file %s\n"),squidguard_in
);
102 if (getword_ptr(buf
,&url
,&gwarea
,'\t')<0) {
103 debuga(_("There is a broken url in file %s\n"),squidguard_in
);
106 if (getword(rule
,sizeof(rule
),&gwarea
,'\n')<0) {
107 debuga(_("There is a broken rule in file %s\n"),squidguard_in
);
115 if(strncmp(df
,"u",1) != 0) {
116 strncpy(data
,data2
+6,2);
118 strncat(data
,data2
+4,2);
120 strncat(data
,data2
,4);
122 strncpy(data
,data2
+4,2);
124 strncat(data
,data2
+6,2);
126 strncat(data
,data2
,4);
130 ip2name(ip
,sizeof(ip
));
137 if(strcmp(ouser
,user
) == 0)
141 if(strcmp(oip
,ip
) == 0)
147 user_find(name
, sizeof(name
), user
);
149 if(SquidGuardReportLimit
) {
150 if(strcmp(ouser2
,name
) == 0) {
156 if(count
>= SquidGuardReportLimit
)
160 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
,data
,hora
);
161 output_html_url(fp_ou
,url
);
163 output_html_string(fp_ou
,url
,100);
164 fprintf(fp_ou
,"</a></td><td class=\"data2\">%s</td></th>\n",rule
);
168 fputs("</table></div>\n",fp_ou
);
169 write_html_trailer(fp_ou
);
172 unlink(squidguard_in
);