]>
git.ipfire.org Git - thirdparty/sarg.git/blob - smartfilter.c
50f9e46cad910e8cbf9f981bf1f67850ee62681e
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 ()
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/sarg-sites" , dirname
);
62 sprintf ( smart_ou
, "%s/smartfilter.log" , dirname
);
63 sprintf ( per
, "%s/sarg-period" , 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 ( period
, sizeof ( period
), 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 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
);
89 fputs ( "</head> \n " , fp_ou
);
90 if ( strlen ( FontFace
) > 0 ) fprintf ( fp_ou
, "<font face=%s> \n " , FontFace
);
91 fprintf ( fp_ou
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
92 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_ou
);
93 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
);
95 fprintf ( fp_ou
, "<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr> \n " , TiColor
, Title
);
96 fprintf ( fp_ou
, "<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr> \n " , HeaderBgColor
, FontSize
, text
[ 89 ], period
);
97 fprintf ( fp_ou
, "<tr><th bgcolor=%s align=center><font size=%s>%s</font></th></tr> \n " , HeaderBgColor
, FontSize
, text
[ 116 ]);
98 fputs ( "</table></center> \n " , fp_ou
);
100 fputs ( "<center><table cellpadding=0 cellspacing=2> \n " , fp_ou
);
101 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
102 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
103 fputs ( "<tr><td></td></tr> \n " , fp_ou
);
104 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
);
106 while ( fgets ( buf
, sizeof ( buf
), fp_in
)!= NULL
) {
107 getword ( user
, buf
, ' ' );
108 getword ( data
, buf
, ' ' );
109 getword ( hora
, buf
, ' ' );
111 getword ( url
, buf
, ' ' );
112 getword ( smartcat
, buf
, ' \n ' );
114 if (( str
=( char *) strstr ( user
, "_" )) != ( char *) NULL
) {
115 if (( str
=( char *) strstr ( str
+ 1 , "_" )) != ( char *) NULL
)
119 if ( strcmp ( ouser
, user
) != 0 ) {
121 sprintf ( smartuser
, "%s/denied_%s.html" , dirname
, user
);
124 fputs ( "</table> \n " , fp_user
);
125 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
126 zdate ( ftime
, DateFormat
);
127 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
);
128 fputs ( html2
, fp_user
);
130 fputs ( "</body> \n </html> \n " , fp_user
);
133 if (( fp_user
= fopen ( smartuser
, "a" )) == 0 ) {
134 fprintf ( stderr
, "SARG: (smartfilter) %s: %s \n " , text
[ 45 ], smartuser
);
139 fputs ( "<!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01 Transitional//EN \" " , fp_ou
);
140 fputs ( " \" http://www.w3.org/TR/html4/loose.dtd \" > \n " , fp_ou
);
141 fputs ( "<html> \n " , fp_user
);
142 fputs ( "<head> \n " , fp_user
);
143 sprintf ( html
, " <meta http-equiv= \" Content-Type \" content= \" text/html; charset=%s \" > \n " , CharSet
);
145 fputs ( "</head> \n " , fp_user
);
147 if ( strlen ( FontFace
) > 0 ) {
148 sprintf ( html2
, "<font face=%s> \n " , FontFace
);
151 sprintf ( html2
, "<body bgcolor=%s text=%s background='%s'> \n " , BgColor
, TxColor
, BgImage
);
152 fputs ( html2
, fp_user
);
153 fputs ( "<center><table cellpadding=0 cellspacing=0> \n " , fp_user
);
154 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
);
155 fprintf ( fp_user
, "<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr> \n " , TiColor
, Title
);
156 fprintf ( fp_user
, "<tr><td align=center bgcolor=%s><font size=%s>%s: %s</font></td></tr> \n " , HeaderBgColor
, FontSize
, text
[ 89 ], period
);
157 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
);
158 fputs ( "</table></center> \n " , fp_user
);
159 fputs ( "<center><table cellpadding=0 cellspacing=2> \n " , fp_user
);
160 fputs ( "<tr><td></td></tr> \n " , fp_user
);
161 fputs ( "<tr><td></td></tr> \n " , fp_user
);
162 fputs ( "<tr><td></td></tr> \n " , fp_user
);
163 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
);
164 fputs ( html2
, fp_user
);
166 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
);
167 fputs ( html2
, fp_user
);
169 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
);
173 fputs ( "</table> \n " , fp_ou
);
175 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
176 zdate ( ftime
, DateFormat
);
177 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
);
181 fputs ( "</body> \n </html> \n " , fp_user
);
185 fputs ( "</table> \n " , fp_user
);
186 if ( strcmp ( ShowSargInfo
, "yes" ) == 0 ) {
187 zdate ( ftime
, DateFormat
);
188 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
);
189 fputs ( html2
, fp_user
);
191 fputs ( "</body> \n </html> \n " , fp_user
);