]> git.ipfire.org Git - thirdparty/sarg.git/blame - smartfilter.c
Imported sarg 2.0.9
[thirdparty/sarg.git] / smartfilter.c
CommitLineData
25697a35 1/*
94ff9470 2 * AUTHOR: Pedro Lineu Orso orso@penguintech.com.br
25697a35 3 * 1998, 2005
94ff9470 4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
25697a35
GS
5 *
6 * SARG donations:
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
9 *
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.
14 *
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.
19 *
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.
23 *
24 */
25
26#include "include/conf.h"
27
28void smartfilter_report()
29{
30
31 FILE *fp_in = NULL, *fp_ou = NULL, *fp_user = NULL;
32
33 char url[MAXLEN];
34 char html[MAXLEN];
35 char html2[MAXLEN];
36 char csort[255];
37 char smart_in[MAXLEN];
38 char smart_ou[MAXLEN];
39 char per[MAXLEN];
40 char sites[MAXLEN];
41 char report[MAXLEN];
42 char periodo[100];
43 char ip[MAXLEN];
44 char user[MAXLEN];
45 char ouser[MAXLEN];
46 char data[15];
47 char hora[15];
48 char smartcat[256];
49 char smartheader[15];
50 char ftime[128];
51 char smartuser[MAXLEN];
52 char *str;
53 int fuser=0;
54
55 ouser[0]='\0';
56
57 sprintf(smartheader,"%s",text[116]);
58 strup(smartheader);
59
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);
65
66 if ((fp_in = fopen(per, "r")) == 0) {
67 fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[45],per);
68 exit(1);
69 }
70
71 fgets(periodo,sizeof(periodo),fp_in);
72 fclose(fp_in);
73
94ff9470 74 sprintf(csort,"sort -n -k 1,1 -k 2,2 -k 3,3 -o '%s' '%s'",smart_ou,smart_in);
25697a35
GS
75 system(csort);
76 unlink(smart_in);
77
78 if((fp_in=fopen(smart_ou,"r"))==NULL) {
79 fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],smart_ou);
80 exit(1);
81 }
82
83 if((fp_ou=fopen(report,"w"))==NULL) {
84 fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[8],report);
85 exit(1);
86 }
87
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);
93 fputs(html,fp_ou);
94 fputs("</head>\n",fp_ou);
95
96 if(strlen(FontFace) > 0) {
97 sprintf(url,"<font face=%s>\n",FontFace);
98 fputs(url,fp_ou);
99 }
100
101 sprintf(url,"<body bgcolor=%s text=%s background='%s'>\n",BgColor,TxColor,BgImage);
102 fputs(url,fp_ou);
103
104 fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
105
106 if(strlen(LogoImage) > 0) {
94ff9470
GS
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>&nbsp;%s</th></tr>\n",LogoImage,Width,Height,LogoText);
25697a35 109 fputs(url,fp_ou);
94ff9470
GS
110 fputs("<tr><td height=\"5\"></td></tr>\n",fp_ou);
111 fputs("</table>\n",fp_ou);
25697a35
GS
112 }
113
114 sprintf(url,"<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor,Title);
115 fputs(url,fp_ou);
116
117 sprintf(url,"<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr>\n",HeaderBgColor,FontSize,text[89],periodo);
118 fputs(url,fp_ou);
119 sprintf(url,"<tr><th bgcolor=%s align=center><font size=%s>%s %s</font></th></tr>\n",HeaderBgColor,FontSize,text[116],text[55]);
120 fputs(url,fp_ou);
121 fputs("</table></center>\n",fp_ou);
122
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);
128 fputs(url,fp_ou);
129
130 while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
131 getword(user,buf,' ');
132 getword(data,buf,' ');
133 getword(hora,buf,' ');
134 getword(ip,buf,' ');
135 getword(url,buf,' ');
136 getword(smartcat,buf,'\n');
137
138 if((str=(char *) strstr(user, "_")) != (char *) NULL ) {
139 if((str=(char *) strstr(str+1, "_")) != (char *) NULL )
140 fixip(user);
141 }
142
143 if(strcmp(ouser,user) != 0) {
144 strcpy(ouser,user);
145 sprintf(smartuser,"%s/denied_%s.html",dirname,user);
146 if(fuser) {
147 fuser=0;
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);
153 }
154 fputs("</body>\n</html>\n",fp_user);
155 fclose(fp_user);
156 }
157 if ((fp_user = fopen(smartuser, "a")) == 0) {
158 fprintf(stderr, "SARG: (smartfilter) %s: %s\n",text[45],smartuser);
159 exit(1);
160 }
161 fuser=1;
162
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);
168 fputs(html,fp_user);
169 fputs("</head>\n",fp_user);
170
171 if(strlen(FontFace) > 0) {
172 sprintf(html2,"<font face=%s>\n",FontFace);
173 fputs(url,fp_user);
174 }
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);
181 }
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);
195 }
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);
198
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);
200 fputs(html,fp_ou);
201 }
202
203 fputs("</table>\n",fp_ou);
204
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);
208 fputs(html,fp_ou);
209 }
210
211 fputs("</body>\n</html>\n",fp_user);
212
213 fclose(fp_ou);
214 if(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);
220 }
221 fputs("</body>\n</html>\n",fp_user);
222 fclose(fp_user);
223 }
224
225 return;
226}