]>
git.ipfire.org Git - thirdparty/sarg.git/blob - smartfilter.c
66cea1225032fe7c13ac5713fade7018d5216b8b
2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
28 void smartfilter_report()
31 FILE *fp_in
= NULL
, *fp_ou
= NULL
, *fp_user
= NULL
;
37 char smart_in
[MAXLEN
];
38 char smart_ou
[MAXLEN
];
51 char smartuser
[MAXLEN
];
57 sprintf(smartheader
,"%s",text
[116]);
60 sprintf(smart_in
,"%s/smartfilter.unsort",dirname
);
61 sprintf(sites
,"%s/sites",dirname
);
62 sprintf(smart_ou
,"%s/smartfilter.log",dirname
);
63 sprintf(per
,"%s/periodo",dirname
);
64 sprintf(report
,"%s/smartfilter.html",dirname
);
66 if ((fp_in
= fopen(per
, "r")) == 0) {
67 fprintf(stderr
, "SARG: (smartfilter) %s: %s\n",text
[45],per
);
71 fgets(periodo
,sizeof(periodo
),fp_in
);
74 sprintf(csort
,"sort -n -k 1,1 -k 2,2 -k 3,3 -o '%s' '%s'",smart_ou
,smart_in
);
78 if((fp_in
=fopen(smart_ou
,"r"))==NULL
) {
79 fprintf(stderr
, "SARG: (smartfilter) %s: %s\n",text
[8],smart_ou
);
83 if((fp_ou
=fopen(report
,"w"))==NULL
) {
84 fprintf(stderr
, "SARG: (smartfilter) %s: %s\n",text
[8],report
);
88 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
89 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
90 fputs("<html>\n",fp_ou
);
91 fputs("<head>\n",fp_ou
);
92 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
94 fputs("</head>\n",fp_ou
);
96 if(strlen(FontFace
) > 0) {
97 sprintf(url
,"<font face=%s>\n",FontFace
);
101 sprintf(url
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
104 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou
);
106 if(strlen(LogoImage
) > 0) {
107 fputs("<center><table cellpadding=\"0\" cellspacing=\"0\">\n",fp_ou
);
108 sprintf(url
,"<tr><th class=\"logo\"><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr>\n",LogoImage
,Width
,Height
,LogoText
);
110 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou
);
111 fputs("</table>\n",fp_ou
);
114 sprintf(url
,"<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor
,Title
);
117 sprintf(url
,"<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr>\n",HeaderBgColor
,FontSize
,text
[89],periodo
);
119 sprintf(url
,"<tr><th bgcolor=%s align=center><font size=%s>%s %s</font></th></tr>\n",HeaderBgColor
,FontSize
,text
[116],text
[55]);
121 fputs("</table></center>\n",fp_ou
);
123 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_ou
);
124 fputs("<tr><td></td></tr>\n",fp_ou
);
125 fputs("<tr><td></td></tr>\n",fp_ou
);
126 fputs("<tr><td></td></tr>\n",fp_ou
);
127 sprintf(url
,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor
,FontSize
,text
[98],HeaderBgColor
,FontSize
,text
[111],HeaderBgColor
,FontSize
,text
[110],HeaderBgColor
,FontSize
,text
[91],HeaderBgColor
,FontSize
,smartheader
);
130 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
131 getword(user
,buf
,' ');
132 getword(data
,buf
,' ');
133 getword(hora
,buf
,' ');
135 getword(url
,buf
,' ');
136 getword(smartcat
,buf
,'\n');
138 if((str
=(char *) strstr(user
, "_")) != (char *) NULL
) {
139 if((str
=(char *) strstr(str
+1, "_")) != (char *) NULL
)
143 if(strcmp(ouser
,user
) != 0) {
145 sprintf(smartuser
,"%s/denied_%s.html",dirname
,user
);
148 fputs("</table>\n",fp_user
);
149 if(strcmp(ShowSargInfo
,"yes") == 0) {
150 zdate(ftime
, DateFormat
);
151 sprintf(html2
,"<br><br><center><font size=-2>%s <a href='%s'>%s-%s</a> %s %s</font></center>\n",text
[108],URL
,PGM
,VERSION
,text
[109],ftime
);
152 fputs(html2
,fp_user
);
154 fputs("</body>\n</html>\n",fp_user
);
157 if ((fp_user
= fopen(smartuser
, "a")) == 0) {
158 fprintf(stderr
, "SARG: (smartfilter) %s: %s\n",text
[45],smartuser
);
163 fputs("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"",fp_ou
);
164 fputs(" \"http://www.w3.org/TR/html4/loose.dtd\">\n",fp_ou
);
165 fputs("<html>\n",fp_user
);
166 fputs("<head>\n",fp_user
);
167 sprintf(html
," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet
);
169 fputs("</head>\n",fp_user
);
171 if(strlen(FontFace
) > 0) {
172 sprintf(html2
,"<font face=%s>\n",FontFace
);
175 sprintf(html2
,"<body bgcolor=%s text=%s background='%s'>\n",BgColor
,TxColor
,BgImage
);
176 fputs(html2
,fp_user
);
177 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_user
);
178 if(strlen(LogoImage
) > 0) {
179 sprintf(html2
,"<tr><th align=left><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage
,Width
,Height
,LogoTextColor
,LogoText
);
180 fputs(html2
,fp_user
);
182 sprintf(html2
,"<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor
,Title
);
183 fputs(html2
,fp_user
);
184 sprintf(html2
,"<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr>\n",HeaderBgColor
,FontSize
,text
[89],periodo
);
185 fputs(html2
,fp_user
);
186 sprintf(html2
,"<tr><td align=center bgcolor=%s><font size=%s>%s:</font><font size=%s> %s</font></td></tr>\n",HeaderBgColor
,FontSize
,text
[90],FontSize
,user
);
187 fputs(html2
,fp_user
);
188 fputs("</table></center>\n",fp_user
);
189 fputs("<center><table cellpadding=0 cellspacing=2>\n",fp_user
);
190 fputs("<tr><td></td></tr>\n",fp_user
);
191 fputs("<tr><td></td></tr>\n",fp_user
);
192 fputs("<tr><td></td></tr>\n",fp_user
);
193 sprintf(html2
,"<tr><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th><th bgcolor=%s><font size=%s>%s</font></th></tr>\n",HeaderBgColor
,FontSize
,text
[98],HeaderBgColor
,FontSize
,text
[111],HeaderBgColor
,FontSize
,text
[110],HeaderBgColor
,FontSize
,text
[91],HeaderBgColor
,FontSize
,smartheader
);
194 fputs(html2
,fp_user
);
196 sprintf(html2
,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor
,FontSize
,user
,TxBgColor
,FontSize
,ip
,TxBgColor
,FontSize
,data
,hora
,TxBgColor
,FontSize
,url
,TxBgColor
,FontSize
,smartcat
);
197 fputs(html2
,fp_user
);
199 sprintf(html
,"<tr><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s</font></td><td bgcolor=%s align=center><font size=%s>%s-%s</font></td><td bgcolor=%s><font size=%s>%s</font></td><td bgcolor=%s><font size=%s>%s</font></td></th>\n",TxBgColor
,FontSize
,user
,TxBgColor
,FontSize
,ip
,TxBgColor
,FontSize
,data
,hora
,TxBgColor
,FontSize
,url
,TxBgColor
,FontSize
,smartcat
);
203 fputs("</table>\n",fp_ou
);
205 if(strcmp(ShowSargInfo
,"yes") == 0) {
206 zdate(ftime
, DateFormat
);
207 sprintf(html
,"<br><br><center><font size=-2>%s <a href='%s'>%s-%s</a> %s %s</font></center>\n",text
[108],URL
,PGM
,VERSION
,text
[109],ftime
);
211 fputs("</body>\n</html>\n",fp_user
);
215 fputs("</table>\n",fp_user
);
216 if(strcmp(ShowSargInfo
,"yes") == 0) {
217 zdate(ftime
, DateFormat
);
218 sprintf(html2
,"<br><br><center><font size=-2>%s <a href='%s'>%s-%s</a> %s %s</font></center>\n",text
[108],URL
,PGM
,VERSION
,text
[109],ftime
);
219 fputs(html2
,fp_user
);
221 fputs("</body>\n</html>\n",fp_user
);