]>
git.ipfire.org Git - thirdparty/sarg.git/blob - smartfilter.c
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
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 ( void )
31 FILE * fp_in
= NULL
, * fp_ou
= NULL
, * fp_user
= NULL
;
35 char smart_in
[ MAXLEN
];
36 char smart_ou
[ MAXLEN
];
49 char smartuser
[ MAXLEN
];
56 sprintf ( smartheader
, "%s" , text
[ 116 ]);
59 sprintf ( smart_in
, "%s/smartfilter.unsort" , dirname
);
60 sprintf ( sites
, "%s/sarg-sites" , dirname
);
61 sprintf ( smart_ou
, "%s/smartfilter.log" , dirname
);
62 sprintf ( per
, "%s/sarg-period" , dirname
);
63 sprintf ( report
, "%s/smartfilter.html" , dirname
);
65 if (( fp_in
= fopen ( per
, "r" )) == 0 ) {
66 fprintf ( stderr
, "SARG: (smartfilter) %s: %s \n " , text
[ 45 ], per
);
70 fgets ( period
, sizeof ( period
), fp_in
);
73 sprintf ( csort
, "sort -n -k 1,1 -k 2,2 -k 3,3 -o '%s' '%s'" , smart_ou
, smart_in
);
74 cstatus
= system ( csort
);
75 if (! WIFEXITED ( cstatus
) || WEXITSTATUS ( cstatus
)) {
76 fprintf ( stderr
, "SARG: sort command return status %d \n " , WEXITSTATUS ( cstatus
));
77 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
80 if (( fp_in
= fopen ( smart_ou
, "r" ))== NULL
) {
81 fprintf ( stderr
, "SARG: (smartfilter) %s: %s \n " , text
[ 8 ], smart_ou
);
82 fprintf ( stderr
, "SARG: sort command: %s \n " , csort
);
87 if (( fp_ou
= fopen ( report
, "w" ))== NULL
) {
88 fprintf ( stderr
, "SARG: (smartfilter) %s: %s \n " , text
[ 8 ], report
);
92 fprintf ( fp_ou
, "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN \" \" http://www.w3.org/TR/html4/loose.dtd \" > \n <html> \n <head> \n <meta http-equiv= \" Content-Type \" content= \" text/html; charset=%s \" > \n " , CharSet
);
93 fputs ( "</head> \n " , fp_ou
);
94 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
95 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
96 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
97 if ( strlen ( LogoImage
) > 0 ) fprintf ( fp_ou
, "<center><table cellpadding= \" 0 \" cellspacing= \" 0 \" > \n <tr><th class= \" logo \" ><img src='%s' border=0 align=absmiddle width=%s height=%s> %s</th></tr> \n <tr><td height= \" 5 \" ></td></tr> \n </table> \n " , LogoImage
, Width
, Height
, LogoText
);
99 fprintf ( fp_ou
, "<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr> \n " , TiColor
, Title
);
100 fprintf ( fp_ou
, "<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr> \n " , HeaderBgColor
, FontSize
, text
[ 89 ], period
);
101 fprintf ( fp_ou
, "<tr><th bgcolor=%s align=center><font size=%s>%s</font></th></tr> \n " , HeaderBgColor
, FontSize
, text
[ 116 ]);
102 fputs ( "</table></center> \n " , fp_ou
);
104 fputs ( "<center><table cellpadding=0 cellspacing=2> \n " , fp_ou
);
105 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
106 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
107 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
108 fprintf ( fp_ou
, "<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
);
110 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
111 if ( getword ( user
, sizeof ( user
), buf
, ' ' )< 0 || getword ( data
, sizeof ( data
), buf
, ' ' )< 0 ||
112 getword ( hora
, sizeof ( hora
), buf
, ' ' )< 0 || getword ( ip
, sizeof ( ip
), buf
, ' ' )< 0 ||
113 getword ( url
, sizeof ( url
), buf
, ' ' )< 0 || getword ( smartcat
, sizeof ( smartcat
), buf
, ' \n ' )< 0 ) {
114 printf ( "SARG: Maybe you have a broken record or garbage in your %s file. \n " , smart_ou
);
118 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
119 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
123 if ( strcmp ( ouser
, user
) != 0 ) {
125 sprintf ( smartuser
, "%s/denied_%s.html" , dirname
, user
);
128 fputs ( "</table> \n " , fp_user
);
129 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
130 zdate ( ftime
, DateFormat
);
131 fprintf ( fp_user
, "<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
);
133 fputs ( "</body> \n </html> \n " , fp_user
);
136 if (( fp_user
= fopen ( smartuser
, "a" )) == 0 ) {
137 fprintf ( stderr
, "SARG: (smartfilter) %s: %s \n " , text
[ 45 ], smartuser
);
142 fputs ( "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN \" " , fp_ou
);
143 fputs ( " \" http://www.w3.org/TR/html4/loose.dtd \" > \n " , fp_ou
);
144 fputs ( "<html> \n " , fp_user
);
145 fputs ( "<head> \n " , fp_user
);
146 fprintf ( fp_user
, " <meta http-equiv= \" Content-Type \" content= \" text/html; charset=%s \" > \n " , CharSet
);
147 fputs ( "</head> \n " , fp_user
);
149 if ( strlen ( FontFace
) > 0 ) {
151 Before merging the sprintf and the fputs, the code looked like this:
152 sprintf(html2,"<font face=%s>\n",FontFace);
154 The two lines don't use the same buffer so the string formated by sprintf is not the string
155 written to fp_user. I (fmarchal) assumed it was a typo and replaced it by a fprintf but
156 that font tag is not valid outside of the body. So, the generated html was likely
157 containing garbage not rendered by the browser.
159 fprintf ( fp_user
, "<font face=%s> \n " , FontFace
);
161 fprintf ( fp_user
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
162 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_user
);
163 if ( strlen ( LogoImage
) > 0 ) fprintf ( fp_user
, "<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
);
164 fprintf ( fp_user
, "<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr> \n " , TiColor
, Title
);
165 fprintf ( fp_user
, "<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr> \n " , HeaderBgColor
, FontSize
, text
[ 89 ], period
);
166 fprintf ( fp_user
, "<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
);
167 fputs ( "</table></center> \n " , fp_user
);
168 fputs ( "<center><table cellpadding=0 cellspacing=2> \n " , fp_user
);
169 fputs ( "<tr><td></td></tr> \n " , fp_user
);
170 fputs ( "<tr><td></td></tr> \n " , fp_user
);
171 fputs ( "<tr><td></td></tr> \n " , fp_user
);
172 fprintf ( fp_user
, "<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
);
174 fprintf ( fp_user
, "<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
);
176 fprintf ( fp_ou
, "<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
);
179 fputs ( "</table> \n " , fp_ou
);
181 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
182 zdate ( ftime
, DateFormat
);
183 fprintf ( fp_ou
, "<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
);
186 fputs ( "</body> \n </html> \n " , fp_user
);
190 fputs ( "</table> \n " , fp_user
);
191 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
192 zdate ( ftime
, DateFormat
);
193 fprintf ( fp_user
, "<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
);
195 fputs ( "</body> \n </html> \n " , fp_user
);